From 364a47f2c746a5eeb1642102580a9daa8bc27fc9 Mon Sep 17 00:00:00 2001
From: Steve Ebersole
Date: Thu, 2 May 2013 10:01:16 -0500
Subject: [PATCH] HHH-8159 - Apply fixups indicated by analysis tools
---
.../org/hibernate/envers/AuditJoinTable.java | 43 +-
.../org/hibernate/envers/AuditMappedBy.java | 26 +-
.../org/hibernate/envers/AuditOverride.java | 46 +-
.../org/hibernate/envers/AuditOverrides.java | 28 +-
.../org/hibernate/envers/AuditReader.java | 358 ++---
.../hibernate/envers/AuditReaderFactory.java | 75 +-
.../java/org/hibernate/envers/AuditTable.java | 26 +-
.../java/org/hibernate/envers/Audited.java | 52 +-
.../CrossTypeRevisionChangesReader.java | 122 +-
.../envers/DefaultRevisionEntity.java | 98 +-
...rackingModifiedEntitiesRevisionEntity.java | 97 +-
.../EntityTrackingRevisionListener.java | 50 +-
.../hibernate/envers/ModificationStore.java | 6 +-
.../hibernate/envers/ModifiedEntityNames.java | 24 +
.../java/org/hibernate/envers/NotAudited.java | 6 +-
.../envers/RelationTargetAuditMode.java | 4 +-
.../org/hibernate/envers/RevisionEntity.java | 12 +-
.../hibernate/envers/RevisionListener.java | 18 +-
.../org/hibernate/envers/RevisionNumber.java | 2 +-
.../hibernate/envers/RevisionTimestamp.java | 2 +-
.../org/hibernate/envers/RevisionType.java | 74 +-
.../hibernate/envers/SecondaryAuditTable.java | 9 +-
.../envers/SecondaryAuditTables.java | 7 +-
.../envers/configuration/EnversSettings.java | 29 +-
.../internal/AuditEntitiesConfiguration.java | 6 +-
.../internal/ClassesAuditingData.java | 172 ++-
.../internal/EntitiesConfigurator.java | 182 +--
.../internal/GlobalConfiguration.java | 13 +-
.../internal/PersistentClassGraphDefiner.java | 66 +-
.../internal/RevisionInfoConfiguration.java | 614 +++++----
.../RevisionInfoConfigurationResult.java | 34 +-
.../metadata/AuditEntityNameRegister.java | 99 +-
.../metadata/AuditMetadataGenerator.java | 958 +++++++------
.../internal/metadata/AuditTableData.java | 50 +-
.../metadata/BasicMetadataGenerator.java | 84 +-
.../metadata/CollectionMetadataGenerator.java | 1214 ++++++++++-------
.../metadata/ComponentMetadataGenerator.java | 63 +-
.../metadata/EntityXmlMappingData.java | 61 +-
.../metadata/IdMetadataGenerator.java | 261 ++--
.../internal/metadata/InheritanceType.java | 58 +-
.../internal/metadata/MetadataTools.java | 586 ++++----
.../metadata/QueryGeneratorBuilder.java | 122 +-
.../ToOneRelationMetadataGenerator.java | 220 +--
.../reader/AnnotationsMetadataReader.java | 117 +-
.../reader/AuditedPropertiesHolder.java | 34 +-
.../reader/AuditedPropertiesReader.java | 769 ++++++-----
.../metadata/reader/ClassAuditingData.java | 77 +-
.../ComponentAuditedPropertiesReader.java | 62 +-
.../reader/ComponentAuditingData.java | 27 +-
.../reader/PersistentPropertiesSource.java | 27 +
.../metadata/reader/PropertyAuditingData.java | 183 +--
.../configuration/spi/AuditConfiguration.java | 53 +-
.../enhanced/OrderedSequenceGenerator.java | 24 +
.../enhanced/SequenceIdRevisionEntity.java | 116 +-
...rackingModifiedEntitiesRevisionEntity.java | 83 +-
.../BaseEnversCollectionEventListener.java | 193 +--
.../event/spi/BaseEnversEventListener.java | 88 +-
.../envers/event/spi/EnversIntegrator.java | 70 +-
.../envers/event/spi/EnversListener.java | 5 +
.../EnversListenerDuplicationStrategy.java | 3 +
...stCollectionRecreateEventListenerImpl.java | 12 +-
.../EnversPostDeleteEventListenerImpl.java | 22 +-
.../EnversPostInsertEventListenerImpl.java | 31 +-
.../EnversPostUpdateEventListenerImpl.java | 32 +-
...sPreCollectionRemoveEventListenerImpl.java | 10 +-
...sPreCollectionUpdateEventListenerImpl.java | 10 +-
.../envers/exception/AuditException.java | 21 +-
.../envers/exception/NotAuditedException.java | 20 +-
.../RevisionDoesNotExistException.java | 39 +-
.../envers/internal/EnversMessageLogger.java | 13 +-
.../entities/EntitiesConfigurations.java | 180 +--
.../entities/EntityConfiguration.java | 214 ++-
.../internal/entities/EntityInstantiator.java | 207 +--
.../internal/entities/IdMappingData.java | 43 +-
.../internal/entities/PropertyData.java | 119 +-
.../entities/RelationDescription.java | 114 +-
.../internal/entities/RelationType.java | 53 +-
.../internal/entities/RevisionTypeType.java | 100 +-
.../entities/TypeContributorImpl.java | 46 +-
.../mapper/ComponentPropertyMapper.java | 147 +-
.../mapper/CompositeMapperBuilder.java | 12 +-
.../mapper/ExtendedPropertyMapper.java | 12 +-
.../entities/mapper/MultiPropertyMapper.java | 265 ++--
.../PersistentCollectionChangeData.java | 89 +-
.../entities/mapper/PropertyMapper.java | 73 +-
.../entities/mapper/SimpleMapperBuilder.java | 9 +-
.../entities/mapper/SinglePropertyMapper.java | 126 +-
.../mapper/SubclassPropertyMapper.java | 155 ++-
.../mapper/id/AbstractCompositeIdMapper.java | 59 +-
.../entities/mapper/id/AbstractIdMapper.java | 134 +-
.../entities/mapper/id/EmbeddedIdMapper.java | 133 +-
.../internal/entities/mapper/id/IdMapper.java | 131 +-
.../entities/mapper/id/MultipleIdMapper.java | 111 +-
.../mapper/id/QueryParameterData.java | 79 +-
.../mapper/id/SimpleIdMapperBuilder.java | 5 +-
.../entities/mapper/id/SingleIdMapper.java | 167 +--
.../relation/AbstractCollectionMapper.java | 279 ++--
.../relation/AbstractOneToOneMapper.java | 120 +-
.../mapper/relation/AbstractToOneMapper.java | 183 ++-
.../relation/BasicCollectionMapper.java | 66 +-
.../relation/CommonCollectionMapperData.java | 67 +-
.../mapper/relation/ListCollectionMapper.java | 93 +-
.../mapper/relation/MapCollectionMapper.java | 92 +-
.../mapper/relation/MiddleComponentData.java | 30 +-
.../mapper/relation/MiddleIdData.java | 89 +-
.../relation/OneToOneNotOwningMapper.java | 41 +-
.../OneToOnePrimaryKeyJoinColumnMapper.java | 110 +-
.../relation/SortedMapCollectionMapper.java | 34 +-
.../relation/SortedSetCollectionMapper.java | 28 +-
.../mapper/relation/ToOneEntityLoader.java | 63 +-
.../mapper/relation/ToOneIdMapper.java | 139 +-
.../component/MiddleComponentMapper.java | 70 +-
.../component/MiddleDummyComponentMapper.java | 33 +-
.../MiddleEmbeddableComponentMapper.java | 54 +-
.../MiddleMapKeyIdComponentMapper.java | 51 +-
.../MiddleMapKeyPropertyComponentMapper.java | 52 +-
.../MiddleRelatedComponentMapper.java | 46 +-
.../MiddleSimpleComponentMapper.java | 52 +-
.../MiddleStraightComponentMapper.java | 53 +-
.../AbstractDelegateSessionImplementor.java | 298 ++--
.../lazy/ToOneDelegateSessionImplementor.java | 56 +-
.../AbstractCollectionInitializor.java | 58 +-
.../ArrayCollectionInitializor.java | 65 +-
.../BasicCollectionInitializor.java | 101 +-
.../lazy/initializor/Initializor.java | 6 +-
.../ListCollectionInitializor.java | 95 +-
.../initializor/MapCollectionInitializor.java | 102 +-
.../SortedMapCollectionInitializor.java | 58 +-
.../SortedSetCollectionInitializor.java | 50 +-
.../relation/lazy/proxy/CollectionProxy.java | 176 +--
.../mapper/relation/lazy/proxy/ListProxy.java | 107 +-
.../mapper/relation/lazy/proxy/MapProxy.java | 171 +--
.../mapper/relation/lazy/proxy/SetProxy.java | 17 +-
.../relation/lazy/proxy/SortedMapProxy.java | 213 +--
.../relation/lazy/proxy/SortedSetProxy.java | 71 +-
.../query/AbstractRelationQueryGenerator.java | 20 +-
.../query/OneAuditEntityQueryGenerator.java | 29 +-
.../query/OneEntityQueryGenerator.java | 35 +-
.../mapper/relation/query/QueryConstants.java | 41 +-
.../query/RelationQueryGenerator.java | 10 +-
.../query/ThreeEntityQueryGenerator.java | 119 +-
.../TwoEntityOneAuditedQueryGenerator.java | 40 +-
.../query/TwoEntityQueryGenerator.java | 94 +-
.../internal/reader/AuditReaderImpl.java | 492 +++----
.../reader/AuditReaderImplementor.java | 14 +-
.../CrossTypeRevisionChangesReaderImpl.java | 196 ++-
.../internal/reader/FirstLevelCache.java | 136 +-
.../DefaultRevisionInfoGenerator.java | 132 +-
...ModifiedEntitiesRevisionInfoGenerator.java | 80 +-
.../ModifiedEntityNamesReader.java | 40 +-
.../revisioninfo/RevisionInfoGenerator.java | 18 +-
.../RevisionInfoNumberReader.java | 21 +-
.../RevisionInfoQueryCreator.java | 53 +-
.../synchronization/AuditProcess.java | 188 +--
.../synchronization/AuditProcessManager.java | 51 +-
.../synchronization/EntityChangeNotifier.java | 78 +-
.../synchronization/SessionCacheCleaner.java | 57 +-
.../work/AbstractAuditWorkUnit.java | 106 +-
.../synchronization/work/AddWorkUnit.java | 106 +-
.../synchronization/work/AuditWorkUnit.java | 56 +-
.../work/CollectionChangeWorkUnit.java | 108 +-
.../synchronization/work/DelWorkUnit.java | 115 +-
.../FakeBidirectionalRelationWorkUnit.java | 317 +++--
.../synchronization/work/ModWorkUnit.java | 113 +-
.../PersistentCollectionChangeWorkUnit.java | 311 +++--
.../work/WorkUnitMergeDispatcher.java | 19 +-
.../work/WorkUnitMergeVisitor.java | 19 +-
.../envers/internal/tools/ArgumentsTools.java | 4 +-
.../envers/internal/tools/ArraysTools.java | 8 +-
.../envers/internal/tools/EntityTools.java | 43 +-
.../envers/internal/tools/MappingTools.java | 29 +-
.../envers/internal/tools/MutableBoolean.java | 34 +-
.../envers/internal/tools/MutableInteger.java | 40 +-
.../internal/tools/ReflectionTools.java | 46 +-
.../envers/internal/tools/StringTools.java | 6 +-
.../envers/internal/tools/Tools.java | 10 +-
.../envers/internal/tools/Triple.java | 87 +-
.../internal/tools/graph/GraphDefiner.java | 17 +-
.../tools/graph/GraphTopologicalSort.java | 64 +-
.../internal/tools/graph/TopologicalSort.java | 58 +-
.../envers/internal/tools/graph/Vertex.java | 70 +-
.../internal/tools/query/Parameters.java | 374 ++---
.../internal/tools/query/QueryBuilder.java | 313 ++---
.../internal/tools/query/UpdateBuilder.java | 127 +-
.../hibernate/envers/query/AuditEntity.java | 107 +-
.../hibernate/envers/query/AuditQuery.java | 29 +-
.../envers/query/AuditQueryCreator.java | 318 +++--
.../criteria/AggregatedAuditExpression.java | 89 +-
.../query/criteria/AuditConjunction.java | 40 +-
.../envers/query/criteria/AuditCriterion.java | 5 +-
.../query/criteria/AuditDisjunction.java | 40 +-
.../envers/query/criteria/AuditId.java | 6 +-
.../envers/query/criteria/AuditProperty.java | 227 +--
.../envers/query/criteria/AuditRelatedId.java | 17 +-
.../query/criteria/ExtendableCriterion.java | 2 +-
.../internal/BetweenAuditExpression.java | 40 +-
.../criteria/internal/CriteriaTools.java | 60 +-
.../internal/IdentifierEqAuditExpression.java | 24 +-
.../criteria/internal/InAuditExpression.java | 31 +-
.../internal/LogicalAuditExpression.java | 29 +-
.../criteria/internal/NotAuditExpression.java | 17 +-
.../internal/NotNullAuditExpression.java | 35 +-
.../internal/NullAuditExpression.java | 35 +-
.../internal/PropertyAuditExpression.java | 36 +-
.../internal/RelatedAuditExpression.java | 49 +-
.../internal/RevisionTypeAuditExpression.java | 21 +-
.../internal/SimpleAuditExpression.java | 55 +-
.../internal/impl/AbstractAuditQuery.java | 283 ++--
.../impl/EntitiesAtRevisionQuery.java | 124 +-
.../impl/EntitiesModifiedAtRevisionQuery.java | 68 +-
.../internal/impl/RevisionsOfEntityQuery.java | 174 +--
.../internal/property/EntityPropertyName.java | 15 +-
.../property/ModifiedFlagPropertyName.java | 18 +-
.../property/OriginalIdPropertyName.java | 17 +-
.../internal/property/PropertyNameGetter.java | 12 +-
.../property/RevisionNumberPropertyName.java | 7 +-
.../RevisionPropertyPropertyName.java | 15 +-
.../property/RevisionTypePropertyName.java | 7 +-
.../envers/query/order/AuditOrder.java | 11 +-
.../order/internal/PropertyAuditOrder.java | 18 +-
.../query/projection/AuditProjection.java | 11 +-
.../internal/PropertyAuditProjection.java | 24 +-
.../envers/strategy/AuditStrategy.java | 137 +-
.../envers/strategy/DefaultAuditStrategy.java | 145 +-
.../strategy/ValidTimeAuditStrategy.java | 9 +-
.../strategy/ValidityAuditStrategy.java | 305 +++--
.../java/org/hibernate/envers/tools/Pair.java | 74 +-
.../tools/hbm2ddl/EnversSchemaGenerator.java | 73 +-
.../test/java/ee/estonia/entities/Child.java | 98 +-
.../test/java/ee/estonia/entities/Parent.java | 118 +-
.../envers/test/AbstractEnversTest.java | 26 +-
.../envers/test/AbstractOneSessionTest.java | 61 +-
.../test/BaseEnversFunctionalTestCase.java | 27 +-
.../test/BaseEnversJPAFunctionalTestCase.java | 35 +-
.../hibernate/envers/test/EnversRunner.java | 109 +-
.../org/hibernate/envers/test/Priority.java | 3 +-
.../test/entities/IntNoAutoIdTestEntity.java | 95 +-
.../envers/test/entities/IntTestEntity.java | 95 +-
.../test/entities/IntTestPrivSeqEntity.java | 99 +-
.../test/entities/PrimitiveTestEntity.java | 61 +-
.../test/entities/StrIntTestEntity.java | 123 +-
.../envers/test/entities/StrTestEntity.java | 95 +-
.../entities/StrTestEntityComparator.java | 10 +-
.../test/entities/StrTestNoProxyEntity.java | 22 +-
.../test/entities/StrTestPrivSeqEntity.java | 99 +-
.../test/entities/UnversionedEntity.java | 117 +-
.../entities/UnversionedStrTestEntity.java | 93 +-
.../collection/EmbeddableListEntity1.java | 18 +-
.../collection/EmbeddableListEntity2.java | 18 +-
.../collection/EmbeddableMapEntity.java | 18 +-
.../collection/EmbeddableSetEntity.java | 18 +-
.../entities/collection/EnumSetEntity.java | 108 +-
.../collection/MultipleCollectionEntity.java | 24 +-
.../MultipleCollectionRefEntity1.java | 2 +-
.../MultipleCollectionRefEntity2.java | 2 +-
.../entities/collection/StringListEntity.java | 81 +-
.../entities/collection/StringMapEntity.java | 81 +-
.../entities/collection/StringSetEntity.java | 79 +-
.../test/entities/components/Component1.java | 83 +-
.../test/entities/components/Component2.java | 83 +-
.../test/entities/components/Component3.java | 39 +-
.../test/entities/components/Component4.java | 26 +-
.../components/ComponentSetTestEntity.java | 43 +-
.../components/ComponentTestEntity.java | 123 +-
.../components/DefaultValueComponent1.java | 22 +-
.../components/DefaultValueComponent2.java | 18 +-
.../DefaultValueComponentTestEntity.java | 24 +-
.../components/UniquePropsEntity.java | 106 +-
.../UniquePropsNotAuditedEntity.java | 108 +-
.../relations/ManyToOneComponent.java | 44 +-
.../ManyToOneComponentTestEntity.java | 73 +-
.../relations/ManyToOneEagerComponent.java | 18 +-
.../NotAuditedManyToOneComponent.java | 45 +-
...otAuditedManyToOneComponentTestEntity.java | 73 +-
.../relations/OneToManyComponent.java | 47 +-
.../OneToManyComponentTestEntity.java | 73 +-
.../test/entities/customtype/Component.java | 77 +-
.../customtype/CompositeCustomTypeEntity.java | 93 +-
.../customtype/CompositeTestUserType.java | 168 +--
.../entities/customtype/EnumTypeEntity.java | 29 +-
.../ParametrizedCustomTypeEntity.java | 93 +-
.../customtype/ParametrizedTestUserType.java | 118 +-
.../customtype/UnspecifiedEnumTypeEntity.java | 29 +-
.../ids/CompositeDateIdTestEntity.java | 89 +-
.../envers/test/entities/ids/CustomEnum.java | 16 +-
.../test/entities/ids/CustomEnumUserType.java | 102 +-
.../envers/test/entities/ids/DateEmbId.java | 85 +-
.../test/entities/ids/DateIdTestEntity.java | 91 +-
.../envers/test/entities/ids/EmbId.java | 85 +-
.../test/entities/ids/EmbIdTestEntity.java | 87 +-
.../entities/ids/EmbIdWithCustomType.java | 85 +-
.../ids/EmbIdWithCustomTypeTestEntity.java | 81 +-
.../ids/ManyToOneIdNotAuditedTestEntity.java | 75 +-
.../ids/ManyToOneNotAuditedEmbId.java | 59 +-
.../envers/test/entities/ids/MulId.java | 83 +-
.../test/entities/ids/MulIdTestEntity.java | 111 +-
.../entities/ids/UnusualIdNamingEntity.java | 20 +-
.../entities/manytomany/ListOwnedEntity.java | 114 +-
.../entities/manytomany/ListOwningEntity.java | 113 +-
.../entities/manytomany/MapOwnedEntity.java | 114 +-
.../entities/manytomany/MapOwningEntity.java | 117 +-
.../entities/manytomany/SetOwnedEntity.java | 114 +-
.../entities/manytomany/SetOwningEntity.java | 113 +-
.../entities/manytomany/SortedSetEntity.java | 116 +-
.../manytomany/WhereJoinTableEntity.java | 137 +-
.../biowned/ListBiowning1Entity.java | 123 +-
.../biowned/ListBiowning2Entity.java | 123 +-
.../manytomany/sametable/Child1Entity.java | 121 +-
.../manytomany/sametable/Child2Entity.java | 121 +-
.../manytomany/sametable/ParentEntity.java | 141 +-
.../unidirectional/JoinTableEntity.java | 28 +-
.../unidirectional/ListUniEntity.java | 113 +-
.../M2MIndexedListTargetNotAuditedEntity.java | 117 +-
.../M2MTargetNotAuditedEntity.java | 39 +-
.../unidirectional/MapUniEntity.java | 116 +-
.../unidirectional/SetUniEntity.java | 113 +-
.../TargetNotAuditedEntity.java | 21 +-
.../onetomany/CollectionRefEdEntity.java | 114 +-
.../onetomany/CollectionRefIngEntity.java | 119 +-
.../entities/onetomany/ListRefEdEntity.java | 114 +-
.../entities/onetomany/ListRefIngEntity.java | 115 +-
.../entities/onetomany/SetRefEdEntity.java | 114 +-
.../entities/onetomany/SetRefIngEntity.java | 123 +-
...stJoinColumnBidirectionalRefEdEntity1.java | 122 +-
...stJoinColumnBidirectionalRefEdEntity2.java | 122 +-
...stJoinColumnBidirectionalRefIngEntity.java | 139 +-
.../detached/DoubleSetRefCollEntity.java | 136 +-
...istJoinColumnBidirectionalRefEdEntity.java | 138 +-
...stJoinColumnBidirectionalRefIngEntity.java | 132 +-
...irectionalInheritanceRefEdChildEntity.java | 93 +-
...rectionalInheritanceRefEdParentEntity.java | 122 +-
...nBidirectionalInheritanceRefIngEntity.java | 130 +-
...istJoinColumnBidirectionalRefEdEntity.java | 120 +-
...stJoinColumnBidirectionalRefIngEntity.java | 128 +-
.../onetomany/detached/ListRefCollEntity.java | 114 +-
.../detached/SetJoinColumnRefCollEntity.java | 118 +-
.../onetomany/detached/SetRefCollEntity.java | 114 +-
.../detached/ids/SetRefCollEntityEmbId.java | 114 +-
.../detached/ids/SetRefCollEntityMulId.java | 138 +-
...stJoinColumnBidirectionalRefIngEntity.java | 90 +-
...stJoinColumnBidirectionalRefIngEntity.java | 132 +-
...istJoinColumnBidirectionalRefEdEntity.java | 138 +-
.../onetomany/ids/SetRefEdEmbIdEntity.java | 114 +-
.../onetomany/ids/SetRefEdMulIdEntity.java | 148 +-
.../onetomany/ids/SetRefIngEmbIdEntity.java | 115 +-
.../onetomany/ids/SetRefIngMulIdEntity.java | 151 +-
...rectionalEagerAnnotationRefEdOneToOne.java | 20 +-
...ectionalEagerAnnotationRefIngOneToOne.java | 20 +-
.../BidirectionalEagerHbmRefEdPK.java | 23 +-
.../BidirectionalEagerHbmRefIngPK.java | 23 +-
.../reventity/CustomDataRevEntity.java | 70 +-
.../reventity/CustomDateRevEntity.java | 91 +-
.../CustomPropertyAccessRevEntity.java | 86 +-
.../entities/reventity/CustomRevEntity.java | 86 +-
.../CustomRevEntityColumnMapping.java | 90 +-
.../AnnotatedTrackingRevisionEntity.java | 122 +-
.../CustomTrackingRevisionEntity.java | 118 +-
.../CustomTrackingRevisionListener.java | 17 +-
.../ExtendedRevisionEntity.java | 16 +-
.../ExtendedRevisionListener.java | 8 +-
.../ModifiedEntityTypeEntity.java | 93 +-
.../test/integration/accesstype/Country.java | 33 +-
.../accesstype/FieldAccessType.java | 64 +-
.../accesstype/FieldAccessTypeEntity.java | 101 +-
.../accesstype/ImmutableClassAccessType.java | 35 +-
.../accesstype/MixedAccessType.java | 70 +-
.../accesstype/MixedAccessTypeEntity.java | 119 +-
.../accesstype/PropertyAccessType.java | 74 +-
.../accesstype/PropertyAccessTypeEntity.java | 119 +-
.../auditReader/AuditReaderAPITest.java | 83 +-
.../auditReader/AuditedTestEntity.java | 87 +-
.../auditReader/NotAuditedTestEntity.java | 85 +-
.../integration/basic/BasicTestEntity1.java | 115 +-
.../integration/basic/BasicTestEntity2.java | 113 +-
.../integration/basic/BasicTestEntity3.java | 111 +-
.../integration/basic/BasicTestEntity4.java | 111 +-
.../basic/ColumnScalePrecisionTest.java | 83 +-
.../envers/test/integration/basic/Delete.java | 158 +--
.../integration/basic/EmptyStringTest.java | 83 +-
.../integration/basic/GlobalVersioned.java | 64 +-
.../basic/ManyOperationsInTransaction.java | 142 +-
.../test/integration/basic/NoneAudited.java | 36 +-
.../test/integration/basic/NotVersioned.java | 56 +-
.../integration/basic/NullProperties.java | 108 +-
.../basic/OutsideTransactionTest.java | 163 +--
.../basic/RegisterUserEventListenersTest.java | 39 +-
.../basic/ScalePrecisionEntity.java | 100 +-
.../envers/test/integration/basic/Simple.java | 62 +-
.../basic/SingleOperationInTransaction.java | 206 +--
.../basic/TransactionRollbackBehaviour.java | 33 +-
.../basic/UnversionedPropertiesChange.java | 82 +-
.../basic/UnversionedProperty.java | 70 +-
.../integration/cache/OneToManyCache.java | 152 +--
.../test/integration/cache/OneToOneCache.java | 86 +-
.../test/integration/cache/QueryCache.java | 80 +-
.../DetachedMultipleCollectionChangeTest.java | 45 +-
.../test/integration/collection/EnumSet.java | 151 +-
.../integration/collection/StringList.java | 124 +-
.../integration/collection/StringMap.java | 144 +-
.../integration/collection/StringSet.java | 124 +-
.../embeddable/BasicEmbeddableCollection.java | 13 +-
.../collection/embeddable/DarkCharacter.java | 22 +-
.../embeddable/EmbeddableList1.java | 18 +-
.../embeddable/EmbeddableList2.java | 20 +-
.../collection/embeddable/EmbeddableMap.java | 27 +-
.../collection/embeddable/EmbeddableSet.java | 18 +-
.../collection/embeddable/Name.java | 20 +-
.../collection/mapkey/ComponentMapKey.java | 108 +-
.../mapkey/ComponentMapKeyEntity.java | 81 +-
.../collection/mapkey/IdMapKey.java | 92 +-
.../collection/mapkey/IdMapKeyEntity.java | 81 +-
.../AbstractCollectionChangeTest.java | 86 +-
.../CollectionChangeNoRevisionTest.java | 15 +-
.../CollectionChangeRevisionTest.java | 19 +-
.../collection/norevision/Name.java | 53 +-
.../collection/norevision/Person.java | 50 +-
.../integration/components/Components.java | 224 +--
.../components/DefaultValueComponents.java | 450 +++---
.../components/PropertiesGroupTest.java | 115 +-
.../collections/CollectionOfComponents.java | 73 +-
.../dynamic/AuditedDynamicComponentTest.java | 15 +-
.../NotAuditedDynamicComponentTest.java | 28 +-
.../NotAuditedDynamicMapComponent.java | 26 +-
.../relations/ManyToOneInComponent.java | 116 +-
.../NotAuditedManyToOneInComponent.java | 104 +-
.../relations/OneToManyInComponent.java | 113 +-
.../customtype/CompositeCustom.java | 89 +-
.../integration/customtype/EnumTypeTest.java | 17 +-
.../customtype/ObjectUserType.java | 19 +-
.../customtype/ObjectUserTypeEntity.java | 29 +-
.../customtype/ObjectUserTypeTest.java | 16 +-
.../customtype/ParametrizedCustom.java | 75 +-
.../customtype/UnspecifiedEnumTypeTest.java | 50 +-
.../test/integration/data/DateTestEntity.java | 105 +-
.../envers/test/integration/data/Dates.java | 64 +-
.../test/integration/data/EnumTestEntity.java | 120 +-
.../envers/test/integration/data/Enums.java | 64 +-
.../data/LobSerializableTestEntity.java | 90 +-
.../integration/data/LobSerializables.java | 77 +-
.../test/integration/data/LobTestEntity.java | 149 +-
.../envers/test/integration/data/Lobs.java | 83 +-
.../test/integration/data/SerObject.java | 53 +-
.../data/SerializableTestEntity.java | 89 +-
.../test/integration/data/Serializables.java | 62 +-
.../entityNames/auditedEntity/Person.java | 19 +-
.../ReadEntityWhitEntityNameTest.java | 215 +--
.../entityNames/manyToManyAudited/Car.java | 18 +-
.../entityNames/manyToManyAudited/Person.java | 21 +-
.../ReadEntityWithAuditedManyToManyTest.java | 182 +--
.../entityNames/oneToManyAudited/Car.java | 18 +-
.../entityNames/oneToManyAudited/Person.java | 19 +-
.../ReadEntityWithAuditedCollectionTest.java | 178 +--
.../entityNames/oneToManyNotAudited/Car.java | 20 +-
.../oneToManyNotAudited/Person.java | 18 +-
.../ReadEntityWithAuditedCollectionTest.java | 180 ++-
.../singleAssociatedAudited/Car.java | 33 +-
.../singleAssociatedAudited/Person.java | 19 +-
.../ReadEntityAssociatedAuditedTest.java | 173 ++-
...ingleDomainObjectToMultipleTablesTest.java | 83 +-
.../singleAssociatedNotAudited/Car.java | 20 +-
.../singleAssociatedNotAudited/Person.java | 18 +-
.../ReadEntityAssociatedNotAuditedTest.java | 179 +--
.../integration/flush/AbstractFlushTest.java | 45 +-
.../integration/flush/DoubleFlushAddDel.java | 60 +-
.../integration/flush/DoubleFlushAddMod.java | 100 +-
.../integration/flush/DoubleFlushModDel.java | 96 +-
.../integration/flush/DoubleFlushModMod.java | 98 +-
.../test/integration/flush/ManualFlush.java | 116 +-
.../flush/ManualFlushAutoCommitDisabled.java | 10 +-
.../hashcode/ChangingHashcode.java | 104 +-
.../test/integration/hashcode/WikiImage.java | 13 +-
.../test/integration/hashcode/WikiPage.java | 21 +-
.../test/integration/ids/CompositeDateId.java | 72 +-
.../test/integration/ids/CompositeIds.java | 294 ++--
.../envers/test/integration/ids/DateId.java | 68 +-
.../ids/ManyToOneIdNotAudited.java | 51 +-
.../test/integration/ids/embeddedid/Item.java | 90 +-
.../integration/ids/embeddedid/ItemId.java | 118 +-
.../integration/ids/embeddedid/Producer.java | 94 +-
.../ids/embeddedid/PurchaseOrder.java | 135 +-
.../RelationInsideEmbeddableTest.java | 125 +-
.../integration/ids/idclass/ClassType.java | 84 +-
.../ids/idclass/IdClassWithRelationTest.java | 167 +--
.../ids/idclass/RelationalClassId.java | 86 +-
.../integration/ids/idclass/SampleClass.java | 128 +-
.../ProtectedConstructorEntity.java | 24 +-
.../ProtectedConstructorTest.java | 19 +-
.../protectedmodifier/WrappedStringId.java | 12 +-
.../inheritance/joined/ChildAuditing.java | 88 +-
.../inheritance/joined/ChildEntity.java | 69 +-
.../inheritance/joined/ChildNullAuditing.java | 88 +-
.../inheritance/joined/ParentAuditing.java | 92 +-
.../inheritance/joined/ParentEntity.java | 87 +-
.../joined/childrelation/ChildIngEntity.java | 85 +-
.../childrelation/ChildReferencing.java | 134 +-
.../childrelation/ParentNotIngEntity.java | 87 +-
.../childrelation/ReferencedEntity.java | 77 +-
.../joined/emptychild/EmptyChildAuditing.java | 86 +-
.../joined/emptychild/EmptyChildEntity.java | 3 +-
.../joined/emptychild/ParentEntity.java | 87 +-
.../joined/notownedrelation/Address.java | 59 +-
.../joined/notownedrelation/Contact.java | 67 +-
.../NotOwnedBidirectional.java | 114 +-
.../notownedrelation/PersonalContact.java | 19 +-
.../ChildPrimaryKeyJoinAuditing.java | 110 +-
.../ChildPrimaryKeyJoinEntity.java | 73 +-
.../joined/relation/ChildIngEntity.java | 69 +-
.../joined/relation/ParentIngEntity.java | 103 +-
.../relation/ParentReferencingChildTest.java | 109 +-
.../inheritance/joined/relation/Person.java | 70 +-
.../relation/PolymorphicCollection.java | 104 +-
.../joined/relation/ReferencedEntity.java | 77 +-
.../joined/relation/RightsSubject.java | 112 +-
.../inheritance/joined/relation/Role.java | 90 +-
.../AbstractContainedEntity.java | 19 +-
.../unidirectional/AbstractSetEntity.java | 29 +-
.../unidirectional/ContainedEntity.java | 3 +-
.../relation/unidirectional/SetEntity.java | 1 +
.../UnidirectionalDoubleAbstract.java | 54 +-
.../MixedInheritanceStrategiesEntityTest.java | 180 +--
.../mixed/entities/AbstractActivity.java | 26 +-
.../mixed/entities/AbstractCheckActivity.java | 44 +-
.../inheritance/mixed/entities/Activity.java | 2 +-
.../mixed/entities/ActivityId.java | 8 +-
.../mixed/entities/CheckInActivity.java | 30 +-
.../mixed/entities/NormalActivity.java | 30 +-
.../inheritance/single/ChildAuditing.java | 86 +-
.../inheritance/single/ChildEntity.java | 77 +-
.../inheritance/single/ParentAuditing.java | 92 +-
.../inheritance/single/ParentEntity.java | 95 +-
.../single/childrelation/ChildIngEntity.java | 93 +-
.../childrelation/ChildReferencing.java | 132 +-
.../childrelation/ParentNotIngEntity.java | 95 +-
.../childrelation/ReferencedEntity.java | 73 +-
.../discriminatorformula/ChildEntity.java | 74 +-
.../discriminatorformula/ClassTypeEntity.java | 78 +-
.../DiscriminatorFormulaTest.java | 218 +--
.../discriminatorformula/ParentEntity.java | 118 +-
.../single/notownedrelation/Address.java | 56 +-
.../single/notownedrelation/Contact.java | 62 +-
.../NotOwnedBidirectional.java | 124 +-
.../notownedrelation/PersonalContact.java | 5 +-
.../single/relation/ChildIngEntity.java | 77 +-
.../single/relation/ParentIngEntity.java | 111 +-
.../relation/PolymorphicCollection.java | 102 +-
.../single/relation/ReferencedEntity.java | 63 +-
.../tableperclass/ChildAuditing.java | 88 +-
.../tableperclass/ChildEntity.java | 69 +-
.../tableperclass/ParentAuditing.java | 92 +-
.../tableperclass/ParentEntity.java | 87 +-
.../AuditedAbstractParentTest.java | 11 +-
.../childrelation/ChildIngEntity.java | 85 +-
.../childrelation/ChildReferencing.java | 134 +-
.../childrelation/ParentNotIngEntity.java | 87 +-
.../childrelation/ReferencedEntity.java | 77 +-
.../notownedrelation/Address.java | 59 +-
.../notownedrelation/Contact.java | 67 +-
.../NotOwnedBidirectional.java | 114 +-
.../notownedrelation/PersonalContact.java | 19 +-
.../relation/ChildIngEntity.java | 69 +-
.../relation/ParentIngEntity.java | 103 +-
.../relation/PolymorphicCollection.java | 104 +-
.../relation/ReferencedEntity.java | 77 +-
.../interfaces/components/Component1.java | 15 +-
.../components/ComponentTestEntity.java | 39 +-
.../interfaces/components/IComponent.java | 1 +
.../components/InterfacesComponents.java | 84 +-
.../allAudited/AbstractAllAuditedTest.java | 179 +--
.../hbm/allAudited/AuditedImplementor.java | 2 +-
.../hbm/allAudited/NonAuditedImplementor.java | 2 -
.../hbm/allAudited/SimpleInterface.java | 10 +-
.../joined/JoinedAllAuditedTest.java | 8 +-
.../subclass/SubclassAllAuditedTest.java | 8 +-
.../allAudited/union/UnionAllAuditedTest.java | 8 +-
.../AbstractPropertiesAuditedTest.java | 65 +-
.../propertiesAudited/AuditedImplementor.java | 4 +-
.../propertiesAudited/SimpleInterface.java | 14 +-
.../joined/JoinedPropertiesAuditedTest.java | 5 +-
.../SubclassPropertiesAuditedTest.java | 3 +-
.../union/UnionPropertiesAuditedTest.java | 5 +-
.../AbstractPropertiesAudited2Test.java | 63 +-
.../AuditedImplementor.java | 4 +-
.../NonAuditedImplementor.java | 3 +-
.../propertiesAudited2/SimpleInterface.java | 14 +-
.../joined/JoinedPropertiesAudited2Test.java | 2 +-
.../SubclassPropertiesAudited2Test.java | 7 +-
.../union/UnionPropertiesAudited2Test.java | 5 +-
.../relation/InterfacesRelation.java | 108 +-
.../interfaces/relation/SetRefEdEntity.java | 92 +-
.../interfaces/relation/SetRefIngEntity.java | 123 +-
.../integration/jta/JtaExceptionListener.java | 66 +-
.../test/integration/jta/JtaTransaction.java | 100 +-
.../integration/manytomany/BasicList.java | 261 ++--
.../test/integration/manytomany/BasicMap.java | 208 +--
.../test/integration/manytomany/BasicSet.java | 258 ++--
.../manytomany/BasicWhereJoinTable.java | 222 +--
.../CustomComparatorEntityTest.java | 346 ++---
.../manytomany/biowned/BasicBiowned.java | 285 ++--
.../inverseToSuperclass/DetailSubclass.java | 1 +
.../inverseToSuperclass/DetailSubclass2.java | 3 +-
.../inverseToSuperclass/DetailSuperclass.java | 1 +
.../ManyToManyInverseToSuperclassTest.java | 35 +-
.../inverseToSuperclass/Master.java | 1 +
.../manytomany/sametable/BasicSametable.java | 425 +++---
.../manytomany/ternary/TernaryMap.java | 224 +--
.../manytomany/ternary/TernaryMapEntity.java | 81 +-
.../manytomany/ternary/TernaryMapFlush.java | 152 +--
.../unidirectional/BasicUniList.java | 196 +--
.../unidirectional/BasicUniMap.java | 136 +-
.../unidirectional/BasicUniSet.java | 196 +--
.../unidirectional/JoinTableDetachedTest.java | 24 +-
.../M2MIndexedListNotAuditedTarget.java | 154 ++-
.../M2MRelationNotAuditedTarget.java | 115 +-
.../bidirectional/ImplicitMappedByTest.java | 151 +-
.../bidirectional/ManyToOneOwning.java | 122 +-
.../bidirectional/OneToManyOwned.java | 122 +-
.../RelationNotAuditedTarget.java | 110 +-
.../test/integration/merge/AddDelTest.java | 95 +-
.../integration/merge/GivenIdStrEntity.java | 88 +-
.../AbstractModifiedFlagsEntityTest.java | 66 +-
.../AbstractModifiedFlagsOneSessionTest.java | 10 +-
.../modifiedflags/HasChangedAPITest.java | 64 +-
.../HasChangedAuditedManyToManyTest.java | 135 +-
.../HasChangedBidirectional2.java | 112 +-
.../HasChangedChildAuditing.java | 76 +-
.../HasChangedChildReferencing.java | 88 +-
.../HasChangedComponentCollection.java | 11 +-
.../HasChangedComponentMapKey.java | 118 +-
.../modifiedflags/HasChangedComponents.java | 225 +--
.../HasChangedCompositeCustom.java | 68 +-
.../HasChangedDetachedMultipleCollection.java | 9 +-
...ngedDoubleJoinColumnBidirectionalList.java | 277 ++--
.../modifiedflags/HasChangedEnumSet.java | 102 +-
.../HasChangedForDefaultNotUsing.java | 172 ++-
.../modifiedflags/HasChangedIdMapKey.java | 74 +-
.../modifiedflags/HasChangedManualFlush.java | 9 +-
.../HasChangedManyToOneInComponent.java | 83 +-
.../modifiedflags/HasChangedMergeTest.java | 9 +-
.../HasChangedNotOwnedBidirectional.java | 84 +-
.../HasChangedNullProperties.java | 112 +-
.../HasChangedOneToManyInComponent.java | 80 +-
.../modifiedflags/HasChangedStringMap.java | 126 +-
.../modifiedflags/HasChangedStringSet.java | 114 +-
.../HasChangedUnversionedProperties.java | 76 +-
.../modifiedflags/ModifiedFlagSuffix.java | 83 +-
.../entities/PartialModifiedFlagsEntity.java | 136 +-
.../WithModifiedFlagReferencingEntity.java | 108 +-
.../multiplerelations/Address.java | 136 +-
.../MultipleAssociationsTest.java | 290 ++--
.../integration/multiplerelations/Person.java | 140 +-
.../test/integration/naming/BasicNaming.java | 119 +-
.../naming/DetachedNamingTestEntity.java | 119 +-
.../naming/EstonianTableAlias.java | 60 +-
.../test/integration/naming/JoinNaming.java | 142 +-
.../naming/JoinNamingRefEdEntity.java | 118 +-
.../naming/JoinNamingRefIngEntity.java | 121 +-
.../integration/naming/NamingTestEntity1.java | 95 +-
.../naming/OneToManyUnidirectionalNaming.java | 138 +-
.../naming/VersionsJoinTableNaming.java | 144 +-
.../VersionsJoinTableRangeComponent.java | 43 +-
...ionsJoinTableRangeComponentNamingTest.java | 154 ++-
...ionsJoinTableRangeComponentTestEntity.java | 109 +-
...ionsJoinTableRangeTestAlternateEntity.java | 39 +-
.../VersionsJoinTableRangeTestEntity.java | 37 +-
...onsJoinTableRangeTestEntitySuperClass.java | 36 +-
.../naming/VersionsJoinTableTestEntity.java | 117 +-
.../integration/naming/ids/EmbIdNaming.java | 89 +-
.../naming/ids/JoinEmbIdNaming.java | 169 ++-
.../ids/JoinEmbIdNamingRefEdEntity.java | 116 +-
.../ids/JoinEmbIdNamingRefIngEntity.java | 123 +-
.../naming/ids/JoinMulIdNaming.java | 169 ++-
.../ids/JoinMulIdNamingRefEdEntity.java | 138 +-
.../ids/JoinMulIdNamingRefIngEntity.java | 134 +-
.../integration/naming/ids/MulIdNaming.java | 89 +-
.../naming/quotation/QuotedFieldsEntity.java | 136 +-
.../naming/quotation/QuotedFieldsTest.java | 152 ++-
.../notinsertable/NotInsertable.java | 62 +-
.../NotInsertableTestEntity.java | 113 +-
.../manytoone/ManyToOneNotInsertable.java | 95 +-
.../ManyToOneNotInsertableEntity.java | 12 +-
.../manytoone/NotInsertableEntityType.java | 36 +-
.../PropertyNotUpdatableEntity.java | 150 +-
.../PropertyNotUpdatableTest.java | 164 ++-
.../onetomany/BasicCollection.java | 212 +--
.../test/integration/onetomany/BasicList.java | 189 +--
.../test/integration/onetomany/BasicSet.java | 214 +--
.../onetomany/BasicSetWithEmbId.java | 198 +--
.../onetomany/BasicSetWithMulId.java | 198 +--
.../onetomany/BasicSetWithNullsDelete.java | 332 ++---
.../onetomany/BidirectionalMapKey.java | 100 +-
.../onetomany/InverseSideChanges.java | 88 +-
.../onetomany/RefEdMapKeyEntity.java | 81 +-
.../onetomany/RefIngMapKeyEntity.java | 85 +-
.../onetomany/detached/BasicDetachedList.java | 138 +-
.../onetomany/detached/BasicDetachedSet.java | 136 +-
.../detached/BasicDetachedSetWithEmbId.java | 139 +-
.../detached/BasicDetachedSetWithMulId.java | 139 +-
.../detached/BasicJoinColumnSet.java | 141 +-
.../detached/DataChangesDetachedSet.java | 96 +-
.../onetomany/detached/DetachedTest.java | 16 +-
.../onetomany/detached/DoubleDetachedSet.java | 133 +-
.../DoubleJoinColumnBidirectionalList.java | 597 +++++---
.../IndexedJoinColumnBidirectionalList.java | 469 ++++---
...nceIndexedJoinColumnBidirectionalList.java | 466 ++++---
.../detached/JoinColumnBidirectionalList.java | 377 +++--
...olumnBidirectionalListWithInheritance.java | 245 ++--
.../onetomany/embeddedid/Constant.java | 92 +-
.../onetomany/embeddedid/MapsIdTest.java | 215 +--
.../onetomany/embeddedid/Person.java | 134 +-
.../onetomany/embeddedid/PersonTuple.java | 260 ++--
.../onetomany/hierarchy/HierarchyTest.java | 149 +-
.../integration/onetomany/hierarchy/Node.java | 146 +-
.../inverseToSuperclass/DetailSubclass.java | 1 +
.../inverseToSuperclass/DetailSubclass2.java | 3 +-
.../inverseToSuperclass/DetailSuperclass.java | 1 +
.../onetomany/inverseToSuperclass/Master.java | 1 +
.../OneToManyInverseToSuperclassTest.java | 65 +-
.../onetoone/bidirectional/BiRefEdEntity.java | 109 +-
.../bidirectional/BiRefIngEntity.java | 109 +-
.../onetoone/bidirectional/Bidirectional.java | 112 +-
.../bidirectional/Bidirectional2.java | 166 +--
.../BidirectionalEagerAnnotationTest.java | 5 +-
.../BidirectionalEagerHbmTest.java | 7 +-
.../bidirectional/BidirectionalNoNulls.java | 134 +-
.../bidirectional/ids/BiEmbIdRefEdEntity.java | 109 +-
.../ids/BiEmbIdRefIngEntity.java | 109 +-
.../bidirectional/ids/BiMulIdRefEdEntity.java | 123 +-
.../ids/BiMulIdRefIngEntity.java | 123 +-
.../bidirectional/ids/EmbIdBidirectional.java | 126 +-
.../bidirectional/ids/MulIdBidirectional.java | 126 +-
.../primarykeyjoincolumn/Account.java | 122 +-
.../AccountNotAuditedOwners.java | 136 +-
.../NotAuditedNoProxyPerson.java | 122 +-
.../NotAuditedProxyPerson.java | 122 +-
.../OneToOneWithPrimaryKeyJoinTest.java | 214 +--
.../primarykeyjoincolumn/Person.java | 116 +-
.../unidirectional/UniRefEdEntity.java | 82 +-
.../unidirectional/UniRefIngEntity.java | 102 +-
.../unidirectional/UniRefIngMulIdEntity.java | 110 +-
.../unidirectional/Unidirectional.java | 166 +--
.../UnidirectionalMulIdWithNulls.java | 66 +-
.../UnidirectionalWithNulls.java | 140 +-
.../primitive/PrimitiveAddDelete.java | 86 +-
.../properties/PropertiesTestEntity.java | 89 +-
.../UnversionedOptimisticLockingField.java | 51 +-
...versionedOptimisticLockingFieldEntity.java | 87 +-
.../properties/VersionsProperties.java | 66 +-
.../proxy/AuditedCollectionProxyTest.java | 88 +-
.../integration/proxy/ProxyIdentifier.java | 72 +-
.../proxy/QueryingWithProxyObjectTest.java | 85 +-
.../proxy/RemovedObjectQueryTest.java | 29 +-
.../integration/query/AggregateQuery.java | 148 +-
.../query/CustomRevEntityQuery.java | 130 +-
.../integration/query/DeletedEntities.java | 92 +-
.../query/MaximalizePropertyQuery.java | 171 +--
.../integration/query/NullPropertyQuery.java | 140 +-
.../integration/query/OrderByLimitQuery.java | 176 +--
.../query/RevisionConstraintQuery.java | 282 ++--
.../test/integration/query/SimpleQuery.java | 494 ++++---
.../integration/query/StoreDeletedData.java | 22 +-
.../query/ids/EmbIdOneToManyQuery.java | 294 ++--
.../query/ids/MulIdOneToManyQuery.java | 280 ++--
.../ReadWriteExpressionChange.java | 81 +-
.../readwriteexpression/Staff.java | 34 +-
.../reference/BidirectionalReference.java | 148 +-
.../integration/reference/GreetingPO.java | 17 +-
.../integration/reference/GreetingSetPO.java | 19 +-
.../reventity/CountingRevisionListener.java | 10 +-
.../test/integration/reventity/Custom.java | 171 +--
.../integration/reventity/CustomBoxed.java | 171 +--
.../reventity/CustomBoxedRevEntity.java | 89 +-
.../reventity/CustomColumnMapping.java | 148 +-
.../integration/reventity/CustomDate.java | 151 +-
.../reventity/CustomNoListener.java | 126 +-
.../reventity/CustomPropertyAccess.java | 149 +-
.../reventity/DifferentDBSchemaTest.java | 103 +-
.../reventity/ExceptionListener.java | 39 +-
.../reventity/ExceptionListenerRevEntity.java | 86 +-
.../GloballyConfiguredRevListenerTest.java | 37 +-
.../test/integration/reventity/Inherited.java | 171 +--
.../test/integration/reventity/Listener.java | 183 +--
.../reventity/ListenerRevEntity.java | 100 +-
...LongRevEntityInheritanceChildAuditing.java | 31 +-
.../integration/reventity/LongRevNumber.java | 102 +-
.../reventity/LongRevNumberRevEntity.java | 88 +-
.../MonotonicRevisionNumberTest.java | 9 +-
.../OverrideCustomRevListenerTest.java | 3 +-
.../OverrideDefaultRevListenerTest.java | 3 +-
.../TestExceptionRevisionListener.java | 6 +-
.../reventity/TestRevisionListener.java | 9 +-
.../AnnotatedTrackingEntitiesTest.java | 5 +-
.../CustomTrackingEntitiesTest.java | 123 +-
.../DefaultTrackingEntitiesTest.java | 267 ++--
.../EntityNamesTest.java | 106 +-
.../ExtendedRevisionEntityTest.java | 29 +-
.../TrackingEntitiesMultipleChangesTest.java | 121 +-
.../revfordate/RevisionForDate.java | 128 +-
.../sameids/SameIdTestEntity1.java | 87 +-
.../sameids/SameIdTestEntity2.java | 87 +-
.../test/integration/sameids/SameIds.java | 83 +-
.../integration/secondary/BasicSecondary.java | 90 +-
.../secondary/NamingSecondary.java | 90 +-
.../secondary/SecondaryNamingTestEntity.java | 113 +-
.../secondary/SecondaryTestEntity.java | 113 +-
.../secondary/ids/EmbIdSecondary.java | 88 +-
.../secondary/ids/MulIdSecondary.java | 88 +-
.../ids/SecondaryEmbIdTestEntity.java | 111 +-
.../ids/SecondaryMulIdTestEntity.java | 135 +-
.../serialization/SerializingCollection.java | 74 +-
.../ValidityAuditStrategyManyToManyTest.java | 182 +--
...tyAuditStrategyRevEndTestCustomRevEnt.java | 482 ++++---
.../ValidityAuditStrategyRevEndTsTest.java | 493 ++++---
.../AuditedMethodMappedSuperclass.java | 13 +-
.../NotAuditedSubclassEntity.java | 21 +-
.../AuditedAllSubclassEntity.java | 81 +-
.../MappedSubclassingAllAuditedTest.java | 89 +-
.../AuditedMethodSubclassEntity.java | 83 +-
.../MappedSubclassingMethodAuditedTest.java | 88 +-
.../AuditedAllMappedSuperclass.java | 13 +-
.../NotAuditedSubclassEntity.java | 21 +-
.../AuditedAllSubclassEntity.java | 83 +-
.../MappedSubclassingAllAuditedTest.java | 89 +-
.../AuditedMethodSubclassEntity.java | 85 +-
.../MappedSubclassingMethodAuditedTest.java | 90 +-
.../auditoverride/AuditClassOverrideTest.java | 120 +-
.../AuditPropertyOverrideTest.java | 148 +-
.../auditoverride/AuditedBaseEntity.java | 118 +-
.../auditoverride/AuditedSpecialEntity.java | 82 +-
.../superclass/auditoverride/BaseEntity.java | 122 +-
.../ClassOverrideAuditedEntity.java | 82 +-
.../ClassOverrideNotAuditedEntity.java | 82 +-
.../auditoverride/ExtendedBaseEntity.java | 114 +-
.../auditoverride/MixedOverrideEntity.java | 86 +-
.../auditoverride/MixedOverrideTest.java | 71 +-
.../auditoverride/NotAuditedBaseEntity.java | 118 +-
.../auditoverride/PropertyOverrideEntity.java | 86 +-
.../TransitiveOverrideEntity.java | 92 +-
.../auditparents/BabyCompleteEntity.java | 73 +-
.../auditparents/ChildCompleteEntity.java | 74 +-
.../ChildMultipleParentsEntity.java | 74 +-
.../auditparents/ChildSingleParentEntity.java | 74 +-
.../ExplicitTransitiveChildEntity.java | 68 +-
.../ImplicitTransitiveChildEntity.java | 68 +-
.../auditparents/MappedGrandparentEntity.java | 102 +-
.../auditparents/MappedParentEntity.java | 85 +-
.../MultipleAuditParentsTest.java | 109 +-
.../auditparents/SingleAuditParentsTest.java | 114 +-
.../auditparents/TotalAuditParentsTest.java | 110 +-
.../TransitiveAuditParentsTest.java | 151 +-
.../auditparents/TransitiveParentEntity.java | 68 +-
.../integration/tools/SchemaExportTest.java | 70 +-
.../AbstractEntityManagerTest.java | 111 +-
.../performance/AbstractPerformanceTest.java | 107 +-
.../test/performance/AllPerformance.java | 9 +-
.../performance/ComplexInsertPerformance.java | 104 +-
.../EvictAuditDataAfterCommitTest.java | 149 +-
.../InsertsOneTransactionPerformance.java | 40 +-
.../test/performance/InsertsPerformance.java | 44 +-
.../test/performance/UpdatesPerformance.java | 74 +-
.../performance/complex/ChildEntity1.java | 119 +-
.../performance/complex/ChildEntity2.java | 105 +-
.../test/performance/complex/RootEntity.java | 199 +--
.../envers/test/tools/TestTools.java | 2 +-
.../envers/test/various/Address.java | 135 +-
.../envers/test/various/HsqlTest.java | 98 +-
.../hibernate/envers/test/various/Person.java | 111 +-
shared/config/checkstyle/checkstyle.xml | 1 +
867 files changed, 45715 insertions(+), 37131 deletions(-)
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/AuditJoinTable.java b/hibernate-envers/src/main/java/org/hibernate/envers/AuditJoinTable.java
index 894bcbc559..2a22d3a9f1 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/AuditJoinTable.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/AuditJoinTable.java
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2008, 2013, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -22,11 +22,12 @@
* Boston, MA 02110-1301 USA
*/
package org.hibernate.envers;
+
+import javax.persistence.JoinColumn;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-import javax.persistence.JoinColumn;
/**
* @author Adam Warski (adam at warski dot org)
@@ -34,25 +35,25 @@ import javax.persistence.JoinColumn;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.METHOD})
public @interface AuditJoinTable {
- /**
- * @return Name of the join table. Defaults to a concatenation of the names of the primary table of the entity
- * owning the association and of the primary table of the entity referenced by the association.
- */
- String name() default "";
+ /**
+ * Name of the join table. Defaults to a concatenation of the names of the primary table of the entity
+ * owning the association and of the primary table of the entity referenced by the association.
+ */
+ String name() default "";
- /**
- * @return The schema of the join table. Defaults to the schema of the entity owning the association.
- */
- String schema() default "";
+ /**
+ * The schema of the join table. Defaults to the schema of the entity owning the association.
+ */
+ String schema() default "";
- /**
- * @return The catalog of the join table. Defaults to the catalog of the entity owning the association.
- */
- String catalog() default "";
+ /**
+ * The catalog of the join table. Defaults to the catalog of the entity owning the association.
+ */
+ String catalog() default "";
- /**
- * @return The foreign key columns of the join table which reference the primary table of the entity that does not
- * own the association (i.e. the inverse side of the association).
- */
- JoinColumn[] inverseJoinColumns() default {};
+ /**
+ * The foreign key columns of the join table which reference the primary table of the entity that does not
+ * own the association (i.e. the inverse side of the association).
+ */
+ JoinColumn[] inverseJoinColumns() default {};
}
\ No newline at end of file
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/AuditMappedBy.java b/hibernate-envers/src/main/java/org/hibernate/envers/AuditMappedBy.java
index e5b1c4aeb4..8c86beea7e 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/AuditMappedBy.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/AuditMappedBy.java
@@ -1,4 +1,5 @@
package org.hibernate.envers;
+
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -11,7 +12,7 @@ import java.lang.annotation.Target;
* the many side. Then, Envers won't use a join table to audit this relation, but will store changes as in a normal
* bi-directional relation.
*
- *
+ *
*
* This annotation is experimental and may change in future releases.
*
@@ -21,16 +22,17 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.FIELD})
public @interface AuditMappedBy {
- /**
- * @return Name of the property in the related entity which maps back to this entity. The property should be
- * mapped with {@code @ManyToOne} and {@code @Column(insertable=false, updatable=false)}.
- */
- String mappedBy();
+ /**
+ * Name of the property in the related entity which maps back to this entity. The property should be
+ * mapped with {@code @ManyToOne} and {@code @Column(insertable=false, updatable=false)}.
+ */
+ String mappedBy();
- /**
- * @return Name of the property in the related entity which maps to the position column. Should be specified only
- * for indexed collection, when @{@link org.hibernate.annotations.IndexColumn} is used on the collection.
- * The property should be mapped with {@code @Column(insertable=false, updatable=false)}.
- */
- String positionMappedBy() default "";
+ /**
+ * Name of the property in the related entity which maps to the position column. Should be specified only
+ * for indexed collection, when @{@link org.hibernate.annotations.IndexColumn} or
+ * {@link javax.persistence.OrderColumn} is used on the collection. The property should be mapped with
+ * {@code @Column(insertable=false, updatable=false)}.
+ */
+ String positionMappedBy() default "";
}
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/AuditOverride.java b/hibernate-envers/src/main/java/org/hibernate/envers/AuditOverride.java
index 96dfea8dd1..0b5059fdad 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/AuditOverride.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/AuditOverride.java
@@ -1,7 +1,30 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2013, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
package org.hibernate.envers;
+
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
-import javax.persistence.MappedSuperclass;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
@@ -10,43 +33,44 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
* The {@code AuditingOverride} annotation is used to override the auditing
- * behavior of a superclass or single property inherited from {@link MappedSuperclass}
+ * behavior of a superclass or single property inherited from {@link javax.persistence.MappedSuperclass}
* type, or attribute inside an embedded component.
*
* @author Erik-Berndt Scheper
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
+ *
* @see javax.persistence.Embedded
* @see javax.persistence.Embeddable
- * @see javax.persistence.MappedSuperclass
+ * @see javax.persistence.MappedSuperclass
* @see javax.persistence.AssociationOverride
* @see AuditJoinTable
*/
-@Target({ TYPE, METHOD, FIELD })
+@Target({TYPE, METHOD, FIELD})
@Retention(RUNTIME)
public @interface AuditOverride {
/**
- * @return Name of the field (or property) whose mapping is being overridden. Allows empty value if
+ * Name of the field (or property) whose mapping is being overridden. Allows empty value if
* {@link AuditOverride} is used to change auditing behavior of all attributes inherited from
- * {@link MappedSuperclass} type.
+ * {@link javax.persistence.MappedSuperclass} type.
*/
String name() default "";
/**
- * @return Indicates if the field (or property) is audited; defaults to {@code true}.
+ * Indicates if the field (or property) is audited; defaults to {@code true}.
*/
boolean isAudited() default true;
/**
- * @return New {@link AuditJoinTable} used for this field (or property). Its value
+ * New {@link AuditJoinTable} used for this field (or property). Its value
* is ignored if {@link #isAudited()} equals to {@code false}.
*/
AuditJoinTable auditJoinTable() default @AuditJoinTable;
/**
- * @return Specifies class which field (or property) mapping is being overridden. Required if
- * {@link AuditOverride} is used to change auditing behavior of attributes inherited from {@link MappedSuperclass}
- * type.
+ * Specifies class which field (or property) mapping is being overridden. Required if
+ * {@link AuditOverride} is used to change auditing behavior of attributes inherited from
+ * {@link javax.persistence.MappedSuperclass} type.
*/
Class forClass() default void.class;
}
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/AuditOverrides.java b/hibernate-envers/src/main/java/org/hibernate/envers/AuditOverrides.java
index b4b4e095de..4f86cee9ae 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/AuditOverrides.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/AuditOverrides.java
@@ -1,4 +1,28 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2013, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
package org.hibernate.envers;
+
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
@@ -21,11 +45,11 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
* @see AuditJoinTable
* @see AuditOverride
*/
-@Target({ TYPE, METHOD, FIELD })
+@Target({TYPE, METHOD, FIELD})
@Retention(RUNTIME)
public @interface AuditOverrides {
/**
- * @return An array of {@link AuditOverride} values, to define the new auditing
+ * An array of {@link AuditOverride} values, to define the new auditing
* behavior.
*/
AuditOverride[] value();
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 498a8ff22d..1230339e2b 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/AuditReader.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/AuditReader.java
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2008, 2013, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -40,207 +40,241 @@ import org.hibernate.envers.query.AuditQueryCreator;
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
*/
public interface AuditReader {
- /**
- * Find an entity by primary key at the given revision.
- * @param cls Class of the entity.
- * @param primaryKey Primary key of the entity.
- * @param revision Revision in which to get the entity.
- * @return The found entity instance at the given revision (its properties may be partially filled
- * if not all properties are audited) or null, if an entity with that id didn't exist at that
- * revision.
- * @throws IllegalArgumentException If cls or primaryKey is null or revision is less or equal to 0.
- * @throws NotAuditedException When entities of the given class are not audited.
- * @throws IllegalStateException If the associated entity manager is closed.
- */
- T find(Class cls, Object primaryKey, Number revision) throws
- IllegalArgumentException, NotAuditedException, IllegalStateException;
-
- /**
- * Find an entity by primary key at the given revision with the specified entityName.
- * @param cls Class of the entity.
- * @param entityName Name of the entity (if can't be guessed basing on the {@code cls}).
- * @param primaryKey Primary key of the entity.
- * @param revision Revision in which to get the entity.
- * @return The found entity instance at the given revision (its properties may be partially filled
- * if not all properties are audited) or null, if an entity with that id didn't exist at that
- * revision.
- * @throws IllegalArgumentException If cls or primaryKey is null or revision is less or equal to 0.
- * @throws NotAuditedException When entities of the given class are not audited.
- * @throws IllegalStateException If the associated entity manager is closed.
- */
- T find(Class cls, String entityName, Object primaryKey,
+ /**
+ * Find an entity by primary key at the given revision.
+ *
+ * @param cls Class of the entity.
+ * @param primaryKey Primary key of the entity.
+ * @param revision Revision in which to get the entity.
+ * @param The type of the entity to find
+ *
+ * @return The found entity instance at the given revision (its properties may be partially filled
+ * if not all properties are audited) or null, if an entity with that id didn't exist at that
+ * revision.
+ *
+ * @throws IllegalArgumentException If cls or primaryKey is null or revision is less or equal to 0.
+ * @throws NotAuditedException When entities of the given class are not audited.
+ * @throws IllegalStateException If the associated entity manager is closed.
+ */
+ T find(Class cls, Object primaryKey, Number revision) throws
+ IllegalArgumentException, NotAuditedException, IllegalStateException;
+
+ /**
+ * Find an entity by primary key at the given revision with the specified entityName.
+ *
+ * @param cls Class of the entity.
+ * @param entityName Name of the entity (if can't be guessed basing on the {@code cls}).
+ * @param primaryKey Primary key of the entity.
+ * @param revision Revision in which to get the entity.
+ * @param The type of the entity to find
+ *
+ * @return The found entity instance at the given revision (its properties may be partially filled
+ * if not all properties are audited) or null, if an entity with that id didn't exist at that
+ * revision.
+ *
+ * @throws IllegalArgumentException If cls or primaryKey is null or revision is less or equal to 0.
+ * @throws NotAuditedException When entities of the given class are not audited.
+ * @throws IllegalStateException If the associated entity manager is closed.
+ */
+ T find(
+ Class cls, String entityName, Object primaryKey,
Number revision) throws IllegalArgumentException,
NotAuditedException, IllegalStateException;
- /**
- * Find an entity by primary key at the given revision with the specified entityName,
- * possibly including deleted entities in the search.
- * @param cls Class of the entity.
- * @param entityName Name of the entity (if can't be guessed basing on the {@code cls}).
- * @param primaryKey Primary key of the entity.
- * @param revision Revision in which to get the entity.
- * @param includeDeletions Whether to include deleted entities in the search.
- * @return The found entity instance at the given revision (its properties may be partially filled
- * if not all properties are audited) or null, if an entity with that id didn't exist at that
- * revision.
- * @throws IllegalArgumentException If cls or primaryKey is null or revision is less or equal to 0.
- * @throws NotAuditedException When entities of the given class are not audited.
- * @throws IllegalStateException If the associated entity manager is closed.
- */
- T find(Class cls, String entityName, Object primaryKey,
+ /**
+ * Find an entity by primary key at the given revision with the specified entityName,
+ * possibly including deleted entities in the search.
+ *
+ * @param cls Class of the entity.
+ * @param entityName Name of the entity (if can't be guessed basing on the {@code cls}).
+ * @param primaryKey Primary key of the entity.
+ * @param revision Revision in which to get the entity.
+ * @param includeDeletions Whether to include deleted entities in the search.
+ * @param The type of the entity to find
+ *
+ * @return The found entity instance at the given revision (its properties may be partially filled
+ * if not all properties are audited) or null, if an entity with that id didn't exist at that
+ * revision.
+ *
+ * @throws IllegalArgumentException If cls or primaryKey is null or revision is less or equal to 0.
+ * @throws NotAuditedException When entities of the given class are not audited.
+ * @throws IllegalStateException If the associated entity manager is closed.
+ */
+ T find(
+ Class cls, String entityName, Object primaryKey,
Number revision, boolean includeDeletions) throws IllegalArgumentException,
NotAuditedException, IllegalStateException;
-
- /**
- * Get a list of revision numbers, at which an entity was modified.
- * @param cls Class of the entity.
- * @param primaryKey Primary key of the entity.
- * @return A list of revision numbers, at which the entity was modified, sorted in ascending order (so older
- * revisions come first).
- * @throws NotAuditedException When entities of the given class are not audited.
- * @throws IllegalArgumentException If cls or primaryKey is null.
- * @throws IllegalStateException If the associated entity manager is closed.
- */
- List getRevisions(Class> cls, Object primaryKey)
- throws IllegalArgumentException, NotAuditedException, IllegalStateException;
-
- /**
- * Get a list of revision numbers, at which an entity was modified, looking by entityName.
- * @param cls Class of the entity.
- * @param entityName Name of the entity (if can't be guessed basing on the {@code cls}).
- * @param primaryKey Primary key of the entity.
- * @return A list of revision numbers, at which the entity was modified, sorted in ascending order (so older
- * revisions come first).
- * @throws NotAuditedException When entities of the given class are not audited.
- * @throws IllegalArgumentException If cls or primaryKey is null.
- * @throws IllegalStateException If the associated entity manager is closed.
- */
- List getRevisions(Class> cls, String entityName, Object primaryKey)
+
+ /**
+ * Get a list of revision numbers, at which an entity was modified.
+ *
+ * @param cls Class of the entity.
+ * @param primaryKey Primary key of the entity.
+ *
+ * @return A list of revision numbers, at which the entity was modified, sorted in ascending order (so older
+ * revisions come first).
+ *
+ * @throws NotAuditedException When entities of the given class are not audited.
+ * @throws IllegalArgumentException If cls or primaryKey is null.
+ * @throws IllegalStateException If the associated entity manager is closed.
+ */
+ List getRevisions(Class> cls, Object primaryKey)
+ throws IllegalArgumentException, NotAuditedException, IllegalStateException;
+
+ /**
+ * Get a list of revision numbers, at which an entity was modified, looking by entityName.
+ *
+ * @param cls Class of the entity.
+ * @param entityName Name of the entity (if can't be guessed basing on the {@code cls}).
+ * @param primaryKey Primary key of the entity.
+ *
+ * @return A list of revision numbers, at which the entity was modified, sorted in ascending order (so older
+ * revisions come first).
+ *
+ * @throws NotAuditedException When entities of the given class are not audited.
+ * @throws IllegalArgumentException If cls or primaryKey is null.
+ * @throws IllegalStateException If the associated entity manager is closed.
+ */
+ List getRevisions(Class> cls, String entityName, Object primaryKey)
throws IllegalArgumentException, NotAuditedException,
IllegalStateException;
- /**
- * Get the date, at which a revision was created.
- * @param revision Number of the revision for which to get the date.
- * @return Date of commiting the given revision.
- * @throws IllegalArgumentException If revision is less or equal to 0.
- * @throws RevisionDoesNotExistException If the revision does not exist.
- * @throws IllegalStateException If the associated entity manager is closed.
- */
- Date getRevisionDate(Number revision) throws IllegalArgumentException, RevisionDoesNotExistException,
- IllegalStateException;
-
- /**
- * Gets the revision number, that corresponds to the given date. More precisely, returns
- * the number of the highest revision, which was created on or before the given date. So:
- * getRevisionDate(getRevisionNumberForDate(date)) <= date
and
- * getRevisionDate(getRevisionNumberForDate(date)+1) > date
.
- * @param date Date for which to get the revision.
- * @return Revision number corresponding to the given date.
- * @throws IllegalStateException If the associated entity manager is closed.
- * @throws RevisionDoesNotExistException If the given date is before the first revision.
- * @throws IllegalArgumentException If date
is null
.
- */
- Number getRevisionNumberForDate(Date date) throws IllegalStateException, RevisionDoesNotExistException,
- IllegalArgumentException;
-
- /**
- * A helper method; should be used only if a custom revision entity is used. See also {@link RevisionEntity}.
- * @param revisionEntityClass Class of the revision entity. Should be annotated with {@link RevisionEntity}.
- * @param revision Number of the revision for which to get the data.
- * @return Entity containing data for the given revision.
- * @throws IllegalArgumentException If revision is less or equal to 0 or if the class of the revision entity
- * is invalid.
- * @throws RevisionDoesNotExistException If the revision does not exist.
- * @throws IllegalStateException If the associated entity manager is closed.
- */
- T findRevision(Class revisionEntityClass, Number revision) throws IllegalArgumentException,
- RevisionDoesNotExistException, IllegalStateException;
-
- /**
- * Find a map of revisions using the revision numbers specified.
- *
- * @param revisionEntityClass
- * Class of the revision entity. Should be annotated with
- * {@link RevisionEntity}.
- * @param revisions
- * Revision numbers of the revision for which to get the data.
- * @return A map of revision number and the given revision entity.
- * @throws IllegalArgumentException
- * If a revision number is less or equal to 0 or if the class of
- * the revision entity is invalid.
- * @throws IllegalStateException
- * If the associated entity manager is closed.
+ /**
+ * Get the date, at which a revision was created.
+ *
+ * @param revision Number of the revision for which to get the date.
+ *
+ * @return Date of commiting the given revision.
+ *
+ * @throws IllegalArgumentException If revision is less or equal to 0.
+ * @throws RevisionDoesNotExistException If the revision does not exist.
+ * @throws IllegalStateException If the associated entity manager is closed.
*/
- Map findRevisions(Class revisionEntityClass,
+ Date getRevisionDate(Number revision) throws IllegalArgumentException, RevisionDoesNotExistException,
+ IllegalStateException;
+
+ /**
+ * Gets the revision number, that corresponds to the given date. More precisely, returns
+ * the number of the highest revision, which was created on or before the given date. So:
+ * getRevisionDate(getRevisionNumberForDate(date)) <= date
and
+ * getRevisionDate(getRevisionNumberForDate(date)+1) > date
.
+ *
+ * @param date Date for which to get the revision.
+ *
+ * @return Revision number corresponding to the given date.
+ *
+ * @throws IllegalStateException If the associated entity manager is closed.
+ * @throws RevisionDoesNotExistException If the given date is before the first revision.
+ * @throws IllegalArgumentException If date
is null
.
+ */
+ Number getRevisionNumberForDate(Date date) throws IllegalStateException, RevisionDoesNotExistException,
+ IllegalArgumentException;
+
+ /**
+ * A helper method; should be used only if a custom revision entity is used. See also {@link RevisionEntity}.
+ *
+ * @param revisionEntityClass Class of the revision entity. Should be annotated with {@link RevisionEntity}.
+ * @param revision Number of the revision for which to get the data.
+ * @param The type of the revision entity to find
+ *
+ * @return Entity containing data for the given revision.
+ *
+ * @throws IllegalArgumentException If revision is less or equal to 0 or if the class of the revision entity
+ * is invalid.
+ * @throws RevisionDoesNotExistException If the revision does not exist.
+ * @throws IllegalStateException If the associated entity manager is closed.
+ */
+ T findRevision(Class revisionEntityClass, Number revision) throws IllegalArgumentException,
+ RevisionDoesNotExistException, IllegalStateException;
+
+ /**
+ * Find a map of revisions using the revision numbers specified.
+ *
+ * @param revisionEntityClass Class of the revision entity. Should be annotated with
+ * {@link RevisionEntity}.
+ * @param revisions Revision numbers of the revision for which to get the data.
+ * @param The type of the revision entity to find
+ *
+ * @return A map of revision number and the given revision entity.
+ *
+ * @throws IllegalArgumentException If a revision number is less or equal to 0 or if the class of
+ * the revision entity is invalid.
+ * @throws IllegalStateException If the associated entity manager is closed.
+ */
+ Map findRevisions(
+ Class revisionEntityClass,
Set revisions) throws IllegalArgumentException,
IllegalStateException;
-
+
/**
* Gets an instance of the current revision entity, to which any entries in the audit tables will be bound.
* Please note the if {@code persist} is {@code false}, and no audited entities are modified in this session,
* then the obtained revision entity instance won't be persisted. If {@code persist} is {@code true}, the revision
* entity instance will always be persisted, regardless of whether audited entities are changed or not.
+ *
* @param revisionEntityClass Class of the revision entity. Should be annotated with {@link RevisionEntity}.
* @param persist If the revision entity is not yet persisted, should it become persisted. This way, the primary
* identifier (id) will be filled (if it's assigned by the DB) and available, but the revision entity will be
* persisted even if there are no changes to audited entities. Otherwise, the revision number (id) can be
* {@code null}.
+ * @param The type of the revision entity to find
+ *
* @return The current revision entity, to which any entries in the audit tables will be bound.
*/
T getCurrentRevision(Class revisionEntityClass, boolean persist);
- /**
- *
- * @return A query creator, associated with this AuditReader instance, with which queries can be
- * created and later executed. Shouldn't be used after the associated Session or EntityManager
- * is closed.
- */
- AuditQueryCreator createQuery();
+ /**
+ * Creates an audit query
+ *
+ * @return A query creator, associated with this AuditReader instance, with which queries can be
+ * created and later executed. Shouldn't be used after the associated Session or EntityManager
+ * is closed.
+ */
+ AuditQueryCreator createQuery();
- /**
+ /**
* Checks if the entityClass was configured to be audited. Calling
* isEntityNameAudited() with the string of the class name will return the
* same value.
- *
- * @param entityClass
- * Class of the entity asking for audit support
- * @return true if the entityClass is audited.
- */
- boolean isEntityClassAudited(Class> entityClass);
-
+ *
+ * @param entityClass Class of the entity asking for audit support
+ *
+ * @return true if the entityClass is audited.
+ */
+ boolean isEntityClassAudited(Class> entityClass);
+
/**
* Checks if the entityName was configured to be audited.
- *
+ *
* @param entityName EntityName of the entity asking for audit support.
+ *
* @return true if the entityName is audited.
*/
- boolean isEntityNameAudited(String entityName);
+ boolean isEntityNameAudited(String entityName);
/**
- *
- * @param entity
- * that was obtained previously from the same AuditReader.
- *
+ * @param entity that was obtained previously from the same AuditReader.
+ *
* @return the entityName for the given entity, null in case the entity is
* not associated with this AuditReader instance.
*/
String getEntityName(Object primaryKey, Number revision, Object entity)
throws HibernateException;
- /**
- * @return Basic implementation of {@link CrossTypeRevisionChangesReader} interface. Raises an exception if the default
- * mechanism of tracking entity names modified during revisions has not been enabled.
- * @throws AuditException If none of the following conditions is satisfied:
- *
- * org.hibernate.envers.track_entities_changed_in_revision
- * parameter is set to true
.
- * Custom revision entity (annotated with {@link RevisionEntity})
- * extends {@link DefaultTrackingModifiedEntitiesRevisionEntity} base class.
- * Custom revision entity (annotated with {@link RevisionEntity}) encapsulates a field
- * marked with {@link ModifiedEntityNames} interface.
- *
- */
- public CrossTypeRevisionChangesReader getCrossTypeRevisionChangesReader() throws AuditException;
+ /**
+ * @return Basic implementation of {@link CrossTypeRevisionChangesReader} interface. Raises an exception if the default
+ * mechanism of tracking entity names modified during revisions has not been enabled.
+ *
+ * @throws AuditException If none of the following conditions is satisfied:
+ *
+ * org.hibernate.envers.track_entities_changed_in_revision
+ * parameter is set to true
.
+ * Custom revision entity (annotated with {@link RevisionEntity})
+ * extends {@link DefaultTrackingModifiedEntitiesRevisionEntity} base class.
+ * Custom revision entity (annotated with {@link RevisionEntity}) encapsulates a field
+ * marked with {@link ModifiedEntityNames} interface.
+ *
+ */
+ public CrossTypeRevisionChangesReader getCrossTypeRevisionChangesReader() throws AuditException;
}
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/AuditReaderFactory.java b/hibernate-envers/src/main/java/org/hibernate/envers/AuditReaderFactory.java
index 74302e7fb9..c19facf355 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/AuditReaderFactory.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/AuditReaderFactory.java
@@ -38,20 +38,25 @@ import org.hibernate.event.spi.PostInsertEventListener;
* @author Adam Warski (adam at warski dot org)
*/
public class AuditReaderFactory {
- private AuditReaderFactory() { }
+ private AuditReaderFactory() {
+ }
- /**
- * Create an audit reader associated with an open session.
- * @param session An open session.
- * @return An audit reader associated with the given sesison. It shouldn't be used
- * after the session is closed.
- * @throws AuditException When the given required listeners aren't installed.
- */
- public static AuditReader get(Session session) throws AuditException {
- SessionImplementor sessionImpl;
- if (!(session instanceof SessionImplementor)) {
+ /**
+ * Create an audit reader associated with an open session.
+ *
+ * @param session An open session.
+ *
+ * @return An audit reader associated with the given sesison. It shouldn't be used
+ * after the session is closed.
+ *
+ * @throws AuditException When the given required listeners aren't installed.
+ */
+ public static AuditReader get(Session session) throws AuditException {
+ SessionImplementor sessionImpl;
+ if ( !(session instanceof SessionImplementor) ) {
sessionImpl = (SessionImplementor) session.getSessionFactory().getCurrentSession();
- } else {
+ }
+ else {
sessionImpl = (SessionImplementor) session;
}
@@ -61,37 +66,41 @@ public class AuditReaderFactory {
.getServiceRegistry()
.getService( EventListenerRegistry.class );
- for ( PostInsertEventListener listener : listenerRegistry.getEventListenerGroup( EventType.POST_INSERT ).listeners() ) {
+ for ( PostInsertEventListener listener : listenerRegistry.getEventListenerGroup( EventType.POST_INSERT )
+ .listeners() ) {
if ( listener instanceof EnversListener ) {
// todo : slightly different from original code in that I am not checking the other listener groups...
return new AuditReaderImpl(
- ( (EnversListener) listener ).getAuditConfiguration(),
+ ((EnversListener) listener).getAuditConfiguration(),
session,
sessionImpl
);
}
}
- throw new AuditException( "Envers listeners were not properly registered" );
- }
+ throw new AuditException( "Envers listeners were not properly registered" );
+ }
- /**
- * Create an audit reader associated with an open entity manager.
- * @param entityManager An open entity manager.
- * @return An audit reader associated with the given entity manager. It shouldn't be used
- * after the entity manager is closed.
- * @throws AuditException When the given entity manager is not based on Hibernate, or if the required
- * listeners aren't installed.
- */
- public static AuditReader get(EntityManager entityManager) throws AuditException {
- if (entityManager.getDelegate() instanceof Session) {
- return get((Session) entityManager.getDelegate());
- }
+ /**
+ * Create an audit reader associated with an open entity manager.
+ *
+ * @param entityManager An open entity manager.
+ *
+ * @return An audit reader associated with the given entity manager. It shouldn't be used
+ * after the entity manager is closed.
+ *
+ * @throws AuditException When the given entity manager is not based on Hibernate, or if the required
+ * listeners aren't installed.
+ */
+ public static AuditReader get(EntityManager entityManager) throws AuditException {
+ if ( entityManager.getDelegate() instanceof Session ) {
+ return get( (Session) entityManager.getDelegate() );
+ }
- if (entityManager.getDelegate() instanceof EntityManager) {
- return get((EntityManager) entityManager.getDelegate());
- }
+ if ( entityManager.getDelegate() instanceof EntityManager ) {
+ return get( (EntityManager) entityManager.getDelegate() );
+ }
- throw new AuditException("Hibernate EntityManager not present!");
- }
+ throw new AuditException( "Hibernate EntityManager not present!" );
+ }
}
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/AuditTable.java b/hibernate-envers/src/main/java/org/hibernate/envers/AuditTable.java
index dfeaed32cc..d4e5b91c23 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/AuditTable.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/AuditTable.java
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2008, 2013, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -22,6 +22,7 @@
* Boston, MA 02110-1301 USA
*/
package org.hibernate.envers;
+
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -33,15 +34,18 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface AuditTable {
- String value();
+ /**
+ * The name of the table
+ */
+ String value();
- /**
- * @return The schema of the table. Defaults to the schema of the annotated entity.
- */
- String schema() default "";
+ /**
+ * The schema of the table. Defaults to the schema of the annotated entity.
+ */
+ String schema() default "";
- /**
- * @return The catalog of the table. Defaults to the catalog of the annotated entity.
- */
- String catalog() default "";
+ /**
+ * The catalog of the table. Defaults to the catalog of the annotated entity.
+ */
+ String catalog() default "";
}
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/Audited.java b/hibernate-envers/src/main/java/org/hibernate/envers/Audited.java
index f37e768677..5afb0f5905 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/Audited.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/Audited.java
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2008, 2013, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -22,6 +22,7 @@
* Boston, MA 02110-1301 USA
*/
package org.hibernate.envers;
+
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -30,6 +31,7 @@ import java.lang.annotation.Target;
/**
* When applied to a class, indicates that all of its properties should be audited.
* When applied to a field, indicates that this field should be audited.
+ *
* @author Adam Warski (adam at warski dot org)
* @author Tomasz Bech
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
@@ -38,33 +40,37 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD})
public @interface Audited {
- ModificationStore modStore() default ModificationStore.FULL;
+ /**
+ * Specifies modification store to use
+ */
+ ModificationStore modStore() default ModificationStore.FULL;
/**
- * @return Specifies if the entity that is the target of the relation should be audited or not. If not, then when
+ * Specifies if the entity that is the target of the relation should be audited or not. If not, then when
* reading a historic version an audited entity, the relation will always point to the "current" entity.
* This is useful for dictionary-like entities, which don't change and don't need to be audited.
*/
- RelationTargetAuditMode targetAuditMode() default RelationTargetAuditMode.AUDITED;
+ RelationTargetAuditMode targetAuditMode() default RelationTargetAuditMode.AUDITED;
- /**
- * @return Specifies the superclasses for which properties should be audited, even if the superclasses are not
- * annotated with {@link Audited}. Causes all properties of the listed classes to be audited, just as if the
- * classes had {@link Audited} annotation applied on the class level.
- *
- * The scope of this functionality is limited to the class hierarchy of the annotated entity.
- *
- * If a parent type lists any of its parent types using this attribute, all properties in the specified classes
- * will also be audited.
- *
- * @deprecated Use {@code @AuditOverride(forClass=SomeEntity.class)} instead.
- */
- Class[] auditParents() default {};
+ /**
+ * Specifies the superclasses for which properties should be audited, even if the superclasses are not
+ * annotated with {@link Audited}. Causes all properties of the listed classes to be audited, just as if the
+ * classes had {@link Audited} annotation applied on the class level.
+ *
+ * The scope of this functionality is limited to the class hierarchy of the annotated entity.
+ *
+ * If a parent type lists any of its parent types using this attribute, all properties in the specified classes
+ * will also be audited.
+ *
+ * @deprecated Use {@code @AuditOverride(forClass=SomeEntity.class)} instead.
+ */
+ @Deprecated
+ Class[] auditParents() default {};
- /**
- * @return Should a modification flag be stored for each property in the annotated class or for the annotated
- * property. The flag stores information if a property has been changed at a given revision.
- * This can be used for example in queries.
- */
+ /**
+ * Should a modification flag be stored for each property in the annotated class or for the annotated
+ * property. The flag stores information if a property has been changed at a given revision.
+ * This can be used for example in queries.
+ */
boolean withModifiedFlag() default false;
}
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 f488ae0e36..d7675cb7e6 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/CrossTypeRevisionChangesReader.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/CrossTypeRevisionChangesReader.java
@@ -1,3 +1,26 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2013, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
package org.hibernate.envers;
import java.util.List;
@@ -10,52 +33,67 @@ import org.hibernate.envers.tools.Pair;
* Queries that allow retrieving snapshots of all entities (regardless of their particular type) changed in the given
* revision. Note that this API can be legally used only when default mechanism of tracking modified entity names
* is enabled.
+ *
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
*/
public interface CrossTypeRevisionChangesReader {
- /**
- * Find all entities changed (added, updated and removed) in a given revision. Executes n+1 SQL queries,
- * where n is a number of different entity classes modified within specified revision.
- * @param revision Revision number.
- * @return Snapshots of all audited entities changed in a given revision.
- * @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;
+ /**
+ * Find all entities changed (added, updated and removed) in a given revision. Executes n+1 SQL queries,
+ * where n is a number of different entity classes modified within specified revision.
+ *
+ * @param revision Revision number.
+ *
+ * @return Snapshots of all audited entities changed in a given revision.
+ *
+ * @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;
- /**
- * Find all entities changed (added, updated or removed) in a given revision. Executes n+1 SQL queries,
- * where n is a number of different entity classes modified within specified revision.
- * @param revision Revision number.
- * @param revisionType Type of modification.
- * @return Snapshots of all audited entities changed in a given revision and filtered by modification type.
- * @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,
- IllegalArgumentException;
+ /**
+ * Find all entities changed (added, updated or removed) in a given revision. Executes n+1 SQL queries,
+ * where n is a number of different entity classes modified within specified revision.
+ *
+ * @param revision Revision number.
+ * @param revisionType Type of modification.
+ *
+ * @return Snapshots of all audited entities changed in a given revision and filtered by modification type.
+ *
+ * @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,
+ IllegalArgumentException;
- /**
- * Find all entities changed (added, updated and removed) in a given revision grouped by modification type.
- * Executes mn+1 SQL queries, where:
- *
- * n - number of different entity classes modified within specified revision.
- * m - number of different revision types. See {@link RevisionType} enum.
- *
- * @param revision Revision number.
- * @return Map containing lists of entity snapshots grouped by modification operation (e.g. addition, update, removal).
- * @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) throws IllegalStateException,
- IllegalArgumentException;
+ /**
+ * Find all entities changed (added, updated and removed) in a given revision grouped by modification type.
+ * Executes mn+1 SQL queries, where:
+ *
+ * n - number of different entity classes modified within specified revision.
+ * m - number of different revision types. See {@link RevisionType} enum.
+ *
+ *
+ * @param revision Revision number.
+ *
+ * @return Map containing lists of entity snapshots grouped by modification operation (e.g. addition, update, removal).
+ *
+ * @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)
+ throws IllegalStateException,
+ IllegalArgumentException;
- /**
- * Returns set of entity names and corresponding Java classes modified in a given revision.
- * @param revision Revision number.
- * @return Set of entity names and corresponding Java classes modified in a given revision.
- * @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) throws IllegalStateException, IllegalArgumentException;
+ /**
+ * Returns set of entity names and corresponding Java classes modified in a given revision.
+ *
+ * @param revision Revision number.
+ *
+ * @return Set of entity names and corresponding Java classes modified in a given revision.
+ *
+ * @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)
+ throws IllegalStateException, IllegalArgumentException;
}
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/DefaultRevisionEntity.java b/hibernate-envers/src/main/java/org/hibernate/envers/DefaultRevisionEntity.java
index 13d32a2629..539144bdd0 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/DefaultRevisionEntity.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/DefaultRevisionEntity.java
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2008, 2013, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -22,13 +22,14 @@
* Boston, MA 02110-1301 USA
*/
package org.hibernate.envers;
-import java.io.Serializable;
-import java.text.DateFormat;
-import java.util.Date;
+
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;
+import java.io.Serializable;
+import java.text.DateFormat;
+import java.util.Date;
/**
* @author Adam Warski (adam at warski dot org)
@@ -36,56 +37,61 @@ import javax.persistence.Transient;
@MappedSuperclass
public class DefaultRevisionEntity implements Serializable {
private static final long serialVersionUID = 8530213963961662300L;
-
- @Id
- @GeneratedValue
- @RevisionNumber
- private int id;
- @RevisionTimestamp
- private long timestamp;
+ @Id
+ @GeneratedValue
+ @RevisionNumber
+ private int id;
- public int getId() {
- return id;
- }
+ @RevisionTimestamp
+ private long timestamp;
- public void setId(int id) {
- this.id = id;
- }
+ public int getId() {
+ return id;
+ }
- @Transient
- public Date getRevisionDate() {
- return new Date(timestamp);
- }
+ public void setId(int id) {
+ this.id = id;
+ }
- public long getTimestamp() {
- return timestamp;
- }
+ @Transient
+ public Date getRevisionDate() {
+ return new Date( timestamp );
+ }
- public void setTimestamp(long timestamp) {
- this.timestamp = timestamp;
- }
+ public long getTimestamp() {
+ return timestamp;
+ }
- public boolean equals(Object o) {
- if (this == o) return true;
- if (!(o instanceof DefaultRevisionEntity)) return false;
+ public void setTimestamp(long timestamp) {
+ this.timestamp = timestamp;
+ }
- DefaultRevisionEntity that = (DefaultRevisionEntity) o;
+ @Override
+ public boolean equals(Object o) {
+ if ( this == o ) {
+ return true;
+ }
+ if ( !(o instanceof DefaultRevisionEntity) ) {
+ return false;
+ }
- if (id != that.id) return false;
- if (timestamp != that.timestamp) return false;
+ final DefaultRevisionEntity that = (DefaultRevisionEntity) o;
+ return id == that.id
+ && timestamp == that.timestamp;
+ }
- return true;
- }
+ @Override
+ public int hashCode() {
+ int result;
+ result = id;
+ result = 31 * result + (int) (timestamp ^ (timestamp >>> 32));
+ return result;
+ }
- public int hashCode() {
- int result;
- result = id;
- result = 31 * result + (int) (timestamp ^ (timestamp >>> 32));
- return result;
- }
-
- public String toString() {
- return "DefaultRevisionEntity(id = " + id + ", revisionDate = " + DateFormat.getDateTimeInstance().format(getRevisionDate()) + ")";
- }
+ @Override
+ public String toString() {
+ return "DefaultRevisionEntity(id = " + id
+ + ", revisionDate = " + DateFormat.getDateTimeInstance().format( getRevisionDate() ) + ")";
+ }
}
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 ca4969ff9c..b6ee60687e 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/DefaultTrackingModifiedEntitiesRevisionEntity.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/DefaultTrackingModifiedEntitiesRevisionEntity.java
@@ -1,13 +1,36 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2013, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
package org.hibernate.envers;
-import java.util.HashSet;
-import java.util.Set;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.MappedSuperclass;
+import java.util.HashSet;
+import java.util.Set;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
@@ -16,45 +39,57 @@ import org.hibernate.annotations.FetchMode;
* Extension of standard {@link DefaultRevisionEntity} that allows tracking entity names changed in each revision.
* This revision entity is implicitly used when {@code org.hibernate.envers.track_entities_changed_in_revision}
* parameter is set to {@code true}.
+ *
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
*/
@MappedSuperclass
public class DefaultTrackingModifiedEntitiesRevisionEntity extends DefaultRevisionEntity {
- @ElementCollection(fetch = FetchType.EAGER)
- @JoinTable(name = "REVCHANGES", joinColumns = @JoinColumn(name = "REV"))
- @Column(name = "ENTITYNAME")
- @Fetch(FetchMode.JOIN)
- @ModifiedEntityNames
- private Set modifiedEntityNames = new HashSet();
+ @ElementCollection(fetch = FetchType.EAGER)
+ @JoinTable(name = "REVCHANGES", joinColumns = @JoinColumn(name = "REV"))
+ @Column(name = "ENTITYNAME")
+ @Fetch(FetchMode.JOIN)
+ @ModifiedEntityNames
+ private Set modifiedEntityNames = new HashSet();
- public Set getModifiedEntityNames() {
- return modifiedEntityNames;
- }
+ public Set getModifiedEntityNames() {
+ return modifiedEntityNames;
+ }
- public void setModifiedEntityNames(Set modifiedEntityNames) {
- this.modifiedEntityNames = modifiedEntityNames;
- }
+ public void setModifiedEntityNames(Set modifiedEntityNames) {
+ this.modifiedEntityNames = modifiedEntityNames;
+ }
- public boolean equals(Object o) {
- if (this == o) return true;
- if (!(o instanceof DefaultTrackingModifiedEntitiesRevisionEntity)) return false;
- if (!super.equals(o)) return false;
+ @Override
+ public boolean equals(Object o) {
+ if ( this == o ) {
+ return true;
+ }
+ if ( !(o instanceof DefaultTrackingModifiedEntitiesRevisionEntity) ) {
+ return false;
+ }
+ if ( !super.equals( o ) ) {
+ return false;
+ }
- DefaultTrackingModifiedEntitiesRevisionEntity that = (DefaultTrackingModifiedEntitiesRevisionEntity) o;
+ final DefaultTrackingModifiedEntitiesRevisionEntity that = (DefaultTrackingModifiedEntitiesRevisionEntity) o;
- if (modifiedEntityNames != null ? !modifiedEntityNames.equals(that.modifiedEntityNames)
- : that.modifiedEntityNames != null) return false;
+ if ( modifiedEntityNames != null ? !modifiedEntityNames.equals( that.modifiedEntityNames )
+ : that.modifiedEntityNames != null ) {
+ return false;
+ }
- return true;
- }
+ return true;
+ }
- public int hashCode() {
- int result = super.hashCode();
- result = 31 * result + (modifiedEntityNames != null ? modifiedEntityNames.hashCode() : 0);
- return result;
- }
+ @Override
+ public int hashCode() {
+ int result = super.hashCode();
+ result = 31 * result + (modifiedEntityNames != null ? modifiedEntityNames.hashCode() : 0);
+ return result;
+ }
- public String toString() {
- return "DefaultTrackingModifiedEntitiesRevisionEntity(" + super.toString() + ", modifiedEntityNames = " + modifiedEntityNames + ")";
- }
+ @Override
+ public String toString() {
+ return "DefaultTrackingModifiedEntitiesRevisionEntity(" + super.toString() + ", modifiedEntityNames = " + modifiedEntityNames + ")";
+ }
}
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/EntityTrackingRevisionListener.java b/hibernate-envers/src/main/java/org/hibernate/envers/EntityTrackingRevisionListener.java
index 0366b7f183..6fb9139249 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/EntityTrackingRevisionListener.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/EntityTrackingRevisionListener.java
@@ -1,3 +1,26 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2013, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
package org.hibernate.envers;
import java.io.Serializable;
@@ -5,19 +28,22 @@ import java.io.Serializable;
/**
* Extension of standard {@link RevisionListener} that notifies whenever an entity instance has been
* added, modified or removed within current revision boundaries.
- * @see RevisionListener
+ *
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
+ * @see RevisionListener
*/
public interface EntityTrackingRevisionListener extends RevisionListener {
- /**
- * Called after audited entity data has been persisted.
- * @param entityClass Audited entity class.
- * @param entityName Name of the audited entity. May be useful when Java class is mapped multiple times,
- * potentially to different tables.
- * @param entityId Identifier of modified entity.
- * @param revisionType Modification type (addition, update or removal).
- * @param revisionEntity An instance of the entity annotated with {@link RevisionEntity}.
- */
- void entityChanged(Class entityClass, String entityName, Serializable entityId, RevisionType revisionType,
- Object revisionEntity);
+ /**
+ * Called after audited entity data has been persisted.
+ *
+ * @param entityClass Audited entity class.
+ * @param entityName Name of the audited entity. May be useful when Java class is mapped multiple times,
+ * potentially to different tables.
+ * @param entityId Identifier of modified entity.
+ * @param revisionType Modification type (addition, update or removal).
+ * @param revisionEntity An instance of the entity annotated with {@link RevisionEntity}.
+ */
+ void entityChanged(
+ Class entityClass, String entityName, Serializable entityId, RevisionType revisionType,
+ Object revisionEntity);
}
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/ModificationStore.java b/hibernate-envers/src/main/java/org/hibernate/envers/ModificationStore.java
index dfc471068b..802dab8181 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/ModificationStore.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/ModificationStore.java
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2008, 2013, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -28,5 +28,5 @@ package org.hibernate.envers;
* @author Adam Warski (adam at warski dot org)
*/
public enum ModificationStore {
- FULL
+ FULL
}
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/ModifiedEntityNames.java b/hibernate-envers/src/main/java/org/hibernate/envers/ModifiedEntityNames.java
index 1bd81775dd..cf02555434 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/ModifiedEntityNames.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/ModifiedEntityNames.java
@@ -1,3 +1,26 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2013, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
package org.hibernate.envers;
import java.lang.annotation.ElementType;
@@ -8,6 +31,7 @@ import java.lang.annotation.Target;
/**
* Marks a property which holds entity names that have been modified during each revision.
* This annotation expects field of {@literal Set}
type.
+ *
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
*/
@Retention(RetentionPolicy.RUNTIME)
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/NotAudited.java b/hibernate-envers/src/main/java/org/hibernate/envers/NotAudited.java
index 4281014749..385589a478 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/NotAudited.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/NotAudited.java
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2008, 2013, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -22,6 +22,7 @@
* Boston, MA 02110-1301 USA
*/
package org.hibernate.envers;
+
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -29,6 +30,7 @@ import java.lang.annotation.Target;
/**
* When applied to a field, indicates that this field should not be audited.
+ *
* @author Sebastian Komander
*/
@Retention(RetentionPolicy.RUNTIME)
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/RelationTargetAuditMode.java b/hibernate-envers/src/main/java/org/hibernate/envers/RelationTargetAuditMode.java
index 1725a5e946..8b0e4d6808 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/RelationTargetAuditMode.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/RelationTargetAuditMode.java
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2008, 2013, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/RevisionEntity.java b/hibernate-envers/src/main/java/org/hibernate/envers/RevisionEntity.java
index 37328ff5b9..e8882a141e 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/RevisionEntity.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/RevisionEntity.java
@@ -34,15 +34,15 @@ import java.lang.annotation.Target;
* and a long-valued property annotated with {@link RevisionTimestamp}. The {@link DefaultRevisionEntity}
* already has those two fields, so you may extend it, but you may also write your own revision entity
* from scratch.
- *
+ *
* @author Adam Warski (adam at warski dot org)
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface RevisionEntity {
- /**
- * @return The optional listener that will be used to fill in the custom revision entity.
- * May also be specified using the {@code org.hibernate.envers.revision_listener} configuration property.
- */
- Class extends RevisionListener> value() default RevisionListener.class;
+ /**
+ * The optional listener that will be used to fill in the custom revision entity.
+ * May also be specified using the {@code org.hibernate.envers.revision_listener} configuration property.
+ */
+ Class extends RevisionListener> value() default RevisionListener.class;
}
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/RevisionListener.java b/hibernate-envers/src/main/java/org/hibernate/envers/RevisionListener.java
index 26956d5dc0..a49eed8530 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/RevisionListener.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/RevisionListener.java
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2008, 2013, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -27,13 +27,15 @@ package org.hibernate.envers;
/**
* An implementation of this class, having a no-arg constructor, should be passed as an argument to the
* {@link RevisionEntity} annotation.
+ *
* @author Adam Warski (adam at warski dot org)
*/
public interface RevisionListener {
- /**
- * Called when a new revision is created.
- * @param revisionEntity An instance of the entity annotated with {@link RevisionEntity}, which will be persisted
- * after this method returns. All properties on this entity that are to be persisted should be set by this method.
- */
- void newRevision(Object revisionEntity);
+ /**
+ * Called when a new revision is created.
+ *
+ * @param revisionEntity An instance of the entity annotated with {@link RevisionEntity}, which will be persisted
+ * after this method returns. All properties on this entity that are to be persisted should be set by this method.
+ */
+ void newRevision(Object revisionEntity);
}
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/RevisionNumber.java b/hibernate-envers/src/main/java/org/hibernate/envers/RevisionNumber.java
index 290b6b2c2e..26fa3749b9 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/RevisionNumber.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/RevisionNumber.java
@@ -33,7 +33,7 @@ import java.lang.annotation.Target;
* {@link RevisionListener}. Values of this property should form a strictly-increasing sequence
* of numbers. The value of this property won't be set by Envers. In most cases, this should be
* an auto-generated database-assigned primary id.
- *
+ *
* @author Adam Warski (adam at warski dot org)
* @author Sanne Grinovero
*/
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/RevisionTimestamp.java b/hibernate-envers/src/main/java/org/hibernate/envers/RevisionTimestamp.java
index 967ed178af..c27b70c770 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/RevisionTimestamp.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/RevisionTimestamp.java
@@ -31,7 +31,7 @@ import java.lang.annotation.Target;
/**
* Marks a property which will hold the timestamp of the revision in a revision entity, see
* {@link RevisionListener}. The value of this property will be automatically set by Envers.
- *
+ *
* @author Adam Warski (adam at warski dot org)
* @author Sanne Grinovero
*/
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/RevisionType.java b/hibernate-envers/src/main/java/org/hibernate/envers/RevisionType.java
index 79ab421292..a24e2f55a1 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/RevisionType.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/RevisionType.java
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2008, 2013, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -26,43 +26,51 @@ package org.hibernate.envers;
/**
* Type of the revision.
+ *
* @author Adam Warski (adam at warski dot org)
*/
public enum RevisionType {
- /**
- * Indicates that the entity was added (persisted) at that revision.
- */
- ADD((byte) 0),
- /**
- * Indicates that the entity was modified (one or more of its fields) at that revision.
- */
- MOD((byte) 1),
- /**
- * Indicates that the entity was deleted (removed) at that revision.
- */
- DEL((byte) 2);
+ /**
+ * Indicates that the entity was added (persisted) at that revision.
+ */
+ ADD( (byte) 0 ),
+ /**
+ * Indicates that the entity was modified (one or more of its fields) at that revision.
+ */
+ MOD( (byte) 1 ),
+ /**
+ * Indicates that the entity was deleted (removed) at that revision.
+ */
+ DEL( (byte) 2 );
- private Byte representation;
+ private Byte representation;
- RevisionType(byte representation) {
- this.representation = representation;
- }
+ RevisionType(byte representation) {
+ this.representation = representation;
+ }
- public Byte getRepresentation() {
- return representation;
- }
+ public Byte getRepresentation() {
+ return representation;
+ }
- public static RevisionType fromRepresentation(Object representation) {
- if (representation == null || !(representation instanceof Byte)) {
- return null;
- }
+ public static RevisionType fromRepresentation(Object representation) {
+ if ( representation == null || !(representation instanceof Byte) ) {
+ return null;
+ }
- switch ((Byte) representation) {
- case 0: return ADD;
- case 1: return MOD;
- case 2: return DEL;
- }
-
- throw new IllegalArgumentException("Unknown representation: " + representation);
- }
+ switch ( (Byte) representation ) {
+ case 0: {
+ return ADD;
+ }
+ case 1: {
+ return MOD;
+ }
+ case 2: {
+ return DEL;
+ }
+ default: {
+ throw new IllegalArgumentException( "Unknown representation: " + representation );
+ }
+ }
+ }
}
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/SecondaryAuditTable.java b/hibernate-envers/src/main/java/org/hibernate/envers/SecondaryAuditTable.java
index bb26ef2be8..da566e7dd6 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/SecondaryAuditTable.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/SecondaryAuditTable.java
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2008, 2013, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -22,6 +22,7 @@
* Boston, MA 02110-1301 USA
*/
package org.hibernate.envers;
+
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -33,7 +34,7 @@ import java.lang.annotation.Target;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface SecondaryAuditTable {
- String secondaryTableName();
+ String secondaryTableName();
- String secondaryAuditTableName();
+ String secondaryAuditTableName();
}
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/SecondaryAuditTables.java b/hibernate-envers/src/main/java/org/hibernate/envers/SecondaryAuditTables.java
index ea7a81a625..97d80a178a 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/SecondaryAuditTables.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/SecondaryAuditTables.java
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2008, 2013, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -22,6 +22,7 @@
* Boston, MA 02110-1301 USA
*/
package org.hibernate.envers;
+
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -33,5 +34,5 @@ import java.lang.annotation.Target;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface SecondaryAuditTables {
- SecondaryAuditTable[] value();
+ SecondaryAuditTable[] value();
}
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 a2eb5c7e76..374428cefe 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
@@ -1,7 +1,28 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2013, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
package org.hibernate.envers.configuration;
-import org.hibernate.envers.strategy.DefaultAuditStrategy;
-
/**
* Configuration property names.
*
@@ -69,7 +90,7 @@ public interface EnversSettings {
public static final String AUDIT_TABLE_SUFFIX = "org.hibernate.envers.audit_table_suffix";
/**
- * Audit strategy. Defaults to {@link DefaultAuditStrategy}.
+ * Audit strategy. Defaults to {@link org.hibernate.envers.strategy.DefaultAuditStrategy}.
*/
public static final String AUDIT_STRATEGY = "org.hibernate.envers.audit_strategy";
@@ -99,7 +120,7 @@ public interface EnversSettings {
* 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";
-
+
/**
* Name of column used for storing ordinal of the change in sets of embeddable elements. Defaults to {@literal SETORDINAL}.
*/
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 1460ec3b4a..ae0a63010a 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
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2008, 2013, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -59,7 +59,7 @@ public class AuditEntitiesConfiguration {
private final boolean revisionEndTimestampEnabled;
private final String revisionEndTimestampFieldName;
-
+
private final String embeddableSetOrdinalPropertyName;
public AuditEntitiesConfiguration(Properties properties, String revisionInfoEntityName) {
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 d9a95069f3..6a8ed4f48f 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
@@ -1,4 +1,28 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2013, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
package org.hibernate.envers.configuration.internal;
+
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashMap;
@@ -15,84 +39,100 @@ import org.hibernate.mapping.PersistentClass;
/**
* A helper class holding auditing meta-data for all persistent classes.
+ *
* @author Adam Warski (adam at warski dot org)
*/
public class ClassesAuditingData {
+ private static final EnversMessageLogger LOG = Logger.getMessageLogger(
+ EnversMessageLogger.class,
+ ClassesAuditingData.class.getName()
+ );
- public static final EnversMessageLogger LOG = Logger.getMessageLogger(EnversMessageLogger.class, 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.
+ *
+ * @param pc Persistent class.
+ * @param cad Auditing meta-data for the given class.
+ */
+ public void addClassAuditingData(PersistentClass pc, ClassAuditingData cad) {
+ entityNameToAuditingData.put( pc.getEntityName(), cad );
+ persistentClassToAuditingData.put( pc, cad );
+ }
- /**
- * Stores information about auditing meta-data for the given class.
- * @param pc Persistent class.
- * @param cad Auditing meta-data for the given class.
- */
- public void addClassAuditingData(PersistentClass pc, ClassAuditingData cad) {
- entityNameToAuditingData.put(pc.getEntityName(), cad);
- persistentClassToAuditingData.put(pc, cad);
- }
+ /**
+ * @return A collection of all auditing meta-data for persistent classes.
+ */
+ public Collection> getAllClassAuditedData() {
+ return persistentClassToAuditingData.entrySet();
+ }
- /**
- * @return A collection of all auditing meta-data for persistent classes.
- */
- public Collection> getAllClassAuditedData() {
- return persistentClassToAuditingData.entrySet();
- }
+ /**
+ * @param entityName Name of the entity.
+ *
+ * @return Auditing meta-data for the given entity.
+ */
+ public ClassAuditingData getClassAuditingData(String entityName) {
+ return entityNameToAuditingData.get( entityName );
+ }
- /**
- * @param entityName Name of the entity.
- * @return Auditing meta-data for the given entity.
- */
- public ClassAuditingData getClassAuditingData(String entityName) {
- return entityNameToAuditingData.get(entityName);
- }
+ /**
+ * After all meta-data is read, updates calculated fields. This includes:
+ *
+ * setting {@code forceInsertable} to {@code true} for properties specified by {@code @AuditMappedBy}
+ *
+ */
+ public void updateCalculatedFields() {
+ for ( Map.Entry classAuditingDataEntry : persistentClassToAuditingData.entrySet() ) {
+ final PersistentClass pc = classAuditingDataEntry.getKey();
+ final ClassAuditingData classAuditingData = classAuditingDataEntry.getValue();
+ for ( String propertyName : classAuditingData.getPropertyNames() ) {
+ final PropertyAuditingData propertyAuditingData = classAuditingData.getPropertyAuditingData( propertyName );
+ // If a property had the @AuditMappedBy annotation, setting the referenced fields to be always insertable.
+ if ( propertyAuditingData.getAuditMappedBy() != null ) {
+ final String referencedEntityName = MappingTools.getReferencedEntityName(
+ pc.getProperty( propertyName ).getValue()
+ );
- /**
- * After all meta-data is read, updates calculated fields. This includes:
- *
- * setting {@code forceInsertable} to {@code true} for properties specified by {@code @AuditMappedBy}
- *
- */
- public void updateCalculatedFields() {
- for (Map.Entry classAuditingDataEntry : persistentClassToAuditingData.entrySet()) {
- PersistentClass pc = classAuditingDataEntry.getKey();
- ClassAuditingData classAuditingData = classAuditingDataEntry.getValue();
- for (String propertyName : classAuditingData.getPropertyNames()) {
- PropertyAuditingData propertyAuditingData = classAuditingData.getPropertyAuditingData(propertyName);
- // If a property had the @AuditMappedBy annotation, setting the referenced fields to be always insertable.
- if (propertyAuditingData.getAuditMappedBy() != null) {
- String referencedEntityName = MappingTools.getReferencedEntityName(pc.getProperty(propertyName).getValue());
+ final ClassAuditingData referencedClassAuditingData = entityNameToAuditingData.get( referencedEntityName );
- ClassAuditingData referencedClassAuditingData = entityNameToAuditingData.get(referencedEntityName);
+ forcePropertyInsertable(
+ referencedClassAuditingData, propertyAuditingData.getAuditMappedBy(),
+ pc.getEntityName(), referencedEntityName
+ );
- forcePropertyInsertable(referencedClassAuditingData, propertyAuditingData.getAuditMappedBy(),
- pc.getEntityName(), referencedEntityName);
+ forcePropertyInsertable(
+ referencedClassAuditingData, propertyAuditingData.getPositionMappedBy(),
+ pc.getEntityName(), referencedEntityName
+ );
+ }
+ }
+ }
+ }
- forcePropertyInsertable(referencedClassAuditingData, propertyAuditingData.getPositionMappedBy(),
- pc.getEntityName(), referencedEntityName);
- }
- }
- }
- }
+ private void forcePropertyInsertable(
+ ClassAuditingData classAuditingData, String propertyName,
+ String entityName, String referencedEntityName) {
+ if ( propertyName != null ) {
+ if ( classAuditingData.getPropertyAuditingData( propertyName ) == null ) {
+ throw new MappingException(
+ "@AuditMappedBy points to a property that doesn't exist: " +
+ referencedEntityName + "." + propertyName
+ );
+ }
- private void forcePropertyInsertable(ClassAuditingData classAuditingData, String propertyName,
- String entityName, String referencedEntityName) {
- if (propertyName != null) {
- if (classAuditingData.getPropertyAuditingData(propertyName) == null) {
- throw new MappingException("@AuditMappedBy points to a property that doesn't exist: " +
- referencedEntityName + "." + propertyName);
- }
+ LOG.debugf(
+ "Non-insertable property %s.%s will be made insertable because a matching @AuditMappedBy was found in the %s entity",
+ referencedEntityName,
+ propertyName,
+ entityName
+ );
- LOG.debugf("Non-insertable property %s.%s will be made insertable because a matching @AuditMappedBy was found in the %s entity",
- referencedEntityName,
- propertyName,
- entityName);
-
- classAuditingData
- .getPropertyAuditingData(propertyName)
- .setForceInsertable(true);
- }
- }
+ classAuditingData
+ .getPropertyAuditingData( propertyName )
+ .setForceInsertable( true );
+ }
+ }
}
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 a12f588edb..540e439c4c 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
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2008, 2013, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -57,108 +57,118 @@ import org.hibernate.mapping.PersistentClass;
* @author Adam Warski (adam at warski dot org)
*/
public class EntitiesConfigurator {
- public EntitiesConfigurations configure(Configuration cfg, ReflectionManager reflectionManager,
- GlobalConfiguration globalCfg, AuditEntitiesConfiguration verEntCfg,
- AuditStrategy auditStrategy, ClassLoaderService classLoaderService,
- Document revisionInfoXmlMapping, Element revisionInfoRelationMapping) {
- // Creating a name register to capture all audit entity names created.
- AuditEntityNameRegister auditEntityNameRegister = new AuditEntityNameRegister();
- DOMWriter writer = new DOMWriter();
+ public EntitiesConfigurations configure(
+ Configuration cfg, ReflectionManager reflectionManager,
+ GlobalConfiguration globalCfg, AuditEntitiesConfiguration verEntCfg,
+ AuditStrategy auditStrategy, ClassLoaderService classLoaderService,
+ Document revisionInfoXmlMapping, Element revisionInfoRelationMapping) {
+ // Creating a name register to capture all audit entity names created.
+ final AuditEntityNameRegister auditEntityNameRegister = new AuditEntityNameRegister();
+ final DOMWriter writer = new DOMWriter();
- // Sorting the persistent class topologically - superclass always before subclass
- Iterator classes = GraphTopologicalSort.sort(new PersistentClassGraphDefiner(cfg)).iterator();
+ // Sorting the persistent class topologically - superclass always before subclass
+ final Iterator classes = GraphTopologicalSort.sort( new PersistentClassGraphDefiner( cfg ) )
+ .iterator();
- ClassesAuditingData classesAuditingData = new ClassesAuditingData();
- Map xmlMappings = new HashMap();
+ final ClassesAuditingData classesAuditingData = new ClassesAuditingData();
+ final Map xmlMappings = new HashMap();
- // Reading metadata from annotations
- while (classes.hasNext()) {
- PersistentClass pc = classes.next();
+ // Reading metadata from annotations
+ while ( classes.hasNext() ) {
+ final PersistentClass pc = classes.next();
- // Collecting information from annotations on the persistent class pc
- AnnotationsMetadataReader annotationsMetadataReader =
- new AnnotationsMetadataReader(globalCfg, reflectionManager, pc);
- ClassAuditingData auditData = annotationsMetadataReader.getAuditData();
+ // Collecting information from annotations on the persistent class pc
+ final AnnotationsMetadataReader annotationsMetadataReader =
+ new AnnotationsMetadataReader( globalCfg, reflectionManager, pc );
+ final ClassAuditingData auditData = annotationsMetadataReader.getAuditData();
- classesAuditingData.addClassAuditingData(pc, auditData);
- }
+ classesAuditingData.addClassAuditingData( pc, auditData );
+ }
- // Now that all information is read we can update the calculated fields.
- classesAuditingData.updateCalculatedFields();
+ // Now that all information is read we can update the calculated fields.
+ classesAuditingData.updateCalculatedFields();
- AuditMetadataGenerator auditMetaGen = new AuditMetadataGenerator(cfg, globalCfg, verEntCfg, auditStrategy,
- classLoaderService, revisionInfoRelationMapping, auditEntityNameRegister);
+ final AuditMetadataGenerator auditMetaGen = new AuditMetadataGenerator(
+ cfg, globalCfg, verEntCfg, auditStrategy,
+ classLoaderService, revisionInfoRelationMapping, auditEntityNameRegister
+ );
- // First pass
- for (Map.Entry pcDatasEntry : classesAuditingData.getAllClassAuditedData()) {
- PersistentClass pc = pcDatasEntry.getKey();
- ClassAuditingData auditData = pcDatasEntry.getValue();
+ // First pass
+ for ( Map.Entry pcDatasEntry : classesAuditingData.getAllClassAuditedData() ) {
+ final PersistentClass pc = pcDatasEntry.getKey();
+ final ClassAuditingData auditData = pcDatasEntry.getValue();
- EntityXmlMappingData xmlMappingData = new EntityXmlMappingData();
- if (auditData.isAudited()) {
- if (!StringTools.isEmpty(auditData.getAuditTable().value())) {
- verEntCfg.addCustomAuditTableName(pc.getEntityName(), auditData.getAuditTable().value());
- }
+ final EntityXmlMappingData xmlMappingData = new EntityXmlMappingData();
+ if ( auditData.isAudited() ) {
+ if ( !StringTools.isEmpty( auditData.getAuditTable().value() ) ) {
+ verEntCfg.addCustomAuditTableName( pc.getEntityName(), auditData.getAuditTable().value() );
+ }
- auditMetaGen.generateFirstPass(pc, auditData, xmlMappingData, true);
- } else {
- auditMetaGen.generateFirstPass(pc, auditData, xmlMappingData, false);
+ auditMetaGen.generateFirstPass( pc, auditData, xmlMappingData, true );
+ }
+ else {
+ auditMetaGen.generateFirstPass( pc, auditData, xmlMappingData, false );
}
- xmlMappings.put(pc, xmlMappingData);
- }
+ xmlMappings.put( pc, xmlMappingData );
+ }
- // Second pass
- for (Map.Entry pcDatasEntry : classesAuditingData.getAllClassAuditedData()) {
- EntityXmlMappingData xmlMappingData = xmlMappings.get(pcDatasEntry.getKey());
+ // Second pass
+ for ( Map.Entry pcDatasEntry : classesAuditingData.getAllClassAuditedData() ) {
+ final EntityXmlMappingData xmlMappingData = xmlMappings.get( pcDatasEntry.getKey() );
- if (pcDatasEntry.getValue().isAudited()) {
- auditMetaGen.generateSecondPass(pcDatasEntry.getKey(), pcDatasEntry.getValue(), xmlMappingData);
- try {
- cfg.addDocument(writer.write(xmlMappingData.getMainXmlMapping()));
- //writeDocument(xmlMappingData.getMainXmlMapping());
+ if ( pcDatasEntry.getValue().isAudited() ) {
+ auditMetaGen.generateSecondPass( pcDatasEntry.getKey(), pcDatasEntry.getValue(), xmlMappingData );
+ try {
+ cfg.addDocument( writer.write( xmlMappingData.getMainXmlMapping() ) );
+ //writeDocument(xmlMappingData.getMainXmlMapping());
- for (Document additionalMapping : xmlMappingData.getAdditionalXmlMappings()) {
- cfg.addDocument(writer.write(additionalMapping));
- //writeDocument(additionalMapping);
- }
- } catch (DocumentException e) {
- throw new MappingException(e);
- }
- }
- }
+ for ( Document additionalMapping : xmlMappingData.getAdditionalXmlMappings() ) {
+ cfg.addDocument( writer.write( additionalMapping ) );
+ //writeDocument(additionalMapping);
+ }
+ }
+ catch (DocumentException e) {
+ throw new MappingException( e );
+ }
+ }
+ }
- // Only if there are any versioned classes
- if (auditMetaGen.getEntitiesConfigurations().size() > 0) {
- try {
- if (revisionInfoXmlMapping != null) {
- //writeDocument(revisionInfoXmlMapping);
- cfg.addDocument(writer.write(revisionInfoXmlMapping));
- }
- } catch (DocumentException e) {
- throw new MappingException(e);
- }
- }
+ // Only if there are any versioned classes
+ if ( auditMetaGen.getEntitiesConfigurations().size() > 0 ) {
+ try {
+ if ( revisionInfoXmlMapping != null ) {
+ //writeDocument(revisionInfoXmlMapping);
+ cfg.addDocument( writer.write( revisionInfoXmlMapping ) );
+ }
+ }
+ catch (DocumentException e) {
+ throw new MappingException( e );
+ }
+ }
- return new EntitiesConfigurations(auditMetaGen.getEntitiesConfigurations(),
- auditMetaGen.getNotAuditedEntitiesConfigurations());
- }
+ return new EntitiesConfigurations(
+ auditMetaGen.getEntitiesConfigurations(),
+ auditMetaGen.getNotAuditedEntitiesConfigurations()
+ );
+ }
- @SuppressWarnings({"UnusedDeclaration"})
- private void writeDocument(Document e) {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- Writer w = new PrintWriter(baos);
+ @SuppressWarnings({"UnusedDeclaration"})
+ private void writeDocument(Document e) {
+ final ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ final Writer w = new PrintWriter( baos );
- try {
- XMLWriter xw = new XMLWriter(w, new OutputFormat(" ", true));
- xw.write(e);
- w.flush();
- } catch (IOException e1) {
- e1.printStackTrace();
- }
+ try {
+ final XMLWriter xw = new XMLWriter( w, new OutputFormat( " ", true ) );
+ xw.write( e );
+ w.flush();
+ }
+ catch (IOException e1) {
+ e1.printStackTrace();
+ }
- System.out.println("-----------");
- System.out.println(baos.toString());
- System.out.println("-----------");
- }
+ System.out.println( "-----------" );
+ System.out.println( baos.toString() );
+ System.out.println( "-----------" );
+ }
}
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/GlobalConfiguration.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/GlobalConfiguration.java
index 295f9d4585..658451430f 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/GlobalConfiguration.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/GlobalConfiguration.java
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2008, 2013, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -116,13 +116,16 @@ public class GlobalConfiguration {
EnversSettings.MODIFIED_FLAG_SUFFIX, properties, "_MOD"
);
- String revisionListenerClassName = properties.getProperty( EnversSettings.REVISION_LISTENER, null );
+ final String revisionListenerClassName = properties.getProperty( EnversSettings.REVISION_LISTENER, null );
if ( revisionListenerClassName != null ) {
try {
revisionListenerClass = ReflectionTools.loadClass( revisionListenerClassName, classLoaderService );
}
- catch ( ClassLoadingException e ) {
- throw new MappingException( "Revision listener class not found: " + revisionListenerClassName + ".", e );
+ catch (ClassLoadingException e) {
+ throw new MappingException(
+ "Revision listener class not found: " + revisionListenerClassName + ".",
+ e
+ );
}
}
else {
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 f82ef769a5..c26a22474a 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
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2008, 2013, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -22,6 +22,7 @@
* Boston, MA 02110-1301 USA
*/
package org.hibernate.envers.configuration.internal;
+
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -34,43 +35,48 @@ import org.hibernate.mapping.PersistentClass;
/**
* Defines a graph, where the vertexes are all persistent classes, and there is an edge from
* p.c. A to p.c. B iff A is a superclass of B.
+ *
* @author Adam Warski (adam at warski dot org)
*/
public class PersistentClassGraphDefiner implements GraphDefiner {
- private Configuration cfg;
+ private Configuration cfg;
- public PersistentClassGraphDefiner(Configuration cfg) {
- this.cfg = cfg;
- }
+ public PersistentClassGraphDefiner(Configuration cfg) {
+ this.cfg = cfg;
+ }
- public String getRepresentation(PersistentClass pc) {
- return pc.getEntityName();
- }
+ @Override
+ public String getRepresentation(PersistentClass pc) {
+ return pc.getEntityName();
+ }
- public PersistentClass getValue(String entityName) {
- return cfg.getClassMapping(entityName);
- }
+ @Override
+ public PersistentClass getValue(String entityName) {
+ return cfg.getClassMapping( entityName );
+ }
- @SuppressWarnings({"unchecked"})
- private void addNeighbours(List neighbours, Iterator subclassIterator) {
- while (subclassIterator.hasNext()) {
- PersistentClass subclass = subclassIterator.next();
- neighbours.add(subclass);
- addNeighbours(neighbours, (Iterator) subclass.getSubclassIterator());
- }
- }
+ @SuppressWarnings({"unchecked"})
+ private void addNeighbours(List neighbours, Iterator subclassIterator) {
+ while ( subclassIterator.hasNext() ) {
+ final PersistentClass subclass = subclassIterator.next();
+ neighbours.add( subclass );
+ addNeighbours( neighbours, (Iterator) subclass.getSubclassIterator() );
+ }
+ }
- @SuppressWarnings({"unchecked"})
- public List getNeighbours(PersistentClass pc) {
- List neighbours = new ArrayList();
+ @Override
+ @SuppressWarnings({"unchecked"})
+ public List getNeighbours(PersistentClass pc) {
+ final List neighbours = new ArrayList();
- addNeighbours(neighbours, (Iterator) pc.getSubclassIterator());
+ addNeighbours( neighbours, (Iterator) pc.getSubclassIterator() );
- return neighbours;
- }
+ return neighbours;
+ }
- @SuppressWarnings({"unchecked"})
- public List getValues() {
- return Tools.iteratorToList( cfg.getClassMappings() );
- }
+ @Override
+ @SuppressWarnings({"unchecked"})
+ public List getValues() {
+ return Tools.iteratorToList( cfg.getClassMappings() );
+ }
}
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/RevisionInfoConfiguration.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/RevisionInfoConfiguration.java
index 7e14efa32b..104b96fa6c 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/RevisionInfoConfiguration.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/RevisionInfoConfiguration.java
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2008, 2013, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -22,10 +22,11 @@
* Boston, MA 02110-1301 USA
*/
package org.hibernate.envers.configuration.internal;
+
+import javax.persistence.Column;
import java.util.Date;
import java.util.Iterator;
import java.util.Set;
-import javax.persistence.Column;
import org.dom4j.Document;
import org.dom4j.Element;
@@ -65,301 +66,394 @@ import org.hibernate.type.Type;
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
*/
public class RevisionInfoConfiguration {
- private String revisionInfoEntityName;
- private PropertyData revisionInfoIdData;
- private PropertyData revisionInfoTimestampData;
- private PropertyData modifiedEntityNamesData;
- private Type revisionInfoTimestampType;
- private GlobalConfiguration globalCfg;
+ private String revisionInfoEntityName;
+ private PropertyData revisionInfoIdData;
+ private PropertyData revisionInfoTimestampData;
+ private PropertyData modifiedEntityNamesData;
+ private Type revisionInfoTimestampType;
+ private GlobalConfiguration globalCfg;
- private String revisionPropType;
- private String revisionPropSqlType;
+ private String revisionPropType;
+ private String revisionPropSqlType;
- public RevisionInfoConfiguration(GlobalConfiguration globalCfg) {
- this.globalCfg = globalCfg;
- if (globalCfg.isUseRevisionEntityWithNativeId()) {
- revisionInfoEntityName = "org.hibernate.envers.DefaultRevisionEntity";
- } else {
- revisionInfoEntityName = "org.hibernate.envers.enhanced.SequenceIdRevisionEntity";
- }
- revisionInfoIdData = new PropertyData("id", "id", "field", null);
- revisionInfoTimestampData = new PropertyData("timestamp", "timestamp", "field", null);
- modifiedEntityNamesData = new PropertyData("modifiedEntityNames", "modifiedEntityNames", "field", null);
- revisionInfoTimestampType = new LongType();
+ public RevisionInfoConfiguration(GlobalConfiguration globalCfg) {
+ this.globalCfg = globalCfg;
+ if ( globalCfg.isUseRevisionEntityWithNativeId() ) {
+ revisionInfoEntityName = "org.hibernate.envers.DefaultRevisionEntity";
+ }
+ else {
+ revisionInfoEntityName = "org.hibernate.envers.enhanced.SequenceIdRevisionEntity";
+ }
+ revisionInfoIdData = new PropertyData( "id", "id", "field", null );
+ revisionInfoTimestampData = new PropertyData( "timestamp", "timestamp", "field", null );
+ modifiedEntityNamesData = new PropertyData( "modifiedEntityNames", "modifiedEntityNames", "field", null );
+ revisionInfoTimestampType = new LongType();
- revisionPropType = "integer";
- }
+ revisionPropType = "integer";
+ }
- private Document generateDefaultRevisionInfoXmlMapping() {
- Document document = XMLHelper.getDocumentFactory().createDocument();
+ private Document generateDefaultRevisionInfoXmlMapping() {
+ final Document document = XMLHelper.getDocumentFactory().createDocument();
- Element class_mapping = MetadataTools.createEntity(document, new AuditTableData(null, null, globalCfg.getDefaultSchemaName(), globalCfg.getDefaultCatalogName()), null, null);
+ final Element classMapping = MetadataTools.createEntity(
+ document,
+ new AuditTableData( null, null, globalCfg.getDefaultSchemaName(), globalCfg.getDefaultCatalogName() ),
+ null,
+ null
+ );
- class_mapping.addAttribute("name", revisionInfoEntityName);
- class_mapping.addAttribute("table", "REVINFO");
+ classMapping.addAttribute( "name", revisionInfoEntityName );
+ classMapping.addAttribute( "table", "REVINFO" );
- Element idProperty = MetadataTools.addNativelyGeneratedId(class_mapping, revisionInfoIdData.getName(),
- revisionPropType, globalCfg.isUseRevisionEntityWithNativeId());
- MetadataTools.addColumn(idProperty, "REV", null, null, null, null, null, null, false);
+ final Element idProperty = MetadataTools.addNativelyGeneratedId(
+ classMapping,
+ revisionInfoIdData.getName(),
+ revisionPropType,
+ globalCfg.isUseRevisionEntityWithNativeId()
+ );
+ MetadataTools.addColumn( idProperty, "REV", null, null, null, null, null, null, false );
- Element timestampProperty = MetadataTools.addProperty(class_mapping, revisionInfoTimestampData.getName(),
- revisionInfoTimestampType.getName(), true, false);
- MetadataTools.addColumn(timestampProperty, "REVTSTMP", null, null, null, null, null, null, false);
+ final Element timestampProperty = MetadataTools.addProperty(
+ classMapping,
+ revisionInfoTimestampData.getName(),
+ revisionInfoTimestampType.getName(),
+ true,
+ false
+ );
+ MetadataTools.addColumn( timestampProperty, "REVTSTMP", null, null, null, null, null, null, false );
- if (globalCfg.isTrackEntitiesChangedInRevision()) {
- generateEntityNamesTrackingTableMapping(class_mapping, "modifiedEntityNames",
- globalCfg.getDefaultSchemaName(), globalCfg.getDefaultCatalogName(),
- "REVCHANGES", "REV", "ENTITYNAME", "string");
- }
+ if ( globalCfg.isTrackEntitiesChangedInRevision() ) {
+ generateEntityNamesTrackingTableMapping(
+ classMapping,
+ "modifiedEntityNames",
+ globalCfg.getDefaultSchemaName(),
+ globalCfg.getDefaultCatalogName(),
+ "REVCHANGES",
+ "REV",
+ "ENTITYNAME",
+ "string"
+ );
+ }
- return document;
- }
+ return document;
+ }
- /**
- * Generates mapping that represents a set of primitive types.
- *
- * <set name="propertyName" table="joinTableName" schema="joinTableSchema" catalog="joinTableCatalog"
- * cascade="persist, delete" lazy="false" fetch="join">
- * <key column="joinTablePrimaryKeyColumnName" />
- * <element type="joinTableValueColumnType">
- * <column name="joinTableValueColumnName" />
- * </element>
- * </set>
- *
- */
- private void generateEntityNamesTrackingTableMapping(Element class_mapping, String propertyName,
- String joinTableSchema, String joinTableCatalog, String joinTableName,
- String joinTablePrimaryKeyColumnName, String joinTableValueColumnName,
- String joinTableValueColumnType) {
- Element set = class_mapping.addElement("set");
- set.addAttribute("name", propertyName);
- set.addAttribute("table", joinTableName);
- set.addAttribute("schema", joinTableSchema);
- set.addAttribute("catalog", joinTableCatalog);
- set.addAttribute("cascade", "persist, delete");
- set.addAttribute("fetch", "join");
- set.addAttribute("lazy", "false");
- Element key = set.addElement("key");
- key.addAttribute("column", joinTablePrimaryKeyColumnName);
- Element element = set.addElement("element");
- element.addAttribute("type", joinTableValueColumnType);
- Element column = element.addElement("column");
- column.addAttribute("name", joinTableValueColumnName);
- }
+ /**
+ * Generates mapping that represents a set of primitive types.
+ *
+ * <set name="propertyName" table="joinTableName" schema="joinTableSchema" catalog="joinTableCatalog"
+ * cascade="persist, delete" lazy="false" fetch="join">
+ * <key column="joinTablePrimaryKeyColumnName" />
+ * <element type="joinTableValueColumnType">
+ * <column name="joinTableValueColumnName" />
+ * </element>
+ * </set>
+ *
+ */
+ private void generateEntityNamesTrackingTableMapping(
+ Element classMapping,
+ String propertyName,
+ String joinTableSchema,
+ String joinTableCatalog,
+ String joinTableName,
+ String joinTablePrimaryKeyColumnName,
+ String joinTableValueColumnName,
+ String joinTableValueColumnType) {
+ final Element set = classMapping.addElement( "set" );
+ set.addAttribute( "name", propertyName );
+ set.addAttribute( "table", joinTableName );
+ set.addAttribute( "schema", joinTableSchema );
+ set.addAttribute( "catalog", joinTableCatalog );
+ set.addAttribute( "cascade", "persist, delete" );
+ set.addAttribute( "fetch", "join" );
+ set.addAttribute( "lazy", "false" );
+ final Element key = set.addElement( "key" );
+ key.addAttribute( "column", joinTablePrimaryKeyColumnName );
+ final Element element = set.addElement( "element" );
+ element.addAttribute( "type", joinTableValueColumnType );
+ final Element column = element.addElement( "column" );
+ column.addAttribute( "name", joinTableValueColumnName );
+ }
- private Element generateRevisionInfoRelationMapping() {
- Document document = XMLHelper.getDocumentFactory().createDocument();
- Element rev_rel_mapping = document.addElement("key-many-to-one");
- rev_rel_mapping.addAttribute("type", revisionPropType);
- rev_rel_mapping.addAttribute("class", revisionInfoEntityName);
+ private Element generateRevisionInfoRelationMapping() {
+ final Document document = XMLHelper.getDocumentFactory().createDocument();
+ final Element revRelMapping = document.addElement( "key-many-to-one" );
+ revRelMapping.addAttribute( "type", revisionPropType );
+ revRelMapping.addAttribute( "class", revisionInfoEntityName );
- if (revisionPropSqlType != null) {
- // Putting a fake name to make Hibernate happy. It will be replaced later anyway.
- MetadataTools.addColumn(rev_rel_mapping, "*" , null, null, null, revisionPropSqlType, null, null, false);
- }
+ if ( revisionPropSqlType != null ) {
+ // Putting a fake name to make Hibernate happy. It will be replaced later anyway.
+ MetadataTools.addColumn( revRelMapping, "*", null, null, null, revisionPropSqlType, null, null, false );
+ }
- return rev_rel_mapping;
- }
+ return revRelMapping;
+ }
- private void searchForRevisionInfoCfgInProperties(XClass clazz, ReflectionManager reflectionManager,
- MutableBoolean revisionNumberFound, MutableBoolean revisionTimestampFound,
- MutableBoolean modifiedEntityNamesFound, String accessType) {
- for (XProperty property : clazz.getDeclaredProperties(accessType)) {
- RevisionNumber revisionNumber = property.getAnnotation(RevisionNumber.class);
- RevisionTimestamp revisionTimestamp = property.getAnnotation(RevisionTimestamp.class);
- ModifiedEntityNames modifiedEntityNames = property.getAnnotation(ModifiedEntityNames.class);
+ private void searchForRevisionInfoCfgInProperties(
+ XClass clazz,
+ ReflectionManager reflectionManager,
+ MutableBoolean revisionNumberFound,
+ MutableBoolean revisionTimestampFound,
+ MutableBoolean modifiedEntityNamesFound,
+ String accessType) {
+ for ( XProperty property : clazz.getDeclaredProperties( accessType ) ) {
+ final RevisionNumber revisionNumber = property.getAnnotation( RevisionNumber.class );
+ final RevisionTimestamp revisionTimestamp = property.getAnnotation( RevisionTimestamp.class );
+ final ModifiedEntityNames modifiedEntityNames = property.getAnnotation( ModifiedEntityNames.class );
- if (revisionNumber != null) {
- if (revisionNumberFound.isSet()) {
- throw new MappingException("Only one property may be annotated with @RevisionNumber!");
- }
+ if ( revisionNumber != null ) {
+ if ( revisionNumberFound.isSet() ) {
+ throw new MappingException( "Only one property may be annotated with @RevisionNumber!" );
+ }
- XClass revisionNumberClass = property.getType();
- if (reflectionManager.equals(revisionNumberClass, Integer.class) ||
- reflectionManager.equals(revisionNumberClass, Integer.TYPE)) {
- revisionInfoIdData = new PropertyData(property.getName(), property.getName(), accessType, null);
- revisionNumberFound.set();
- } else if (reflectionManager.equals(revisionNumberClass, Long.class) ||
- reflectionManager.equals(revisionNumberClass, Long.TYPE)) {
- revisionInfoIdData = new PropertyData(property.getName(), property.getName(), accessType, null);
- revisionNumberFound.set();
+ final XClass revisionNumberClass = property.getType();
+ if ( reflectionManager.equals( revisionNumberClass, Integer.class ) ||
+ reflectionManager.equals( revisionNumberClass, Integer.TYPE ) ) {
+ revisionInfoIdData = new PropertyData( property.getName(), property.getName(), accessType, null );
+ revisionNumberFound.set();
+ }
+ else if ( reflectionManager.equals( revisionNumberClass, Long.class ) ||
+ reflectionManager.equals( revisionNumberClass, Long.TYPE ) ) {
+ revisionInfoIdData = new PropertyData( property.getName(), property.getName(), accessType, null );
+ revisionNumberFound.set();
- // The default is integer
- revisionPropType = "long";
- } else {
- throw new MappingException("The field annotated with @RevisionNumber must be of type " +
- "int, Integer, long or Long");
- }
+ // The default is integer
+ revisionPropType = "long";
+ }
+ else {
+ throw new MappingException(
+ "The field annotated with @RevisionNumber must be of type " +
+ "int, Integer, long or Long"
+ );
+ }
- // Getting the @Column definition of the revision number property, to later use that info to
- // generate the same mapping for the relation from an audit table's revision number to the
- // revision entity revision number.
- Column revisionPropColumn = property.getAnnotation(Column.class);
- if (revisionPropColumn != null) {
- revisionPropSqlType = revisionPropColumn.columnDefinition();
- }
- }
+ // Getting the @Column definition of the revision number property, to later use that info to
+ // generate the same mapping for the relation from an audit table's revision number to the
+ // revision entity revision number.
+ final Column revisionPropColumn = property.getAnnotation( Column.class );
+ if ( revisionPropColumn != null ) {
+ revisionPropSqlType = revisionPropColumn.columnDefinition();
+ }
+ }
- if (revisionTimestamp != null) {
- if (revisionTimestampFound.isSet()) {
- throw new MappingException("Only one property may be annotated with @RevisionTimestamp!");
- }
+ if ( revisionTimestamp != null ) {
+ if ( revisionTimestampFound.isSet() ) {
+ throw new MappingException( "Only one property may be annotated with @RevisionTimestamp!" );
+ }
- XClass revisionTimestampClass = property.getType();
- if (reflectionManager.equals(revisionTimestampClass, Long.class) ||
- reflectionManager.equals(revisionTimestampClass, Long.TYPE) ||
- reflectionManager.equals(revisionTimestampClass, Date.class) ||
- reflectionManager.equals(revisionTimestampClass, java.sql.Date.class)) {
- revisionInfoTimestampData = new PropertyData(property.getName(), property.getName(), accessType, null);
- revisionTimestampFound.set();
- } else {
- throw new MappingException("The field annotated with @RevisionTimestamp must be of type " +
- "long, Long, java.util.Date or java.sql.Date");
- }
- }
+ final XClass revisionTimestampClass = property.getType();
+ if ( reflectionManager.equals( revisionTimestampClass, Long.class ) ||
+ reflectionManager.equals( revisionTimestampClass, Long.TYPE ) ||
+ reflectionManager.equals( revisionTimestampClass, Date.class ) ||
+ reflectionManager.equals( revisionTimestampClass, java.sql.Date.class ) ) {
+ revisionInfoTimestampData = new PropertyData(
+ property.getName(),
+ property.getName(),
+ accessType,
+ null
+ );
+ revisionTimestampFound.set();
+ }
+ else {
+ throw new MappingException(
+ "The field annotated with @RevisionTimestamp must be of type " +
+ "long, Long, java.util.Date or java.sql.Date"
+ );
+ }
+ }
- if (modifiedEntityNames != null) {
- if (modifiedEntityNamesFound.isSet()) {
- throw new MappingException("Only one property may be annotated with @ModifiedEntityNames!");
- }
- XClass modifiedEntityNamesClass = property.getType();
- if (reflectionManager.equals(modifiedEntityNamesClass, Set.class) &&
- reflectionManager.equals(property.getElementClass(), String.class)) {
- modifiedEntityNamesData = new PropertyData(property.getName(), property.getName(), accessType, null);
- modifiedEntityNamesFound.set();
- } else {
- throw new MappingException("The field annotated with @ModifiedEntityNames must be of Set type.");
- }
- }
- }
- }
+ if ( modifiedEntityNames != null ) {
+ if ( modifiedEntityNamesFound.isSet() ) {
+ throw new MappingException( "Only one property may be annotated with @ModifiedEntityNames!" );
+ }
+ final XClass modifiedEntityNamesClass = property.getType();
+ if ( reflectionManager.equals( modifiedEntityNamesClass, Set.class ) &&
+ reflectionManager.equals( property.getElementClass(), String.class ) ) {
+ modifiedEntityNamesData = new PropertyData(
+ property.getName(),
+ property.getName(),
+ accessType,
+ null
+ );
+ modifiedEntityNamesFound.set();
+ }
+ else {
+ throw new MappingException(
+ "The field annotated with @ModifiedEntityNames must be of Set type."
+ );
+ }
+ }
+ }
+ }
- private void searchForRevisionInfoCfg(XClass clazz, ReflectionManager reflectionManager,
- MutableBoolean revisionNumberFound, MutableBoolean revisionTimestampFound,
- MutableBoolean modifiedEntityNamesFound) {
- XClass superclazz = clazz.getSuperclass();
- if (!"java.lang.Object".equals(superclazz.getName())) {
- searchForRevisionInfoCfg(superclazz, reflectionManager, revisionNumberFound, revisionTimestampFound, modifiedEntityNamesFound);
- }
+ private void searchForRevisionInfoCfg(
+ XClass clazz, ReflectionManager reflectionManager,
+ MutableBoolean revisionNumberFound, MutableBoolean revisionTimestampFound,
+ MutableBoolean modifiedEntityNamesFound) {
+ final XClass superclazz = clazz.getSuperclass();
+ if ( !"java.lang.Object".equals( superclazz.getName() ) ) {
+ searchForRevisionInfoCfg(
+ superclazz,
+ reflectionManager,
+ revisionNumberFound,
+ revisionTimestampFound,
+ modifiedEntityNamesFound
+ );
+ }
- searchForRevisionInfoCfgInProperties(clazz, reflectionManager, revisionNumberFound, revisionTimestampFound,
- modifiedEntityNamesFound, "field");
- searchForRevisionInfoCfgInProperties(clazz, reflectionManager, revisionNumberFound, revisionTimestampFound,
- modifiedEntityNamesFound, "property");
- }
+ searchForRevisionInfoCfgInProperties(
+ clazz, reflectionManager, revisionNumberFound, revisionTimestampFound,
+ modifiedEntityNamesFound, "field"
+ );
+ searchForRevisionInfoCfgInProperties(
+ clazz, reflectionManager, revisionNumberFound, revisionTimestampFound,
+ modifiedEntityNamesFound, "property"
+ );
+ }
- public RevisionInfoConfigurationResult configure(Configuration cfg, ReflectionManager reflectionManager) {
- Iterator classes = cfg.getClassMappings();
- boolean revisionEntityFound = false;
- RevisionInfoGenerator revisionInfoGenerator = null;
+ public RevisionInfoConfigurationResult configure(Configuration cfg, ReflectionManager reflectionManager) {
+ boolean revisionEntityFound = false;
+ RevisionInfoGenerator revisionInfoGenerator = null;
+ Class> revisionInfoClass = null;
- Class> revisionInfoClass = null;
+ final Iterator classes = cfg.getClassMappings();
+ while ( classes.hasNext() ) {
+ PersistentClass pc = classes.next();
+ XClass clazz;
+ try {
+ clazz = reflectionManager.classForName( pc.getClassName(), this.getClass() );
+ }
+ catch (ClassNotFoundException e) {
+ throw new MappingException( e );
+ }
- while (classes.hasNext()) {
- PersistentClass pc = classes.next();
- XClass clazz;
- try {
- clazz = reflectionManager.classForName(pc.getClassName(), this.getClass());
- } catch (ClassNotFoundException e) {
- throw new MappingException(e);
- }
+ final RevisionEntity revisionEntity = clazz.getAnnotation( RevisionEntity.class );
+ if ( revisionEntity != null ) {
+ if ( revisionEntityFound ) {
+ throw new MappingException( "Only one entity may be annotated with @RevisionEntity!" );
+ }
- RevisionEntity revisionEntity = clazz.getAnnotation(RevisionEntity.class);
- if (revisionEntity != null) {
- if (revisionEntityFound) {
- throw new MappingException("Only one entity may be annotated with @RevisionEntity!");
- }
+ // Checking if custom revision entity isn't audited
+ if ( clazz.getAnnotation( Audited.class ) != null ) {
+ throw new MappingException( "An entity annotated with @RevisionEntity cannot be audited!" );
+ }
- // Checking if custom revision entity isn't audited
- if (clazz.getAnnotation(Audited.class) != null) {
- throw new MappingException("An entity annotated with @RevisionEntity cannot be audited!");
- }
+ revisionEntityFound = true;
- revisionEntityFound = true;
+ final MutableBoolean revisionNumberFound = new MutableBoolean();
+ final MutableBoolean revisionTimestampFound = new MutableBoolean();
+ final MutableBoolean modifiedEntityNamesFound = new MutableBoolean();
- MutableBoolean revisionNumberFound = new MutableBoolean();
- MutableBoolean revisionTimestampFound = new MutableBoolean();
- MutableBoolean modifiedEntityNamesFound = new MutableBoolean();
+ searchForRevisionInfoCfg(
+ clazz,
+ reflectionManager,
+ revisionNumberFound,
+ revisionTimestampFound,
+ modifiedEntityNamesFound
+ );
- searchForRevisionInfoCfg(clazz, reflectionManager, revisionNumberFound, revisionTimestampFound, modifiedEntityNamesFound);
+ if ( !revisionNumberFound.isSet() ) {
+ throw new MappingException(
+ "An entity annotated with @RevisionEntity must have a field annotated " +
+ "with @RevisionNumber!"
+ );
+ }
- if (!revisionNumberFound.isSet()) {
- throw new MappingException("An entity annotated with @RevisionEntity must have a field annotated " +
- "with @RevisionNumber!");
- }
+ if ( !revisionTimestampFound.isSet() ) {
+ throw new MappingException(
+ "An entity annotated with @RevisionEntity must have a field annotated " +
+ "with @RevisionTimestamp!"
+ );
+ }
- if (!revisionTimestampFound.isSet()) {
- throw new MappingException("An entity annotated with @RevisionEntity must have a field annotated " +
- "with @RevisionTimestamp!");
- }
+ revisionInfoEntityName = pc.getEntityName();
+ revisionInfoClass = pc.getMappedClass();
+ final Class extends RevisionListener> revisionListenerClass = getRevisionListenerClass( revisionEntity.value() );
+ revisionInfoTimestampType = pc.getProperty( revisionInfoTimestampData.getName() ).getType();
+ if ( globalCfg.isTrackEntitiesChangedInRevision()
+ || (globalCfg.isUseRevisionEntityWithNativeId() && DefaultTrackingModifiedEntitiesRevisionEntity.class
+ .isAssignableFrom( revisionInfoClass ))
+ || (!globalCfg.isUseRevisionEntityWithNativeId() && SequenceIdTrackingModifiedEntitiesRevisionEntity.class
+ .isAssignableFrom( revisionInfoClass ))
+ || modifiedEntityNamesFound.isSet() ) {
+ // If tracking modified entities parameter is enabled, custom revision info entity is a subtype
+ // of DefaultTrackingModifiedEntitiesRevisionEntity class, or @ModifiedEntityNames annotation is used.
+ revisionInfoGenerator = new DefaultTrackingModifiedEntitiesRevisionInfoGenerator(
+ revisionInfoEntityName,
+ revisionInfoClass, revisionListenerClass, revisionInfoTimestampData, isTimestampAsDate(),
+ modifiedEntityNamesData
+ );
+ globalCfg.setTrackEntitiesChangedInRevision( true );
+ }
+ else {
+ revisionInfoGenerator = new DefaultRevisionInfoGenerator(
+ revisionInfoEntityName, revisionInfoClass,
+ revisionListenerClass, revisionInfoTimestampData, isTimestampAsDate()
+ );
+ }
+ }
+ }
- revisionInfoEntityName = pc.getEntityName();
- revisionInfoClass = pc.getMappedClass();
- Class extends RevisionListener> revisionListenerClass = getRevisionListenerClass(revisionEntity.value());
- revisionInfoTimestampType = pc.getProperty(revisionInfoTimestampData.getName()).getType();
- if (globalCfg.isTrackEntitiesChangedInRevision()
- || (globalCfg.isUseRevisionEntityWithNativeId() && DefaultTrackingModifiedEntitiesRevisionEntity.class.isAssignableFrom(revisionInfoClass))
- || (!globalCfg.isUseRevisionEntityWithNativeId() && SequenceIdTrackingModifiedEntitiesRevisionEntity.class.isAssignableFrom(revisionInfoClass))
- || modifiedEntityNamesFound.isSet()) {
- // If tracking modified entities parameter is enabled, custom revision info entity is a subtype
- // of DefaultTrackingModifiedEntitiesRevisionEntity class, or @ModifiedEntityNames annotation is used.
- revisionInfoGenerator = new DefaultTrackingModifiedEntitiesRevisionInfoGenerator(revisionInfoEntityName,
- revisionInfoClass, revisionListenerClass, revisionInfoTimestampData, isTimestampAsDate(),
- modifiedEntityNamesData);
- globalCfg.setTrackEntitiesChangedInRevision(true);
- } else {
- revisionInfoGenerator = new DefaultRevisionInfoGenerator(revisionInfoEntityName, revisionInfoClass,
- revisionListenerClass, revisionInfoTimestampData, isTimestampAsDate());
- }
- }
- }
+ // In case of a custom revision info generator, the mapping will be null.
+ Document revisionInfoXmlMapping = null;
- // In case of a custom revision info generator, the mapping will be null.
- Document revisionInfoXmlMapping = null;
+ final Class extends RevisionListener> revisionListenerClass = getRevisionListenerClass( RevisionListener.class );
- Class extends RevisionListener> revisionListenerClass = getRevisionListenerClass(RevisionListener.class);
+ if ( revisionInfoGenerator == null ) {
+ if ( globalCfg.isTrackEntitiesChangedInRevision() ) {
+ revisionInfoClass = globalCfg.isUseRevisionEntityWithNativeId() ?
+ DefaultTrackingModifiedEntitiesRevisionEntity.class
+ :
+ SequenceIdTrackingModifiedEntitiesRevisionEntity.class;
+ revisionInfoEntityName = revisionInfoClass.getName();
+ revisionInfoGenerator = new DefaultTrackingModifiedEntitiesRevisionInfoGenerator(
+ revisionInfoEntityName, revisionInfoClass,
+ revisionListenerClass, revisionInfoTimestampData, isTimestampAsDate(), modifiedEntityNamesData
+ );
+ }
+ else {
+ revisionInfoClass = globalCfg.isUseRevisionEntityWithNativeId() ? DefaultRevisionEntity.class
+ : SequenceIdRevisionEntity.class;
+ revisionInfoGenerator = new DefaultRevisionInfoGenerator(
+ revisionInfoEntityName, revisionInfoClass,
+ revisionListenerClass, revisionInfoTimestampData, isTimestampAsDate()
+ );
+ }
+ revisionInfoXmlMapping = generateDefaultRevisionInfoXmlMapping();
+ }
- if (revisionInfoGenerator == null) {
- if (globalCfg.isTrackEntitiesChangedInRevision()) {
- revisionInfoClass = globalCfg.isUseRevisionEntityWithNativeId() ? DefaultTrackingModifiedEntitiesRevisionEntity.class
- : SequenceIdTrackingModifiedEntitiesRevisionEntity.class;
- revisionInfoEntityName = revisionInfoClass.getName();
- revisionInfoGenerator = new DefaultTrackingModifiedEntitiesRevisionInfoGenerator(revisionInfoEntityName, revisionInfoClass,
- revisionListenerClass, revisionInfoTimestampData, isTimestampAsDate(), modifiedEntityNamesData);
- } else {
- revisionInfoClass = globalCfg.isUseRevisionEntityWithNativeId() ? DefaultRevisionEntity.class
- : SequenceIdRevisionEntity.class;
- revisionInfoGenerator = new DefaultRevisionInfoGenerator(revisionInfoEntityName, revisionInfoClass,
- revisionListenerClass, revisionInfoTimestampData, isTimestampAsDate());
- }
- revisionInfoXmlMapping = generateDefaultRevisionInfoXmlMapping();
- }
+ return new RevisionInfoConfigurationResult(
+ revisionInfoGenerator, revisionInfoXmlMapping,
+ new RevisionInfoQueryCreator(
+ revisionInfoEntityName, revisionInfoIdData.getName(),
+ revisionInfoTimestampData.getName(), isTimestampAsDate()
+ ),
+ generateRevisionInfoRelationMapping(),
+ new RevisionInfoNumberReader( revisionInfoClass, revisionInfoIdData ),
+ globalCfg.isTrackEntitiesChangedInRevision() ? new ModifiedEntityNamesReader(
+ revisionInfoClass,
+ modifiedEntityNamesData
+ )
+ : null,
+ revisionInfoEntityName, revisionInfoClass, revisionInfoTimestampData
+ );
+ }
- return new RevisionInfoConfigurationResult(
- revisionInfoGenerator, revisionInfoXmlMapping,
- new RevisionInfoQueryCreator(revisionInfoEntityName, revisionInfoIdData.getName(),
- revisionInfoTimestampData.getName(), isTimestampAsDate()),
- generateRevisionInfoRelationMapping(),
- new RevisionInfoNumberReader(revisionInfoClass, revisionInfoIdData),
- globalCfg.isTrackEntitiesChangedInRevision() ? new ModifiedEntityNamesReader(revisionInfoClass, modifiedEntityNamesData)
- : null,
- revisionInfoEntityName, revisionInfoClass, revisionInfoTimestampData);
- }
+ private boolean isTimestampAsDate() {
+ final String typename = revisionInfoTimestampType.getName();
+ return "date".equals( typename ) || "time".equals( typename ) || "timestamp".equals( typename );
+ }
- private boolean isTimestampAsDate() {
- String typename = revisionInfoTimestampType.getName();
- return "date".equals(typename) || "time".equals(typename) || "timestamp".equals(typename);
- }
-
- /**
- * @param defaultListener Revision listener that shall be applied if {@code org.hibernate.envers.revision_listener}
- * parameter has not been set.
- * @return Revision listener.
- */
- private Class extends RevisionListener> getRevisionListenerClass(Class extends RevisionListener> defaultListener) {
- if (globalCfg.getRevisionListenerClass() != null) {
- return globalCfg.getRevisionListenerClass();
- }
- return defaultListener;
- }
+ /**
+ * @param defaultListener Revision listener that shall be applied if {@code org.hibernate.envers.revision_listener}
+ * parameter has not been set.
+ *
+ * @return Revision listener.
+ */
+ private Class extends RevisionListener> getRevisionListenerClass(Class extends RevisionListener> defaultListener) {
+ if ( globalCfg.getRevisionListenerClass() != null ) {
+ return globalCfg.getRevisionListenerClass();
+ }
+ return defaultListener;
+ }
}
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/RevisionInfoConfigurationResult.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/RevisionInfoConfigurationResult.java
index 0b89067929..33267cfc33 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/RevisionInfoConfigurationResult.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/RevisionInfoConfigurationResult.java
@@ -1,3 +1,26 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2013, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
package org.hibernate.envers.configuration.internal;
import org.dom4j.Document;
@@ -23,11 +46,12 @@ public class RevisionInfoConfigurationResult {
private final Class> revisionInfoClass;
private final PropertyData revisionInfoTimestampData;
- RevisionInfoConfigurationResult(RevisionInfoGenerator revisionInfoGenerator,
- Document revisionInfoXmlMapping, RevisionInfoQueryCreator revisionInfoQueryCreator,
- Element revisionInfoRelationMapping, RevisionInfoNumberReader revisionInfoNumberReader,
- ModifiedEntityNamesReader modifiedEntityNamesReader, String revisionInfoEntityName,
- Class> revisionInfoClass, PropertyData revisionInfoTimestampData) {
+ RevisionInfoConfigurationResult(
+ RevisionInfoGenerator revisionInfoGenerator,
+ Document revisionInfoXmlMapping, RevisionInfoQueryCreator revisionInfoQueryCreator,
+ Element revisionInfoRelationMapping, RevisionInfoNumberReader revisionInfoNumberReader,
+ ModifiedEntityNamesReader modifiedEntityNamesReader, String revisionInfoEntityName,
+ Class> revisionInfoClass, PropertyData revisionInfoTimestampData) {
this.revisionInfoGenerator = revisionInfoGenerator;
this.revisionInfoXmlMapping = revisionInfoXmlMapping;
this.revisionInfoQueryCreator = revisionInfoQueryCreator;
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 c2d00fdcf6..8f5b76a05c 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
@@ -1,4 +1,28 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2013, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
package org.hibernate.envers.configuration.internal.metadata;
+
import java.util.HashSet;
import java.util.Set;
@@ -6,46 +30,49 @@ import org.hibernate.MappingException;
/**
* A register of all audit entity names used so far.
+ *
* @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.
- * @return True if the given audit entity name is already used.
- */
- private boolean check(String auditEntityName) {
- return auditEntityNames.contains(auditEntityName);
- }
-
- /**
- * Register an audit entity name. If the name is already registered, an exception is thrown.
- * @param auditEntityName Name of the audit entity.
- */
- public void register(String auditEntityName) {
- if (auditEntityNames.contains(auditEntityName)) {
- throw new MappingException("The audit entity name '" + auditEntityName + "' is already registered.");
- }
-
- auditEntityNames.add(auditEntityName);
- }
-
- /**
- * Creates a unique (not yet registered) audit entity name by appending consecutive numbers to the base
- * name. If the base name is not yet used, it is returned unmodified.
+ /**
+ * @param auditEntityName Name of the audit entity.
*
- * @param baseAuditEntityName The base entity name.
- *
- * @return A unique audit entity name
- */
- public String createUnique(final String baseAuditEntityName) {
- String auditEntityName = baseAuditEntityName;
- int count = 1;
- while (check(auditEntityName)) {
- auditEntityName = baseAuditEntityName + count++;
- }
+ * @return True if the given audit entity name is already used.
+ */
+ private boolean check(String auditEntityName) {
+ return auditEntityNames.contains( auditEntityName );
+ }
- return auditEntityName;
- }
+ /**
+ * Register an audit entity name. If the name is already registered, an exception is thrown.
+ *
+ * @param auditEntityName Name of the audit entity.
+ */
+ public void register(String auditEntityName) {
+ if ( auditEntityNames.contains( auditEntityName ) ) {
+ throw new MappingException( "The audit entity name '" + auditEntityName + "' is already registered." );
+ }
+
+ auditEntityNames.add( auditEntityName );
+ }
+
+ /**
+ * Creates a unique (not yet registered) audit entity name by appending consecutive numbers to the base
+ * name. If the base name is not yet used, it is returned unmodified.
+ *
+ * @param baseAuditEntityName The base entity name.
+ *
+ * @return A unique audit entity name
+ */
+ public String createUnique(final String baseAuditEntityName) {
+ String auditEntityName = baseAuditEntityName;
+ int count = 1;
+ while ( check( auditEntityName ) ) {
+ auditEntityName = baseAuditEntityName + count++;
+ }
+
+ return auditEntityName;
+ }
}
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 a0994f789e..a117e85c96 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
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2008, 2013, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -28,6 +28,7 @@ import java.util.Iterator;
import java.util.Map;
import org.dom4j.Element;
+
import org.jboss.logging.Logger;
import org.hibernate.MappingException;
@@ -73,124 +74,167 @@ import org.hibernate.type.Type;
* @author Michal Skowronek (mskowr at o2 dot pl)
*/
public final class AuditMetadataGenerator {
+ private static final EnversMessageLogger LOG = Logger.getMessageLogger(
+ EnversMessageLogger.class,
+ AuditMetadataGenerator.class.getName()
+ );
- public static final EnversMessageLogger LOG = Logger.getMessageLogger(EnversMessageLogger.class, AuditMetadataGenerator.class.getName());
-
- private final Configuration cfg;
- private final GlobalConfiguration globalCfg;
- private final AuditEntitiesConfiguration verEntCfg;
- private final AuditStrategy auditStrategy;
+ private final Configuration cfg;
+ private final GlobalConfiguration globalCfg;
+ private final AuditEntitiesConfiguration verEntCfg;
+ private final AuditStrategy auditStrategy;
private final ClassLoaderService classLoaderService;
- private final Element revisionInfoRelationMapping;
+ private final Element revisionInfoRelationMapping;
- /*
- * Generators for different kinds of property values/types.
- */
- private final BasicMetadataGenerator basicMetadataGenerator;
+ /*
+ * Generators for different kinds of property values/types.
+ */
+ private final BasicMetadataGenerator basicMetadataGenerator;
private final ComponentMetadataGenerator componentMetadataGenerator;
- private final IdMetadataGenerator idMetadataGenerator;
- private final ToOneRelationMetadataGenerator toOneRelationMetadataGenerator;
+ private final IdMetadataGenerator idMetadataGenerator;
+ private final ToOneRelationMetadataGenerator toOneRelationMetadataGenerator;
- /*
- * Here information about already generated mappings will be accumulated.
- */
- private final Map entitiesConfigurations;
- private final Map notAuditedEntitiesConfigurations;
+ /*
+ * Here information about already generated mappings will be accumulated.
+ */
+ private final Map entitiesConfigurations;
+ private final Map notAuditedEntitiesConfigurations;
- private final AuditEntityNameRegister auditEntityNameRegister;
+ private final AuditEntityNameRegister auditEntityNameRegister;
- // Map entity name -> (join descriptor -> element describing the "versioned" join)
- private final Map> entitiesJoins;
+ // Map entity name -> (join descriptor -> element describing the "versioned" join)
+ private final Map> entitiesJoins;
- public AuditMetadataGenerator(Configuration cfg, GlobalConfiguration globalCfg,
- AuditEntitiesConfiguration verEntCfg,
- AuditStrategy auditStrategy, ClassLoaderService classLoaderService,
- Element revisionInfoRelationMapping,
- AuditEntityNameRegister auditEntityNameRegister) {
- this.cfg = cfg;
- this.globalCfg = globalCfg;
- this.verEntCfg = verEntCfg;
- this.auditStrategy = auditStrategy;
+ public AuditMetadataGenerator(
+ Configuration cfg, GlobalConfiguration globalCfg,
+ AuditEntitiesConfiguration verEntCfg,
+ AuditStrategy auditStrategy, ClassLoaderService classLoaderService,
+ Element revisionInfoRelationMapping,
+ AuditEntityNameRegister auditEntityNameRegister) {
+ this.cfg = cfg;
+ this.globalCfg = globalCfg;
+ this.verEntCfg = verEntCfg;
+ this.auditStrategy = auditStrategy;
this.classLoaderService = classLoaderService;
- this.revisionInfoRelationMapping = revisionInfoRelationMapping;
+ this.revisionInfoRelationMapping = revisionInfoRelationMapping;
- this.basicMetadataGenerator = new BasicMetadataGenerator();
- this.componentMetadataGenerator = new ComponentMetadataGenerator(this);
- this.idMetadataGenerator = new IdMetadataGenerator(this);
- this.toOneRelationMetadataGenerator = new ToOneRelationMetadataGenerator(this);
+ this.basicMetadataGenerator = new BasicMetadataGenerator();
+ this.componentMetadataGenerator = new ComponentMetadataGenerator( this );
+ this.idMetadataGenerator = new IdMetadataGenerator( this );
+ this.toOneRelationMetadataGenerator = new ToOneRelationMetadataGenerator( this );
- this.auditEntityNameRegister = auditEntityNameRegister;
+ this.auditEntityNameRegister = auditEntityNameRegister;
- entitiesConfigurations = new HashMap();
- notAuditedEntitiesConfigurations = new HashMap();
- entitiesJoins = new HashMap>();
- }
+ entitiesConfigurations = new HashMap();
+ notAuditedEntitiesConfigurations = new HashMap();
+ entitiesJoins = new HashMap>();
+ }
- /**
- * Clones the revision info relation mapping, so that it can be added to other mappings. Also, the name of
- * the property and the column are set properly.
- * @return A revision info mapping, which can be added to other mappings (has no parent).
- */
- private Element cloneAndSetupRevisionInfoRelationMapping() {
- Element rev_mapping = (Element) revisionInfoRelationMapping.clone();
- rev_mapping.addAttribute("name", verEntCfg.getRevisionFieldName());
+ /**
+ * Clones the revision info relation mapping, so that it can be added to other mappings. Also, the name of
+ * the property and the column are set properly.
+ *
+ * @return A revision info mapping, which can be added to other mappings (has no parent).
+ */
+ private Element cloneAndSetupRevisionInfoRelationMapping() {
+ final Element revMapping = (Element) revisionInfoRelationMapping.clone();
+ revMapping.addAttribute( "name", verEntCfg.getRevisionFieldName() );
- MetadataTools.addOrModifyColumn(rev_mapping, verEntCfg.getRevisionFieldName());
+ MetadataTools.addOrModifyColumn( revMapping, verEntCfg.getRevisionFieldName() );
- return rev_mapping;
- }
+ return revMapping;
+ }
- void addRevisionInfoRelation(Element any_mapping) {
- any_mapping.add(cloneAndSetupRevisionInfoRelationMapping());
- }
+ void addRevisionInfoRelation(Element anyMapping) {
+ anyMapping.add( cloneAndSetupRevisionInfoRelationMapping() );
+ }
- void addRevisionType(Element any_mapping, Element any_mapping_end) {
- Element revTypeProperty = MetadataTools.addProperty(any_mapping, verEntCfg.getRevisionTypePropName(),
- verEntCfg.getRevisionTypePropType(), true, false);
- revTypeProperty.addAttribute("type", "org.hibernate.envers.internal.entities.RevisionTypeType");
+ void addRevisionType(Element anyMapping, Element anyMappingEnd) {
+ final Element revTypeProperty = MetadataTools.addProperty(
+ anyMapping,
+ verEntCfg.getRevisionTypePropName(),
+ verEntCfg.getRevisionTypePropType(),
+ true,
+ false
+ );
+ revTypeProperty.addAttribute( "type", "org.hibernate.envers.internal.entities.RevisionTypeType" );
- // Adding the end revision, if appropriate
- addEndRevision(any_mapping_end);
- }
+ // Adding the end revision, if appropriate
+ addEndRevision( anyMappingEnd );
+ }
- private void addEndRevision(Element any_mapping ) {
- // Add the end-revision field, if the appropriate strategy is used.
- if (auditStrategy instanceof ValidityAuditStrategy) {
- Element end_rev_mapping = (Element) revisionInfoRelationMapping.clone();
- end_rev_mapping.setName("many-to-one");
- end_rev_mapping.addAttribute("name", verEntCfg.getRevisionEndFieldName());
- MetadataTools.addOrModifyColumn(end_rev_mapping, verEntCfg.getRevisionEndFieldName());
+ private void addEndRevision(Element anyMapping) {
+ // Add the end-revision field, if the appropriate strategy is used.
+ if ( auditStrategy instanceof ValidityAuditStrategy ) {
+ final Element endRevMapping = (Element) revisionInfoRelationMapping.clone();
+ endRevMapping.setName( "many-to-one" );
+ endRevMapping.addAttribute( "name", verEntCfg.getRevisionEndFieldName() );
+ MetadataTools.addOrModifyColumn( endRevMapping, verEntCfg.getRevisionEndFieldName() );
- any_mapping.add(end_rev_mapping);
+ anyMapping.add( endRevMapping );
- if (verEntCfg.isRevisionEndTimestampEnabled()) {
- // add a column for the timestamp of the end revision
- String revisionInfoTimestampSqlType = TimestampType.INSTANCE.getName();
- Element timestampProperty = MetadataTools.addProperty(any_mapping, verEntCfg.getRevisionEndTimestampFieldName(), revisionInfoTimestampSqlType, true, true, false);
- MetadataTools.addColumn(timestampProperty, verEntCfg.getRevisionEndTimestampFieldName(), null, null, null, null, null, null);
- }
- }
- }
+ if ( verEntCfg.isRevisionEndTimestampEnabled() ) {
+ // add a column for the timestamp of the end revision
+ final String revisionInfoTimestampSqlType = TimestampType.INSTANCE.getName();
+ final Element timestampProperty = MetadataTools.addProperty(
+ anyMapping,
+ verEntCfg.getRevisionEndTimestampFieldName(),
+ revisionInfoTimestampSqlType,
+ true,
+ true,
+ false
+ );
+ MetadataTools.addColumn(
+ timestampProperty,
+ verEntCfg.getRevisionEndTimestampFieldName(),
+ null,
+ null,
+ null,
+ null,
+ null,
+ null
+ );
+ }
+ }
+ }
- private void addValueInFirstPass(Element parent, Value value, CompositeMapperBuilder currentMapper, String entityName,
- EntityXmlMappingData xmlMappingData, PropertyAuditingData propertyAuditingData,
- boolean insertable, boolean processModifiedFlag) {
- Type type = value.getType();
+ private void addValueInFirstPass(
+ Element parent,
+ Value value,
+ CompositeMapperBuilder currentMapper,
+ String entityName,
+ EntityXmlMappingData xmlMappingData,
+ PropertyAuditingData propertyAuditingData,
+ boolean insertable,
+ boolean processModifiedFlag) {
+ final Type type = value.getType();
+ final boolean isBasic = basicMetadataGenerator.addBasic(
+ parent,
+ propertyAuditingData,
+ value,
+ currentMapper,
+ insertable,
+ false
+ );
- if (basicMetadataGenerator.addBasic(parent, propertyAuditingData, value, currentMapper, insertable, false)) {
+ if ( isBasic ) {
// The property was mapped by the basic generator.
- } else if (type instanceof ComponentType) {
- componentMetadataGenerator.addComponent(parent, propertyAuditingData, value, currentMapper,
- entityName, xmlMappingData, true);
- } else {
- if (!processedInSecondPass(type)) {
+ }
+ else if ( type instanceof ComponentType ) {
+ componentMetadataGenerator.addComponent(
+ parent, propertyAuditingData, value, currentMapper,
+ entityName, xmlMappingData, true
+ );
+ }
+ else {
+ if ( !processedInSecondPass( type ) ) {
// If we got here in the first pass, it means the basic mapper didn't map it, and none of the
// above branches either.
- throwUnsupportedTypeException(type, entityName, propertyAuditingData.getName());
+ throwUnsupportedTypeException( type, entityName, propertyAuditingData.getName() );
}
return;
}
- addModifiedFlagIfNeeded(parent, propertyAuditingData, processModifiedFlag);
+ addModifiedFlagIfNeeded( parent, propertyAuditingData, processModifiedFlag );
}
private boolean processedInSecondPass(Type type) {
@@ -198,79 +242,143 @@ public final class AuditMetadataGenerator {
type instanceof OneToOneType || type instanceof CollectionType;
}
- private void addValueInSecondPass(Element parent, Value value, CompositeMapperBuilder currentMapper, String entityName,
- EntityXmlMappingData xmlMappingData, PropertyAuditingData propertyAuditingData,
- boolean insertable, boolean processModifiedFlag) {
- Type type = value.getType();
+ private void addValueInSecondPass(
+ Element parent,
+ Value value,
+ CompositeMapperBuilder currentMapper,
+ String entityName,
+ EntityXmlMappingData xmlMappingData,
+ PropertyAuditingData propertyAuditingData,
+ boolean insertable,
+ boolean processModifiedFlag) {
+ final Type type = value.getType();
- if (type instanceof ComponentType) {
- componentMetadataGenerator.addComponent(parent, propertyAuditingData, value, currentMapper,
- entityName, xmlMappingData, false);
- return;// mod flag field has been already generated in first pass
- } else if (type instanceof ManyToOneType) {
- toOneRelationMetadataGenerator.addToOne(parent, propertyAuditingData, value, currentMapper,
- entityName, insertable);
- } else if (type instanceof OneToOneType) {
- OneToOne oneToOne = (OneToOne) value;
- if (oneToOne.getReferencedPropertyName() != null) {
- toOneRelationMetadataGenerator.addOneToOneNotOwning(propertyAuditingData, value,
- currentMapper, entityName);
- } else {
- // @OneToOne relation marked with @PrimaryKeyJoinColumn
- toOneRelationMetadataGenerator.addOneToOnePrimaryKeyJoinColumn(propertyAuditingData, value,
- currentMapper, entityName, insertable);
- }
- } else if (type instanceof CollectionType) {
- CollectionMetadataGenerator collectionMetadataGenerator = new CollectionMetadataGenerator(this,
- (Collection) value, currentMapper, entityName, xmlMappingData,
- propertyAuditingData);
- collectionMetadataGenerator.addCollection();
- } else {
+ if ( type instanceof ComponentType ) {
+ componentMetadataGenerator.addComponent(
+ parent,
+ propertyAuditingData,
+ value,
+ currentMapper,
+ entityName,
+ xmlMappingData,
+ false
+ );
+ // mod flag field has been already generated in first pass
return;
}
- addModifiedFlagIfNeeded(parent, propertyAuditingData, processModifiedFlag);
+ else if ( type instanceof ManyToOneType ) {
+ toOneRelationMetadataGenerator.addToOne(
+ parent,
+ propertyAuditingData,
+ value,
+ currentMapper,
+ entityName,
+ insertable
+ );
+ }
+ else if ( type instanceof OneToOneType ) {
+ final OneToOne oneToOne = (OneToOne) value;
+ if ( oneToOne.getReferencedPropertyName() != null ) {
+ toOneRelationMetadataGenerator.addOneToOneNotOwning(
+ propertyAuditingData,
+ value,
+ currentMapper,
+ entityName
+ );
+ }
+ else {
+ // @OneToOne relation marked with @PrimaryKeyJoinColumn
+ toOneRelationMetadataGenerator.addOneToOnePrimaryKeyJoinColumn(
+ propertyAuditingData,
+ value,
+ currentMapper,
+ entityName,
+ insertable
+ );
+ }
+ }
+ else if ( type instanceof CollectionType ) {
+ final CollectionMetadataGenerator collectionMetadataGenerator = new CollectionMetadataGenerator(
+ this,
+ (Collection) value,
+ currentMapper,
+ entityName,
+ xmlMappingData,
+ propertyAuditingData
+ );
+ collectionMetadataGenerator.addCollection();
+ }
+ else {
+ return;
+ }
+ addModifiedFlagIfNeeded( parent, propertyAuditingData, processModifiedFlag );
}
- private void addModifiedFlagIfNeeded(Element parent, PropertyAuditingData propertyAuditingData, boolean processModifiedFlag) {
- if (processModifiedFlag && propertyAuditingData.isUsingModifiedFlag()) {
- MetadataTools.addModifiedFlagProperty(parent,
+ private void addModifiedFlagIfNeeded(
+ Element parent,
+ PropertyAuditingData propertyAuditingData,
+ boolean processModifiedFlag) {
+ if ( processModifiedFlag && propertyAuditingData.isUsingModifiedFlag() ) {
+ MetadataTools.addModifiedFlagProperty(
+ parent,
propertyAuditingData.getName(),
- globalCfg.getModifiedFlagSuffix());
+ globalCfg.getModifiedFlagSuffix()
+ );
}
}
- void addValue(Element parent, Value value, CompositeMapperBuilder currentMapper, String entityName,
- EntityXmlMappingData xmlMappingData, PropertyAuditingData propertyAuditingData,
- boolean insertable, boolean firstPass, boolean processModifiedFlag) {
- if (firstPass) {
- addValueInFirstPass(parent, value, currentMapper, entityName,
- xmlMappingData, propertyAuditingData, insertable, processModifiedFlag);
- } else {
- addValueInSecondPass(parent, value, currentMapper, entityName,
- xmlMappingData, propertyAuditingData, insertable, processModifiedFlag);
+ void addValue(
+ Element parent, Value value, CompositeMapperBuilder currentMapper, String entityName,
+ EntityXmlMappingData xmlMappingData, PropertyAuditingData propertyAuditingData,
+ boolean insertable, boolean firstPass, boolean processModifiedFlag) {
+ if ( firstPass ) {
+ addValueInFirstPass(
+ parent, value, currentMapper, entityName,
+ xmlMappingData, propertyAuditingData, insertable, processModifiedFlag
+ );
+ }
+ else {
+ addValueInSecondPass(
+ parent, value, currentMapper, entityName,
+ xmlMappingData, propertyAuditingData, insertable, processModifiedFlag
+ );
}
}
- private void addProperties(Element parent, Iterator properties, CompositeMapperBuilder currentMapper,
- ClassAuditingData auditingData, String entityName, EntityXmlMappingData xmlMappingData,
- boolean firstPass) {
- while (properties.hasNext()) {
- Property property = properties.next();
- String propertyName = property.getName();
- PropertyAuditingData propertyAuditingData = auditingData.getPropertyAuditingData(propertyName);
- if (propertyAuditingData != null) {
- addValue(parent, property.getValue(), currentMapper, entityName, xmlMappingData, propertyAuditingData,
- property.isInsertable(), firstPass, true);
- }
- }
- }
+ private void addProperties(
+ Element parent,
+ Iterator properties,
+ CompositeMapperBuilder currentMapper,
+ ClassAuditingData auditingData,
+ String entityName,
+ EntityXmlMappingData xmlMappingData,
+ boolean firstPass) {
+ while ( properties.hasNext() ) {
+ final Property property = properties.next();
+ final String propertyName = property.getName();
+ final PropertyAuditingData propertyAuditingData = auditingData.getPropertyAuditingData( propertyName );
+ if ( propertyAuditingData != null ) {
+ addValue(
+ parent,
+ property.getValue(),
+ currentMapper,
+ entityName,
+ xmlMappingData,
+ propertyAuditingData,
+ property.isInsertable(),
+ firstPass,
+ true
+ );
+ }
+ }
+ }
private boolean checkPropertiesAudited(Iterator properties, ClassAuditingData auditingData) {
- while (properties.hasNext()) {
- Property property = properties.next();
- String propertyName = property.getName();
- PropertyAuditingData propertyAuditingData = auditingData.getPropertyAuditingData(propertyName);
- if (propertyAuditingData == null) {
+ while ( properties.hasNext() ) {
+ final Property property = properties.next();
+ final String propertyName = property.getName();
+ final PropertyAuditingData propertyAuditingData = auditingData.getPropertyAuditingData( propertyName );
+ if ( propertyAuditingData == null ) {
return false;
}
}
@@ -278,325 +386,385 @@ public final class AuditMetadataGenerator {
return true;
}
- protected String getSchema(String schemaFromAnnotation, Table table) {
- // Get the schema from the annotation ...
- String schema = schemaFromAnnotation;
- // ... if empty, try using the default ...
- if (StringTools.isEmpty(schema)) {
- schema = globalCfg.getDefaultSchemaName();
+ protected String getSchema(String schemaFromAnnotation, Table table) {
+ // Get the schema from the annotation ...
+ String schema = schemaFromAnnotation;
+ // ... if empty, try using the default ...
+ if ( StringTools.isEmpty( schema ) ) {
+ schema = globalCfg.getDefaultSchemaName();
- // ... if still empty, use the same as the normal table.
- if (StringTools.isEmpty(schema)) {
- schema = table.getSchema();
- }
- }
+ // ... if still empty, use the same as the normal table.
+ if ( StringTools.isEmpty( schema ) ) {
+ schema = table.getSchema();
+ }
+ }
- return schema;
- }
+ return schema;
+ }
- protected String getCatalog(String catalogFromAnnotation, Table table) {
- // Get the catalog from the annotation ...
- String catalog = catalogFromAnnotation;
- // ... if empty, try using the default ...
- if (StringTools.isEmpty(catalog)) {
- catalog = globalCfg.getDefaultCatalogName();
+ protected String getCatalog(String catalogFromAnnotation, Table table) {
+ // Get the catalog from the annotation ...
+ String catalog = catalogFromAnnotation;
+ // ... if empty, try using the default ...
+ if ( StringTools.isEmpty( catalog ) ) {
+ catalog = globalCfg.getDefaultCatalogName();
- // ... if still empty, use the same as the normal table.
- if (StringTools.isEmpty(catalog)) {
- catalog = table.getCatalog();
- }
- }
+ // ... if still empty, use the same as the normal table.
+ if ( StringTools.isEmpty( catalog ) ) {
+ catalog = table.getCatalog();
+ }
+ }
- return catalog;
- }
+ return catalog;
+ }
- @SuppressWarnings({"unchecked"})
- private void createJoins(PersistentClass pc, Element parent, ClassAuditingData auditingData) {
- Iterator joins = pc.getJoinIterator();
+ @SuppressWarnings({"unchecked"})
+ private void createJoins(PersistentClass pc, Element parent, ClassAuditingData auditingData) {
+ final Iterator joins = pc.getJoinIterator();
+ final Map joinElements = new HashMap();
+ entitiesJoins.put( pc.getEntityName(), joinElements );
- Map joinElements = new HashMap();
- entitiesJoins.put(pc.getEntityName(), joinElements);
-
- while (joins.hasNext()) {
- Join join = joins.next();
+ while ( joins.hasNext() ) {
+ Join join = joins.next();
// Checking if all of the join properties are audited
- if (!checkPropertiesAudited(join.getPropertyIterator(), auditingData)) {
+ if ( !checkPropertiesAudited( join.getPropertyIterator(), auditingData ) ) {
continue;
}
- // Determining the table name. If there is no entry in the dictionary, just constructing the table name
- // as if it was an entity (by appending/prepending configured strings).
- String originalTableName = join.getTable().getName();
- String auditTableName = auditingData.getSecondaryTableDictionary().get(originalTableName);
- if (auditTableName == null) {
- auditTableName = verEntCfg.getAuditEntityName(originalTableName);
- }
-
- String schema = getSchema(auditingData.getAuditTable().schema(), join.getTable());
- String catalog = getCatalog(auditingData.getAuditTable().catalog(), join.getTable());
-
- Element joinElement = MetadataTools.createJoin(parent, auditTableName, schema, catalog);
- joinElements.put(join, joinElement);
-
- Element joinKey = joinElement.addElement("key");
- MetadataTools.addColumns(joinKey, join.getKey().getColumnIterator());
- MetadataTools.addColumn(joinKey, verEntCfg.getRevisionFieldName(), null, null, null, null, null, null);
- }
- }
-
- @SuppressWarnings({"unchecked"})
- private void addJoins(PersistentClass pc, CompositeMapperBuilder currentMapper, ClassAuditingData auditingData,
- String entityName, EntityXmlMappingData xmlMappingData,boolean firstPass) {
- Iterator joins = pc.getJoinIterator();
-
- while (joins.hasNext()) {
- Join join = joins.next();
- Element joinElement = entitiesJoins.get(entityName).get(join);
-
- if (joinElement != null) {
- addProperties(joinElement, join.getPropertyIterator(), currentMapper, auditingData, entityName,
- xmlMappingData, firstPass);
+ // Determining the table name. If there is no entry in the dictionary, just constructing the table name
+ // as if it was an entity (by appending/prepending configured strings).
+ final String originalTableName = join.getTable().getName();
+ String auditTableName = auditingData.getSecondaryTableDictionary().get( originalTableName );
+ if ( auditTableName == null ) {
+ auditTableName = verEntCfg.getAuditEntityName( originalTableName );
}
- }
- }
- @SuppressWarnings({"unchecked"})
- private Triple generateMappingData(
- PersistentClass pc, EntityXmlMappingData xmlMappingData, AuditTableData auditTableData,
- IdMappingData idMapper) {
- Element class_mapping = MetadataTools.createEntity(xmlMappingData.getMainXmlMapping(), auditTableData,
- pc.getDiscriminatorValue(), pc.isAbstract());
- ExtendedPropertyMapper propertyMapper = new MultiPropertyMapper();
+ final String schema = getSchema( auditingData.getAuditTable().schema(), join.getTable() );
+ final String catalog = getCatalog( auditingData.getAuditTable().catalog(), join.getTable() );
- // Checking if there is a discriminator column
- if (pc.getDiscriminator() != null) {
- Element discriminator_element = class_mapping.addElement("discriminator");
- // Database column or SQL formula allowed to distinguish entity types
- MetadataTools.addColumnsOrFormulas(discriminator_element, pc.getDiscriminator().getColumnIterator());
- discriminator_element.addAttribute("type", pc.getDiscriminator().getType().getName());
- }
+ final Element joinElement = MetadataTools.createJoin( parent, auditTableName, schema, catalog );
+ joinElements.put( join, joinElement );
- // Adding the id mapping
- class_mapping.add((Element) idMapper.getXmlMapping().clone());
+ final Element joinKey = joinElement.addElement( "key" );
+ MetadataTools.addColumns( joinKey, join.getKey().getColumnIterator() );
+ MetadataTools.addColumn( joinKey, verEntCfg.getRevisionFieldName(), null, null, null, null, null, null );
+ }
+ }
- // Adding the "revision type" property
- addRevisionType(class_mapping, class_mapping);
+ @SuppressWarnings({"unchecked"})
+ private void addJoins(
+ PersistentClass pc,
+ CompositeMapperBuilder currentMapper,
+ ClassAuditingData auditingData,
+ String entityName,
+ EntityXmlMappingData xmlMappingData,
+ boolean firstPass) {
+ final Iterator joins = pc.getJoinIterator();
- return Triple.make(class_mapping, propertyMapper, null);
- }
+ while ( joins.hasNext() ) {
+ final Join join = joins.next();
+ final Element joinElement = entitiesJoins.get( entityName ).get( join );
- private Triple generateInheritanceMappingData(
- PersistentClass pc, EntityXmlMappingData xmlMappingData, AuditTableData auditTableData,
- String inheritanceMappingType) {
- String extendsEntityName = verEntCfg.getAuditEntityName(pc.getSuperclass().getEntityName());
- Element class_mapping = MetadataTools.createSubclassEntity(xmlMappingData.getMainXmlMapping(),
- inheritanceMappingType, auditTableData, extendsEntityName, pc.getDiscriminatorValue(), pc.isAbstract());
+ if ( joinElement != null ) {
+ addProperties(
+ joinElement,
+ join.getPropertyIterator(),
+ currentMapper,
+ auditingData,
+ entityName,
+ xmlMappingData,
+ firstPass
+ );
+ }
+ }
+ }
- // The id and revision type is already mapped in the parent
+ @SuppressWarnings({"unchecked"})
+ private Triple generateMappingData(
+ PersistentClass pc, EntityXmlMappingData xmlMappingData, AuditTableData auditTableData,
+ IdMappingData idMapper) {
+ final Element classMapping = MetadataTools.createEntity(
+ xmlMappingData.getMainXmlMapping(),
+ auditTableData,
+ pc.getDiscriminatorValue(),
+ pc.isAbstract()
+ );
+ final ExtendedPropertyMapper propertyMapper = new MultiPropertyMapper();
- // Getting the property mapper of the parent - when mapping properties, they need to be included
- String parentEntityName = pc.getSuperclass().getEntityName();
+ // Checking if there is a discriminator column
+ if ( pc.getDiscriminator() != null ) {
+ final Element discriminatorElement = classMapping.addElement( "discriminator" );
+ // Database column or SQL formula allowed to distinguish entity types
+ MetadataTools.addColumnsOrFormulas( discriminatorElement, pc.getDiscriminator().getColumnIterator() );
+ discriminatorElement.addAttribute( "type", pc.getDiscriminator().getType().getName() );
+ }
- EntityConfiguration parentConfiguration = entitiesConfigurations.get(parentEntityName);
- if (parentConfiguration == null) {
- throw new MappingException("Entity '" + pc.getEntityName() + "' is audited, but its superclass: '" +
- parentEntityName + "' is not.");
- }
+ // Adding the id mapping
+ classMapping.add( (Element) idMapper.getXmlMapping().clone() );
- ExtendedPropertyMapper parentPropertyMapper = parentConfiguration.getPropertyMapper();
- ExtendedPropertyMapper propertyMapper = new SubclassPropertyMapper(new MultiPropertyMapper(), parentPropertyMapper);
+ // Adding the "revision type" property
+ addRevisionType( classMapping, classMapping );
- return Triple.make(class_mapping, propertyMapper, parentEntityName);
- }
+ return Triple.make( classMapping, propertyMapper, null );
+ }
- @SuppressWarnings({"unchecked"})
- public void generateFirstPass(PersistentClass pc, ClassAuditingData auditingData,
- EntityXmlMappingData xmlMappingData, boolean isAudited) {
- String schema = getSchema(auditingData.getAuditTable().schema(), pc.getTable());
- String catalog = getCatalog(auditingData.getAuditTable().catalog(), pc.getTable());
+ private Triple generateInheritanceMappingData(
+ PersistentClass pc, EntityXmlMappingData xmlMappingData, AuditTableData auditTableData,
+ String inheritanceMappingType) {
+ final String extendsEntityName = verEntCfg.getAuditEntityName( pc.getSuperclass().getEntityName() );
+ final Element classMapping = MetadataTools.createSubclassEntity(
+ xmlMappingData.getMainXmlMapping(),
+ inheritanceMappingType,
+ auditTableData,
+ extendsEntityName,
+ pc.getDiscriminatorValue(),
+ pc.isAbstract()
+ );
- if (!isAudited) {
- String entityName = pc.getEntityName();
- IdMappingData idMapper = idMetadataGenerator.addId(pc, false);
+ // The id and revision type is already mapped in the parent
- if (idMapper == null) {
- // Unsupported id mapping, e.g. key-many-to-one. If the entity is used in auditing, an exception
- // will be thrown later on.
- LOG.debugf("Unable to create auditing id mapping for entity %s, because of an unsupported Hibernate id mapping (e.g. key-many-to-one)",
- entityName);
- return;
- }
+ // Getting the property mapper of the parent - when mapping properties, they need to be included
+ final String parentEntityName = pc.getSuperclass().getEntityName();
- ExtendedPropertyMapper propertyMapper = null;
- String parentEntityName = null;
- EntityConfiguration entityCfg = new EntityConfiguration(entityName, pc.getClassName(), idMapper, propertyMapper,
- parentEntityName);
- notAuditedEntitiesConfigurations.put(entityName, entityCfg);
+ final EntityConfiguration parentConfiguration = entitiesConfigurations.get( parentEntityName );
+ if ( parentConfiguration == null ) {
+ throw new MappingException(
+ "Entity '" + pc.getEntityName() + "' is audited, but its superclass: '" +
+ parentEntityName + "' is not."
+ );
+ }
+
+ final ExtendedPropertyMapper parentPropertyMapper = parentConfiguration.getPropertyMapper();
+ final ExtendedPropertyMapper propertyMapper = new SubclassPropertyMapper(
+ new MultiPropertyMapper(),
+ parentPropertyMapper
+ );
+
+ return Triple.make( classMapping, propertyMapper, parentEntityName );
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public void generateFirstPass(
+ PersistentClass pc,
+ ClassAuditingData auditingData,
+ EntityXmlMappingData xmlMappingData,
+ boolean isAudited) {
+ final String schema = getSchema( auditingData.getAuditTable().schema(), pc.getTable() );
+ final String catalog = getCatalog( auditingData.getAuditTable().catalog(), pc.getTable() );
+
+ if ( !isAudited ) {
+ final String entityName = pc.getEntityName();
+ final IdMappingData idMapper = idMetadataGenerator.addId( pc, false );
+
+ if ( idMapper == null ) {
+ // Unsupported id mapping, e.g. key-many-to-one. If the entity is used in auditing, an exception
+ // will be thrown later on.
+ LOG.debugf(
+ "Unable to create auditing id mapping for entity %s, because of an unsupported Hibernate id mapping (e.g. key-many-to-one)",
+ entityName
+ );
+ return;
+ }
+
+ final ExtendedPropertyMapper propertyMapper = null;
+ final String parentEntityName = null;
+ final EntityConfiguration entityCfg = new EntityConfiguration(
+ entityName,
+ pc.getClassName(),
+ idMapper,
+ propertyMapper,
+ parentEntityName
+ );
+ notAuditedEntitiesConfigurations.put( entityName, entityCfg );
return;
}
- String entityName = pc.getEntityName();
- LOG.debugf("Generating first-pass auditing mapping for entity %s", entityName);
+ final String entityName = pc.getEntityName();
+ LOG.debugf( "Generating first-pass auditing mapping for entity %s", entityName );
- String auditEntityName = verEntCfg.getAuditEntityName(entityName);
- String auditTableName = verEntCfg.getAuditTableName(entityName, pc.getTable().getName());
+ final String auditEntityName = verEntCfg.getAuditEntityName( entityName );
+ final String auditTableName = verEntCfg.getAuditTableName( entityName, pc.getTable().getName() );
- // Registering the audit entity name, now that it is known
- auditEntityNameRegister.register(auditEntityName);
+ // Registering the audit entity name, now that it is known
+ auditEntityNameRegister.register( auditEntityName );
- AuditTableData auditTableData = new AuditTableData(auditEntityName, auditTableName, schema, catalog);
+ final AuditTableData auditTableData = new AuditTableData( auditEntityName, auditTableName, schema, catalog );
- // Generating a mapping for the id
- IdMappingData idMapper = idMetadataGenerator.addId(pc, true);
+ // Generating a mapping for the id
+ final IdMappingData idMapper = idMetadataGenerator.addId( pc, true );
- InheritanceType inheritanceType = InheritanceType.get(pc);
+ final InheritanceType inheritanceType = InheritanceType.get( pc );
- // These properties will be read from the mapping data
- final Element class_mapping;
- final ExtendedPropertyMapper propertyMapper;
- final String parentEntityName;
+ // These properties will be read from the mapping data
+ final Element classMapping;
+ final ExtendedPropertyMapper propertyMapper;
+ final String parentEntityName;
- final Triple mappingData;
+ final Triple mappingData;
- // Reading the mapping data depending on inheritance type (if any)
- switch (inheritanceType) {
- case NONE:
- mappingData = generateMappingData(pc, xmlMappingData, auditTableData, idMapper);
- break;
+ // Reading the mapping data depending on inheritance type (if any)
+ switch ( inheritanceType ) {
+ case NONE:
+ mappingData = generateMappingData( pc, xmlMappingData, auditTableData, idMapper );
+ break;
- case SINGLE:
- mappingData = generateInheritanceMappingData(pc, xmlMappingData, auditTableData, "subclass");
- break;
+ case SINGLE:
+ mappingData = generateInheritanceMappingData( pc, xmlMappingData, auditTableData, "subclass" );
+ break;
- case JOINED:
- mappingData = generateInheritanceMappingData(pc, xmlMappingData, auditTableData, "joined-subclass");
+ case JOINED:
+ mappingData = generateInheritanceMappingData( pc, xmlMappingData, auditTableData, "joined-subclass" );
- // Adding the "key" element with all id columns...
- Element keyMapping = mappingData.getFirst().addElement("key");
- MetadataTools.addColumns(keyMapping, pc.getTable().getPrimaryKey().columnIterator());
+ // Adding the "key" element with all id columns...
+ final Element keyMapping = mappingData.getFirst().addElement( "key" );
+ MetadataTools.addColumns( keyMapping, pc.getTable().getPrimaryKey().columnIterator() );
- // ... and the revision number column, read from the revision info relation mapping.
- keyMapping.add((Element) cloneAndSetupRevisionInfoRelationMapping().element("column").clone());
- break;
+ // ... and the revision number column, read from the revision info relation mapping.
+ keyMapping.add( (Element) cloneAndSetupRevisionInfoRelationMapping().element( "column" ).clone() );
+ break;
- case TABLE_PER_CLASS:
- mappingData = generateInheritanceMappingData(pc, xmlMappingData, auditTableData, "union-subclass");
- break;
+ case TABLE_PER_CLASS:
+ mappingData = generateInheritanceMappingData( pc, xmlMappingData, auditTableData, "union-subclass" );
+ break;
- default:
- throw new AssertionError("Impossible enum value.");
- }
+ default:
+ throw new AssertionError( "Impossible enum value." );
+ }
- class_mapping = mappingData.getFirst();
- propertyMapper = mappingData.getSecond();
- parentEntityName = mappingData.getThird();
+ classMapping = mappingData.getFirst();
+ propertyMapper = mappingData.getSecond();
+ parentEntityName = mappingData.getThird();
- xmlMappingData.setClassMapping(class_mapping);
+ xmlMappingData.setClassMapping( classMapping );
- // Mapping unjoined properties
- addProperties(class_mapping, pc.getUnjoinedPropertyIterator(), propertyMapper,
- auditingData, pc.getEntityName(), xmlMappingData,
- true);
+ // Mapping unjoined properties
+ addProperties(
+ classMapping, pc.getUnjoinedPropertyIterator(), propertyMapper,
+ auditingData, pc.getEntityName(), xmlMappingData,
+ true
+ );
- // Creating and mapping joins (first pass)
- createJoins(pc, class_mapping, auditingData);
- addJoins(pc, propertyMapper, auditingData, pc.getEntityName(), xmlMappingData, true);
+ // Creating and mapping joins (first pass)
+ createJoins( pc, classMapping, auditingData );
+ addJoins( pc, propertyMapper, auditingData, pc.getEntityName(), xmlMappingData, true );
- // Storing the generated configuration
- EntityConfiguration entityCfg = new EntityConfiguration(auditEntityName, pc.getClassName(), idMapper,
- propertyMapper, parentEntityName);
- entitiesConfigurations.put(pc.getEntityName(), entityCfg);
- }
+ // Storing the generated configuration
+ final EntityConfiguration entityCfg = new EntityConfiguration(
+ auditEntityName,
+ pc.getClassName(),
+ idMapper,
+ propertyMapper,
+ parentEntityName
+ );
+ entitiesConfigurations.put( pc.getEntityName(), entityCfg );
+ }
- @SuppressWarnings({"unchecked"})
- public void generateSecondPass(PersistentClass pc, ClassAuditingData auditingData,
- EntityXmlMappingData xmlMappingData) {
- String entityName = pc.getEntityName();
- LOG.debugf("Generating second-pass auditing mapping for entity %s", entityName);
+ @SuppressWarnings({"unchecked"})
+ public void generateSecondPass(
+ PersistentClass pc,
+ ClassAuditingData auditingData,
+ EntityXmlMappingData xmlMappingData) {
+ final String entityName = pc.getEntityName();
+ LOG.debugf( "Generating second-pass auditing mapping for entity %s", entityName );
- CompositeMapperBuilder propertyMapper = entitiesConfigurations.get(entityName).getPropertyMapper();
+ final CompositeMapperBuilder propertyMapper = entitiesConfigurations.get( entityName ).getPropertyMapper();
- // Mapping unjoined properties
- Element parent = xmlMappingData.getClassMapping();
+ // Mapping unjoined properties
+ final Element parent = xmlMappingData.getClassMapping();
- addProperties(parent, pc.getUnjoinedPropertyIterator(),
- propertyMapper, auditingData, entityName, xmlMappingData, false);
+ addProperties(
+ parent,
+ pc.getUnjoinedPropertyIterator(),
+ propertyMapper,
+ auditingData,
+ entityName,
+ xmlMappingData,
+ false
+ );
- // Mapping joins (second pass)
- addJoins(pc, propertyMapper, auditingData, entityName, xmlMappingData, false);
- }
+ // Mapping joins (second pass)
+ addJoins( pc, propertyMapper, auditingData, entityName, xmlMappingData, false );
+ }
- public Map getEntitiesConfigurations() {
- return entitiesConfigurations;
- }
+ public Map getEntitiesConfigurations() {
+ return entitiesConfigurations;
+ }
- // Getters for generators and configuration
+ // Getters for generators and configuration
- BasicMetadataGenerator getBasicMetadataGenerator() {
- return basicMetadataGenerator;
- }
+ BasicMetadataGenerator getBasicMetadataGenerator() {
+ return basicMetadataGenerator;
+ }
- Configuration getCfg() {
- return cfg;
- }
+ Configuration getCfg() {
+ return cfg;
+ }
- GlobalConfiguration getGlobalCfg() {
- return globalCfg;
- }
+ GlobalConfiguration getGlobalCfg() {
+ return globalCfg;
+ }
- AuditEntitiesConfiguration getVerEntCfg() {
- return verEntCfg;
- }
+ AuditEntitiesConfiguration getVerEntCfg() {
+ return verEntCfg;
+ }
- AuditStrategy getAuditStrategy() {
- return auditStrategy;
- }
+ AuditStrategy getAuditStrategy() {
+ return auditStrategy;
+ }
ClassLoaderService getClassLoaderService() {
return classLoaderService;
}
- AuditEntityNameRegister getAuditEntityNameRegister() {
- return auditEntityNameRegister;
- }
+ AuditEntityNameRegister getAuditEntityNameRegister() {
+ return auditEntityNameRegister;
+ }
- void throwUnsupportedTypeException(Type type, String entityName, String propertyName) {
- String message = "Type not supported for auditing: " + type.getClass().getName() +
- ", on entity " + entityName + ", property '" + propertyName + "'.";
+ void throwUnsupportedTypeException(Type type, String entityName, String propertyName) {
+ final String message = "Type not supported for auditing: " + type.getClass().getName() +
+ ", on entity " + entityName + ", property '" + propertyName + "'.";
- throw new MappingException(message);
- }
+ throw new MappingException( message );
+ }
- /**
- * Reads the id mapping data of a referenced entity.
- * @param entityName Name of the entity which is the source of the relation.
- * @param referencedEntityName Name of the entity which is the target of the relation.
- * @param propertyAuditingData Auditing data of the property that is the source of the relation.
- * @param allowNotAuditedTarget Are not-audited target entities allowed.
- * @throws MappingException If a relation from an audited to a non-audited entity is detected, which is not
- * mapped using {@link RelationTargetAuditMode#NOT_AUDITED}.
- * @return The id mapping data of the related entity.
- */
- IdMappingData getReferencedIdMappingData(String entityName, String referencedEntityName,
- PropertyAuditingData propertyAuditingData,
- boolean allowNotAuditedTarget) {
- EntityConfiguration configuration = getEntitiesConfigurations().get(referencedEntityName);
- if (configuration == null) {
- RelationTargetAuditMode relationTargetAuditMode = propertyAuditingData.getRelationTargetAuditMode();
- configuration = getNotAuditedEntitiesConfigurations().get(referencedEntityName);
+ /**
+ * Reads the id mapping data of a referenced entity.
+ *
+ * @param entityName Name of the entity which is the source of the relation.
+ * @param referencedEntityName Name of the entity which is the target of the relation.
+ * @param propertyAuditingData Auditing data of the property that is the source of the relation.
+ * @param allowNotAuditedTarget Are not-audited target entities allowed.
+ *
+ * @return The id mapping data of the related entity.
+ *
+ * @throws MappingException If a relation from an audited to a non-audited entity is detected, which is not
+ * mapped using {@link RelationTargetAuditMode#NOT_AUDITED}.
+ */
+ IdMappingData getReferencedIdMappingData(
+ String entityName, String referencedEntityName,
+ PropertyAuditingData propertyAuditingData,
+ boolean allowNotAuditedTarget) {
+ EntityConfiguration configuration = getEntitiesConfigurations().get( referencedEntityName );
+ if ( configuration == null ) {
+ final RelationTargetAuditMode relationTargetAuditMode = propertyAuditingData.getRelationTargetAuditMode();
+ configuration = getNotAuditedEntitiesConfigurations().get( referencedEntityName );
- if (configuration == null || !allowNotAuditedTarget || !RelationTargetAuditMode.NOT_AUDITED.equals(relationTargetAuditMode)) {
- throw new MappingException("An audited relation from " + entityName + "."
- + propertyAuditingData.getName() + " to a not audited entity " + referencedEntityName + "!"
- + (allowNotAuditedTarget ?
- " Such mapping is possible, but has to be explicitly defined using @Audited(targetAuditMode = NOT_AUDITED)." :
- ""));
+ if ( configuration == null || !allowNotAuditedTarget || !RelationTargetAuditMode.NOT_AUDITED.equals(
+ relationTargetAuditMode
+ ) ) {
+ throw new MappingException(
+ "An audited relation from " + entityName + "."
+ + propertyAuditingData.getName() + " to a not audited entity " + referencedEntityName + "!"
+ + (allowNotAuditedTarget ?
+ " Such mapping is possible, but has to be explicitly defined using @Audited(targetAuditMode = NOT_AUDITED)." :
+ "")
+ );
}
}
- return configuration.getIdMappingData();
- }
+ return configuration.getIdMappingData();
+ }
/**
* Get the notAuditedEntitiesConfigurations property.
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/AuditTableData.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/AuditTableData.java
index 3d68cfcd2b..fb20152f25 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/AuditTableData.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/AuditTableData.java
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2008, 2013, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -21,41 +21,41 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
-
package org.hibernate.envers.configuration.internal.metadata;
/**
* Holds information necessary to create an audit table: its name, schema and catalog, as well as the audit
* entity name.
+ *
* @author Adam Warski (adam at warski dot org)
*/
public class AuditTableData {
- private final String auditEntityName;
- private final String auditTableName;
- private final String schema;
- private final String catalog;
+ private final String auditEntityName;
+ private final String auditTableName;
+ private final String schema;
+ private final String catalog;
- public AuditTableData(String auditEntityName, String auditTableName, String schema, String catalog) {
- this.auditEntityName = auditEntityName;
- this.auditTableName = auditTableName;
- this.schema = schema;
- this.catalog = catalog;
- }
+ public AuditTableData(String auditEntityName, String auditTableName, String schema, String catalog) {
+ this.auditEntityName = auditEntityName;
+ this.auditTableName = auditTableName;
+ this.schema = schema;
+ this.catalog = catalog;
+ }
- public String getAuditEntityName() {
- return auditEntityName;
- }
+ public String getAuditEntityName() {
+ return auditEntityName;
+ }
- public String getAuditTableName() {
- return auditTableName;
- }
+ public String getAuditTableName() {
+ return auditTableName;
+ }
- public String getSchema() {
- return schema;
- }
+ public String getSchema() {
+ return schema;
+ }
- public String getCatalog() {
- return catalog;
- }
+ public String getCatalog() {
+ return catalog;
+ }
}
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/BasicMetadataGenerator.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/BasicMetadataGenerator.java
index 62cdf89678..27e5ebe671 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/BasicMetadataGenerator.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/BasicMetadataGenerator.java
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2008, 2013, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -40,47 +40,54 @@ import org.hibernate.usertype.DynamicParameterizedType;
/**
* Generates metadata for basic properties: immutable types (including enums).
+ *
* @author Adam Warski (adam at warski dot org)
*/
public final class BasicMetadataGenerator {
- @SuppressWarnings({ "unchecked" })
- boolean addBasic(Element parent, PropertyAuditingData propertyAuditingData,
- Value value, SimpleMapperBuilder mapper, boolean insertable, boolean key) {
- Type type = value.getType();
+ @SuppressWarnings({"unchecked"})
+ boolean addBasic(
+ Element parent, PropertyAuditingData propertyAuditingData,
+ Value value, SimpleMapperBuilder mapper, boolean insertable, boolean key) {
+ final Type type = value.getType();
- if ( type instanceof BasicType || type instanceof SerializableToBlobType ||
- "org.hibernate.type.PrimitiveByteArrayBlobType".equals( type.getClass().getName() ) ) {
+ if ( type instanceof BasicType
+ || type instanceof SerializableToBlobType
+ || "org.hibernate.type.PrimitiveByteArrayBlobType".equals( type.getClass().getName() ) ) {
if ( parent != null ) {
- boolean addNestedType = ( value instanceof SimpleValue ) && ( (SimpleValue) value ).getTypeParameters() != null;
+ final boolean addNestedType = (value instanceof SimpleValue)
+ && ((SimpleValue) value).getTypeParameters() != null;
String typeName = type.getName();
if ( typeName == null ) {
typeName = type.getClass().getName();
}
- Element prop_mapping = MetadataTools.addProperty(
- parent, propertyAuditingData.getName(),
- addNestedType ? null : typeName, propertyAuditingData.isForceInsertable() || insertable, key
+ final Element propMapping = MetadataTools.addProperty(
+ parent,
+ propertyAuditingData.getName(),
+ addNestedType ? null : typeName,
+ propertyAuditingData.isForceInsertable() || insertable,
+ key
);
- MetadataTools.addColumns( prop_mapping, value.getColumnIterator() );
+ MetadataTools.addColumns( propMapping, value.getColumnIterator() );
if ( addNestedType ) {
- Properties typeParameters = ( (SimpleValue) value ).getTypeParameters();
- Element type_mapping = prop_mapping.addElement( "type" );
- type_mapping.addAttribute( "name", typeName );
+ final Properties typeParameters = ((SimpleValue) value).getTypeParameters();
+ final Element typeMapping = propMapping.addElement( "type" );
+ typeMapping.addAttribute( "name", typeName );
if ( "org.hibernate.type.EnumType".equals( typeName ) ) {
// Proper handling of enumeration type
- mapEnumerationType( type_mapping, type, typeParameters );
+ mapEnumerationType( typeMapping, type, typeParameters );
}
else {
// By default copying all Hibernate properties
for ( Object object : typeParameters.keySet() ) {
- String keyType = (String) object;
- String property = typeParameters.getProperty( keyType );
+ final String keyType = (String) object;
+ final String property = typeParameters.getProperty( keyType );
if ( property != null ) {
- type_mapping.addElement( "param" ).addAttribute( "name", keyType ).setText( property );
+ typeMapping.addElement( "param" ).addAttribute( "name", keyType ).setText( property );
}
}
}
@@ -101,32 +108,43 @@ public final class BasicMetadataGenerator {
private void mapEnumerationType(Element parent, Type type, Properties parameters) {
if ( parameters.getProperty( EnumType.ENUM ) != null ) {
- parent.addElement( "param" ).addAttribute( "name", EnumType.ENUM ).setText( parameters.getProperty( EnumType.ENUM ) );
+ parent.addElement( "param" )
+ .addAttribute( "name", EnumType.ENUM )
+ .setText( parameters.getProperty( EnumType.ENUM ) );
}
else {
- parent.addElement( "param" ).addAttribute( "name", EnumType.ENUM ).setText( type.getReturnedClass().getName() );
+ parent.addElement( "param" ).addAttribute( "name", EnumType.ENUM ).setText(
+ type.getReturnedClass()
+ .getName()
+ );
}
if ( parameters.getProperty( EnumType.NAMED ) != null ) {
- parent.addElement( "param" ).addAttribute( "name", EnumType.NAMED ).setText( parameters.getProperty( EnumType.NAMED ) );
+ parent.addElement( "param" ).addAttribute( "name", EnumType.NAMED ).setText(
+ parameters.getProperty(
+ EnumType.NAMED
+ )
+ );
}
else if ( parameters.get( DynamicParameterizedType.XPROPERTY ) != null ) {
// Case of annotations.
parent.addElement( "param" ).addAttribute( "name", EnumType.NAMED )
- .setText( "" + !( (EnumType) ( (CustomType) type ).getUserType() ).isOrdinal() );
- }
- else {
- // Otherwise we assume that the choice between ordinal and named representation has been omitted.
- // Call to EnumType#isOrdinal() would always return the default Types.INTEGER. We let Hibernate
- // to choose the proper strategy during runtime.
+ .setText( "" + !((EnumType) ((CustomType) type).getUserType()).isOrdinal() );
}
+ // Otherwise we assume that the choice between ordinal and named representation has been omitted.
+ // Call to EnumType#isOrdinal() would always return the default Types.INTEGER. We let Hibernate
+ // to choose the proper strategy during runtime.
}
- @SuppressWarnings({ "unchecked" })
- boolean addManyToOne(Element parent, PropertyAuditingData propertyAuditingData, Value value, SimpleMapperBuilder mapper) {
- Type type = value.getType();
+ @SuppressWarnings({"unchecked"})
+ boolean addManyToOne(
+ Element parent,
+ PropertyAuditingData propertyAuditingData,
+ Value value,
+ SimpleMapperBuilder mapper) {
+ final Type type = value.getType();
// A null mapper occurs when adding to composite-id element
- Element manyToOneElement = parent.addElement( mapper != null ? "many-to-one" : "key-many-to-one" );
+ final Element manyToOneElement = parent.addElement( mapper != null ? "many-to-one" : "key-many-to-one" );
manyToOneElement.addAttribute( "name", propertyAuditingData.getName() );
manyToOneElement.addAttribute( "class", type.getName() );
MetadataTools.addColumns( manyToOneElement, value.getColumnIterator() );
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/CollectionMetadataGenerator.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/CollectionMetadataGenerator.java
index 8ed1b9db3f..708baea3a4 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/CollectionMetadataGenerator.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/CollectionMetadataGenerator.java
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2008, 2013, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -23,6 +23,7 @@
*/
package org.hibernate.envers.configuration.internal.metadata;
+import javax.persistence.JoinColumn;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@@ -32,9 +33,9 @@ import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
-import javax.persistence.JoinColumn;
import org.dom4j.Element;
+
import org.jboss.logging.Logger;
import org.hibernate.MappingException;
@@ -102,380 +103,502 @@ import org.hibernate.type.Type;
/**
* Generates metadata for a collection-valued property.
+ *
* @author Adam Warski (adam at warski dot org)
* @author HernпїЅn Chanfreau
*/
public final class CollectionMetadataGenerator {
+ private static final EnversMessageLogger LOG = Logger.getMessageLogger(
+ EnversMessageLogger.class,
+ CollectionMetadataGenerator.class.getName()
+ );
- public static final EnversMessageLogger LOG = Logger.getMessageLogger(EnversMessageLogger.class, CollectionMetadataGenerator.class.getName());
+ private final AuditMetadataGenerator mainGenerator;
+ private final String propertyName;
+ private final Collection propertyValue;
+ private final CompositeMapperBuilder currentMapper;
+ private final String referencingEntityName;
+ private final EntityXmlMappingData xmlMappingData;
+ private final PropertyAuditingData propertyAuditingData;
- private final AuditMetadataGenerator mainGenerator;
- private final String propertyName;
- private final Collection propertyValue;
- private final CompositeMapperBuilder currentMapper;
- private final String referencingEntityName;
- private final EntityXmlMappingData xmlMappingData;
- private final PropertyAuditingData propertyAuditingData;
-
- private final EntityConfiguration referencingEntityConfiguration;
- /**
- * Null if this collection isn't a relation to another entity.
- */
- private final String referencedEntityName;
+ private final EntityConfiguration referencingEntityConfiguration;
+ /**
+ * Null if this collection isn't a relation to another entity.
+ */
+ private final String referencedEntityName;
/**
- * @param mainGenerator Main generator, giving access to configuration and the basic mapper.
- * @param propertyValue Value of the collection, as mapped by Hibernate.
- * @param currentMapper Mapper, to which the appropriate {@link PropertyMapper} will be added.
- * @param referencingEntityName Name of the entity that owns this collection.
- * @param xmlMappingData In case this collection requires a middle table, additional mapping documents will
- * be created using this object.
- * @param propertyAuditingData Property auditing (meta-)data. Among other things, holds the name of the
- * property that references the collection in the referencing entity, the user data for middle (join)
- * table and the value of the @MapKey
annotation, if there was one.
- */
- public CollectionMetadataGenerator(AuditMetadataGenerator mainGenerator,
- Collection propertyValue, CompositeMapperBuilder currentMapper,
- String referencingEntityName, EntityXmlMappingData xmlMappingData,
- PropertyAuditingData propertyAuditingData) {
- this.mainGenerator = mainGenerator;
- this.propertyValue = propertyValue;
- this.currentMapper = currentMapper;
- this.referencingEntityName = referencingEntityName;
- this.xmlMappingData = xmlMappingData;
- this.propertyAuditingData = propertyAuditingData;
+ * @param mainGenerator Main generator, giving access to configuration and the basic mapper.
+ * @param propertyValue Value of the collection, as mapped by Hibernate.
+ * @param currentMapper Mapper, to which the appropriate {@link PropertyMapper} will be added.
+ * @param referencingEntityName Name of the entity that owns this collection.
+ * @param xmlMappingData In case this collection requires a middle table, additional mapping documents will
+ * be created using this object.
+ * @param propertyAuditingData Property auditing (meta-)data. Among other things, holds the name of the
+ * property that references the collection in the referencing entity, the user data for middle (join)
+ * table and the value of the @MapKey
annotation, if there was one.
+ */
+ public CollectionMetadataGenerator(
+ AuditMetadataGenerator mainGenerator,
+ Collection propertyValue, CompositeMapperBuilder currentMapper,
+ String referencingEntityName, EntityXmlMappingData xmlMappingData,
+ PropertyAuditingData propertyAuditingData) {
+ this.mainGenerator = mainGenerator;
+ this.propertyValue = propertyValue;
+ this.currentMapper = currentMapper;
+ this.referencingEntityName = referencingEntityName;
+ this.xmlMappingData = xmlMappingData;
+ this.propertyAuditingData = propertyAuditingData;
- this.propertyName = propertyAuditingData.getName();
+ this.propertyName = propertyAuditingData.getName();
- referencingEntityConfiguration = mainGenerator.getEntitiesConfigurations().get(referencingEntityName);
- if (referencingEntityConfiguration == null) {
- throw new MappingException("Unable to read auditing configuration for " + referencingEntityName + "!");
- }
+ referencingEntityConfiguration = mainGenerator.getEntitiesConfigurations().get( referencingEntityName );
+ if ( referencingEntityConfiguration == null ) {
+ throw new MappingException( "Unable to read auditing configuration for " + referencingEntityName + "!" );
+ }
- referencedEntityName = MappingTools.getReferencedEntityName(propertyValue.getElement());
- }
+ referencedEntityName = MappingTools.getReferencedEntityName( propertyValue.getElement() );
+ }
- void addCollection() {
- Type type = propertyValue.getType();
- Value value = propertyValue.getElement();
+ void addCollection() {
+ final Type type = propertyValue.getType();
+ final Value value = propertyValue.getElement();
- boolean oneToManyAttachedType = type instanceof BagType || type instanceof SetType || type instanceof MapType || type instanceof ListType;
- boolean inverseOneToMany = (value instanceof OneToMany) && (propertyValue.isInverse());
- boolean owningManyToOneWithJoinTableBidirectional = (value instanceof ManyToOne) && (propertyAuditingData.getRelationMappedBy() != null);
- boolean fakeOneToManyBidirectional = (value instanceof OneToMany) && (propertyAuditingData.getAuditMappedBy() != null);
+ final boolean oneToManyAttachedType = type instanceof BagType || type instanceof SetType || type instanceof MapType || type instanceof ListType;
+ final boolean inverseOneToMany = (value instanceof OneToMany) && (propertyValue.isInverse());
+ final boolean owningManyToOneWithJoinTableBidirectional = (value instanceof ManyToOne) && (propertyAuditingData.getRelationMappedBy() != null);
+ final boolean fakeOneToManyBidirectional = (value instanceof OneToMany) && (propertyAuditingData.getAuditMappedBy() != null);
- if (oneToManyAttachedType && (inverseOneToMany || fakeOneToManyBidirectional || owningManyToOneWithJoinTableBidirectional)) {
- // A one-to-many relation mapped using @ManyToOne and @OneToMany(mappedBy="...")
- addOneToManyAttached(fakeOneToManyBidirectional);
- } else {
- // All other kinds of relations require a middle (join) table.
- addWithMiddleTable();
- }
- }
+ if ( oneToManyAttachedType && (inverseOneToMany || fakeOneToManyBidirectional || owningManyToOneWithJoinTableBidirectional) ) {
+ // A one-to-many relation mapped using @ManyToOne and @OneToMany(mappedBy="...")
+ addOneToManyAttached( fakeOneToManyBidirectional );
+ }
+ else {
+ // All other kinds of relations require a middle (join) table.
+ addWithMiddleTable();
+ }
+ }
- private MiddleIdData createMiddleIdData(IdMappingData idMappingData, String prefix, String entityName) {
- return new MiddleIdData(mainGenerator.getVerEntCfg(), idMappingData, prefix, entityName,
- mainGenerator.getEntitiesConfigurations().containsKey(entityName));
- }
+ private MiddleIdData createMiddleIdData(IdMappingData idMappingData, String prefix, String entityName) {
+ return new MiddleIdData(
+ mainGenerator.getVerEntCfg(), idMappingData, prefix, entityName,
+ mainGenerator.getEntitiesConfigurations().containsKey( entityName )
+ );
+ }
- @SuppressWarnings({"unchecked"})
- private void addOneToManyAttached(boolean fakeOneToManyBidirectional) {
- LOG.debugf("Adding audit mapping for property %s.%s: one-to-many collection, using a join column on the referenced entity",
- referencingEntityName,
- propertyName);
+ @SuppressWarnings({"unchecked"})
+ private void addOneToManyAttached(boolean fakeOneToManyBidirectional) {
+ LOG.debugf(
+ "Adding audit mapping for property %s.%s: one-to-many collection, using a join column on the referenced entity",
+ referencingEntityName,
+ propertyName
+ );
- String mappedBy = getMappedBy(propertyValue);
+ final String mappedBy = getMappedBy( propertyValue );
- IdMappingData referencedIdMapping = mainGenerator.getReferencedIdMappingData(referencingEntityName,
- referencedEntityName, propertyAuditingData, false);
- IdMappingData referencingIdMapping = referencingEntityConfiguration.getIdMappingData();
+ final IdMappingData referencedIdMapping = mainGenerator.getReferencedIdMappingData(
+ referencingEntityName,
+ referencedEntityName,
+ propertyAuditingData,
+ false
+ );
+ final IdMappingData referencingIdMapping = referencingEntityConfiguration.getIdMappingData();
- // Generating the id mappers data for the referencing side of the relation.
- MiddleIdData referencingIdData = createMiddleIdData(referencingIdMapping,
- mappedBy + "_", referencingEntityName);
+ // Generating the id mappers data for the referencing side of the relation.
+ final MiddleIdData referencingIdData = createMiddleIdData(
+ referencingIdMapping,
+ mappedBy + "_",
+ referencingEntityName
+ );
- // And for the referenced side. The prefixed mapper won't be used (as this collection isn't persisted
- // in a join table, so the prefix value is arbitrary).
- MiddleIdData referencedIdData = createMiddleIdData(referencedIdMapping,
- null, referencedEntityName);
+ // And for the referenced side. The prefixed mapper won't be used (as this collection isn't persisted
+ // in a join table, so the prefix value is arbitrary).
+ final MiddleIdData referencedIdData = createMiddleIdData(
+ referencedIdMapping,
+ null, referencedEntityName
+ );
- // Generating the element mapping.
- MiddleComponentData elementComponentData = new MiddleComponentData(
- new MiddleRelatedComponentMapper(referencedIdData), 0);
+ // Generating the element mapping.
+ final MiddleComponentData elementComponentData = new MiddleComponentData(
+ new MiddleRelatedComponentMapper( referencedIdData ), 0
+ );
- // Generating the index mapping, if an index exists. It can only exists in case a javax.persistence.MapKey
- // annotation is present on the entity. So the middleEntityXml will be not be used. The queryGeneratorBuilder
- // will only be checked for nullnes.
- MiddleComponentData indexComponentData = addIndex(null, null);
+ // Generating the index mapping, if an index exists. It can only exists in case a javax.persistence.MapKey
+ // annotation is present on the entity. So the middleEntityXml will be not be used. The queryGeneratorBuilder
+ // will only be checked for nullnes.
+ MiddleComponentData indexComponentData = addIndex( null, null );
- // Generating the query generator - it should read directly from the related entity.
- RelationQueryGenerator queryGenerator = new OneAuditEntityQueryGenerator(mainGenerator.getGlobalCfg(),
- mainGenerator.getVerEntCfg(), mainGenerator.getAuditStrategy(),
- referencingIdData, referencedEntityName, referencedIdData, isEmbeddableElementType());
+ // Generating the query generator - it should read directly from the related entity.
+ final RelationQueryGenerator queryGenerator = new OneAuditEntityQueryGenerator(
+ mainGenerator.getGlobalCfg(),
+ mainGenerator.getVerEntCfg(),
+ mainGenerator.getAuditStrategy(),
+ referencingIdData,
+ referencedEntityName,
+ referencedIdData,
+ isEmbeddableElementType()
+ );
- // Creating common mapper data.
- CommonCollectionMapperData commonCollectionMapperData = new CommonCollectionMapperData(
- mainGenerator.getVerEntCfg(), referencedEntityName,
- propertyAuditingData.getPropertyData(),
- referencingIdData, queryGenerator);
+ // Creating common mapper data.
+ final CommonCollectionMapperData commonCollectionMapperData = new CommonCollectionMapperData(
+ mainGenerator.getVerEntCfg(), referencedEntityName,
+ propertyAuditingData.getPropertyData(),
+ referencingIdData, queryGenerator
+ );
- PropertyMapper fakeBidirectionalRelationMapper;
- PropertyMapper fakeBidirectionalRelationIndexMapper;
- if (fakeOneToManyBidirectional) {
- // In case of a fake many-to-one bidirectional relation, we have to generate a mapper which maps
- // the mapped-by property name to the id of the related entity (which is the owner of the collection).
- String auditMappedBy = propertyAuditingData.getAuditMappedBy();
+ PropertyMapper fakeBidirectionalRelationMapper;
+ PropertyMapper fakeBidirectionalRelationIndexMapper;
+ if ( fakeOneToManyBidirectional ) {
+ // In case of a fake many-to-one bidirectional relation, we have to generate a mapper which maps
+ // the mapped-by property name to the id of the related entity (which is the owner of the collection).
+ final String auditMappedBy = propertyAuditingData.getAuditMappedBy();
- // Creating a prefixed relation mapper.
- IdMapper relMapper = referencingIdMapping.getIdMapper().prefixMappedProperties(
- MappingTools.createToOneRelationPrefix(auditMappedBy));
+ // Creating a prefixed relation mapper.
+ final IdMapper relMapper = referencingIdMapping.getIdMapper().prefixMappedProperties(
+ MappingTools.createToOneRelationPrefix( auditMappedBy )
+ );
- fakeBidirectionalRelationMapper = new ToOneIdMapper(
- relMapper,
- // The mapper will only be used to map from entity to map, so no need to provide other details
- // when constructing the PropertyData.
- new PropertyData(auditMappedBy, null, null, null),
- referencingEntityName, false);
+ fakeBidirectionalRelationMapper = new ToOneIdMapper(
+ relMapper,
+ // The mapper will only be used to map from entity to map, so no need to provide other details
+ // when constructing the PropertyData.
+ new PropertyData( auditMappedBy, null, null, null ),
+ referencingEntityName, false
+ );
- // Checking if there's an index defined. If so, adding a mapper for it.
- if (propertyAuditingData.getPositionMappedBy() != null) {
- String positionMappedBy = propertyAuditingData.getPositionMappedBy();
- fakeBidirectionalRelationIndexMapper = new SinglePropertyMapper(new PropertyData(positionMappedBy, null, null, null));
+ // Checking if there's an index defined. If so, adding a mapper for it.
+ if ( propertyAuditingData.getPositionMappedBy() != null ) {
+ final String positionMappedBy = propertyAuditingData.getPositionMappedBy();
+ fakeBidirectionalRelationIndexMapper = new SinglePropertyMapper(
+ new PropertyData(
+ positionMappedBy,
+ null,
+ null,
+ null
+ )
+ );
- // Also, overwriting the index component data to properly read the index.
- indexComponentData = new MiddleComponentData(new MiddleStraightComponentMapper(positionMappedBy), 0);
- } else {
- fakeBidirectionalRelationIndexMapper = null;
- }
- } else {
- fakeBidirectionalRelationMapper = null;
- fakeBidirectionalRelationIndexMapper = null;
- }
+ // Also, overwriting the index component data to properly read the index.
+ indexComponentData = new MiddleComponentData(
+ new MiddleStraightComponentMapper( positionMappedBy ),
+ 0
+ );
+ }
+ else {
+ fakeBidirectionalRelationIndexMapper = null;
+ }
+ }
+ else {
+ fakeBidirectionalRelationMapper = null;
+ fakeBidirectionalRelationIndexMapper = null;
+ }
- // Checking the type of the collection and adding an appropriate mapper.
- addMapper(commonCollectionMapperData, elementComponentData, indexComponentData);
+ // Checking the type of the collection and adding an appropriate mapper.
+ addMapper( commonCollectionMapperData, elementComponentData, indexComponentData );
- // Storing information about this relation.
- referencingEntityConfiguration.addToManyNotOwningRelation(propertyName, mappedBy,
- referencedEntityName, referencingIdData.getPrefixedMapper(), fakeBidirectionalRelationMapper,
- fakeBidirectionalRelationIndexMapper);
- }
+ // Storing information about this relation.
+ referencingEntityConfiguration.addToManyNotOwningRelation(
+ propertyName,
+ mappedBy,
+ referencedEntityName,
+ referencingIdData.getPrefixedMapper(),
+ fakeBidirectionalRelationMapper,
+ fakeBidirectionalRelationIndexMapper
+ );
+ }
- /**
- * Adds mapping of the id of a related entity to the given xml mapping, prefixing the id with the given prefix.
- * @param xmlMapping Mapping, to which to add the xml.
- * @param prefix Prefix for the names of properties which will be prepended to properties that form the id.
- * @param columnNameIterator Iterator over the column names that will be used for properties that form the id.
- * @param relatedIdMapping Id mapping data of the related entity.
- */
- @SuppressWarnings({"unchecked"})
- private void addRelatedToXmlMapping(Element xmlMapping, String prefix,
- MetadataTools.ColumnNameIterator columnNameIterator,
- IdMappingData relatedIdMapping) {
- Element properties = (Element) relatedIdMapping.getXmlRelationMapping().clone();
- MetadataTools.prefixNamesInPropertyElement(properties, prefix, columnNameIterator, true, true);
- for (Element idProperty : (java.util.List) properties.elements()) {
- xmlMapping.add((Element) idProperty.clone());
- }
- }
+ /**
+ * Adds mapping of the id of a related entity to the given xml mapping, prefixing the id with the given prefix.
+ *
+ * @param xmlMapping Mapping, to which to add the xml.
+ * @param prefix Prefix for the names of properties which will be prepended to properties that form the id.
+ * @param columnNameIterator Iterator over the column names that will be used for properties that form the id.
+ * @param relatedIdMapping Id mapping data of the related entity.
+ */
+ @SuppressWarnings({"unchecked"})
+ private void addRelatedToXmlMapping(
+ Element xmlMapping, String prefix,
+ MetadataTools.ColumnNameIterator columnNameIterator,
+ IdMappingData relatedIdMapping) {
+ final Element properties = (Element) relatedIdMapping.getXmlRelationMapping().clone();
+ MetadataTools.prefixNamesInPropertyElement( properties, prefix, columnNameIterator, true, true );
+ for ( Element idProperty : (java.util.List) properties.elements() ) {
+ xmlMapping.add( (Element) idProperty.clone() );
+ }
+ }
- private String getMiddleTableName(Collection value, String entityName) {
- // We check how Hibernate maps the collection.
- if (value.getElement() instanceof OneToMany && !value.isInverse()) {
- // This must be a @JoinColumn+@OneToMany mapping. Generating the table name, as Hibernate doesn't use a
- // middle table for mapping this relation.
- return StringTools.getLastComponent(entityName) + "_" + StringTools.getLastComponent(MappingTools.getReferencedEntityName(value.getElement()));
- }
- // Hibernate uses a middle table for mapping this relation, so we get it's name directly.
- return value.getCollectionTable().getName();
- }
+ private String getMiddleTableName(Collection value, String entityName) {
+ // We check how Hibernate maps the collection.
+ if ( value.getElement() instanceof OneToMany && !value.isInverse() ) {
+ // This must be a @JoinColumn+@OneToMany mapping. Generating the table name, as Hibernate doesn't use a
+ // middle table for mapping this relation.
+ return StringTools.getLastComponent( entityName ) + "_" + StringTools.getLastComponent(
+ MappingTools.getReferencedEntityName(
+ value.getElement()
+ )
+ );
+ }
+ // Hibernate uses a middle table for mapping this relation, so we get it's name directly.
+ return value.getCollectionTable().getName();
+ }
- @SuppressWarnings({"unchecked"})
- private void addWithMiddleTable() {
+ @SuppressWarnings({"unchecked"})
+ private void addWithMiddleTable() {
- LOG.debugf("Adding audit mapping for property %s.%s: collection with a join table", referencingEntityName, propertyName);
+ LOG.debugf(
+ "Adding audit mapping for property %s.%s: collection with a join table",
+ referencingEntityName,
+ propertyName
+ );
- // Generating the name of the middle table
- String auditMiddleTableName;
- String auditMiddleEntityName;
- if (!StringTools.isEmpty(propertyAuditingData.getJoinTable().name())) {
- auditMiddleTableName = propertyAuditingData.getJoinTable().name();
- auditMiddleEntityName = propertyAuditingData.getJoinTable().name();
- } else {
- String middleTableName = getMiddleTableName(propertyValue, referencingEntityName);
- auditMiddleTableName = mainGenerator.getVerEntCfg().getAuditTableName(null, middleTableName);
- auditMiddleEntityName = mainGenerator.getVerEntCfg().getAuditEntityName(middleTableName);
- }
+ // Generating the name of the middle table
+ String auditMiddleTableName;
+ String auditMiddleEntityName;
+ if ( !StringTools.isEmpty( propertyAuditingData.getJoinTable().name() ) ) {
+ auditMiddleTableName = propertyAuditingData.getJoinTable().name();
+ auditMiddleEntityName = propertyAuditingData.getJoinTable().name();
+ }
+ else {
+ final String middleTableName = getMiddleTableName( propertyValue, referencingEntityName );
+ auditMiddleTableName = mainGenerator.getVerEntCfg().getAuditTableName( null, middleTableName );
+ auditMiddleEntityName = mainGenerator.getVerEntCfg().getAuditEntityName( middleTableName );
+ }
- LOG.debugf("Using join table name: %s", auditMiddleTableName);
+ LOG.debugf( "Using join table name: %s", auditMiddleTableName );
- // Generating the XML mapping for the middle entity, only if the relation isn't inverse.
- // If the relation is inverse, will be later checked by comparing middleEntityXml with null.
- Element middleEntityXml;
- if (!propertyValue.isInverse()) {
- // Generating a unique middle entity name
- auditMiddleEntityName = mainGenerator.getAuditEntityNameRegister().createUnique(auditMiddleEntityName);
+ // Generating the XML mapping for the middle entity, only if the relation isn't inverse.
+ // If the relation is inverse, will be later checked by comparing middleEntityXml with null.
+ Element middleEntityXml;
+ if ( !propertyValue.isInverse() ) {
+ // Generating a unique middle entity name
+ auditMiddleEntityName = mainGenerator.getAuditEntityNameRegister().createUnique( auditMiddleEntityName );
- // Registering the generated name
- mainGenerator.getAuditEntityNameRegister().register(auditMiddleEntityName);
+ // Registering the generated name
+ mainGenerator.getAuditEntityNameRegister().register( auditMiddleEntityName );
- middleEntityXml = createMiddleEntityXml(auditMiddleTableName, auditMiddleEntityName, propertyValue.getWhere());
- } else {
- middleEntityXml = null;
- }
+ middleEntityXml = createMiddleEntityXml(
+ auditMiddleTableName,
+ auditMiddleEntityName,
+ propertyValue.getWhere()
+ );
+ }
+ else {
+ middleEntityXml = null;
+ }
- // ******
- // Generating the mapping for the referencing entity (it must be an entity).
- // ******
- // Getting the id-mapping data of the referencing entity (the entity that "owns" this collection).
- IdMappingData referencingIdMapping = referencingEntityConfiguration.getIdMappingData();
+ // ******
+ // Generating the mapping for the referencing entity (it must be an entity).
+ // ******
+ // Getting the id-mapping data of the referencing entity (the entity that "owns" this collection).
+ final IdMappingData referencingIdMapping = referencingEntityConfiguration.getIdMappingData();
- // Only valid for an inverse relation; null otherwise.
- String mappedBy;
+ // Only valid for an inverse relation; null otherwise.
+ String mappedBy;
- // The referencing prefix is always for a related entity. So it has always the "_" at the end added.
- String referencingPrefixRelated;
- String referencedPrefix;
+ // The referencing prefix is always for a related entity. So it has always the "_" at the end added.
+ String referencingPrefixRelated;
+ String referencedPrefix;
- if (propertyValue.isInverse()) {
- // If the relation is inverse, then referencedEntityName is not null.
- mappedBy = getMappedBy(propertyValue.getCollectionTable(), mainGenerator.getCfg().getClassMapping(referencedEntityName));
+ if ( propertyValue.isInverse() ) {
+ // If the relation is inverse, then referencedEntityName is not null.
+ mappedBy = getMappedBy(
+ propertyValue.getCollectionTable(),
+ mainGenerator.getCfg().getClassMapping( referencedEntityName )
+ );
- referencingPrefixRelated = mappedBy + "_";
- referencedPrefix = StringTools.getLastComponent(referencedEntityName);
- } else {
- mappedBy = null;
+ referencingPrefixRelated = mappedBy + "_";
+ referencedPrefix = StringTools.getLastComponent( referencedEntityName );
+ }
+ else {
+ mappedBy = null;
- referencingPrefixRelated = StringTools.getLastComponent(referencingEntityName) + "_";
- referencedPrefix = referencedEntityName == null ? "element" : propertyName;
- }
+ referencingPrefixRelated = StringTools.getLastComponent( referencingEntityName ) + "_";
+ referencedPrefix = referencedEntityName == null ? "element" : propertyName;
+ }
- // Storing the id data of the referencing entity: original mapper, prefixed mapper and entity name.
- MiddleIdData referencingIdData = createMiddleIdData(referencingIdMapping,
- referencingPrefixRelated, referencingEntityName);
+ // Storing the id data of the referencing entity: original mapper, prefixed mapper and entity name.
+ final MiddleIdData referencingIdData = createMiddleIdData(
+ referencingIdMapping,
+ referencingPrefixRelated,
+ referencingEntityName
+ );
- // Creating a query generator builder, to which additional id data will be added, in case this collection
- // references some entities (either from the element or index). At the end, this will be used to build
- // a query generator to read the raw data collection from the middle table.
- QueryGeneratorBuilder queryGeneratorBuilder = new QueryGeneratorBuilder(mainGenerator.getGlobalCfg(),
- mainGenerator.getVerEntCfg(), mainGenerator.getAuditStrategy(), referencingIdData,
- auditMiddleEntityName, isEmbeddableElementType());
+ // Creating a query generator builder, to which additional id data will be added, in case this collection
+ // references some entities (either from the element or index). At the end, this will be used to build
+ // a query generator to read the raw data collection from the middle table.
+ final QueryGeneratorBuilder queryGeneratorBuilder = new QueryGeneratorBuilder(
+ mainGenerator.getGlobalCfg(),
+ mainGenerator.getVerEntCfg(),
+ mainGenerator.getAuditStrategy(),
+ referencingIdData,
+ auditMiddleEntityName,
+ isEmbeddableElementType()
+ );
- // Adding the XML mapping for the referencing entity, if the relation isn't inverse.
- if (middleEntityXml != null) {
- // Adding related-entity (in this case: the referencing's entity id) id mapping to the xml.
- addRelatedToXmlMapping(middleEntityXml, referencingPrefixRelated,
- MetadataTools.getColumnNameIterator(propertyValue.getKey().getColumnIterator()),
- referencingIdMapping);
- }
+ // Adding the XML mapping for the referencing entity, if the relation isn't inverse.
+ if ( middleEntityXml != null ) {
+ // Adding related-entity (in this case: the referencing's entity id) id mapping to the xml.
+ addRelatedToXmlMapping(
+ middleEntityXml, referencingPrefixRelated,
+ MetadataTools.getColumnNameIterator( propertyValue.getKey().getColumnIterator() ),
+ referencingIdMapping
+ );
+ }
- // ******
- // Generating the element mapping.
- // ******
- MiddleComponentData elementComponentData = addValueToMiddleTable(propertyValue.getElement(), middleEntityXml,
- queryGeneratorBuilder, referencedPrefix, propertyAuditingData.getJoinTable().inverseJoinColumns());
+ // ******
+ // Generating the element mapping.
+ // ******
+ final MiddleComponentData elementComponentData = addValueToMiddleTable(
+ propertyValue.getElement(),
+ middleEntityXml,
+ queryGeneratorBuilder,
+ referencedPrefix,
+ propertyAuditingData.getJoinTable().inverseJoinColumns()
+ );
- // ******
- // Generating the index mapping, if an index exists.
- // ******
- MiddleComponentData indexComponentData = addIndex(middleEntityXml, queryGeneratorBuilder);
+ // ******
+ // Generating the index mapping, if an index exists.
+ // ******
+ final MiddleComponentData indexComponentData = addIndex( middleEntityXml, queryGeneratorBuilder );
- // ******
- // Generating the property mapper.
- // ******
- // Building the query generator.
- RelationQueryGenerator queryGenerator = queryGeneratorBuilder.build(elementComponentData, indexComponentData);
+ // ******
+ // Generating the property mapper.
+ // ******
+ // Building the query generator.
+ final RelationQueryGenerator queryGenerator = queryGeneratorBuilder.build( elementComponentData, indexComponentData );
- // Creating common data
- CommonCollectionMapperData commonCollectionMapperData = new CommonCollectionMapperData(
- mainGenerator.getVerEntCfg(), auditMiddleEntityName,
- propertyAuditingData.getPropertyData(),
- referencingIdData, queryGenerator);
+ // Creating common data
+ final CommonCollectionMapperData commonCollectionMapperData = new CommonCollectionMapperData(
+ mainGenerator.getVerEntCfg(),
+ auditMiddleEntityName,
+ propertyAuditingData.getPropertyData(),
+ referencingIdData,
+ queryGenerator
+ );
- // Checking the type of the collection and adding an appropriate mapper.
- addMapper(commonCollectionMapperData, elementComponentData, indexComponentData);
+ // Checking the type of the collection and adding an appropriate mapper.
+ addMapper( commonCollectionMapperData, elementComponentData, indexComponentData );
- // ******
- // Storing information about this relation.
- // ******
- storeMiddleEntityRelationInformation(mappedBy);
- }
+ // ******
+ // Storing information about this relation.
+ // ******
+ storeMiddleEntityRelationInformation( mappedBy );
+ }
- private MiddleComponentData addIndex(Element middleEntityXml, QueryGeneratorBuilder queryGeneratorBuilder) {
- if (propertyValue instanceof IndexedCollection) {
- IndexedCollection indexedValue = (IndexedCollection) propertyValue;
- String mapKey = propertyAuditingData.getMapKey();
- if (mapKey == null) {
- // This entity doesn't specify a javax.persistence.MapKey. Mapping it to the middle entity.
- return addValueToMiddleTable(indexedValue.getIndex(), middleEntityXml,
- queryGeneratorBuilder, "mapkey", null);
- } else {
- IdMappingData referencedIdMapping = mainGenerator.getEntitiesConfigurations()
- .get(referencedEntityName).getIdMappingData();
- int currentIndex = queryGeneratorBuilder == null ? 0 : queryGeneratorBuilder.getCurrentIndex();
- if ("".equals(mapKey)) {
- // The key of the map is the id of the entity.
- return new MiddleComponentData(new MiddleMapKeyIdComponentMapper(mainGenerator.getVerEntCfg(),
- referencedIdMapping.getIdMapper()), currentIndex);
- } else {
- // The key of the map is a property of the entity.
- return new MiddleComponentData(new MiddleMapKeyPropertyComponentMapper(mapKey,
- propertyAuditingData.getAccessType()), currentIndex);
- }
- }
- } else {
- // No index - creating a dummy mapper.
- return new MiddleComponentData(new MiddleDummyComponentMapper(), 0);
- }
- }
+ private MiddleComponentData addIndex(Element middleEntityXml, QueryGeneratorBuilder queryGeneratorBuilder) {
+ if ( propertyValue instanceof IndexedCollection ) {
+ final IndexedCollection indexedValue = (IndexedCollection) propertyValue;
+ final String mapKey = propertyAuditingData.getMapKey();
+ if ( mapKey == null ) {
+ // This entity doesn't specify a javax.persistence.MapKey. Mapping it to the middle entity.
+ return addValueToMiddleTable(
+ indexedValue.getIndex(),
+ middleEntityXml,
+ queryGeneratorBuilder,
+ "mapkey",
+ null
+ );
+ }
+ else {
+ final IdMappingData referencedIdMapping = mainGenerator.getEntitiesConfigurations()
+ .get( referencedEntityName ).getIdMappingData();
+ final int currentIndex = queryGeneratorBuilder == null ? 0 : queryGeneratorBuilder.getCurrentIndex();
+ if ( "".equals( mapKey ) ) {
+ // The key of the map is the id of the entity.
+ return new MiddleComponentData(
+ new MiddleMapKeyIdComponentMapper(
+ mainGenerator.getVerEntCfg(),
+ referencedIdMapping.getIdMapper()
+ ),
+ currentIndex
+ );
+ }
+ else {
+ // The key of the map is a property of the entity.
+ return new MiddleComponentData(
+ new MiddleMapKeyPropertyComponentMapper(
+ mapKey,
+ propertyAuditingData.getAccessType()
+ ),
+ currentIndex
+ );
+ }
+ }
+ }
+ else {
+ // No index - creating a dummy mapper.
+ return new MiddleComponentData( new MiddleDummyComponentMapper(), 0 );
+ }
+ }
- /**
- *
- * @param value Value, which should be mapped to the middle-table, either as a relation to another entity,
- * or as a simple value.
- * @param xmlMapping If not null
, xml mapping for this value is added to this element.
- * @param queryGeneratorBuilder In case value
is a relation to another entity, information about it
- * should be added to the given.
- * @param prefix Prefix for proeprty names of related entities identifiers.
- * @param joinColumns Names of columns to use in the xml mapping, if this array isn't null and has any elements.
- * @return Data for mapping this component.
- */
- @SuppressWarnings({"unchecked"})
- private MiddleComponentData addValueToMiddleTable(Value value, Element xmlMapping,
- QueryGeneratorBuilder queryGeneratorBuilder,
- String prefix, JoinColumn[] joinColumns) {
- Type type = value.getType();
- if (type instanceof ManyToOneType) {
- String prefixRelated = prefix + "_";
+ /**
+ * @param value Value, which should be mapped to the middle-table, either as a relation to another entity,
+ * or as a simple value.
+ * @param xmlMapping If not null
, xml mapping for this value is added to this element.
+ * @param queryGeneratorBuilder In case value
is a relation to another entity, information about it
+ * should be added to the given.
+ * @param prefix Prefix for proeprty names of related entities identifiers.
+ * @param joinColumns Names of columns to use in the xml mapping, if this array isn't null and has any elements.
+ *
+ * @return Data for mapping this component.
+ */
+ @SuppressWarnings({"unchecked"})
+ private MiddleComponentData addValueToMiddleTable(
+ Value value,
+ Element xmlMapping,
+ QueryGeneratorBuilder queryGeneratorBuilder,
+ String prefix,
+ JoinColumn[] joinColumns) {
+ final Type type = value.getType();
+ if ( type instanceof ManyToOneType ) {
+ final String prefixRelated = prefix + "_";
- String referencedEntityName = MappingTools.getReferencedEntityName(value);
+ final String referencedEntityName = MappingTools.getReferencedEntityName( value );
- IdMappingData referencedIdMapping = mainGenerator.getReferencedIdMappingData(referencingEntityName,
- referencedEntityName, propertyAuditingData, true);
+ final IdMappingData referencedIdMapping = mainGenerator.getReferencedIdMappingData(
+ referencingEntityName,
+ referencedEntityName,
+ propertyAuditingData,
+ true
+ );
- // Adding related-entity (in this case: the referenced entities id) id mapping to the xml only if the
- // relation isn't inverse (so when xmlMapping
is not null).
- if (xmlMapping != null) {
- addRelatedToXmlMapping(xmlMapping, prefixRelated,
- joinColumns != null && joinColumns.length > 0
- ? MetadataTools.getColumnNameIterator(joinColumns)
- : MetadataTools.getColumnNameIterator(value.getColumnIterator()),
- referencedIdMapping);
- }
+ // Adding related-entity (in this case: the referenced entities id) id mapping to the xml only if the
+ // relation isn't inverse (so when xmlMapping
is not null).
+ if ( xmlMapping != null ) {
+ addRelatedToXmlMapping(
+ xmlMapping, prefixRelated,
+ joinColumns != null && joinColumns.length > 0
+ ? MetadataTools.getColumnNameIterator( joinColumns )
+ : MetadataTools.getColumnNameIterator( value.getColumnIterator() ),
+ referencedIdMapping
+ );
+ }
- // Storing the id data of the referenced entity: original mapper, prefixed mapper and entity name.
- MiddleIdData referencedIdData = createMiddleIdData(referencedIdMapping,
- prefixRelated, referencedEntityName);
- // And adding it to the generator builder.
- queryGeneratorBuilder.addRelation(referencedIdData);
+ // Storing the id data of the referenced entity: original mapper, prefixed mapper and entity name.
+ final MiddleIdData referencedIdData = createMiddleIdData(
+ referencedIdMapping,
+ prefixRelated,
+ referencedEntityName
+ );
+ // And adding it to the generator builder.
+ queryGeneratorBuilder.addRelation( referencedIdData );
- return new MiddleComponentData(new MiddleRelatedComponentMapper(referencedIdData),
- queryGeneratorBuilder.getCurrentIndex());
- } else if ( type instanceof ComponentType ) {
+ return new MiddleComponentData(
+ new MiddleRelatedComponentMapper( referencedIdData ),
+ queryGeneratorBuilder.getCurrentIndex()
+ );
+ }
+ else if ( type instanceof ComponentType ) {
// Collection of embeddable elements.
final Component component = (Component) value;
- final Class componentClass = ReflectionTools.loadClass( component.getComponentClassName(), mainGenerator.getClassLoaderService() );
- final MiddleEmbeddableComponentMapper componentMapper = new MiddleEmbeddableComponentMapper( new MultiPropertyMapper(), componentClass );
+ final Class componentClass = ReflectionTools.loadClass(
+ component.getComponentClassName(),
+ mainGenerator.getClassLoaderService()
+ );
+ final MiddleEmbeddableComponentMapper componentMapper = new MiddleEmbeddableComponentMapper(
+ new MultiPropertyMapper(),
+ componentClass
+ );
final Element parentXmlMapping = xmlMapping.getParent();
final ComponentAuditingData auditData = new ComponentAuditingData();
@@ -489,27 +612,40 @@ public final class CollectionMetadataGenerator {
// Emulating first pass.
for ( String auditedPropertyName : auditData.getPropertyNames() ) {
- PropertyAuditingData nestedAuditingData = auditData.getPropertyAuditingData( auditedPropertyName );
+ final PropertyAuditingData nestedAuditingData = auditData.getPropertyAuditingData( auditedPropertyName );
mainGenerator.addValue(
- parentXmlMapping, component.getProperty( auditedPropertyName ).getValue(), componentMapper,
- prefix, xmlMappingData, nestedAuditingData, true, true, true
+ parentXmlMapping,
+ component.getProperty( auditedPropertyName ).getValue(),
+ componentMapper,
+ prefix, xmlMappingData,
+ nestedAuditingData,
+ true,
+ true,
+ true
);
}
// Emulating second pass so that the relations can be mapped too.
for ( String auditedPropertyName : auditData.getPropertyNames() ) {
- PropertyAuditingData nestedAuditingData = auditData.getPropertyAuditingData( auditedPropertyName );
+ final PropertyAuditingData nestedAuditingData = auditData.getPropertyAuditingData( auditedPropertyName );
mainGenerator.addValue(
- parentXmlMapping, component.getProperty( auditedPropertyName ).getValue(),
- componentMapper, referencingEntityName, xmlMappingData, nestedAuditingData,
- true, false, true
+ parentXmlMapping,
+ component.getProperty( auditedPropertyName ).getValue(),
+ componentMapper,
+ referencingEntityName,
+ xmlMappingData,
+ nestedAuditingData,
+ true,
+ false,
+ true
);
}
// Add an additional column holding a number to make each entry unique within the set.
// Embeddable properties may contain null values, so cannot be stored within composite primary key.
if ( propertyValue.isSet() ) {
- final String setOrdinalPropertyName = mainGenerator.getVerEntCfg().getEmbeddableSetOrdinalPropertyName();
+ final String setOrdinalPropertyName = mainGenerator.getVerEntCfg()
+ .getEmbeddableSetOrdinalPropertyName();
final Element ordinalProperty = MetadataTools.addProperty(
xmlMapping, setOrdinalPropertyName, "integer", true, true
);
@@ -519,96 +655,185 @@ public final class CollectionMetadataGenerator {
}
return new MiddleComponentData( componentMapper, 0 );
- } else {
- // Last but one parameter: collection components are always insertable
- boolean mapped = mainGenerator.getBasicMetadataGenerator().addBasic(xmlMapping,
- new PropertyAuditingData(prefix, "field", ModificationStore.FULL, RelationTargetAuditMode.AUDITED, null, null, false),
- value, null, true, true);
+ }
+ else {
+ // Last but one parameter: collection components are always insertable
+ final boolean mapped = mainGenerator.getBasicMetadataGenerator().addBasic(
+ xmlMapping,
+ new PropertyAuditingData(
+ prefix,
+ "field",
+ ModificationStore.FULL,
+ RelationTargetAuditMode.AUDITED,
+ null,
+ null,
+ false
+ ),
+ value,
+ null,
+ true,
+ true
+ );
- if (mapped) {
- // Simple values are always stored in the first item of the array returned by the query generator.
- return new MiddleComponentData(new MiddleSimpleComponentMapper(mainGenerator.getVerEntCfg(), prefix), 0);
- } else {
- mainGenerator.throwUnsupportedTypeException(type, referencingEntityName, propertyName);
- // Impossible to get here.
- throw new AssertionError();
- }
- }
- }
+ if ( mapped ) {
+ // Simple values are always stored in the first item of the array returned by the query generator.
+ return new MiddleComponentData(
+ new MiddleSimpleComponentMapper( mainGenerator.getVerEntCfg(), prefix ),
+ 0
+ );
+ }
+ else {
+ mainGenerator.throwUnsupportedTypeException( type, referencingEntityName, propertyName );
+ // Impossible to get here.
+ throw new AssertionError();
+ }
+ }
+ }
- private void addMapper(CommonCollectionMapperData commonCollectionMapperData, MiddleComponentData elementComponentData,
- MiddleComponentData indexComponentData) {
- Type type = propertyValue.getType();
- boolean embeddableElementType = isEmbeddableElementType();
- if (type instanceof SortedSetType) {
- currentMapper.addComposite( propertyAuditingData.getPropertyData(), new SortedSetCollectionMapper(
- commonCollectionMapperData, TreeSet.class, SortedSetProxy.class, elementComponentData,
- propertyValue.getComparator(), embeddableElementType, embeddableElementType ) );
- } else if (type instanceof SetType) {
- currentMapper.addComposite( propertyAuditingData.getPropertyData(), new BasicCollectionMapper(
- commonCollectionMapperData, HashSet.class, SetProxy.class, elementComponentData,
- embeddableElementType, embeddableElementType ) );
- } else if (type instanceof SortedMapType) {
- // Indexed collection, so indexComponentData
is not null.
- currentMapper.addComposite(propertyAuditingData.getPropertyData(),
- new SortedMapCollectionMapper(commonCollectionMapperData,
- TreeMap.class, SortedMapProxy.class, elementComponentData, indexComponentData, propertyValue.getComparator(),
- embeddableElementType));
- } else if (type instanceof MapType) {
- // Indexed collection, so indexComponentData
is not null.
- currentMapper.addComposite(propertyAuditingData.getPropertyData(),
- new MapCollectionMapper(commonCollectionMapperData,
- HashMap.class, MapProxy.class, elementComponentData, indexComponentData, embeddableElementType));
- } else if (type instanceof BagType) {
- currentMapper.addComposite( propertyAuditingData.getPropertyData(), new BasicCollectionMapper(
- commonCollectionMapperData, ArrayList.class, ListProxy.class, elementComponentData,
- embeddableElementType, embeddableElementType ) );
- } else if (type instanceof ListType) {
- // Indexed collection, so indexComponentData
is not null.
- currentMapper.addComposite(propertyAuditingData.getPropertyData(),
- new ListCollectionMapper(commonCollectionMapperData,
- elementComponentData, indexComponentData, embeddableElementType));
- } else {
- mainGenerator.throwUnsupportedTypeException(type, referencingEntityName, propertyName);
- }
- }
+ private void addMapper(
+ CommonCollectionMapperData commonCollectionMapperData,
+ MiddleComponentData elementComponentData,
+ MiddleComponentData indexComponentData) {
+ final Type type = propertyValue.getType();
+ final boolean embeddableElementType = isEmbeddableElementType();
+ if ( type instanceof SortedSetType ) {
+ currentMapper.addComposite(
+ propertyAuditingData.getPropertyData(),
+ new SortedSetCollectionMapper(
+ commonCollectionMapperData,
+ TreeSet.class,
+ SortedSetProxy.class,
+ elementComponentData,
+ propertyValue.getComparator(),
+ embeddableElementType,
+ embeddableElementType
+ )
+ );
+ }
+ else if ( type instanceof SetType ) {
+ currentMapper.addComposite(
+ propertyAuditingData.getPropertyData(),
+ new BasicCollectionMapper(
+ commonCollectionMapperData,
+ HashSet.class,
+ SetProxy.class,
+ elementComponentData,
+ embeddableElementType,
+ embeddableElementType
+ )
+ );
+ }
+ else if ( type instanceof SortedMapType ) {
+ // Indexed collection, so indexComponentData
is not null.
+ currentMapper.addComposite(
+ propertyAuditingData.getPropertyData(),
+ new SortedMapCollectionMapper(
+ commonCollectionMapperData,
+ TreeMap.class,
+ SortedMapProxy.class,
+ elementComponentData,
+ indexComponentData,
+ propertyValue.getComparator(),
+ embeddableElementType
+ )
+ );
+ }
+ else if ( type instanceof MapType ) {
+ // Indexed collection, so indexComponentData
is not null.
+ currentMapper.addComposite(
+ propertyAuditingData.getPropertyData(),
+ new MapCollectionMapper(
+ commonCollectionMapperData,
+ HashMap.class,
+ MapProxy.class,
+ elementComponentData,
+ indexComponentData,
+ embeddableElementType
+ )
+ );
+ }
+ else if ( type instanceof BagType ) {
+ currentMapper.addComposite(
+ propertyAuditingData.getPropertyData(),
+ new BasicCollectionMapper(
+ commonCollectionMapperData,
+ ArrayList.class,
+ ListProxy.class,
+ elementComponentData,
+ embeddableElementType,
+ embeddableElementType
+ )
+ );
+ }
+ else if ( type instanceof ListType ) {
+ // Indexed collection, so indexComponentData
is not null.
+ currentMapper.addComposite(
+ propertyAuditingData.getPropertyData(),
+ new ListCollectionMapper(
+ commonCollectionMapperData,
+ elementComponentData,
+ indexComponentData,
+ embeddableElementType
+ )
+ );
+ }
+ else {
+ mainGenerator.throwUnsupportedTypeException( type, referencingEntityName, propertyName );
+ }
+ }
- private void storeMiddleEntityRelationInformation(String mappedBy) {
- // Only if this is a relation (when there is a referenced entity).
- if (referencedEntityName != null) {
- if (propertyValue.isInverse()) {
- referencingEntityConfiguration.addToManyMiddleNotOwningRelation(propertyName, mappedBy, referencedEntityName);
- } else {
- referencingEntityConfiguration.addToManyMiddleRelation(propertyName, referencedEntityName);
- }
- }
- }
+ private void storeMiddleEntityRelationInformation(String mappedBy) {
+ // Only if this is a relation (when there is a referenced entity).
+ if ( referencedEntityName != null ) {
+ if ( propertyValue.isInverse() ) {
+ referencingEntityConfiguration.addToManyMiddleNotOwningRelation(
+ propertyName,
+ mappedBy,
+ referencedEntityName
+ );
+ }
+ else {
+ referencingEntityConfiguration.addToManyMiddleRelation( propertyName, referencedEntityName );
+ }
+ }
+ }
- private Element createMiddleEntityXml(String auditMiddleTableName, String auditMiddleEntityName, String where) {
- String schema = mainGenerator.getSchema(propertyAuditingData.getJoinTable().schema(), propertyValue.getCollectionTable());
- String catalog = mainGenerator.getCatalog(propertyAuditingData.getJoinTable().catalog(), propertyValue.getCollectionTable());
+ private Element createMiddleEntityXml(String auditMiddleTableName, String auditMiddleEntityName, String where) {
+ final String schema = mainGenerator.getSchema(
+ propertyAuditingData.getJoinTable().schema(),
+ propertyValue.getCollectionTable()
+ );
+ final String catalog = mainGenerator.getCatalog(
+ propertyAuditingData.getJoinTable().catalog(),
+ propertyValue.getCollectionTable()
+ );
- Element middleEntityXml = MetadataTools.createEntity(xmlMappingData.newAdditionalMapping(),
- new AuditTableData(auditMiddleEntityName, auditMiddleTableName, schema, catalog), null, null);
- Element middleEntityXmlId = middleEntityXml.addElement("composite-id");
+ final Element middleEntityXml = MetadataTools.createEntity(
+ xmlMappingData.newAdditionalMapping(),
+ new AuditTableData( auditMiddleEntityName, auditMiddleTableName, schema, catalog ), null, null
+ );
+ final Element middleEntityXmlId = middleEntityXml.addElement( "composite-id" );
- // If there is a where clause on the relation, adding it to the middle entity.
- if (where != null) {
- middleEntityXml.addAttribute("where", where);
- }
+ // If there is a where clause on the relation, adding it to the middle entity.
+ if ( where != null ) {
+ middleEntityXml.addAttribute( "where", where );
+ }
- middleEntityXmlId.addAttribute("name", mainGenerator.getVerEntCfg().getOriginalIdPropName());
+ middleEntityXmlId.addAttribute( "name", mainGenerator.getVerEntCfg().getOriginalIdPropName() );
- // Adding the revision number as a foreign key to the revision info entity to the composite id of the
- // middle table.
- mainGenerator.addRevisionInfoRelation(middleEntityXmlId);
+ // Adding the revision number as a foreign key to the revision info entity to the composite id of the
+ // middle table.
+ mainGenerator.addRevisionInfoRelation( middleEntityXmlId );
- // Adding the revision type property to the entity xml.
- mainGenerator.addRevisionType(isEmbeddableElementType() ? middleEntityXmlId : middleEntityXml, middleEntityXml);
+ // Adding the revision type property to the entity xml.
+ mainGenerator.addRevisionType(
+ isEmbeddableElementType() ? middleEntityXmlId : middleEntityXml,
+ middleEntityXml
+ );
- // All other properties should also be part of the primary key of the middle entity.
- return middleEntityXmlId;
- }
+ // All other properties should also be part of the primary key of the middle entity.
+ return middleEntityXmlId;
+ }
/**
* Checks if the collection element is of {@link ComponentType} type.
@@ -617,107 +842,118 @@ public final class CollectionMetadataGenerator {
return propertyValue.getElement().getType() instanceof ComponentType;
}
- private String getMappedBy(Collection collectionValue) {
- PersistentClass referencedClass = null;
- if (collectionValue.getElement() instanceof OneToMany) {
- OneToMany oneToManyValue = (OneToMany) collectionValue.getElement();
- referencedClass = oneToManyValue.getAssociatedClass();
- } else if (collectionValue.getElement() instanceof ManyToOne) {
- // Case for bi-directional relation with @JoinTable on the owning @ManyToOne side.
- ManyToOne manyToOneValue = (ManyToOne) collectionValue.getElement();
- referencedClass = manyToOneValue.getMappings().getClass(manyToOneValue.getReferencedEntityName());
- }
+ private String getMappedBy(Collection collectionValue) {
+ PersistentClass referencedClass = null;
+ if ( collectionValue.getElement() instanceof OneToMany ) {
+ final OneToMany oneToManyValue = (OneToMany) collectionValue.getElement();
+ referencedClass = oneToManyValue.getAssociatedClass();
+ }
+ else if ( collectionValue.getElement() instanceof ManyToOne ) {
+ // Case for bi-directional relation with @JoinTable on the owning @ManyToOne side.
+ final ManyToOne manyToOneValue = (ManyToOne) collectionValue.getElement();
+ referencedClass = manyToOneValue.getMappings().getClass( manyToOneValue.getReferencedEntityName() );
+ }
- // If there's an @AuditMappedBy specified, returning it directly.
- String auditMappedBy = propertyAuditingData.getAuditMappedBy();
- if (auditMappedBy != null) {
- return auditMappedBy;
- }
+ // If there's an @AuditMappedBy specified, returning it directly.
+ final String auditMappedBy = propertyAuditingData.getAuditMappedBy();
+ if ( auditMappedBy != null ) {
+ return auditMappedBy;
+ }
- // searching in referenced class
- String mappedBy = this.searchMappedBy(referencedClass, collectionValue);
+ // searching in referenced class
+ String mappedBy = this.searchMappedBy( referencedClass, collectionValue );
- if(mappedBy == null) {
- LOG.debugf("Going to search the mapped by attribute for %s in superclasses of entity: %s",
- propertyName,
- referencedClass.getClassName());
+ if ( mappedBy == null ) {
+ LOG.debugf(
+ "Going to search the mapped by attribute for %s in superclasses of entity: %s",
+ propertyName,
+ referencedClass.getClassName()
+ );
- PersistentClass tempClass = referencedClass;
- while ((mappedBy == null) && (tempClass.getSuperclass() != null)) {
- LOG.debugf("Searching in superclass: %s", tempClass.getSuperclass().getClassName());
- mappedBy = this.searchMappedBy(tempClass.getSuperclass(), collectionValue);
+ PersistentClass tempClass = referencedClass;
+ while ( (mappedBy == null) && (tempClass.getSuperclass() != null) ) {
+ LOG.debugf( "Searching in superclass: %s", tempClass.getSuperclass().getClassName() );
+ mappedBy = this.searchMappedBy( tempClass.getSuperclass(), collectionValue );
tempClass = tempClass.getSuperclass();
}
- }
+ }
- if(mappedBy == null) {
- throw new MappingException("Unable to read the mapped by attribute for " + propertyName + " in "
- + referencedClass.getClassName() + "!");
- }
+ if ( mappedBy == null ) {
+ throw new MappingException(
+ "Unable to read the mapped by attribute for " + propertyName + " in "
+ + referencedClass.getClassName() + "!"
+ );
+ }
- return mappedBy;
- }
+ return mappedBy;
+ }
- @SuppressWarnings({"unchecked"})
- private String searchMappedBy(PersistentClass referencedClass, Collection collectionValue) {
- Iterator assocClassProps = referencedClass.getPropertyIterator();
- while (assocClassProps.hasNext()) {
- Property property = assocClassProps.next();
+ @SuppressWarnings({"unchecked"})
+ private String searchMappedBy(PersistentClass referencedClass, Collection collectionValue) {
+ final Iterator assocClassProps = referencedClass.getPropertyIterator();
+ while ( assocClassProps.hasNext() ) {
+ final Property property = assocClassProps.next();
- if (Tools.iteratorsContentEqual(property.getValue().getColumnIterator(),
- collectionValue.getKey().getColumnIterator())) {
- return property.getName();
- }
- }
- return null;
- }
-
- private String getMappedBy(Table collectionTable, PersistentClass referencedClass) {
- // If there's an @AuditMappedBy specified, returning it directly.
- String auditMappedBy = propertyAuditingData.getAuditMappedBy();
- if (auditMappedBy != null) {
- return auditMappedBy;
- }
-
- // searching in referenced class
- String mappedBy = this.searchMappedBy(referencedClass, collectionTable);
-
- // not found on referenced class, searching on superclasses
- if(mappedBy == null) {
- LOG.debugf("Going to search the mapped by attribute for %s in superclasses of entity: %s",
- propertyName,
- referencedClass.getClassName());
-
- PersistentClass tempClass = referencedClass;
- while ((mappedBy == null) && (tempClass.getSuperclass() != null)) {
- LOG.debugf("Searching in superclass: %s", tempClass.getSuperclass().getClassName());
- mappedBy = this.searchMappedBy(tempClass.getSuperclass(), collectionTable);
- tempClass = tempClass.getSuperclass();
+ if ( Tools.iteratorsContentEqual(
+ property.getValue().getColumnIterator(),
+ collectionValue.getKey().getColumnIterator()
+ ) ) {
+ return property.getName();
}
- }
+ }
+ return null;
+ }
- if(mappedBy == null) {
- throw new MappingException("Unable to read the mapped by attribute for " + propertyName + " in "
- + referencedClass.getClassName() + "!");
- }
+ private String getMappedBy(Table collectionTable, PersistentClass referencedClass) {
+ // If there's an @AuditMappedBy specified, returning it directly.
+ final String auditMappedBy = propertyAuditingData.getAuditMappedBy();
+ if ( auditMappedBy != null ) {
+ return auditMappedBy;
+ }
- return mappedBy;
- }
+ // searching in referenced class
+ String mappedBy = this.searchMappedBy( referencedClass, collectionTable );
- @SuppressWarnings({"unchecked"})
- private String searchMappedBy(PersistentClass referencedClass, Table collectionTable) {
- Iterator properties = referencedClass.getPropertyIterator();
- while (properties.hasNext()) {
- Property property = properties.next();
- if (property.getValue() instanceof Collection) {
- // The equality is intentional. We want to find a collection property with the same collection table.
- //noinspection ObjectEquality
- if (((Collection) property.getValue()).getCollectionTable() == collectionTable) {
- return property.getName();
- }
- }
- }
- return null;
- }
+ // not found on referenced class, searching on superclasses
+ if ( mappedBy == null ) {
+ LOG.debugf(
+ "Going to search the mapped by attribute for %s in superclasses of entity: %s",
+ propertyName,
+ referencedClass.getClassName()
+ );
+
+ PersistentClass tempClass = referencedClass;
+ while ( (mappedBy == null) && (tempClass.getSuperclass() != null) ) {
+ LOG.debugf( "Searching in superclass: %s", tempClass.getSuperclass().getClassName() );
+ mappedBy = this.searchMappedBy( tempClass.getSuperclass(), collectionTable );
+ tempClass = tempClass.getSuperclass();
+ }
+ }
+
+ if ( mappedBy == null ) {
+ throw new MappingException(
+ "Unable to read the mapped by attribute for " + propertyName + " in "
+ + referencedClass.getClassName() + "!"
+ );
+ }
+
+ return mappedBy;
+ }
+
+ @SuppressWarnings({"unchecked"})
+ private String searchMappedBy(PersistentClass referencedClass, Table collectionTable) {
+ final Iterator properties = referencedClass.getPropertyIterator();
+ while ( properties.hasNext() ) {
+ final Property property = properties.next();
+ if ( property.getValue() instanceof Collection ) {
+ // The equality is intentional. We want to find a collection property with the same collection table.
+ //noinspection ObjectEquality
+ if ( ((Collection) property.getValue()).getCollectionTable() == collectionTable ) {
+ return property.getName();
+ }
+ }
+ }
+ return null;
+ }
}
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/ComponentMetadataGenerator.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/ComponentMetadataGenerator.java
index b1efd5c803..103a17e9f5 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/ComponentMetadataGenerator.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/ComponentMetadataGenerator.java
@@ -1,3 +1,26 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2013, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
package org.hibernate.envers.configuration.internal.metadata;
import java.util.Iterator;
@@ -14,6 +37,7 @@ import org.hibernate.mapping.Value;
/**
* Generates metadata for components.
+ *
* @author Adam Warski (adam at warski dot org)
*/
public final class ComponentMetadataGenerator {
@@ -24,29 +48,38 @@ public final class ComponentMetadataGenerator {
}
@SuppressWarnings({"unchecked"})
- public void addComponent(Element parent, PropertyAuditingData propertyAuditingData,
- Value value, CompositeMapperBuilder mapper, String entityName,
- EntityXmlMappingData xmlMappingData, boolean firstPass) {
- Component prop_component = (Component) value;
+ public void addComponent(
+ Element parent, PropertyAuditingData propertyAuditingData,
+ Value value, CompositeMapperBuilder mapper, String entityName,
+ EntityXmlMappingData xmlMappingData, boolean firstPass) {
+ final Component propComponent = (Component) value;
- Class componentClass = ReflectionTools.loadClass( prop_component.getComponentClassName(), mainGenerator.getClassLoaderService() );
- CompositeMapperBuilder componentMapper = mapper.addComponent( propertyAuditingData.getPropertyData(), componentClass );
+ final Class componentClass = ReflectionTools.loadClass(
+ propComponent.getComponentClassName(),
+ mainGenerator.getClassLoaderService()
+ );
+ final CompositeMapperBuilder componentMapper = mapper.addComponent(
+ propertyAuditingData.getPropertyData(),
+ componentClass
+ );
// The property auditing data must be for a component.
- ComponentAuditingData componentAuditingData = (ComponentAuditingData) propertyAuditingData;
+ final ComponentAuditingData componentAuditingData = (ComponentAuditingData) propertyAuditingData;
// Adding all properties of the component
- Iterator properties = (Iterator) prop_component.getPropertyIterator();
- while (properties.hasNext()) {
- Property property = properties.next();
+ final Iterator properties = (Iterator) propComponent.getPropertyIterator();
+ while ( properties.hasNext() ) {
+ final Property property = properties.next();
- PropertyAuditingData componentPropertyAuditingData =
- componentAuditingData.getPropertyAuditingData(property.getName());
+ final PropertyAuditingData componentPropertyAuditingData =
+ componentAuditingData.getPropertyAuditingData( property.getName() );
// Checking if that property is audited
- if (componentPropertyAuditingData != null) {
- mainGenerator.addValue(parent, property.getValue(), componentMapper, entityName, xmlMappingData,
- componentPropertyAuditingData, property.isInsertable(), firstPass, false);
+ if ( componentPropertyAuditingData != null ) {
+ mainGenerator.addValue(
+ parent, property.getValue(), componentMapper, entityName, xmlMappingData,
+ componentPropertyAuditingData, property.isInsertable(), firstPass, false
+ );
}
}
}
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 7584d16643..8132442490 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
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2008, 2013, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -22,6 +22,7 @@
* Boston, MA 02110-1301 USA
*/
package org.hibernate.envers.configuration.internal.metadata;
+
import java.util.ArrayList;
import java.util.List;
@@ -33,39 +34,39 @@ import org.dom4j.Element;
* @author Adam Warski (adam at warski dot org)
*/
public class EntityXmlMappingData {
- private Document mainXmlMapping;
- private List additionalXmlMappings;
- /**
- * The xml element that maps the class. The root can be one of the folowing elements:
- * class, subclass, union-subclass, joined-subclass
- */
- private Element classMapping;
+ private Document mainXmlMapping;
+ private List additionalXmlMappings;
+ /**
+ * The xml element that maps the class. The root can be one of the folowing elements:
+ * class, subclass, union-subclass, joined-subclass
+ */
+ private Element classMapping;
- public EntityXmlMappingData() {
- mainXmlMapping = DocumentHelper.createDocument();
- additionalXmlMappings = new ArrayList();
- }
+ public EntityXmlMappingData() {
+ mainXmlMapping = DocumentHelper.createDocument();
+ additionalXmlMappings = new ArrayList();
+ }
- public Document getMainXmlMapping() {
- return mainXmlMapping;
- }
+ public Document getMainXmlMapping() {
+ return mainXmlMapping;
+ }
- public List getAdditionalXmlMappings() {
- return additionalXmlMappings;
- }
+ public List getAdditionalXmlMappings() {
+ return additionalXmlMappings;
+ }
- public Document newAdditionalMapping() {
- Document additionalMapping = DocumentHelper.createDocument();
- additionalXmlMappings.add(additionalMapping);
+ public Document newAdditionalMapping() {
+ Document additionalMapping = DocumentHelper.createDocument();
+ additionalXmlMappings.add( additionalMapping );
- return additionalMapping;
- }
+ return additionalMapping;
+ }
- public Element getClassMapping() {
- return classMapping;
- }
+ public Element getClassMapping() {
+ return classMapping;
+ }
- public void setClassMapping(Element classMapping) {
- this.classMapping = classMapping;
- }
+ public void setClassMapping(Element classMapping) {
+ this.classMapping = classMapping;
+ }
}
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/IdMetadataGenerator.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/IdMetadataGenerator.java
index d0064390cc..aa03697b1e 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/IdMetadataGenerator.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/IdMetadataGenerator.java
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2008, 2013, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -22,6 +22,7 @@
* Boston, MA 02110-1301 USA
*/
package org.hibernate.envers.configuration.internal.metadata;
+
import java.util.Iterator;
import org.dom4j.Element;
@@ -47,127 +48,181 @@ import org.hibernate.type.Type;
/**
* Generates metadata for primary identifiers (ids) of versions entities.
+ *
* @author Adam Warski (adam at warski dot org)
*/
public final class IdMetadataGenerator {
- private final AuditMetadataGenerator mainGenerator;
+ private final AuditMetadataGenerator mainGenerator;
- IdMetadataGenerator(AuditMetadataGenerator auditMetadataGenerator) {
- mainGenerator = auditMetadataGenerator;
- }
+ IdMetadataGenerator(AuditMetadataGenerator auditMetadataGenerator) {
+ mainGenerator = auditMetadataGenerator;
+ }
- @SuppressWarnings({"unchecked"})
- private boolean addIdProperties(Element parent, Iterator properties, SimpleMapperBuilder mapper, boolean key,
- boolean audited) {
- while (properties.hasNext()) {
- Property property = properties.next();
- Type propertyType = property.getType();
- if (!"_identifierMapper".equals(property.getName())) {
- boolean added = false;
- if (propertyType instanceof ManyToOneType) {
- added = mainGenerator.getBasicMetadataGenerator().addManyToOne(parent,
- getIdPersistentPropertyAuditingData(property),
- property.getValue(), mapper);
- } else {
- // Last but one parameter: ids are always insertable
- added = mainGenerator.getBasicMetadataGenerator().addBasic(parent,
- getIdPersistentPropertyAuditingData(property),
- property.getValue(), mapper, true, key);
- }
- if (!added) {
- // If the entity is audited, and a non-supported id component is used, throwing an exception.
- // If the entity is not audited, then we simply don't support this entity, even in
- // target relation mode not audited.
- if (audited) {
- throw new MappingException("Type not supported: " + propertyType.getClass().getName());
- } else {
- return false;
- }
- }
- }
- }
+ @SuppressWarnings({"unchecked"})
+ private boolean addIdProperties(
+ Element parent,
+ Iterator properties,
+ SimpleMapperBuilder mapper,
+ boolean key,
+ boolean audited) {
+ while ( properties.hasNext() ) {
+ final Property property = properties.next();
+ final Type propertyType = property.getType();
+ if ( !"_identifierMapper".equals( property.getName() ) ) {
+ boolean added = false;
+ if ( propertyType instanceof ManyToOneType ) {
+ added = mainGenerator.getBasicMetadataGenerator().addManyToOne(
+ parent,
+ getIdPersistentPropertyAuditingData( property ),
+ property.getValue(),
+ mapper
+ );
+ }
+ else {
+ // Last but one parameter: ids are always insertable
+ added = mainGenerator.getBasicMetadataGenerator().addBasic(
+ parent,
+ getIdPersistentPropertyAuditingData( property ),
+ property.getValue(),
+ mapper,
+ true,
+ key
+ );
+ }
+ if ( !added ) {
+ // If the entity is audited, and a non-supported id component is used, throwing an exception.
+ // If the entity is not audited, then we simply don't support this entity, even in
+ // target relation mode not audited.
+ if ( audited ) {
+ throw new MappingException( "Type not supported: " + propertyType.getClass().getName() );
+ }
+ else {
+ return false;
+ }
+ }
+ }
+ }
- return true;
- }
+ return true;
+ }
- @SuppressWarnings({"unchecked"})
- IdMappingData addId(PersistentClass pc, boolean audited) {
- // Xml mapping which will be used for relations
- Element rel_id_mapping = new DefaultElement("properties");
- // Xml mapping which will be used for the primary key of the versions table
- Element orig_id_mapping = new DefaultElement("composite-id");
+ @SuppressWarnings({"unchecked"})
+ IdMappingData addId(PersistentClass pc, boolean audited) {
+ // Xml mapping which will be used for relations
+ final Element relIdMapping = new DefaultElement( "properties" );
+ // Xml mapping which will be used for the primary key of the versions table
+ final Element origIdMapping = new DefaultElement( "composite-id" );
- Property id_prop = pc.getIdentifierProperty();
- Component id_mapper = pc.getIdentifierMapper();
+ final Property idProp = pc.getIdentifierProperty();
+ final Component idMapper = pc.getIdentifierMapper();
- // Checking if the id mapping is supported
- if (id_mapper == null && id_prop == null) {
- return null;
- }
+ // Checking if the id mapping is supported
+ if ( idMapper == null && idProp == null ) {
+ return null;
+ }
- SimpleIdMapperBuilder mapper;
- if (id_mapper != null) {
- // Multiple id
-
- Class componentClass = ReflectionTools.loadClass(
- ( (Component) pc.getIdentifier() ).getComponentClassName(), mainGenerator.getClassLoaderService()
+ SimpleIdMapperBuilder mapper;
+ if ( idMapper != null ) {
+ // Multiple id
+ final Class componentClass = ReflectionTools.loadClass(
+ ( (Component) pc.getIdentifier() ).getComponentClassName(),
+ mainGenerator.getClassLoaderService()
);
mapper = new MultipleIdMapper( componentClass );
- if (!addIdProperties(rel_id_mapping, (Iterator) id_mapper.getPropertyIterator(), mapper, false, audited)) {
- return null;
- }
+ if ( !addIdProperties(
+ relIdMapping,
+ (Iterator) idMapper.getPropertyIterator(),
+ mapper,
+ false,
+ audited
+ ) ) {
+ return null;
+ }
- // null mapper - the mapping where already added the first time, now we only want to generate the xml
- if (!addIdProperties(orig_id_mapping, (Iterator) id_mapper.getPropertyIterator(), null, true, audited)) {
- return null;
- }
- } else if (id_prop.isComposite()) {
- // Embedded id
-
- Component id_component = (Component) id_prop.getValue();
- Class embeddableClass = ReflectionTools.loadClass(
- id_component.getComponentClassName(), mainGenerator.getClassLoaderService()
+ // null mapper - the mapping where already added the first time, now we only want to generate the xml
+ if ( !addIdProperties(
+ origIdMapping,
+ (Iterator) idMapper.getPropertyIterator(),
+ null,
+ true,
+ audited
+ ) ) {
+ return null;
+ }
+ }
+ else if ( idProp.isComposite() ) {
+ // Embedded id
+ final Component idComponent = (Component) idProp.getValue();
+ final Class embeddableClass = ReflectionTools.loadClass(
+ idComponent.getComponentClassName(),
+ mainGenerator.getClassLoaderService()
);
- mapper = new EmbeddedIdMapper( getIdPropertyData(id_prop), embeddableClass );
- if (!addIdProperties(rel_id_mapping, (Iterator) id_component.getPropertyIterator(), mapper, false, audited)) {
- return null;
- }
+ mapper = new EmbeddedIdMapper( getIdPropertyData( idProp ), embeddableClass );
+ if ( !addIdProperties(
+ relIdMapping,
+ (Iterator) idComponent.getPropertyIterator(),
+ mapper,
+ false,
+ audited
+ ) ) {
+ return null;
+ }
- // null mapper - the mapping where already added the first time, now we only want to generate the xml
- if (!addIdProperties(orig_id_mapping, (Iterator) id_component.getPropertyIterator(), null, true, audited)) {
- return null;
- }
- } else {
- // Single id
-
- mapper = new SingleIdMapper();
+ // null mapper - the mapping where already added the first time, now we only want to generate the xml
+ if ( !addIdProperties(
+ origIdMapping,
+ (Iterator) idComponent.getPropertyIterator(),
+ null,
+ true,
+ audited
+ ) ) {
+ return null;
+ }
+ }
+ else {
+ // Single id
+ mapper = new SingleIdMapper();
- // Last but one parameter: ids are always insertable
- mainGenerator.getBasicMetadataGenerator().addBasic(rel_id_mapping,
- getIdPersistentPropertyAuditingData(id_prop),
- id_prop.getValue(), mapper, true, false);
+ // Last but one parameter: ids are always insertable
+ mainGenerator.getBasicMetadataGenerator().addBasic(
+ relIdMapping,
+ getIdPersistentPropertyAuditingData( idProp ),
+ idProp.getValue(),
+ mapper,
+ true,
+ false
+ );
- // null mapper - the mapping where already added the first time, now we only want to generate the xml
- mainGenerator.getBasicMetadataGenerator().addBasic(orig_id_mapping,
- getIdPersistentPropertyAuditingData(id_prop),
- id_prop.getValue(), null, true, true);
- }
+ // null mapper - the mapping where already added the first time, now we only want to generate the xml
+ mainGenerator.getBasicMetadataGenerator().addBasic(
+ origIdMapping,
+ getIdPersistentPropertyAuditingData( idProp ),
+ idProp.getValue(),
+ null,
+ true,
+ true
+ );
+ }
- orig_id_mapping.addAttribute("name", mainGenerator.getVerEntCfg().getOriginalIdPropName());
+ origIdMapping.addAttribute( "name", mainGenerator.getVerEntCfg().getOriginalIdPropName() );
- // Adding a relation to the revision entity (effectively: the "revision number" property)
- mainGenerator.addRevisionInfoRelation(orig_id_mapping);
+ // Adding a relation to the revision entity (effectively: the "revision number" property)
+ mainGenerator.addRevisionInfoRelation( origIdMapping );
- return new IdMappingData(mapper, orig_id_mapping, rel_id_mapping);
- }
+ return new IdMappingData( mapper, origIdMapping, relIdMapping );
+ }
- private PropertyData getIdPropertyData(Property property) {
- return new PropertyData(property.getName(), property.getName(), property.getPropertyAccessorName(),
- ModificationStore.FULL);
- }
+ private PropertyData getIdPropertyData(Property property) {
+ return new PropertyData(
+ property.getName(), property.getName(), property.getPropertyAccessorName(),
+ ModificationStore.FULL
+ );
+ }
- private PropertyAuditingData getIdPersistentPropertyAuditingData(Property property) {
- return new PropertyAuditingData(property.getName(), property.getPropertyAccessorName(),
- ModificationStore.FULL, RelationTargetAuditMode.AUDITED, null, null, false);
- }
+ private PropertyAuditingData getIdPersistentPropertyAuditingData(Property property) {
+ return new PropertyAuditingData(
+ property.getName(), property.getPropertyAccessorName(),
+ ModificationStore.FULL, RelationTargetAuditMode.AUDITED, null, null, false
+ );
+ }
}
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/InheritanceType.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/InheritanceType.java
index 87cb5a7f0c..e912f525ff 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/InheritanceType.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/InheritanceType.java
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2008, 2013, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -22,6 +22,7 @@
* Boston, MA 02110-1301 USA
*/
package org.hibernate.envers.configuration.internal.metadata;
+
import org.hibernate.MappingException;
import org.hibernate.mapping.JoinedSubclass;
import org.hibernate.mapping.PersistentClass;
@@ -33,33 +34,36 @@ import org.hibernate.mapping.UnionSubclass;
* @author Adam Warski (adam at warski dot org)
*/
public enum InheritanceType {
- NONE,
- JOINED,
- SINGLE,
- TABLE_PER_CLASS;
+ NONE,
+ JOINED,
+ SINGLE,
+ TABLE_PER_CLASS;
- /**
- * @param pc The class for which to get the inheritance type.
- * @return The inheritance type of this class. NONE, if this class does not inherit from
- * another persisten class.
- */
- public static InheritanceType get(PersistentClass pc) {
- PersistentClass superclass = pc.getSuperclass();
- if (superclass == null) {
- return InheritanceType.NONE;
- }
+ /**
+ * @param pc The class for which to get the inheritance type.
+ *
+ * @return The inheritance type of this class. NONE, if this class does not inherit from
+ * another persistent class.
+ */
+ public static InheritanceType get(PersistentClass pc) {
+ final PersistentClass superclass = pc.getSuperclass();
+ if ( superclass == null ) {
+ return InheritanceType.NONE;
+ }
- // We assume that every subclass is of the same type.
- Subclass subclass = (Subclass) superclass.getSubclassIterator().next();
+ // We assume that every subclass is of the same type.
+ final Subclass subclass = (Subclass) superclass.getSubclassIterator().next();
- if (subclass instanceof SingleTableSubclass) {
- return InheritanceType.SINGLE;
- } else if (subclass instanceof JoinedSubclass) {
- return InheritanceType.JOINED;
- } else if (subclass instanceof UnionSubclass) {
- return InheritanceType.TABLE_PER_CLASS;
- }
+ if ( subclass instanceof SingleTableSubclass ) {
+ return InheritanceType.SINGLE;
+ }
+ else if ( subclass instanceof JoinedSubclass ) {
+ return InheritanceType.JOINED;
+ }
+ else if ( subclass instanceof UnionSubclass ) {
+ return InheritanceType.TABLE_PER_CLASS;
+ }
- throw new MappingException("Unknown subclass class: " + subclass.getClass());
- }
+ throw new MappingException( "Unknown subclass class: " + subclass.getClass() );
+ }
}
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/MetadataTools.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/MetadataTools.java
index 5bc51020c2..98863cae25 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/MetadataTools.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/MetadataTools.java
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2008, 2013, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -22,8 +22,9 @@
* Boston, MA 02110-1301 USA
*/
package org.hibernate.envers.configuration.internal.metadata;
-import java.util.Iterator;
+
import javax.persistence.JoinColumn;
+import java.util.Iterator;
import org.dom4j.Attribute;
import org.dom4j.Document;
@@ -41,52 +42,72 @@ import org.hibernate.mapping.Selectable;
*/
public class MetadataTools {
- public static Element addNativelyGeneratedId(Element parent, String name, String type,
- boolean useRevisionEntityWithNativeId) {
- Element id_mapping = parent.addElement("id");
- id_mapping.addAttribute("name", name).addAttribute("type", type);
+ public static Element addNativelyGeneratedId(
+ Element parent, String name, String type,
+ boolean useRevisionEntityWithNativeId) {
+ final Element idMapping = parent.addElement( "id" );
+ idMapping.addAttribute( "name", name ).addAttribute( "type", type );
- Element generator_mapping = id_mapping.addElement("generator");
- if (useRevisionEntityWithNativeId) {
- generator_mapping.addAttribute("class", "native");
- } else {
- generator_mapping.addAttribute("class", "org.hibernate.envers.enhanced.OrderedSequenceGenerator");
- generator_mapping.addElement("param").addAttribute("name", "sequence_name").setText("REVISION_GENERATOR");
- generator_mapping.addElement("param").addAttribute("name", "table_name").setText("REVISION_GENERATOR");
- generator_mapping.addElement("param").addAttribute("name", "initial_value").setText("1");
- generator_mapping.addElement("param").addAttribute("name", "increment_size").setText("1");
- }
-// generator_mapping.addAttribute("class", "sequence");
-// generator_mapping.addElement("param").addAttribute("name", "sequence").setText("custom");
+ final Element generatorMapping = idMapping.addElement( "generator" );
+ if ( useRevisionEntityWithNativeId ) {
+ generatorMapping.addAttribute( "class", "native" );
+ }
+ else {
+ generatorMapping.addAttribute( "class", "org.hibernate.envers.enhanced.OrderedSequenceGenerator" );
+ generatorMapping.addElement( "param" ).addAttribute( "name", "sequence_name" ).setText(
+ "REVISION_GENERATOR"
+ );
+ generatorMapping.addElement( "param" )
+ .addAttribute( "name", "table_name" )
+ .setText( "REVISION_GENERATOR" );
+ generatorMapping.addElement( "param" ).addAttribute( "name", "initial_value" ).setText( "1" );
+ generatorMapping.addElement( "param" ).addAttribute( "name", "increment_size" ).setText( "1" );
+ }
+// generatorMapping.addAttribute("class", "sequence");
+// generatorMapping.addElement("param").addAttribute("name", "sequence").setText("custom");
- return id_mapping;
- }
+ return idMapping;
+ }
- public static Element addProperty(Element parent, String name, String type, boolean insertable, boolean updateable, boolean key) {
- Element prop_mapping;
- if (key) {
- prop_mapping = parent.addElement("key-property");
- } else {
- prop_mapping = parent.addElement("property");
- }
+ public static Element addProperty(
+ Element parent,
+ String name,
+ String type,
+ boolean insertable,
+ boolean updateable,
+ boolean key) {
+ final Element propMapping;
+ if ( key ) {
+ propMapping = parent.addElement( "key-property" );
+ }
+ else {
+ propMapping = parent.addElement( "property" );
+ }
- prop_mapping.addAttribute("name", name);
- prop_mapping.addAttribute("insert", Boolean.toString(insertable));
- prop_mapping.addAttribute("update", Boolean.toString(updateable));
+ propMapping.addAttribute( "name", name );
+ propMapping.addAttribute( "insert", Boolean.toString( insertable ) );
+ propMapping.addAttribute( "update", Boolean.toString( updateable ) );
- if (type != null) {
- prop_mapping.addAttribute("type", type);
- }
+ if ( type != null ) {
+ propMapping.addAttribute( "type", type );
+ }
- return prop_mapping;
- }
+ return propMapping;
+ }
- public static Element addProperty(Element parent, String name, String type, boolean insertable, boolean key) {
- return addProperty(parent, name, type, insertable, false, key);
- }
+ public static Element addProperty(Element parent, String name, String type, boolean insertable, boolean key) {
+ return addProperty( parent, name, type, insertable, false, key );
+ }
public static Element addModifiedFlagProperty(Element parent, String propertyName, String suffix) {
- return addProperty(parent, getModifiedFlagPropertyName(propertyName, suffix), "boolean", true, false, false);
+ return addProperty(
+ parent,
+ getModifiedFlagPropertyName( propertyName, suffix ),
+ "boolean",
+ true,
+ false,
+ false
+ );
}
public static String getModifiedFlagPropertyName(String propertyName, String suffix) {
@@ -94,256 +115,319 @@ public class MetadataTools {
}
private static void addOrModifyAttribute(Element parent, String name, String value) {
- Attribute attribute = parent.attribute(name);
- if (attribute == null) {
- parent.addAttribute(name, value);
- } else {
- attribute.setValue(value);
- }
- }
-
- /**
- * Column name shall be wrapped with '`' signs if quotation required.
- */
- public static Element addOrModifyColumn(Element parent, String name) {
- Element column_mapping = parent.element("column");
-
- if (column_mapping == null) {
- return addColumn(parent, name, null, null, null, null, null, null);
- }
-
- if (!StringTools.isEmpty(name)) {
- addOrModifyAttribute(column_mapping, "name", name);
- }
-
- return column_mapping;
- }
-
- /**
- * Adds new column
element. Method assumes that the value of name
attribute is already
- * wrapped with '`' signs if quotation required. It shall be invoked when column name is taken directly from configuration
- * file and not from {@link org.hibernate.mapping.PersistentClass} descriptor.
- */
- public static Element addColumn(Element parent, String name, Integer length, Integer scale, Integer precision,
- String sqlType, String customRead, String customWrite) {
- return addColumn(parent, name, length, scale, precision, sqlType, customRead, customWrite, false);
- }
-
- public static Element addColumn(Element parent, String name, Integer length, Integer scale, Integer precision,
- String sqlType, String customRead, String customWrite, boolean quoted) {
- Element column_mapping = parent.addElement("column");
-
- column_mapping.addAttribute("name", quoted ? "`" + name + "`" : name);
- if (length != null) {
- column_mapping.addAttribute("length", length.toString());
- }
- if (scale != null) {
- column_mapping.addAttribute("scale", Integer.toString(scale));
+ final Attribute attribute = parent.attribute( name );
+ if ( attribute == null ) {
+ parent.addAttribute( name, value );
}
- if (precision != null) {
- column_mapping.addAttribute("precision", Integer.toString(precision));
+ else {
+ attribute.setValue( value );
}
- if (!StringTools.isEmpty(sqlType)) {
- column_mapping.addAttribute("sql-type", sqlType);
- }
+ }
- if (!StringTools.isEmpty(customRead)) {
- column_mapping.addAttribute("read", customRead);
- }
- if (!StringTools.isEmpty(customWrite)) {
- column_mapping.addAttribute("write", customWrite);
- }
+ /**
+ * Column name shall be wrapped with '`' signs if quotation required.
+ */
+ public static Element addOrModifyColumn(Element parent, String name) {
+ final Element columnMapping = parent.element( "column" );
- return column_mapping;
- }
+ if ( columnMapping == null ) {
+ return addColumn( parent, name, null, null, null, null, null, null );
+ }
- private static Element createEntityCommon(Document document, String type, AuditTableData auditTableData,
- String discriminatorValue, Boolean isAbstract) {
- Element hibernate_mapping = document.addElement("hibernate-mapping");
- hibernate_mapping.addAttribute("auto-import", "false");
+ if ( !StringTools.isEmpty( name ) ) {
+ addOrModifyAttribute( columnMapping, "name", name );
+ }
- Element class_mapping = hibernate_mapping.addElement(type);
+ return columnMapping;
+ }
- if (auditTableData.getAuditEntityName() != null) {
- class_mapping.addAttribute("entity-name", auditTableData.getAuditEntityName());
- }
+ /**
+ * Adds new column
element. Method assumes that the value of name
attribute is already
+ * wrapped with '`' signs if quotation required. It shall be invoked when column name is taken directly from configuration
+ * file and not from {@link org.hibernate.mapping.PersistentClass} descriptor.
+ */
+ public static Element addColumn(
+ Element parent,
+ String name,
+ Integer length,
+ Integer scale,
+ Integer precision,
+ String sqlType,
+ String customRead,
+ String customWrite) {
+ return addColumn( parent, name, length, scale, precision, sqlType, customRead, customWrite, false );
+ }
- if (discriminatorValue != null) {
- class_mapping.addAttribute("discriminator-value", discriminatorValue);
- }
+ public static Element addColumn(
+ Element parent,
+ String name,
+ Integer length,
+ Integer scale,
+ Integer precision,
+ String sqlType,
+ String customRead,
+ String customWrite,
+ boolean quoted) {
+ final Element columnMapping = parent.addElement( "column" );
- if (!StringTools.isEmpty(auditTableData.getAuditTableName())) {
- class_mapping.addAttribute("table", auditTableData.getAuditTableName());
- }
+ columnMapping.addAttribute( "name", quoted ? "`" + name + "`" : name );
+ if ( length != null ) {
+ columnMapping.addAttribute( "length", length.toString() );
+ }
+ if ( scale != null ) {
+ columnMapping.addAttribute( "scale", Integer.toString( scale ) );
+ }
+ if ( precision != null ) {
+ columnMapping.addAttribute( "precision", Integer.toString( precision ) );
+ }
+ if ( !StringTools.isEmpty( sqlType ) ) {
+ columnMapping.addAttribute( "sql-type", sqlType );
+ }
- if (!StringTools.isEmpty(auditTableData.getSchema())) {
- class_mapping.addAttribute("schema", auditTableData.getSchema());
- }
+ if ( !StringTools.isEmpty( customRead ) ) {
+ columnMapping.addAttribute( "read", customRead );
+ }
+ if ( !StringTools.isEmpty( customWrite ) ) {
+ columnMapping.addAttribute( "write", customWrite );
+ }
- if (!StringTools.isEmpty(auditTableData.getCatalog())) {
- class_mapping.addAttribute("catalog", auditTableData.getCatalog());
- }
+ return columnMapping;
+ }
- if (isAbstract != null) {
- class_mapping.addAttribute("abstract", isAbstract.toString());
- }
+ private static Element createEntityCommon(
+ Document document,
+ String type,
+ AuditTableData auditTableData,
+ String discriminatorValue,
+ Boolean isAbstract) {
+ final Element hibernateMapping = document.addElement( "hibernate-mapping" );
+ hibernateMapping.addAttribute( "auto-import", "false" );
- return class_mapping;
- }
+ final Element classMapping = hibernateMapping.addElement( type );
- public static Element createEntity(Document document, AuditTableData auditTableData, String discriminatorValue,
- Boolean isAbstract) {
- return createEntityCommon(document, "class", auditTableData, discriminatorValue, isAbstract);
- }
+ if ( auditTableData.getAuditEntityName() != null ) {
+ classMapping.addAttribute( "entity-name", auditTableData.getAuditEntityName() );
+ }
- public static Element createSubclassEntity(Document document, String subclassType, AuditTableData auditTableData,
- String extendsEntityName, String discriminatorValue, Boolean isAbstract) {
- Element class_mapping = createEntityCommon(document, subclassType, auditTableData, discriminatorValue, isAbstract);
+ if ( discriminatorValue != null ) {
+ classMapping.addAttribute( "discriminator-value", discriminatorValue );
+ }
- class_mapping.addAttribute("extends", extendsEntityName);
+ if ( !StringTools.isEmpty( auditTableData.getAuditTableName() ) ) {
+ classMapping.addAttribute( "table", auditTableData.getAuditTableName() );
+ }
- return class_mapping;
- }
+ if ( !StringTools.isEmpty( auditTableData.getSchema() ) ) {
+ classMapping.addAttribute( "schema", auditTableData.getSchema() );
+ }
- public static Element createJoin(Element parent, String tableName,
- String schema, String catalog) {
- Element join_mapping = parent.addElement("join");
+ if ( !StringTools.isEmpty( auditTableData.getCatalog() ) ) {
+ classMapping.addAttribute( "catalog", auditTableData.getCatalog() );
+ }
- join_mapping.addAttribute("table", tableName);
+ if ( isAbstract != null ) {
+ classMapping.addAttribute( "abstract", isAbstract.toString() );
+ }
- if (!StringTools.isEmpty(schema)) {
- join_mapping.addAttribute("schema", schema);
- }
+ return classMapping;
+ }
- if (!StringTools.isEmpty(catalog)) {
- join_mapping.addAttribute("catalog", catalog);
- }
+ public static Element createEntity(
+ Document document,
+ AuditTableData auditTableData,
+ String discriminatorValue,
+ Boolean isAbstract) {
+ return createEntityCommon( document, "class", auditTableData, discriminatorValue, isAbstract );
+ }
- return join_mapping;
- }
+ public static Element createSubclassEntity(
+ Document document,
+ String subclassType,
+ AuditTableData auditTableData,
+ String extendsEntityName,
+ String discriminatorValue,
+ Boolean isAbstract) {
+ final Element classMapping = createEntityCommon(
+ document,
+ subclassType,
+ auditTableData,
+ discriminatorValue,
+ isAbstract
+ );
- public static void addColumns(Element any_mapping, Iterator selectables) {
- while ( selectables.hasNext() ) {
+ classMapping.addAttribute( "extends", extendsEntityName );
+
+ return classMapping;
+ }
+
+ public static Element createJoin(
+ Element parent,
+ String tableName,
+ String schema,
+ String catalog) {
+ final Element joinMapping = parent.addElement( "join" );
+
+ joinMapping.addAttribute( "table", tableName );
+
+ if ( !StringTools.isEmpty( schema ) ) {
+ joinMapping.addAttribute( "schema", schema );
+ }
+
+ if ( !StringTools.isEmpty( catalog ) ) {
+ joinMapping.addAttribute( "catalog", catalog );
+ }
+
+ return joinMapping;
+ }
+
+ public static void addColumns(Element anyMapping, Iterator selectables) {
+ while ( selectables.hasNext() ) {
final Selectable selectable = (Selectable) selectables.next();
if ( selectable.isFormula() ) {
throw new FormulaNotSupportedException();
}
- addColumn( any_mapping, (Column) selectable );
- }
- }
-
- /**
- * Adds column
element with the following attributes (unless empty): name
,
- * length
, scale
, precision
, sql-type
, read
- * and write
.
- * @param any_mapping Parent element.
- * @param column Column descriptor.
- */
- public static void addColumn(Element any_mapping, Column column) {
- addColumn(any_mapping, column.getName(), column.getLength(), column.getScale(), column.getPrecision(),
- column.getSqlType(), column.getCustomRead(), column.getCustomWrite(), column.isQuoted());
- }
-
- @SuppressWarnings({"unchecked"})
- private static void changeNamesInColumnElement(Element element, ColumnNameIterator columnNameIterator) {
- Iterator properties = element.elementIterator();
- while (properties.hasNext()) {
- Element property = properties.next();
-
- if ("column".equals(property.getName())) {
- Attribute nameAttr = property.attribute("name");
- if (nameAttr != null) {
- nameAttr.setText(columnNameIterator.next());
- }
- }
- }
- }
-
- @SuppressWarnings({"unchecked"})
- public static void prefixNamesInPropertyElement(Element element, String prefix, ColumnNameIterator columnNameIterator,
- boolean changeToKey, boolean insertable) {
- Iterator properties = element.elementIterator();
- while (properties.hasNext()) {
- Element property = properties.next();
-
- if ("property".equals(property.getName()) || "many-to-one".equals(property.getName())) {
- Attribute nameAttr = property.attribute("name");
- if (nameAttr != null) {
- nameAttr.setText(prefix + nameAttr.getText());
- }
-
- changeNamesInColumnElement(property, columnNameIterator);
-
- if (changeToKey) {
- property.setName("key-" + property.getName());
- }
-
- if ("property".equals(property.getName())) {
- Attribute insert = property.attribute("insert");
- insert.setText(Boolean.toString(insertable));
- }
- }
- }
- }
-
- /**
- * Adds formula
element.
- * @param element Parent element.
- * @param formula Formula descriptor.
- */
- public static void addFormula(Element element, Formula formula) {
- element.addElement("formula").setText(formula.getText());
- }
-
- /**
- * Adds all column
or formula
elements.
- * @param element Parent element.
- * @param columnIterator Iterator pointing at {@link org.hibernate.mapping.Column} and/or
- * {@link org.hibernate.mapping.Formula} objects.
- */
- public static void addColumnsOrFormulas(Element element, Iterator columnIterator) {
- while (columnIterator.hasNext()) {
- Object o = columnIterator.next();
- if (o instanceof Column) {
- addColumn(element, (Column) o);
- } else if (o instanceof Formula) {
- addFormula(element, (Formula) o);
- }
- }
- }
-
- /**
- * An iterator over column names.
- */
- public static abstract class ColumnNameIterator implements Iterator {
+ addColumn( anyMapping, (Column) selectable );
+ }
}
- public static ColumnNameIterator getColumnNameIterator(final Iterator selectableIterator) {
- return new ColumnNameIterator() {
- public boolean hasNext() {
+ /**
+ * Adds column
element with the following attributes (unless empty): name
,
+ * length
, scale
, precision
, sql-type
, read
+ * and write
.
+ *
+ * @param anyMapping Parent element.
+ * @param column Column descriptor.
+ */
+ public static void addColumn(Element anyMapping, Column column) {
+ addColumn(
+ anyMapping,
+ column.getName(),
+ column.getLength(),
+ column.getScale(),
+ column.getPrecision(),
+ column.getSqlType(),
+ column.getCustomRead(),
+ column.getCustomWrite(),
+ column.isQuoted()
+ );
+ }
+
+ @SuppressWarnings({"unchecked"})
+ private static void changeNamesInColumnElement(Element element, ColumnNameIterator columnNameIterator) {
+ final Iterator properties = element.elementIterator();
+ while ( properties.hasNext() ) {
+ final Element property = properties.next();
+
+ if ( "column".equals( property.getName() ) ) {
+ final Attribute nameAttr = property.attribute( "name" );
+ if ( nameAttr != null ) {
+ nameAttr.setText( columnNameIterator.next() );
+ }
+ }
+ }
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public static void prefixNamesInPropertyElement(
+ Element element,
+ String prefix,
+ ColumnNameIterator columnNameIterator,
+ boolean changeToKey,
+ boolean insertable) {
+ final Iterator properties = element.elementIterator();
+ while ( properties.hasNext() ) {
+ final Element property = properties.next();
+
+ if ( "property".equals( property.getName() ) || "many-to-one".equals( property.getName() ) ) {
+ final Attribute nameAttr = property.attribute( "name" );
+ if ( nameAttr != null ) {
+ nameAttr.setText( prefix + nameAttr.getText() );
+ }
+
+ changeNamesInColumnElement( property, columnNameIterator );
+
+ if ( changeToKey ) {
+ property.setName( "key-" + property.getName() );
+ }
+
+ if ( "property".equals( property.getName() ) ) {
+ final Attribute insert = property.attribute( "insert" );
+ insert.setText( Boolean.toString( insertable ) );
+ }
+ }
+ }
+ }
+
+ /**
+ * Adds formula
element.
+ *
+ * @param element Parent element.
+ * @param formula Formula descriptor.
+ */
+ public static void addFormula(Element element, Formula formula) {
+ element.addElement( "formula" ).setText( formula.getText() );
+ }
+
+ /**
+ * Adds all column
or formula
elements.
+ *
+ * @param element Parent element.
+ * @param columnIterator Iterator pointing at {@link org.hibernate.mapping.Column} and/or
+ * {@link org.hibernate.mapping.Formula} objects.
+ */
+ public static void addColumnsOrFormulas(Element element, Iterator columnIterator) {
+ while ( columnIterator.hasNext() ) {
+ final Object o = columnIterator.next();
+ if ( o instanceof Column ) {
+ addColumn( element, (Column) o );
+ }
+ else if ( o instanceof Formula ) {
+ addFormula( element, (Formula) o );
+ }
+ }
+ }
+
+ /**
+ * An iterator over column names.
+ */
+ public static abstract class ColumnNameIterator implements Iterator {
+ }
+
+ public static ColumnNameIterator getColumnNameIterator(final Iterator selectableIterator) {
+ return new ColumnNameIterator() {
+ public boolean hasNext() {
return selectableIterator.hasNext();
}
- public String next() {
+ public String next() {
final Selectable next = selectableIterator.next();
if ( next.isFormula() ) {
throw new FormulaNotSupportedException();
}
- return ( (Column) next ).getName();
+ return ((Column) next).getName();
}
- public void remove() {
+ public void remove() {
selectableIterator.remove();
}
- };
- }
+ };
+ }
- public static ColumnNameIterator getColumnNameIterator(final JoinColumn[] joinColumns) {
- return new ColumnNameIterator() {
- int counter = 0;
- public boolean hasNext() { return counter < joinColumns.length; }
- public String next() { return joinColumns[counter++].name(); }
- public void remove() { throw new UnsupportedOperationException(); }
- };
- }
+ public static ColumnNameIterator getColumnNameIterator(final JoinColumn[] joinColumns) {
+ return new ColumnNameIterator() {
+ int counter = 0;
+
+ public boolean hasNext() {
+ return counter < joinColumns.length;
+ }
+
+ public String next() {
+ return joinColumns[counter++].name();
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+ };
+ }
}
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 4312097d19..c7912f74c5 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
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2008, 2013, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -22,6 +22,7 @@
* Boston, MA 02110-1301 USA
*/
package org.hibernate.envers.configuration.internal.metadata;
+
import java.util.ArrayList;
import java.util.List;
@@ -40,64 +41,83 @@ import org.hibernate.envers.strategy.AuditStrategy;
/**
* Builds query generators, for reading collection middle tables, along with any related entities.
* The related entities information can be added gradually, and when complete, the query generator can be built.
+ *
* @author Adam Warski (adam at warski dot org)
*/
public final class QueryGeneratorBuilder {
- private final GlobalConfiguration globalCfg;
- private final AuditEntitiesConfiguration verEntCfg;
- private final AuditStrategy auditStrategy;
- private final MiddleIdData referencingIdData;
- private final String auditMiddleEntityName;
- private final List idDatas;
+ private final GlobalConfiguration globalCfg;
+ private final AuditEntitiesConfiguration verEntCfg;
+ private final AuditStrategy auditStrategy;
+ private final MiddleIdData referencingIdData;
+ private final String auditMiddleEntityName;
+ private final List idDatas;
private final boolean revisionTypeInId;
- QueryGeneratorBuilder(GlobalConfiguration globalCfg, AuditEntitiesConfiguration verEntCfg,
- AuditStrategy auditStrategy, MiddleIdData referencingIdData, String auditMiddleEntityName,
- boolean revisionTypeInId) {
- this.globalCfg = globalCfg;
- this.verEntCfg = verEntCfg;
- this.auditStrategy = auditStrategy;
- this.referencingIdData = referencingIdData;
- this.auditMiddleEntityName = auditMiddleEntityName;
+ QueryGeneratorBuilder(
+ GlobalConfiguration globalCfg,
+ AuditEntitiesConfiguration verEntCfg,
+ AuditStrategy auditStrategy,
+ MiddleIdData referencingIdData,
+ String auditMiddleEntityName,
+ boolean revisionTypeInId) {
+ this.globalCfg = globalCfg;
+ this.verEntCfg = verEntCfg;
+ this.auditStrategy = auditStrategy;
+ this.referencingIdData = referencingIdData;
+ this.auditMiddleEntityName = auditMiddleEntityName;
this.revisionTypeInId = revisionTypeInId;
- idDatas = new ArrayList();
- }
+ idDatas = new ArrayList();
+ }
- void addRelation(MiddleIdData idData) {
- idDatas.add(idData);
- }
+ void addRelation(MiddleIdData idData) {
+ idDatas.add( idData );
+ }
- RelationQueryGenerator build(MiddleComponentData... componentDatas) {
- if (idDatas.size() == 0) {
- return new OneEntityQueryGenerator(verEntCfg, auditStrategy, auditMiddleEntityName, referencingIdData,
- revisionTypeInId, componentDatas);
- } else if (idDatas.size() == 1) {
- if (idDatas.get(0).isAudited()) {
- return new TwoEntityQueryGenerator(globalCfg, verEntCfg, auditStrategy, auditMiddleEntityName, referencingIdData,
- idDatas.get(0), revisionTypeInId, componentDatas);
- } else {
- return new TwoEntityOneAuditedQueryGenerator(verEntCfg, auditStrategy, auditMiddleEntityName, referencingIdData,
- idDatas.get(0), revisionTypeInId, componentDatas);
- }
- } else if (idDatas.size() == 2) {
- // All entities must be audited.
- if (!idDatas.get(0).isAudited() || !idDatas.get(1).isAudited()) {
- throw new MappingException("Ternary relations using @Audited(targetAuditMode = NOT_AUDITED) are not supported.");
- }
+ RelationQueryGenerator build(MiddleComponentData... componentDatas) {
+ if ( idDatas.size() == 0 ) {
+ return new OneEntityQueryGenerator(
+ verEntCfg, auditStrategy, auditMiddleEntityName, referencingIdData,
+ revisionTypeInId, componentDatas
+ );
+ }
+ else if ( idDatas.size() == 1 ) {
+ if ( idDatas.get( 0 ).isAudited() ) {
+ return new TwoEntityQueryGenerator(
+ globalCfg, verEntCfg, auditStrategy, auditMiddleEntityName, referencingIdData,
+ idDatas.get( 0 ), revisionTypeInId, componentDatas
+ );
+ }
+ else {
+ return new TwoEntityOneAuditedQueryGenerator(
+ verEntCfg, auditStrategy, auditMiddleEntityName, referencingIdData,
+ idDatas.get( 0 ), revisionTypeInId, componentDatas
+ );
+ }
+ }
+ else if ( idDatas.size() == 2 ) {
+ // All entities must be audited.
+ if ( !idDatas.get( 0 ).isAudited() || !idDatas.get( 1 ).isAudited() ) {
+ throw new MappingException(
+ "Ternary relations using @Audited(targetAuditMode = NOT_AUDITED) are not supported."
+ );
+ }
- return new ThreeEntityQueryGenerator(globalCfg, verEntCfg, auditStrategy, auditMiddleEntityName, referencingIdData,
- idDatas.get(0), idDatas.get(1), revisionTypeInId, componentDatas);
- } else {
- throw new IllegalStateException("Illegal number of related entities.");
- }
- }
+ return new ThreeEntityQueryGenerator(
+ globalCfg, verEntCfg, auditStrategy, auditMiddleEntityName, referencingIdData,
+ idDatas.get( 0 ), idDatas.get( 1 ), revisionTypeInId, componentDatas
+ );
+ }
+ else {
+ throw new IllegalStateException( "Illegal number of related entities." );
+ }
+ }
- /**
- * @return Current index of data in the array, which will be the element of a list, returned when executing a query
- * generated by the built query generator.
- */
- int getCurrentIndex() {
- return idDatas.size();
- }
+ /**
+ * @return Current index of data in the array, which will be the element of a list, returned when executing a query
+ * generated by the built query generator.
+ */
+ int getCurrentIndex() {
+ return idDatas.size();
+ }
}
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/ToOneRelationMetadataGenerator.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/ToOneRelationMetadataGenerator.java
index 2e644d8e11..b18179dc39 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/ToOneRelationMetadataGenerator.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/ToOneRelationMetadataGenerator.java
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2008, 2013, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -22,6 +22,7 @@
* Boston, MA 02110-1301 USA
*/
package org.hibernate.envers.configuration.internal.metadata;
+
import org.dom4j.Element;
import org.hibernate.MappingException;
@@ -41,121 +42,166 @@ import org.hibernate.mapping.Value;
/**
* Generates metadata for to-one relations (reference-valued properties).
+ *
* @author Adam Warski (adam at warski dot org)
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
*/
public final class ToOneRelationMetadataGenerator {
- private final AuditMetadataGenerator mainGenerator;
+ private final AuditMetadataGenerator mainGenerator;
- ToOneRelationMetadataGenerator(AuditMetadataGenerator auditMetadataGenerator) {
- mainGenerator = auditMetadataGenerator;
- }
+ ToOneRelationMetadataGenerator(AuditMetadataGenerator auditMetadataGenerator) {
+ mainGenerator = auditMetadataGenerator;
+ }
- @SuppressWarnings({"unchecked"})
- void addToOne(Element parent, PropertyAuditingData propertyAuditingData, Value value,
- CompositeMapperBuilder mapper, String entityName, boolean insertable) {
- String referencedEntityName = ((ToOne) value).getReferencedEntityName();
+ @SuppressWarnings({"unchecked"})
+ void addToOne(
+ Element parent,
+ PropertyAuditingData propertyAuditingData,
+ Value value,
+ CompositeMapperBuilder mapper,
+ String entityName,
+ boolean insertable) {
+ final String referencedEntityName = ((ToOne) value).getReferencedEntityName();
- IdMappingData idMapping = mainGenerator.getReferencedIdMappingData(entityName, referencedEntityName,
- propertyAuditingData, true);
+ final IdMappingData idMapping = mainGenerator.getReferencedIdMappingData(
+ entityName,
+ referencedEntityName,
+ propertyAuditingData,
+ true
+ );
- String lastPropertyPrefix = MappingTools.createToOneRelationPrefix(propertyAuditingData.getName());
+ final String lastPropertyPrefix = MappingTools.createToOneRelationPrefix( propertyAuditingData.getName() );
- // Generating the id mapper for the relation
- IdMapper relMapper = idMapping.getIdMapper().prefixMappedProperties(lastPropertyPrefix);
+ // Generating the id mapper for the relation
+ final IdMapper relMapper = idMapping.getIdMapper().prefixMappedProperties( lastPropertyPrefix );
- // Storing information about this relation
- mainGenerator.getEntitiesConfigurations().get(entityName).addToOneRelation(
- propertyAuditingData.getName(), referencedEntityName, relMapper, insertable);
+ // Storing information about this relation
+ mainGenerator.getEntitiesConfigurations().get( entityName ).addToOneRelation(
+ propertyAuditingData.getName(),
+ referencedEntityName,
+ relMapper,
+ insertable
+ );
- // If the property isn't insertable, checking if this is not a "fake" bidirectional many-to-one relationship,
- // that is, when the one side owns the relation (and is a collection), and the many side is non insertable.
- // When that's the case and the user specified to store this relation without a middle table (using
- // @AuditMappedBy), we have to make the property insertable for the purposes of Envers. In case of changes to
- // the entity that didn't involve the relation, it's value will then be stored properly. In case of changes
- // to the entity that did involve the relation, it's the responsibility of the collection side to store the
- // proper data.
- boolean nonInsertableFake;
- if (!insertable && propertyAuditingData.isForceInsertable()) {
- nonInsertableFake = true;
- insertable = true;
- } else {
- nonInsertableFake = false;
- }
+ // If the property isn't insertable, checking if this is not a "fake" bidirectional many-to-one relationship,
+ // that is, when the one side owns the relation (and is a collection), and the many side is non insertable.
+ // When that's the case and the user specified to store this relation without a middle table (using
+ // @AuditMappedBy), we have to make the property insertable for the purposes of Envers. In case of changes to
+ // the entity that didn't involve the relation, it's value will then be stored properly. In case of changes
+ // to the entity that did involve the relation, it's the responsibility of the collection side to store the
+ // proper data.
+ boolean nonInsertableFake;
+ if ( !insertable && propertyAuditingData.isForceInsertable() ) {
+ nonInsertableFake = true;
+ insertable = true;
+ }
+ else {
+ nonInsertableFake = false;
+ }
- // Adding an element to the mapping corresponding to the references entity id's
- Element properties = (Element) idMapping.getXmlRelationMapping().clone();
- properties.addAttribute("name", propertyAuditingData.getName());
+ // Adding an element to the mapping corresponding to the references entity id's
+ final Element properties = (Element) idMapping.getXmlRelationMapping().clone();
+ properties.addAttribute( "name", propertyAuditingData.getName() );
- MetadataTools.prefixNamesInPropertyElement(properties, lastPropertyPrefix,
- MetadataTools.getColumnNameIterator(value.getColumnIterator()), false, insertable);
+ MetadataTools.prefixNamesInPropertyElement(
+ properties,
+ lastPropertyPrefix,
+ MetadataTools.getColumnNameIterator( value.getColumnIterator() ),
+ false,
+ insertable
+ );
// Extracting related id properties from properties tag
- for (Object o : properties.content()) {
- Element element = (Element) o;
- element.setParent(null);
- parent.add(element);
+ for ( Object o : properties.content() ) {
+ final Element element = (Element) o;
+ element.setParent( null );
+ parent.add( element );
}
// Adding mapper for the id
- PropertyData propertyData = propertyAuditingData.getPropertyData();
- mapper.addComposite(propertyData, new ToOneIdMapper(relMapper, propertyData, referencedEntityName, nonInsertableFake));
- }
+ final PropertyData propertyData = propertyAuditingData.getPropertyData();
+ mapper.addComposite(
+ propertyData,
+ new ToOneIdMapper( relMapper, propertyData, referencedEntityName, nonInsertableFake )
+ );
+ }
- @SuppressWarnings({"unchecked"})
- void addOneToOneNotOwning(PropertyAuditingData propertyAuditingData, Value value,
- CompositeMapperBuilder mapper, String entityName) {
- OneToOne propertyValue = (OneToOne) value;
+ @SuppressWarnings({"unchecked"})
+ void addOneToOneNotOwning(
+ PropertyAuditingData propertyAuditingData,
+ Value value,
+ CompositeMapperBuilder mapper,
+ String entityName) {
+ final OneToOne propertyValue = (OneToOne) value;
+ final String owningReferencePropertyName = propertyValue.getReferencedPropertyName();
- String owningReferencePropertyName = propertyValue.getReferencedPropertyName(); // mappedBy
+ final EntityConfiguration configuration = mainGenerator.getEntitiesConfigurations().get( entityName );
+ if ( configuration == null ) {
+ throw new MappingException( "An audited relation to a non-audited entity " + entityName + "!" );
+ }
- EntityConfiguration configuration = mainGenerator.getEntitiesConfigurations().get(entityName);
- if (configuration == null) {
- throw new MappingException("An audited relation to a non-audited entity " + entityName + "!");
- }
+ final IdMappingData ownedIdMapping = configuration.getIdMappingData();
- IdMappingData ownedIdMapping = configuration.getIdMappingData();
+ if ( ownedIdMapping == null ) {
+ throw new MappingException( "An audited relation to a non-audited entity " + entityName + "!" );
+ }
- if (ownedIdMapping == null) {
- throw new MappingException("An audited relation to a non-audited entity " + entityName + "!");
- }
+ final String lastPropertyPrefix = MappingTools.createToOneRelationPrefix( owningReferencePropertyName );
+ final String referencedEntityName = propertyValue.getReferencedEntityName();
- String lastPropertyPrefix = MappingTools.createToOneRelationPrefix(owningReferencePropertyName);
- String referencedEntityName = propertyValue.getReferencedEntityName();
+ // Generating the id mapper for the relation
+ final IdMapper ownedIdMapper = ownedIdMapping.getIdMapper().prefixMappedProperties( lastPropertyPrefix );
- // Generating the id mapper for the relation
- IdMapper ownedIdMapper = ownedIdMapping.getIdMapper().prefixMappedProperties(lastPropertyPrefix);
+ // Storing information about this relation
+ mainGenerator.getEntitiesConfigurations().get( entityName ).addToOneNotOwningRelation(
+ propertyAuditingData.getName(),
+ owningReferencePropertyName,
+ referencedEntityName,
+ ownedIdMapper
+ );
- // Storing information about this relation
- mainGenerator.getEntitiesConfigurations().get(entityName).addToOneNotOwningRelation(
- propertyAuditingData.getName(), owningReferencePropertyName,
- referencedEntityName, ownedIdMapper);
+ // Adding mapper for the id
+ final PropertyData propertyData = propertyAuditingData.getPropertyData();
+ mapper.addComposite(
+ propertyData,
+ new OneToOneNotOwningMapper( entityName, referencedEntityName, owningReferencePropertyName, propertyData )
+ );
+ }
- // Adding mapper for the id
- PropertyData propertyData = propertyAuditingData.getPropertyData();
- mapper.addComposite(propertyData, new OneToOneNotOwningMapper(entityName, referencedEntityName,
- owningReferencePropertyName, propertyData));
- }
+ @SuppressWarnings({"unchecked"})
+ void addOneToOnePrimaryKeyJoinColumn(
+ PropertyAuditingData propertyAuditingData,
+ Value value,
+ CompositeMapperBuilder mapper,
+ String entityName,
+ boolean insertable) {
+ final String referencedEntityName = ((ToOne) value).getReferencedEntityName();
- @SuppressWarnings({"unchecked"})
- void addOneToOnePrimaryKeyJoinColumn(PropertyAuditingData propertyAuditingData, Value value,
- CompositeMapperBuilder mapper, String entityName, boolean insertable) {
- String referencedEntityName = ((ToOne) value).getReferencedEntityName();
+ final IdMappingData idMapping = mainGenerator.getReferencedIdMappingData(
+ entityName,
+ referencedEntityName,
+ propertyAuditingData,
+ true
+ );
- IdMappingData idMapping = mainGenerator.getReferencedIdMappingData(entityName, referencedEntityName,
- propertyAuditingData, true);
+ final String lastPropertyPrefix = MappingTools.createToOneRelationPrefix( propertyAuditingData.getName() );
- String lastPropertyPrefix = MappingTools.createToOneRelationPrefix(propertyAuditingData.getName());
+ // Generating the id mapper for the relation
+ final IdMapper relMapper = idMapping.getIdMapper().prefixMappedProperties( lastPropertyPrefix );
- // Generating the id mapper for the relation
- IdMapper relMapper = idMapping.getIdMapper().prefixMappedProperties(lastPropertyPrefix);
+ // Storing information about this relation
+ mainGenerator.getEntitiesConfigurations().get( entityName ).addToOneRelation(
+ propertyAuditingData.getName(),
+ referencedEntityName,
+ relMapper,
+ insertable
+ );
- // Storing information about this relation
- mainGenerator.getEntitiesConfigurations().get(entityName).addToOneRelation(propertyAuditingData.getName(),
- referencedEntityName, relMapper, insertable);
-
- // Adding mapper for the id
- PropertyData propertyData = propertyAuditingData.getPropertyData();
- mapper.addComposite(propertyData, new OneToOnePrimaryKeyJoinColumnMapper(entityName, referencedEntityName, propertyData));
- }
+ // Adding mapper for the id
+ final PropertyData propertyData = propertyAuditingData.getPropertyData();
+ mapper.addComposite(
+ propertyData,
+ new OneToOnePrimaryKeyJoinColumnMapper( entityName, referencedEntityName, propertyData )
+ );
+ }
}
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/AnnotationsMetadataReader.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/AnnotationsMetadataReader.java
index 0a3b5d512e..88f21f9f44 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/AnnotationsMetadataReader.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/AnnotationsMetadataReader.java
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2008, 2013, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -22,6 +22,7 @@
* Boston, MA 02110-1301 USA
*/
package org.hibernate.envers.configuration.internal.metadata.reader;
+
import java.lang.annotation.Annotation;
import java.util.Iterator;
@@ -39,6 +40,7 @@ import org.hibernate.mapping.Property;
/**
* A helper class to read versioning meta-data from annotations on a persistent class.
+ *
* @author Adam Warski (adam at warski dot org)
* @author Sebastian Komander
*/
@@ -53,8 +55,9 @@ public final class AnnotationsMetadataReader {
*/
private final ClassAuditingData auditData;
- public AnnotationsMetadataReader(GlobalConfiguration globalCfg, ReflectionManager reflectionManager,
- PersistentClass pc) {
+ public AnnotationsMetadataReader(
+ GlobalConfiguration globalCfg, ReflectionManager reflectionManager,
+ PersistentClass pc) {
this.globalCfg = globalCfg;
this.reflectionManager = reflectionManager;
this.pc = pc;
@@ -63,71 +66,95 @@ public final class AnnotationsMetadataReader {
}
private ModificationStore getDefaultAudited(XClass clazz) {
- Audited defaultAudited = clazz.getAnnotation(Audited.class);
+ final Audited defaultAudited = clazz.getAnnotation( Audited.class );
- if (defaultAudited != null) {
+ if ( defaultAudited != null ) {
return defaultAudited.modStore();
- } else {
+ }
+ else {
return null;
}
}
private void addAuditTable(XClass clazz) {
- AuditTable auditTable = clazz.getAnnotation(AuditTable.class);
- if (auditTable != null) {
- auditData.setAuditTable(auditTable);
- } else {
- auditData.setAuditTable(getDefaultAuditTable());
+ final AuditTable auditTable = clazz.getAnnotation( AuditTable.class );
+ if ( auditTable != null ) {
+ auditData.setAuditTable( auditTable );
+ }
+ else {
+ auditData.setAuditTable( getDefaultAuditTable() );
}
}
private void addAuditSecondaryTables(XClass clazz) {
// Getting information on secondary tables
- SecondaryAuditTable secondaryVersionsTable1 = clazz.getAnnotation(SecondaryAuditTable.class);
- if (secondaryVersionsTable1 != null) {
- auditData.getSecondaryTableDictionary().put(secondaryVersionsTable1.secondaryTableName(),
- secondaryVersionsTable1.secondaryAuditTableName());
+ final SecondaryAuditTable secondaryVersionsTable1 = clazz.getAnnotation( SecondaryAuditTable.class );
+ if ( secondaryVersionsTable1 != null ) {
+ auditData.getSecondaryTableDictionary().put(
+ secondaryVersionsTable1.secondaryTableName(),
+ secondaryVersionsTable1.secondaryAuditTableName()
+ );
}
- SecondaryAuditTables secondaryAuditTables = clazz.getAnnotation(SecondaryAuditTables.class);
- if (secondaryAuditTables != null) {
- for (SecondaryAuditTable secondaryAuditTable2 : secondaryAuditTables.value()) {
- auditData.getSecondaryTableDictionary().put(secondaryAuditTable2.secondaryTableName(),
- secondaryAuditTable2.secondaryAuditTableName());
+ final SecondaryAuditTables secondaryAuditTables = clazz.getAnnotation( SecondaryAuditTables.class );
+ if ( secondaryAuditTables != null ) {
+ for ( SecondaryAuditTable secondaryAuditTable2 : secondaryAuditTables.value() ) {
+ auditData.getSecondaryTableDictionary().put(
+ secondaryAuditTable2.secondaryTableName(),
+ secondaryAuditTable2.secondaryAuditTableName()
+ );
}
}
}
public ClassAuditingData getAuditData() {
- if (pc.getClassName() == null) {
+ if ( pc.getClassName() == null ) {
return auditData;
}
try {
- XClass xclass = reflectionManager.classForName(pc.getClassName(), this.getClass());
+ final XClass xclass = reflectionManager.classForName( pc.getClassName(), this.getClass() );
- ModificationStore defaultStore = getDefaultAudited(xclass);
- if (defaultStore != null) {
- auditData.setDefaultAudited(true);
+ final ModificationStore defaultStore = getDefaultAudited( xclass );
+ if ( defaultStore != null ) {
+ auditData.setDefaultAudited( true );
}
- new AuditedPropertiesReader(defaultStore, new PersistentClassPropertiesSource(xclass), auditData,
- globalCfg, reflectionManager, "").read();
+ new AuditedPropertiesReader(
+ defaultStore,
+ new PersistentClassPropertiesSource( xclass ),
+ auditData,
+ globalCfg,
+ reflectionManager,
+ ""
+ ).read();
- addAuditTable(xclass);
- addAuditSecondaryTables(xclass);
- } catch (ClassNotFoundException e) {
- throw new MappingException(e);
+ addAuditTable( xclass );
+ addAuditSecondaryTables( xclass );
+ }
+ catch (ClassNotFoundException e) {
+ throw new MappingException( e );
}
return auditData;
}
private AuditTable defaultAuditTable = new AuditTable() {
- public String value() { return ""; }
- public String schema() { return ""; }
- public String catalog() { return ""; }
- public Class extends Annotation> annotationType() { return this.getClass(); }
+ public String value() {
+ return "";
+ }
+
+ public String schema() {
+ return "";
+ }
+
+ public String catalog() {
+ return "";
+ }
+
+ public Class extends Annotation> annotationType() {
+ return this.getClass();
+ }
};
private AuditTable getDefaultAuditTable() {
@@ -137,11 +164,21 @@ public final class AnnotationsMetadataReader {
private class PersistentClassPropertiesSource implements PersistentPropertiesSource {
private final XClass xclass;
- private PersistentClassPropertiesSource(XClass xclass) { this.xclass = xclass; }
+ private PersistentClassPropertiesSource(XClass xclass) {
+ this.xclass = xclass;
+ }
@SuppressWarnings({"unchecked"})
- public Iterator getPropertyIterator() { return pc.getPropertyIterator(); }
- public Property getProperty(String propertyName) { return pc.getProperty(propertyName); }
- public XClass getXClass() { return xclass; }
+ public Iterator getPropertyIterator() {
+ return pc.getPropertyIterator();
+ }
+
+ public Property getProperty(String propertyName) {
+ return pc.getProperty( propertyName );
+ }
+
+ public XClass getXClass() {
+ return xclass;
+ }
}
}
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/AuditedPropertiesHolder.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/AuditedPropertiesHolder.java
index 5cd511c74b..73e488013a 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/AuditedPropertiesHolder.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/AuditedPropertiesHolder.java
@@ -1,14 +1,39 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2013, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
package org.hibernate.envers.configuration.internal.metadata.reader;
/**
* Implementations hold other audited properties.
+ *
* @author Adam Warski (adam at warski dot org)
* @author Hern&aacut;n Chanfreau
*/
public interface AuditedPropertiesHolder {
/**
* Add an audited property.
+ *
* @param propertyName Name of the audited property.
* @param auditingData Data for the audited property.
*/
@@ -16,19 +41,20 @@ public interface AuditedPropertiesHolder {
/**
* @param propertyName Name of a property.
+ *
* @return Auditing data for the property.
*/
PropertyAuditingData getPropertyAuditingData(String propertyName);
-
-
+
+
/**
* @return true if the holder contains any audited property
*/
boolean isEmpty();
-
+
/**
* @return true if the holder contains the given audited property
*/
boolean contains(String propertyName);
-
+
}
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/AuditedPropertiesReader.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/AuditedPropertiesReader.java
index feab0942e4..a76050504a 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/AuditedPropertiesReader.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/AuditedPropertiesReader.java
@@ -1,5 +1,32 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2013, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
package org.hibernate.envers.configuration.internal.metadata.reader;
+import javax.persistence.JoinColumn;
+import javax.persistence.MapKey;
+import javax.persistence.OneToMany;
+import javax.persistence.Version;
import java.lang.annotation.Annotation;
import java.util.Arrays;
import java.util.Collections;
@@ -7,10 +34,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import javax.persistence.JoinColumn;
-import javax.persistence.MapKey;
-import javax.persistence.OneToMany;
-import javax.persistence.Version;
import org.hibernate.MappingException;
import org.hibernate.annotations.common.reflection.ReflectionManager;
@@ -65,12 +88,13 @@ public class AuditedPropertiesReader {
private final Set overriddenAuditedClasses;
private final Set overriddenNotAuditedClasses;
- public AuditedPropertiesReader(ModificationStore defaultStore,
- PersistentPropertiesSource persistentPropertiesSource,
- AuditedPropertiesHolder auditedPropertiesHolder,
- GlobalConfiguration globalCfg,
- ReflectionManager reflectionManager,
- String propertyNamePrefix) {
+ public AuditedPropertiesReader(
+ ModificationStore defaultStore,
+ PersistentPropertiesSource persistentPropertiesSource,
+ AuditedPropertiesHolder auditedPropertiesHolder,
+ GlobalConfiguration globalCfg,
+ ReflectionManager reflectionManager,
+ String propertyNamePrefix) {
this.defaultStore = defaultStore;
this.persistentPropertiesSource = persistentPropertiesSource;
this.auditedPropertiesHolder = auditedPropertiesHolder;
@@ -93,245 +117,300 @@ public class AuditedPropertiesReader {
// First reading the access types for the persistent properties.
readPersistentPropertiesAccess();
- // Retrieve classes and properties that are explicitly marked for auditing process by any superclass
- // of currently mapped entity or itself.
- XClass clazz = persistentPropertiesSource.getXClass();
- readAuditOverrides(clazz);
+ // Retrieve classes and properties that are explicitly marked for auditing process by any superclass
+ // of currently mapped entity or itself.
+ final XClass clazz = persistentPropertiesSource.getXClass();
+ readAuditOverrides( clazz );
- // Adding all properties from the given class.
- addPropertiesFromClass(clazz);
+ // Adding all properties from the given class.
+ addPropertiesFromClass( clazz );
}
- /**
- * Recursively constructs sets of audited and not audited properties and classes which behavior has been overridden
- * using {@link AuditOverride} annotation.
- * @param clazz Class that is being processed. Currently mapped entity shall be passed during first invocation.
- */
- private void readAuditOverrides(XClass clazz) {
- /* TODO: Code to remove with @Audited.auditParents - start. */
- Audited allClassAudited = clazz.getAnnotation(Audited.class);
- if (allClassAudited != null && allClassAudited.auditParents().length > 0) {
- for (Class c : allClassAudited.auditParents()) {
- XClass parentClass = reflectionManager.toXClass(c);
- checkSuperclass(clazz, parentClass);
- if (!overriddenNotAuditedClasses.contains(parentClass)) {
- // If the class has not been marked as not audited by the subclass.
- overriddenAuditedClasses.add(parentClass);
- }
- }
- }
+ /**
+ * Recursively constructs sets of audited and not audited properties and classes which behavior has been overridden
+ * using {@link AuditOverride} annotation.
+ *
+ * @param clazz Class that is being processed. Currently mapped entity shall be passed during first invocation.
+ */
+ private void readAuditOverrides(XClass clazz) {
+ /* TODO: Code to remove with @Audited.auditParents - start. */
+ final Audited allClassAudited = clazz.getAnnotation( Audited.class );
+ if ( allClassAudited != null && allClassAudited.auditParents().length > 0 ) {
+ for ( Class c : allClassAudited.auditParents() ) {
+ final XClass parentClass = reflectionManager.toXClass( c );
+ checkSuperclass( clazz, parentClass );
+ if ( !overriddenNotAuditedClasses.contains( parentClass ) ) {
+ // If the class has not been marked as not audited by the subclass.
+ overriddenAuditedClasses.add( parentClass );
+ }
+ }
+ }
/* TODO: Code to remove with @Audited.auditParents - finish. */
- List auditOverrides = computeAuditOverrides(clazz);
- for (AuditOverride auditOverride : auditOverrides) {
- if (auditOverride.forClass() != void.class) {
- XClass overrideClass = reflectionManager.toXClass(auditOverride.forClass());
- checkSuperclass(clazz, overrideClass);
- String propertyName = auditOverride.name();
- if (!StringTools.isEmpty(propertyName)) {
- // Override @Audited annotation on property level.
- XProperty property = getProperty(overrideClass, propertyName);
- if (auditOverride.isAudited()) {
- if (!overriddenNotAuditedProperties.contains(property)) {
- // If the property has not been marked as not audited by the subclass.
- overriddenAuditedProperties.add(property);
- }
- } else {
- if (!overriddenAuditedProperties.contains(property)) {
- // If the property has not been marked as audited by the subclass.
- overriddenNotAuditedProperties.add(property);
- }
- }
- } else {
- // Override @Audited annotation on class level.
- if (auditOverride.isAudited()) {
- if (!overriddenNotAuditedClasses.contains(overrideClass)) {
- // If the class has not been marked as not audited by the subclass.
- overriddenAuditedClasses.add(overrideClass);
- }
- } else {
- if (!overriddenAuditedClasses.contains(overrideClass)) {
- // If the class has not been marked as audited by the subclass.
- overriddenNotAuditedClasses.add(overrideClass);
- }
- }
- }
- }
- }
- XClass superclass = clazz.getSuperclass();
- if (!clazz.isInterface() && !Object.class.getName().equals(superclass.getName())) {
- readAuditOverrides(superclass);
- }
- }
+ final List auditOverrides = computeAuditOverrides( clazz );
+ for ( AuditOverride auditOverride : auditOverrides ) {
+ if ( auditOverride.forClass() != void.class ) {
+ final XClass overrideClass = reflectionManager.toXClass( auditOverride.forClass() );
+ checkSuperclass( clazz, overrideClass );
+ final String propertyName = auditOverride.name();
+ if ( !StringTools.isEmpty( propertyName ) ) {
+ // Override @Audited annotation on property level.
+ final XProperty property = getProperty( overrideClass, propertyName );
+ if ( auditOverride.isAudited() ) {
+ if ( !overriddenNotAuditedProperties.contains( property ) ) {
+ // If the property has not been marked as not audited by the subclass.
+ overriddenAuditedProperties.add( property );
+ }
+ }
+ else {
+ if ( !overriddenAuditedProperties.contains( property ) ) {
+ // If the property has not been marked as audited by the subclass.
+ overriddenNotAuditedProperties.add( property );
+ }
+ }
+ }
+ else {
+ // Override @Audited annotation on class level.
+ if ( auditOverride.isAudited() ) {
+ if ( !overriddenNotAuditedClasses.contains( overrideClass ) ) {
+ // If the class has not been marked as not audited by the subclass.
+ overriddenAuditedClasses.add( overrideClass );
+ }
+ }
+ else {
+ if ( !overriddenAuditedClasses.contains( overrideClass ) ) {
+ // If the class has not been marked as audited by the subclass.
+ overriddenNotAuditedClasses.add( overrideClass );
+ }
+ }
+ }
+ }
+ }
+ final XClass superclass = clazz.getSuperclass();
+ if ( !clazz.isInterface() && !Object.class.getName().equals( superclass.getName() ) ) {
+ readAuditOverrides( superclass );
+ }
+ }
- /**
- * @param clazz Source class.
- * @return List of @AuditOverride annotations applied at class level.
- */
- private List computeAuditOverrides(XClass clazz) {
- AuditOverrides auditOverrides = clazz.getAnnotation(AuditOverrides.class);
- AuditOverride auditOverride = clazz.getAnnotation(AuditOverride.class);
- if (auditOverrides == null && auditOverride != null) {
- return Arrays.asList(auditOverride);
- } else if (auditOverrides != null && auditOverride == null) {
- return Arrays.asList(auditOverrides.value());
- } else if (auditOverrides != null && auditOverride != null) {
- throw new MappingException("@AuditOverrides annotation should encapsulate all @AuditOverride declarations. " +
- "Please revise Envers annotations applied to class " + clazz.getName() + ".");
- }
- return Collections.EMPTY_LIST;
- }
+ /**
+ * @param clazz Source class.
+ *
+ * @return List of @AuditOverride annotations applied at class level.
+ */
+ private List computeAuditOverrides(XClass clazz) {
+ final AuditOverrides auditOverrides = clazz.getAnnotation( AuditOverrides.class );
+ final AuditOverride auditOverride = clazz.getAnnotation( AuditOverride.class );
+ if ( auditOverrides == null && auditOverride != null ) {
+ return Arrays.asList( auditOverride );
+ }
+ else if ( auditOverrides != null && auditOverride == null ) {
+ return Arrays.asList( auditOverrides.value() );
+ }
+ else if ( auditOverrides != null && auditOverride != null ) {
+ throw new MappingException(
+ "@AuditOverrides annotation should encapsulate all @AuditOverride declarations. " +
+ "Please revise Envers annotations applied to class " + clazz.getName() + "."
+ );
+ }
+ return Collections.emptyList();
+ }
- /**
- * Checks whether one class is assignable from another. If not {@link MappingException} is thrown.
- * @param child Subclass.
- * @param parent Superclass.
- */
- private void checkSuperclass(XClass child, XClass parent) {
- if (!parent.isAssignableFrom(child)) {
- throw new MappingException("Class " + parent.getName() + " is not assignable from " + child.getName() + ". " +
- "Please revise Envers annotations applied to " + child.getName() + " type.");
- }
- }
+ /**
+ * Checks whether one class is assignable from another. If not {@link MappingException} is thrown.
+ *
+ * @param child Subclass.
+ * @param parent Superclass.
+ */
+ private void checkSuperclass(XClass child, XClass parent) {
+ if ( !parent.isAssignableFrom( child ) ) {
+ throw new MappingException(
+ "Class " + parent.getName() + " is not assignable from " + child.getName() + ". " +
+ "Please revise Envers annotations applied to " + child.getName() + " type."
+ );
+ }
+ }
- /**
- * Checks whether class contains property with a given name. If not {@link MappingException} is thrown.
- * @param clazz Class.
- * @param propertyName Property name.
- * @return Property object.
- */
- private XProperty getProperty(XClass clazz, String propertyName) {
- XProperty property = ReflectionTools.getProperty(clazz, propertyName);
- if (property == null) {
- throw new MappingException("Property '" + propertyName + "' not found in class " + clazz.getName() + ". " +
- "Please revise Envers annotations applied to class " + persistentPropertiesSource.getXClass() + ".");
- }
- return property;
- }
+ /**
+ * Checks whether class contains property with a given name. If not {@link MappingException} is thrown.
+ *
+ * @param clazz Class.
+ * @param propertyName Property name.
+ *
+ * @return Property object.
+ */
+ private XProperty getProperty(XClass clazz, String propertyName) {
+ final XProperty property = ReflectionTools.getProperty( clazz, propertyName );
+ if ( property == null ) {
+ throw new MappingException(
+ "Property '" + propertyName + "' not found in class " + clazz.getName() + ". " +
+ "Please revise Envers annotations applied to class " + persistentPropertiesSource.getXClass() + "."
+ );
+ }
+ return property;
+ }
private void readPersistentPropertiesAccess() {
- Iterator propertyIter = persistentPropertiesSource.getPropertyIterator();
- while (propertyIter.hasNext()) {
- Property property = propertyIter.next();
- addPersistentProperty(property);
- if ("embedded".equals(property.getPropertyAccessorName()) && property.getName().equals(property.getNodeName())) {
+ final Iterator propertyIter = persistentPropertiesSource.getPropertyIterator();
+ while ( propertyIter.hasNext() ) {
+ final Property property = propertyIter.next();
+ addPersistentProperty( property );
+ if ( "embedded".equals( property.getPropertyAccessorName() ) && property.getName()
+ .equals( property.getNodeName() ) ) {
// If property name equals node name and embedded accessor type is used, processing component
// has been defined with tag. See HHH-6636 JIRA issue.
- createPropertiesGroupMapping(property);
+ createPropertiesGroupMapping( property );
}
}
}
- private void addPersistentProperty(Property property) {
- if ("field".equals(property.getPropertyAccessorName())) {
- fieldAccessedPersistentProperties.add(property.getName());
- } else {
- propertyAccessedPersistentProperties.add(property.getName());
- }
- }
+ private void addPersistentProperty(Property property) {
+ if ( "field".equals( property.getPropertyAccessorName() ) ) {
+ fieldAccessedPersistentProperties.add( property.getName() );
+ }
+ else {
+ propertyAccessedPersistentProperties.add( property.getName() );
+ }
+ }
- private void createPropertiesGroupMapping(Property property) {
- Component component = (Component) property.getValue();
- Iterator componentProperties = component.getPropertyIterator();
- while (componentProperties.hasNext()) {
- Property componentProperty = componentProperties.next();
- propertiesGroupMapping.put(componentProperty.getName(), component.getNodeName());
- }
- }
+ @SuppressWarnings("unchecked")
+ private void createPropertiesGroupMapping(Property property) {
+ final Component component = (Component) property.getValue();
+ final Iterator componentProperties = component.getPropertyIterator();
+ while ( componentProperties.hasNext() ) {
+ final Property componentProperty = componentProperties.next();
+ propertiesGroupMapping.put( componentProperty.getName(), component.getNodeName() );
+ }
+ }
- /**
- * @param clazz Class which properties are currently being added.
- * @return {@link Audited} annotation of specified class. If processed type hasn't been explicitly marked, method
- * checks whether given class exists in {@link AuditedPropertiesReader#overriddenAuditedClasses} collection.
- * In case of success, {@link Audited} configuration of currently mapped entity is returned, otherwise
- * {@code null}. If processed type exists in {@link AuditedPropertiesReader#overriddenNotAuditedClasses}
- * collection, the result is also {@code null}.
- */
- private Audited computeAuditConfiguration(XClass clazz) {
- Audited allClassAudited = clazz.getAnnotation(Audited.class);
- // If processed class is not explicitly marked with @Audited annotation, check whether auditing is
- // forced by any of its child entities configuration (@AuditedOverride.forClass).
- if (allClassAudited == null && overriddenAuditedClasses.contains(clazz)) {
- // Declared audited parent copies @Audited.modStore and @Audited.targetAuditMode configuration from
- // currently mapped entity.
- allClassAudited = persistentPropertiesSource.getXClass().getAnnotation(Audited.class);
- if (allClassAudited == null) {
- // If parent class declares @Audited on the field/property level.
- allClassAudited = DEFAULT_AUDITED;
- }
- } else if (allClassAudited != null && overriddenNotAuditedClasses.contains(clazz)) {
- return null;
- }
- return allClassAudited;
- }
+ /**
+ * @param clazz Class which properties are currently being added.
+ *
+ * @return {@link Audited} annotation of specified class. If processed type hasn't been explicitly marked, method
+ * checks whether given class exists in {@link AuditedPropertiesReader#overriddenAuditedClasses} collection.
+ * In case of success, {@link Audited} configuration of currently mapped entity is returned, otherwise
+ * {@code null}. If processed type exists in {@link AuditedPropertiesReader#overriddenNotAuditedClasses}
+ * collection, the result is also {@code null}.
+ */
+ private Audited computeAuditConfiguration(XClass clazz) {
+ Audited allClassAudited = clazz.getAnnotation( Audited.class );
+ // If processed class is not explicitly marked with @Audited annotation, check whether auditing is
+ // forced by any of its child entities configuration (@AuditedOverride.forClass).
+ if ( allClassAudited == null && overriddenAuditedClasses.contains( clazz ) ) {
+ // Declared audited parent copies @Audited.modStore and @Audited.targetAuditMode configuration from
+ // currently mapped entity.
+ allClassAudited = persistentPropertiesSource.getXClass().getAnnotation( Audited.class );
+ if ( allClassAudited == null ) {
+ // If parent class declares @Audited on the field/property level.
+ allClassAudited = DEFAULT_AUDITED;
+ }
+ }
+ else if ( allClassAudited != null && overriddenNotAuditedClasses.contains( clazz ) ) {
+ return null;
+ }
+ return allClassAudited;
+ }
- /**
- * Recursively adds all audited properties of entity class and its superclasses.
- * @param clazz Currently processed class.
- */
- private void addPropertiesFromClass(XClass clazz) {
- Audited allClassAudited = computeAuditConfiguration(clazz);
+ /**
+ * Recursively adds all audited properties of entity class and its superclasses.
+ *
+ * @param clazz Currently processed class.
+ */
+ private void addPropertiesFromClass(XClass clazz) {
+ final Audited allClassAudited = computeAuditConfiguration( clazz );
//look in the class
- addFromProperties(clazz.getDeclaredProperties("field"), "field", fieldAccessedPersistentProperties, allClassAudited);
- addFromProperties(clazz.getDeclaredProperties("property"), "property", propertyAccessedPersistentProperties, allClassAudited);
-
- if(allClassAudited != null || !auditedPropertiesHolder.isEmpty()) {
- XClass superclazz = clazz.getSuperclass();
- if (!clazz.isInterface() && !"java.lang.Object".equals(superclazz.getName())) {
- addPropertiesFromClass(superclazz);
+ addFromProperties(
+ clazz.getDeclaredProperties( "field" ),
+ "field",
+ fieldAccessedPersistentProperties,
+ allClassAudited
+ );
+ addFromProperties(
+ clazz.getDeclaredProperties( "property" ),
+ "property",
+ propertyAccessedPersistentProperties,
+ allClassAudited
+ );
+
+ if ( allClassAudited != null || !auditedPropertiesHolder.isEmpty() ) {
+ final XClass superclazz = clazz.getSuperclass();
+ if ( !clazz.isInterface() && !"java.lang.Object".equals( superclazz.getName() ) ) {
+ addPropertiesFromClass( superclazz );
}
}
}
- private void addFromProperties(Iterable properties, String accessType, Set persistentProperties, Audited allClassAudited) {
- for (XProperty property : properties) {
+ private void addFromProperties(
+ Iterable properties,
+ String accessType,
+ Set persistentProperties,
+ Audited allClassAudited) {
+ for ( XProperty property : properties ) {
// If this is not a persistent property, with the same access type as currently checked,
// it's not audited as well.
// If the property was already defined by the subclass, is ignored by superclasses
- if ((persistentProperties.contains(property.getName()) && (!auditedPropertiesHolder
- .contains(property.getName())))) {
- Value propertyValue = persistentPropertiesSource.getProperty(property.getName()).getValue();
- if (propertyValue instanceof Component) {
- this.addFromComponentProperty(property, accessType, (Component)propertyValue, allClassAudited);
- } else {
- this.addFromNotComponentProperty(property, accessType, allClassAudited);
+ if ( persistentProperties.contains( property.getName() )
+ && !auditedPropertiesHolder.contains( property.getName() ) ) {
+ final Value propertyValue = persistentPropertiesSource.getProperty( property.getName() ).getValue();
+ if ( propertyValue instanceof Component ) {
+ this.addFromComponentProperty( property, accessType, (Component) propertyValue, allClassAudited );
}
- } else if (propertiesGroupMapping.containsKey(property.getName())) {
+ else {
+ this.addFromNotComponentProperty( property, accessType, allClassAudited );
+ }
+ }
+ else if ( propertiesGroupMapping.containsKey( property.getName() ) ) {
// Retrieve embedded component name based on class field.
- final String embeddedName = propertiesGroupMapping.get(property.getName());
- if (!auditedPropertiesHolder.contains(embeddedName)) {
+ final String embeddedName = propertiesGroupMapping.get( property.getName() );
+ if ( !auditedPropertiesHolder.contains( embeddedName ) ) {
// Manage properties mapped within tag.
- Value propertyValue = persistentPropertiesSource.getProperty(embeddedName).getValue();
- this.addFromPropertiesGroup(embeddedName, property, accessType, (Component)propertyValue, allClassAudited);
+ final Value propertyValue = persistentPropertiesSource.getProperty( embeddedName ).getValue();
+ this.addFromPropertiesGroup(
+ embeddedName,
+ property,
+ accessType,
+ (Component) propertyValue,
+ allClassAudited
+ );
}
}
}
}
- private void addFromPropertiesGroup(String embeddedName, XProperty property, String accessType, Component propertyValue,
- Audited allClassAudited) {
- ComponentAuditingData componentData = new ComponentAuditingData();
- boolean isAudited = fillPropertyData(property, componentData, accessType, allClassAudited);
- if (isAudited) {
+ private void addFromPropertiesGroup(
+ String embeddedName,
+ XProperty property,
+ String accessType,
+ Component propertyValue,
+ Audited allClassAudited) {
+ final ComponentAuditingData componentData = new ComponentAuditingData();
+ final boolean isAudited = fillPropertyData( property, componentData, accessType, allClassAudited );
+ if ( isAudited ) {
// EntityPersister.getPropertyNames() returns name of embedded component instead of class field.
- componentData.setName(embeddedName);
+ componentData.setName( embeddedName );
// Marking component properties as placed directly in class (not inside another component).
- componentData.setBeanName(null);
+ componentData.setBeanName( null );
- PersistentPropertiesSource componentPropertiesSource = new ComponentPropertiesSource( reflectionManager, propertyValue );
- AuditedPropertiesReader audPropReader = new AuditedPropertiesReader(
+ final PersistentPropertiesSource componentPropertiesSource = new ComponentPropertiesSource(
+ reflectionManager,
+ propertyValue
+ );
+ final AuditedPropertiesReader audPropReader = new AuditedPropertiesReader(
ModificationStore.FULL, componentPropertiesSource, componentData, globalCfg, reflectionManager,
- propertyNamePrefix + MappingTools.createComponentPrefix(embeddedName)
+ propertyNamePrefix + MappingTools.createComponentPrefix( embeddedName )
);
audPropReader.read();
- auditedPropertiesHolder.addPropertyAuditingData(embeddedName, componentData);
+ auditedPropertiesHolder.addPropertyAuditingData( embeddedName, componentData );
}
}
- private void addFromComponentProperty(XProperty property, String accessType, Component propertyValue, Audited allClassAudited) {
- ComponentAuditingData componentData = new ComponentAuditingData();
- boolean isAudited = fillPropertyData( property, componentData, accessType, allClassAudited );
+ private void addFromComponentProperty(
+ XProperty property,
+ String accessType,
+ Component propertyValue,
+ Audited allClassAudited) {
+ final ComponentAuditingData componentData = new ComponentAuditingData();
+ final boolean isAudited = fillPropertyData( property, componentData, accessType, allClassAudited );
if ( propertyValue.isDynamic() ) {
if ( isAudited ) {
@@ -343,12 +422,16 @@ public class AuditedPropertiesReader {
return;
}
- PersistentPropertiesSource componentPropertiesSource = new ComponentPropertiesSource(
+ final PersistentPropertiesSource componentPropertiesSource = new ComponentPropertiesSource(
reflectionManager, propertyValue
);
- ComponentAuditedPropertiesReader audPropReader = new ComponentAuditedPropertiesReader(
- ModificationStore.FULL, componentPropertiesSource, componentData, globalCfg, reflectionManager,
+ final ComponentAuditedPropertiesReader audPropReader = new ComponentAuditedPropertiesReader(
+ ModificationStore.FULL,
+ componentPropertiesSource,
+ componentData,
+ globalCfg,
+ reflectionManager,
propertyNamePrefix + MappingTools.createComponentPrefix( property.getName() )
);
audPropReader.read();
@@ -359,85 +442,102 @@ public class AuditedPropertiesReader {
}
}
- private void addFromNotComponentProperty(XProperty property, String accessType, Audited allClassAudited){
- PropertyAuditingData propertyData = new PropertyAuditingData();
- boolean isAudited = fillPropertyData(property, propertyData, accessType, allClassAudited);
+ private void addFromNotComponentProperty(XProperty property, String accessType, Audited allClassAudited) {
+ final PropertyAuditingData propertyData = new PropertyAuditingData();
+ final boolean isAudited = fillPropertyData( property, propertyData, accessType, allClassAudited );
- if (isAudited) {
+ if ( isAudited ) {
// Now we know that the property is audited
- auditedPropertiesHolder.addPropertyAuditingData(property.getName(), propertyData);
+ auditedPropertiesHolder.addPropertyAuditingData( property.getName(), propertyData );
}
}
-
-
+
+
/**
* Checks if a property is audited and if yes, fills all of its data.
+ *
* @param property Property to check.
* @param propertyData Property data, on which to set this property's modification store.
* @param accessType Access type for the property.
+ *
* @return False if this property is not audited.
*/
- private boolean fillPropertyData(XProperty property, PropertyAuditingData propertyData,
- String accessType, Audited allClassAudited) {
+ private boolean fillPropertyData(
+ XProperty property,
+ PropertyAuditingData propertyData,
+ String accessType,
+ Audited allClassAudited) {
// check if a property is declared as not audited to exclude it
// useful if a class is audited but some properties should be excluded
- NotAudited unVer = property.getAnnotation(NotAudited.class);
- if ((unVer != null && !overriddenAuditedProperties.contains(property)) || overriddenNotAuditedProperties.contains(property)) {
+ final NotAudited unVer = property.getAnnotation( NotAudited.class );
+ if ( (unVer != null
+ && !overriddenAuditedProperties.contains( property ))
+ || overriddenNotAuditedProperties.contains( property ) ) {
return false;
- } else {
+ }
+ else {
// if the optimistic locking field has to be unversioned and the current property
// is the optimistic locking field, don't audit it
- if (globalCfg.isDoNotAuditOptimisticLockingField()) {
- Version jpaVer = property.getAnnotation(Version.class);
- if (jpaVer != null) {
+ if ( globalCfg.isDoNotAuditOptimisticLockingField() ) {
+ final Version jpaVer = property.getAnnotation( Version.class );
+ if ( jpaVer != null ) {
return false;
}
}
}
-
- if(!this.checkAudited(property, propertyData, allClassAudited)){
+
+ if ( !this.checkAudited( property, propertyData, allClassAudited ) ) {
return false;
}
- String propertyName = propertyNamePrefix + property.getName();
- propertyData.setName(propertyName);
+ final String propertyName = propertyNamePrefix + property.getName();
+ propertyData.setName( propertyName );
propertyData.setModifiedFlagName(
- MetadataTools.getModifiedFlagPropertyName(
- propertyName,
- globalCfg.getModifiedFlagSuffix()));
- propertyData.setBeanName(property.getName());
- propertyData.setAccessType(accessType);
+ MetadataTools.getModifiedFlagPropertyName(
+ propertyName,
+ globalCfg.getModifiedFlagSuffix()
+ )
+ );
+ propertyData.setBeanName( property.getName() );
+ propertyData.setAccessType( accessType );
- addPropertyJoinTables(property, propertyData);
- addPropertyAuditingOverrides(property, propertyData);
- if (!processPropertyAuditingOverrides(property, propertyData)) {
- return false; // not audited due to AuditOverride annotation
+ addPropertyJoinTables( property, propertyData );
+ addPropertyAuditingOverrides( property, propertyData );
+ if ( !processPropertyAuditingOverrides( property, propertyData ) ) {
+ // not audited due to AuditOverride annotation
+ return false;
}
- addPropertyMapKey(property, propertyData);
- setPropertyAuditMappedBy(property, propertyData);
- setPropertyRelationMappedBy(property, propertyData);
+ addPropertyMapKey( property, propertyData );
+ setPropertyAuditMappedBy( property, propertyData );
+ setPropertyRelationMappedBy( property, propertyData );
return true;
}
- protected boolean checkAudited(XProperty property,
+ protected boolean checkAudited(
+ XProperty property,
PropertyAuditingData propertyData, Audited allClassAudited) {
// Checking if this property is explicitly audited or if all properties are.
- Audited aud = (property.isAnnotationPresent(Audited.class)) ? (property.getAnnotation(Audited.class)) : allClassAudited;
- if (aud == null && overriddenAuditedProperties.contains(property) && !overriddenNotAuditedProperties.contains(property)) {
+ Audited aud = (property.isAnnotationPresent( Audited.class ))
+ ? property.getAnnotation( Audited.class )
+ : allClassAudited;
+ if ( aud == null
+ && overriddenAuditedProperties.contains( property )
+ && !overriddenNotAuditedProperties.contains( property ) ) {
// Assigning @Audited defaults. If anyone needs to customize those values in the future,
// appropriate fields shall be added to @AuditOverride annotation.
aud = DEFAULT_AUDITED;
}
- if (aud != null) {
- propertyData.setStore(aud.modStore());
- propertyData.setRelationTargetAuditMode(aud.targetAuditMode());
- propertyData.setUsingModifiedFlag(checkUsingModifiedFlag(aud));
+ if ( aud != null ) {
+ propertyData.setStore( aud.modStore() );
+ propertyData.setRelationTargetAuditMode( aud.targetAuditMode() );
+ propertyData.setUsingModifiedFlag( checkUsingModifiedFlag( aud ) );
return true;
- } else {
+ }
+ else {
return false;
}
}
@@ -447,121 +547,172 @@ public class AuditedPropertiesReader {
globalCfg.isGlobalWithModifiedFlag() : aud.withModifiedFlag();
}
- private void setPropertyRelationMappedBy(XProperty property, PropertyAuditingData propertyData) {
- OneToMany oneToMany = property.getAnnotation(OneToMany.class);
- if (oneToMany != null && !"".equals(oneToMany.mappedBy())) {
- propertyData.setRelationMappedBy(oneToMany.mappedBy());
- }
- }
+ private void setPropertyRelationMappedBy(XProperty property, PropertyAuditingData propertyData) {
+ final OneToMany oneToMany = property.getAnnotation( OneToMany.class );
+ if ( oneToMany != null && !"".equals( oneToMany.mappedBy() ) ) {
+ propertyData.setRelationMappedBy( oneToMany.mappedBy() );
+ }
+ }
private void setPropertyAuditMappedBy(XProperty property, PropertyAuditingData propertyData) {
- AuditMappedBy auditMappedBy = property.getAnnotation(AuditMappedBy.class);
- if (auditMappedBy != null) {
- propertyData.setAuditMappedBy(auditMappedBy.mappedBy());
- if (!"".equals(auditMappedBy.positionMappedBy())) {
- propertyData.setPositionMappedBy(auditMappedBy.positionMappedBy());
- }
- }
- }
+ final AuditMappedBy auditMappedBy = property.getAnnotation( AuditMappedBy.class );
+ if ( auditMappedBy != null ) {
+ propertyData.setAuditMappedBy( auditMappedBy.mappedBy() );
+ if ( !"".equals( auditMappedBy.positionMappedBy() ) ) {
+ propertyData.setPositionMappedBy( auditMappedBy.positionMappedBy() );
+ }
+ }
+ }
private void addPropertyMapKey(XProperty property, PropertyAuditingData propertyData) {
- MapKey mapKey = property.getAnnotation(MapKey.class);
- if (mapKey != null) {
- propertyData.setMapKey(mapKey.name());
+ final MapKey mapKey = property.getAnnotation( MapKey.class );
+ if ( mapKey != null ) {
+ propertyData.setMapKey( mapKey.name() );
}
}
private void addPropertyJoinTables(XProperty property, PropertyAuditingData propertyData) {
// first set the join table based on the AuditJoinTable annotation
- AuditJoinTable joinTable = property.getAnnotation(AuditJoinTable.class);
- if (joinTable != null) {
- propertyData.setJoinTable(joinTable);
- } else {
- propertyData.setJoinTable(DEFAULT_AUDIT_JOIN_TABLE);
+ final AuditJoinTable joinTable = property.getAnnotation( AuditJoinTable.class );
+ if ( joinTable != null ) {
+ propertyData.setJoinTable( joinTable );
+ }
+ else {
+ propertyData.setJoinTable( DEFAULT_AUDIT_JOIN_TABLE );
}
}
- /***
+ /**
* Add the {@link AuditOverride} annotations.
*
* @param property the property being processed
* @param propertyData the Envers auditing data for this property
*/
private void addPropertyAuditingOverrides(XProperty property, PropertyAuditingData propertyData) {
- AuditOverride annotationOverride = property.getAnnotation(AuditOverride.class);
- if (annotationOverride != null) {
- propertyData.addAuditingOverride(annotationOverride);
+ final AuditOverride annotationOverride = property.getAnnotation( AuditOverride.class );
+ if ( annotationOverride != null ) {
+ propertyData.addAuditingOverride( annotationOverride );
}
- AuditOverrides annotationOverrides = property.getAnnotation(AuditOverrides.class);
- if (annotationOverrides != null) {
- propertyData.addAuditingOverrides(annotationOverrides);
+ final AuditOverrides annotationOverrides = property.getAnnotation( AuditOverrides.class );
+ if ( annotationOverrides != null ) {
+ propertyData.addAuditingOverrides( annotationOverrides );
}
}
/**
* Process the {@link AuditOverride} annotations for this property.
*
- * @param property
- * the property for which the {@link AuditOverride}
- * annotations are being processed
- * @param propertyData
- * the Envers auditing data for this property
+ * @param property the property for which the {@link AuditOverride}
+ * annotations are being processed
+ * @param propertyData the Envers auditing data for this property
+ *
* @return {@code false} if isAudited() of the override annotation was set to
*/
private boolean processPropertyAuditingOverrides(XProperty property, PropertyAuditingData propertyData) {
// if this property is part of a component, process all override annotations
- if (this.auditedPropertiesHolder instanceof ComponentAuditingData) {
- List overrides = ((ComponentAuditingData) this.auditedPropertiesHolder).getAuditingOverrides();
- for (AuditOverride override : overrides) {
- if (property.getName().equals(override.name())) {
+ if ( this.auditedPropertiesHolder instanceof ComponentAuditingData ) {
+ final List overrides = ( (ComponentAuditingData) this.auditedPropertiesHolder ).getAuditingOverrides();
+ for ( AuditOverride override : overrides ) {
+ if ( property.getName().equals( override.name() ) ) {
// the override applies to this property
- if (!override.isAudited()) {
+ if ( !override.isAudited() ) {
return false;
- } else {
- if (override.auditJoinTable() != null) {
- propertyData.setJoinTable(override.auditJoinTable());
+ }
+ else {
+ if ( override.auditJoinTable() != null ) {
+ propertyData.setJoinTable( override.auditJoinTable() );
}
}
}
}
-
+
}
return true;
}
- private static Audited DEFAULT_AUDITED = new Audited() {
- public ModificationStore modStore() { return ModificationStore.FULL; }
- public RelationTargetAuditMode targetAuditMode() { return RelationTargetAuditMode.AUDITED; }
- public Class[] auditParents() { return new Class[0]; }
- public boolean withModifiedFlag() { return false; }
- public Class extends Annotation> annotationType() { return this.getClass(); }
- };
+ private static final Audited DEFAULT_AUDITED = new Audited() {
+ @Override
+ public ModificationStore modStore() {
+ return ModificationStore.FULL;
+ }
- private static AuditJoinTable DEFAULT_AUDIT_JOIN_TABLE = new AuditJoinTable() {
- public String name() { return ""; }
- public String schema() { return ""; }
- public String catalog() { return ""; }
- public JoinColumn[] inverseJoinColumns() { return new JoinColumn[0]; }
- public Class extends Annotation> annotationType() { return this.getClass(); }
+ @Override
+ public RelationTargetAuditMode targetAuditMode() {
+ return RelationTargetAuditMode.AUDITED;
+ }
+
+ @Override
+ public Class[] auditParents() {
+ return new Class[0];
+ }
+
+ @Override
+ public boolean withModifiedFlag() {
+ return false;
+ }
+
+ @Override
+ public Class extends Annotation> annotationType() {
+ return this.getClass();
+ }
};
- public static class ComponentPropertiesSource implements PersistentPropertiesSource {
+ private static final AuditJoinTable DEFAULT_AUDIT_JOIN_TABLE = new AuditJoinTable() {
+ @Override
+ public String name() {
+ return "";
+ }
+
+ @Override
+ public String schema() {
+ return "";
+ }
+
+ @Override
+ public String catalog() {
+ return "";
+ }
+
+ @Override
+ public JoinColumn[] inverseJoinColumns() {
+ return new JoinColumn[0];
+ }
+
+ @Override
+ public Class extends Annotation> annotationType() {
+ return this.getClass();
+ }
+ };
+
+ public static class ComponentPropertiesSource implements PersistentPropertiesSource {
private final XClass xclass;
private final Component component;
public ComponentPropertiesSource(ReflectionManager reflectionManager, Component component) {
try {
- this.xclass = reflectionManager.classForName(component.getComponentClassName(), this.getClass());
- } catch (ClassNotFoundException e) {
- throw new MappingException(e);
+ this.xclass = reflectionManager.classForName( component.getComponentClassName(), this.getClass() );
+ }
+ catch (ClassNotFoundException e) {
+ throw new MappingException( e );
}
this.component = component;
}
+ @Override
@SuppressWarnings({"unchecked"})
- public Iterator getPropertyIterator() { return component.getPropertyIterator(); }
- public Property getProperty(String propertyName) { return component.getProperty(propertyName); }
- public XClass getXClass() { return xclass; }
+ public Iterator getPropertyIterator() {
+ return component.getPropertyIterator();
+ }
+
+ @Override
+ public Property getProperty(String propertyName) {
+ return component.getProperty( propertyName );
+ }
+
+ @Override
+ public XClass getXClass() {
+ return xclass;
+ }
}
}
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/ClassAuditingData.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/ClassAuditingData.java
index 785c11fd75..ed20a7f5bf 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/ClassAuditingData.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/ClassAuditingData.java
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2008, 2013, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -22,6 +22,7 @@
* Boston, MA 02110-1301 USA
*/
package org.hibernate.envers.configuration.internal.metadata.reader;
+
import java.util.Map;
import org.hibernate.envers.AuditTable;
@@ -32,12 +33,12 @@ import static org.hibernate.envers.internal.tools.Tools.newHashMap;
* @author Adam Warski (adam at warski dot org)
* @author Sebastian Komander
* @author Hern&aacut;n Chanfreau
-*/
+ */
public class ClassAuditingData implements AuditedPropertiesHolder {
- private final Map properties;
- private final Map secondaryTableDictionary;
+ private final Map properties;
+ private final Map secondaryTableDictionary;
- private AuditTable auditTable;
+ private AuditTable auditTable;
/**
* True if the class is audited globally (this helps to cover the cases when there are no fields in the class,
@@ -45,48 +46,52 @@ public class ClassAuditingData implements AuditedPropertiesHolder {
*/
private boolean defaultAudited;
- public ClassAuditingData() {
- properties = newHashMap();
- secondaryTableDictionary = newHashMap();
- }
-
- public boolean isEmpty() {
- return properties.isEmpty();
- }
-
- public void addPropertyAuditingData(String propertyName, PropertyAuditingData auditingData) {
- properties.put(propertyName, auditingData);
+ public ClassAuditingData() {
+ properties = newHashMap();
+ secondaryTableDictionary = newHashMap();
}
- public PropertyAuditingData getPropertyAuditingData(String propertyName) {
- return properties.get(propertyName);
- }
+ @Override
+ public boolean isEmpty() {
+ return properties.isEmpty();
+ }
- public Iterable getPropertyNames() {
- return properties.keySet();
- }
+ @Override
+ public void addPropertyAuditingData(String propertyName, PropertyAuditingData auditingData) {
+ properties.put( propertyName, auditingData );
+ }
- public Map getSecondaryTableDictionary() {
- return secondaryTableDictionary;
- }
+ @Override
+ public PropertyAuditingData getPropertyAuditingData(String propertyName) {
+ return properties.get( propertyName );
+ }
- public AuditTable getAuditTable() {
- return auditTable;
- }
+ public Iterable getPropertyNames() {
+ return properties.keySet();
+ }
- public void setAuditTable(AuditTable auditTable) {
- this.auditTable = auditTable;
- }
+ public Map getSecondaryTableDictionary() {
+ return secondaryTableDictionary;
+ }
+
+ public AuditTable getAuditTable() {
+ return auditTable;
+ }
+
+ public void setAuditTable(AuditTable auditTable) {
+ this.auditTable = auditTable;
+ }
public void setDefaultAudited(boolean defaultAudited) {
this.defaultAudited = defaultAudited;
}
public boolean isAudited() {
- return defaultAudited || properties.size() > 0;
- }
-
+ return defaultAudited || properties.size() > 0;
+ }
+
+ @Override
public boolean contains(String propertyName) {
- return properties.containsKey(propertyName);
+ return properties.containsKey( propertyName );
}
}
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/ComponentAuditedPropertiesReader.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/ComponentAuditedPropertiesReader.java
index 3e970cfe78..fa7d250237 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/ComponentAuditedPropertiesReader.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/ComponentAuditedPropertiesReader.java
@@ -1,4 +1,28 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2013, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
package org.hibernate.envers.configuration.internal.metadata.reader;
+
import org.hibernate.annotations.common.reflection.ReflectionManager;
import org.hibernate.annotations.common.reflection.XProperty;
import org.hibernate.envers.Audited;
@@ -7,34 +31,40 @@ import org.hibernate.envers.configuration.internal.GlobalConfiguration;
/**
* Reads the audited properties for components.
- *
+ *
* @author Hern&aacut;n Chanfreau
* @author Michal Skowronek (mskowr at o2 dot pl)
*/
public class ComponentAuditedPropertiesReader extends AuditedPropertiesReader {
- public ComponentAuditedPropertiesReader(ModificationStore defaultStore,
+ public ComponentAuditedPropertiesReader(
+ ModificationStore defaultStore,
PersistentPropertiesSource persistentPropertiesSource,
AuditedPropertiesHolder auditedPropertiesHolder,
GlobalConfiguration globalCfg, ReflectionManager reflectionManager,
String propertyNamePrefix) {
- super(defaultStore, persistentPropertiesSource, auditedPropertiesHolder,
- globalCfg, reflectionManager, propertyNamePrefix);
+ super(
+ defaultStore, persistentPropertiesSource, auditedPropertiesHolder,
+ globalCfg, reflectionManager, propertyNamePrefix
+ );
}
-
+
@Override
- protected boolean checkAudited(XProperty property,
- PropertyAuditingData propertyData, Audited allClassAudited) {
+ protected boolean checkAudited(
+ XProperty property,
+ PropertyAuditingData propertyData,
+ Audited allClassAudited) {
// Checking if this property is explicitly audited or if all properties are.
- Audited aud = property.getAnnotation(Audited.class);
- if (aud != null) {
- propertyData.setStore(aud.modStore());
- propertyData.setRelationTargetAuditMode(aud.targetAuditMode());
- propertyData.setUsingModifiedFlag(checkUsingModifiedFlag(aud));
- } else {
- propertyData.setStore(ModificationStore.FULL);
- }
- return true;
+ final Audited aud = property.getAnnotation( Audited.class );
+ if ( aud != null ) {
+ propertyData.setStore( aud.modStore() );
+ propertyData.setRelationTargetAuditMode( aud.targetAuditMode() );
+ propertyData.setUsingModifiedFlag( checkUsingModifiedFlag( aud ) );
+ }
+ else {
+ propertyData.setStore( ModificationStore.FULL );
+ }
+ return true;
}
}
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/ComponentAuditingData.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/ComponentAuditingData.java
index 60c3ff2299..754c26bc60 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/ComponentAuditingData.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/ComponentAuditingData.java
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2008, 2013, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,9 +20,9 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.envers.configuration.internal.metadata.reader;
+
import java.util.Map;
import java.util.Set;
@@ -30,6 +30,7 @@ import static org.hibernate.envers.internal.tools.Tools.newHashMap;
/**
* Audit mapping meta-data for component.
+ *
* @author Adam Warski (adam at warski dot org)
* @author Hern&aacut;n Chanfreau
*/
@@ -40,21 +41,25 @@ public class ComponentAuditingData extends PropertyAuditingData implements Audit
this.properties = newHashMap();
}
+ @Override
public boolean isEmpty() {
return properties.isEmpty();
}
+ @Override
public void addPropertyAuditingData(String propertyName, PropertyAuditingData auditingData) {
- properties.put(propertyName, auditingData);
+ properties.put( propertyName, auditingData );
}
- public PropertyAuditingData getPropertyAuditingData(String propertyName) {
- return properties.get(propertyName);
- }
-
- public boolean contains(String propertyName) {
- return properties.containsKey(propertyName);
- }
+ @Override
+ public PropertyAuditingData getPropertyAuditingData(String propertyName) {
+ return properties.get( propertyName );
+ }
+
+ @Override
+ public boolean contains(String propertyName) {
+ return properties.containsKey( propertyName );
+ }
public Set getPropertyNames() {
return properties.keySet();
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/PersistentPropertiesSource.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/PersistentPropertiesSource.java
index 864d5382b7..b4832e5f91 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/PersistentPropertiesSource.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/PersistentPropertiesSource.java
@@ -1,4 +1,28 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2013, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
package org.hibernate.envers.configuration.internal.metadata.reader;
+
import java.util.Iterator;
import org.hibernate.annotations.common.reflection.XClass;
@@ -6,10 +30,13 @@ import org.hibernate.mapping.Property;
/**
* A source of data on persistent properties of a class or component.
+ *
* @author Adam Warski (adam at warski dot org)
*/
public interface PersistentPropertiesSource {
Iterator getPropertyIterator();
+
Property getProperty(String propertyName);
+
XClass getXClass();
}
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 500ad95403..85d4424c8d 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
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2008, 2013, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,9 +20,9 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.envers.configuration.internal.metadata.reader;
+
import java.util.ArrayList;
import java.util.List;
@@ -38,45 +38,46 @@ import org.hibernate.envers.internal.entities.PropertyData;
* @author Michal Skowronek (mskowr at o2 dot pl)
*/
public class PropertyAuditingData {
- private String name;
+ private String name;
private String beanName;
- private ModificationStore store;
- private String mapKey;
- private AuditJoinTable joinTable;
- private String accessType;
- private final List auditJoinTableOverrides = new ArrayList(0);
+ private ModificationStore store;
+ private String mapKey;
+ private AuditJoinTable joinTable;
+ private String accessType;
+ private final List auditJoinTableOverrides = new ArrayList( 0 );
private RelationTargetAuditMode relationTargetAuditMode;
- private String auditMappedBy;
- private String relationMappedBy;
- private String positionMappedBy;
- private boolean forceInsertable;
+ private String auditMappedBy;
+ private String relationMappedBy;
+ private String positionMappedBy;
+ private boolean forceInsertable;
private boolean usingModifiedFlag;
private String modifiedFlagName;
public PropertyAuditingData() {
- }
+ }
- public PropertyAuditingData(String name, String accessType, ModificationStore store,
- RelationTargetAuditMode relationTargetAuditMode,
- String auditMappedBy, String positionMappedBy,
- boolean forceInsertable) {
- this.name = name;
+ public PropertyAuditingData(
+ String name, String accessType, ModificationStore store,
+ RelationTargetAuditMode relationTargetAuditMode,
+ String auditMappedBy, String positionMappedBy,
+ boolean forceInsertable) {
+ this.name = name;
this.beanName = name;
- this.accessType = accessType;
- this.store = store;
+ this.accessType = accessType;
+ this.store = store;
this.relationTargetAuditMode = relationTargetAuditMode;
- this.auditMappedBy = auditMappedBy;
- this.positionMappedBy = positionMappedBy;
- this.forceInsertable = forceInsertable;
- }
+ this.auditMappedBy = auditMappedBy;
+ this.positionMappedBy = positionMappedBy;
+ this.forceInsertable = forceInsertable;
+ }
public String getName() {
- return name;
- }
+ return name;
+ }
- public void setName(String name) {
- this.name = name;
- }
+ public void setName(String name) {
+ this.name = name;
+ }
public String getBeanName() {
return beanName;
@@ -87,77 +88,79 @@ public class PropertyAuditingData {
}
public ModificationStore getStore() {
- return store;
- }
+ return store;
+ }
- public void setStore(ModificationStore store) {
- this.store = store;
- }
+ public void setStore(ModificationStore store) {
+ this.store = store;
+ }
- public String getMapKey() {
- return mapKey;
- }
+ public String getMapKey() {
+ return mapKey;
+ }
- public void setMapKey(String mapKey) {
- this.mapKey = mapKey;
- }
+ public void setMapKey(String mapKey) {
+ this.mapKey = mapKey;
+ }
- public AuditJoinTable getJoinTable() {
- return joinTable;
- }
+ public AuditJoinTable getJoinTable() {
+ return joinTable;
+ }
- public void setJoinTable(AuditJoinTable joinTable) {
- this.joinTable = joinTable;
- }
+ public void setJoinTable(AuditJoinTable joinTable) {
+ this.joinTable = joinTable;
+ }
- public String getAccessType() {
- return accessType;
- }
+ public String getAccessType() {
+ return accessType;
+ }
- public void setAccessType(String accessType) {
- this.accessType = accessType;
- }
+ public void setAccessType(String accessType) {
+ this.accessType = accessType;
+ }
- public PropertyData getPropertyData() {
- return new PropertyData(name, beanName, accessType, store,
- usingModifiedFlag, modifiedFlagName);
- }
+ public PropertyData getPropertyData() {
+ return new PropertyData(
+ name, beanName, accessType, store,
+ usingModifiedFlag, modifiedFlagName
+ );
+ }
public List getAuditingOverrides() {
return auditJoinTableOverrides;
}
- public String getAuditMappedBy() {
- return auditMappedBy;
- }
+ public String getAuditMappedBy() {
+ return auditMappedBy;
+ }
- public void setAuditMappedBy(String auditMappedBy) {
- this.auditMappedBy = auditMappedBy;
- }
+ public void setAuditMappedBy(String auditMappedBy) {
+ this.auditMappedBy = auditMappedBy;
+ }
- public String getRelationMappedBy() {
- return relationMappedBy;
- }
+ public String getRelationMappedBy() {
+ return relationMappedBy;
+ }
- public void setRelationMappedBy(String relationMappedBy) {
- this.relationMappedBy = relationMappedBy;
- }
+ public void setRelationMappedBy(String relationMappedBy) {
+ this.relationMappedBy = relationMappedBy;
+ }
- public String getPositionMappedBy() {
- return positionMappedBy;
- }
+ public String getPositionMappedBy() {
+ return positionMappedBy;
+ }
- public void setPositionMappedBy(String positionMappedBy) {
- this.positionMappedBy = positionMappedBy;
- }
+ public void setPositionMappedBy(String positionMappedBy) {
+ this.positionMappedBy = positionMappedBy;
+ }
- public boolean isForceInsertable() {
- return forceInsertable;
- }
+ public boolean isForceInsertable() {
+ return forceInsertable;
+ }
- public void setForceInsertable(boolean forceInsertable) {
- this.forceInsertable = forceInsertable;
- }
+ public void setForceInsertable(boolean forceInsertable) {
+ this.forceInsertable = forceInsertable;
+ }
public boolean isUsingModifiedFlag() {
return usingModifiedFlag;
@@ -172,25 +175,25 @@ public class PropertyAuditingData {
}
public void addAuditingOverride(AuditOverride annotation) {
- if (annotation != null) {
- String overrideName = annotation.name();
+ if ( annotation != null ) {
+ final String overrideName = annotation.name();
boolean present = false;
- for (AuditOverride current : auditJoinTableOverrides) {
- if (current.name().equals(overrideName)) {
+ for ( AuditOverride current : auditJoinTableOverrides ) {
+ if ( current.name().equals( overrideName ) ) {
present = true;
break;
}
}
- if (!present) {
- auditJoinTableOverrides.add(annotation);
+ if ( !present ) {
+ auditJoinTableOverrides.add( annotation );
}
}
}
public void addAuditingOverrides(AuditOverrides annotationOverrides) {
- if (annotationOverrides != null) {
- for (AuditOverride annotation : annotationOverrides.value()) {
- addAuditingOverride(annotation);
+ if ( annotationOverrides != null ) {
+ for ( AuditOverride annotation : annotationOverrides.value() ) {
+ addAuditingOverride( annotation );
}
}
}
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/spi/AuditConfiguration.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/spi/AuditConfiguration.java
index ce32b2c187..2675a1a541 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/spi/AuditConfiguration.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/spi/AuditConfiguration.java
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2008, 2013, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -107,30 +107,30 @@ public class AuditConfiguration {
public AuditConfiguration(Configuration cfg, ClassLoaderService classLoaderService) {
// TODO: Temporarily allow Envers to continuing using
// hibernate-commons-annotations' for reflection and class loading.
- ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+ final ClassLoader tccl = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader( ClassLoaderHelper.getContextClassLoader() );
-
- Properties properties = cfg.getProperties();
- ReflectionManager reflectionManager = cfg.getReflectionManager();
- globalCfg = new GlobalConfiguration( properties, classLoaderService );
- RevisionInfoConfiguration revInfoCfg = new RevisionInfoConfiguration( globalCfg );
- RevisionInfoConfigurationResult revInfoCfgResult = revInfoCfg.configure( cfg, reflectionManager );
- auditEntCfg = new AuditEntitiesConfiguration( properties, revInfoCfgResult.getRevisionInfoEntityName() );
- auditProcessManager = new AuditProcessManager( revInfoCfgResult.getRevisionInfoGenerator() );
- revisionInfoQueryCreator = revInfoCfgResult.getRevisionInfoQueryCreator();
- revisionInfoNumberReader = revInfoCfgResult.getRevisionInfoNumberReader();
- modifiedEntityNamesReader = revInfoCfgResult.getModifiedEntityNamesReader();
+ final Properties properties = cfg.getProperties();
+
+ final ReflectionManager reflectionManager = cfg.getReflectionManager();
+ this.globalCfg = new GlobalConfiguration( properties, classLoaderService );
+ final RevisionInfoConfiguration revInfoCfg = new RevisionInfoConfiguration( globalCfg );
+ final RevisionInfoConfigurationResult revInfoCfgResult = revInfoCfg.configure( cfg, reflectionManager );
+ this.auditEntCfg = new AuditEntitiesConfiguration( properties, revInfoCfgResult.getRevisionInfoEntityName() );
+ this.auditProcessManager = new AuditProcessManager( revInfoCfgResult.getRevisionInfoGenerator() );
+ this.revisionInfoQueryCreator = revInfoCfgResult.getRevisionInfoQueryCreator();
+ this.revisionInfoNumberReader = revInfoCfgResult.getRevisionInfoNumberReader();
+ this.modifiedEntityNamesReader = revInfoCfgResult.getModifiedEntityNamesReader();
this.classLoaderService = classLoaderService;
- auditStrategy = initializeAuditStrategy(
+ this.auditStrategy = initializeAuditStrategy(
revInfoCfgResult.getRevisionInfoClass(),
revInfoCfgResult.getRevisionInfoTimestampData()
);
- entCfg = new EntitiesConfigurator().configure(
+ this.entCfg = new EntitiesConfigurator().configure(
cfg, reflectionManager, globalCfg, auditEntCfg, auditStrategy, classLoaderService,
revInfoCfgResult.getRevisionInfoXmlMapping(), revInfoCfgResult.getRevisionInfoRelationMapping()
);
-
+
Thread.currentThread().setContextClassLoader( tccl );
}
@@ -143,11 +143,14 @@ public class AuditConfiguration {
auditStrategyClass = this.getClass().getClassLoader().loadClass( auditEntCfg.getAuditStrategyName() );
}
catch (Exception e) {
- auditStrategyClass = ReflectionTools.loadClass( auditEntCfg.getAuditStrategyName(), classLoaderService );
+ auditStrategyClass = ReflectionTools.loadClass(
+ auditEntCfg.getAuditStrategyName(),
+ classLoaderService
+ );
}
- strategy = (AuditStrategy) ReflectHelper.getDefaultConstructor(auditStrategyClass).newInstance();
+ strategy = (AuditStrategy) ReflectHelper.getDefaultConstructor( auditStrategyClass ).newInstance();
}
- catch ( Exception e ) {
+ catch (Exception e) {
throw new MappingException(
String.format( "Unable to create AuditStrategy[%s] instance.", auditEntCfg.getAuditStrategyName() ),
e
@@ -156,27 +159,25 @@ public class AuditConfiguration {
if ( strategy instanceof ValidityAuditStrategy ) {
// further initialization required
- Getter revisionTimestampGetter = ReflectionTools.getGetter( revisionInfoClass, revisionInfoTimestampData );
+ final Getter revisionTimestampGetter = ReflectionTools.getGetter( revisionInfoClass, revisionInfoTimestampData );
( (ValidityAuditStrategy) strategy ).setRevisionTimestampGetter( revisionTimestampGetter );
}
return strategy;
}
- //
-
- private static Map cfgs = new WeakHashMap();
+ private static final Map CFGS = new WeakHashMap();
public synchronized static AuditConfiguration getFor(Configuration cfg) {
return getFor( cfg, null );
}
public synchronized static AuditConfiguration getFor(Configuration cfg, ClassLoaderService classLoaderService) {
- AuditConfiguration verCfg = cfgs.get( cfg );
+ AuditConfiguration verCfg = CFGS.get( cfg );
if ( verCfg == null ) {
verCfg = new AuditConfiguration( cfg, classLoaderService );
- cfgs.put( cfg, verCfg );
+ CFGS.put( cfg, verCfg );
cfg.buildMappings();
}
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/enhanced/OrderedSequenceGenerator.java b/hibernate-envers/src/main/java/org/hibernate/envers/enhanced/OrderedSequenceGenerator.java
index 9747280269..d25753b39e 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/enhanced/OrderedSequenceGenerator.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/enhanced/OrderedSequenceGenerator.java
@@ -1,3 +1,26 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2013, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
package org.hibernate.envers.enhanced;
import org.hibernate.HibernateException;
@@ -8,6 +31,7 @@ import org.hibernate.internal.util.StringHelper;
/**
* Revision number generator has to produce values in ascending order (gaps may occur).
+ *
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
*/
public class OrderedSequenceGenerator extends SequenceStyleGenerator {
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/enhanced/SequenceIdRevisionEntity.java b/hibernate-envers/src/main/java/org/hibernate/envers/enhanced/SequenceIdRevisionEntity.java
index 41a78fdebc..540f629693 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/enhanced/SequenceIdRevisionEntity.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/enhanced/SequenceIdRevisionEntity.java
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2008, 2013, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -23,13 +23,13 @@
*/
package org.hibernate.envers.enhanced;
-import java.io.Serializable;
-import java.text.DateFormat;
-import java.util.Date;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;
+import java.io.Serializable;
+import java.text.DateFormat;
+import java.util.Date;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;
@@ -42,64 +42,72 @@ import org.hibernate.envers.RevisionTimestamp;
*/
@MappedSuperclass
public class SequenceIdRevisionEntity implements Serializable {
- private static final long serialVersionUID = 4159156677698841902L;
-
- @Id
- @GeneratedValue(generator = "RevisionNumberSequenceGenerator")
- @GenericGenerator(name = "RevisionNumberSequenceGenerator",
- strategy = "org.hibernate.envers.enhanced.OrderedSequenceGenerator",
- parameters = {@Parameter(name = "table_name", value = "REVISION_GENERATOR"),
- @Parameter(name = "sequence_name", value = "REVISION_GENERATOR"),
- @Parameter(name = "initial_value", value = "1"),
- @Parameter(name = "increment_size", value = "1")
- }
- )
- @RevisionNumber
- private int id;
+ private static final long serialVersionUID = 4159156677698841902L;
- @RevisionTimestamp
- private long timestamp;
+ @Id
+ @GeneratedValue(generator = "RevisionNumberSequenceGenerator")
+ @GenericGenerator(
+ name = "RevisionNumberSequenceGenerator",
+ strategy = "org.hibernate.envers.enhanced.OrderedSequenceGenerator",
+ parameters = {
+ @Parameter(name = "table_name", value = "REVISION_GENERATOR"),
+ @Parameter(name = "sequence_name", value = "REVISION_GENERATOR"),
+ @Parameter(name = "initial_value", value = "1"),
+ @Parameter(name = "increment_size", value = "1")
+ }
+ )
+ @RevisionNumber
+ private int id;
- public int getId() {
- return id;
- }
+ @RevisionTimestamp
+ private long timestamp;
- public void setId(int id) {
- this.id = id;
- }
+ public int getId() {
+ return id;
+ }
- @Transient
- public Date getRevisionDate() {
- return new Date(timestamp);
- }
+ public void setId(int id) {
+ this.id = id;
+ }
- public long getTimestamp() {
- return timestamp;
- }
+ @Transient
+ public Date getRevisionDate() {
+ return new Date( timestamp );
+ }
- public void setTimestamp(long timestamp) {
- this.timestamp = timestamp;
- }
+ public long getTimestamp() {
+ return timestamp;
+ }
- public boolean equals(Object o) {
- if (this == o) return true;
- if (!(o instanceof SequenceIdRevisionEntity )) return false;
+ @SuppressWarnings("UnusedDeclaration")
+ public void setTimestamp(long timestamp) {
+ this.timestamp = timestamp;
+ }
- SequenceIdRevisionEntity that = (SequenceIdRevisionEntity) o;
+ @Override
+ public boolean equals(Object o) {
+ if ( this == o ) {
+ return true;
+ }
+ if ( !(o instanceof SequenceIdRevisionEntity) ) {
+ return false;
+ }
- if (id != that.id) return false;
- if (timestamp != that.timestamp) return false;
+ final SequenceIdRevisionEntity that = (SequenceIdRevisionEntity) o;
+ return id == that.id && timestamp == that.timestamp;
+ }
- return true;
- }
+ @Override
+ public int hashCode() {
+ int result = id;
+ result = 31 * result + (int) (timestamp ^ (timestamp >>> 32));
+ return result;
+ }
- public int hashCode() {
- int result = id;
- result = 31 * result + (int) (timestamp ^ (timestamp >>> 32));
- return result;
- }
-
- public String toString() {
- return "SequenceIdRevisionEntity(id = " + id + ", revisionDate = " + DateFormat.getDateTimeInstance().format(getRevisionDate()) + ")";
- }
+ @Override
+ public String toString() {
+ return "SequenceIdRevisionEntity(id = " + id + ", revisionDate = " + DateFormat.getDateTimeInstance().format(
+ getRevisionDate()
+ ) + ")";
+ }
}
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 889cd723cb..3c037b6ffb 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
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2008, 2013, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -23,14 +23,14 @@
*/
package org.hibernate.envers.enhanced;
-import java.util.HashSet;
-import java.util.Set;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.MappedSuperclass;
+import java.util.HashSet;
+import java.util.Set;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
@@ -40,45 +40,60 @@ import org.hibernate.envers.ModifiedEntityNames;
* Extension of standard {@link SequenceIdRevisionEntity} that allows tracking entity names changed in each revision.
* This revision entity is implicitly used when {@code org.hibernate.envers.track_entities_changed_in_revision}
* parameter is set to {@code true}.
+ *
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
*/
@MappedSuperclass
public class SequenceIdTrackingModifiedEntitiesRevisionEntity extends SequenceIdRevisionEntity {
- @ElementCollection(fetch = FetchType.EAGER)
- @JoinTable(name = "REVCHANGES", joinColumns = @JoinColumn(name = "REV"))
- @Column(name = "ENTITYNAME")
- @Fetch(FetchMode.JOIN)
- @ModifiedEntityNames
- private Set modifiedEntityNames = new HashSet();
+ @ElementCollection(fetch = FetchType.EAGER)
+ @JoinTable(name = "REVCHANGES", joinColumns = @JoinColumn(name = "REV"))
+ @Column(name = "ENTITYNAME")
+ @Fetch(FetchMode.JOIN)
+ @ModifiedEntityNames
+ private Set modifiedEntityNames = new HashSet();
- public Set getModifiedEntityNames() {
- return modifiedEntityNames;
- }
+ @SuppressWarnings("UnusedDeclaration")
+ public Set getModifiedEntityNames() {
+ return modifiedEntityNames;
+ }
- public void setModifiedEntityNames(Set modifiedEntityNames) {
- this.modifiedEntityNames = modifiedEntityNames;
- }
+ @SuppressWarnings("UnusedDeclaration")
+ public void setModifiedEntityNames(Set modifiedEntityNames) {
+ this.modifiedEntityNames = modifiedEntityNames;
+ }
- public boolean equals(Object o) {
- if (this == o) return true;
- if (!(o instanceof SequenceIdTrackingModifiedEntitiesRevisionEntity )) return false;
- if (!super.equals(o)) return false;
+ @Override
+ public boolean equals(Object o) {
+ if ( this == o ) {
+ return true;
+ }
+ if ( !(o instanceof SequenceIdTrackingModifiedEntitiesRevisionEntity) ) {
+ return false;
+ }
+ if ( !super.equals( o ) ) {
+ return false;
+ }
- SequenceIdTrackingModifiedEntitiesRevisionEntity that = (SequenceIdTrackingModifiedEntitiesRevisionEntity) o;
+ final SequenceIdTrackingModifiedEntitiesRevisionEntity that = (SequenceIdTrackingModifiedEntitiesRevisionEntity) o;
- if (modifiedEntityNames != null ? !modifiedEntityNames.equals(that.modifiedEntityNames)
- : that.modifiedEntityNames != null) return false;
+ if ( modifiedEntityNames == null ) {
+ return that.modifiedEntityNames == null;
+ }
+ else {
+ return modifiedEntityNames.equals( that.modifiedEntityNames );
+ }
+ }
- return true;
- }
+ @Override
+ public int hashCode() {
+ int result = super.hashCode();
+ result = 31 * result + (modifiedEntityNames != null ? modifiedEntityNames.hashCode() : 0);
+ return result;
+ }
- public int hashCode() {
- int result = super.hashCode();
- result = 31 * result + (modifiedEntityNames != null ? modifiedEntityNames.hashCode() : 0);
- return result;
- }
-
- public String toString() {
- return "SequenceIdTrackingModifiedEntitiesRevisionEntity(" + super.toString() + ", modifiedEntityNames = " + modifiedEntityNames + ")";
- }
+ @Override
+ public String toString() {
+ return "SequenceIdTrackingModifiedEntitiesRevisionEntity(" + super.toString()
+ + ", modifiedEntityNames = " + modifiedEntityNames + ")";
+ }
}
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/BaseEnversCollectionEventListener.java b/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/BaseEnversCollectionEventListener.java
index b8fe96286f..ab7a00547a 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/BaseEnversCollectionEventListener.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/BaseEnversCollectionEventListener.java
@@ -57,40 +57,40 @@ public abstract class BaseEnversCollectionEventListener extends BaseEnversEventL
super( enversConfiguration );
}
- protected final CollectionEntry getCollectionEntry(AbstractCollectionEvent event) {
- return event.getSession().getPersistenceContext().getCollectionEntry(event.getCollection());
- }
+ protected final CollectionEntry getCollectionEntry(AbstractCollectionEvent event) {
+ return event.getSession().getPersistenceContext().getCollectionEntry( event.getCollection() );
+ }
- protected final void onCollectionAction(
+ protected final void onCollectionAction(
AbstractCollectionEvent event,
PersistentCollection newColl,
Serializable oldColl,
CollectionEntry collectionEntry) {
- if ( shouldGenerateRevision( event ) ) {
- checkIfTransactionInProgress(event.getSession());
-
- AuditProcess auditProcess = getAuditConfiguration().getSyncManager().get(event.getSession());
+ if ( shouldGenerateRevision( event ) ) {
+ checkIfTransactionInProgress( event.getSession() );
- String entityName = event.getAffectedOwnerEntityName();
- String ownerEntityName = ((AbstractCollectionPersister) collectionEntry.getLoadedPersister()).getOwnerEntityName();
- String referencingPropertyName = collectionEntry.getRole().substring(ownerEntityName.length() + 1);
+ final AuditProcess auditProcess = getAuditConfiguration().getSyncManager().get( event.getSession() );
- // Checking if this is not a "fake" many-to-one bidirectional relation. The relation description may be
- // null in case of collections of non-entities.
- RelationDescription rd = searchForRelationDescription( entityName, referencingPropertyName );
- if ( rd != null && rd.getMappedByPropertyName() != null ) {
- generateFakeBidirecationalRelationWorkUnits(
+ final String entityName = event.getAffectedOwnerEntityName();
+ final String ownerEntityName = ((AbstractCollectionPersister) collectionEntry.getLoadedPersister()).getOwnerEntityName();
+ final String referencingPropertyName = collectionEntry.getRole().substring( ownerEntityName.length() + 1 );
+
+ // Checking if this is not a "fake" many-to-one bidirectional relation. The relation description may be
+ // null in case of collections of non-entities.
+ final RelationDescription rd = searchForRelationDescription( entityName, referencingPropertyName );
+ if ( rd != null && rd.getMappedByPropertyName() != null ) {
+ generateFakeBidirecationalRelationWorkUnits(
auditProcess,
newColl,
oldColl,
entityName,
- referencingPropertyName,
+ referencingPropertyName,
event,
rd
);
- }
+ }
else {
- PersistentCollectionChangeWorkUnit workUnit = new PersistentCollectionChangeWorkUnit(
+ final PersistentCollectionChangeWorkUnit workUnit = new PersistentCollectionChangeWorkUnit(
event.getSession(),
entityName,
getAuditConfiguration(),
@@ -102,9 +102,9 @@ public abstract class BaseEnversCollectionEventListener extends BaseEnversEventL
);
auditProcess.addWorkUnit( workUnit );
- if (workUnit.containsWork()) {
- // There are some changes: a revision needs also be generated for the collection owner
- auditProcess.addWorkUnit(
+ if ( workUnit.containsWork() ) {
+ // There are some changes: a revision needs also be generated for the collection owner
+ auditProcess.addWorkUnit(
new CollectionChangeWorkUnit(
event.getSession(),
event.getAffectedOwnerEntityName(),
@@ -115,15 +115,17 @@ public abstract class BaseEnversCollectionEventListener extends BaseEnversEventL
)
);
- generateBidirectionalCollectionChangeWorkUnits( auditProcess, event, workUnit, rd );
- }
- }
- }
- }
+ generateBidirectionalCollectionChangeWorkUnits( auditProcess, event, workUnit, rd );
+ }
+ }
+ }
+ }
/**
* Forces persistent collection initialization.
+ *
* @param event Collection event.
+ *
* @return Stored snapshot.
*/
protected Serializable initializeCollection(AbstractCollectionEvent event) {
@@ -133,7 +135,9 @@ public abstract class BaseEnversCollectionEventListener extends BaseEnversEventL
/**
* Checks whether modification of not-owned relation field triggers new revision and owner entity is versioned.
+ *
* @param event Collection event.
+ *
* @return {@code true} if revision based on given event should be generated, {@code false} otherwise.
*/
protected boolean shouldGenerateRevision(AbstractCollectionEvent event) {
@@ -142,27 +146,27 @@ public abstract class BaseEnversCollectionEventListener extends BaseEnversEventL
&& getAuditConfiguration().getEntCfg().isVersioned( entityName );
}
- /**
- * Looks up a relation description corresponding to the given property in the given entity. If no description is
- * found in the given entity, the parent entity is checked (so that inherited relations work).
+ /**
+ * Looks up a relation description corresponding to the given property in the given entity. If no description is
+ * found in the given entity, the parent entity is checked (so that inherited relations work).
*
- * @param entityName Name of the entity, in which to start looking.
- * @param referencingPropertyName The name of the property.
- *
- * @return A found relation description corresponding to the given entity or {@code null}, if no description can
- * be found.
- */
- private RelationDescription searchForRelationDescription(String entityName, String referencingPropertyName) {
- EntityConfiguration configuration = getAuditConfiguration().getEntCfg().get( entityName );
- RelationDescription rd = configuration.getRelationDescription(referencingPropertyName);
- if ( rd == null && configuration.getParentEntityName() != null ) {
- return searchForRelationDescription( configuration.getParentEntityName(), referencingPropertyName );
- }
+ * @param entityName Name of the entity, in which to start looking.
+ * @param referencingPropertyName The name of the property.
+ *
+ * @return A found relation description corresponding to the given entity or {@code null}, if no description can
+ * be found.
+ */
+ private RelationDescription searchForRelationDescription(String entityName, String referencingPropertyName) {
+ final EntityConfiguration configuration = getAuditConfiguration().getEntCfg().get( entityName );
+ final RelationDescription rd = configuration.getRelationDescription( referencingPropertyName );
+ if ( rd == null && configuration.getParentEntityName() != null ) {
+ return searchForRelationDescription( configuration.getParentEntityName(), referencingPropertyName );
+ }
- return rd;
- }
+ return rd;
+ }
- private void generateFakeBidirecationalRelationWorkUnits(
+ private void generateFakeBidirecationalRelationWorkUnits(
AuditProcess auditProcess,
PersistentCollection newColl,
Serializable oldColl,
@@ -170,41 +174,47 @@ public abstract class BaseEnversCollectionEventListener extends BaseEnversEventL
String referencingPropertyName,
AbstractCollectionEvent event,
RelationDescription rd) {
- // First computing the relation changes
- List collectionChanges = getAuditConfiguration()
+ // First computing the relation changes
+ final List collectionChanges = getAuditConfiguration()
.getEntCfg()
.get( collectionEntityName )
.getPropertyMapper()
- .mapCollectionChanges( event.getSession(), referencingPropertyName, newColl, oldColl, event.getAffectedOwnerIdOrNull() );
+ .mapCollectionChanges(
+ event.getSession(),
+ referencingPropertyName,
+ newColl,
+ oldColl,
+ event.getAffectedOwnerIdOrNull()
+ );
- // Getting the id mapper for the related entity, as the work units generated will corrspond to the related
- // entities.
- String relatedEntityName = rd.getToEntityName();
- IdMapper relatedIdMapper = getAuditConfiguration().getEntCfg().get(relatedEntityName).getIdMapper();
+ // Getting the id mapper for the related entity, as the work units generated will correspond to the related
+ // entities.
+ final String relatedEntityName = rd.getToEntityName();
+ final IdMapper relatedIdMapper = getAuditConfiguration().getEntCfg().get( relatedEntityName ).getIdMapper();
- // For each collection change, generating the bidirectional work unit.
- for ( PersistentCollectionChangeData changeData : collectionChanges ) {
- Object relatedObj = changeData.getChangedElement();
- Serializable relatedId = (Serializable) relatedIdMapper.mapToIdFromEntity(relatedObj);
- RevisionType revType = (RevisionType) changeData.getData().get(
+ // For each collection change, generating the bidirectional work unit.
+ for ( PersistentCollectionChangeData changeData : collectionChanges ) {
+ final Object relatedObj = changeData.getChangedElement();
+ final Serializable relatedId = (Serializable) relatedIdMapper.mapToIdFromEntity( relatedObj );
+ final RevisionType revType = (RevisionType) changeData.getData().get(
getAuditConfiguration().getAuditEntCfg().getRevisionTypePropName()
);
- // This can be different from relatedEntityName, in case of inheritance (the real entity may be a subclass
- // of relatedEntityName).
- String realRelatedEntityName = event.getSession().bestGuessEntityName(relatedObj);
+ // This can be different from relatedEntityName, in case of inheritance (the real entity may be a subclass
+ // of relatedEntityName).
+ final String realRelatedEntityName = event.getSession().bestGuessEntityName( relatedObj );
- // By default, the nested work unit is a collection change work unit.
- AuditWorkUnit nestedWorkUnit = new CollectionChangeWorkUnit(
+ // By default, the nested work unit is a collection change work unit.
+ final AuditWorkUnit nestedWorkUnit = new CollectionChangeWorkUnit(
event.getSession(),
realRelatedEntityName,
rd.getMappedByPropertyName(),
getAuditConfiguration(),
- relatedId,
+ relatedId,
relatedObj
);
- auditProcess.addWorkUnit(
+ auditProcess.addWorkUnit(
new FakeBidirectionalRelationWorkUnit(
event.getSession(),
realRelatedEntityName,
@@ -218,10 +228,10 @@ public abstract class BaseEnversCollectionEventListener extends BaseEnversEventL
nestedWorkUnit
)
);
- }
+ }
- // We also have to generate a collection change work unit for the owning entity.
- auditProcess.addWorkUnit(
+ // We also have to generate a collection change work unit for the owning entity.
+ auditProcess.addWorkUnit(
new CollectionChangeWorkUnit(
event.getSession(),
collectionEntityName,
@@ -231,44 +241,47 @@ public abstract class BaseEnversCollectionEventListener extends BaseEnversEventL
event.getAffectedOwnerOrNull()
)
);
- }
+ }
- private void generateBidirectionalCollectionChangeWorkUnits(
+ private void generateBidirectionalCollectionChangeWorkUnits(
AuditProcess auditProcess,
AbstractCollectionEvent event,
PersistentCollectionChangeWorkUnit workUnit,
RelationDescription rd) {
- // Checking if this is enabled in configuration ...
- if ( ! getAuditConfiguration().getGlobalCfg().isGenerateRevisionsForCollections() ) {
- return;
- }
+ // Checking if this is enabled in configuration ...
+ if ( !getAuditConfiguration().getGlobalCfg().isGenerateRevisionsForCollections() ) {
+ return;
+ }
- // Checking if this is not a bidirectional relation - then, a revision needs also be generated for
- // the other side of the relation.
- // relDesc can be null if this is a collection of simple values (not a relation).
- if ( rd != null && rd.isBidirectional() ) {
- String relatedEntityName = rd.getToEntityName();
- IdMapper relatedIdMapper = getAuditConfiguration().getEntCfg().get( relatedEntityName ).getIdMapper();
+ // Checking if this is not a bidirectional relation - then, a revision needs also be generated for
+ // the other side of the relation.
+ // relDesc can be null if this is a collection of simple values (not a relation).
+ if ( rd != null && rd.isBidirectional() ) {
+ final String relatedEntityName = rd.getToEntityName();
+ final IdMapper relatedIdMapper = getAuditConfiguration().getEntCfg().get( relatedEntityName ).getIdMapper();
- Set toPropertyNames = getAuditConfiguration().getEntCfg()
- .getToPropertyNames(event.getAffectedOwnerEntityName(), rd.getFromPropertyName(), relatedEntityName);
- String toPropertyName = toPropertyNames.iterator().next();
+ final Set toPropertyNames = getAuditConfiguration().getEntCfg().getToPropertyNames(
+ event.getAffectedOwnerEntityName(),
+ rd.getFromPropertyName(),
+ relatedEntityName
+ );
+ final String toPropertyName = toPropertyNames.iterator().next();
- for ( PersistentCollectionChangeData changeData : workUnit.getCollectionChanges() ) {
- Object relatedObj = changeData.getChangedElement();
- Serializable relatedId = (Serializable) relatedIdMapper.mapToIdFromEntity( relatedObj );
+ for ( PersistentCollectionChangeData changeData : workUnit.getCollectionChanges() ) {
+ final Object relatedObj = changeData.getChangedElement();
+ final Serializable relatedId = (Serializable) relatedIdMapper.mapToIdFromEntity( relatedObj );
- auditProcess.addWorkUnit(
+ auditProcess.addWorkUnit(
new CollectionChangeWorkUnit(
event.getSession(),
- event.getSession().bestGuessEntityName(relatedObj),
+ event.getSession().bestGuessEntityName( relatedObj ),
toPropertyName,
getAuditConfiguration(),
relatedId,
relatedObj
)
);
- }
- }
- }
+ }
+ }
+ }
}
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/BaseEnversEventListener.java b/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/BaseEnversEventListener.java
index 6e4e4e2408..f65fcef4a9 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/BaseEnversEventListener.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/BaseEnversEventListener.java
@@ -66,72 +66,84 @@ public abstract class BaseEnversEventListener implements EnversListener {
Object[] oldState,
SessionImplementor session) {
// Checking if this is enabled in configuration ...
- if ( ! enversConfiguration.getGlobalCfg().isGenerateRevisionsForCollections() ) {
+ if ( !enversConfiguration.getGlobalCfg().isGenerateRevisionsForCollections() ) {
return;
}
// Checks every property of the entity, if it is an "owned" to-one relation to another entity.
// If the value of that property changed, and the relation is bi-directional, a new revision
// for the related entity is generated.
- String[] propertyNames = entityPersister.getPropertyNames();
+ final String[] propertyNames = entityPersister.getPropertyNames();
- for ( int i=0; i toPropertyNames = enversConfiguration.getEntCfg()
- .getToPropertyNames(fromEntityName, relDesc.getFromPropertyName(), toEntityName);
- String toPropertyName = toPropertyNames.iterator().next();
+ final Set toPropertyNames = enversConfiguration.getEntCfg().getToPropertyNames(
+ fromEntityName,
+ relDesc.getFromPropertyName(),
+ toEntityName
+ );
+ final String toPropertyName = toPropertyNames.iterator().next();
- auditProcess.addWorkUnit(new CollectionChangeWorkUnit(session, toEntityName,
- toPropertyName, enversConfiguration, id, value));
+ auditProcess.addWorkUnit(
+ new CollectionChangeWorkUnit(
+ session, toEntityName,
+ toPropertyName, enversConfiguration, id, value
+ )
+ );
}
- protected void checkIfTransactionInProgress(SessionImplementor session) {
- if (!session.isTransactionInProgress()) {
- // Historical data would not be flushed to audit tables if outside of active transaction
- // (AuditProcess#doBeforeTransactionCompletion(SessionImplementor) not executed).
- throw new AuditException("Unable to create revision because of non-active transaction");
- }
- }
+ protected void checkIfTransactionInProgress(SessionImplementor session) {
+ if ( !session.isTransactionInProgress() ) {
+ // Historical data would not be flushed to audit tables if outside of active transaction
+ // (AuditProcess#doBeforeTransactionCompletion(SessionImplementor) not executed).
+ throw new AuditException( "Unable to create revision because of non-active transaction" );
+ }
+ }
}
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversIntegrator.java b/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversIntegrator.java
index 36abe0f220..6afdc5e10f 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversIntegrator.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversIntegrator.java
@@ -43,8 +43,15 @@ import org.hibernate.service.spi.SessionFactoryServiceRegistry;
* @author Steve Ebersole
*/
public class EnversIntegrator implements Integrator {
- private static final CoreMessageLogger LOG = Logger.getMessageLogger( CoreMessageLogger.class, EnversIntegrator.class.getName() );
+ private static final CoreMessageLogger LOG = Logger.getMessageLogger(
+ CoreMessageLogger.class,
+ EnversIntegrator.class.getName()
+ );
+ /**
+ * The name of a configuration setting that can be used to control whether auto registration of envers listeners
+ * should happen or not. Default is true
+ */
public static final String AUTO_REGISTER = "hibernate.listeners.envers.autoRegister";
@Override
@@ -52,25 +59,55 @@ public class EnversIntegrator implements Integrator {
Configuration configuration,
SessionFactoryImplementor sessionFactory,
SessionFactoryServiceRegistry serviceRegistry) {
- final boolean autoRegister = ConfigurationHelper.getBoolean( AUTO_REGISTER, configuration.getProperties(), true );
+ final boolean autoRegister = ConfigurationHelper.getBoolean(
+ AUTO_REGISTER,
+ configuration.getProperties(),
+ true
+ );
if ( !autoRegister ) {
LOG.debug( "Skipping Envers listener auto registration" );
return;
}
- EventListenerRegistry listenerRegistry = serviceRegistry.getService( EventListenerRegistry.class );
+ final EventListenerRegistry listenerRegistry = serviceRegistry.getService( EventListenerRegistry.class );
listenerRegistry.addDuplicationStrategy( EnversListenerDuplicationStrategy.INSTANCE );
- final AuditConfiguration enversConfiguration = AuditConfiguration.getFor( configuration, serviceRegistry.getService( ClassLoaderService.class ) );
+ final AuditConfiguration enversConfiguration = AuditConfiguration.getFor(
+ configuration,
+ serviceRegistry.getService(
+ ClassLoaderService.class
+ )
+ );
- if (enversConfiguration.getEntCfg().hasAuditedEntities()) {
- listenerRegistry.appendListeners( EventType.POST_DELETE, new EnversPostDeleteEventListenerImpl( enversConfiguration ) );
- listenerRegistry.appendListeners( EventType.POST_INSERT, new EnversPostInsertEventListenerImpl( enversConfiguration ) );
- listenerRegistry.appendListeners( EventType.POST_UPDATE, new EnversPostUpdateEventListenerImpl( enversConfiguration ) );
- listenerRegistry.appendListeners( EventType.POST_COLLECTION_RECREATE, new EnversPostCollectionRecreateEventListenerImpl( enversConfiguration ) );
- listenerRegistry.appendListeners( EventType.PRE_COLLECTION_REMOVE, new EnversPreCollectionRemoveEventListenerImpl( enversConfiguration ) );
- listenerRegistry.appendListeners( EventType.PRE_COLLECTION_UPDATE, new EnversPreCollectionUpdateEventListenerImpl( enversConfiguration ) );
- }
+ if ( enversConfiguration.getEntCfg().hasAuditedEntities() ) {
+ listenerRegistry.appendListeners(
+ EventType.POST_DELETE, new EnversPostDeleteEventListenerImpl(
+ enversConfiguration
+ )
+ );
+ listenerRegistry.appendListeners(
+ EventType.POST_INSERT, new EnversPostInsertEventListenerImpl(
+ enversConfiguration
+ )
+ );
+ listenerRegistry.appendListeners(
+ EventType.POST_UPDATE, new EnversPostUpdateEventListenerImpl(
+ enversConfiguration
+ )
+ );
+ listenerRegistry.appendListeners(
+ EventType.POST_COLLECTION_RECREATE,
+ new EnversPostCollectionRecreateEventListenerImpl( enversConfiguration )
+ );
+ listenerRegistry.appendListeners(
+ EventType.PRE_COLLECTION_REMOVE,
+ new EnversPreCollectionRemoveEventListenerImpl( enversConfiguration )
+ );
+ listenerRegistry.appendListeners(
+ EventType.PRE_COLLECTION_UPDATE,
+ new EnversPreCollectionUpdateEventListenerImpl( enversConfiguration )
+ );
+ }
}
@Override
@@ -84,9 +121,10 @@ public class EnversIntegrator implements Integrator {
* @see org.hibernate.integrator.spi.Integrator#integrate(org.hibernate.metamodel.source.MetadataImplementor, org.hibernate.engine.spi.SessionFactoryImplementor, org.hibernate.service.spi.SessionFactoryServiceRegistry)
*/
@Override
- public void integrate( MetadataImplementor metadata,
- SessionFactoryImplementor sessionFactory,
- SessionFactoryServiceRegistry serviceRegistry ) {
- // TODO: implement
+ public void integrate(
+ MetadataImplementor metadata,
+ SessionFactoryImplementor sessionFactory,
+ SessionFactoryServiceRegistry serviceRegistry) {
+ // TODO: implement
}
}
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversListener.java b/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversListener.java
index 9cd8086635..cd8f36ef90 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversListener.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversListener.java
@@ -31,5 +31,10 @@ import org.hibernate.envers.configuration.spi.AuditConfiguration;
* @author Steve Ebersole
*/
public interface EnversListener {
+ /**
+ * Get the Envers AuditConfiguration
+ *
+ * @return The Envers AuditConfiguration
+ */
public AuditConfiguration getAuditConfiguration();
}
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversListenerDuplicationStrategy.java b/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversListenerDuplicationStrategy.java
index d5442adc83..a4a3c4b55d 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversListenerDuplicationStrategy.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversListenerDuplicationStrategy.java
@@ -31,6 +31,9 @@ import org.hibernate.event.service.spi.DuplicationStrategy;
* @author Steve Ebersole
*/
public class EnversListenerDuplicationStrategy implements DuplicationStrategy {
+ /**
+ * Singleton access
+ */
public static final EnversListenerDuplicationStrategy INSTANCE = new EnversListenerDuplicationStrategy();
@Override
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversPostCollectionRecreateEventListenerImpl.java b/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversPostCollectionRecreateEventListenerImpl.java
index 64c615dc4b..0a88a50a05 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversPostCollectionRecreateEventListenerImpl.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversPostCollectionRecreateEventListenerImpl.java
@@ -29,12 +29,14 @@ import org.hibernate.event.spi.PostCollectionRecreateEvent;
import org.hibernate.event.spi.PostCollectionRecreateEventListener;
/**
+ * Envers-specific collection recreation event listener
+ *
* @author Adam Warski (adam at warski dot org)
* @author HernпїЅn Chanfreau
* @author Steve Ebersole
*/
public class EnversPostCollectionRecreateEventListenerImpl
- extends BaseEnversCollectionEventListener
+ extends BaseEnversCollectionEventListener
implements PostCollectionRecreateEventListener {
protected EnversPostCollectionRecreateEventListenerImpl(AuditConfiguration enversConfiguration) {
@@ -43,9 +45,9 @@ public class EnversPostCollectionRecreateEventListenerImpl
@Override
public void onPostRecreateCollection(PostCollectionRecreateEvent event) {
- CollectionEntry collectionEntry = getCollectionEntry( event );
- if ( ! collectionEntry.getLoadedPersister().isInverse() ) {
- onCollectionAction( event, event.getCollection(), null, collectionEntry );
- }
+ final CollectionEntry collectionEntry = getCollectionEntry( event );
+ if ( !collectionEntry.getLoadedPersister().isInverse() ) {
+ onCollectionAction( event, event.getCollection(), null, collectionEntry );
+ }
}
}
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversPostDeleteEventListenerImpl.java b/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversPostDeleteEventListenerImpl.java
index 9782e25d79..79cacd10e3 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversPostDeleteEventListenerImpl.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversPostDeleteEventListenerImpl.java
@@ -32,6 +32,8 @@ import org.hibernate.event.spi.PostDeleteEventListener;
import org.hibernate.persister.entity.EntityPersister;
/**
+ * Envers-specific entity (post) deletion event listener
+ *
* @author Adam Warski (adam at warski dot org)
* @author HernпїЅn Chanfreau
* @author Steve Ebersole
@@ -43,30 +45,30 @@ public class EnversPostDeleteEventListenerImpl extends BaseEnversEventListener i
@Override
public void onPostDelete(PostDeleteEvent event) {
- String entityName = event.getPersister().getEntityName();
+ final String entityName = event.getPersister().getEntityName();
- if ( getAuditConfiguration().getEntCfg().isVersioned( entityName ) ) {
- checkIfTransactionInProgress(event.getSession());
+ if ( getAuditConfiguration().getEntCfg().isVersioned( entityName ) ) {
+ checkIfTransactionInProgress( event.getSession() );
- AuditProcess auditProcess = getAuditConfiguration().getSyncManager().get( event.getSession() );
+ final AuditProcess auditProcess = getAuditConfiguration().getSyncManager().get( event.getSession() );
- AuditWorkUnit workUnit = new DelWorkUnit(
+ final AuditWorkUnit workUnit = new DelWorkUnit(
event.getSession(),
event.getPersister().getEntityName(),
getAuditConfiguration(),
- event.getId(),
+ event.getId(),
event.getPersister(),
event.getDeletedState()
);
- auditProcess.addWorkUnit( workUnit );
+ auditProcess.addWorkUnit( workUnit );
- if ( workUnit.containsWork() ) {
- generateBidirectionalCollectionChangeWorkUnits(
+ if ( workUnit.containsWork() ) {
+ generateBidirectionalCollectionChangeWorkUnits(
auditProcess,
event.getPersister(),
entityName,
null,
- event.getDeletedState(),
+ event.getDeletedState(),
event.getSession()
);
}
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversPostInsertEventListenerImpl.java b/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversPostInsertEventListenerImpl.java
index e0e8d48b2c..db3c1d1853 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversPostInsertEventListenerImpl.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversPostInsertEventListenerImpl.java
@@ -32,44 +32,47 @@ import org.hibernate.event.spi.PostInsertEventListener;
import org.hibernate.persister.entity.EntityPersister;
/**
+ * Envers-specific entity (post) insertion event listener
+ *
* @author Adam Warski (adam at warski dot org)
* @author HernпїЅn Chanfreau
* @author Steve Ebersole
*/
public class EnversPostInsertEventListenerImpl extends BaseEnversEventListener implements PostInsertEventListener {
- public EnversPostInsertEventListenerImpl(AuditConfiguration enversConfiguration) {
+ protected EnversPostInsertEventListenerImpl(AuditConfiguration enversConfiguration) {
super( enversConfiguration );
}
- public void onPostInsert(PostInsertEvent event) {
- String entityName = event.getPersister().getEntityName();
+ @Override
+ public void onPostInsert(PostInsertEvent event) {
+ final String entityName = event.getPersister().getEntityName();
- if ( getAuditConfiguration().getEntCfg().isVersioned( entityName ) ) {
- checkIfTransactionInProgress(event.getSession());
+ if ( getAuditConfiguration().getEntCfg().isVersioned( entityName ) ) {
+ checkIfTransactionInProgress( event.getSession() );
- AuditProcess auditProcess = getAuditConfiguration().getSyncManager().get(event.getSession());
+ final AuditProcess auditProcess = getAuditConfiguration().getSyncManager().get( event.getSession() );
- AuditWorkUnit workUnit = new AddWorkUnit(
+ final AuditWorkUnit workUnit = new AddWorkUnit(
event.getSession(),
event.getPersister().getEntityName(),
getAuditConfiguration(),
- event.getId(),
+ event.getId(),
event.getPersister(),
event.getState()
);
- auditProcess.addWorkUnit( workUnit );
+ auditProcess.addWorkUnit( workUnit );
- if ( workUnit.containsWork() ) {
- generateBidirectionalCollectionChangeWorkUnits(
+ if ( workUnit.containsWork() ) {
+ generateBidirectionalCollectionChangeWorkUnits(
auditProcess,
event.getPersister(),
entityName,
event.getState(),
- null,
+ null,
event.getSession()
);
- }
- }
+ }
+ }
}
@Override
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversPostUpdateEventListenerImpl.java b/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversPostUpdateEventListenerImpl.java
index ea399a5c63..956bf01a38 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversPostUpdateEventListenerImpl.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversPostUpdateEventListenerImpl.java
@@ -32,6 +32,8 @@ import org.hibernate.event.spi.PostUpdateEventListener;
import org.hibernate.persister.entity.EntityPersister;
/**
+ * Envers-specific entity (post) update event listener
+ *
* @author Adam Warski (adam at warski dot org)
* @author HernпїЅn Chanfreau
* @author Steve Ebersole
@@ -43,43 +45,41 @@ public class EnversPostUpdateEventListenerImpl extends BaseEnversEventListener i
@Override
public void onPostUpdate(PostUpdateEvent event) {
- String entityName = event.getPersister().getEntityName();
+ final String entityName = event.getPersister().getEntityName();
- if ( getAuditConfiguration().getEntCfg().isVersioned(entityName) ) {
- checkIfTransactionInProgress(event.getSession());
-
- AuditProcess auditProcess = getAuditConfiguration().getSyncManager().get(event.getSession());
+ if ( getAuditConfiguration().getEntCfg().isVersioned( entityName ) ) {
+ checkIfTransactionInProgress( event.getSession() );
+ final AuditProcess auditProcess = getAuditConfiguration().getSyncManager().get( event.getSession() );
final Object[] newDbState = postUpdateDBState( event );
-
- AuditWorkUnit workUnit = new ModWorkUnit(
+ final AuditWorkUnit workUnit = new ModWorkUnit(
event.getSession(),
event.getPersister().getEntityName(),
getAuditConfiguration(),
- event.getId(),
+ event.getId(),
event.getPersister(),
newDbState,
event.getOldState()
);
- auditProcess.addWorkUnit( workUnit );
+ auditProcess.addWorkUnit( workUnit );
- if ( workUnit.containsWork() ) {
- generateBidirectionalCollectionChangeWorkUnits(
+ if ( workUnit.containsWork() ) {
+ generateBidirectionalCollectionChangeWorkUnits(
auditProcess,
event.getPersister(),
entityName,
newDbState,
- event.getOldState(),
+ event.getOldState(),
event.getSession()
);
- }
- }
+ }
+ }
}
private Object[] postUpdateDBState(PostUpdateEvent event) {
- Object[] newDbState = event.getState().clone();
+ final Object[] newDbState = event.getState().clone();
if ( event.getOldState() != null ) {
- EntityPersister entityPersister = event.getPersister();
+ final EntityPersister entityPersister = event.getPersister();
for ( int i = 0; i < entityPersister.getPropertyNames().length; ++i ) {
if ( !entityPersister.getPropertyUpdateability()[i] ) {
// Assuming that PostUpdateEvent#getOldState() returns database state of the record before modification.
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversPreCollectionRemoveEventListenerImpl.java b/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversPreCollectionRemoveEventListenerImpl.java
index aa4204f99a..61a3c1a5ca 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversPreCollectionRemoveEventListenerImpl.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversPreCollectionRemoveEventListenerImpl.java
@@ -31,6 +31,8 @@ import org.hibernate.event.spi.PreCollectionRemoveEvent;
import org.hibernate.event.spi.PreCollectionRemoveEventListener;
/**
+ * Envers-specific collection removal event listener
+ *
* @author Adam Warski (adam at warski dot org)
* @author HernпїЅn Chanfreau
* @author Steve Ebersole
@@ -46,14 +48,14 @@ public class EnversPreCollectionRemoveEventListenerImpl
@Override
public void onPreRemoveCollection(PreCollectionRemoveEvent event) {
- CollectionEntry collectionEntry = getCollectionEntry( event );
- if ( collectionEntry != null && !collectionEntry.getLoadedPersister().isInverse() ) {
+ final CollectionEntry collectionEntry = getCollectionEntry( event );
+ if ( collectionEntry != null && !collectionEntry.getLoadedPersister().isInverse() ) {
Serializable oldColl = collectionEntry.getSnapshot();
if ( !event.getCollection().wasInitialized() && shouldGenerateRevision( event ) ) {
// In case of uninitialized collection we need a fresh snapshot to properly calculate audit data.
oldColl = initializeCollection( event );
}
- onCollectionAction( event, null, oldColl, collectionEntry );
- }
+ onCollectionAction( event, null, oldColl, collectionEntry );
+ }
}
}
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversPreCollectionUpdateEventListenerImpl.java b/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversPreCollectionUpdateEventListenerImpl.java
index a088c2c891..b416349ce6 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversPreCollectionUpdateEventListenerImpl.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversPreCollectionUpdateEventListenerImpl.java
@@ -29,6 +29,8 @@ import org.hibernate.event.spi.PreCollectionUpdateEvent;
import org.hibernate.event.spi.PreCollectionUpdateEventListener;
/**
+ * Envers-specific collection update event listener
+ *
* @author Adam Warski (adam at warski dot org)
* @author HernпїЅn Chanfreau
* @author Steve Ebersole
@@ -43,9 +45,9 @@ public class EnversPreCollectionUpdateEventListenerImpl
@Override
public void onPreUpdateCollection(PreCollectionUpdateEvent event) {
- CollectionEntry collectionEntry = getCollectionEntry( event );
- if ( ! collectionEntry.getLoadedPersister().isInverse() ) {
- onCollectionAction( event, event.getCollection(), collectionEntry.getSnapshot(), collectionEntry );
- }
+ final CollectionEntry collectionEntry = getCollectionEntry( event );
+ if ( !collectionEntry.getLoadedPersister().isInverse() ) {
+ onCollectionAction( event, event.getCollection(), collectionEntry.getSnapshot(), collectionEntry );
+ }
}
}
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/exception/AuditException.java b/hibernate-envers/src/main/java/org/hibernate/envers/exception/AuditException.java
index a92d3c2b28..d0407c3825 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/exception/AuditException.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/exception/AuditException.java
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2008, 2013, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -22,6 +22,7 @@
* Boston, MA 02110-1301 USA
*/
package org.hibernate.envers.exception;
+
import org.hibernate.HibernateException;
/**
@@ -31,14 +32,14 @@ public class AuditException extends HibernateException {
private static final long serialVersionUID = 4306480965630972168L;
public AuditException(String message) {
- super(message);
- }
+ super( message );
+ }
- public AuditException(String message, Throwable cause) {
- super(message, cause);
- }
+ public AuditException(String message, Throwable cause) {
+ super( message, cause );
+ }
- public AuditException(Throwable cause) {
- super(cause);
- }
+ public AuditException(Throwable cause) {
+ super( cause );
+ }
}
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/exception/NotAuditedException.java b/hibernate-envers/src/main/java/org/hibernate/envers/exception/NotAuditedException.java
index afafd43952..d086ba0acf 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/exception/NotAuditedException.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/exception/NotAuditedException.java
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2013, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -29,15 +29,15 @@ package org.hibernate.envers.exception;
*/
public class NotAuditedException extends AuditException {
private static final long serialVersionUID = 4809674577449455510L;
-
- private final String entityName;
+
+ private final String entityName;
public NotAuditedException(String entityName, String message) {
- super(message);
- this.entityName = entityName;
- }
+ super( message );
+ this.entityName = entityName;
+ }
- public String getEntityName() {
- return entityName;
- }
+ public String getEntityName() {
+ return entityName;
+ }
}
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/exception/RevisionDoesNotExistException.java b/hibernate-envers/src/main/java/org/hibernate/envers/exception/RevisionDoesNotExistException.java
index eda609bf8d..277e547ca4 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/exception/RevisionDoesNotExistException.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/exception/RevisionDoesNotExistException.java
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2013, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -22,6 +22,7 @@
* Boston, MA 02110-1301 USA
*/
package org.hibernate.envers.exception;
+
import java.util.Date;
/**
@@ -29,25 +30,27 @@ import java.util.Date;
*/
public class RevisionDoesNotExistException extends AuditException {
private static final long serialVersionUID = -6417768274074962282L;
-
- private Number revision;
- private Date date;
+
+ private final Number revision;
+ private final Date date;
public RevisionDoesNotExistException(Number revision) {
- super("Revision " + revision + " does not exist.");
- this.revision = revision;
- }
+ super( "Revision " + revision + " does not exist." );
+ this.revision = revision;
+ this.date = null;
+ }
- public RevisionDoesNotExistException(Date date) {
- super("There is no revision before or at " + date + ".");
- this.date = date;
- }
+ public RevisionDoesNotExistException(Date date) {
+ super( "There is no revision before or at " + date + "." );
+ this.date = date;
+ this.revision = null;
+ }
- public Number getRevision() {
- return revision;
- }
+ public Number getRevision() {
+ return revision;
+ }
- public Date getDate() {
- return date;
- }
+ public Date getDate() {
+ return date;
+ }
}
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/EnversMessageLogger.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/EnversMessageLogger.java
index b8208f3994..93e04e3851 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/EnversMessageLogger.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/EnversMessageLogger.java
@@ -1,7 +1,7 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2007-2011, Red Hat Inc. or third-party contributors as
+ * Copyright (c) 2013, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
@@ -37,10 +37,13 @@ import static org.jboss.logging.Logger.Level.WARN;
*
* New messages must be added after the last message defined to ensure message codes are unique.
*/
-@MessageLogger( projectCode = "HHH" )
+@MessageLogger(projectCode = "HHH")
public interface EnversMessageLogger extends CoreMessageLogger {
- @LogMessage( level = WARN )
- @Message( value = "ValidTimeAuditStrategy is deprecated, please use ValidityAuditStrategy instead", id = 25001 )
- void validTimeAuditStrategyDeprecated();
+ /**
+ * Message indicating that user attempted to use the deprecated ValidTimeAuditStrategy
+ */
+ @LogMessage(level = WARN)
+ @Message(value = "ValidTimeAuditStrategy is deprecated, please use ValidityAuditStrategy instead", id = 25001)
+ void validTimeAuditStrategyDeprecated();
}
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 0221e5229c..3c49bae34a 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
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2008, 2013, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -22,6 +22,7 @@
* Boston, MA 02110-1301 USA
*/
package org.hibernate.envers.internal.entities;
+
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
@@ -31,129 +32,136 @@ import java.util.Set;
/**
* Configuration of the user entities: property mapping of the entities, relations, inheritance.
+ *
* @author Adam Warski (adam at warski dot org)
* @author Hernán Chanfreau
* @author Michal Skowronek (mskowr at o2 dot pl)
*/
public class EntitiesConfigurations {
- private Map entitiesConfigurations;
- private Map notAuditedEntitiesConfigurations;
+ private Map entitiesConfigurations;
+ private Map notAuditedEntitiesConfigurations;
- // Map versions entity name -> entity name
- private Map entityNamesForVersionsEntityNames = new HashMap();
+ // Map versions entity name -> entity name
+ private Map entityNamesForVersionsEntityNames = new HashMap();
- public EntitiesConfigurations(Map entitiesConfigurations,
- Map notAuditedEntitiesConfigurations) {
- this.entitiesConfigurations = entitiesConfigurations;
- this.notAuditedEntitiesConfigurations = notAuditedEntitiesConfigurations;
+ public EntitiesConfigurations(
+ Map entitiesConfigurations,
+ Map notAuditedEntitiesConfigurations) {
+ this.entitiesConfigurations = entitiesConfigurations;
+ this.notAuditedEntitiesConfigurations = notAuditedEntitiesConfigurations;
- generateBidirectionRelationInfo();
- generateVersionsEntityToEntityNames();
- }
+ generateBidirectionRelationInfo();
+ generateVersionsEntityToEntityNames();
+ }
- private void generateVersionsEntityToEntityNames() {
- entityNamesForVersionsEntityNames = new HashMap();
+ private void generateVersionsEntityToEntityNames() {
+ entityNamesForVersionsEntityNames = new HashMap();
- for (String entityName : entitiesConfigurations.keySet()) {
- entityNamesForVersionsEntityNames.put(entitiesConfigurations.get(entityName).getVersionsEntityName(),
- entityName);
- }
- }
+ for ( String entityName : entitiesConfigurations.keySet() ) {
+ entityNamesForVersionsEntityNames.put(
+ entitiesConfigurations.get( entityName ).getVersionsEntityName(),
+ entityName
+ );
+ }
+ }
- private void generateBidirectionRelationInfo() {
- // Checking each relation if it is bidirectional. If so, storing that information.
- for (String entityName : entitiesConfigurations.keySet()) {
- EntityConfiguration entCfg = entitiesConfigurations.get(entityName);
- // 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
- // a mapped-by attribute to the currently checked. If so, this is a bidirectional relation.
- if (relDesc.getRelationType() == RelationType.TO_ONE ||
- relDesc.getRelationType() == RelationType.TO_MANY_MIDDLE) {
- EntityConfiguration entityConfiguration = entitiesConfigurations.get(relDesc.getToEntityName());
- if (entityConfiguration != null) {
- for (RelationDescription other : entityConfiguration.getRelationsIterator()) {
- if (relDesc.getFromPropertyName().equals(other.getMappedByPropertyName()) &&
- (entityName.equals(other.getToEntityName()))) {
- relDesc.setBidirectional(true);
- other.setBidirectional(true);
+ 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 );
+ // 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
+ // a mapped-by attribute to the currently checked. If so, this is a bidirectional relation.
+ if ( relDesc.getRelationType() == RelationType.TO_ONE ||
+ relDesc.getRelationType() == RelationType.TO_MANY_MIDDLE ) {
+ final EntityConfiguration entityConfiguration = entitiesConfigurations.get( relDesc.getToEntityName() );
+ if ( entityConfiguration != null ) {
+ for ( RelationDescription other : entityConfiguration.getRelationsIterator() ) {
+ if ( relDesc.getFromPropertyName().equals( other.getMappedByPropertyName() ) &&
+ (entityName.equals( other.getToEntityName() )) ) {
+ relDesc.setBidirectional( true );
+ other.setBidirectional( true );
}
}
}
- }
- }
- }
- }
+ }
+ }
+ }
+ }
- public EntityConfiguration get(String entityName) {
- return entitiesConfigurations.get(entityName);
- }
+ public EntityConfiguration get(String entityName) {
+ return entitiesConfigurations.get( entityName );
+ }
- public EntityConfiguration getNotVersionEntityConfiguration(String entityName) {
- return notAuditedEntitiesConfigurations.get(entityName);
- }
+ public EntityConfiguration getNotVersionEntityConfiguration(String entityName) {
+ return notAuditedEntitiesConfigurations.get( entityName );
+ }
- public String getEntityNameForVersionsEntityName(String versionsEntityName) {
- return entityNamesForVersionsEntityNames.get(versionsEntityName);
- }
+ public String getEntityNameForVersionsEntityName(String versionsEntityName) {
+ return entityNamesForVersionsEntityNames.get( versionsEntityName );
+ }
- public boolean isVersioned(String entityName) {
- return get(entityName) != null;
- }
+ public boolean isVersioned(String entityName) {
+ return get( entityName ) != null;
+ }
- public boolean hasAuditedEntities() {
- return entitiesConfigurations.size() != 0;
- }
+ public boolean hasAuditedEntities() {
+ return entitiesConfigurations.size() != 0;
+ }
- public RelationDescription getRelationDescription(String entityName, String propertyName) {
- EntityConfiguration entCfg = entitiesConfigurations.get(entityName);
- RelationDescription relDesc = entCfg.getRelationDescription(propertyName);
- if (relDesc != null) {
- return relDesc;
- } else if (entCfg.getParentEntityName() != null) {
- // The field may be declared in a superclass ...
- return getRelationDescription(entCfg.getParentEntityName(), propertyName);
- } else {
- return null;
- }
- }
+ public RelationDescription getRelationDescription(String entityName, String propertyName) {
+ final EntityConfiguration entCfg = entitiesConfigurations.get( entityName );
+ final RelationDescription relDesc = entCfg.getRelationDescription( propertyName );
+ if ( relDesc != null ) {
+ return relDesc;
+ }
+ else if ( entCfg.getParentEntityName() != null ) {
+ // The field may be declared in a superclass ...
+ return getRelationDescription( entCfg.getParentEntityName(), propertyName );
+ }
+ else {
+ return null;
+ }
+ }
private Collection getRelationDescriptions(String entityName) {
- EntityConfiguration entCfg = entitiesConfigurations.get(entityName);
+ final EntityConfiguration entCfg = entitiesConfigurations.get( entityName );
Collection descriptions = new ArrayList();
- if (entCfg.getParentEntityName() != null) {
+ if ( entCfg.getParentEntityName() != null ) {
// collect descriptions from super classes
- descriptions.addAll(getRelationDescriptions(entCfg.getParentEntityName()));
+ descriptions.addAll( getRelationDescriptions( entCfg.getParentEntityName() ) );
}
- for (RelationDescription relationDescription : entCfg.getRelationsIterator()) {
- descriptions.add(relationDescription);
+ for ( RelationDescription relationDescription : entCfg.getRelationsIterator() ) {
+ descriptions.add( relationDescription );
}
return descriptions;
}
private void addWithParentEntityNames(String entityName, Set entityNames) {
- entityNames.add(entityName);
- EntityConfiguration entCfg = entitiesConfigurations.get(entityName);
- if (entCfg.getParentEntityName() != null) {
+ entityNames.add( entityName );
+ final EntityConfiguration entCfg = entitiesConfigurations.get( entityName );
+ if ( entCfg.getParentEntityName() != null ) {
// collect descriptions from super classes
- addWithParentEntityNames(entCfg.getParentEntityName(), entityNames);
+ addWithParentEntityNames( entCfg.getParentEntityName(), entityNames );
}
}
private Set getEntityAndParentsNames(String entityName) {
- Set names = new HashSet();
- addWithParentEntityNames(entityName, names);
+ final Set names = new HashSet();
+ addWithParentEntityNames( entityName, names );
return names;
}
public Set getToPropertyNames(String fromEntityName, String fromPropertyName, String toEntityName) {
- Set entityAndParentsNames = getEntityAndParentsNames(fromEntityName);
- Set