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 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 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 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 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 revisionListenerClass = getRevisionListenerClass( RevisionListener.class ); - Class 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 getRevisionListenerClass(Class 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 getRevisionListenerClass(Class 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 annotationType() { return this.getClass(); } + public String value() { + return ""; + } + + public String schema() { + return ""; + } + + public String catalog() { + return ""; + } + + public Class 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 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 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 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 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 toPropertyNames = new HashSet(); - for (RelationDescription relationDescription : getRelationDescriptions(toEntityName)) { - String relToEntityName = relationDescription.getToEntityName(); - String mappedByPropertyName = relationDescription.getMappedByPropertyName(); - if (entityAndParentsNames.contains(relToEntityName) && mappedByPropertyName != null && mappedByPropertyName.equals(fromPropertyName)) { - toPropertyNames.add(relationDescription.getFromPropertyName()); + final Set entityAndParentsNames = getEntityAndParentsNames( fromEntityName ); + final Set toPropertyNames = new HashSet(); + for ( RelationDescription relationDescription : getRelationDescriptions( toEntityName ) ) { + final String relToEntityName = relationDescription.getToEntityName(); + final String mappedByPropertyName = relationDescription.getMappedByPropertyName(); + if ( entityAndParentsNames.contains( relToEntityName ) && mappedByPropertyName != null && mappedByPropertyName + .equals( fromPropertyName ) ) { + toPropertyNames.add( relationDescription.getFromPropertyName() ); } } return toPropertyNames; diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/EntityConfiguration.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/EntityConfiguration.java index ba5a59e81d..8ee7d237e3 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/EntityConfiguration.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/EntityConfiguration.java @@ -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.HashMap; import java.util.Map; @@ -34,93 +35,160 @@ import org.hibernate.envers.internal.entities.mapper.id.IdMapper; * @author HernпїЅn Chanfreau */ public class EntityConfiguration { - private String versionsEntityName; - /** Holds the className for instantiation the configured entity */ - private String entityClassName; + private String versionsEntityName; + /** + * Holds the className for instantiation the configured entity + */ + private String entityClassName; private IdMappingData idMappingData; - private ExtendedPropertyMapper propertyMapper; - // Maps from property name - private Map relations; - private String parentEntityName; + private ExtendedPropertyMapper propertyMapper; + // Maps from property name + private Map relations; + private String parentEntityName; - public EntityConfiguration(String versionsEntityName, String entityClassName, IdMappingData idMappingData, - ExtendedPropertyMapper propertyMapper, String parentEntityName) { - this.versionsEntityName = versionsEntityName; - this.entityClassName = entityClassName; - this.idMappingData = idMappingData; - this.propertyMapper = propertyMapper; - this.parentEntityName = parentEntityName; + public EntityConfiguration( + String versionsEntityName, String entityClassName, IdMappingData idMappingData, + ExtendedPropertyMapper propertyMapper, String parentEntityName) { + this.versionsEntityName = versionsEntityName; + this.entityClassName = entityClassName; + this.idMappingData = idMappingData; + this.propertyMapper = propertyMapper; + this.parentEntityName = parentEntityName; - this.relations = new HashMap(); - } + this.relations = new HashMap(); + } - public void addToOneRelation(String fromPropertyName, String toEntityName, IdMapper idMapper, boolean insertable) { - relations.put(fromPropertyName, new RelationDescription(fromPropertyName, RelationType.TO_ONE, - toEntityName, null, idMapper, null, null, insertable)); - } + public void addToOneRelation(String fromPropertyName, String toEntityName, IdMapper idMapper, boolean insertable) { + relations.put( + fromPropertyName, + new RelationDescription( + fromPropertyName, + RelationType.TO_ONE, + toEntityName, + null, + idMapper, + null, + null, + insertable + ) + ); + } - public void addToOneNotOwningRelation(String fromPropertyName, String mappedByPropertyName, String toEntityName, - IdMapper idMapper) { - relations.put(fromPropertyName, new RelationDescription(fromPropertyName, RelationType.TO_ONE_NOT_OWNING, - toEntityName, mappedByPropertyName, idMapper, null, null, true)); - } + public void addToOneNotOwningRelation( + String fromPropertyName, + String mappedByPropertyName, + String toEntityName, + IdMapper idMapper) { + relations.put( + fromPropertyName, + new RelationDescription( + fromPropertyName, + RelationType.TO_ONE_NOT_OWNING, + toEntityName, + mappedByPropertyName, + idMapper, + null, + null, + true + ) + ); + } - public void addToManyNotOwningRelation(String fromPropertyName, String mappedByPropertyName, String toEntityName, - IdMapper idMapper, PropertyMapper fakeBidirectionalRelationMapper, - PropertyMapper fakeBidirectionalRelationIndexMapper) { - relations.put(fromPropertyName, new RelationDescription(fromPropertyName, RelationType.TO_MANY_NOT_OWNING, - toEntityName, mappedByPropertyName, idMapper, fakeBidirectionalRelationMapper, - fakeBidirectionalRelationIndexMapper, true)); - } + public void addToManyNotOwningRelation( + String fromPropertyName, + String mappedByPropertyName, + String toEntityName, + IdMapper idMapper, + PropertyMapper fakeBidirectionalRelationMapper, + PropertyMapper fakeBidirectionalRelationIndexMapper) { + relations.put( + fromPropertyName, + new RelationDescription( + fromPropertyName, + RelationType.TO_MANY_NOT_OWNING, + toEntityName, + mappedByPropertyName, + idMapper, + fakeBidirectionalRelationMapper, + fakeBidirectionalRelationIndexMapper, + true + ) + ); + } - public void addToManyMiddleRelation(String fromPropertyName, String toEntityName) { - relations.put(fromPropertyName, new RelationDescription(fromPropertyName, RelationType.TO_MANY_MIDDLE, - toEntityName, null, null, null, null, true)); - } + public void addToManyMiddleRelation(String fromPropertyName, String toEntityName) { + relations.put( + fromPropertyName, + new RelationDescription( + fromPropertyName, + RelationType.TO_MANY_MIDDLE, + toEntityName, + null, + null, + null, + null, + true + ) + ); + } - public void addToManyMiddleNotOwningRelation(String fromPropertyName, String mappedByPropertyName, String toEntityName) { - relations.put(fromPropertyName, new RelationDescription(fromPropertyName, RelationType.TO_MANY_MIDDLE_NOT_OWNING, - toEntityName, mappedByPropertyName, null, null, null, true)); - } + public void addToManyMiddleNotOwningRelation( + String fromPropertyName, + String mappedByPropertyName, + String toEntityName) { + relations.put( + fromPropertyName, + new RelationDescription( + fromPropertyName, + RelationType.TO_MANY_MIDDLE_NOT_OWNING, + toEntityName, + mappedByPropertyName, + null, + null, + null, + true + ) + ); + } - public boolean isRelation(String propertyName) { - return relations.get(propertyName) != null; - } - - public RelationDescription getRelationDescription(String propertyName) { - return relations.get(propertyName); - } + public boolean isRelation(String propertyName) { + return relations.get( propertyName ) != null; + } - public IdMappingData getIdMappingData() { - return idMappingData; - } + public RelationDescription getRelationDescription(String propertyName) { + return relations.get( propertyName ); + } - public IdMapper getIdMapper() { - return idMappingData.getIdMapper(); - } + public IdMappingData getIdMappingData() { + return idMappingData; + } - public ExtendedPropertyMapper getPropertyMapper() { - return propertyMapper; - } + public IdMapper getIdMapper() { + return idMappingData.getIdMapper(); + } - public String getParentEntityName() { - return parentEntityName; - } + public ExtendedPropertyMapper getPropertyMapper() { + return propertyMapper; + } - // For use by EntitiesConfigurations + public String getParentEntityName() { + return parentEntityName; + } - String getVersionsEntityName() { - return versionsEntityName; - } + // For use by EntitiesConfigurations - Iterable getRelationsIterator() { - return relations.values(); - } - - /** - * @return the className for the configured entity - */ - public String getEntityClassName() { + String getVersionsEntityName() { + return versionsEntityName; + } + + Iterable getRelationsIterator() { + return relations.values(); + } + + /** + * @return the className for the configured entity + */ + public String getEntityClassName() { return entityClassName; } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/EntityInstantiator.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/EntityInstantiator.java index cf9cf211cb..acac9babe8 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/EntityInstantiator.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/EntityInstantiator.java @@ -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 @@ -44,109 +44,136 @@ import org.hibernate.proxy.LazyInitializer; * @author Hernán Chanfreau */ public class EntityInstantiator { - private final AuditConfiguration verCfg; - private final AuditReaderImplementor versionsReader; + private final AuditConfiguration verCfg; + private final AuditReaderImplementor versionsReader; - public EntityInstantiator(AuditConfiguration verCfg, AuditReaderImplementor versionsReader) { - this.verCfg = verCfg; - this.versionsReader = versionsReader; - } + public EntityInstantiator(AuditConfiguration verCfg, AuditReaderImplementor versionsReader) { + this.verCfg = verCfg; + this.versionsReader = versionsReader; + } - /** - * Creates an entity instance based on an entry from the versions table. - * @param entityName Name of the entity, which instances should be read - * @param versionsEntity An entry in the versions table, from which data should be mapped. - * @param revision Revision at which this entity was read. - * @return An entity instance, with versioned properties set as in the versionsEntity map, and proxies - * created for collections. - */ - public Object createInstanceFromVersionsEntity(String entityName, Map versionsEntity, Number revision) { - if (versionsEntity == null) { - return null; - } + /** + * Creates an entity instance based on an entry from the versions table. + * + * @param entityName Name of the entity, which instances should be read + * @param versionsEntity An entry in the versions table, from which data should be mapped. + * @param revision Revision at which this entity was read. + * + * @return An entity instance, with versioned properties set as in the versionsEntity map, and proxies + * created for collections. + */ + public Object createInstanceFromVersionsEntity(String entityName, Map versionsEntity, Number revision) { + if ( versionsEntity == null ) { + return null; + } - // The $type$ property holds the name of the (versions) entity - String type = verCfg.getEntCfg().getEntityNameForVersionsEntityName((String) versionsEntity.get("$type$")); + // The $type$ property holds the name of the (versions) entity + final String type = verCfg.getEntCfg().getEntityNameForVersionsEntityName( (String) versionsEntity.get( "$type$" ) ); - if (type != null) { - entityName = type; - } + if ( type != null ) { + entityName = type; + } - // First mapping the primary key - IdMapper idMapper = verCfg.getEntCfg().get(entityName).getIdMapper(); - Map originalId = (Map) versionsEntity.get(verCfg.getAuditEntCfg().getOriginalIdPropName()); + // First mapping the primary key + final IdMapper idMapper = verCfg.getEntCfg().get( entityName ).getIdMapper(); + final Map originalId = (Map) versionsEntity.get( verCfg.getAuditEntCfg().getOriginalIdPropName() ); - // Fixes HHH-4751 issue (@IdClass with @ManyToOne relation mapping inside) - // Note that identifiers are always audited - // Replace identifier proxies if do not point to audit tables - replaceNonAuditIdProxies(versionsEntity, revision); + // Fixes HHH-4751 issue (@IdClass with @ManyToOne relation mapping inside) + // Note that identifiers are always audited + // Replace identifier proxies if do not point to audit tables + replaceNonAuditIdProxies( versionsEntity, revision ); - Object primaryKey = idMapper.mapToIdFromMap(originalId); + final Object primaryKey = idMapper.mapToIdFromMap( originalId ); - // Checking if the entity is in cache - if (versionsReader.getFirstLevelCache().contains(entityName, revision, primaryKey)) { - return versionsReader.getFirstLevelCache().get(entityName, revision, primaryKey); - } + // Checking if the entity is in cache + if ( versionsReader.getFirstLevelCache().contains( entityName, revision, primaryKey ) ) { + return versionsReader.getFirstLevelCache().get( entityName, revision, primaryKey ); + } - // If it is not in the cache, creating a new entity instance - Object ret; - try { - EntityConfiguration entCfg = verCfg.getEntCfg().get(entityName); - if(entCfg == null) { - // a relation marked as RelationTargetAuditMode.NOT_AUDITED - entCfg = verCfg.getEntCfg().getNotVersionEntityConfiguration(entityName); - } + // If it is not in the cache, creating a new entity instance + Object ret; + try { + EntityConfiguration entCfg = verCfg.getEntCfg().get( entityName ); + if ( entCfg == null ) { + // a relation marked as RelationTargetAuditMode.NOT_AUDITED + entCfg = verCfg.getEntCfg().getNotVersionEntityConfiguration( entityName ); + } - Class cls = ReflectionTools.loadClass( entCfg.getEntityClassName(), verCfg.getClassLoaderService() ); - ret = ReflectHelper.getDefaultConstructor(cls).newInstance(); - } catch (Exception e) { - throw new AuditException(e); - } + final Class cls = ReflectionTools.loadClass( entCfg.getEntityClassName(), verCfg.getClassLoaderService() ); + ret = ReflectHelper.getDefaultConstructor( cls ).newInstance(); + } + catch (Exception e) { + throw new AuditException( e ); + } - // Putting the newly created entity instance into the first level cache, in case a one-to-one bidirectional - // relation is present (which is eagerly loaded). - versionsReader.getFirstLevelCache().put(entityName, revision, primaryKey, ret); + // Putting the newly created entity instance into the first level cache, in case a one-to-one bidirectional + // relation is present (which is eagerly loaded). + versionsReader.getFirstLevelCache().put( entityName, revision, primaryKey, ret ); - verCfg.getEntCfg().get(entityName).getPropertyMapper().mapToEntityFromMap(verCfg, ret, versionsEntity, primaryKey, - versionsReader, revision); - idMapper.mapToEntityFromMap(ret, originalId); + verCfg.getEntCfg().get( entityName ).getPropertyMapper().mapToEntityFromMap( + verCfg, + ret, + versionsEntity, + primaryKey, + versionsReader, + revision + ); + idMapper.mapToEntityFromMap( ret, originalId ); - // Put entity on entityName cache after mapping it from the map representation - versionsReader.getFirstLevelCache().putOnEntityNameCache(primaryKey, revision, ret, entityName); - - return ret; - } + // Put entity on entityName cache after mapping it from the map representation + versionsReader.getFirstLevelCache().putOnEntityNameCache( primaryKey, revision, ret, entityName ); - @SuppressWarnings({"unchecked"}) - private void replaceNonAuditIdProxies(Map versionsEntity, Number revision) { - final Map originalId = (Map) versionsEntity.get( verCfg.getAuditEntCfg().getOriginalIdPropName() ); - for (Object key : originalId.keySet()) { - Object value = originalId.get(key); - if (value instanceof HibernateProxy) { - HibernateProxy hibernateProxy = (HibernateProxy) value; - LazyInitializer initializer = hibernateProxy.getHibernateLazyInitializer(); - final String entityName = initializer.getEntityName(); - final Serializable entityId = initializer.getIdentifier(); - if (verCfg.getEntCfg().isVersioned(entityName)) { - final String entityClassName = verCfg.getEntCfg().get(entityName).getEntityClassName(); - final Class entityClass = ReflectionTools.loadClass( entityClassName, verCfg.getClassLoaderService() ); - final ToOneDelegateSessionImplementor delegate = new ToOneDelegateSessionImplementor( - versionsReader, entityClass, entityId, revision, - RevisionType.DEL.equals( versionsEntity.get( verCfg.getAuditEntCfg().getRevisionTypePropName() ) ), - verCfg); - originalId.put(key, - versionsReader.getSessionImplementor().getFactory().getEntityPersister(entityName).createProxy(entityId, delegate)); - } - } - } - } + return ret; + } - @SuppressWarnings({"unchecked"}) - public void addInstancesFromVersionsEntities(String entityName, Collection addTo, List versionsEntities, Number revision) { - for (Map versionsEntity : versionsEntities) { - addTo.add(createInstanceFromVersionsEntity(entityName, versionsEntity, revision)); - } - } + @SuppressWarnings({"unchecked"}) + private void replaceNonAuditIdProxies(Map versionsEntity, Number revision) { + final Map originalId = (Map) versionsEntity.get( verCfg.getAuditEntCfg().getOriginalIdPropName() ); + for ( Object key : originalId.keySet() ) { + final Object value = originalId.get( key ); + if ( value instanceof HibernateProxy ) { + final HibernateProxy hibernateProxy = (HibernateProxy) value; + final LazyInitializer initializer = hibernateProxy.getHibernateLazyInitializer(); + final String entityName = initializer.getEntityName(); + final Serializable entityId = initializer.getIdentifier(); + if ( verCfg.getEntCfg().isVersioned( entityName ) ) { + final String entityClassName = verCfg.getEntCfg().get( entityName ).getEntityClassName(); + final Class entityClass = ReflectionTools.loadClass( + entityClassName, + verCfg.getClassLoaderService() + ); + final ToOneDelegateSessionImplementor delegate = new ToOneDelegateSessionImplementor( + versionsReader, entityClass, entityId, revision, + RevisionType.DEL.equals( + versionsEntity.get( + verCfg.getAuditEntCfg() + .getRevisionTypePropName() + ) + ), + verCfg + ); + originalId.put( + key, + versionsReader.getSessionImplementor() + .getFactory() + .getEntityPersister( entityName ) + .createProxy( entityId, delegate ) + ); + } + } + } + } + + @SuppressWarnings({"unchecked"}) + public void addInstancesFromVersionsEntities( + String entityName, + Collection addTo, + List versionsEntities, + Number revision) { + for ( Map versionsEntity : versionsEntities ) { + addTo.add( createInstanceFromVersionsEntity( entityName, versionsEntity, revision ) ); + } + } public AuditConfiguration getAuditConfiguration() { return verCfg; diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/IdMappingData.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/IdMappingData.java index e554f28eeb..681a8c725d 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/IdMappingData.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/IdMappingData.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 org.dom4j.Element; import org.hibernate.envers.internal.entities.mapper.id.IdMapper; @@ -30,27 +31,27 @@ import org.hibernate.envers.internal.entities.mapper.id.IdMapper; * @author Adam Warski (adam at warski dot org) */ public class IdMappingData { - private final IdMapper idMapper; - // Mapping which will be used to generate the entity - private final Element xmlMapping; - // Mapping which will be used to generate references to the entity in related entities - private final Element xmlRelationMapping; + private final IdMapper idMapper; + // Mapping which will be used to generate the entity + private final Element xmlMapping; + // Mapping which will be used to generate references to the entity in related entities + private final Element xmlRelationMapping; - public IdMappingData(IdMapper idMapper, Element xmlMapping, Element xmlRelationMapping) { - this.idMapper = idMapper; - this.xmlMapping = xmlMapping; - this.xmlRelationMapping = xmlRelationMapping; - } + public IdMappingData(IdMapper idMapper, Element xmlMapping, Element xmlRelationMapping) { + this.idMapper = idMapper; + this.xmlMapping = xmlMapping; + this.xmlRelationMapping = xmlRelationMapping; + } - public IdMapper getIdMapper() { - return idMapper; - } + public IdMapper getIdMapper() { + return idMapper; + } - public Element getXmlMapping() { - return xmlMapping; - } + public Element getXmlMapping() { + return xmlMapping; + } - public Element getXmlRelationMapping() { - return xmlRelationMapping; - } + public Element getXmlRelationMapping() { + return xmlRelationMapping; + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/PropertyData.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/PropertyData.java index 0494d2db7b..52d76a89aa 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/PropertyData.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/PropertyData.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,76 +22,86 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.internal.entities; + import org.hibernate.envers.ModificationStore; +import org.hibernate.internal.util.compare.EqualsHelper; /** * Holds information on a property that is audited. + * * @author Adam Warski (adam at warski dot org) */ public class PropertyData { - private final String name; + private final String name; /** * Name of the property in the bean. */ private final String beanName; - private final String accessType; - private final ModificationStore store; + private final String accessType; + private final ModificationStore store; private boolean usingModifiedFlag; private String modifiedFlagName; - /** - * Copies the given property data, except the name. - * @param newName New name. - * @param propertyData Property data to copy the rest of properties from. - */ - public PropertyData(String newName, PropertyData propertyData) { - this.name = newName; + /** + * Copies the given property data, except the name. + * + * @param newName New name. + * @param propertyData Property data to copy the rest of properties from. + */ + public PropertyData(String newName, PropertyData propertyData) { + this.name = newName; this.beanName = propertyData.beanName; - this.accessType = propertyData.accessType; - this.store = propertyData.store; - } - - /** - * @param name Name of the property. - * @param beanName Name of the property in the bean. - * @param accessType Accessor type for this property. - * @param store How this property should be stored. - */ - public PropertyData(String name, String beanName, String accessType, ModificationStore store) { - this.name = name; - this.beanName = beanName; - this.accessType = accessType; - this.store = store; - } + this.accessType = propertyData.accessType; + this.store = propertyData.store; + } /** - * @param name Name of the property. + * @param name Name of the property. * @param beanName Name of the property in the bean. - * @param accessType Accessor type for this property. - * @param store How this property should be stored. - * @param usingModifiedFlag Defines if field changes should be tracked - */ - public PropertyData(String name, String beanName, String accessType, ModificationStore store, boolean usingModifiedFlag, String modifiedFlagName) { - this(name, beanName, accessType, store); + * @param accessType Accessor type for this property. + * @param store How this property should be stored. + */ + public PropertyData(String name, String beanName, String accessType, ModificationStore store) { + this.name = name; + this.beanName = beanName; + this.accessType = accessType; + this.store = store; + } + + /** + * @param name Name of the property. + * @param beanName Name of the property in the bean. + * @param accessType Accessor type for this property. + * @param store How this property should be stored. + * @param usingModifiedFlag Defines if field changes should be tracked + */ + public PropertyData( + String name, + String beanName, + String accessType, + ModificationStore store, + boolean usingModifiedFlag, + String modifiedFlagName) { + this( name, beanName, accessType, store ); this.usingModifiedFlag = usingModifiedFlag; this.modifiedFlagName = modifiedFlagName; } - public String getName() { - return name; - } + public String getName() { + return name; + } public String getBeanName() { return beanName; } public String getAccessType() { - return accessType; - } + return accessType; + } - public ModificationStore getStore() { - return store; - } + public ModificationStore getStore() { + return store; + } public boolean isUsingModifiedFlag() { return usingModifiedFlag; @@ -103,18 +113,19 @@ public class PropertyData { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } - PropertyData that = (PropertyData) o; - - if (accessType != null ? !accessType.equals(that.accessType) : that.accessType != null) return false; - if (beanName != null ? !beanName.equals(that.beanName) : that.beanName != null) return false; - if (name != null ? !name.equals(that.name) : that.name != null) return false; - if (store != that.store) return false; - if (usingModifiedFlag != that.usingModifiedFlag) return false; - - return true; + final PropertyData that = (PropertyData) o; + return usingModifiedFlag == that.usingModifiedFlag + && store == that.store + && EqualsHelper.equals( accessType, that.accessType ) + && EqualsHelper.equals( beanName, that.beanName ) + && EqualsHelper.equals( name, that.name ); } @Override diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/RelationDescription.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/RelationDescription.java index b129500944..a4cc200a68 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/RelationDescription.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/RelationDescription.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,76 +22,78 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.internal.entities; + import org.hibernate.envers.internal.entities.mapper.PropertyMapper; import org.hibernate.envers.internal.entities.mapper.id.IdMapper; /** * @author Adam Warski (adam at warski dot org) -*/ + */ public class RelationDescription { - private final String fromPropertyName; - private final RelationType relationType; - private final String toEntityName; - private final String mappedByPropertyName; - private final IdMapper idMapper; - private final PropertyMapper fakeBidirectionalRelationMapper; - private final PropertyMapper fakeBidirectionalRelationIndexMapper; - private final boolean insertable; - private boolean bidirectional; + private final String fromPropertyName; + private final RelationType relationType; + private final String toEntityName; + private final String mappedByPropertyName; + private final IdMapper idMapper; + private final PropertyMapper fakeBidirectionalRelationMapper; + private final PropertyMapper fakeBidirectionalRelationIndexMapper; + private final boolean insertable; + private boolean bidirectional; - public RelationDescription(String fromPropertyName, RelationType relationType, String toEntityName, - String mappedByPropertyName, IdMapper idMapper, - PropertyMapper fakeBidirectionalRelationMapper, - PropertyMapper fakeBidirectionalRelationIndexMapper, boolean insertable) { - this.fromPropertyName = fromPropertyName; - this.relationType = relationType; - this.toEntityName = toEntityName; - this.mappedByPropertyName = mappedByPropertyName; - this.idMapper = idMapper; - this.fakeBidirectionalRelationMapper = fakeBidirectionalRelationMapper; - this.fakeBidirectionalRelationIndexMapper = fakeBidirectionalRelationIndexMapper; - this.insertable = insertable; + public RelationDescription( + String fromPropertyName, RelationType relationType, String toEntityName, + String mappedByPropertyName, IdMapper idMapper, + PropertyMapper fakeBidirectionalRelationMapper, + PropertyMapper fakeBidirectionalRelationIndexMapper, boolean insertable) { + this.fromPropertyName = fromPropertyName; + this.relationType = relationType; + this.toEntityName = toEntityName; + this.mappedByPropertyName = mappedByPropertyName; + this.idMapper = idMapper; + this.fakeBidirectionalRelationMapper = fakeBidirectionalRelationMapper; + this.fakeBidirectionalRelationIndexMapper = fakeBidirectionalRelationIndexMapper; + this.insertable = insertable; - this.bidirectional = false; - } + this.bidirectional = false; + } - public String getFromPropertyName() { - return fromPropertyName; - } + public String getFromPropertyName() { + return fromPropertyName; + } - public RelationType getRelationType() { - return relationType; - } + public RelationType getRelationType() { + return relationType; + } - public String getToEntityName() { - return toEntityName; - } + public String getToEntityName() { + return toEntityName; + } - public String getMappedByPropertyName() { - return mappedByPropertyName; - } + public String getMappedByPropertyName() { + return mappedByPropertyName; + } - public IdMapper getIdMapper() { - return idMapper; - } + public IdMapper getIdMapper() { + return idMapper; + } - public PropertyMapper getFakeBidirectionalRelationMapper() { - return fakeBidirectionalRelationMapper; - } + public PropertyMapper getFakeBidirectionalRelationMapper() { + return fakeBidirectionalRelationMapper; + } - public PropertyMapper getFakeBidirectionalRelationIndexMapper() { - return fakeBidirectionalRelationIndexMapper; - } + public PropertyMapper getFakeBidirectionalRelationIndexMapper() { + return fakeBidirectionalRelationIndexMapper; + } - public boolean isInsertable() { - return insertable; - } + public boolean isInsertable() { + return insertable; + } - public boolean isBidirectional() { - return bidirectional; - } + public boolean isBidirectional() { + return bidirectional; + } - void setBidirectional(boolean bidirectional) { - this.bidirectional = bidirectional; - } + void setBidirectional(boolean bidirectional) { + this.bidirectional = bidirectional; + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/RelationType.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/RelationType.java index 449b4ecfd9..fa53383dc9 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/RelationType.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/RelationType.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,30 +26,31 @@ package org.hibernate.envers.internal.entities; /** * Type of a relation between two entities. + * * @author Adam Warski (adam at warski dot org) -*/ + */ public enum RelationType { - /** - * A single-reference-valued relation. The entity owns the relation. - */ - TO_ONE, - /** - * A single-reference-valued relation. The entity doesn't own the relation. It is directly mapped in the related - * entity. - */ - TO_ONE_NOT_OWNING, - /** - * A collection-of-references-valued relation. The entity doesn't own the relation. It is directly mapped in the - * related entity. - */ - TO_MANY_NOT_OWNING, - /** - * A collection-of-references-valued relation. The entity owns the relation. It is mapped using a middle table. - */ - TO_MANY_MIDDLE, - /** - * A collection-of-references-valued relation. The entity doesn't own the relation. It is mapped using a middle - * table. - */ - TO_MANY_MIDDLE_NOT_OWNING + /** + * A single-reference-valued relation. The entity owns the relation. + */ + TO_ONE, + /** + * A single-reference-valued relation. The entity doesn't own the relation. It is directly mapped in the related + * entity. + */ + TO_ONE_NOT_OWNING, + /** + * A collection-of-references-valued relation. The entity doesn't own the relation. It is directly mapped in the + * related entity. + */ + TO_MANY_NOT_OWNING, + /** + * A collection-of-references-valued relation. The entity owns the relation. It is mapped using a middle table. + */ + TO_MANY_MIDDLE, + /** + * A collection-of-references-valued relation. The entity doesn't own the relation. It is mapped using a middle + * table. + */ + TO_MANY_MIDDLE_NOT_OWNING } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/RevisionTypeType.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/RevisionTypeType.java index 0580c804c2..9557a8a70f 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/RevisionTypeType.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/RevisionTypeType.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 @@ -32,78 +32,84 @@ import java.sql.Types; import org.hibernate.HibernateException; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.envers.RevisionType; +import org.hibernate.internal.util.compare.EqualsHelper; import org.hibernate.type.IntegerType; import org.hibernate.usertype.UserType; /** * A hibernate type for the {@link RevisionType} enum. + * * @author Adam Warski (adam at warski dot org) */ public class RevisionTypeType implements UserType, Serializable { - private static final long serialVersionUID = -1053201518229282688L; - - private static final int[] SQL_TYPES = { Types.TINYINT }; + private static final long serialVersionUID = -1053201518229282688L; - public int[] sqlTypes() { - return SQL_TYPES; - } + private static final int[] SQL_TYPES = {Types.TINYINT}; - public Class returnedClass() { - return RevisionType.class; - } + @Override + public int[] sqlTypes() { + return SQL_TYPES; + } - public RevisionType nullSafeGet(ResultSet resultSet, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException { - Integer representationInt = IntegerType.INSTANCE.nullSafeGet( resultSet, names[0], session ); + @Override + public Class returnedClass() { + return RevisionType.class; + } + + @Override + public RevisionType nullSafeGet(ResultSet resultSet, String[] names, SessionImplementor session, Object owner) + throws HibernateException, SQLException { + final Integer representationInt = IntegerType.INSTANCE.nullSafeGet( resultSet, names[0], session ); return representationInt == null ? null : RevisionType.fromRepresentation( representationInt.byteValue() ); - } + } - public void nullSafeSet(PreparedStatement preparedStatement, Object value, int index, SessionImplementor session) throws HibernateException, SQLException { + @Override + public void nullSafeSet(PreparedStatement preparedStatement, Object value, int index, SessionImplementor session) + throws HibernateException, SQLException { IntegerType.INSTANCE.nullSafeSet( preparedStatement, - ( value == null ? null : ((RevisionType) value).getRepresentation().intValue() ), + (value == null ? null : ((RevisionType) value).getRepresentation().intValue()), index, session ); - } + } - public Object deepCopy(Object value) throws HibernateException{ - return value; - } + @Override + public Object deepCopy(Object value) throws HibernateException { + return value; + } - public boolean isMutable() { - return false; - } + @Override + public boolean isMutable() { + return false; + } - public Object assemble(Serializable cached, Object owner) throws HibernateException { - return cached; - } + @Override + public Object assemble(Serializable cached, Object owner) throws HibernateException { + return cached; + } - public Serializable disassemble(Object value) throws HibernateException { - return (Serializable)value; - } + @Override + public Serializable disassemble(Object value) throws HibernateException { + return (Serializable) value; + } - public Object replace(Object original, Object target, Object owner) throws HibernateException { - return original; - } + @Override + public Object replace(Object original, Object target, Object owner) throws HibernateException { + return original; + } - public int hashCode(Object x) throws HibernateException { - return x.hashCode(); - } + @Override + public int hashCode(Object x) throws HibernateException { + return x.hashCode(); + } - public boolean equals(Object x, Object y) throws HibernateException { - //noinspection ObjectEquality - if (x == y) { - return true; - } - - if (null == x || null == y) { - return false; - } - - return x.equals(y); - } + @Override + public boolean equals(Object x, Object y) throws HibernateException { + return EqualsHelper.equals( x, y ); + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/TypeContributorImpl.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/TypeContributorImpl.java index 0a49200a26..e2366a0b80 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/TypeContributorImpl.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/TypeContributorImpl.java @@ -1,22 +1,25 @@ -/* +/* * Hibernate, Relational Persistence for Idiomatic Java - * - * JBoss, Home of Professional Open Source - * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors - * as indicated by the @authors tag. All rights reserved. - * See the copyright.txt in the distribution for a - * full listing of individual contributors. * - * 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, v. 2.1. - * This program is distributed in the hope that it will be useful, but WITHOUT A - * 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, - * v.2.1 along with this distribution; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. + * 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.internal.entities; @@ -25,14 +28,17 @@ import org.hibernate.metamodel.spi.TypeContributor; import org.hibernate.service.ServiceRegistry; /** + * Envers specific TypeContributor + * * @author Brett Meyer */ public class TypeContributorImpl implements TypeContributor { - @Override public void contribute(TypeContributions typeContributions, ServiceRegistry serviceRegistry) { - typeContributions.contributeType( new RevisionTypeType(), - new String[] { RevisionTypeType.class.getName() } ); + typeContributions.contributeType( + new RevisionTypeType(), + new String[] { RevisionTypeType.class.getName() } + ); } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/ComponentPropertyMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/ComponentPropertyMapper.java index 52d0323998..3cdb1c2d89 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/ComponentPropertyMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/ComponentPropertyMapper.java @@ -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 @@ -43,98 +43,127 @@ import org.hibernate.property.Setter; * @author Michal Skowronek (mskowr at o2 dot pl) */ public class ComponentPropertyMapper implements PropertyMapper, CompositeMapperBuilder { - private final PropertyData propertyData; - private final MultiPropertyMapper delegate; + private final PropertyData propertyData; + private final MultiPropertyMapper delegate; private final Class componentClass; - public ComponentPropertyMapper(PropertyData propertyData, Class componentClass) { - this.propertyData = propertyData; - this.delegate = new MultiPropertyMapper(); + public ComponentPropertyMapper(PropertyData propertyData, Class componentClass) { + this.propertyData = propertyData; + this.delegate = new MultiPropertyMapper(); this.componentClass = componentClass; - } - - public void add(PropertyData propertyData) { - delegate.add(propertyData); - } - - public CompositeMapperBuilder addComponent(PropertyData propertyData, Class componentClass) { - return delegate.addComponent(propertyData, componentClass); - } - - public void addComposite(PropertyData propertyData, PropertyMapper propertyMapper) { - delegate.addComposite(propertyData, propertyMapper); - } - - public boolean mapToMapFromEntity(SessionImplementor session, Map data, Object newObj, Object oldObj) { - return delegate.mapToMapFromEntity(session, data, newObj, oldObj); - } + } @Override - public void mapModifiedFlagsToMapFromEntity(SessionImplementor session, Map data, Object newObj, Object oldObj) { - if (propertyData.isUsingModifiedFlag()) { - data.put(propertyData.getModifiedFlagPropertyName(), - delegate.mapToMapFromEntity(session, new HashMap(), newObj, oldObj)); + public void add(PropertyData propertyData) { + delegate.add( propertyData ); + } + + @Override + public CompositeMapperBuilder addComponent(PropertyData propertyData, Class componentClass) { + return delegate.addComponent( propertyData, componentClass ); + } + + @Override + public void addComposite(PropertyData propertyData, PropertyMapper propertyMapper) { + delegate.addComposite( propertyData, propertyMapper ); + } + + @Override + public boolean mapToMapFromEntity( + SessionImplementor session, + Map data, + Object newObj, + Object oldObj) { + return delegate.mapToMapFromEntity( session, data, newObj, oldObj ); + } + + @Override + public void mapModifiedFlagsToMapFromEntity( + SessionImplementor session, + Map data, + Object newObj, + Object oldObj) { + if ( propertyData.isUsingModifiedFlag() ) { + data.put( + propertyData.getModifiedFlagPropertyName(), + delegate.mapToMapFromEntity( session, new HashMap(), newObj, oldObj ) + ); } } @Override public void mapModifiedFlagsToMapForCollectionChange(String collectionPropertyName, Map data) { - if (propertyData.isUsingModifiedFlag()) { + if ( propertyData.isUsingModifiedFlag() ) { boolean hasModifiedCollection = false; - for (PropertyData propData : delegate.getProperties().keySet()) { - if (collectionPropertyName.equals(propData.getName())) { + for ( PropertyData propData : delegate.getProperties().keySet() ) { + if ( collectionPropertyName.equals( propData.getName() ) ) { hasModifiedCollection = true; break; } } - data.put(propertyData.getModifiedFlagPropertyName(), hasModifiedCollection); + data.put( propertyData.getModifiedFlagPropertyName(), hasModifiedCollection ); } } - public void mapToEntityFromMap(AuditConfiguration verCfg, Object obj, Map data, Object primaryKey, AuditReaderImplementor versionsReader, Number revision) { - if (data == null || obj == null) { - return; - } + @Override + public void mapToEntityFromMap( + AuditConfiguration verCfg, + Object obj, + Map data, + Object primaryKey, + AuditReaderImplementor versionsReader, + Number revision) { + if ( data == null || obj == null ) { + return; + } - if (propertyData.getBeanName() == null) { - // If properties are not encapsulated in a component but placed directly in a class - // (e.g. by applying tag). - delegate.mapToEntityFromMap(verCfg, obj, data, primaryKey, versionsReader, revision); - return; - } + if ( propertyData.getBeanName() == null ) { + // If properties are not encapsulated in a component but placed directly in a class + // (e.g. by applying tag). + delegate.mapToEntityFromMap( verCfg, obj, data, primaryKey, versionsReader, revision ); + return; + } - Setter setter = ReflectionTools.getSetter(obj.getClass(), propertyData); + final Setter setter = ReflectionTools.getSetter( obj.getClass(), propertyData ); // If all properties are null and single, then the component has to be null also. boolean allNullAndSingle = true; - for (Map.Entry property : delegate.getProperties().entrySet()) { - if (data.get(property.getKey().getName()) != null || !(property.getValue() instanceof SinglePropertyMapper)) { + for ( Map.Entry property : delegate.getProperties().entrySet() ) { + if ( data.get( + property.getKey() + .getName() + ) != null || !(property.getValue() instanceof SinglePropertyMapper) ) { allNullAndSingle = false; break; } } - if (allNullAndSingle) { + if ( allNullAndSingle ) { // single property, but default value need not be null, so we'll set it to null anyway - setter.set(obj, null, null); - } else { + setter.set( obj, null, null ); + } + else { // set the component try { - Object subObj = ReflectHelper.getDefaultConstructor(componentClass).newInstance(); - setter.set(obj, subObj, null); - delegate.mapToEntityFromMap(verCfg, subObj, data, primaryKey, versionsReader, revision); - } catch (Exception e) { - throw new AuditException(e); + final Object subObj = ReflectHelper.getDefaultConstructor( componentClass ).newInstance(); + setter.set( obj, subObj, null ); + delegate.mapToEntityFromMap( verCfg, subObj, data, primaryKey, versionsReader, revision ); + } + catch (Exception e) { + throw new AuditException( e ); } } - } + } - public List mapCollectionChanges(SessionImplementor session, String referencingPropertyName, - PersistentCollection newColl, - Serializable oldColl, Serializable id) { - return delegate.mapCollectionChanges(session, referencingPropertyName, newColl, oldColl, id); - } + @Override + public List mapCollectionChanges( + SessionImplementor session, String referencingPropertyName, + PersistentCollection newColl, + Serializable oldColl, Serializable id) { + return delegate.mapCollectionChanges( session, referencingPropertyName, newColl, oldColl, id ); + } + @Override public Map getProperties() { return delegate.getProperties(); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/CompositeMapperBuilder.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/CompositeMapperBuilder.java index c863249ea0..aa3c5fb8bb 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/CompositeMapperBuilder.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/CompositeMapperBuilder.java @@ -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 @@ -30,8 +30,10 @@ import org.hibernate.envers.internal.entities.PropertyData; /** * @author Adam Warski (adam at warski dot org) */ -public interface CompositeMapperBuilder extends SimpleMapperBuilder { - public CompositeMapperBuilder addComponent(PropertyData propertyData, Class componentClass); - public void addComposite(PropertyData propertyData, PropertyMapper propertyMapper); +public interface CompositeMapperBuilder extends SimpleMapperBuilder { + public CompositeMapperBuilder addComponent(PropertyData propertyData, Class componentClass); + + public void addComposite(PropertyData propertyData, PropertyMapper propertyMapper); + public Map getProperties(); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/ExtendedPropertyMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/ExtendedPropertyMapper.java index a804087836..6c3bec77cc 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/ExtendedPropertyMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/ExtendedPropertyMapper.java @@ -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.internal.entities.mapper; + import java.util.Map; import org.hibernate.engine.spi.SessionImplementor; @@ -30,5 +31,10 @@ import org.hibernate.engine.spi.SessionImplementor; * @author Adam Warski (adam at warski dot org) */ public interface ExtendedPropertyMapper extends PropertyMapper, CompositeMapperBuilder { - public boolean map(SessionImplementor session, Map data, String[] propertyNames, Object[] newState, Object[] oldState); + public boolean map( + SessionImplementor session, + Map data, + String[] propertyNames, + Object[] newState, + Object[] oldState); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/MultiPropertyMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/MultiPropertyMapper.java index cff9d7aff1..fe99f02166 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/MultiPropertyMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/MultiPropertyMapper.java @@ -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 @@ -43,148 +43,183 @@ import org.hibernate.property.Getter; * @author Michal Skowronek (mskowr at o2 dot pl) */ public class MultiPropertyMapper implements ExtendedPropertyMapper { - protected final Map properties; - private final Map propertyDatas; + protected final Map properties; + private final Map propertyDatas; - public MultiPropertyMapper() { - properties = Tools.newHashMap(); - propertyDatas = Tools.newHashMap(); - } - - public void add(PropertyData propertyData) { - SinglePropertyMapper single = new SinglePropertyMapper(); - single.add(propertyData); - properties.put(propertyData, single); - propertyDatas.put(propertyData.getName(), propertyData); - } - - public CompositeMapperBuilder addComponent(PropertyData propertyData, Class componentClass) { - if (properties.get(propertyData) != null) { - // This is needed for second pass to work properly in the components mapper - return (CompositeMapperBuilder) properties.get(propertyData); - } - - ComponentPropertyMapper componentMapperBuilder = new ComponentPropertyMapper(propertyData, componentClass); - addComposite(propertyData, componentMapperBuilder); - - return componentMapperBuilder; - } - - public void addComposite(PropertyData propertyData, PropertyMapper propertyMapper) { - properties.put(propertyData, propertyMapper); - propertyDatas.put(propertyData.getName(), propertyData); - } - - private Object getAtIndexOrNull(Object[] array, int index) { return array == null ? null : array[index]; } - - public boolean map(SessionImplementor session, Map data, String[] propertyNames, Object[] newState, Object[] oldState) { - boolean ret = false; - for (int i=0; i data, Object newObj, Object oldObj) { - boolean ret = false; - for (PropertyData propertyData : properties.keySet()) { - Getter getter; - if (newObj != null) { - getter = ReflectionTools.getGetter(newObj.getClass(), propertyData); - } else if (oldObj != null) { - getter = ReflectionTools.getGetter(oldObj.getClass(), propertyData); - } else { - return false; - } - - ret |= properties.get(propertyData).mapToMapFromEntity(session, data, - newObj == null ? null : getter.get(newObj), - oldObj == null ? null : getter.get(oldObj)); - } - - return ret; - } - - @Override - public void mapModifiedFlagsToMapFromEntity(SessionImplementor session, Map data, Object newObj, Object oldObj) { - for (PropertyData propertyData : properties.keySet()) { - Getter getter; - if (newObj != null) { - getter = ReflectionTools.getGetter(newObj.getClass(), propertyData); - } else if (oldObj != null) { - getter = ReflectionTools.getGetter(oldObj.getClass(), propertyData); - } else { - return; - } - - properties.get(propertyData).mapModifiedFlagsToMapFromEntity(session, data, - newObj == null ? null : getter.get(newObj), - oldObj == null ? null : getter.get(oldObj)); - } + public MultiPropertyMapper() { + properties = Tools.newHashMap(); + propertyDatas = Tools.newHashMap(); } - public void mapToEntityFromMap(AuditConfiguration verCfg, Object obj, Map data, Object primaryKey, - AuditReaderImplementor versionsReader, Number revision) { - for (PropertyMapper mapper : properties.values()) { - mapper.mapToEntityFromMap(verCfg, obj, data, primaryKey, versionsReader, revision); - } - } + @Override + public void add(PropertyData propertyData) { + final SinglePropertyMapper single = new SinglePropertyMapper(); + single.add( propertyData ); + properties.put( propertyData, single ); + propertyDatas.put( propertyData.getName(), propertyData ); + } - private Pair getMapperAndDelegatePropName(String referencingPropertyName){ + @Override + public CompositeMapperBuilder addComponent(PropertyData propertyData, Class componentClass) { + if ( properties.get( propertyData ) != null ) { + // This is needed for second pass to work properly in the components mapper + return (CompositeMapperBuilder) properties.get( propertyData ); + } + + final ComponentPropertyMapper componentMapperBuilder = new ComponentPropertyMapper( propertyData, componentClass ); + addComposite( propertyData, componentMapperBuilder ); + + return componentMapperBuilder; + } + + @Override + public void addComposite(PropertyData propertyData, PropertyMapper propertyMapper) { + properties.put( propertyData, propertyMapper ); + propertyDatas.put( propertyData.getName(), propertyData ); + } + + private Object getAtIndexOrNull(Object[] array, int index) { + return array == null ? null : array[index]; + } + + @Override + public boolean map( + SessionImplementor session, + Map data, + String[] propertyNames, + Object[] newState, + Object[] oldState) { + boolean ret = false; + for ( int i = 0; i < propertyNames.length; i++ ) { + final String propertyName = propertyNames[i]; + + if ( propertyDatas.containsKey( propertyName ) ) { + final PropertyMapper propertyMapper = properties.get( propertyDatas.get( propertyName ) ); + final Object newObj = getAtIndexOrNull( newState, i ); + final Object oldObj = getAtIndexOrNull( oldState, i ); + ret |= propertyMapper.mapToMapFromEntity( session, data, newObj, oldObj ); + propertyMapper.mapModifiedFlagsToMapFromEntity( session, data, newObj, oldObj ); + } + } + + return ret; + } + + @Override + public boolean mapToMapFromEntity( + SessionImplementor session, + Map data, + Object newObj, + Object oldObj) { + boolean ret = false; + for ( PropertyData propertyData : properties.keySet() ) { + Getter getter; + if ( newObj != null ) { + getter = ReflectionTools.getGetter( newObj.getClass(), propertyData ); + } + else if ( oldObj != null ) { + getter = ReflectionTools.getGetter( oldObj.getClass(), propertyData ); + } + else { + return false; + } + + ret |= properties.get( propertyData ).mapToMapFromEntity( + session, data, + newObj == null ? null : getter.get( newObj ), + oldObj == null ? null : getter.get( oldObj ) + ); + } + + return ret; + } + + @Override + public void mapModifiedFlagsToMapFromEntity( + SessionImplementor session, + Map data, + Object newObj, + Object oldObj) { + for ( PropertyData propertyData : properties.keySet() ) { + Getter getter; + if ( newObj != null ) { + getter = ReflectionTools.getGetter( newObj.getClass(), propertyData ); + } + else if ( oldObj != null ) { + getter = ReflectionTools.getGetter( oldObj.getClass(), propertyData ); + } + else { + return; + } + + properties.get( propertyData ).mapModifiedFlagsToMapFromEntity( + session, data, + newObj == null ? null : getter.get( newObj ), + oldObj == null ? null : getter.get( oldObj ) + ); + } + } + + @Override + public void mapToEntityFromMap( + AuditConfiguration verCfg, Object obj, Map data, Object primaryKey, + AuditReaderImplementor versionsReader, Number revision) { + for ( PropertyMapper mapper : properties.values() ) { + mapper.mapToEntityFromMap( verCfg, obj, data, primaryKey, versionsReader, revision ); + } + } + + private Pair getMapperAndDelegatePropName(String referencingPropertyName) { // Name of the property, to which we will delegate the mapping. String delegatePropertyName; // Checking if the property name doesn't reference a collection in a component - then the name will containa a . - int dotIndex = referencingPropertyName.indexOf('.'); - if (dotIndex != -1) { + final int dotIndex = referencingPropertyName.indexOf( '.' ); + if ( dotIndex != -1 ) { // Computing the name of the component - String componentName = referencingPropertyName.substring(0, dotIndex); + final String componentName = referencingPropertyName.substring( 0, dotIndex ); // And the name of the property in the component - String propertyInComponentName = MappingTools.createComponentPrefix(componentName) - + referencingPropertyName.substring(dotIndex+1); + final String propertyInComponentName = MappingTools.createComponentPrefix( componentName ) + + referencingPropertyName.substring( dotIndex + 1 ); // We need to get the mapper for the component. referencingPropertyName = componentName; // As this is a component, we delegate to the property in the component. delegatePropertyName = propertyInComponentName; - } else { + } + else { // If this is not a component, we delegate to the same property. delegatePropertyName = referencingPropertyName; } - return Pair.make(properties.get(propertyDatas.get(referencingPropertyName)), delegatePropertyName); + return Pair.make( properties.get( propertyDatas.get( referencingPropertyName ) ), delegatePropertyName ); } @Override public void mapModifiedFlagsToMapForCollectionChange(String collectionPropertyName, Map data) { - Pair pair = getMapperAndDelegatePropName(collectionPropertyName); - PropertyMapper mapper = pair.getFirst(); - if (mapper != null) { - mapper.mapModifiedFlagsToMapForCollectionChange(pair.getSecond(), data); + final Pair pair = getMapperAndDelegatePropName( collectionPropertyName ); + final PropertyMapper mapper = pair.getFirst(); + if ( mapper != null ) { + mapper.mapModifiedFlagsToMapForCollectionChange( pair.getSecond(), data ); } } - public List mapCollectionChanges(SessionImplementor session, - String referencingPropertyName, - PersistentCollection newColl, - Serializable oldColl, Serializable id) { - Pair pair = getMapperAndDelegatePropName(referencingPropertyName); - PropertyMapper mapper = pair.getFirst(); - if (mapper != null) { - return mapper.mapCollectionChanges(session, pair.getSecond(), newColl, oldColl, id); - } else { + @Override + public List mapCollectionChanges( + SessionImplementor session, + String referencingPropertyName, + PersistentCollection newColl, + Serializable oldColl, Serializable id) { + final Pair pair = getMapperAndDelegatePropName( referencingPropertyName ); + final PropertyMapper mapper = pair.getFirst(); + if ( mapper != null ) { + return mapper.mapCollectionChanges( session, pair.getSecond(), newColl, oldColl, id ); + } + else { return null; } } + @Override public Map getProperties() { return properties; } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/PersistentCollectionChangeData.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/PersistentCollectionChangeData.java index cce22395ee..ce75a7c83a 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/PersistentCollectionChangeData.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/PersistentCollectionChangeData.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.mapper; + import java.util.Map; import org.hibernate.envers.tools.Pair; @@ -29,58 +30,58 @@ import org.hibernate.envers.tools.Pair; /** * Data describing the change of a single object in a persistent collection (when the object was added, removed or * modified in the collection). + * * @author Adam Warski (adam at warski dot org) */ public class PersistentCollectionChangeData { - private final String entityName; - private final Map data; - private final Object changedElement; + private final String entityName; + private final Map data; + private final Object changedElement; - public PersistentCollectionChangeData(String entityName, Map data, Object changedElement) { - this.entityName = entityName; - this.data = data; - this.changedElement = changedElement; - } + public PersistentCollectionChangeData(String entityName, Map data, Object changedElement) { + this.entityName = entityName; + this.data = data; + this.changedElement = changedElement; + } - /** - * - * @return Name of the (middle) entity that holds the collection data. - */ - public String getEntityName() { - return entityName; - } + /** + * @return Name of the (middle) entity that holds the collection data. + */ + public String getEntityName() { + return entityName; + } - public Map getData() { - return data; - } + public Map getData() { + return data; + } - /** - * @return The affected element, which was changed (added, removed, modified) in the collection. - */ - public Object getChangedElement() { - if (changedElement instanceof Pair) { - return ((Pair) changedElement).getSecond(); - } + /** + * @return The affected element, which was changed (added, removed, modified) in the collection. + */ + public Object getChangedElement() { + if ( changedElement instanceof Pair ) { + return ((Pair) changedElement).getSecond(); + } - if (changedElement instanceof Map.Entry) { - return ((Map.Entry) changedElement).getValue(); - } + if ( changedElement instanceof Map.Entry ) { + return ((Map.Entry) changedElement).getValue(); + } - return changedElement; - } + return changedElement; + } - /** - * @return Index of the affected element, or {@code null} if the collection isn't indexed. - */ - public Object getChangedElementIndex() { - if (changedElement instanceof Pair) { - return ((Pair) changedElement).getFirst(); - } + /** + * @return Index of the affected element, or {@code null} if the collection isn't indexed. + */ + public Object getChangedElementIndex() { + if ( changedElement instanceof Pair ) { + return ((Pair) changedElement).getFirst(); + } - if (changedElement instanceof Map.Entry) { - return ((Map.Entry) changedElement).getKey(); - } + if ( changedElement instanceof Map.Entry ) { + return ((Map.Entry) changedElement).getKey(); + } - return null; - } + return null; + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/PropertyMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/PropertyMapper.java index f8e23b044e..43d6acaa14 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/PropertyMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/PropertyMapper.java @@ -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.internal.entities.mapper; + import java.io.Serializable; import java.util.List; import java.util.Map; @@ -36,41 +37,53 @@ import org.hibernate.envers.internal.reader.AuditReaderImplementor; * @author Michal Skowronek (mskowr at o2 dot pl) */ public interface PropertyMapper { - /** - * Maps properties to the given map, basing on differences between properties of new and old objects. - * @param session The current session. + /** + * Maps properties to the given map, basing on differences between properties of new and old objects. + * + * @param session The current session. * @param data Data to map to. * @param newObj New state of the entity. * @param oldObj Old state of the entity. + * * @return True if there are any differences between the states represented by newObj and oldObj. - */ - boolean mapToMapFromEntity(SessionImplementor session, Map data, Object newObj, Object oldObj); + */ + boolean mapToMapFromEntity(SessionImplementor session, Map data, Object newObj, Object oldObj); - /** - * Maps properties from the given map to the given object. - * @param verCfg Versions configuration. - * @param obj Object to map to. - * @param data Data to map from. - * @param primaryKey Primary key of the object to which we map (for relations) - * @param versionsReader VersionsReader for reading relations - * @param revision Revision at which the object is read, for reading relations - */ - void mapToEntityFromMap(AuditConfiguration verCfg, Object obj, Map data, Object primaryKey, - AuditReaderImplementor versionsReader, Number revision); + /** + * Maps properties from the given map to the given object. + * + * @param verCfg Versions configuration. + * @param obj Object to map to. + * @param data Data to map from. + * @param primaryKey Primary key of the object to which we map (for relations) + * @param versionsReader VersionsReader for reading relations + * @param revision Revision at which the object is read, for reading relations + */ + void mapToEntityFromMap( + AuditConfiguration verCfg, Object obj, Map data, Object primaryKey, + AuditReaderImplementor versionsReader, Number revision); - /** - * Maps collection changes. + /** + * Maps collection changes. + * * @param session The current session. - * @param referencingPropertyName Name of the field, which holds the collection in the entity. - * @param newColl New collection, after updates. - * @param oldColl Old collection, before updates. - * @param id Id of the object owning the collection. - * @return List of changes that need to be performed on the persistent store. - */ - List mapCollectionChanges(SessionImplementor session, String referencingPropertyName, - PersistentCollection newColl, - Serializable oldColl, Serializable id); + * @param referencingPropertyName Name of the field, which holds the collection in the entity. + * @param newColl New collection, after updates. + * @param oldColl Old collection, before updates. + * @param id Id of the object owning the collection. + * + * @return List of changes that need to be performed on the persistent store. + */ + List mapCollectionChanges( + SessionImplementor session, String referencingPropertyName, + PersistentCollection newColl, + Serializable oldColl, Serializable id); + + void mapModifiedFlagsToMapFromEntity( + SessionImplementor session, + Map data, + Object newObj, + Object oldObj); - void mapModifiedFlagsToMapFromEntity(SessionImplementor session, Map data, Object newObj, Object oldObj); void mapModifiedFlagsToMapForCollectionChange(String collectionPropertyName, Map data); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/SimpleMapperBuilder.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/SimpleMapperBuilder.java index 6843e62c63..4e545f845b 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/SimpleMapperBuilder.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/SimpleMapperBuilder.java @@ -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,11 +22,12 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.internal.entities.mapper; + import org.hibernate.envers.internal.entities.PropertyData; /** * @author Adam Warski (adam at warski dot org) */ -public interface SimpleMapperBuilder { - public void add(PropertyData propertyData); +public interface SimpleMapperBuilder { + public void add(PropertyData propertyData); } \ No newline at end of file diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/SinglePropertyMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/SinglePropertyMapper.java index 329955604e..f45f026640 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/SinglePropertyMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/SinglePropertyMapper.java @@ -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 @@ -43,40 +43,53 @@ import org.hibernate.property.Setter; /** * TODO: diff + * * @author Adam Warski (adam at warski dot org) * @author Michal Skowronek (mskowr at o2 dot pl) */ public class SinglePropertyMapper implements PropertyMapper, SimpleMapperBuilder { - private PropertyData propertyData; + private PropertyData propertyData; - public SinglePropertyMapper(PropertyData propertyData) { - this.propertyData = propertyData; - } + public SinglePropertyMapper(PropertyData propertyData) { + this.propertyData = propertyData; + } - public SinglePropertyMapper() { } - - public void add(PropertyData propertyData) { - if (this.propertyData != null) { - throw new AuditException("Only one property can be added!"); - } - - this.propertyData = propertyData; - } - - public boolean mapToMapFromEntity(SessionImplementor session, Map data, Object newObj, Object oldObj) { - data.put(propertyData.getName(), newObj); - boolean dbLogicallyDifferent = true; - if ((session.getFactory().getDialect() instanceof Oracle8iDialect) && (newObj instanceof String || oldObj instanceof String)) { - // Don't generate new revision when database replaces empty string with NULL during INSERT or UPDATE statements. - dbLogicallyDifferent = !(StringTools.isEmpty(newObj) && StringTools.isEmpty(oldObj)); - } - return dbLogicallyDifferent && !Tools.objectsEqual(newObj, oldObj); - } + public SinglePropertyMapper() { + } @Override - public void mapModifiedFlagsToMapFromEntity(SessionImplementor session, Map data, Object newObj, Object oldObj) { - if (propertyData.isUsingModifiedFlag()) { - data.put(propertyData.getModifiedFlagPropertyName(), !Tools.objectsEqual(newObj, oldObj)); + public void add(PropertyData propertyData) { + if ( this.propertyData != null ) { + throw new AuditException( "Only one property can be added!" ); + } + + this.propertyData = propertyData; + } + + @Override + public boolean mapToMapFromEntity( + SessionImplementor session, + Map data, + Object newObj, + Object oldObj) { + data.put( propertyData.getName(), newObj ); + boolean dbLogicallyDifferent = true; + if ( (session.getFactory() + .getDialect() instanceof Oracle8iDialect) && (newObj instanceof String || oldObj instanceof String) ) { + // Don't generate new revision when database replaces empty string with NULL during INSERT or UPDATE statements. + dbLogicallyDifferent = !(StringTools.isEmpty( newObj ) && StringTools.isEmpty( oldObj )); + } + return dbLogicallyDifferent && !Tools.objectsEqual( newObj, oldObj ); + } + + @Override + public void mapModifiedFlagsToMapFromEntity( + SessionImplementor session, + Map data, + Object newObj, + Object oldObj) { + if ( propertyData.isUsingModifiedFlag() ) { + data.put( propertyData.getModifiedFlagPropertyName(), !Tools.objectsEqual( newObj, oldObj ) ); } } @@ -84,43 +97,50 @@ public class SinglePropertyMapper implements PropertyMapper, SimpleMapperBuilder public void mapModifiedFlagsToMapForCollectionChange(String collectionPropertyName, Map data) { } - public void mapToEntityFromMap(AuditConfiguration verCfg, Object obj, Map data, Object primaryKey, - AuditReaderImplementor versionsReader, Number revision) { - if (data == null || obj == null) { - return; - } - - Setter setter = ReflectionTools.getSetter(obj.getClass(), propertyData); - Object value = data.get(propertyData.getName()); - // We only set a null value if the field is not primite. Otherwise, we leave it intact. - if (value != null || !isPrimitive(setter, propertyData, obj.getClass())) { - setter.set(obj, value, null); + @Override + public void mapToEntityFromMap( + AuditConfiguration verCfg, Object obj, Map data, Object primaryKey, + AuditReaderImplementor versionsReader, Number revision) { + if ( data == null || obj == null ) { + return; } - } + + final Setter setter = ReflectionTools.getSetter( obj.getClass(), propertyData ); + final Object value = data.get( propertyData.getName() ); + // We only set a null value if the field is not primite. Otherwise, we leave it intact. + if ( value != null || !isPrimitive( setter, propertyData, obj.getClass() ) ) { + setter.set( obj, value, null ); + } + } private boolean isPrimitive(Setter setter, PropertyData propertyData, Class cls) { - if (cls == null) { - throw new HibernateException("No field found for property: " + propertyData.getName()); + if ( cls == null ) { + throw new HibernateException( "No field found for property: " + propertyData.getName() ); } - if (setter instanceof DirectPropertyAccessor.DirectSetter) { + if ( setter instanceof DirectPropertyAccessor.DirectSetter ) { // In a direct setter, getMethod() returns null // Trying to look up the field try { - return cls.getDeclaredField(propertyData.getBeanName()).getType().isPrimitive(); - } catch (NoSuchFieldException e) { - return isPrimitive(setter, propertyData, cls.getSuperclass()); + return cls.getDeclaredField( propertyData.getBeanName() ).getType().isPrimitive(); } - } else { + catch (NoSuchFieldException e) { + return isPrimitive( setter, propertyData, cls.getSuperclass() ); + } + } + else { return setter.getMethod().getParameterTypes()[0].isPrimitive(); } } - public List mapCollectionChanges(SessionImplementor sessionImplementor, - String referencingPropertyName, - PersistentCollection newColl, - Serializable oldColl, Serializable id) { - return null; - } + @Override + public List mapCollectionChanges( + SessionImplementor sessionImplementor, + String referencingPropertyName, + PersistentCollection newColl, + Serializable oldColl, + Serializable id) { + return null; + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/SubclassPropertyMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/SubclassPropertyMapper.java index f673d6e5a9..3696a30dd6 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/SubclassPropertyMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/SubclassPropertyMapper.java @@ -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.internal.entities.mapper; + import java.io.Serializable; import java.util.HashMap; import java.util.List; @@ -36,84 +37,124 @@ import org.hibernate.envers.internal.reader.AuditReaderImplementor; /** * A mapper which maps from a parent mapper and a "main" one, but adds only to the "main". The "main" mapper * should be the mapper of the subclass. + * * @author Adam Warski (adam at warski dot org) * @author Michal Skowronek (mskowr at o2 dot pl) */ public class SubclassPropertyMapper implements ExtendedPropertyMapper { - private ExtendedPropertyMapper main; - private ExtendedPropertyMapper parentMapper; + private ExtendedPropertyMapper main; + private ExtendedPropertyMapper parentMapper; - public SubclassPropertyMapper(ExtendedPropertyMapper main, ExtendedPropertyMapper parentMapper) { - this.main = main; - this.parentMapper = parentMapper; - } - - public boolean map(SessionImplementor session, Map data, String[] propertyNames, Object[] newState, Object[] oldState) { - boolean parentDiffs = parentMapper.map(session, data, propertyNames, newState, oldState); - boolean mainDiffs = main.map(session, data, propertyNames, newState, oldState); - - return parentDiffs || mainDiffs; - } - - public boolean mapToMapFromEntity(SessionImplementor session, Map data, Object newObj, Object oldObj) { - boolean parentDiffs = parentMapper.mapToMapFromEntity(session, data, newObj, oldObj); - boolean mainDiffs = main.mapToMapFromEntity(session, data, newObj, oldObj); - - return parentDiffs || mainDiffs; - } + public SubclassPropertyMapper(ExtendedPropertyMapper main, ExtendedPropertyMapper parentMapper) { + this.main = main; + this.parentMapper = parentMapper; + } @Override - public void mapModifiedFlagsToMapFromEntity(SessionImplementor session, Map data, Object newObj, Object oldObj) { - parentMapper.mapModifiedFlagsToMapFromEntity(session, data, newObj, oldObj); - main.mapModifiedFlagsToMapFromEntity(session, data, newObj, oldObj); + public boolean map( + SessionImplementor session, + Map data, + String[] propertyNames, + Object[] newState, + Object[] oldState) { + final boolean parentDiffs = parentMapper.map( session, data, propertyNames, newState, oldState ); + final boolean mainDiffs = main.map( session, data, propertyNames, newState, oldState ); + + return parentDiffs || mainDiffs; + } + + @Override + public boolean mapToMapFromEntity( + SessionImplementor session, + Map data, + Object newObj, + Object oldObj) { + final boolean parentDiffs = parentMapper.mapToMapFromEntity( session, data, newObj, oldObj ); + final boolean mainDiffs = main.mapToMapFromEntity( session, data, newObj, oldObj ); + + return parentDiffs || mainDiffs; + } + + @Override + public void mapModifiedFlagsToMapFromEntity( + SessionImplementor session, + Map data, + Object newObj, + Object oldObj) { + parentMapper.mapModifiedFlagsToMapFromEntity( session, data, newObj, oldObj ); + main.mapModifiedFlagsToMapFromEntity( session, data, newObj, oldObj ); } @Override public void mapModifiedFlagsToMapForCollectionChange(String collectionPropertyName, Map data) { - parentMapper.mapModifiedFlagsToMapForCollectionChange(collectionPropertyName, data); - main.mapModifiedFlagsToMapForCollectionChange(collectionPropertyName, data); + parentMapper.mapModifiedFlagsToMapForCollectionChange( collectionPropertyName, data ); + main.mapModifiedFlagsToMapForCollectionChange( collectionPropertyName, data ); } - public void mapToEntityFromMap(AuditConfiguration verCfg, Object obj, Map data, Object primaryKey, AuditReaderImplementor versionsReader, Number revision) { - parentMapper.mapToEntityFromMap(verCfg, obj, data, primaryKey, versionsReader, revision); - main.mapToEntityFromMap(verCfg, obj, data, primaryKey, versionsReader, revision); - } + @Override + public void mapToEntityFromMap( + AuditConfiguration verCfg, + Object obj, + Map data, + Object primaryKey, + AuditReaderImplementor versionsReader, + Number revision) { + parentMapper.mapToEntityFromMap( verCfg, obj, data, primaryKey, versionsReader, revision ); + main.mapToEntityFromMap( verCfg, obj, data, primaryKey, versionsReader, revision ); + } - public List mapCollectionChanges(SessionImplementor session, String referencingPropertyName, - PersistentCollection newColl, - Serializable oldColl, Serializable id) { - List parentCollectionChanges = parentMapper.mapCollectionChanges( - session, referencingPropertyName, newColl, oldColl, id); + @Override + public List mapCollectionChanges( + SessionImplementor session, String referencingPropertyName, + PersistentCollection newColl, + Serializable oldColl, Serializable id) { + final List parentCollectionChanges = parentMapper.mapCollectionChanges( + session, + referencingPropertyName, + newColl, + oldColl, + id + ); - List mainCollectionChanges = main.mapCollectionChanges( - session, referencingPropertyName, newColl, oldColl, id); + final List mainCollectionChanges = main.mapCollectionChanges( + session, + referencingPropertyName, + newColl, + oldColl, + id + ); - if (parentCollectionChanges == null) { - return mainCollectionChanges; - } else { - if(mainCollectionChanges != null) { - parentCollectionChanges.addAll(mainCollectionChanges); - } + if ( parentCollectionChanges == null ) { + return mainCollectionChanges; + } + else { + if ( mainCollectionChanges != null ) { + parentCollectionChanges.addAll( mainCollectionChanges ); + } return parentCollectionChanges; - } - } + } + } - public CompositeMapperBuilder addComponent(PropertyData propertyData, Class componentClass) { - return main.addComponent(propertyData, componentClass); - } + @Override + public CompositeMapperBuilder addComponent(PropertyData propertyData, Class componentClass) { + return main.addComponent( propertyData, componentClass ); + } - public void addComposite(PropertyData propertyData, PropertyMapper propertyMapper) { - main.addComposite(propertyData, propertyMapper); - } + @Override + public void addComposite(PropertyData propertyData, PropertyMapper propertyMapper) { + main.addComposite( propertyData, propertyMapper ); + } - public void add(PropertyData propertyData) { - main.add(propertyData); - } + @Override + public void add(PropertyData propertyData) { + main.add( propertyData ); + } + @Override public Map getProperties() { final Map joinedProperties = new HashMap(); - joinedProperties.putAll(parentMapper.getProperties()); - joinedProperties.putAll(main.getProperties()); + joinedProperties.putAll( parentMapper.getProperties() ); + joinedProperties.putAll( main.getProperties() ); return joinedProperties; } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/AbstractCompositeIdMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/AbstractCompositeIdMapper.java index c60531148a..7909a8880c 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/AbstractCompositeIdMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/AbstractCompositeIdMapper.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 @@ -35,36 +35,39 @@ import org.hibernate.internal.util.ReflectHelper; * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public abstract class AbstractCompositeIdMapper extends AbstractIdMapper implements SimpleIdMapperBuilder { - protected Map ids; - protected Class compositeIdClass; + protected Map ids; + protected Class compositeIdClass; - protected AbstractCompositeIdMapper(Class compositeIdClass) { - ids = Tools.newLinkedHashMap(); - this.compositeIdClass = compositeIdClass; - } + protected AbstractCompositeIdMapper(Class compositeIdClass) { + ids = Tools.newLinkedHashMap(); + this.compositeIdClass = compositeIdClass; + } - public void add(PropertyData propertyData) { - ids.put(propertyData, new SingleIdMapper(propertyData)); - } + @Override + public void add(PropertyData propertyData) { + ids.put( propertyData, new SingleIdMapper( propertyData ) ); + } - public Object mapToIdFromMap(Map data) { - if (data == null) { - return null; - } + @Override + public Object mapToIdFromMap(Map data) { + if ( data == null ) { + return null; + } - Object ret; - try { - ret = ReflectHelper.getDefaultConstructor(compositeIdClass).newInstance(); - } catch (Exception e) { - throw new AuditException(e); - } + final Object ret; + try { + ret = ReflectHelper.getDefaultConstructor( compositeIdClass ).newInstance(); + } + catch (Exception e) { + throw new AuditException( e ); + } - for (SingleIdMapper mapper : ids.values()) { - if (!mapper.mapToEntityFromMap(ret, data)) { - return null; - } - } + for ( SingleIdMapper mapper : ids.values() ) { + if ( !mapper.mapToEntityFromMap( ret, data ) ) { + return null; + } + } - return ret; - } + return ret; + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/AbstractIdMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/AbstractIdMapper.java index 111c7b6c54..28eb8dfa3c 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/AbstractIdMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/AbstractIdMapper.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.mapper.id; + import java.util.Iterator; import java.util.List; @@ -31,69 +32,96 @@ import org.hibernate.envers.internal.tools.query.Parameters; * @author Adam Warski (adam at warski dot org) */ public abstract class AbstractIdMapper implements IdMapper { - private Parameters getParametersToUse(Parameters parameters, List paramDatas) { - if (paramDatas.size() > 1) { - return parameters.addSubParameters("and"); - } else { - return parameters; - } - } + private Parameters getParametersToUse(Parameters parameters, List paramDatas) { + if ( paramDatas.size() > 1 ) { + return parameters.addSubParameters( "and" ); + } + else { + return parameters; + } + } - public void addIdsEqualToQuery(Parameters parameters, String prefix1, String prefix2) { - List paramDatas = mapToQueryParametersFromId(null); + @Override + public void addIdsEqualToQuery(Parameters parameters, String prefix1, String prefix2) { + final List paramDatas = mapToQueryParametersFromId( null ); - Parameters parametersToUse = getParametersToUse(parameters, paramDatas); + final Parameters parametersToUse = getParametersToUse( parameters, paramDatas ); - for (QueryParameterData paramData : paramDatas) { - parametersToUse.addWhere(paramData.getProperty(prefix1), false, "=", paramData.getProperty(prefix2), false); - } - } + for ( QueryParameterData paramData : paramDatas ) { + parametersToUse.addWhere( + paramData.getProperty( prefix1 ), + false, + "=", + paramData.getProperty( prefix2 ), + false + ); + } + } - public void addIdsEqualToQuery(Parameters parameters, String prefix1, IdMapper mapper2, String prefix2) { - List paramDatas1 = mapToQueryParametersFromId(null); - List paramDatas2 = mapper2.mapToQueryParametersFromId(null); + @Override + public void addIdsEqualToQuery(Parameters parameters, String prefix1, IdMapper mapper2, String prefix2) { + final List paramDatas1 = mapToQueryParametersFromId( null ); + final List paramDatas2 = mapper2.mapToQueryParametersFromId( null ); - Parameters parametersToUse = getParametersToUse(parameters, paramDatas1); + final Parameters parametersToUse = getParametersToUse( parameters, paramDatas1 ); - Iterator paramDataIter1 = paramDatas1.iterator(); - Iterator paramDataIter2 = paramDatas2.iterator(); - while (paramDataIter1.hasNext()) { - QueryParameterData paramData1 = paramDataIter1.next(); - QueryParameterData paramData2 = paramDataIter2.next(); + final Iterator paramDataIter1 = paramDatas1.iterator(); + final Iterator paramDataIter2 = paramDatas2.iterator(); + while ( paramDataIter1.hasNext() ) { + final QueryParameterData paramData1 = paramDataIter1.next(); + final QueryParameterData paramData2 = paramDataIter2.next(); - parametersToUse.addWhere(paramData1.getProperty(prefix1), false, "=", paramData2.getProperty(prefix2), false); - } - } + parametersToUse.addWhere( + paramData1.getProperty( prefix1 ), + false, + "=", + paramData2.getProperty( prefix2 ), + false + ); + } + } - public void addIdEqualsToQuery(Parameters parameters, Object id, String prefix, boolean equals) { - List paramDatas = mapToQueryParametersFromId(id); + @Override + public void addIdEqualsToQuery(Parameters parameters, Object id, String prefix, boolean equals) { + final List paramDatas = mapToQueryParametersFromId( id ); - Parameters parametersToUse = getParametersToUse(parameters, paramDatas); + final Parameters parametersToUse = getParametersToUse( parameters, paramDatas ); - for (QueryParameterData paramData : paramDatas) { - if (paramData.getValue() == null) { - handleNullValue(parametersToUse, paramData.getProperty(prefix), equals); - } else { - parametersToUse.addWhereWithParam(paramData.getProperty(prefix), equals ? "=" : "<>", paramData.getValue()); - } - } - } + for ( QueryParameterData paramData : paramDatas ) { + if ( paramData.getValue() == null ) { + handleNullValue( parametersToUse, paramData.getProperty( prefix ), equals ); + } + else { + parametersToUse.addWhereWithParam( + paramData.getProperty( prefix ), + equals ? "=" : "<>", + paramData.getValue() + ); + } + } + } - public void addNamedIdEqualsToQuery(Parameters parameters, String prefix, boolean equals) { - List paramDatas = mapToQueryParametersFromId(null); + @Override + public void addNamedIdEqualsToQuery(Parameters parameters, String prefix, boolean equals) { + final List paramDatas = mapToQueryParametersFromId( null ); - Parameters parametersToUse = getParametersToUse(parameters, paramDatas); + final Parameters parametersToUse = getParametersToUse( parameters, paramDatas ); - for (QueryParameterData paramData : paramDatas) { - parametersToUse.addWhereWithNamedParam(paramData.getProperty(prefix), equals ? "=" : "<>", paramData.getQueryParameterName()); - } - } + for ( QueryParameterData paramData : paramDatas ) { + parametersToUse.addWhereWithNamedParam( + paramData.getProperty( prefix ), + equals ? "=" : "<>", + paramData.getQueryParameterName() + ); + } + } - private void handleNullValue(Parameters parameters, String propertyName, boolean equals) { - if (equals) { - parameters.addNullRestriction(propertyName, equals); - } else { - parameters.addNotNullRestriction(propertyName, equals); - } - } + private void handleNullValue(Parameters parameters, String propertyName, boolean equals) { + if ( equals ) { + parameters.addNullRestriction( propertyName, equals ); + } + else { + parameters.addNotNullRestriction( propertyName, equals ); + } + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/EmbeddedIdMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/EmbeddedIdMapper.java index 4cdc539f91..f965d39f9d 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/EmbeddedIdMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/EmbeddedIdMapper.java @@ -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 @@ -39,85 +39,92 @@ import org.hibernate.property.Setter; * @author Adam Warski (adam at warski dot org) */ public class EmbeddedIdMapper extends AbstractCompositeIdMapper implements SimpleIdMapperBuilder { - private PropertyData idPropertyData; + private PropertyData idPropertyData; - public EmbeddedIdMapper(PropertyData idPropertyData, Class compositeIdClass) { - super(compositeIdClass); + public EmbeddedIdMapper(PropertyData idPropertyData, Class compositeIdClass) { + super( compositeIdClass ); - this.idPropertyData = idPropertyData; - } + this.idPropertyData = idPropertyData; + } - public void mapToMapFromId(Map data, Object obj) { - for (IdMapper idMapper : ids.values()) { - idMapper.mapToMapFromEntity(data, obj); - } - } + @Override + public void mapToMapFromId(Map data, Object obj) { + for ( IdMapper idMapper : ids.values() ) { + idMapper.mapToMapFromEntity( data, obj ); + } + } - public void mapToMapFromEntity(Map data, Object obj) { - if (obj == null) { - return; - } + @Override + public void mapToMapFromEntity(Map data, Object obj) { + if ( obj == null ) { + return; + } - Getter getter = ReflectionTools.getGetter(obj.getClass(), idPropertyData); - mapToMapFromId(data, getter.get(obj)); - } + final Getter getter = ReflectionTools.getGetter( obj.getClass(), idPropertyData ); + mapToMapFromId( data, getter.get( obj ) ); + } - public boolean mapToEntityFromMap(Object obj, Map data) { - if (data == null || obj == null) { - return false; - } + @Override + public boolean mapToEntityFromMap(Object obj, Map data) { + if ( data == null || obj == null ) { + return false; + } - Getter getter = ReflectionTools.getGetter(obj.getClass(), idPropertyData); - Setter setter = ReflectionTools.getSetter(obj.getClass(), idPropertyData); + final Getter getter = ReflectionTools.getGetter( obj.getClass(), idPropertyData ); + final Setter setter = ReflectionTools.getSetter( obj.getClass(), idPropertyData ); - try { - Object subObj = ReflectHelper.getDefaultConstructor( getter.getReturnType() ).newInstance(); + try { + final Object subObj = ReflectHelper.getDefaultConstructor( getter.getReturnType() ).newInstance(); - boolean ret = true; - for (IdMapper idMapper : ids.values()) { - ret &= idMapper.mapToEntityFromMap(subObj, data); - } + boolean ret = true; + for ( IdMapper idMapper : ids.values() ) { + ret &= idMapper.mapToEntityFromMap( subObj, data ); + } - if (ret) { - setter.set(obj, subObj, null); - } + if ( ret ) { + setter.set( obj, subObj, null ); + } - return ret; - } catch (Exception e) { - throw new AuditException(e); - } - } + return ret; + } + catch (Exception e) { + throw new AuditException( e ); + } + } - public IdMapper prefixMappedProperties(String prefix) { - EmbeddedIdMapper ret = new EmbeddedIdMapper(idPropertyData, compositeIdClass); + @Override + public IdMapper prefixMappedProperties(String prefix) { + final EmbeddedIdMapper ret = new EmbeddedIdMapper( idPropertyData, compositeIdClass ); - for (PropertyData propertyData : ids.keySet()) { - String propertyName = propertyData.getName(); - ret.ids.put(propertyData, new SingleIdMapper(new PropertyData(prefix + propertyName, propertyData))); - } + for ( PropertyData propertyData : ids.keySet() ) { + final String propertyName = propertyData.getName(); + ret.ids.put( propertyData, new SingleIdMapper( new PropertyData( prefix + propertyName, propertyData ) ) ); + } - return ret; - } + return ret; + } - public Object mapToIdFromEntity(Object data) { - if (data == null) { - return null; - } + @Override + public Object mapToIdFromEntity(Object data) { + if ( data == null ) { + return null; + } - Getter getter = ReflectionTools.getGetter(data.getClass(), idPropertyData); - return getter.get(data); - } + final Getter getter = ReflectionTools.getGetter( data.getClass(), idPropertyData ); + return getter.get( data ); + } - public List mapToQueryParametersFromId(Object obj) { - Map data = new LinkedHashMap(); - mapToMapFromId(data, obj); + @Override + public List mapToQueryParametersFromId(Object obj) { + final Map data = new LinkedHashMap(); + mapToMapFromId( data, obj ); - List ret = new ArrayList(); + final List ret = new ArrayList(); - for (Map.Entry propertyData : data.entrySet()) { - ret.add(new QueryParameterData(propertyData.getKey(), propertyData.getValue())); - } + for ( Map.Entry propertyData : data.entrySet() ) { + ret.add( new QueryParameterData( propertyData.getKey(), propertyData.getValue() ) ); + } - return ret; - } + return ret; + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/IdMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/IdMapper.java index c490b1ea1f..b292ad0fd8 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/IdMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/IdMapper.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.internal.entities.mapper.id; + import java.util.List; import java.util.Map; @@ -31,73 +32,81 @@ import org.hibernate.envers.internal.tools.query.Parameters; * @author Adam Warski (adam at warski dot org) */ public interface IdMapper { - void mapToMapFromId(Map data, Object obj); + void mapToMapFromId(Map data, Object obj); - void mapToMapFromEntity(Map data, Object obj); + void mapToMapFromEntity(Map data, Object obj); - /** - * @param obj Object to map to. - * @param data Data to map. - * @return True if data was mapped; false otherwise (when the id is {@code null}). - */ - boolean mapToEntityFromMap(Object obj, Map data); + /** + * @param obj Object to map to. + * @param data Data to map. + * + * @return True if data was mapped; false otherwise (when the id is {@code null}). + */ + boolean mapToEntityFromMap(Object obj, Map data); - Object mapToIdFromEntity(Object data); + Object mapToIdFromEntity(Object data); - Object mapToIdFromMap(Map data); + Object mapToIdFromMap(Map data); - /** - * Creates a mapper with all mapped properties prefixed. A mapped property is a property which - * is directly mapped to values (not composite). - * @param prefix Prefix to add to mapped properties - * @return A copy of the current property mapper, with mapped properties prefixed. - */ - IdMapper prefixMappedProperties(String prefix); + /** + * Creates a mapper with all mapped properties prefixed. A mapped property is a property which + * is directly mapped to values (not composite). + * + * @param prefix Prefix to add to mapped properties + * + * @return A copy of the current property mapper, with mapped properties prefixed. + */ + IdMapper prefixMappedProperties(String prefix); - /** - * @param obj Id from which to map. - * @return A set parameter data, needed to build a query basing on the given id. - */ - List mapToQueryParametersFromId(Object obj); + /** + * @param obj Id from which to map. + * + * @return A set parameter data, needed to build a query basing on the given id. + */ + List mapToQueryParametersFromId(Object obj); - /** - * Adds query statements, which contains restrictions, which express the property that the id of the entity - * with alias prefix1, is equal to the id of the entity with alias prefix2 (the entity is the same). - * @param parameters Parameters, to which to add the statements. - * @param prefix1 First alias of the entity + prefix to add to the properties. - * @param prefix2 Second alias of the entity + prefix to add to the properties. - */ - void addIdsEqualToQuery(Parameters parameters, String prefix1, String prefix2); + /** + * Adds query statements, which contains restrictions, which express the property that the id of the entity + * with alias prefix1, is equal to the id of the entity with alias prefix2 (the entity is the same). + * + * @param parameters Parameters, to which to add the statements. + * @param prefix1 First alias of the entity + prefix to add to the properties. + * @param prefix2 Second alias of the entity + prefix to add to the properties. + */ + void addIdsEqualToQuery(Parameters parameters, String prefix1, String prefix2); - /** - * Adds query statements, which contains restrictions, which express the property that the id of the entity - * with alias prefix1, is equal to the id of the entity with alias prefix2 mapped by the second mapper - * (the second mapper must be for the same entity, but it can have, for example, prefixed properties). - * @param parameters Parameters, to which to add the statements. - * @param prefix1 First alias of the entity + prefix to add to the properties. - * @param mapper2 Second mapper for the same entity, which will be used to get properties for the right side - * of the equation. - * @param prefix2 Second alias of the entity + prefix to add to the properties. - */ - void addIdsEqualToQuery(Parameters parameters, String prefix1, IdMapper mapper2, String prefix2); + /** + * Adds query statements, which contains restrictions, which express the property that the id of the entity + * with alias prefix1, is equal to the id of the entity with alias prefix2 mapped by the second mapper + * (the second mapper must be for the same entity, but it can have, for example, prefixed properties). + * + * @param parameters Parameters, to which to add the statements. + * @param prefix1 First alias of the entity + prefix to add to the properties. + * @param mapper2 Second mapper for the same entity, which will be used to get properties for the right side + * of the equation. + * @param prefix2 Second alias of the entity + prefix to add to the properties. + */ + void addIdsEqualToQuery(Parameters parameters, String prefix1, IdMapper mapper2, String prefix2); - /** - * Adds query statements, which contains restrictions, which express the property that the id of the entity - * with alias prefix, is equal to the given object. - * @param parameters Parameters, to which to add the statements. - * @param id Value of id. - * @param prefix Prefix to add to the properties (may be null). - * @param equals Should this query express the "=" relation or the "<>" relation. - */ - void addIdEqualsToQuery(Parameters parameters, Object id, String prefix, boolean equals); + /** + * Adds query statements, which contains restrictions, which express the property that the id of the entity + * with alias prefix, is equal to the given object. + * + * @param parameters Parameters, to which to add the statements. + * @param id Value of id. + * @param prefix Prefix to add to the properties (may be null). + * @param equals Should this query express the "=" relation or the "<>" relation. + */ + void addIdEqualsToQuery(Parameters parameters, Object id, String prefix, boolean equals); - /** - * Adds query statements, which contains named parameters, which express the property that the id of the entity - * with alias prefix, is equal to the given object. It is the responsibility of the using method to read - * parameter values from the id and specify them on the final query object. - * @param parameters Parameters, to which to add the statements. - * @param prefix Prefix to add to the properties (may be null). - * @param equals Should this query express the "=" relation or the "<>" relation. - */ - void addNamedIdEqualsToQuery(Parameters parameters, String prefix, boolean equals); + /** + * Adds query statements, which contains named parameters, which express the property that the id of the entity + * with alias prefix, is equal to the given object. It is the responsibility of the using method to read + * parameter values from the id and specify them on the final query object. + * + * @param parameters Parameters, to which to add the statements. + * @param prefix Prefix to add to the properties (may be null). + * @param equals Should this query express the "=" relation or the "<>" relation. + */ + void addNamedIdEqualsToQuery(Parameters parameters, String prefix, boolean equals); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/MultipleIdMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/MultipleIdMapper.java index 25f5e4a1a5..aadf588ac3 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/MultipleIdMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/MultipleIdMapper.java @@ -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 @@ -36,69 +36,76 @@ import org.hibernate.internal.util.ReflectHelper; * @author Adam Warski (adam at warski dot org) */ public class MultipleIdMapper extends AbstractCompositeIdMapper implements SimpleIdMapperBuilder { - public MultipleIdMapper(Class compositeIdClass) { - super(compositeIdClass); - } + public MultipleIdMapper(Class compositeIdClass) { + super( compositeIdClass ); + } - public void mapToMapFromId(Map data, Object obj) { - for (IdMapper idMapper : ids.values()) { - idMapper.mapToMapFromEntity(data, obj); - } - } + @Override + public void mapToMapFromId(Map data, Object obj) { + for ( IdMapper idMapper : ids.values() ) { + idMapper.mapToMapFromEntity( data, obj ); + } + } - public void mapToMapFromEntity(Map data, Object obj) { - mapToMapFromId(data, obj); - } + @Override + public void mapToMapFromEntity(Map data, Object obj) { + mapToMapFromId( data, obj ); + } - public boolean mapToEntityFromMap(Object obj, Map data) { - boolean ret = true; - for (IdMapper idMapper : ids.values()) { - ret &= idMapper.mapToEntityFromMap(obj, data); - } + @Override + public boolean mapToEntityFromMap(Object obj, Map data) { + boolean ret = true; + for ( IdMapper idMapper : ids.values() ) { + ret &= idMapper.mapToEntityFromMap( obj, data ); + } - return ret; - } + return ret; + } - public IdMapper prefixMappedProperties(String prefix) { - MultipleIdMapper ret = new MultipleIdMapper(compositeIdClass); + @Override + public IdMapper prefixMappedProperties(String prefix) { + final MultipleIdMapper ret = new MultipleIdMapper( compositeIdClass ); - for (PropertyData propertyData : ids.keySet()) { - String propertyName = propertyData.getName(); - ret.ids.put(propertyData, new SingleIdMapper(new PropertyData(prefix + propertyName, propertyData))); - } + for ( PropertyData propertyData : ids.keySet() ) { + final String propertyName = propertyData.getName(); + ret.ids.put( propertyData, new SingleIdMapper( new PropertyData( prefix + propertyName, propertyData ) ) ); + } - return ret; - } + return ret; + } - public Object mapToIdFromEntity(Object data) { - if (data == null) { - return null; - } + @Override + public Object mapToIdFromEntity(Object data) { + if ( data == null ) { + return null; + } - Object ret; - try { - ret = ReflectHelper.getDefaultConstructor(compositeIdClass).newInstance(); - } catch (Exception e) { - throw new AuditException(e); - } + final Object ret; + try { + ret = ReflectHelper.getDefaultConstructor( compositeIdClass ).newInstance(); + } + catch (Exception e) { + throw new AuditException( e ); + } - for (SingleIdMapper mapper : ids.values()) { - mapper.mapToEntityFromEntity(ret, data); - } + for ( SingleIdMapper mapper : ids.values() ) { + mapper.mapToEntityFromEntity( ret, data ); + } - return ret; - } + return ret; + } - public List mapToQueryParametersFromId(Object obj) { - Map data = new LinkedHashMap(); - mapToMapFromId(data, obj); + @Override + public List mapToQueryParametersFromId(Object obj) { + final Map data = new LinkedHashMap(); + mapToMapFromId( data, obj ); - List ret = new ArrayList(); + final List ret = new ArrayList(); - for (Map.Entry propertyData : data.entrySet()) { - ret.add(new QueryParameterData(propertyData.getKey(), propertyData.getValue())); - } + for ( Map.Entry propertyData : data.entrySet() ) { + ret.add( new QueryParameterData( propertyData.getKey(), propertyData.getValue() ) ); + } - return ret; - } + return ret; + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/QueryParameterData.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/QueryParameterData.java index 75201a220d..a87c2d6dae 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/QueryParameterData.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/QueryParameterData.java @@ -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,53 +22,58 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.internal.entities.mapper.id; + import org.hibernate.Query; +import org.hibernate.internal.util.compare.EqualsHelper; /** * @author Adam Warski (adam at warski dot org) */ public class QueryParameterData { - private String flatEntityPropertyName; - private Object value; + private String flatEntityPropertyName; + private Object value; - public QueryParameterData(String flatEntityPropertyName, Object value) { - this.flatEntityPropertyName = flatEntityPropertyName; - this.value = value; - } + public QueryParameterData(String flatEntityPropertyName, Object value) { + this.flatEntityPropertyName = flatEntityPropertyName; + this.value = value; + } - public String getProperty(String prefix) { - if (prefix != null) { - return prefix + "." + flatEntityPropertyName; - } else { - return flatEntityPropertyName; - } - } + public String getProperty(String prefix) { + if ( prefix != null ) { + return prefix + "." + flatEntityPropertyName; + } + else { + return flatEntityPropertyName; + } + } - public Object getValue() { - return value; - } + public Object getValue() { + return value; + } - public void setParameterValue(Query query) { - query.setParameter(flatEntityPropertyName, value); - } + public void setParameterValue(Query query) { + query.setParameter( flatEntityPropertyName, value ); + } - public String getQueryParameterName() { - return flatEntityPropertyName; - } + public String getQueryParameterName() { + return flatEntityPropertyName; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof QueryParameterData)) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof QueryParameterData) ) { + return false; + } - QueryParameterData that = (QueryParameterData) o; + final QueryParameterData that = (QueryParameterData) o; + return EqualsHelper.equals( flatEntityPropertyName, that.flatEntityPropertyName ); + } - if (flatEntityPropertyName != null ? !flatEntityPropertyName.equals(that.flatEntityPropertyName) : that.flatEntityPropertyName != null) - return false; - - return true; - } - - public int hashCode() { - return (flatEntityPropertyName != null ? flatEntityPropertyName.hashCode() : 0); - } + @Override + public int hashCode() { + return (flatEntityPropertyName != null ? flatEntityPropertyName.hashCode() : 0); + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/SimpleIdMapperBuilder.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/SimpleIdMapperBuilder.java index 12039e4de2..65bfc8d643 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/SimpleIdMapperBuilder.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/SimpleIdMapperBuilder.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.internal.entities.mapper.id; + import org.hibernate.envers.internal.entities.mapper.SimpleMapperBuilder; /** diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/SingleIdMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/SingleIdMapper.java index 0f14c16c4f..376c36f937 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/SingleIdMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/SingleIdMapper.java @@ -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 @@ -38,100 +38,111 @@ import org.hibernate.proxy.HibernateProxy; * @author Adam Warski (adam at warski dot org) */ public class SingleIdMapper extends AbstractIdMapper implements SimpleIdMapperBuilder { - private PropertyData propertyData; + private PropertyData propertyData; - public SingleIdMapper() { - } + public SingleIdMapper() { + } - public SingleIdMapper(PropertyData propertyData) { - this.propertyData = propertyData; - } + public SingleIdMapper(PropertyData propertyData) { + this.propertyData = propertyData; + } - public void add(PropertyData propertyData) { - if (this.propertyData != null) { - throw new AuditException("Only one property can be added!"); - } + @Override + public void add(PropertyData propertyData) { + if ( this.propertyData != null ) { + throw new AuditException( "Only one property can be added!" ); + } - this.propertyData = propertyData; - } + this.propertyData = propertyData; + } - public boolean mapToEntityFromMap(Object obj, Map data) { - if (data == null || obj == null) { - return false; - } + @Override + public boolean mapToEntityFromMap(Object obj, Map data) { + if ( data == null || obj == null ) { + return false; + } - Object value = data.get(propertyData.getName()); - if (value == null) { - return false; - } + final Object value = data.get( propertyData.getName() ); + if ( value == null ) { + return false; + } - Setter setter = ReflectionTools.getSetter(obj.getClass(), propertyData); - setter.set(obj, value, null); + final Setter setter = ReflectionTools.getSetter( obj.getClass(), propertyData ); + setter.set( obj, value, null ); - return true; - } + return true; + } - public Object mapToIdFromMap(Map data) { - if (data == null) { - return null; - } + @Override + public Object mapToIdFromMap(Map data) { + if ( data == null ) { + return null; + } - return data.get(propertyData.getName()); - } + return data.get( propertyData.getName() ); + } - public Object mapToIdFromEntity(Object data) { - if (data == null) { - return null; - } + @Override + public Object mapToIdFromEntity(Object data) { + if ( data == null ) { + return null; + } - if(data instanceof HibernateProxy) { - HibernateProxy hibernateProxy = (HibernateProxy) data; - return hibernateProxy.getHibernateLazyInitializer().getIdentifier(); - } else { - Getter getter = ReflectionTools.getGetter(data.getClass(), propertyData); - return getter.get(data); - } - } + if ( data instanceof HibernateProxy ) { + final HibernateProxy hibernateProxy = (HibernateProxy) data; + return hibernateProxy.getHibernateLazyInitializer().getIdentifier(); + } + else { + final Getter getter = ReflectionTools.getGetter( data.getClass(), propertyData ); + return getter.get( data ); + } + } - public void mapToMapFromId(Map data, Object obj) { - if (data != null) { - data.put(propertyData.getName(), obj); - } - } + @Override + public void mapToMapFromId(Map data, Object obj) { + if ( data != null ) { + data.put( propertyData.getName(), obj ); + } + } - public void mapToMapFromEntity(Map data, Object obj) { - if (obj == null) { - data.put(propertyData.getName(), null); - } else { - if(obj instanceof HibernateProxy) { - HibernateProxy hibernateProxy = (HibernateProxy)obj; - data.put(propertyData.getName(), hibernateProxy.getHibernateLazyInitializer().getIdentifier()); - } else { - Getter getter = ReflectionTools.getGetter(obj.getClass(), propertyData); - data.put(propertyData.getName(), getter.get(obj)); - } - } - } + @Override + public void mapToMapFromEntity(Map data, Object obj) { + if ( obj == null ) { + data.put( propertyData.getName(), null ); + } + else { + if ( obj instanceof HibernateProxy ) { + final HibernateProxy hibernateProxy = (HibernateProxy) obj; + data.put( propertyData.getName(), hibernateProxy.getHibernateLazyInitializer().getIdentifier() ); + } + else { + final Getter getter = ReflectionTools.getGetter( obj.getClass(), propertyData ); + data.put( propertyData.getName(), getter.get( obj ) ); + } + } + } - public void mapToEntityFromEntity(Object objTo, Object objFrom) { - if (objTo == null || objFrom == null) { - return; - } + public void mapToEntityFromEntity(Object objTo, Object objFrom) { + if ( objTo == null || objFrom == null ) { + return; + } - Getter getter = ReflectionTools.getGetter(objFrom.getClass(), propertyData); - Setter setter = ReflectionTools.getSetter(objTo.getClass(), propertyData); - setter.set(objTo, getter.get(objFrom), null); - } + final Getter getter = ReflectionTools.getGetter( objFrom.getClass(), propertyData ); + final Setter setter = ReflectionTools.getSetter( objTo.getClass(), propertyData ); + setter.set( objTo, getter.get( objFrom ), null ); + } - public IdMapper prefixMappedProperties(String prefix) { - return new SingleIdMapper(new PropertyData(prefix + propertyData.getName(), propertyData)); - } + @Override + public IdMapper prefixMappedProperties(String prefix) { + return new SingleIdMapper( new PropertyData( prefix + propertyData.getName(), propertyData ) ); + } - public List mapToQueryParametersFromId(Object obj) { - List ret = new ArrayList(); + @Override + public List mapToQueryParametersFromId(Object obj) { + final List ret = new ArrayList(); - ret.add(new QueryParameterData(propertyData.getName(), obj)); + ret.add( new QueryParameterData( propertyData.getName(), obj ) ); - return ret; - } + return ret; + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/AbstractCollectionMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/AbstractCollectionMapper.java index a06cc6270a..dbf7443853 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/AbstractCollectionMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/AbstractCollectionMapper.java @@ -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 @@ -53,43 +53,53 @@ import org.hibernate.property.Setter; * @author Michal Skowronek (mskowr at o2 dot pl) */ public abstract class AbstractCollectionMapper implements PropertyMapper { - protected final CommonCollectionMapperData commonCollectionMapperData; - protected final Class collectionClass; - protected final boolean ordinalInId; + protected final CommonCollectionMapperData commonCollectionMapperData; + protected final Class collectionClass; + protected final boolean ordinalInId; protected final boolean revisionTypeInId; - private final Constructor proxyConstructor; + private final Constructor proxyConstructor; - protected AbstractCollectionMapper(CommonCollectionMapperData commonCollectionMapperData, + protected AbstractCollectionMapper( + CommonCollectionMapperData commonCollectionMapperData, Class collectionClass, Class proxyClass, boolean ordinalInId, boolean revisionTypeInId) { - this.commonCollectionMapperData = commonCollectionMapperData; - this.collectionClass = collectionClass; + this.commonCollectionMapperData = commonCollectionMapperData; + this.collectionClass = collectionClass; this.ordinalInId = ordinalInId; this.revisionTypeInId = revisionTypeInId; - try { - proxyConstructor = proxyClass.getConstructor(Initializor.class); - } catch (NoSuchMethodException e) { - throw new AuditException(e); - } - } + try { + proxyConstructor = proxyClass.getConstructor( Initializor.class ); + } + catch (NoSuchMethodException e) { + throw new AuditException( e ); + } + } - protected abstract Collection getNewCollectionContent(PersistentCollection newCollection); - protected abstract Collection getOldCollectionContent(Serializable oldCollection); + protected abstract Collection getNewCollectionContent(PersistentCollection newCollection); - /** - * Maps the changed collection element to the given map. + protected abstract Collection getOldCollectionContent(Serializable oldCollection); + + /** + * Maps the changed collection element to the given map. + * * @param idData Map to which composite-id data should be added. - * @param data Where to map the data. - * @param changed The changed collection element to map. - */ - protected abstract void mapToMapFromObject(SessionImplementor session, Map idData, Map data, Object changed); + * @param data Where to map the data. + * @param changed The changed collection element to map. + */ + protected abstract void mapToMapFromObject( + SessionImplementor session, + Map idData, + Map data, + Object changed); /** * Creates map for storing identifier data. Ordinal parameter guarantees uniqueness of primary key. * Composite primary key cannot contain embeddable properties since they might be nullable. + * * @param ordinal Iteration ordinal. + * * @return Map for holding identifier data. */ protected Map createIdMap(int ordinal) { @@ -100,79 +110,113 @@ public abstract class AbstractCollectionMapper implements PropertyMapper { return idMap; } - private void addCollectionChanges(SessionImplementor session, List collectionChanges, - Set changed, RevisionType revisionType, Serializable id) { + private void addCollectionChanges( + SessionImplementor session, List collectionChanges, + Set changed, RevisionType revisionType, Serializable id) { int ordinal = 0; - for (Object changedObj : changed) { - Map entityData = new HashMap(); - Map originalId = createIdMap( ordinal++ ); - entityData.put(commonCollectionMapperData.getVerEntCfg().getOriginalIdPropName(), originalId); + for ( Object changedObj : changed ) { + final Map entityData = new HashMap(); + final Map originalId = createIdMap( ordinal++ ); + entityData.put( commonCollectionMapperData.getVerEntCfg().getOriginalIdPropName(), originalId ); - collectionChanges.add(new PersistentCollectionChangeData( - commonCollectionMapperData.getVersionsMiddleEntityName(), entityData, changedObj)); - // Mapping the collection owner's id. - commonCollectionMapperData.getReferencingIdData().getPrefixedMapper().mapToMapFromId(originalId, id); + collectionChanges.add( + new PersistentCollectionChangeData( + commonCollectionMapperData.getVersionsMiddleEntityName(), entityData, changedObj + ) + ); + // Mapping the collection owner's id. + commonCollectionMapperData.getReferencingIdData().getPrefixedMapper().mapToMapFromId( originalId, id ); - // Mapping collection element and index (if present). - mapToMapFromObject(session, originalId, entityData, changedObj); + // Mapping collection element and index (if present). + mapToMapFromObject( session, originalId, entityData, changedObj ); - (revisionTypeInId ? originalId : entityData).put(commonCollectionMapperData.getVerEntCfg().getRevisionTypePropName(), revisionType); - } - } - - @SuppressWarnings({"unchecked"}) - public List mapCollectionChanges(SessionImplementor session, - String referencingPropertyName, - PersistentCollection newColl, - Serializable oldColl, Serializable id) { - if (!commonCollectionMapperData.getCollectionReferencingPropertyData().getName().equals(referencingPropertyName)) { - return null; - } - - List collectionChanges = new ArrayList(); - - // Comparing new and old collection content. - Collection newCollection = getNewCollectionContent(newColl); - Collection oldCollection = getOldCollectionContent(oldColl); - - Set added = new HashSet(); - if (newColl != null) { added.addAll(newCollection); } - // Re-hashing the old collection as the hash codes of the elements there may have changed, and the - // removeAll in AbstractSet has an implementation that is hashcode-change sensitive (as opposed to addAll). - if (oldColl != null) { added.removeAll(new HashSet(oldCollection)); } - - addCollectionChanges(session, collectionChanges, added, RevisionType.ADD, id); - - Set deleted = new HashSet(); - if (oldColl != null) { deleted.addAll(oldCollection); } - // The same as above - re-hashing new collection. - if (newColl != null) { deleted.removeAll(new HashSet(newCollection)); } - - addCollectionChanges(session, collectionChanges, deleted, RevisionType.DEL, id); - - return collectionChanges; - } - - public boolean mapToMapFromEntity(SessionImplementor session, Map data, Object newObj, Object oldObj) { - // Changes are mapped in the "mapCollectionChanges" method. - return false; - } + (revisionTypeInId ? originalId : entityData).put( + commonCollectionMapperData.getVerEntCfg() + .getRevisionTypePropName(), revisionType + ); + } + } @Override - public void mapModifiedFlagsToMapFromEntity(SessionImplementor session, Map data, Object newObj, Object oldObj) { - PropertyData propertyData = commonCollectionMapperData.getCollectionReferencingPropertyData(); - if (propertyData.isUsingModifiedFlag()) { - if (isNotPersistentCollection(newObj) || isNotPersistentCollection(oldObj)) { + @SuppressWarnings({"unchecked"}) + public List mapCollectionChanges( + SessionImplementor session, + String referencingPropertyName, + PersistentCollection newColl, + Serializable oldColl, Serializable id) { + if ( !commonCollectionMapperData.getCollectionReferencingPropertyData().getName().equals( + referencingPropertyName + ) ) { + return null; + } + + final List collectionChanges = new ArrayList(); + + // Comparing new and old collection content. + final Collection newCollection = getNewCollectionContent( newColl ); + final Collection oldCollection = getOldCollectionContent( oldColl ); + + final Set added = new HashSet(); + if ( newColl != null ) { + added.addAll( newCollection ); + } + // Re-hashing the old collection as the hash codes of the elements there may have changed, and the + // removeAll in AbstractSet has an implementation that is hashcode-change sensitive (as opposed to addAll). + if ( oldColl != null ) { + added.removeAll( new HashSet( oldCollection ) ); + } + + addCollectionChanges( session, collectionChanges, added, RevisionType.ADD, id ); + + final Set deleted = new HashSet(); + if ( oldColl != null ) { + deleted.addAll( oldCollection ); + } + // The same as above - re-hashing new collection. + if ( newColl != null ) { + deleted.removeAll( new HashSet( newCollection ) ); + } + + addCollectionChanges( session, collectionChanges, deleted, RevisionType.DEL, id ); + + return collectionChanges; + } + + @Override + public boolean mapToMapFromEntity( + SessionImplementor session, + Map data, + Object newObj, + Object oldObj) { + // Changes are mapped in the "mapCollectionChanges" method. + return false; + } + + @Override + public void mapModifiedFlagsToMapFromEntity( + SessionImplementor session, + Map data, + Object newObj, + Object oldObj) { + final PropertyData propertyData = commonCollectionMapperData.getCollectionReferencingPropertyData(); + if ( propertyData.isUsingModifiedFlag() ) { + if ( isNotPersistentCollection( newObj ) || isNotPersistentCollection( oldObj ) ) { // Compare POJOs. - data.put(propertyData.getModifiedFlagPropertyName(), !Tools.objectsEqual(newObj, oldObj)); - } else if (isFromNullToEmptyOrFromEmptyToNull((PersistentCollection) newObj, (Serializable) oldObj)) { - data.put(propertyData.getModifiedFlagPropertyName(), true); - } else { - List changes = mapCollectionChanges(session, - commonCollectionMapperData.getCollectionReferencingPropertyData().getName(), - (PersistentCollection) newObj, (Serializable) oldObj, null); - data.put(propertyData.getModifiedFlagPropertyName(), !changes.isEmpty()); + data.put( propertyData.getModifiedFlagPropertyName(), !Tools.objectsEqual( newObj, oldObj ) ); + } + else if ( isFromNullToEmptyOrFromEmptyToNull( (PersistentCollection) newObj, (Serializable) oldObj ) ) { + data.put( propertyData.getModifiedFlagPropertyName(), true ); + } + else { + final List changes = mapCollectionChanges( + session, + commonCollectionMapperData.getCollectionReferencingPropertyData().getName(), + (PersistentCollection) newObj, + (Serializable) oldObj, + null + ); + data.put( propertyData.getModifiedFlagPropertyName(), !changes.isEmpty() ); } } } @@ -183,8 +227,8 @@ public abstract class AbstractCollectionMapper implements PropertyMapper { private boolean isFromNullToEmptyOrFromEmptyToNull(PersistentCollection newColl, Serializable oldColl) { // Comparing new and old collection content. - Collection newCollection = getNewCollectionContent(newColl); - Collection oldCollection = getOldCollectionContent(oldColl); + final Collection newCollection = getNewCollectionContent( newColl ); + final Collection oldCollection = getOldCollectionContent( oldColl ); return oldCollection == null && newCollection != null && newCollection.isEmpty() || newCollection == null && oldCollection != null && oldCollection.isEmpty(); @@ -192,36 +236,53 @@ public abstract class AbstractCollectionMapper implements PropertyMapper { @Override public void mapModifiedFlagsToMapForCollectionChange(String collectionPropertyName, Map data) { - PropertyData propertyData = commonCollectionMapperData.getCollectionReferencingPropertyData(); - if (propertyData.isUsingModifiedFlag()) { - data.put(propertyData.getModifiedFlagPropertyName(), propertyData.getName().equals(collectionPropertyName)); + final PropertyData propertyData = commonCollectionMapperData.getCollectionReferencingPropertyData(); + if ( propertyData.isUsingModifiedFlag() ) { + data.put( + propertyData.getModifiedFlagPropertyName(), + propertyData.getName().equals( collectionPropertyName ) + ); } } - protected abstract Initializor getInitializor(AuditConfiguration verCfg, - AuditReaderImplementor versionsReader, Object primaryKey, - Number revision, boolean removed); + protected abstract Initializor getInitializor( + AuditConfiguration verCfg, + AuditReaderImplementor versionsReader, Object primaryKey, + Number revision, boolean removed); - public void mapToEntityFromMap(AuditConfiguration verCfg, Object obj, Map data, Object primaryKey, - AuditReaderImplementor versionsReader, Number revision) { - Setter setter = ReflectionTools.getSetter(obj.getClass(), commonCollectionMapperData.getCollectionReferencingPropertyData()); - try { + @Override + public void mapToEntityFromMap( + AuditConfiguration verCfg, Object obj, Map data, Object primaryKey, + AuditReaderImplementor versionsReader, Number revision) { + final Setter setter = ReflectionTools.getSetter( + obj.getClass(), + commonCollectionMapperData.getCollectionReferencingPropertyData() + ); + try { setter.set( obj, proxyConstructor.newInstance( getInitializor( verCfg, versionsReader, primaryKey, revision, - RevisionType.DEL.equals( data.get( verCfg.getAuditEntCfg().getRevisionTypePropName() ) ) + RevisionType.DEL.equals( + data.get( + verCfg.getAuditEntCfg() + .getRevisionTypePropName() + ) + ) ) ), null ); - } catch (InstantiationException e) { - throw new AuditException(e); - } catch (IllegalAccessException e) { - throw new AuditException(e); - } catch (InvocationTargetException e) { - throw new AuditException(e); - } - } + } + catch (InstantiationException e) { + throw new AuditException( e ); + } + catch (IllegalAccessException e) { + throw new AuditException( e ); + } + catch (InvocationTargetException e) { + throw new AuditException( e ); + } + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/AbstractOneToOneMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/AbstractOneToOneMapper.java index 31fe58fc19..48a72ba7c7 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/AbstractOneToOneMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/AbstractOneToOneMapper.java @@ -1,8 +1,31 @@ +/* + * 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.internal.entities.mapper.relation; +import javax.persistence.NoResultException; import java.io.Serializable; import java.util.Map; -import javax.persistence.NoResultException; import org.hibernate.NonUniqueResultException; import org.hibernate.engine.spi.SessionImplementor; @@ -13,54 +36,69 @@ import org.hibernate.envers.internal.reader.AuditReaderImplementor; /** * Template class for property mappers that manage one-to-one relation. + * * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public abstract class AbstractOneToOneMapper extends AbstractToOneMapper { - private final String entityName; - private final String referencedEntityName; + private final String entityName; + private final String referencedEntityName; - protected AbstractOneToOneMapper(String entityName, String referencedEntityName, PropertyData propertyData) { - super(propertyData); - this.entityName = entityName; - this.referencedEntityName = referencedEntityName; - } + protected AbstractOneToOneMapper(String entityName, String referencedEntityName, PropertyData propertyData) { + super( propertyData ); + this.entityName = entityName; + this.referencedEntityName = referencedEntityName; + } - @Override - public void nullSafeMapToEntityFromMap(AuditConfiguration verCfg, Object obj, Map data, Object primaryKey, - AuditReaderImplementor versionsReader, Number revision) { - EntityInfo referencedEntity = getEntityInfo(verCfg, referencedEntityName); + @Override + public void nullSafeMapToEntityFromMap( + AuditConfiguration verCfg, Object obj, Map data, Object primaryKey, + AuditReaderImplementor versionsReader, Number revision) { + final EntityInfo referencedEntity = getEntityInfo( verCfg, referencedEntityName ); - Object value = null; - try { - value = queryForReferencedEntity(versionsReader, referencedEntity, (Serializable) primaryKey, revision); - } catch (NoResultException e) { - value = null; - } catch (NonUniqueResultException e) { - throw new AuditException("Many versions results for one-to-one relationship " + entityName + - "." + getPropertyData().getBeanName() + ".", e); - } + Object value; + try { + value = queryForReferencedEntity( versionsReader, referencedEntity, (Serializable) primaryKey, revision ); + } + catch (NoResultException e) { + value = null; + } + catch (NonUniqueResultException e) { + throw new AuditException( + "Many versions results for one-to-one relationship " + entityName + + "." + getPropertyData().getBeanName() + ".", e + ); + } - setPropertyValue(obj, value); - } + setPropertyValue( obj, value ); + } - /** - * @param versionsReader Audit reader. - * @param referencedEntity Referenced entity descriptor. - * @param primaryKey Referenced entity identifier. - * @param revision Revision number. - * @return Referenced object or proxy of one-to-one relation. - */ - protected abstract Object queryForReferencedEntity(AuditReaderImplementor versionsReader, EntityInfo referencedEntity, - Serializable primaryKey, Number revision); + /** + * @param versionsReader Audit reader. + * @param referencedEntity Referenced entity descriptor. + * @param primaryKey Referenced entity identifier. + * @param revision Revision number. + * + * @return Referenced object or proxy of one-to-one relation. + */ + protected abstract Object queryForReferencedEntity( + AuditReaderImplementor versionsReader, EntityInfo referencedEntity, + Serializable primaryKey, Number revision); - @Override - public void mapModifiedFlagsToMapFromEntity(SessionImplementor session, Map data, Object newObj, Object oldObj) { - } + @Override + public void mapModifiedFlagsToMapFromEntity( + SessionImplementor session, + Map data, + Object newObj, + Object oldObj) { + } - @Override - public void mapModifiedFlagsToMapForCollectionChange(String collectionPropertyName, Map data) { - if (getPropertyData().isUsingModifiedFlag()) { - data.put(getPropertyData().getModifiedFlagPropertyName(), collectionPropertyName.equals(getPropertyData().getName())); - } - } + @Override + public void mapModifiedFlagsToMapForCollectionChange(String collectionPropertyName, Map data) { + if ( getPropertyData().isUsingModifiedFlag() ) { + data.put( + getPropertyData().getModifiedFlagPropertyName(), + collectionPropertyName.equals( getPropertyData().getName() ) + ); + } + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/AbstractToOneMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/AbstractToOneMapper.java index 80fcec3bbf..ef292e3280 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/AbstractToOneMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/AbstractToOneMapper.java @@ -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.internal.entities.mapper.relation; import java.io.Serializable; @@ -17,87 +40,109 @@ import org.hibernate.property.Setter; /** * Base class for property mappers that manage to-one relation. + * * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public abstract class AbstractToOneMapper implements PropertyMapper { - private final PropertyData propertyData; + private final PropertyData propertyData; - protected AbstractToOneMapper(PropertyData propertyData) { - this.propertyData = propertyData; - } + protected AbstractToOneMapper(PropertyData propertyData) { + this.propertyData = propertyData; + } - @Override - public boolean mapToMapFromEntity(SessionImplementor session, Map data, Object newObj, Object oldObj) { - return false; - } + @Override + public boolean mapToMapFromEntity( + SessionImplementor session, + Map data, + Object newObj, + Object oldObj) { + return false; + } - @Override - public void mapToEntityFromMap(AuditConfiguration verCfg, Object obj, Map data, Object primaryKey, - AuditReaderImplementor versionsReader, Number revision) { - if (obj != null) { - nullSafeMapToEntityFromMap(verCfg, obj, data, primaryKey, versionsReader, revision); - } - } + @Override + public void mapToEntityFromMap( + AuditConfiguration verCfg, Object obj, Map data, Object primaryKey, + AuditReaderImplementor versionsReader, Number revision) { + if ( obj != null ) { + nullSafeMapToEntityFromMap( verCfg, obj, data, primaryKey, versionsReader, revision ); + } + } - @Override - public List mapCollectionChanges(SessionImplementor session, String referencingPropertyName, - PersistentCollection newColl, Serializable oldColl, - Serializable id) { - return null; - } + @Override + public List mapCollectionChanges( + SessionImplementor session, String referencingPropertyName, + PersistentCollection newColl, Serializable oldColl, + Serializable id) { + return null; + } - /** - * @param verCfg Audit configuration. - * @param entityName Entity name. - * @return Entity class, name and information whether it is audited or not. - */ - protected EntityInfo getEntityInfo(AuditConfiguration verCfg, String entityName) { - EntityConfiguration entCfg = verCfg.getEntCfg().get(entityName); - boolean isRelationAudited = true; - if (entCfg == null) { - // a relation marked as RelationTargetAuditMode.NOT_AUDITED - entCfg = verCfg.getEntCfg().getNotVersionEntityConfiguration(entityName); - isRelationAudited = false; - } - Class entityClass = ReflectionTools.loadClass( entCfg.getEntityClassName(), verCfg.getClassLoaderService() ); - return new EntityInfo(entityClass, entityName, isRelationAudited); - } + /** + * @param verCfg Audit configuration. + * @param entityName Entity name. + * + * @return Entity class, name and information whether it is audited or not. + */ + protected EntityInfo getEntityInfo(AuditConfiguration verCfg, String entityName) { + EntityConfiguration entCfg = verCfg.getEntCfg().get( entityName ); + boolean isRelationAudited = true; + if ( entCfg == null ) { + // a relation marked as RelationTargetAuditMode.NOT_AUDITED + entCfg = verCfg.getEntCfg().getNotVersionEntityConfiguration( entityName ); + isRelationAudited = false; + } + final Class entityClass = ReflectionTools.loadClass( entCfg.getEntityClassName(), verCfg.getClassLoaderService() ); + return new EntityInfo( entityClass, entityName, isRelationAudited ); + } - protected void setPropertyValue(Object targetObject, Object value) { - Setter setter = ReflectionTools.getSetter(targetObject.getClass(), propertyData); - setter.set(targetObject, value, null); - } + protected void setPropertyValue(Object targetObject, Object value) { + final Setter setter = ReflectionTools.getSetter( targetObject.getClass(), propertyData ); + setter.set( targetObject, value, null ); + } - /** - * @return Bean property that represents the relation. - */ - protected PropertyData getPropertyData() { - return propertyData; - } + /** + * @return Bean property that represents the relation. + */ + protected PropertyData getPropertyData() { + return propertyData; + } - /** - * Parameter {@code obj} is never {@code null}. - * @see PropertyMapper#mapToEntityFromMap(AuditConfiguration, Object, Map, Object, AuditReaderImplementor, Number) - */ - public abstract void nullSafeMapToEntityFromMap(AuditConfiguration verCfg, Object obj, Map data, Object primaryKey, - AuditReaderImplementor versionsReader, Number revision); + /** + * Parameter {@code obj} is never {@code null}. + * + * @see PropertyMapper#mapToEntityFromMap(AuditConfiguration, Object, Map, Object, AuditReaderImplementor, Number) + */ + public abstract void nullSafeMapToEntityFromMap( + AuditConfiguration verCfg, + Object obj, + Map data, + Object primaryKey, + AuditReaderImplementor versionsReader, + Number revision); - /** - * Simple descriptor of an entity. - */ - protected class EntityInfo { - private final Class entityClass; - private final String entityName; - private final boolean audited; + /** + * Simple descriptor of an entity. + */ + protected class EntityInfo { + private final Class entityClass; + private final String entityName; + private final boolean audited; - public EntityInfo(Class entityClass, String entityName, boolean audited) { - this.entityClass = entityClass; - this.entityName = entityName; - this.audited = audited; - } + public EntityInfo(Class entityClass, String entityName, boolean audited) { + this.entityClass = entityClass; + this.entityName = entityName; + this.audited = audited; + } - public Class getEntityClass() { return entityClass; } - public String getEntityName() { return entityName; } - public boolean isAudited() { return audited; } - } + public Class getEntityClass() { + return entityClass; + } + + public String getEntityName() { + return entityName; + } + + public boolean isAudited() { + return audited; + } + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/BasicCollectionMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/BasicCollectionMapper.java index ca327fe78d..2b11620037 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/BasicCollectionMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/BasicCollectionMapper.java @@ -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 @@ -39,36 +39,50 @@ import org.hibernate.envers.internal.reader.AuditReaderImplementor; * @author Adam Warski (adam at warski dot org) */ public class BasicCollectionMapper extends AbstractCollectionMapper implements PropertyMapper { - protected final MiddleComponentData elementComponentData; + protected final MiddleComponentData elementComponentData; - public BasicCollectionMapper(CommonCollectionMapperData commonCollectionMapperData, + public BasicCollectionMapper( + CommonCollectionMapperData commonCollectionMapperData, Class collectionClass, Class proxyClass, MiddleComponentData elementComponentData, boolean ordinalInId, boolean revisionTypeInId) { super( commonCollectionMapperData, collectionClass, proxyClass, ordinalInId, revisionTypeInId ); - this.elementComponentData = elementComponentData; - } + this.elementComponentData = elementComponentData; + } - protected Initializor getInitializor(AuditConfiguration verCfg, AuditReaderImplementor versionsReader, - Object primaryKey, Number revision, boolean removed) { - return new BasicCollectionInitializor(verCfg, versionsReader, commonCollectionMapperData.getQueryGenerator(), - primaryKey, revision, removed, collectionClass, elementComponentData); - } + @Override + protected Initializor getInitializor( + AuditConfiguration verCfg, AuditReaderImplementor versionsReader, + Object primaryKey, Number revision, boolean removed) { + return new BasicCollectionInitializor( + verCfg, versionsReader, commonCollectionMapperData.getQueryGenerator(), + primaryKey, revision, removed, collectionClass, elementComponentData + ); + } - protected Collection getNewCollectionContent(PersistentCollection newCollection) { - return (Collection) newCollection; - } + @Override + protected Collection getNewCollectionContent(PersistentCollection newCollection) { + return (Collection) newCollection; + } - protected Collection getOldCollectionContent(Serializable oldCollection) { - if (oldCollection == null) { - return null; - } else if (oldCollection instanceof Map) { - return ((Map) oldCollection).keySet(); - } else { - return (Collection) oldCollection; - } - } + @Override + protected Collection getOldCollectionContent(Serializable oldCollection) { + if ( oldCollection == null ) { + return null; + } + else if ( oldCollection instanceof Map ) { + return ((Map) oldCollection).keySet(); + } + else { + return (Collection) oldCollection; + } + } - protected void mapToMapFromObject(SessionImplementor session, Map idData, Map data, Object changed) { - elementComponentData.getComponentMapper().mapToMapFromObject(session, idData, data, changed); - } + @Override + protected void mapToMapFromObject( + SessionImplementor session, + Map idData, + Map data, + Object changed) { + elementComponentData.getComponentMapper().mapToMapFromObject( session, idData, data, changed ); + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/CommonCollectionMapperData.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/CommonCollectionMapperData.java index dc22be02d1..97edad9b6d 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/CommonCollectionMapperData.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/CommonCollectionMapperData.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,48 +22,51 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.internal.entities.mapper.relation; + import org.hibernate.envers.configuration.internal.AuditEntitiesConfiguration; import org.hibernate.envers.internal.entities.PropertyData; import org.hibernate.envers.internal.entities.mapper.relation.query.RelationQueryGenerator; /** - * Data that is used by all collection mappers, regardless of the type. + * Data that is used by all collection mappers, regardless of the type. + * * @author Adam Warski (adam at warski dot org) */ public final class CommonCollectionMapperData { - private final AuditEntitiesConfiguration verEntCfg; - private final String versionsMiddleEntityName; - private final PropertyData collectionReferencingPropertyData; - private final MiddleIdData referencingIdData; - private final RelationQueryGenerator queryGenerator; + private final AuditEntitiesConfiguration verEntCfg; + private final String versionsMiddleEntityName; + private final PropertyData collectionReferencingPropertyData; + private final MiddleIdData referencingIdData; + private final RelationQueryGenerator queryGenerator; - public CommonCollectionMapperData(AuditEntitiesConfiguration verEntCfg, String versionsMiddleEntityName, - PropertyData collectionReferencingPropertyData, MiddleIdData referencingIdData, - RelationQueryGenerator queryGenerator) { - this.verEntCfg = verEntCfg; - this.versionsMiddleEntityName = versionsMiddleEntityName; - this.collectionReferencingPropertyData = collectionReferencingPropertyData; - this.referencingIdData = referencingIdData; - this.queryGenerator = queryGenerator; - } + public CommonCollectionMapperData( + AuditEntitiesConfiguration verEntCfg, String versionsMiddleEntityName, + PropertyData collectionReferencingPropertyData, MiddleIdData referencingIdData, + RelationQueryGenerator queryGenerator) { + this.verEntCfg = verEntCfg; + this.versionsMiddleEntityName = versionsMiddleEntityName; + this.collectionReferencingPropertyData = collectionReferencingPropertyData; + this.referencingIdData = referencingIdData; + this.queryGenerator = queryGenerator; + } - public AuditEntitiesConfiguration getVerEntCfg() { - return verEntCfg; - } + public AuditEntitiesConfiguration getVerEntCfg() { + return verEntCfg; + } - public String getVersionsMiddleEntityName() { - return versionsMiddleEntityName; - } + public String getVersionsMiddleEntityName() { + return versionsMiddleEntityName; + } - public PropertyData getCollectionReferencingPropertyData() { - return collectionReferencingPropertyData; - } + public PropertyData getCollectionReferencingPropertyData() { + return collectionReferencingPropertyData; + } - public MiddleIdData getReferencingIdData() { - return referencingIdData; - } + public MiddleIdData getReferencingIdData() { + return referencingIdData; + } - public RelationQueryGenerator getQueryGenerator() { - return queryGenerator; - } + public RelationQueryGenerator getQueryGenerator() { + return queryGenerator; + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/ListCollectionMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/ListCollectionMapper.java index 3b58a11706..6d1ca6ea2c 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/ListCollectionMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/ListCollectionMapper.java @@ -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 @@ -43,45 +43,64 @@ import org.hibernate.envers.tools.Pair; * @author Adam Warski (adam at warski dot org) */ public final class ListCollectionMapper extends AbstractCollectionMapper implements PropertyMapper { - private final MiddleComponentData elementComponentData; - private final MiddleComponentData indexComponentData; + private final MiddleComponentData elementComponentData; + private final MiddleComponentData indexComponentData; - public ListCollectionMapper(CommonCollectionMapperData commonCollectionMapperData, - MiddleComponentData elementComponentData, MiddleComponentData indexComponentData, - boolean revisionTypeInId) { + public ListCollectionMapper( + CommonCollectionMapperData commonCollectionMapperData, + MiddleComponentData elementComponentData, MiddleComponentData indexComponentData, + boolean revisionTypeInId) { super( commonCollectionMapperData, List.class, ListProxy.class, false, revisionTypeInId ); - this.elementComponentData = elementComponentData; - this.indexComponentData = indexComponentData; - } + this.elementComponentData = elementComponentData; + this.indexComponentData = indexComponentData; + } - protected Initializor getInitializor(AuditConfiguration verCfg, AuditReaderImplementor versionsReader, - Object primaryKey, Number revision, boolean removed) { - return new ListCollectionInitializor(verCfg, versionsReader, commonCollectionMapperData.getQueryGenerator(), - primaryKey, revision, removed, elementComponentData, indexComponentData); - } + @Override + protected Initializor getInitializor( + AuditConfiguration verCfg, AuditReaderImplementor versionsReader, + Object primaryKey, Number revision, boolean removed) { + return new ListCollectionInitializor( + verCfg, versionsReader, commonCollectionMapperData.getQueryGenerator(), + primaryKey, revision, removed, elementComponentData, indexComponentData + ); + } - @SuppressWarnings({"unchecked"}) - protected Collection getNewCollectionContent(PersistentCollection newCollection) { - if (newCollection == null) { - return null; - } else { - return Tools.listToIndexElementPairList((List) newCollection); - } - } + @Override + @SuppressWarnings({"unchecked"}) + protected Collection getNewCollectionContent(PersistentCollection newCollection) { + if ( newCollection == null ) { + return null; + } + else { + return Tools.listToIndexElementPairList( (List) newCollection ); + } + } - @SuppressWarnings({"unchecked"}) - protected Collection getOldCollectionContent(Serializable oldCollection) { - if (oldCollection == null) { - return null; - } else { - return Tools.listToIndexElementPairList((List) oldCollection); - } - } + @Override + @SuppressWarnings({"unchecked"}) + protected Collection getOldCollectionContent(Serializable oldCollection) { + if ( oldCollection == null ) { + return null; + } + else { + return Tools.listToIndexElementPairList( (List) oldCollection ); + } + } - @SuppressWarnings({"unchecked"}) - protected void mapToMapFromObject(SessionImplementor session, Map idData, Map data, Object changed) { - Pair indexValuePair = (Pair) changed; - elementComponentData.getComponentMapper().mapToMapFromObject(session, idData, data, indexValuePair.getSecond()); - indexComponentData.getComponentMapper().mapToMapFromObject(session, idData, data, indexValuePair.getFirst()); - } + @Override + @SuppressWarnings({"unchecked"}) + protected void mapToMapFromObject( + SessionImplementor session, + Map idData, + Map data, + Object changed) { + final Pair indexValuePair = (Pair) changed; + elementComponentData.getComponentMapper().mapToMapFromObject( + session, + idData, + data, + indexValuePair.getSecond() + ); + indexComponentData.getComponentMapper().mapToMapFromObject( session, idData, data, indexValuePair.getFirst() ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/MapCollectionMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/MapCollectionMapper.java index 5310ced432..fbc3671bcd 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/MapCollectionMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/MapCollectionMapper.java @@ -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 @@ -39,42 +39,66 @@ import org.hibernate.envers.internal.reader.AuditReaderImplementor; * @author Adam Warski (adam at warski dot org) */ public class MapCollectionMapper extends AbstractCollectionMapper implements PropertyMapper { - protected final MiddleComponentData elementComponentData; - protected final MiddleComponentData indexComponentData; + protected final MiddleComponentData elementComponentData; + protected final MiddleComponentData indexComponentData; - public MapCollectionMapper(CommonCollectionMapperData commonCollectionMapperData, - Class collectionClass, Class proxyClass, - MiddleComponentData elementComponentData, MiddleComponentData indexComponentData, - boolean revisionTypeInId) { + public MapCollectionMapper( + CommonCollectionMapperData commonCollectionMapperData, + Class collectionClass, Class proxyClass, + MiddleComponentData elementComponentData, MiddleComponentData indexComponentData, + boolean revisionTypeInId) { super( commonCollectionMapperData, collectionClass, proxyClass, false, revisionTypeInId ); - this.elementComponentData = elementComponentData; - this.indexComponentData = indexComponentData; - } + this.elementComponentData = elementComponentData; + this.indexComponentData = indexComponentData; + } - protected Initializor getInitializor(AuditConfiguration verCfg, AuditReaderImplementor versionsReader, - Object primaryKey, Number revision, boolean removed) { - return new MapCollectionInitializor(verCfg, versionsReader, commonCollectionMapperData.getQueryGenerator(), - primaryKey, revision, removed, collectionClass, elementComponentData, indexComponentData); - } + @Override + protected Initializor getInitializor( + AuditConfiguration verCfg, AuditReaderImplementor versionsReader, + Object primaryKey, Number revision, boolean removed) { + return new MapCollectionInitializor( + verCfg, versionsReader, commonCollectionMapperData.getQueryGenerator(), + primaryKey, revision, removed, collectionClass, elementComponentData, indexComponentData + ); + } - protected Collection getNewCollectionContent(PersistentCollection newCollection) { - if (newCollection == null) { - return null; - } else { - return ((Map) newCollection).entrySet(); - } - } + @Override + protected Collection getNewCollectionContent(PersistentCollection newCollection) { + if ( newCollection == null ) { + return null; + } + else { + return ((Map) newCollection).entrySet(); + } + } - protected Collection getOldCollectionContent(Serializable oldCollection) { - if (oldCollection == null) { - return null; - } else { - return ((Map) oldCollection).entrySet(); - } - } + @Override + protected Collection getOldCollectionContent(Serializable oldCollection) { + if ( oldCollection == null ) { + return null; + } + else { + return ((Map) oldCollection).entrySet(); + } + } - protected void mapToMapFromObject(SessionImplementor session, Map idData, Map data, Object changed) { - elementComponentData.getComponentMapper().mapToMapFromObject(session, idData, data, ((Map.Entry) changed).getValue()); - indexComponentData.getComponentMapper().mapToMapFromObject(session, idData, data, ((Map.Entry) changed).getKey()); - } + @Override + protected void mapToMapFromObject( + SessionImplementor session, + Map idData, + Map data, + Object changed) { + elementComponentData.getComponentMapper().mapToMapFromObject( + session, + idData, + data, + ((Map.Entry) changed).getValue() + ); + indexComponentData.getComponentMapper().mapToMapFromObject( + session, + idData, + data, + ((Map.Entry) changed).getKey() + ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/MiddleComponentData.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/MiddleComponentData.java index 7ac2ff25b1..ca2e7bef07 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/MiddleComponentData.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/MiddleComponentData.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.internal.entities.mapper.relation; + import org.hibernate.envers.internal.entities.mapper.relation.component.MiddleComponentMapper; /** @@ -29,22 +30,23 @@ import org.hibernate.envers.internal.entities.mapper.relation.component.MiddleCo * - component mapper used to map the component to and from versions entities * - an index, which specifies in which element of the array returned by the query for reading the collection the data * of the component is + * * @author Adam Warski (adam at warski dot org) */ public final class MiddleComponentData { - private final MiddleComponentMapper componentMapper; - private final int componentIndex; + private final MiddleComponentMapper componentMapper; + private final int componentIndex; - public MiddleComponentData(MiddleComponentMapper componentMapper, int componentIndex) { - this.componentMapper = componentMapper; - this.componentIndex = componentIndex; - } + public MiddleComponentData(MiddleComponentMapper componentMapper, int componentIndex) { + this.componentMapper = componentMapper; + this.componentIndex = componentIndex; + } - public MiddleComponentMapper getComponentMapper() { - return componentMapper; - } + public MiddleComponentMapper getComponentMapper() { + return componentMapper; + } - public int getComponentIndex() { - return componentIndex; - } + public int getComponentIndex() { + return componentIndex; + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/MiddleIdData.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/MiddleIdData.java index 8d688e541e..a5b1ca45ff 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/MiddleIdData.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/MiddleIdData.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.internal.entities.mapper.relation; + import org.hibernate.envers.configuration.internal.AuditEntitiesConfiguration; import org.hibernate.envers.internal.entities.IdMappingData; import org.hibernate.envers.internal.entities.mapper.id.IdMapper; @@ -29,54 +30,56 @@ import org.hibernate.envers.internal.entities.mapper.id.IdMapper; /** * A class holding information about ids, which form a virtual "relation" from a middle-table. Middle-tables are used * when mapping collections. + * * @author Adam Warski (adam at warski dot org) */ public final class MiddleIdData { - private final IdMapper originalMapper; - private final IdMapper prefixedMapper; - private final String entityName; - private final String auditEntityName; + private final IdMapper originalMapper; + private final IdMapper prefixedMapper; + private final String entityName; + private final String auditEntityName; - public MiddleIdData(AuditEntitiesConfiguration verEntCfg, IdMappingData mappingData, String prefix, - String entityName, boolean audited) { - this.originalMapper = mappingData.getIdMapper(); - this.prefixedMapper = mappingData.getIdMapper().prefixMappedProperties(prefix); - this.entityName = entityName; - this.auditEntityName = audited ? verEntCfg.getAuditEntityName(entityName) : null; - } + public MiddleIdData( + AuditEntitiesConfiguration verEntCfg, IdMappingData mappingData, String prefix, + String entityName, boolean audited) { + this.originalMapper = mappingData.getIdMapper(); + this.prefixedMapper = mappingData.getIdMapper().prefixMappedProperties( prefix ); + this.entityName = entityName; + this.auditEntityName = audited ? verEntCfg.getAuditEntityName( entityName ) : null; + } - /** - * @return Original id mapper of the related entity. - */ - public IdMapper getOriginalMapper() { - return originalMapper; - } + /** + * @return Original id mapper of the related entity. + */ + public IdMapper getOriginalMapper() { + return originalMapper; + } - /** - * @return prefixed id mapper (with the names for the id fields that are used in the middle table) of the related entity. - */ - public IdMapper getPrefixedMapper() { - return prefixedMapper; - } + /** + * @return prefixed id mapper (with the names for the id fields that are used in the middle table) of the related entity. + */ + public IdMapper getPrefixedMapper() { + return prefixedMapper; + } - /** - * @return Name of the related entity (regular, not audited). - */ - public String getEntityName() { - return entityName; - } + /** + * @return Name of the related entity (regular, not audited). + */ + public String getEntityName() { + return entityName; + } - /** - * @return Audit name of the related entity. - */ - public String getAuditEntityName() { - return auditEntityName; - } + /** + * @return Audit name of the related entity. + */ + public String getAuditEntityName() { + return auditEntityName; + } - /** - * @return Is the entity, to which this middle id data correspond, audited. - */ - public boolean isAudited() { - return auditEntityName != null; - } + /** + * @return Is the entity, to which this middle id data correspond, audited. + */ + public boolean isAudited() { + return auditEntityName != null; + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/OneToOneNotOwningMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/OneToOneNotOwningMapper.java index c56754876b..9b3b66b3b9 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/OneToOneNotOwningMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/OneToOneNotOwningMapper.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 @@ -23,8 +23,8 @@ */ package org.hibernate.envers.internal.entities.mapper.relation; -import java.io.Serializable; import javax.persistence.OneToOne; +import java.io.Serializable; import org.hibernate.envers.internal.entities.PropertyData; import org.hibernate.envers.internal.reader.AuditReaderImplementor; @@ -32,26 +32,31 @@ import org.hibernate.envers.query.AuditEntity; /** * Property mapper for not owning side of {@link OneToOne} relation. + * * @author Adam Warski (adam at warski dot org) * @author HernпїЅn Chanfreau - * @author Michal Skowronek (mskowr at o2 dot pl) + * @author Michal Skowronek (mskowr at o2 dot pl) * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public class OneToOneNotOwningMapper extends AbstractOneToOneMapper { - private final String owningReferencePropertyName; + private final String owningReferencePropertyName; - public OneToOneNotOwningMapper(String notOwningEntityName, String owningEntityName, String owningReferencePropertyName, - PropertyData propertyData) { - super(notOwningEntityName, owningEntityName, propertyData); - this.owningReferencePropertyName = owningReferencePropertyName; - } + public OneToOneNotOwningMapper( + String notOwningEntityName, String owningEntityName, String owningReferencePropertyName, + PropertyData propertyData) { + super( notOwningEntityName, owningEntityName, propertyData ); + this.owningReferencePropertyName = owningReferencePropertyName; + } - @Override - protected Object queryForReferencedEntity(AuditReaderImplementor versionsReader, EntityInfo referencedEntity, - Serializable primaryKey, Number revision) { - return versionsReader.createQuery().forEntitiesAtRevision(referencedEntity.getEntityClass(), - referencedEntity.getEntityName(), revision) - .add(AuditEntity.relatedId(owningReferencePropertyName).eq(primaryKey)) - .getSingleResult(); - } + @Override + protected Object queryForReferencedEntity( + AuditReaderImplementor versionsReader, EntityInfo referencedEntity, + Serializable primaryKey, Number revision) { + return versionsReader.createQuery().forEntitiesAtRevision( + referencedEntity.getEntityClass(), + referencedEntity.getEntityName(), revision + ) + .add( AuditEntity.relatedId( owningReferencePropertyName ).eq( primaryKey ) ) + .getSingleResult(); + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/OneToOnePrimaryKeyJoinColumnMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/OneToOnePrimaryKeyJoinColumnMapper.java index 6ef8ff4d71..7503bc0284 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/OneToOnePrimaryKeyJoinColumnMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/OneToOnePrimaryKeyJoinColumnMapper.java @@ -1,54 +1,88 @@ +/* + * 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.internal.entities.mapper.relation; import java.io.Serializable; -import javax.persistence.OneToOne; -import javax.persistence.PrimaryKeyJoinColumn; -import org.hibernate.envers.Audited; import org.hibernate.envers.internal.entities.PropertyData; import org.hibernate.envers.internal.reader.AuditReaderImplementor; import org.hibernate.envers.query.AuditEntity; import org.hibernate.persister.entity.EntityPersister; /** - * Property mapper for {@link OneToOne} with {@link PrimaryKeyJoinColumn} relation. + * Property mapper for {@link javax.persistence.OneToOne} with {@link javax.persistence.PrimaryKeyJoinColumn} relation. + * * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public class OneToOnePrimaryKeyJoinColumnMapper extends AbstractOneToOneMapper { - public OneToOnePrimaryKeyJoinColumnMapper(String entityName, String referencedEntityName, PropertyData propertyData) { - super(entityName, referencedEntityName, propertyData); - } + public OneToOnePrimaryKeyJoinColumnMapper( + String entityName, + String referencedEntityName, + PropertyData propertyData) { + super( entityName, referencedEntityName, propertyData ); + } - @Override - protected Object queryForReferencedEntity(AuditReaderImplementor versionsReader, EntityInfo referencedEntity, - Serializable primaryKey, Number revision) { - if (referencedEntity.isAudited()) { - // Audited relation. - return versionsReader.createQuery().forEntitiesAtRevision(referencedEntity.getEntityClass(), - referencedEntity.getEntityName(), revision) - .add(AuditEntity.id().eq(primaryKey)) - .getSingleResult(); - } else { - // Not audited relation. - return createNotAuditedEntityReference(versionsReader, referencedEntity.getEntityClass(), - referencedEntity.getEntityName(), primaryKey); - } - } + @Override + protected Object queryForReferencedEntity( + AuditReaderImplementor versionsReader, EntityInfo referencedEntity, + Serializable primaryKey, Number revision) { + if ( referencedEntity.isAudited() ) { + // Audited relation. + return versionsReader.createQuery().forEntitiesAtRevision( + referencedEntity.getEntityClass(), + referencedEntity.getEntityName(), revision + ) + .add( AuditEntity.id().eq( primaryKey ) ) + .getSingleResult(); + } + else { + // Not audited relation. + return createNotAuditedEntityReference( + versionsReader, referencedEntity.getEntityClass(), + referencedEntity.getEntityName(), primaryKey + ); + } + } - /** - * Create Hibernate proxy or retrieve the complete object of referenced, not audited entity. According to - * {@link Audited#targetAuditMode()}} documentation, reference shall point to current (non-historical) version - * of an entity. - */ - private Object createNotAuditedEntityReference(AuditReaderImplementor versionsReader, Class entityClass, - String entityName, Serializable primaryKey) { - EntityPersister entityPersister = versionsReader.getSessionImplementor().getFactory().getEntityPersister(entityName); - if (entityPersister.hasProxy()) { - // If possible create a proxy. Returning complete object may affect performance. - return versionsReader.getSession().load(entityClass, primaryKey); - } else { - // If proxy is not allowed (e.g. @Proxy(lazy=false)) construct the original object. - return versionsReader.getSession().get(entityClass, primaryKey); - } - } + /** + * Create Hibernate proxy or retrieve the complete object of referenced, not audited entity. According to + * {@link org.hibernate.envers.Audited#targetAuditMode()}} documentation, reference shall point to current + * (non-historical) version of an entity. + */ + private Object createNotAuditedEntityReference( + AuditReaderImplementor versionsReader, Class entityClass, + String entityName, Serializable primaryKey) { + final EntityPersister entityPersister = versionsReader.getSessionImplementor().getFactory().getEntityPersister( + entityName + ); + if ( entityPersister.hasProxy() ) { + // If possible create a proxy. Returning complete object may affect performance. + return versionsReader.getSession().load( entityClass, primaryKey ); + } + else { + // If proxy is not allowed (e.g. @Proxy(lazy=false)) construct the original object. + return versionsReader.getSession().get( entityClass, primaryKey ); + } + } } \ No newline at end of file diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/SortedMapCollectionMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/SortedMapCollectionMapper.java index 8f96fa3a0d..a9ec7f442a 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/SortedMapCollectionMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/SortedMapCollectionMapper.java @@ -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 @@ -37,18 +37,30 @@ import org.hibernate.envers.internal.reader.AuditReaderImplementor; public final class SortedMapCollectionMapper extends MapCollectionMapper { private final Comparator comparator; - public SortedMapCollectionMapper(CommonCollectionMapperData commonCollectionMapperData, - Class collectionClass, Class proxyClass, - MiddleComponentData elementComponentData, MiddleComponentData indexComponentData, Comparator comparator, - boolean revisionTypeInId) { - super(commonCollectionMapperData, collectionClass, proxyClass, elementComponentData, indexComponentData, revisionTypeInId); + public SortedMapCollectionMapper( + CommonCollectionMapperData commonCollectionMapperData, + Class collectionClass, Class proxyClass, + MiddleComponentData elementComponentData, MiddleComponentData indexComponentData, Comparator comparator, + boolean revisionTypeInId) { + super( + commonCollectionMapperData, + collectionClass, + proxyClass, + elementComponentData, + indexComponentData, + revisionTypeInId + ); this.comparator = comparator; } - protected Initializor getInitializor(AuditConfiguration verCfg, AuditReaderImplementor versionsReader, - Object primaryKey, Number revision, boolean removed) { - return new SortedMapCollectionInitializor(verCfg, versionsReader, commonCollectionMapperData.getQueryGenerator(), - primaryKey, revision, removed, collectionClass, elementComponentData, indexComponentData, comparator); + @Override + protected Initializor getInitializor( + AuditConfiguration verCfg, AuditReaderImplementor versionsReader, + Object primaryKey, Number revision, boolean removed) { + return new SortedMapCollectionInitializor( + verCfg, versionsReader, commonCollectionMapperData.getQueryGenerator(), + primaryKey, revision, removed, collectionClass, elementComponentData, indexComponentData, comparator + ); } } \ No newline at end of file diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/SortedSetCollectionMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/SortedSetCollectionMapper.java index aad21b113a..fd275143e2 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/SortedSetCollectionMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/SortedSetCollectionMapper.java @@ -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 @@ -37,17 +37,29 @@ import org.hibernate.envers.internal.reader.AuditReaderImplementor; public final class SortedSetCollectionMapper extends BasicCollectionMapper { private final Comparator comparator; - public SortedSetCollectionMapper(CommonCollectionMapperData commonCollectionMapperData, + public SortedSetCollectionMapper( + CommonCollectionMapperData commonCollectionMapperData, Class collectionClass, Class proxyClass, MiddleComponentData elementComponentData, Comparator comparator, boolean ordinalInId, boolean revisionTypeInId) { - super( commonCollectionMapperData, collectionClass, proxyClass, elementComponentData, ordinalInId, revisionTypeInId ); + super( + commonCollectionMapperData, + collectionClass, + proxyClass, + elementComponentData, + ordinalInId, + revisionTypeInId + ); this.comparator = comparator; } - protected Initializor getInitializor(AuditConfiguration verCfg, AuditReaderImplementor versionsReader, - Object primaryKey, Number revision, boolean removed) { - return new SortedSetCollectionInitializor(verCfg, versionsReader, commonCollectionMapperData.getQueryGenerator(), - primaryKey, revision, removed, collectionClass, elementComponentData, comparator); + @Override + protected Initializor getInitializor( + AuditConfiguration verCfg, AuditReaderImplementor versionsReader, + Object primaryKey, Number revision, boolean removed) { + return new SortedSetCollectionInitializor( + verCfg, versionsReader, commonCollectionMapperData.getQueryGenerator(), + primaryKey, revision, removed, collectionClass, elementComponentData, comparator + ); } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/ToOneEntityLoader.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/ToOneEntityLoader.java index 3d9aeaa016..af8897846e 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/ToOneEntityLoader.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/ToOneEntityLoader.java @@ -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.internal.entities.mapper.relation; import java.io.Serializable; @@ -14,13 +37,19 @@ public class ToOneEntityLoader { /** * Immediately loads historical entity or its current state when excluded from audit process. */ - public static Object loadImmediate(AuditReaderImplementor versionsReader, Class entityClass, String entityName, - Object entityId, Number revision, boolean removed, AuditConfiguration verCfg) { + public static Object loadImmediate( + AuditReaderImplementor versionsReader, + Class entityClass, + String entityName, + Object entityId, + Number revision, + boolean removed, + AuditConfiguration verCfg) { if ( verCfg.getEntCfg().getNotVersionEntityConfiguration( entityName ) == null ) { // Audited relation, look up entity with Envers. // When user traverses removed entities graph, do not restrict revision type of referencing objects // to ADD or MOD (DEL possible). See HHH-5845. - return versionsReader.find( entityClass, entityName, entityId, revision, removed); + return versionsReader.find( entityClass, entityName, entityId, revision, removed ); } else { // Not audited relation, look up entity with Hibernate. @@ -31,9 +60,17 @@ public class ToOneEntityLoader { /** * Creates proxy of referenced *-to-one entity. */ - public static Object createProxy(AuditReaderImplementor versionsReader, Class entityClass, String entityName, - Object entityId, Number revision, boolean removed, AuditConfiguration verCfg) { - EntityPersister persister = versionsReader.getSessionImplementor().getFactory().getEntityPersister( entityName ); + public static Object createProxy( + AuditReaderImplementor versionsReader, + Class entityClass, + String entityName, + Object entityId, + Number revision, + boolean removed, + AuditConfiguration verCfg) { + final EntityPersister persister = versionsReader.getSessionImplementor() + .getFactory() + .getEntityPersister( entityName ); return persister.createProxy( (Serializable) entityId, new ToOneDelegateSessionImplementor( versionsReader, entityClass, entityId, revision, removed, verCfg ) @@ -44,9 +81,17 @@ public class ToOneEntityLoader { * Creates Hibernate proxy or retrieves the complete object of an entity if proxy is not * allowed (e.g. @Proxy(lazy=false), final class). */ - public static Object createProxyOrLoadImmediate(AuditReaderImplementor versionsReader, Class entityClass, String entityName, - Object entityId, Number revision, boolean removed, AuditConfiguration verCfg) { - EntityPersister persister = versionsReader.getSessionImplementor().getFactory().getEntityPersister( entityName ); + public static Object createProxyOrLoadImmediate( + AuditReaderImplementor versionsReader, + Class entityClass, + String entityName, + Object entityId, + Number revision, + boolean removed, + AuditConfiguration verCfg) { + final EntityPersister persister = versionsReader.getSessionImplementor() + .getFactory() + .getEntityPersister( entityName ); if ( persister.hasProxy() ) { return createProxy( versionsReader, entityClass, entityName, entityId, revision, removed, verCfg ); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/ToOneIdMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/ToOneIdMapper.java index 3382b0136d..f41bfd7a07 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/ToOneIdMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/ToOneIdMapper.java @@ -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 @@ -41,71 +41,100 @@ import org.hibernate.envers.internal.tools.query.Parameters; * @author Michal Skowronek (mskowr at o2 dot pl) */ public class ToOneIdMapper extends AbstractToOneMapper { - private final IdMapper delegate; - private final String referencedEntityName; - private final boolean nonInsertableFake; + private final IdMapper delegate; + private final String referencedEntityName; + private final boolean nonInsertableFake; - public ToOneIdMapper(IdMapper delegate, PropertyData propertyData, String referencedEntityName, boolean nonInsertableFake) { - super(propertyData); - this.delegate = delegate; - this.referencedEntityName = referencedEntityName; - this.nonInsertableFake = nonInsertableFake; - } + public ToOneIdMapper( + IdMapper delegate, + PropertyData propertyData, + String referencedEntityName, + boolean nonInsertableFake) { + super( propertyData ); + this.delegate = delegate; + this.referencedEntityName = referencedEntityName; + this.nonInsertableFake = nonInsertableFake; + } - public boolean mapToMapFromEntity(SessionImplementor session, Map data, Object newObj, Object oldObj) { - HashMap newData = new HashMap(); + @Override + public boolean mapToMapFromEntity( + SessionImplementor session, + Map data, + Object newObj, + Object oldObj) { + final HashMap newData = new HashMap(); - // If this property is originally non-insertable, but made insertable because it is in a many-to-one "fake" - // bi-directional relation, we always store the "old", unchaged data, to prevent storing changes made - // to this field. It is the responsibility of the collection to properly update it if it really changed. - delegate.mapToMapFromEntity(newData, nonInsertableFake ? oldObj : newObj); + // If this property is originally non-insertable, but made insertable because it is in a many-to-one "fake" + // bi-directional relation, we always store the "old", unchaged data, to prevent storing changes made + // to this field. It is the responsibility of the collection to properly update it if it really changed. + delegate.mapToMapFromEntity( newData, nonInsertableFake ? oldObj : newObj ); - for (Map.Entry entry : newData.entrySet()) { - data.put(entry.getKey(), entry.getValue()); + for ( Map.Entry entry : newData.entrySet() ) { + data.put( entry.getKey(), entry.getValue() ); } - return checkModified(session, newObj, oldObj); - } + return checkModified( session, newObj, oldObj ); + } - @Override - public void mapModifiedFlagsToMapFromEntity(SessionImplementor session, Map data, Object newObj, Object oldObj) { - if (getPropertyData().isUsingModifiedFlag()) { - data.put(getPropertyData().getModifiedFlagPropertyName(), checkModified(session, newObj, oldObj)); - } - } + @Override + public void mapModifiedFlagsToMapFromEntity( + SessionImplementor session, + Map data, + Object newObj, + Object oldObj) { + if ( getPropertyData().isUsingModifiedFlag() ) { + data.put( getPropertyData().getModifiedFlagPropertyName(), checkModified( session, newObj, oldObj ) ); + } + } - @Override - public void mapModifiedFlagsToMapForCollectionChange(String collectionPropertyName, Map data) { - if (getPropertyData().isUsingModifiedFlag()) { - data.put(getPropertyData().getModifiedFlagPropertyName(), collectionPropertyName.equals(getPropertyData().getName())); - } - } + @Override + public void mapModifiedFlagsToMapForCollectionChange(String collectionPropertyName, Map data) { + if ( getPropertyData().isUsingModifiedFlag() ) { + data.put( + getPropertyData().getModifiedFlagPropertyName(), + collectionPropertyName.equals( getPropertyData().getName() ) + ); + } + } - protected boolean checkModified(SessionImplementor session, Object newObj, Object oldObj) { - //noinspection SimplifiableConditionalExpression - return nonInsertableFake ? false : !EntityTools.entitiesEqual(session, referencedEntityName, newObj, oldObj); - } + protected boolean checkModified(SessionImplementor session, Object newObj, Object oldObj) { + //noinspection SimplifiableConditionalExpression + return nonInsertableFake ? false : !EntityTools.entitiesEqual( session, referencedEntityName, newObj, oldObj ); + } - public void nullSafeMapToEntityFromMap(AuditConfiguration verCfg, Object obj, Map data, Object primaryKey, - AuditReaderImplementor versionsReader, Number revision) { - Object entityId = delegate.mapToIdFromMap(data); - Object value = null; - if (entityId != null) { - if (versionsReader.getFirstLevelCache().contains(referencedEntityName, revision, entityId)) { - value = versionsReader.getFirstLevelCache().get(referencedEntityName, revision, entityId); - } else { - EntityInfo referencedEntity = getEntityInfo(verCfg, referencedEntityName); - value = ToOneEntityLoader.createProxyOrLoadImmediate( - versionsReader, referencedEntity.getEntityClass(), referencedEntityName, - entityId, revision, RevisionType.DEL.equals( data.get( verCfg.getAuditEntCfg().getRevisionTypePropName() ) ), verCfg - ); - } - } + @Override + public void nullSafeMapToEntityFromMap( + AuditConfiguration verCfg, Object obj, Map data, Object primaryKey, + AuditReaderImplementor versionsReader, Number revision) { + final Object entityId = delegate.mapToIdFromMap( data ); + Object value = null; + if ( entityId != null ) { + if ( versionsReader.getFirstLevelCache().contains( referencedEntityName, revision, entityId ) ) { + value = versionsReader.getFirstLevelCache().get( referencedEntityName, revision, entityId ); + } + else { + final EntityInfo referencedEntity = getEntityInfo( verCfg, referencedEntityName ); + value = ToOneEntityLoader.createProxyOrLoadImmediate( + versionsReader, referencedEntity.getEntityClass(), referencedEntityName, + entityId, revision, RevisionType.DEL.equals( + data.get( + verCfg.getAuditEntCfg() + .getRevisionTypePropName() + ) + ), verCfg + ); + } + } - setPropertyValue(obj, value); - } + setPropertyValue( obj, value ); + } - public void addMiddleEqualToQuery(Parameters parameters, String idPrefix1, String prefix1, String idPrefix2, String prefix2) { + public void addMiddleEqualToQuery( + Parameters parameters, + String idPrefix1, + String prefix1, + String idPrefix2, + String prefix2) { delegate.addIdsEqualToQuery( parameters, prefix1, delegate, prefix2 ); } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/component/MiddleComponentMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/component/MiddleComponentMapper.java index f9213ab8ac..77615a6d31 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/component/MiddleComponentMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/component/MiddleComponentMapper.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 @@ -33,36 +33,50 @@ import org.hibernate.envers.internal.tools.query.Parameters; * @author Adam Warski (adam at warski dot org) */ public interface MiddleComponentMapper { - /** - * Maps from full object data, contained in the given map (or object representation of the map, if - * available), to an object. - * @param entityInstantiator An entity instatiator bound with an open versions reader. - * @param data Full object data. - * @param dataObject An optional object representation of the data. - * @param revision Revision at which the data is read. - * @return An object with data corresponding to the one found in the given map. - */ - Object mapToObjectFromFullMap(EntityInstantiator entityInstantiator, Map data, - Object dataObject, Number revision); + /** + * Maps from full object data, contained in the given map (or object representation of the map, if + * available), to an object. + * + * @param entityInstantiator An entity instatiator bound with an open versions reader. + * @param data Full object data. + * @param dataObject An optional object representation of the data. + * @param revision Revision at which the data is read. + * + * @return An object with data corresponding to the one found in the given map. + */ + Object mapToObjectFromFullMap( + EntityInstantiator entityInstantiator, Map data, + Object dataObject, Number revision); - /** - * Maps from an object to the object's map representation (for an entity - only its id). + /** + * Maps from an object to the object's map representation (for an entity - only its id). + * * @param session The current session. * @param idData Map to which composite-id data should be added. - * @param data Map to which data should be added. - * @param obj Object to map from. - */ - void mapToMapFromObject(SessionImplementor session, Map idData, Map data, Object obj); + * @param data Map to which data should be added. + * @param obj Object to map from. + */ + void mapToMapFromObject( + SessionImplementor session, + Map idData, + Map data, + Object obj); - /** - * Adds query statements, which contains restrictions, which express the property that part of the middle - * entity with alias prefix1, is equal to part of the middle entity with alias prefix2 (the entity is the same). - * The part is the component's representation in the middle entity. - * @param parameters Parameters, to which to add the statements. + /** + * Adds query statements, which contains restrictions, which express the property that part of the middle + * entity with alias prefix1, is equal to part of the middle entity with alias prefix2 (the entity is the same). + * The part is the component's representation in the middle entity. + * + * @param parameters Parameters, to which to add the statements. * @param idPrefix1 First alias of the entity + prefix + id to add to the properties. - * @param prefix1 First alias of the entity + prefix to add to the properties. + * @param prefix1 First alias of the entity + prefix to add to the properties. * @param idPrefix2 Second alias of the entity + prefix + id to add to the properties. - * @param prefix2 Second alias of the entity + prefix to add to the properties. - */ - void addMiddleEqualToQuery(Parameters parameters, String idPrefix1, String prefix1, String idPrefix2, String prefix2); + * @param prefix2 Second alias of the entity + prefix to add to the properties. + */ + void addMiddleEqualToQuery( + Parameters parameters, + String idPrefix1, + String prefix1, + String idPrefix2, + String prefix2); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/component/MiddleDummyComponentMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/component/MiddleDummyComponentMapper.java index b4da4f3c37..257c50d115 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/component/MiddleDummyComponentMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/component/MiddleDummyComponentMapper.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.internal.entities.mapper.relation.component; + import java.util.Map; import org.hibernate.engine.spi.SessionImplementor; @@ -32,14 +33,26 @@ import org.hibernate.envers.internal.tools.query.Parameters; * @author Adam Warski (adam at warski dot org) */ public final class MiddleDummyComponentMapper implements MiddleComponentMapper { - public Object mapToObjectFromFullMap(EntityInstantiator entityInstantiator, Map data, - Object dataObject, Number revision) { - return null; - } + public Object mapToObjectFromFullMap( + EntityInstantiator entityInstantiator, Map data, + Object dataObject, Number revision) { + return null; + } - public void mapToMapFromObject(SessionImplementor session, Map idData, Map data, Object obj) { - } + @Override + public void mapToMapFromObject( + SessionImplementor session, + Map idData, + Map data, + Object obj) { + } - public void addMiddleEqualToQuery(Parameters parameters, String idPrefix1, String prefix1, String idPrefix2, String prefix2) { - } + @Override + public void addMiddleEqualToQuery( + Parameters parameters, + String idPrefix1, + String prefix1, + String idPrefix2, + String prefix2) { + } } \ No newline at end of file diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/component/MiddleEmbeddableComponentMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/component/MiddleEmbeddableComponentMapper.java index f599d81e8c..8a36315829 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/component/MiddleEmbeddableComponentMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/component/MiddleEmbeddableComponentMapper.java @@ -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 @@ -49,39 +49,73 @@ public class MiddleEmbeddableComponentMapper implements MiddleComponentMapper, C } @Override - public Object mapToObjectFromFullMap(EntityInstantiator entityInstantiator, Map data, Object dataObject, Number revision) { + public Object mapToObjectFromFullMap( + EntityInstantiator entityInstantiator, + Map data, + Object dataObject, + Number revision) { try { - final Object componentInstance = dataObject != null ? dataObject : ReflectHelper.getDefaultConstructor( componentClass ).newInstance(); + final Object componentInstance = dataObject != null ? dataObject : ReflectHelper.getDefaultConstructor( + componentClass + ).newInstance(); delegate.mapToEntityFromMap( entityInstantiator.getAuditConfiguration(), componentInstance, data, null, entityInstantiator.getAuditReaderImplementor(), revision ); return componentInstance; } - catch ( Exception e ) { + catch (Exception e) { throw new AuditException( e ); } } @Override - public void mapToMapFromObject(SessionImplementor session, Map idData, Map data, Object obj) { + public void mapToMapFromObject( + SessionImplementor session, + Map idData, + Map data, + Object obj) { delegate.mapToMapFromEntity( session, data, obj, obj ); } @Override - public void addMiddleEqualToQuery(Parameters parameters, String idPrefix1, String prefix1, String idPrefix2, String prefix2) { + public void addMiddleEqualToQuery( + Parameters parameters, + String idPrefix1, + String prefix1, + String idPrefix2, + String prefix2) { addMiddleEqualToQuery( delegate, parameters, idPrefix1, prefix1, idPrefix2, prefix2 ); } - protected void addMiddleEqualToQuery(CompositeMapperBuilder compositeMapper, Parameters parameters, String idPrefix1, String prefix1, String idPrefix2, String prefix2) { + protected void addMiddleEqualToQuery( + CompositeMapperBuilder compositeMapper, + Parameters parameters, + String idPrefix1, + String prefix1, + String idPrefix2, + String prefix2) { for ( final Map.Entry entry : compositeMapper.getProperties().entrySet() ) { final String propertyName = entry.getKey().getName(); final PropertyMapper nestedMapper = entry.getValue(); if ( nestedMapper instanceof CompositeMapperBuilder ) { - addMiddleEqualToQuery( (CompositeMapperBuilder) nestedMapper, parameters, idPrefix1, prefix1, idPrefix2, prefix2 ); + addMiddleEqualToQuery( + (CompositeMapperBuilder) nestedMapper, + parameters, + idPrefix1, + prefix1, + idPrefix2, + prefix2 + ); } else if ( nestedMapper instanceof ToOneIdMapper ) { - ( (ToOneIdMapper) nestedMapper ).addMiddleEqualToQuery( parameters, idPrefix1, prefix1, idPrefix2, prefix2 ); + ((ToOneIdMapper) nestedMapper).addMiddleEqualToQuery( + parameters, + idPrefix1, + prefix1, + idPrefix2, + prefix2 + ); } else { parameters.addWhere( prefix1 + '.' + propertyName, false, "=", prefix2 + '.' + propertyName, false ); diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/component/MiddleMapKeyIdComponentMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/component/MiddleMapKeyIdComponentMapper.java index cc9c899e75..5298441418 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/component/MiddleMapKeyIdComponentMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/component/MiddleMapKeyIdComponentMapper.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.internal.entities.mapper.relation.component; + import java.util.Map; import org.hibernate.engine.spi.SessionImplementor; @@ -34,27 +35,41 @@ import org.hibernate.envers.internal.tools.query.Parameters; * A component mapper for the @MapKey mapping: the value of the map's key is the id of the entity. This * doesn't have an effect on the data stored in the versions tables, so mapToMapFromObject is * empty. + * * @author Adam Warski (adam at warski dot org) */ public final class MiddleMapKeyIdComponentMapper implements MiddleComponentMapper { - private final AuditEntitiesConfiguration verEntCfg; - private final IdMapper relatedIdMapper; + private final AuditEntitiesConfiguration verEntCfg; + private final IdMapper relatedIdMapper; - public MiddleMapKeyIdComponentMapper(AuditEntitiesConfiguration verEntCfg, IdMapper relatedIdMapper) { - this.verEntCfg = verEntCfg; - this.relatedIdMapper = relatedIdMapper; - } + public MiddleMapKeyIdComponentMapper(AuditEntitiesConfiguration verEntCfg, IdMapper relatedIdMapper) { + this.verEntCfg = verEntCfg; + this.relatedIdMapper = relatedIdMapper; + } - public Object mapToObjectFromFullMap(EntityInstantiator entityInstantiator, Map data, - Object dataObject, Number revision) { - return relatedIdMapper.mapToIdFromMap((Map) data.get(verEntCfg.getOriginalIdPropName())); - } + @Override + public Object mapToObjectFromFullMap( + EntityInstantiator entityInstantiator, Map data, + Object dataObject, Number revision) { + return relatedIdMapper.mapToIdFromMap( (Map) data.get( verEntCfg.getOriginalIdPropName() ) ); + } - public void mapToMapFromObject(SessionImplementor session, Map idData, Map data, Object obj) { - // Doing nothing. - } + @Override + public void mapToMapFromObject( + SessionImplementor session, + Map idData, + Map data, + Object obj) { + // Doing nothing. + } - public void addMiddleEqualToQuery(Parameters parameters, String idPrefix1, String prefix1, String idPrefix2, String prefix2) { - // Doing nothing. - } + @Override + public void addMiddleEqualToQuery( + Parameters parameters, + String idPrefix1, + String prefix1, + String idPrefix2, + String prefix2) { + // Doing nothing. + } } \ No newline at end of file diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/component/MiddleMapKeyPropertyComponentMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/component/MiddleMapKeyPropertyComponentMapper.java index 943c22cab4..1a68b800a1 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/component/MiddleMapKeyPropertyComponentMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/component/MiddleMapKeyPropertyComponentMapper.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 @@ -34,28 +34,42 @@ import org.hibernate.envers.internal.tools.query.Parameters; * A component mapper for the @MapKey mapping with the name parameter specified: the value of the map's key * is a property of the entity. This doesn't have an effect on the data stored in the versions tables, * so mapToMapFromObject is empty. + * * @author Adam Warski (adam at warski dot org) */ public class MiddleMapKeyPropertyComponentMapper implements MiddleComponentMapper { - private final String propertyName; - private final String accessType; + private final String propertyName; + private final String accessType; - public MiddleMapKeyPropertyComponentMapper(String propertyName, String accessType) { - this.propertyName = propertyName; - this.accessType = accessType; - } + public MiddleMapKeyPropertyComponentMapper(String propertyName, String accessType) { + this.propertyName = propertyName; + this.accessType = accessType; + } - public Object mapToObjectFromFullMap(EntityInstantiator entityInstantiator, Map data, - Object dataObject, Number revision) { - // dataObject is not null, as this mapper can only be used in an index. - return ReflectionTools.getGetter(dataObject.getClass(), propertyName, accessType).get(dataObject); - } + @Override + public Object mapToObjectFromFullMap( + EntityInstantiator entityInstantiator, Map data, + Object dataObject, Number revision) { + // dataObject is not null, as this mapper can only be used in an index. + return ReflectionTools.getGetter( dataObject.getClass(), propertyName, accessType ).get( dataObject ); + } - public void mapToMapFromObject(SessionImplementor session, Map idData, Map data, Object obj) { - // Doing nothing. - } + @Override + public void mapToMapFromObject( + SessionImplementor session, + Map idData, + Map data, + Object obj) { + // Doing nothing. + } - public void addMiddleEqualToQuery(Parameters parameters, String idPrefix1, String prefix1, String idPrefix2, String prefix2) { - // Doing nothing. - } + @Override + public void addMiddleEqualToQuery( + Parameters parameters, + String idPrefix1, + String prefix1, + String idPrefix2, + String prefix2) { + // Doing nothing. + } } \ No newline at end of file diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/component/MiddleRelatedComponentMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/component/MiddleRelatedComponentMapper.java index de340038d0..9150b4cf1a 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/component/MiddleRelatedComponentMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/component/MiddleRelatedComponentMapper.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.internal.entities.mapper.relation.component; + import java.util.Map; import org.hibernate.engine.spi.SessionImplementor; @@ -33,22 +34,35 @@ import org.hibernate.envers.internal.tools.query.Parameters; * @author Adam Warski (adam at warski dot org) */ public final class MiddleRelatedComponentMapper implements MiddleComponentMapper { - private final MiddleIdData relatedIdData; + private final MiddleIdData relatedIdData; - public MiddleRelatedComponentMapper(MiddleIdData relatedIdData) { - this.relatedIdData = relatedIdData; - } + public MiddleRelatedComponentMapper(MiddleIdData relatedIdData) { + this.relatedIdData = relatedIdData; + } - public Object mapToObjectFromFullMap(EntityInstantiator entityInstantiator, Map data, - Object dataObject, Number revision) { - return entityInstantiator.createInstanceFromVersionsEntity(relatedIdData.getEntityName(), data, revision); - } + @Override + public Object mapToObjectFromFullMap( + EntityInstantiator entityInstantiator, Map data, + Object dataObject, Number revision) { + return entityInstantiator.createInstanceFromVersionsEntity( relatedIdData.getEntityName(), data, revision ); + } - public void mapToMapFromObject(SessionImplementor session, Map idData, Map data, Object obj) { - relatedIdData.getPrefixedMapper().mapToMapFromEntity(idData, obj); - } + @Override + public void mapToMapFromObject( + SessionImplementor session, + Map idData, + Map data, + Object obj) { + relatedIdData.getPrefixedMapper().mapToMapFromEntity( idData, obj ); + } - public void addMiddleEqualToQuery(Parameters parameters, String idPrefix1, String prefix1, String idPrefix2, String prefix2) { - relatedIdData.getPrefixedMapper().addIdsEqualToQuery(parameters, idPrefix1, idPrefix2); - } + @Override + public void addMiddleEqualToQuery( + Parameters parameters, + String idPrefix1, + String prefix1, + String idPrefix2, + String prefix2) { + relatedIdData.getPrefixedMapper().addIdsEqualToQuery( parameters, idPrefix1, idPrefix2 ); + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/component/MiddleSimpleComponentMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/component/MiddleSimpleComponentMapper.java index 4ccf1de192..25b5a2ea9a 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/component/MiddleSimpleComponentMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/component/MiddleSimpleComponentMapper.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.internal.entities.mapper.relation.component; + import java.util.Map; import org.hibernate.engine.spi.SessionImplementor; @@ -33,25 +34,38 @@ import org.hibernate.envers.internal.tools.query.Parameters; * @author Adam Warski (adam at warski dot org) */ public final class MiddleSimpleComponentMapper implements MiddleComponentMapper { - private final String propertyName; - private final AuditEntitiesConfiguration verEntCfg; + private final String propertyName; + private final AuditEntitiesConfiguration verEntCfg; - public MiddleSimpleComponentMapper(AuditEntitiesConfiguration verEntCfg, String propertyName) { - this.propertyName = propertyName; - this.verEntCfg = verEntCfg; - } + public MiddleSimpleComponentMapper(AuditEntitiesConfiguration verEntCfg, String propertyName) { + this.propertyName = propertyName; + this.verEntCfg = verEntCfg; + } - @SuppressWarnings({"unchecked"}) - public Object mapToObjectFromFullMap(EntityInstantiator entityInstantiator, Map data, - Object dataObject, Number revision) { - return ((Map) data.get(verEntCfg.getOriginalIdPropName())).get(propertyName); - } + @Override + @SuppressWarnings({"unchecked"}) + public Object mapToObjectFromFullMap( + EntityInstantiator entityInstantiator, Map data, + Object dataObject, Number revision) { + return ((Map) data.get( verEntCfg.getOriginalIdPropName() )).get( propertyName ); + } - public void mapToMapFromObject(SessionImplementor session, Map idData, Map data, Object obj) { - idData.put(propertyName, obj); - } + @Override + public void mapToMapFromObject( + SessionImplementor session, + Map idData, + Map data, + Object obj) { + idData.put( propertyName, obj ); + } - public void addMiddleEqualToQuery(Parameters parameters, String idPrefix1, String prefix1, String idPrefix2, String prefix2) { - parameters.addWhere(idPrefix1 + "." + propertyName, false, "=", idPrefix2 + "." + propertyName, false); - } + @Override + public void addMiddleEqualToQuery( + Parameters parameters, + String idPrefix1, + String prefix1, + String idPrefix2, + String prefix2) { + parameters.addWhere( idPrefix1 + "." + propertyName, false, "=", idPrefix2 + "." + propertyName, false ); + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/component/MiddleStraightComponentMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/component/MiddleStraightComponentMapper.java index 2457155d6d..02275fea4b 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/component/MiddleStraightComponentMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/component/MiddleStraightComponentMapper.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.internal.entities.mapper.relation.component; + import java.util.Map; import org.hibernate.engine.spi.SessionImplementor; @@ -30,27 +31,41 @@ import org.hibernate.envers.internal.tools.query.Parameters; /** * A mapper for reading and writing a property straight to/from maps. This mapper cannot be used with middle tables, - * but only with "fake" bidirectional indexed relations. + * but only with "fake" bidirectional indexed relations. + * * @author Adam Warski (adam at warski dot org) */ public final class MiddleStraightComponentMapper implements MiddleComponentMapper { - private final String propertyName; + private final String propertyName; - public MiddleStraightComponentMapper(String propertyName) { - this.propertyName = propertyName; - } - - @SuppressWarnings({"unchecked"}) - public Object mapToObjectFromFullMap(EntityInstantiator entityInstantiator, Map data, - Object dataObject, Number revision) { - return data.get(propertyName); - } - - public void mapToMapFromObject(SessionImplementor session, Map idData, Map data, Object obj) { - idData.put(propertyName, obj); + public MiddleStraightComponentMapper(String propertyName) { + this.propertyName = propertyName; } - public void addMiddleEqualToQuery(Parameters parameters, String idPrefix1, String prefix1, String idPrefix2, String prefix2) { - throw new UnsupportedOperationException("Cannot use this mapper with a middle table!"); - } + @Override + @SuppressWarnings({"unchecked"}) + public Object mapToObjectFromFullMap( + EntityInstantiator entityInstantiator, Map data, + Object dataObject, Number revision) { + return data.get( propertyName ); + } + + @Override + public void mapToMapFromObject( + SessionImplementor session, + Map idData, + Map data, + Object obj) { + idData.put( propertyName, obj ); + } + + @Override + public void addMiddleEqualToQuery( + Parameters parameters, + String idPrefix1, + String prefix1, + String idPrefix2, + String prefix2) { + throw new UnsupportedOperationException( "Cannot use this mapper with a middle table!" ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/AbstractDelegateSessionImplementor.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/AbstractDelegateSessionImplementor.java index cd4823b78c..57bcd04a86 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/AbstractDelegateSessionImplementor.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/AbstractDelegateSessionImplementor.java @@ -1,7 +1,7 @@ /* * Hibernate, Relational Persistence for Idiomatic Java * - * Copyright (c) 2008-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. @@ -56,22 +56,22 @@ import org.hibernate.type.Type; /** * @author Adam Warski (adam at warski dot org) */ -@SuppressWarnings( {"deprecation"}) +@SuppressWarnings({"deprecation"}) public abstract class AbstractDelegateSessionImplementor implements SessionImplementor { - protected SessionImplementor delegate; + protected SessionImplementor delegate; - public AbstractDelegateSessionImplementor(SessionImplementor delegate) { - this.delegate = delegate; - } + public AbstractDelegateSessionImplementor(SessionImplementor delegate) { + this.delegate = delegate; + } - public abstract Object doImmediateLoad(String entityName); + public abstract Object doImmediateLoad(String entityName); @Override - public Object immediateLoad(String entityName, Serializable id) throws HibernateException { - return doImmediateLoad(entityName); - } + public Object immediateLoad(String entityName, Serializable id) throws HibernateException { + return doImmediateLoad( entityName ); + } - // Delegate methods + // Delegate methods @Override @@ -106,13 +106,13 @@ public abstract class AbstractDelegateSessionImplementor implements SessionImple @Override public Interceptor getInterceptor() { - return delegate.getInterceptor(); - } + return delegate.getInterceptor(); + } @Override - public void setAutoClear(boolean enabled) { - delegate.setAutoClear(enabled); - } + public void setAutoClear(boolean enabled) { + delegate.setAutoClear( enabled ); + } @Override public void disableTransactionAutoJoin() { @@ -121,148 +121,154 @@ public abstract class AbstractDelegateSessionImplementor implements SessionImple @Override public boolean isTransactionInProgress() { - return delegate.isTransactionInProgress(); - } + return delegate.isTransactionInProgress(); + } @Override - public void initializeCollection(PersistentCollection collection, boolean writing) throws HibernateException { - delegate.initializeCollection(collection, writing); - } + public void initializeCollection(PersistentCollection collection, boolean writing) throws HibernateException { + delegate.initializeCollection( collection, writing ); + } @Override - public Object internalLoad(String entityName, Serializable id, boolean eager, boolean nullable) throws HibernateException { - return delegate.internalLoad(entityName, id, eager, nullable); - } + public Object internalLoad(String entityName, Serializable id, boolean eager, boolean nullable) + throws HibernateException { + return delegate.internalLoad( entityName, id, eager, nullable ); + } @Override - public long getTimestamp() { - return delegate.getTimestamp(); - } + public long getTimestamp() { + return delegate.getTimestamp(); + } @Override - public SessionFactoryImplementor getFactory() { - return delegate.getFactory(); - } + public SessionFactoryImplementor getFactory() { + return delegate.getFactory(); + } @Override - public List list(String query, QueryParameters queryParameters) throws HibernateException { - return delegate.list(query, queryParameters); - } + public List list(String query, QueryParameters queryParameters) throws HibernateException { + return delegate.list( query, queryParameters ); + } @Override - public Iterator iterate(String query, QueryParameters queryParameters) throws HibernateException { - return delegate.iterate(query, queryParameters); - } + public Iterator iterate(String query, QueryParameters queryParameters) throws HibernateException { + return delegate.iterate( query, queryParameters ); + } @Override - public ScrollableResults scroll(String query, QueryParameters queryParameters) throws HibernateException { - return delegate.scroll(query, queryParameters); - } + public ScrollableResults scroll(String query, QueryParameters queryParameters) throws HibernateException { + return delegate.scroll( query, queryParameters ); + } @Override - public ScrollableResults scroll(Criteria criteria, ScrollMode scrollMode) { - return delegate.scroll(criteria, scrollMode); - } + public ScrollableResults scroll(Criteria criteria, ScrollMode scrollMode) { + return delegate.scroll( criteria, scrollMode ); + } @Override - public List list(Criteria criteria) { - return delegate.list(criteria); - } + public List list(Criteria criteria) { + return delegate.list( criteria ); + } @Override - public List listFilter(Object collection, String filter, QueryParameters queryParameters) throws HibernateException { - return delegate.listFilter(collection, filter, queryParameters); - } + public List listFilter(Object collection, String filter, QueryParameters queryParameters) + throws HibernateException { + return delegate.listFilter( collection, filter, queryParameters ); + } @Override - public Iterator iterateFilter(Object collection, String filter, QueryParameters queryParameters) throws HibernateException { - return delegate.iterateFilter(collection, filter, queryParameters); - } + public Iterator iterateFilter(Object collection, String filter, QueryParameters queryParameters) + throws HibernateException { + return delegate.iterateFilter( collection, filter, queryParameters ); + } @Override - public EntityPersister getEntityPersister(String entityName, Object object) throws HibernateException { - return delegate.getEntityPersister(entityName, object); - } + public EntityPersister getEntityPersister(String entityName, Object object) throws HibernateException { + return delegate.getEntityPersister( entityName, object ); + } @Override - public Object getEntityUsingInterceptor(EntityKey key) throws HibernateException { - return delegate.getEntityUsingInterceptor(key); - } + public Object getEntityUsingInterceptor(EntityKey key) throws HibernateException { + return delegate.getEntityUsingInterceptor( key ); + } @Override - public Serializable getContextEntityIdentifier(Object object) { - return delegate.getContextEntityIdentifier(object); - } + public Serializable getContextEntityIdentifier(Object object) { + return delegate.getContextEntityIdentifier( object ); + } @Override - public String bestGuessEntityName(Object object) { - return delegate.bestGuessEntityName(object); - } + public String bestGuessEntityName(Object object) { + return delegate.bestGuessEntityName( object ); + } @Override - public String guessEntityName(Object entity) throws HibernateException { - return delegate.guessEntityName(entity); - } + public String guessEntityName(Object entity) throws HibernateException { + return delegate.guessEntityName( entity ); + } @Override - public Object instantiate(String entityName, Serializable id) throws HibernateException { - return delegate.instantiate(entityName, id); - } + public Object instantiate(String entityName, Serializable id) throws HibernateException { + return delegate.instantiate( entityName, id ); + } @Override - public List listCustomQuery(CustomQuery customQuery, QueryParameters queryParameters) throws HibernateException { - return delegate.listCustomQuery(customQuery, queryParameters); - } + public List listCustomQuery(CustomQuery customQuery, QueryParameters queryParameters) throws HibernateException { + return delegate.listCustomQuery( customQuery, queryParameters ); + } @Override - public ScrollableResults scrollCustomQuery(CustomQuery customQuery, QueryParameters queryParameters) throws HibernateException { - return delegate.scrollCustomQuery(customQuery, queryParameters); - } + public ScrollableResults scrollCustomQuery(CustomQuery customQuery, QueryParameters queryParameters) + throws HibernateException { + return delegate.scrollCustomQuery( customQuery, queryParameters ); + } @Override - public List list(NativeSQLQuerySpecification spec, QueryParameters queryParameters) throws HibernateException { - return delegate.list(spec, queryParameters); - } + public List list(NativeSQLQuerySpecification spec, QueryParameters queryParameters) throws HibernateException { + return delegate.list( spec, queryParameters ); + } @Override - public ScrollableResults scroll(NativeSQLQuerySpecification spec, QueryParameters queryParameters) throws HibernateException { - return delegate.scroll(spec, queryParameters); - } + public ScrollableResults scroll(NativeSQLQuerySpecification spec, QueryParameters queryParameters) + throws HibernateException { + return delegate.scroll( spec, queryParameters ); + } @Override - public Object getFilterParameterValue(String filterParameterName) { - return delegate.getFilterParameterValue(filterParameterName); - } + public Object getFilterParameterValue(String filterParameterName) { + return delegate.getFilterParameterValue( filterParameterName ); + } @Override - public Type getFilterParameterType(String filterParameterName) { - return delegate.getFilterParameterType(filterParameterName); - } + public Type getFilterParameterType(String filterParameterName) { + return delegate.getFilterParameterType( filterParameterName ); + } @Override - public Map getEnabledFilters() { - return delegate.getEnabledFilters(); - } + public Map getEnabledFilters() { + return delegate.getEnabledFilters(); + } @Override - public int getDontFlushFromFind() { - return delegate.getDontFlushFromFind(); - } + public int getDontFlushFromFind() { + return delegate.getDontFlushFromFind(); + } @Override - public PersistenceContext getPersistenceContext() { - return delegate.getPersistenceContext(); - } + public PersistenceContext getPersistenceContext() { + return delegate.getPersistenceContext(); + } @Override - public int executeUpdate(String query, QueryParameters queryParameters) throws HibernateException { - return delegate.executeUpdate(query, queryParameters); - } + public int executeUpdate(String query, QueryParameters queryParameters) throws HibernateException { + return delegate.executeUpdate( query, queryParameters ); + } @Override - public int executeNativeUpdate(NativeSQLQuerySpecification specification, QueryParameters queryParameters) throws HibernateException { - return delegate.executeNativeUpdate(specification, queryParameters); - } + public int executeNativeUpdate(NativeSQLQuerySpecification specification, QueryParameters queryParameters) + throws HibernateException { + return delegate.executeNativeUpdate( specification, queryParameters ); + } @Override public NonFlushedChanges getNonFlushedChanges() throws HibernateException { @@ -275,74 +281,74 @@ public abstract class AbstractDelegateSessionImplementor implements SessionImple } @Override - public CacheMode getCacheMode() { - return delegate.getCacheMode(); - } + public CacheMode getCacheMode() { + return delegate.getCacheMode(); + } @Override - public void setCacheMode(CacheMode cm) { - delegate.setCacheMode(cm); - } + public void setCacheMode(CacheMode cm) { + delegate.setCacheMode( cm ); + } @Override - public boolean isOpen() { - return delegate.isOpen(); - } + public boolean isOpen() { + return delegate.isOpen(); + } @Override - public boolean isConnected() { - return delegate.isConnected(); - } + public boolean isConnected() { + return delegate.isConnected(); + } @Override - public FlushMode getFlushMode() { - return delegate.getFlushMode(); - } + public FlushMode getFlushMode() { + return delegate.getFlushMode(); + } @Override - public void setFlushMode(FlushMode fm) { - delegate.setFlushMode(fm); - } + public void setFlushMode(FlushMode fm) { + delegate.setFlushMode( fm ); + } @Override - public Connection connection() { - return delegate.connection(); - } + public Connection connection() { + return delegate.connection(); + } @Override - public void flush() { - delegate.flush(); - } + public void flush() { + delegate.flush(); + } @Override - public Query getNamedQuery(String name) { - return delegate.getNamedQuery(name); - } + public Query getNamedQuery(String name) { + return delegate.getNamedQuery( name ); + } @Override - public Query getNamedSQLQuery(String name) { - return delegate.getNamedSQLQuery(name); - } + public Query getNamedSQLQuery(String name) { + return delegate.getNamedSQLQuery( name ); + } @Override - public boolean isEventSource() { - return delegate.isEventSource(); - } + public boolean isEventSource() { + return delegate.isEventSource(); + } @Override - public void afterScrollOperation() { - delegate.afterScrollOperation(); - } + public void afterScrollOperation() { + delegate.afterScrollOperation(); + } @Override - public void setFetchProfile(String name) { - delegate.setFetchProfile(name); - } + public void setFetchProfile(String name) { + delegate.setFetchProfile( name ); + } @Override - public String getFetchProfile() { - return delegate.getFetchProfile(); - } + public String getFetchProfile() { + return delegate.getFetchProfile(); + } @Override public TransactionCoordinator getTransactionCoordinator() { @@ -351,6 +357,6 @@ public abstract class AbstractDelegateSessionImplementor implements SessionImple @Override public boolean isClosed() { - return delegate.isClosed(); - } + return delegate.isClosed(); + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/ToOneDelegateSessionImplementor.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/ToOneDelegateSessionImplementor.java index 13394d437f..23f1855490 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/ToOneDelegateSessionImplementor.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/ToOneDelegateSessionImplementor.java @@ -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 @@ -35,27 +35,37 @@ import org.hibernate.envers.internal.reader.AuditReaderImplementor; */ public class ToOneDelegateSessionImplementor extends AbstractDelegateSessionImplementor { private static final long serialVersionUID = 4770438372940785488L; - - private final AuditReaderImplementor versionsReader; - private final Class entityClass; - private final Object entityId; - private final Number revision; - private final boolean removed; - private final AuditConfiguration verCfg; - public ToOneDelegateSessionImplementor(AuditReaderImplementor versionsReader, - Class entityClass, Object entityId, Number revision, boolean removed, - AuditConfiguration verCfg) { - super(versionsReader.getSessionImplementor()); - this.versionsReader = versionsReader; - this.entityClass = entityClass; - this.entityId = entityId; - this.revision = revision; - this.removed = removed; - this.verCfg = verCfg; - } + private final AuditReaderImplementor versionsReader; + private final Class entityClass; + private final Object entityId; + private final Number revision; + private final boolean removed; + private final AuditConfiguration verCfg; - public Object doImmediateLoad(String entityName) throws HibernateException { - return ToOneEntityLoader.loadImmediate( versionsReader, entityClass, entityName, entityId, revision, removed, verCfg ); - } + public ToOneDelegateSessionImplementor( + AuditReaderImplementor versionsReader, + Class entityClass, Object entityId, Number revision, boolean removed, + AuditConfiguration verCfg) { + super( versionsReader.getSessionImplementor() ); + this.versionsReader = versionsReader; + this.entityClass = entityClass; + this.entityId = entityId; + this.revision = revision; + this.removed = removed; + this.verCfg = verCfg; + } + + @Override + public Object doImmediateLoad(String entityName) throws HibernateException { + return ToOneEntityLoader.loadImmediate( + versionsReader, + entityClass, + entityName, + entityId, + revision, + removed, + verCfg + ); + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/initializor/AbstractCollectionInitializor.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/initializor/AbstractCollectionInitializor.java index c2d43ff8eb..55f91f2542 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/initializor/AbstractCollectionInitializor.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/initializor/AbstractCollectionInitializor.java @@ -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.internal.entities.mapper.relation.lazy.initializor; + import java.util.List; import org.hibernate.envers.configuration.spi.AuditConfiguration; @@ -31,42 +32,45 @@ import org.hibernate.envers.internal.reader.AuditReaderImplementor; /** * Initializes a persistent collection. + * * @author Adam Warski (adam at warski dot org) */ public abstract class AbstractCollectionInitializor implements Initializor { - private final AuditReaderImplementor versionsReader; - private final RelationQueryGenerator queryGenerator; - private final Object primaryKey; - protected final Number revision; + private final AuditReaderImplementor versionsReader; + private final RelationQueryGenerator queryGenerator; + private final Object primaryKey; + protected final Number revision; protected final boolean removed; - protected final EntityInstantiator entityInstantiator; + protected final EntityInstantiator entityInstantiator; - public AbstractCollectionInitializor(AuditConfiguration verCfg, - AuditReaderImplementor versionsReader, - RelationQueryGenerator queryGenerator, - Object primaryKey, Number revision, boolean removed) { - this.versionsReader = versionsReader; - this.queryGenerator = queryGenerator; - this.primaryKey = primaryKey; - this.revision = revision; + public AbstractCollectionInitializor( + AuditConfiguration verCfg, + AuditReaderImplementor versionsReader, + RelationQueryGenerator queryGenerator, + Object primaryKey, Number revision, boolean removed) { + this.versionsReader = versionsReader; + this.queryGenerator = queryGenerator; + this.primaryKey = primaryKey; + this.revision = revision; this.removed = removed; - entityInstantiator = new EntityInstantiator(verCfg, versionsReader); - } + entityInstantiator = new EntityInstantiator( verCfg, versionsReader ); + } - protected abstract T initializeCollection(int size); + protected abstract T initializeCollection(int size); - protected abstract void addToCollection(T collection, Object collectionRow); + protected abstract void addToCollection(T collection, Object collectionRow); - public T initialize() { - List collectionContent = queryGenerator.getQuery(versionsReader, primaryKey, revision, removed).list(); + @Override + public T initialize() { + final List collectionContent = queryGenerator.getQuery( versionsReader, primaryKey, revision, removed ).list(); - T collection = initializeCollection(collectionContent.size()); + final T collection = initializeCollection( collectionContent.size() ); - for (Object collectionRow : collectionContent) { - addToCollection(collection, collectionRow); - } + for ( Object collectionRow : collectionContent ) { + addToCollection( collection, collectionRow ); + } - return collection; - } + return collection; + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/initializor/ArrayCollectionInitializor.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/initializor/ArrayCollectionInitializor.java index d6116fdde5..37d1b8ccdb 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/initializor/ArrayCollectionInitializor.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/initializor/ArrayCollectionInitializor.java @@ -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.internal.entities.mapper.relation.lazy.initializor; + import java.util.List; import java.util.Map; @@ -32,39 +33,47 @@ import org.hibernate.envers.internal.reader.AuditReaderImplementor; /** * Initializes a map. + * * @author Adam Warski (adam at warski dot org) */ public class ArrayCollectionInitializor extends AbstractCollectionInitializor { - private final MiddleComponentData elementComponentData; - private final MiddleComponentData indexComponentData; + private final MiddleComponentData elementComponentData; + private final MiddleComponentData indexComponentData; - public ArrayCollectionInitializor(AuditConfiguration verCfg, - AuditReaderImplementor versionsReader, - RelationQueryGenerator queryGenerator, - Object primaryKey, Number revision, boolean removed, - MiddleComponentData elementComponentData, - MiddleComponentData indexComponentData) { - super(verCfg, versionsReader, queryGenerator, primaryKey, revision, removed); + public ArrayCollectionInitializor( + AuditConfiguration verCfg, + AuditReaderImplementor versionsReader, + RelationQueryGenerator queryGenerator, + Object primaryKey, Number revision, boolean removed, + MiddleComponentData elementComponentData, + MiddleComponentData indexComponentData) { + super( verCfg, versionsReader, queryGenerator, primaryKey, revision, removed ); - this.elementComponentData = elementComponentData; - this.indexComponentData = indexComponentData; - } + this.elementComponentData = elementComponentData; + this.indexComponentData = indexComponentData; + } - protected Object[] initializeCollection(int size) { - return new Object[size]; - } + @Override + protected Object[] initializeCollection(int size) { + return new Object[size]; + } - @SuppressWarnings({"unchecked"}) - protected void addToCollection(Object[] collection, Object collectionRow) { - Object elementData = ((List) collectionRow).get(elementComponentData.getComponentIndex()); - Object element = elementComponentData.getComponentMapper().mapToObjectFromFullMap(entityInstantiator, - (Map) elementData, null, revision); + @Override + @SuppressWarnings({"unchecked"}) + protected void addToCollection(Object[] collection, Object collectionRow) { + final Object elementData = ((List) collectionRow).get( elementComponentData.getComponentIndex() ); + final Object element = elementComponentData.getComponentMapper().mapToObjectFromFullMap( + entityInstantiator, + (Map) elementData, null, revision + ); - Object indexData = ((List) collectionRow).get(indexComponentData.getComponentIndex()); - Object indexObj = indexComponentData.getComponentMapper().mapToObjectFromFullMap(entityInstantiator, - (Map) indexData, element, revision); - int index = ((Number) indexObj).intValue(); + final Object indexData = ((List) collectionRow).get( indexComponentData.getComponentIndex() ); + final Object indexObj = indexComponentData.getComponentMapper().mapToObjectFromFullMap( + entityInstantiator, + (Map) indexData, element, revision + ); + final int index = ((Number) indexObj).intValue(); - collection[index] = element; - } + collection[index] = element; + } } \ No newline at end of file diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/initializor/BasicCollectionInitializor.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/initializor/BasicCollectionInitializor.java index f3c00bfba6..754b918099 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/initializor/BasicCollectionInitializor.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/initializor/BasicCollectionInitializor.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 @@ -37,54 +37,65 @@ import org.hibernate.internal.util.ReflectHelper; /** * Initializes a non-indexed java collection (set or list, eventually sorted). + * * @author Adam Warski (adam at warski dot org) */ public class BasicCollectionInitializor extends AbstractCollectionInitializor { - protected final Class collectionClass; - private final MiddleComponentData elementComponentData; + protected final Class collectionClass; + private final MiddleComponentData elementComponentData; - public BasicCollectionInitializor(AuditConfiguration verCfg, - AuditReaderImplementor versionsReader, - RelationQueryGenerator queryGenerator, - Object primaryKey, Number revision, boolean removed, - Class collectionClass, - MiddleComponentData elementComponentData) { - super(verCfg, versionsReader, queryGenerator, primaryKey, revision, removed); + public BasicCollectionInitializor( + AuditConfiguration verCfg, + AuditReaderImplementor versionsReader, + RelationQueryGenerator queryGenerator, + Object primaryKey, Number revision, boolean removed, + Class collectionClass, + MiddleComponentData elementComponentData) { + super( verCfg, versionsReader, queryGenerator, primaryKey, revision, removed ); - this.collectionClass = collectionClass; - this.elementComponentData = elementComponentData; - } - - protected T initializeCollection(int size) { - try { - return (T) ReflectHelper.getDefaultConstructor(collectionClass).newInstance(); - } catch (InstantiationException e) { - throw new AuditException(e); - } catch (IllegalAccessException e) { - throw new AuditException(e); - } catch (InvocationTargetException e) { - throw new AuditException(e); - } - } - - @SuppressWarnings({"unchecked"}) - protected void addToCollection(T collection, Object collectionRow) { - // collectionRow will be the actual object if retrieved from audit relation or middle table - // otherwise it will be a List - Object elementData = collectionRow; - if (collectionRow instanceof java.util.List) { - elementData = ((List) collectionRow).get(elementComponentData.getComponentIndex()); + this.collectionClass = collectionClass; + this.elementComponentData = elementComponentData; } - // If the target entity is not audited, the elements may be the entities already, so we have to check - // if they are maps or not. - Object element; - if (elementData instanceof Map) { - element = elementComponentData.getComponentMapper().mapToObjectFromFullMap(entityInstantiator, - (Map) elementData, null, revision); - } else { - element = elementData; - } - collection.add(element); - } + @Override + @SuppressWarnings("unchecked") + protected T initializeCollection(int size) { + try { + return (T) ReflectHelper.getDefaultConstructor( collectionClass ).newInstance(); + } + catch (InstantiationException e) { + throw new AuditException( e ); + } + catch (IllegalAccessException e) { + throw new AuditException( e ); + } + catch (InvocationTargetException e) { + throw new AuditException( e ); + } + } + + @Override + @SuppressWarnings({"unchecked"}) + protected void addToCollection(T collection, Object collectionRow) { + // collectionRow will be the actual object if retrieved from audit relation or middle table + // otherwise it will be a List + Object elementData = collectionRow; + if ( collectionRow instanceof java.util.List ) { + elementData = ((List) collectionRow).get( elementComponentData.getComponentIndex() ); + } + + // If the target entity is not audited, the elements may be the entities already, so we have to check + // if they are maps or not. + Object element; + if ( elementData instanceof Map ) { + element = elementComponentData.getComponentMapper().mapToObjectFromFullMap( + entityInstantiator, + (Map) elementData, null, revision + ); + } + else { + element = elementData; + } + collection.add( element ); + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/initializor/Initializor.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/initializor/Initializor.java index a283eb1d57..55116651fe 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/initializor/Initializor.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/initializor/Initializor.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 @@ -28,5 +28,5 @@ package org.hibernate.envers.internal.entities.mapper.relation.lazy.initializor; * @author Adam Warski (adam at warski dot org) */ public interface Initializor { - T initialize(); + T initialize(); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/initializor/ListCollectionInitializor.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/initializor/ListCollectionInitializor.java index 44eef60d8f..851254631d 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/initializor/ListCollectionInitializor.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/initializor/ListCollectionInitializor.java @@ -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.internal.entities.mapper.relation.lazy.initializor; + import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -33,52 +34,62 @@ import org.hibernate.envers.internal.reader.AuditReaderImplementor; /** * Initializes a map. + * * @author Adam Warski (adam at warski dot org) */ public class ListCollectionInitializor extends AbstractCollectionInitializor { - private final MiddleComponentData elementComponentData; - private final MiddleComponentData indexComponentData; + private final MiddleComponentData elementComponentData; + private final MiddleComponentData indexComponentData; - public ListCollectionInitializor(AuditConfiguration verCfg, - AuditReaderImplementor versionsReader, - RelationQueryGenerator queryGenerator, - Object primaryKey, Number revision, boolean removed, - MiddleComponentData elementComponentData, - MiddleComponentData indexComponentData) { - super(verCfg, versionsReader, queryGenerator, primaryKey, revision, removed); + public ListCollectionInitializor( + AuditConfiguration verCfg, + AuditReaderImplementor versionsReader, + RelationQueryGenerator queryGenerator, + Object primaryKey, Number revision, boolean removed, + MiddleComponentData elementComponentData, + MiddleComponentData indexComponentData) { + super( verCfg, versionsReader, queryGenerator, primaryKey, revision, removed ); - this.elementComponentData = elementComponentData; - this.indexComponentData = indexComponentData; - } - - @SuppressWarnings({"unchecked"}) - protected List initializeCollection(int size) { - // Creating a list of the given capacity with all elements null initially. This ensures that we can then - // fill the elements safely using the List.set method. - List list = new ArrayList(size); - for (int i=0; i) elementData, null, revision) - : elementData ; - Object indexObj = indexComponentData.getComponentMapper().mapToObjectFromFullMap(entityInstantiator, - (Map) indexData, element, revision); - int index = ((Number) indexObj).intValue(); + @Override + @SuppressWarnings({"unchecked"}) + protected List initializeCollection(int size) { + // Creating a list of the given capacity with all elements null initially. This ensures that we can then + // fill the elements safely using the List.set method. + final List list = new ArrayList( size ); + for ( int i = 0; i < size; i++ ) { + list.add( null ); + } + return list; + } - collection.set(index, element); - } + @Override + @SuppressWarnings({"unchecked"}) + protected void addToCollection(List collection, Object collectionRow) { + // collectionRow will be the actual object if retrieved from audit relation or middle table + // otherwise it will be a List + Object elementData = collectionRow; + Object indexData = collectionRow; + if ( collectionRow instanceof java.util.List ) { + elementData = ((List) collectionRow).get( elementComponentData.getComponentIndex() ); + indexData = ((List) collectionRow).get( indexComponentData.getComponentIndex() ); + } + final Object element = elementData instanceof Map + ? elementComponentData.getComponentMapper().mapToObjectFromFullMap( + entityInstantiator, + (Map) elementData, null, revision + ) + : elementData; + + final Object indexObj = indexComponentData.getComponentMapper().mapToObjectFromFullMap( + entityInstantiator, + (Map) indexData, element, revision + ); + final int index = ((Number) indexObj).intValue(); + + collection.set( index, element ); + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/initializor/MapCollectionInitializor.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/initializor/MapCollectionInitializor.java index 7994fad18f..f6d1c34104 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/initializor/MapCollectionInitializor.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/initializor/MapCollectionInitializor.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 @@ -36,55 +36,67 @@ import org.hibernate.internal.util.ReflectHelper; /** * Initializes a map. + * * @author Adam Warski (adam at warski dot org) */ public class MapCollectionInitializor extends AbstractCollectionInitializor { - protected final Class collectionClass; - private final MiddleComponentData elementComponentData; - private final MiddleComponentData indexComponentData; + protected final Class collectionClass; + private final MiddleComponentData elementComponentData; + private final MiddleComponentData indexComponentData; - public MapCollectionInitializor(AuditConfiguration verCfg, - AuditReaderImplementor versionsReader, - RelationQueryGenerator queryGenerator, - Object primaryKey, Number revision, boolean removed, - Class collectionClass, - MiddleComponentData elementComponentData, - MiddleComponentData indexComponentData) { - super(verCfg, versionsReader, queryGenerator, primaryKey, revision, removed); + public MapCollectionInitializor( + AuditConfiguration verCfg, + AuditReaderImplementor versionsReader, + RelationQueryGenerator queryGenerator, + Object primaryKey, Number revision, boolean removed, + Class collectionClass, + MiddleComponentData elementComponentData, + MiddleComponentData indexComponentData) { + super( verCfg, versionsReader, queryGenerator, primaryKey, revision, removed ); - this.collectionClass = collectionClass; - this.elementComponentData = elementComponentData; - this.indexComponentData = indexComponentData; - } - - protected T initializeCollection(int size) { - try { - return (T) ReflectHelper.getDefaultConstructor(collectionClass).newInstance(); - } catch (InstantiationException e) { - throw new AuditException(e); - } catch (IllegalAccessException e) { - throw new AuditException(e); - } catch (InvocationTargetException e) { - throw new AuditException(e); - } - } - - @SuppressWarnings({"unchecked"}) - protected void addToCollection(T collection, Object collectionRow) { - // collectionRow will be the actual object if retrieved from audit relation or middle table - // otherwise it will be a List - Object elementData = collectionRow; - Object indexData = collectionRow; - if (collectionRow instanceof java.util.List) { - elementData = ((List) collectionRow).get(elementComponentData.getComponentIndex()); - indexData = ((List) collectionRow).get(indexComponentData.getComponentIndex()); + this.collectionClass = collectionClass; + this.elementComponentData = elementComponentData; + this.indexComponentData = indexComponentData; } - Object element = elementComponentData.getComponentMapper().mapToObjectFromFullMap(entityInstantiator, - (Map) elementData, null, revision); - Object index = indexComponentData.getComponentMapper().mapToObjectFromFullMap(entityInstantiator, - (Map) indexData, element, revision); + @Override + @SuppressWarnings("unchecked") + protected T initializeCollection(int size) { + try { + return (T) ReflectHelper.getDefaultConstructor( collectionClass ).newInstance(); + } + catch (InstantiationException e) { + throw new AuditException( e ); + } + catch (IllegalAccessException e) { + throw new AuditException( e ); + } + catch (InvocationTargetException e) { + throw new AuditException( e ); + } + } - collection.put(index, element); - } + @Override + @SuppressWarnings({"unchecked"}) + protected void addToCollection(T collection, Object collectionRow) { + // collectionRow will be the actual object if retrieved from audit relation or middle table + // otherwise it will be a List + Object elementData = collectionRow; + Object indexData = collectionRow; + if ( collectionRow instanceof java.util.List ) { + elementData = ((List) collectionRow).get( elementComponentData.getComponentIndex() ); + indexData = ((List) collectionRow).get( indexComponentData.getComponentIndex() ); + } + final Object element = elementComponentData.getComponentMapper().mapToObjectFromFullMap( + entityInstantiator, + (Map) elementData, null, revision + ); + + final Object index = indexComponentData.getComponentMapper().mapToObjectFromFullMap( + entityInstantiator, + (Map) indexData, element, revision + ); + + collection.put( index, element ); + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/initializor/SortedMapCollectionInitializor.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/initializor/SortedMapCollectionInitializor.java index d7107e6482..562d4f3546 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/initializor/SortedMapCollectionInitializor.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/initializor/SortedMapCollectionInitializor.java @@ -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 @@ -41,31 +41,47 @@ import org.hibernate.envers.internal.reader.AuditReaderImplementor; public class SortedMapCollectionInitializor extends MapCollectionInitializor { private final Comparator comparator; - public SortedMapCollectionInitializor(AuditConfiguration verCfg, - AuditReaderImplementor versionsReader, - RelationQueryGenerator queryGenerator, - Object primaryKey, Number revision, boolean removed, - Class collectionClass, - MiddleComponentData elementComponentData, - MiddleComponentData indexComponentData, Comparator comparator) { - super(verCfg, versionsReader, queryGenerator, primaryKey, revision, removed, collectionClass, elementComponentData, indexComponentData); + public SortedMapCollectionInitializor( + AuditConfiguration verCfg, + AuditReaderImplementor versionsReader, + RelationQueryGenerator queryGenerator, + Object primaryKey, Number revision, boolean removed, + Class collectionClass, + MiddleComponentData elementComponentData, + MiddleComponentData indexComponentData, Comparator comparator) { + super( + verCfg, + versionsReader, + queryGenerator, + primaryKey, + revision, + removed, + collectionClass, + elementComponentData, + indexComponentData + ); this.comparator = comparator; } + @Override protected SortedMap initializeCollection(int size) { - if (comparator == null) { - return super.initializeCollection(size); + if ( comparator == null ) { + return super.initializeCollection( size ); } try { - return collectionClass.getConstructor(Comparator.class).newInstance(comparator); - } catch (InstantiationException e) { - throw new AuditException(e); - } catch (IllegalAccessException e) { - throw new AuditException(e); - } catch (NoSuchMethodException e) { - throw new AuditException(e); - } catch (InvocationTargetException e) { - throw new AuditException(e); + return collectionClass.getConstructor( Comparator.class ).newInstance( comparator ); + } + catch (InstantiationException e) { + throw new AuditException( e ); + } + catch (IllegalAccessException e) { + throw new AuditException( e ); + } + catch (NoSuchMethodException e) { + throw new AuditException( e ); + } + catch (InvocationTargetException e) { + throw new AuditException( e ); } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/initializor/SortedSetCollectionInitializor.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/initializor/SortedSetCollectionInitializor.java index 3958de056e..f171e5f68b 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/initializor/SortedSetCollectionInitializor.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/initializor/SortedSetCollectionInitializor.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 @@ -41,29 +41,43 @@ import org.hibernate.envers.internal.reader.AuditReaderImplementor; public class SortedSetCollectionInitializor extends BasicCollectionInitializor { private final Comparator comparator; - public SortedSetCollectionInitializor(AuditConfiguration verCfg, AuditReaderImplementor versionsReader, - RelationQueryGenerator queryGenerator, Object primaryKey, Number revision, boolean removed, - Class collectionClass, MiddleComponentData elementComponentData, - Comparator comparator) { - super(verCfg, versionsReader, queryGenerator, primaryKey, revision, removed, collectionClass, elementComponentData); + public SortedSetCollectionInitializor( + AuditConfiguration verCfg, AuditReaderImplementor versionsReader, + RelationQueryGenerator queryGenerator, Object primaryKey, Number revision, boolean removed, + Class collectionClass, MiddleComponentData elementComponentData, + Comparator comparator) { + super( + verCfg, + versionsReader, + queryGenerator, + primaryKey, + revision, + removed, + collectionClass, + elementComponentData + ); this.comparator = comparator; } @Override protected SortedSet initializeCollection(int size) { - if (comparator == null) { - return super.initializeCollection(size); + if ( comparator == null ) { + return super.initializeCollection( size ); } try { - return collectionClass.getConstructor(Comparator.class).newInstance(comparator); - } catch (InstantiationException e) { - throw new AuditException(e); - } catch (IllegalAccessException e) { - throw new AuditException(e); - } catch (NoSuchMethodException e) { - throw new AuditException(e); - } catch (InvocationTargetException e) { - throw new AuditException(e); + return collectionClass.getConstructor( Comparator.class ).newInstance( comparator ); + } + catch (InstantiationException e) { + throw new AuditException( e ); + } + catch (IllegalAccessException e) { + throw new AuditException( e ); + } + catch (NoSuchMethodException e) { + throw new AuditException( e ); + } + catch (InvocationTargetException e) { + throw new AuditException( e ); } } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/proxy/CollectionProxy.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/proxy/CollectionProxy.java index d44180cbe0..74cc36fd50 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/proxy/CollectionProxy.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/proxy/CollectionProxy.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.internal.entities.mapper.relation.lazy.proxy; + import java.io.Serializable; import java.util.Collection; import java.util.Iterator; @@ -35,102 +36,115 @@ public abstract class CollectionProxy> implements Col private static final long serialVersionUID = 8698249863871832402L; private transient org.hibernate.envers.internal.entities.mapper.relation.lazy.initializor.Initializor initializor; - protected T delegate; + protected T delegate; - protected CollectionProxy() { - } + protected CollectionProxy() { + } - public CollectionProxy(Initializor initializor) { - this.initializor = initializor; - } + public CollectionProxy(Initializor initializor) { + this.initializor = initializor; + } - protected void checkInit() { - if (delegate == null) { - delegate = initializor.initialize(); - } - } + protected void checkInit() { + if ( delegate == null ) { + delegate = initializor.initialize(); + } + } - public int size() { - checkInit(); - return delegate.size(); - } + @Override + public int size() { + checkInit(); + return delegate.size(); + } - public boolean isEmpty() { - checkInit(); - return delegate.isEmpty(); - } + @Override + public boolean isEmpty() { + checkInit(); + return delegate.isEmpty(); + } - public boolean contains(Object o) { - checkInit(); - return delegate.contains(o); - } + @Override + public boolean contains(Object o) { + checkInit(); + return delegate.contains( o ); + } - public Iterator iterator() { - checkInit(); - return delegate.iterator(); - } + @Override + public Iterator iterator() { + checkInit(); + return delegate.iterator(); + } - public Object[] toArray() { - checkInit(); - return delegate.toArray(); - } + @Override + public Object[] toArray() { + checkInit(); + return delegate.toArray(); + } - public V[] toArray(V[] a) { - checkInit(); - return delegate.toArray(a); - } + @Override + public V[] toArray(V[] a) { + checkInit(); + return delegate.toArray( a ); + } - public boolean add(U o) { - checkInit(); - return delegate.add(o); - } + @Override + public boolean add(U o) { + checkInit(); + return delegate.add( o ); + } - public boolean remove(Object o) { - checkInit(); - return delegate.remove(o); - } + @Override + public boolean remove(Object o) { + checkInit(); + return delegate.remove( o ); + } - public boolean containsAll(Collection c) { - checkInit(); - return delegate.containsAll(c); - } + @Override + public boolean containsAll(Collection c) { + checkInit(); + return delegate.containsAll( c ); + } - public boolean addAll(Collection c) { - checkInit(); - return delegate.addAll(c); - } + @Override + public boolean addAll(Collection c) { + checkInit(); + return delegate.addAll( c ); + } - public boolean removeAll(Collection c) { - checkInit(); - return delegate.removeAll(c); - } + @Override + public boolean removeAll(Collection c) { + checkInit(); + return delegate.removeAll( c ); + } - public boolean retainAll(Collection c) { - checkInit(); - return delegate.retainAll(c); - } + @Override + public boolean retainAll(Collection c) { + checkInit(); + return delegate.retainAll( c ); + } - public void clear() { - checkInit(); - delegate.clear(); - } + @Override + public void clear() { + checkInit(); + delegate.clear(); + } - @Override - public String toString() { - checkInit(); - return delegate.toString(); - } + @Override + public String toString() { + checkInit(); + return delegate.toString(); + } - @SuppressWarnings({"EqualsWhichDoesntCheckParameterClass"}) - @Override - public boolean equals(Object obj) { - checkInit(); - return delegate.equals(obj); - } + @SuppressWarnings({"EqualsWhichDoesntCheckParameterClass"}) + @Override + public boolean equals(Object obj) { + checkInit(); + return delegate.equals( obj ); + } - @Override - public int hashCode() { - checkInit(); - return delegate.hashCode(); - } + @Override + public int hashCode() { + checkInit(); + return delegate.hashCode(); + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/proxy/ListProxy.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/proxy/ListProxy.java index 348f778711..55ccf5de52 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/proxy/ListProxy.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/proxy/ListProxy.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.internal.entities.mapper.relation.lazy.proxy; + import java.util.Collection; import java.util.List; import java.util.ListIterator; @@ -30,62 +31,72 @@ import java.util.ListIterator; * @author Adam Warski (adam at warski dot org) */ public class ListProxy extends CollectionProxy> implements List { - private static final long serialVersionUID = -5479232938279790987L; + private static final long serialVersionUID = -5479232938279790987L; - public ListProxy() { - } + public ListProxy() { + } - public ListProxy(org.hibernate.envers.internal.entities.mapper.relation.lazy.initializor.Initializor> initializor) { - super(initializor); - } + public ListProxy(org.hibernate.envers.internal.entities.mapper.relation.lazy.initializor.Initializor> initializor) { + super( initializor ); + } - public boolean addAll(int index, Collection c) { - checkInit(); - return delegate.addAll(index, c); - } + @Override + public boolean addAll(int index, Collection c) { + checkInit(); + return delegate.addAll( index, c ); + } - public U get(int index) { - checkInit(); - return delegate.get(index); - } + @Override + public U get(int index) { + checkInit(); + return delegate.get( index ); + } - public U set(int index, U element) { - checkInit(); - return delegate.set(index, element); - } + @Override + public U set(int index, U element) { + checkInit(); + return delegate.set( index, element ); + } - public void add(int index, U element) { - checkInit(); - delegate.add(index, element); - } + @Override + public void add(int index, U element) { + checkInit(); + delegate.add( index, element ); + } - public U remove(int index) { - checkInit(); - return delegate.remove(index); - } + @Override + public U remove(int index) { + checkInit(); + return delegate.remove( index ); + } - public int indexOf(Object o) { - checkInit(); - return delegate.indexOf(o); - } + @Override + public int indexOf(Object o) { + checkInit(); + return delegate.indexOf( o ); + } - public int lastIndexOf(Object o) { - checkInit(); - return delegate.lastIndexOf(o); - } + @Override + public int lastIndexOf(Object o) { + checkInit(); + return delegate.lastIndexOf( o ); + } - public ListIterator listIterator() { - checkInit(); - return delegate.listIterator(); - } + @Override + public ListIterator listIterator() { + checkInit(); + return delegate.listIterator(); + } - public ListIterator listIterator(int index) { - checkInit(); - return delegate.listIterator(index); - } + @Override + public ListIterator listIterator(int index) { + checkInit(); + return delegate.listIterator( index ); + } - public List subList(int fromIndex, int toIndex) { - checkInit(); - return delegate.subList(fromIndex, toIndex); - } + @Override + public List subList(int fromIndex, int toIndex) { + checkInit(); + return delegate.subList( fromIndex, toIndex ); + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/proxy/MapProxy.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/proxy/MapProxy.java index bbc4e97386..f1096ef82e 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/proxy/MapProxy.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/proxy/MapProxy.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.internal.entities.mapper.relation.lazy.proxy; + import java.io.Serializable; import java.util.Collection; import java.util.Map; @@ -33,100 +34,112 @@ import org.hibernate.envers.internal.entities.mapper.relation.lazy.initializor.I * @author Adam Warski (adam at warski dot org) */ public class MapProxy implements Map, Serializable { - private static final long serialVersionUID = 8418037541773074646L; + private static final long serialVersionUID = 8418037541773074646L; - private transient Initializor> initializor; - protected Map delegate; + private transient Initializor> initializor; + protected Map delegate; - public MapProxy() { - } + public MapProxy() { + } - public MapProxy(org.hibernate.envers.internal.entities.mapper.relation.lazy.initializor.Initializor> initializor) { - this.initializor = initializor; - } + public MapProxy(org.hibernate.envers.internal.entities.mapper.relation.lazy.initializor.Initializor> initializor) { + this.initializor = initializor; + } - private void checkInit() { - if (delegate == null) { - delegate = initializor.initialize(); - } - } + private void checkInit() { + if ( delegate == null ) { + delegate = initializor.initialize(); + } + } - public int size() { - checkInit(); - return delegate.size(); - } + @Override + public int size() { + checkInit(); + return delegate.size(); + } - public boolean isEmpty() { - checkInit(); - return delegate.isEmpty(); - } + @Override + public boolean isEmpty() { + checkInit(); + return delegate.isEmpty(); + } - public boolean containsKey(Object o) { - checkInit(); - return delegate.containsKey(o); - } + @Override + public boolean containsKey(Object o) { + checkInit(); + return delegate.containsKey( o ); + } - public boolean containsValue(Object o) { - checkInit(); - return delegate.containsValue(o); - } + @Override + public boolean containsValue(Object o) { + checkInit(); + return delegate.containsValue( o ); + } - public V get(Object o) { - checkInit(); - return delegate.get(o); - } + @Override + public V get(Object o) { + checkInit(); + return delegate.get( o ); + } - public V put(K k, V v) { - checkInit(); - return delegate.put(k, v); - } + @Override + public V put(K k, V v) { + checkInit(); + return delegate.put( k, v ); + } - public V remove(Object o) { - checkInit(); - return delegate.remove(o); - } + @Override + public V remove(Object o) { + checkInit(); + return delegate.remove( o ); + } - public void putAll(Map map) { - checkInit(); - delegate.putAll(map); - } + @Override + public void putAll(Map map) { + checkInit(); + delegate.putAll( map ); + } - public void clear() { - checkInit(); - delegate.clear(); - } + @Override + public void clear() { + checkInit(); + delegate.clear(); + } - public Set keySet() { - checkInit(); - return delegate.keySet(); - } + @Override + public Set keySet() { + checkInit(); + return delegate.keySet(); + } - public Collection values() { - checkInit(); - return delegate.values(); - } + @Override + public Collection values() { + checkInit(); + return delegate.values(); + } - public Set> entrySet() { - checkInit(); - return delegate.entrySet(); - } + @Override + public Set> entrySet() { + checkInit(); + return delegate.entrySet(); + } - @Override - public String toString() { - checkInit(); - return delegate.toString(); - } + @Override + public String toString() { + checkInit(); + return delegate.toString(); + } - @SuppressWarnings({"EqualsWhichDoesntCheckParameterClass"}) - @Override - public boolean equals(Object obj) { - checkInit(); - return delegate.equals(obj); - } + @Override + @SuppressWarnings({"EqualsWhichDoesntCheckParameterClass"}) + public boolean equals(Object obj) { + checkInit(); + return delegate.equals( obj ); + } - @Override - public int hashCode() { - checkInit(); - return delegate.hashCode(); - } + @Override + public int hashCode() { + checkInit(); + return delegate.hashCode(); + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/proxy/SetProxy.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/proxy/SetProxy.java index e57473b887..ae7648a10c 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/proxy/SetProxy.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/proxy/SetProxy.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,18 +22,19 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.internal.entities.mapper.relation.lazy.proxy; + import java.util.Set; /** * @author Adam Warski (adam at warski dot org) */ public class SetProxy extends CollectionProxy> implements Set { - private static final long serialVersionUID = 131464133074137701L; + private static final long serialVersionUID = 131464133074137701L; - public SetProxy() { - } + public SetProxy() { + } - public SetProxy(org.hibernate.envers.internal.entities.mapper.relation.lazy.initializor.Initializor> initializor) { - super(initializor); - } + public SetProxy(org.hibernate.envers.internal.entities.mapper.relation.lazy.initializor.Initializor> initializor) { + super( initializor ); + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/proxy/SortedMapProxy.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/proxy/SortedMapProxy.java index 51a199125f..25e8c19f84 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/proxy/SortedMapProxy.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/proxy/SortedMapProxy.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.internal.entities.mapper.relation.lazy.proxy; + import java.io.Serializable; import java.util.Collection; import java.util.Comparator; @@ -35,122 +36,142 @@ import org.hibernate.envers.internal.entities.mapper.relation.lazy.initializor.I * @author Adam Warski (adam at warski dot org) */ public class SortedMapProxy implements SortedMap, Serializable { - private static final long serialVersionUID = 2645817952901452375L; + private static final long serialVersionUID = 2645817952901452375L; - private transient Initializor> initializor; - protected SortedMap delegate; + private transient Initializor> initializor; + protected SortedMap delegate; - public SortedMapProxy() { - } + public SortedMapProxy() { + } - public SortedMapProxy(org.hibernate.envers.internal.entities.mapper.relation.lazy.initializor.Initializor> initializor) { - this.initializor = initializor; - } + public SortedMapProxy(org.hibernate.envers.internal.entities.mapper.relation.lazy.initializor.Initializor> initializor) { + this.initializor = initializor; + } - private void checkInit() { - if (delegate == null) { - delegate = initializor.initialize(); - } - } + private void checkInit() { + if ( delegate == null ) { + delegate = initializor.initialize(); + } + } - public int size() { - checkInit(); - return delegate.size(); - } + @Override + public int size() { + checkInit(); + return delegate.size(); + } - public boolean isEmpty() { - checkInit(); - return delegate.isEmpty(); - } + @Override + public boolean isEmpty() { + checkInit(); + return delegate.isEmpty(); + } - public boolean containsKey(Object o) { - checkInit(); - return delegate.containsKey(o); - } + @Override + public boolean containsKey(Object o) { + checkInit(); + return delegate.containsKey( o ); + } - public boolean containsValue(Object o) { - checkInit(); - return delegate.containsValue(o); - } + @Override + public boolean containsValue(Object o) { + checkInit(); + return delegate.containsValue( o ); + } - public V get(Object o) { - checkInit(); - return delegate.get(o); - } + @Override + public V get(Object o) { + checkInit(); + return delegate.get( o ); + } - public V put(K k, V v) { - checkInit(); - return delegate.put(k, v); - } + @Override + public V put(K k, V v) { + checkInit(); + return delegate.put( k, v ); + } - public V remove(Object o) { - checkInit(); - return delegate.remove(o); - } + @Override + public V remove(Object o) { + checkInit(); + return delegate.remove( o ); + } - public void putAll(Map map) { - checkInit(); - delegate.putAll(map); - } + @Override + public void putAll(Map map) { + checkInit(); + delegate.putAll( map ); + } - public void clear() { - checkInit(); - delegate.clear(); - } + @Override + public void clear() { + checkInit(); + delegate.clear(); + } - public Set keySet() { - checkInit(); - return delegate.keySet(); - } + @Override + public Set keySet() { + checkInit(); + return delegate.keySet(); + } - public Collection values() { - checkInit(); - return delegate.values(); - } + @Override + public Collection values() { + checkInit(); + return delegate.values(); + } - public Set> entrySet() { - checkInit(); - return delegate.entrySet(); - } + @Override + public Set> entrySet() { + checkInit(); + return delegate.entrySet(); + } - public Comparator comparator() { - checkInit(); - return delegate.comparator(); - } + @Override + public Comparator comparator() { + checkInit(); + return delegate.comparator(); + } - public SortedMap subMap(K k, K k1) { - checkInit(); - return delegate.subMap(k, k1); - } + @Override + public SortedMap subMap(K k, K k1) { + checkInit(); + return delegate.subMap( k, k1 ); + } - public SortedMap headMap(K k) { - checkInit(); - return delegate.headMap(k); - } + @Override + public SortedMap headMap(K k) { + checkInit(); + return delegate.headMap( k ); + } - public SortedMap tailMap(K k) { - checkInit(); - return delegate.tailMap(k); - } + @Override + public SortedMap tailMap(K k) { + checkInit(); + return delegate.tailMap( k ); + } - public K firstKey() { - checkInit(); - return delegate.firstKey(); - } + @Override + public K firstKey() { + checkInit(); + return delegate.firstKey(); + } - public K lastKey() { - checkInit(); - return delegate.lastKey(); - } + @Override + public K lastKey() { + checkInit(); + return delegate.lastKey(); + } - @SuppressWarnings({"EqualsWhichDoesntCheckParameterClass"}) - public boolean equals(Object o) { - checkInit(); - return delegate.equals(o); - } + @Override + @SuppressWarnings({"EqualsWhichDoesntCheckParameterClass"}) + public boolean equals(Object o) { + checkInit(); + return delegate.equals( o ); + } - public int hashCode() { - checkInit(); - return delegate.hashCode(); - } + @Override + public int hashCode() { + checkInit(); + return delegate.hashCode(); + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/proxy/SortedSetProxy.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/proxy/SortedSetProxy.java index 962a754094..3b189e2de6 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/proxy/SortedSetProxy.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/proxy/SortedSetProxy.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.internal.entities.mapper.relation.lazy.proxy; + import java.util.Comparator; import java.util.SortedSet; @@ -29,42 +30,48 @@ import java.util.SortedSet; * @author Adam Warski (adam at warski dot org) */ public class SortedSetProxy extends CollectionProxy> implements SortedSet { - private static final long serialVersionUID = 2092884107178125905L; + private static final long serialVersionUID = 2092884107178125905L; - public SortedSetProxy() { - } + public SortedSetProxy() { + } - public SortedSetProxy(org.hibernate.envers.internal.entities.mapper.relation.lazy.initializor.Initializor> initializor) { - super(initializor); - } + public SortedSetProxy(org.hibernate.envers.internal.entities.mapper.relation.lazy.initializor.Initializor> initializor) { + super( initializor ); + } - public Comparator comparator() { - checkInit(); - return delegate.comparator(); - } + @Override + public Comparator comparator() { + checkInit(); + return delegate.comparator(); + } - public SortedSet subSet(U u, U u1) { - checkInit(); - return delegate.subSet(u, u1); - } + @Override + public SortedSet subSet(U u, U u1) { + checkInit(); + return delegate.subSet( u, u1 ); + } - public SortedSet headSet(U u) { - checkInit(); - return delegate.headSet(u); - } + @Override + public SortedSet headSet(U u) { + checkInit(); + return delegate.headSet( u ); + } - public SortedSet tailSet(U u) { - checkInit(); - return delegate.tailSet(u); - } + @Override + public SortedSet tailSet(U u) { + checkInit(); + return delegate.tailSet( u ); + } - public U first() { - checkInit(); - return delegate.first(); - } + @Override + public U first() { + checkInit(); + return delegate.first(); + } - public U last() { - checkInit(); - return delegate.last(); - } + @Override + public U last() { + checkInit(); + return delegate.last(); + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/query/AbstractRelationQueryGenerator.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/query/AbstractRelationQueryGenerator.java index 7c73f61b52..e30e4626f7 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/query/AbstractRelationQueryGenerator.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/query/AbstractRelationQueryGenerator.java @@ -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 @@ -47,8 +47,9 @@ public abstract class AbstractRelationQueryGenerator implements RelationQueryGen protected final MiddleIdData referencingIdData; protected final boolean revisionTypeInId; - protected AbstractRelationQueryGenerator(AuditEntitiesConfiguration verEntCfg, MiddleIdData referencingIdData, - boolean revisionTypeInId) { + protected AbstractRelationQueryGenerator( + AuditEntitiesConfiguration verEntCfg, MiddleIdData referencingIdData, + boolean revisionTypeInId) { this.verEntCfg = verEntCfg; this.referencingIdData = referencingIdData; this.revisionTypeInId = revisionTypeInId; @@ -61,16 +62,19 @@ public abstract class AbstractRelationQueryGenerator implements RelationQueryGen /** * @return Query executed to retrieve state of audited entity valid at previous revision - * or removed during exactly specified revision number. Used only when traversing deleted - * entities graph. + * or removed during exactly specified revision number. Used only when traversing deleted + * entities graph. */ protected abstract String getQueryRemovedString(); + @Override public Query getQuery(AuditReaderImplementor versionsReader, Object primaryKey, Number revision, boolean removed) { - Query query = versionsReader.getSession().createQuery( removed ? getQueryRemovedString() : getQueryString() ); + final Query query = versionsReader.getSession().createQuery( removed ? getQueryRemovedString() : getQueryString() ); query.setParameter( DEL_REVISION_TYPE_PARAMETER, RevisionType.DEL ); query.setParameter( REVISION_PARAMETER, revision ); - for ( QueryParameterData paramData : referencingIdData.getPrefixedMapper().mapToQueryParametersFromId( primaryKey ) ) { + for ( QueryParameterData paramData : referencingIdData.getPrefixedMapper().mapToQueryParametersFromId( + primaryKey + ) ) { paramData.setParameterValue( query ); } return query; diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/query/OneAuditEntityQueryGenerator.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/query/OneAuditEntityQueryGenerator.java index 7fdab24325..87c54f2b5c 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/query/OneAuditEntityQueryGenerator.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/query/OneAuditEntityQueryGenerator.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 @@ -45,9 +45,10 @@ public final class OneAuditEntityQueryGenerator extends AbstractRelationQueryGen private final String queryString; private final String queryRemovedString; - public OneAuditEntityQueryGenerator(GlobalConfiguration globalCfg, AuditEntitiesConfiguration verEntCfg, - AuditStrategy auditStrategy, MiddleIdData referencingIdData, - String referencedEntityName, MiddleIdData referencedIdData, boolean revisionTypeInId) { + public OneAuditEntityQueryGenerator( + GlobalConfiguration globalCfg, AuditEntitiesConfiguration verEntCfg, + AuditStrategy auditStrategy, MiddleIdData referencingIdData, + String referencedEntityName, MiddleIdData referencedIdData, boolean revisionTypeInId) { super( verEntCfg, referencingIdData, revisionTypeInId ); /* @@ -96,9 +97,10 @@ public final class OneAuditEntityQueryGenerator extends AbstractRelationQueryGen /** * Creates query restrictions used to retrieve only actual data. */ - private void createValidDataRestrictions(GlobalConfiguration globalCfg, AuditStrategy auditStrategy, - MiddleIdData referencedIdData, QueryBuilder qb, Parameters rootParameters, - boolean inclusive) { + private void createValidDataRestrictions( + GlobalConfiguration globalCfg, AuditStrategy auditStrategy, + MiddleIdData referencedIdData, QueryBuilder qb, Parameters rootParameters, + boolean inclusive) { final String revisionPropertyPath = verEntCfg.getRevisionNumberPath(); // (selecting e entities at revision :revision) // --> based on auditStrategy (see above) @@ -115,11 +117,14 @@ public final class OneAuditEntityQueryGenerator extends AbstractRelationQueryGen /** * Create query restrictions used to retrieve actual data and deletions that took place at exactly given revision. */ - private void createValidAndRemovedDataRestrictions(GlobalConfiguration globalCfg, AuditStrategy auditStrategy, - MiddleIdData referencedIdData, QueryBuilder remQb) { + private void createValidAndRemovedDataRestrictions( + GlobalConfiguration globalCfg, AuditStrategy auditStrategy, + MiddleIdData referencedIdData, QueryBuilder remQb) { final Parameters disjoint = remQb.getRootParameters().addSubParameters( "or" ); - final Parameters valid = disjoint.addSubParameters( "and" ); // Restrictions to match all valid rows. - final Parameters removed = disjoint.addSubParameters( "and" ); // Restrictions to match all rows deleted at exactly given revision. + // Restrictions to match all valid rows. + final Parameters valid = disjoint.addSubParameters( "and" ); + // Restrictions to match all rows deleted at exactly given revision. + final Parameters removed = disjoint.addSubParameters( "and" ); // Excluding current revision, because we need to match data valid at the previous one. createValidDataRestrictions( globalCfg, auditStrategy, referencedIdData, remQb, valid, false ); // e.revision = :revision diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/query/OneEntityQueryGenerator.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/query/OneEntityQueryGenerator.java index 66575b2bf2..63402f0511 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/query/OneEntityQueryGenerator.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/query/OneEntityQueryGenerator.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 @@ -44,9 +44,10 @@ public final class OneEntityQueryGenerator extends AbstractRelationQueryGenerato private final String queryString; private final String queryRemovedString; - public OneEntityQueryGenerator(AuditEntitiesConfiguration verEntCfg, AuditStrategy auditStrategy, - String versionsMiddleEntityName, MiddleIdData referencingIdData, - boolean revisionTypeInId, MiddleComponentData... componentData) { + public OneEntityQueryGenerator( + AuditEntitiesConfiguration verEntCfg, AuditStrategy auditStrategy, + String versionsMiddleEntityName, MiddleIdData referencingIdData, + boolean revisionTypeInId, MiddleComponentData... componentData) { super( verEntCfg, referencingIdData, revisionTypeInId ); /* @@ -89,16 +90,21 @@ public final class OneEntityQueryGenerator extends AbstractRelationQueryGenerato qb.addProjection( null, MIDDLE_ENTITY_ALIAS, false, false ); // WHERE // ee.originalId.id_ref_ing = :id_ref_ing - referencingIdData.getPrefixedMapper().addNamedIdEqualsToQuery( qb.getRootParameters(), verEntCfg.getOriginalIdPropName(), true ); + referencingIdData.getPrefixedMapper().addNamedIdEqualsToQuery( + qb.getRootParameters(), + verEntCfg.getOriginalIdPropName(), + true + ); return qb; } /** * Creates query restrictions used to retrieve only actual data. */ - private void createValidDataRestrictions(AuditStrategy auditStrategy, String versionsMiddleEntityName, - QueryBuilder qb, Parameters rootParameters, boolean inclusive, - MiddleComponentData... componentData) { + private void createValidDataRestrictions( + AuditStrategy auditStrategy, String versionsMiddleEntityName, + QueryBuilder qb, Parameters rootParameters, boolean inclusive, + MiddleComponentData... componentData) { final String revisionPropertyPath = verEntCfg.getRevisionNumberPath(); final String originalIdPropertyName = verEntCfg.getOriginalIdPropName(); final String eeOriginalIdPropertyPath = MIDDLE_ENTITY_ALIAS + "." + originalIdPropertyName; @@ -116,11 +122,14 @@ public final class OneEntityQueryGenerator extends AbstractRelationQueryGenerato /** * Create query restrictions used to retrieve actual data and deletions that took place at exactly given revision. */ - private void createValidAndRemovedDataRestrictions(AuditStrategy auditStrategy, String versionsMiddleEntityName, - QueryBuilder remQb, MiddleComponentData... componentData) { + private void createValidAndRemovedDataRestrictions( + AuditStrategy auditStrategy, String versionsMiddleEntityName, + QueryBuilder remQb, MiddleComponentData... componentData) { final Parameters disjoint = remQb.getRootParameters().addSubParameters( "or" ); - final Parameters valid = disjoint.addSubParameters( "and" ); // Restrictions to match all valid rows. - final Parameters removed = disjoint.addSubParameters( "and" ); // Restrictions to match all rows deleted at exactly given revision. + // Restrictions to match all valid rows. + final Parameters valid = disjoint.addSubParameters( "and" ); + // Restrictions to match all rows deleted at exactly given revision. + final Parameters removed = disjoint.addSubParameters( "and" ); // Excluding current revision, because we need to match data valid at the previous one. createValidDataRestrictions( auditStrategy, versionsMiddleEntityName, remQb, valid, false, componentData ); // ee.revision = :revision diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/query/QueryConstants.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/query/QueryConstants.java index bb01740dd4..086bfc2e1f 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/query/QueryConstants.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/query/QueryConstants.java @@ -1,20 +1,43 @@ +/* + * 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.internal.entities.mapper.relation.query; /** * Constants used in JPQL queries. - * + * * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public class QueryConstants { - public static final String REFERENCED_ENTITY_ALIAS = "e__"; - public static final String REFERENCED_ENTITY_ALIAS_DEF_AUD_STR = "e2__"; + public static final String REFERENCED_ENTITY_ALIAS = "e__"; + public static final String REFERENCED_ENTITY_ALIAS_DEF_AUD_STR = "e2__"; - public static final String INDEX_ENTITY_ALIAS = "f__"; - public static final String INDEX_ENTITY_ALIAS_DEF_AUD_STR = "f2__"; + public static final String INDEX_ENTITY_ALIAS = "f__"; + public static final String INDEX_ENTITY_ALIAS_DEF_AUD_STR = "f2__"; - public static final String MIDDLE_ENTITY_ALIAS = "ee__"; - public static final String MIDDLE_ENTITY_ALIAS_DEF_AUD_STR = "ee2__"; + public static final String MIDDLE_ENTITY_ALIAS = "ee__"; + public static final String MIDDLE_ENTITY_ALIAS_DEF_AUD_STR = "ee2__"; - public static final String REVISION_PARAMETER = "revision"; - public static final String DEL_REVISION_TYPE_PARAMETER = "delrevisiontype"; + public static final String REVISION_PARAMETER = "revision"; + public static final String DEL_REVISION_TYPE_PARAMETER = "delrevisiontype"; } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/query/RelationQueryGenerator.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/query/RelationQueryGenerator.java index c65e8c90f1..191595c8be 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/query/RelationQueryGenerator.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/query/RelationQueryGenerator.java @@ -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,17 +22,19 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.internal.entities.mapper.relation.query; + import org.hibernate.Query; import org.hibernate.envers.internal.reader.AuditReaderImplementor; /** * TODO: cleanup implementations and extract common code - * + *

* Implementations of this interface provide a method to generate queries on a relation table (a table used * for mapping relations). The query can select, apart from selecting the content of the relation table, also data of * other "related" entities. + * * @author Adam Warski (adam at warski dot org) */ public interface RelationQueryGenerator { - Query getQuery(AuditReaderImplementor versionsReader, Object primaryKey, Number revision, boolean removed); + Query getQuery(AuditReaderImplementor versionsReader, Object primaryKey, Number revision, boolean removed); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/query/ThreeEntityQueryGenerator.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/query/ThreeEntityQueryGenerator.java index c548031531..5d374b8f54 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/query/ThreeEntityQueryGenerator.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/query/ThreeEntityQueryGenerator.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 @@ -49,11 +49,12 @@ public final class ThreeEntityQueryGenerator extends AbstractRelationQueryGenera private final String queryString; private final String queryRemovedString; - public ThreeEntityQueryGenerator(GlobalConfiguration globalCfg, AuditEntitiesConfiguration verEntCfg, - AuditStrategy auditStrategy, String versionsMiddleEntityName, - MiddleIdData referencingIdData, MiddleIdData referencedIdData, - MiddleIdData indexIdData, boolean revisionTypeInId, - MiddleComponentData... componentData) { + public ThreeEntityQueryGenerator( + GlobalConfiguration globalCfg, AuditEntitiesConfiguration verEntCfg, + AuditStrategy auditStrategy, String versionsMiddleEntityName, + MiddleIdData referencingIdData, MiddleIdData referencedIdData, + MiddleIdData indexIdData, boolean revisionTypeInId, + MiddleComponentData... componentData) { super( verEntCfg, referencingIdData, revisionTypeInId ); /* @@ -102,7 +103,12 @@ public final class ThreeEntityQueryGenerator extends AbstractRelationQueryGenera * e.revision_type != DEL AND * f.revision_type != DEL */ - final QueryBuilder commonPart = commonQueryPart( referencedIdData, indexIdData, versionsMiddleEntityName, verEntCfg.getOriginalIdPropName() ); + final QueryBuilder commonPart = commonQueryPart( + referencedIdData, + indexIdData, + versionsMiddleEntityName, + verEntCfg.getOriginalIdPropName() + ); final QueryBuilder validQuery = commonPart.deepCopy(); final QueryBuilder removedQuery = commonPart.deepCopy(); createValidDataRestrictions( @@ -120,8 +126,9 @@ public final class ThreeEntityQueryGenerator extends AbstractRelationQueryGenera /** * Compute common part for both queries. */ - private QueryBuilder commonQueryPart(MiddleIdData referencedIdData, MiddleIdData indexIdData, - String versionsMiddleEntityName, String originalIdPropertyName) { + private QueryBuilder commonQueryPart( + MiddleIdData referencedIdData, MiddleIdData indexIdData, + String versionsMiddleEntityName, String originalIdPropertyName) { final String eeOriginalIdPropertyPath = MIDDLE_ENTITY_ALIAS + "." + originalIdPropertyName; // SELECT new list(ee) FROM middleEntity ee final QueryBuilder qb = new QueryBuilder( versionsMiddleEntityName, MIDDLE_ENTITY_ALIAS ); @@ -151,9 +158,10 @@ public final class ThreeEntityQueryGenerator extends AbstractRelationQueryGenera /** * Creates query restrictions used to retrieve only actual data. */ - private void createValidDataRestrictions(GlobalConfiguration globalCfg, AuditStrategy auditStrategy, - MiddleIdData referencedIdData, String versionsMiddleEntityName, QueryBuilder qb, - Parameters rootParameters, boolean inclusive, MiddleComponentData... componentData) { + private void createValidDataRestrictions( + GlobalConfiguration globalCfg, AuditStrategy auditStrategy, + MiddleIdData referencedIdData, String versionsMiddleEntityName, QueryBuilder qb, + Parameters rootParameters, boolean inclusive, MiddleComponentData... componentData) { final String revisionPropertyPath = verEntCfg.getRevisionNumberPath(); final String originalIdPropertyName = verEntCfg.getOriginalIdPropName(); final String eeOriginalIdPropertyPath = MIDDLE_ENTITY_ALIAS + "." + originalIdPropertyName; @@ -161,16 +169,34 @@ public final class ThreeEntityQueryGenerator extends AbstractRelationQueryGenera // (selecting e entities at revision :revision) // --> based on auditStrategy (see above) auditStrategy.addEntityAtRevisionRestriction( - globalCfg, qb, rootParameters, REFERENCED_ENTITY_ALIAS + "." + revisionPropertyPath, - REFERENCED_ENTITY_ALIAS + "." + verEntCfg.getRevisionEndFieldName(), false, referencedIdData, revisionPropertyPath, - originalIdPropertyName, REFERENCED_ENTITY_ALIAS, REFERENCED_ENTITY_ALIAS_DEF_AUD_STR, inclusive + globalCfg, + qb, + rootParameters, + REFERENCED_ENTITY_ALIAS + "." + revisionPropertyPath, + REFERENCED_ENTITY_ALIAS + "." + verEntCfg.getRevisionEndFieldName(), + false, + referencedIdData, + revisionPropertyPath, + originalIdPropertyName, + REFERENCED_ENTITY_ALIAS, + REFERENCED_ENTITY_ALIAS_DEF_AUD_STR, + inclusive ); // (selecting f entities at revision :revision) // --> based on auditStrategy (see above) auditStrategy.addEntityAtRevisionRestriction( - globalCfg, qb, rootParameters, REFERENCED_ENTITY_ALIAS + "." + revisionPropertyPath, - REFERENCED_ENTITY_ALIAS + "." + verEntCfg.getRevisionEndFieldName(), false, referencedIdData, revisionPropertyPath, - originalIdPropertyName, INDEX_ENTITY_ALIAS, INDEX_ENTITY_ALIAS_DEF_AUD_STR, inclusive + globalCfg, + qb, + rootParameters, + REFERENCED_ENTITY_ALIAS + "." + revisionPropertyPath, + REFERENCED_ENTITY_ALIAS + "." + verEntCfg.getRevisionEndFieldName(), + false, + referencedIdData, + revisionPropertyPath, + originalIdPropertyName, + INDEX_ENTITY_ALIAS, + INDEX_ENTITY_ALIAS_DEF_AUD_STR, + inclusive ); // (with ee association at revision :revision) // --> based on auditStrategy (see above) @@ -182,20 +208,33 @@ public final class ThreeEntityQueryGenerator extends AbstractRelationQueryGenera // ee.revision_type != DEL rootParameters.addWhereWithNamedParam( revisionTypePropName, "!=", DEL_REVISION_TYPE_PARAMETER ); // e.revision_type != DEL - rootParameters.addWhereWithNamedParam( REFERENCED_ENTITY_ALIAS + "." + revisionTypePropName, false, "!=", DEL_REVISION_TYPE_PARAMETER ); + rootParameters.addWhereWithNamedParam( + REFERENCED_ENTITY_ALIAS + "." + revisionTypePropName, + false, + "!=", + DEL_REVISION_TYPE_PARAMETER + ); // f.revision_type != DEL - rootParameters.addWhereWithNamedParam( INDEX_ENTITY_ALIAS + "." + revisionTypePropName, false, "!=", DEL_REVISION_TYPE_PARAMETER ); + rootParameters.addWhereWithNamedParam( + INDEX_ENTITY_ALIAS + "." + revisionTypePropName, + false, + "!=", + DEL_REVISION_TYPE_PARAMETER + ); } /** * Create query restrictions used to retrieve actual data and deletions that took place at exactly given revision. */ - private void createValidAndRemovedDataRestrictions(GlobalConfiguration globalCfg, AuditStrategy auditStrategy, - MiddleIdData referencedIdData, String versionsMiddleEntityName, - QueryBuilder remQb, MiddleComponentData... componentData) { + private void createValidAndRemovedDataRestrictions( + GlobalConfiguration globalCfg, AuditStrategy auditStrategy, + MiddleIdData referencedIdData, String versionsMiddleEntityName, + QueryBuilder remQb, MiddleComponentData... componentData) { final Parameters disjoint = remQb.getRootParameters().addSubParameters( "or" ); - final Parameters valid = disjoint.addSubParameters( "and" ); // Restrictions to match all valid rows. - final Parameters removed = disjoint.addSubParameters( "and" ); // Restrictions to match all rows deleted at exactly given revision. + // Restrictions to match all valid rows. + final Parameters valid = disjoint.addSubParameters( "and" ); + // Restrictions to match all rows deleted at exactly given revision. + final Parameters removed = disjoint.addSubParameters( "and" ); final String revisionPropertyPath = verEntCfg.getRevisionNumberPath(); final String revisionTypePropName = getRevisionTypePath(); // Excluding current revision, because we need to match data valid at the previous one. @@ -205,15 +244,35 @@ public final class ThreeEntityQueryGenerator extends AbstractRelationQueryGenera // ee.revision = :revision removed.addWhereWithNamedParam( revisionPropertyPath, "=", REVISION_PARAMETER ); // e.revision = :revision - removed.addWhereWithNamedParam( REFERENCED_ENTITY_ALIAS + "." + revisionPropertyPath, false, "=", REVISION_PARAMETER ); + removed.addWhereWithNamedParam( + REFERENCED_ENTITY_ALIAS + "." + revisionPropertyPath, + false, + "=", + REVISION_PARAMETER + ); // f.revision = :revision - removed.addWhereWithNamedParam( INDEX_ENTITY_ALIAS + "." + revisionPropertyPath, false, "=", REVISION_PARAMETER ); + removed.addWhereWithNamedParam( + INDEX_ENTITY_ALIAS + "." + revisionPropertyPath, + false, + "=", + REVISION_PARAMETER + ); // ee.revision_type = DEL removed.addWhereWithNamedParam( revisionTypePropName, "=", DEL_REVISION_TYPE_PARAMETER ); // e.revision_type = DEL - removed.addWhereWithNamedParam( REFERENCED_ENTITY_ALIAS + "." + revisionTypePropName, false, "=", DEL_REVISION_TYPE_PARAMETER ); + removed.addWhereWithNamedParam( + REFERENCED_ENTITY_ALIAS + "." + revisionTypePropName, + false, + "=", + DEL_REVISION_TYPE_PARAMETER + ); // f.revision_type = DEL - removed.addWhereWithNamedParam( INDEX_ENTITY_ALIAS + "." + revisionTypePropName, false, "=", DEL_REVISION_TYPE_PARAMETER ); + removed.addWhereWithNamedParam( + INDEX_ENTITY_ALIAS + "." + revisionTypePropName, + false, + "=", + DEL_REVISION_TYPE_PARAMETER + ); } @Override diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/query/TwoEntityOneAuditedQueryGenerator.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/query/TwoEntityOneAuditedQueryGenerator.java index 23c26e92c5..065239c0cd 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/query/TwoEntityOneAuditedQueryGenerator.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/query/TwoEntityOneAuditedQueryGenerator.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 @@ -45,10 +45,11 @@ public final class TwoEntityOneAuditedQueryGenerator extends AbstractRelationQue private final String queryString; private final String queryRemovedString; - public TwoEntityOneAuditedQueryGenerator(AuditEntitiesConfiguration verEntCfg, AuditStrategy auditStrategy, - String versionsMiddleEntityName, MiddleIdData referencingIdData, - MiddleIdData referencedIdData, boolean revisionTypeInId, - MiddleComponentData... componentData) { + public TwoEntityOneAuditedQueryGenerator( + AuditEntitiesConfiguration verEntCfg, AuditStrategy auditStrategy, + String versionsMiddleEntityName, MiddleIdData referencingIdData, + MiddleIdData referencedIdData, boolean revisionTypeInId, + MiddleComponentData... componentData) { super( verEntCfg, referencingIdData, revisionTypeInId ); /* @@ -73,7 +74,11 @@ public final class TwoEntityOneAuditedQueryGenerator extends AbstractRelationQue * (only non-deleted entities and associations) * ee.revision_type != DEL */ - final QueryBuilder commonPart = commonQueryPart( referencedIdData, versionsMiddleEntityName, verEntCfg.getOriginalIdPropName() ); + final QueryBuilder commonPart = commonQueryPart( + referencedIdData, + versionsMiddleEntityName, + verEntCfg.getOriginalIdPropName() + ); final QueryBuilder validQuery = commonPart.deepCopy(); final QueryBuilder removedQuery = commonPart.deepCopy(); createValidDataRestrictions( @@ -88,8 +93,9 @@ public final class TwoEntityOneAuditedQueryGenerator extends AbstractRelationQue /** * Compute common part for both queries. */ - private QueryBuilder commonQueryPart(MiddleIdData referencedIdData, String versionsMiddleEntityName, - String originalIdPropertyName) { + private QueryBuilder commonQueryPart( + MiddleIdData referencedIdData, String versionsMiddleEntityName, + String originalIdPropertyName) { final String eeOriginalIdPropertyPath = MIDDLE_ENTITY_ALIAS + "." + originalIdPropertyName; // SELECT new list(ee) FROM middleEntity ee final QueryBuilder qb = new QueryBuilder( versionsMiddleEntityName, MIDDLE_ENTITY_ALIAS ); @@ -109,8 +115,9 @@ public final class TwoEntityOneAuditedQueryGenerator extends AbstractRelationQue /** * Creates query restrictions used to retrieve only actual data. */ - private void createValidDataRestrictions(AuditStrategy auditStrategy, String versionsMiddleEntityName, QueryBuilder qb, - Parameters rootParameters, MiddleComponentData... componentData) { + private void createValidDataRestrictions( + AuditStrategy auditStrategy, String versionsMiddleEntityName, QueryBuilder qb, + Parameters rootParameters, MiddleComponentData... componentData) { final String revisionPropertyPath = verEntCfg.getRevisionNumberPath(); final String originalIdPropertyName = verEntCfg.getOriginalIdPropName(); final String eeOriginalIdPropertyPath = MIDDLE_ENTITY_ALIAS + "." + originalIdPropertyName; @@ -128,11 +135,14 @@ public final class TwoEntityOneAuditedQueryGenerator extends AbstractRelationQue /** * Create query restrictions used to retrieve actual data and deletions that took place at exactly given revision. */ - private void createValidAndRemovedDataRestrictions(AuditStrategy auditStrategy, String versionsMiddleEntityName, - QueryBuilder remQb, MiddleComponentData... componentData) { + private void createValidAndRemovedDataRestrictions( + AuditStrategy auditStrategy, String versionsMiddleEntityName, + QueryBuilder remQb, MiddleComponentData... componentData) { final Parameters disjoint = remQb.getRootParameters().addSubParameters( "or" ); - final Parameters valid = disjoint.addSubParameters( "and" ); // Restrictions to match all valid rows. - final Parameters removed = disjoint.addSubParameters( "and" ); // Restrictions to match all rows deleted at exactly given revision. + // Restrictions to match all valid rows. + final Parameters valid = disjoint.addSubParameters( "and" ); + // Restrictions to match all rows deleted at exactly given revision. + final Parameters removed = disjoint.addSubParameters( "and" ); createValidDataRestrictions( auditStrategy, versionsMiddleEntityName, remQb, valid, componentData ); // ee.revision = :revision removed.addWhereWithNamedParam( verEntCfg.getRevisionNumberPath(), "=", REVISION_PARAMETER ); diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/query/TwoEntityQueryGenerator.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/query/TwoEntityQueryGenerator.java index 2fc6cbec2b..21ea05cb48 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/query/TwoEntityQueryGenerator.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/query/TwoEntityQueryGenerator.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 @@ -47,10 +47,11 @@ public final class TwoEntityQueryGenerator extends AbstractRelationQueryGenerato private final String queryString; private final String queryRemovedString; - public TwoEntityQueryGenerator(GlobalConfiguration globalCfg, AuditEntitiesConfiguration verEntCfg, - AuditStrategy auditStrategy, String versionsMiddleEntityName, - MiddleIdData referencingIdData, MiddleIdData referencedIdData, - boolean revisionTypeInId, MiddleComponentData... componentData) { + public TwoEntityQueryGenerator( + GlobalConfiguration globalCfg, AuditEntitiesConfiguration verEntCfg, + AuditStrategy auditStrategy, String versionsMiddleEntityName, + MiddleIdData referencingIdData, MiddleIdData referencedIdData, + boolean revisionTypeInId, MiddleComponentData... componentData) { super( verEntCfg, referencingIdData, revisionTypeInId ); /* @@ -84,7 +85,11 @@ public final class TwoEntityQueryGenerator extends AbstractRelationQueryGenerato * ee.revision_type != DEL AND * e.revision_type != DEL */ - final QueryBuilder commonPart = commonQueryPart( referencedIdData, versionsMiddleEntityName, verEntCfg.getOriginalIdPropName() ); + final QueryBuilder commonPart = commonQueryPart( + referencedIdData, + versionsMiddleEntityName, + verEntCfg.getOriginalIdPropName() + ); final QueryBuilder validQuery = commonPart.deepCopy(); final QueryBuilder removedQuery = commonPart.deepCopy(); createValidDataRestrictions( @@ -102,8 +107,9 @@ public final class TwoEntityQueryGenerator extends AbstractRelationQueryGenerato /** * Compute common part for both queries. */ - private QueryBuilder commonQueryPart(MiddleIdData referencedIdData, String versionsMiddleEntityName, - String originalIdPropertyName) { + private QueryBuilder commonQueryPart( + MiddleIdData referencedIdData, String versionsMiddleEntityName, + String originalIdPropertyName) { final String eeOriginalIdPropertyPath = MIDDLE_ENTITY_ALIAS + "." + originalIdPropertyName; // SELECT new list(ee) FROM middleEntity ee QueryBuilder qb = new QueryBuilder( versionsMiddleEntityName, MIDDLE_ENTITY_ALIAS ); @@ -124,9 +130,10 @@ public final class TwoEntityQueryGenerator extends AbstractRelationQueryGenerato /** * Creates query restrictions used to retrieve only actual data. */ - private void createValidDataRestrictions(GlobalConfiguration globalCfg, AuditStrategy auditStrategy, MiddleIdData referencedIdData, - String versionsMiddleEntityName, QueryBuilder qb, Parameters rootParameters, - boolean inclusive, MiddleComponentData... componentData) { + private void createValidDataRestrictions( + GlobalConfiguration globalCfg, AuditStrategy auditStrategy, MiddleIdData referencedIdData, + String versionsMiddleEntityName, QueryBuilder qb, Parameters rootParameters, + boolean inclusive, MiddleComponentData... componentData) { final String revisionPropertyPath = verEntCfg.getRevisionNumberPath(); final String originalIdPropertyName = verEntCfg.getOriginalIdPropName(); final String eeOriginalIdPropertyPath = MIDDLE_ENTITY_ALIAS + "." + originalIdPropertyName; @@ -134,13 +141,23 @@ public final class TwoEntityQueryGenerator extends AbstractRelationQueryGenerato // (selecting e entities at revision :revision) // --> based on auditStrategy (see above) auditStrategy.addEntityAtRevisionRestriction( - globalCfg, qb, rootParameters, REFERENCED_ENTITY_ALIAS + "." + revisionPropertyPath, - REFERENCED_ENTITY_ALIAS + "." + verEntCfg.getRevisionEndFieldName(), false, referencedIdData, revisionPropertyPath, - originalIdPropertyName, REFERENCED_ENTITY_ALIAS, REFERENCED_ENTITY_ALIAS_DEF_AUD_STR, inclusive + globalCfg, + qb, + rootParameters, + REFERENCED_ENTITY_ALIAS + "." + revisionPropertyPath, + REFERENCED_ENTITY_ALIAS + "." + verEntCfg.getRevisionEndFieldName(), + false, + referencedIdData, + revisionPropertyPath, + originalIdPropertyName, + REFERENCED_ENTITY_ALIAS, + REFERENCED_ENTITY_ALIAS_DEF_AUD_STR, + inclusive ); // (with ee association at revision :revision) // --> based on auditStrategy (see above) - auditStrategy.addAssociationAtRevisionRestriction( qb, rootParameters, revisionPropertyPath, + auditStrategy.addAssociationAtRevisionRestriction( + qb, rootParameters, revisionPropertyPath, verEntCfg.getRevisionEndFieldName(), true, referencingIdData, versionsMiddleEntityName, eeOriginalIdPropertyPath, revisionPropertyPath, originalIdPropertyName, MIDDLE_ENTITY_ALIAS, inclusive, componentData @@ -148,30 +165,57 @@ public final class TwoEntityQueryGenerator extends AbstractRelationQueryGenerato // ee.revision_type != DEL rootParameters.addWhereWithNamedParam( revisionTypePropName, "!=", DEL_REVISION_TYPE_PARAMETER ); // e.revision_type != DEL - rootParameters.addWhereWithNamedParam( REFERENCED_ENTITY_ALIAS + "." + revisionTypePropName, false, "!=", DEL_REVISION_TYPE_PARAMETER ); + rootParameters.addWhereWithNamedParam( + REFERENCED_ENTITY_ALIAS + "." + revisionTypePropName, + false, + "!=", + DEL_REVISION_TYPE_PARAMETER + ); } /** * Create query restrictions used to retrieve actual data and deletions that took place at exactly given revision. */ - private void createValidAndRemovedDataRestrictions(GlobalConfiguration globalCfg, AuditStrategy auditStrategy, - MiddleIdData referencedIdData, String versionsMiddleEntityName, - QueryBuilder remQb, MiddleComponentData... componentData) { + private void createValidAndRemovedDataRestrictions( + GlobalConfiguration globalCfg, AuditStrategy auditStrategy, + MiddleIdData referencedIdData, String versionsMiddleEntityName, + QueryBuilder remQb, MiddleComponentData... componentData) { final Parameters disjoint = remQb.getRootParameters().addSubParameters( "or" ); - final Parameters valid = disjoint.addSubParameters( "and" ); // Restrictions to match all valid rows. - final Parameters removed = disjoint.addSubParameters( "and" ); // Restrictions to match all rows deleted at exactly given revision. + // Restrictions to match all valid rows. + final Parameters valid = disjoint.addSubParameters( "and" ); + // Restrictions to match all rows deleted at exactly given revision. + final Parameters removed = disjoint.addSubParameters( "and" ); final String revisionPropertyPath = verEntCfg.getRevisionNumberPath(); final String revisionTypePropName = getRevisionTypePath(); // Excluding current revision, because we need to match data valid at the previous one. - createValidDataRestrictions( globalCfg, auditStrategy, referencedIdData, versionsMiddleEntityName, remQb, valid, false, componentData ); + createValidDataRestrictions( + globalCfg, + auditStrategy, + referencedIdData, + versionsMiddleEntityName, + remQb, + valid, + false, + componentData + ); // ee.revision = :revision removed.addWhereWithNamedParam( revisionPropertyPath, "=", REVISION_PARAMETER ); // e.revision = :revision - removed.addWhereWithNamedParam( REFERENCED_ENTITY_ALIAS + "." + revisionPropertyPath, false, "=", REVISION_PARAMETER ); + removed.addWhereWithNamedParam( + REFERENCED_ENTITY_ALIAS + "." + revisionPropertyPath, + false, + "=", + REVISION_PARAMETER + ); // ee.revision_type = DEL removed.addWhereWithNamedParam( revisionTypePropName, "=", DEL_REVISION_TYPE_PARAMETER ); // e.revision_type = DEL - removed.addWhereWithNamedParam( REFERENCED_ENTITY_ALIAS + "." + revisionTypePropName, false, "=", DEL_REVISION_TYPE_PARAMETER ); + removed.addWhereWithNamedParam( + REFERENCED_ENTITY_ALIAS + "." + revisionTypePropName, + false, + "=", + DEL_REVISION_TYPE_PARAMETER + ); } @Override diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/reader/AuditReaderImpl.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/reader/AuditReaderImpl.java index 7a64945109..5ae1cc4e4f 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/reader/AuditReaderImpl.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/reader/AuditReaderImpl.java @@ -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 @@ -23,13 +23,13 @@ */ package org.hibernate.envers.internal.reader; +import javax.persistence.NoResultException; import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; -import javax.persistence.NoResultException; import org.hibernate.Criteria; import org.hibernate.HibernateException; @@ -57,260 +57,292 @@ import static org.hibernate.envers.internal.tools.EntityTools.getTargetClassIfPr * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public class AuditReaderImpl implements AuditReaderImplementor { - private final AuditConfiguration verCfg; - private final SessionImplementor sessionImplementor; - private final Session session; - private final FirstLevelCache firstLevelCache; - private final CrossTypeRevisionChangesReader crossTypeRevisionChangesReader; + private final AuditConfiguration verCfg; + private final SessionImplementor sessionImplementor; + private final Session session; + private final FirstLevelCache firstLevelCache; + private final CrossTypeRevisionChangesReader crossTypeRevisionChangesReader; - public AuditReaderImpl(AuditConfiguration verCfg, Session session, - SessionImplementor sessionImplementor) { - this.verCfg = verCfg; - this.sessionImplementor = sessionImplementor; - this.session = session; + public AuditReaderImpl( + AuditConfiguration verCfg, Session session, + SessionImplementor sessionImplementor) { + this.verCfg = verCfg; + this.sessionImplementor = sessionImplementor; + this.session = session; - firstLevelCache = new FirstLevelCache(); - crossTypeRevisionChangesReader = new CrossTypeRevisionChangesReaderImpl(this, verCfg); - } + firstLevelCache = new FirstLevelCache(); + crossTypeRevisionChangesReader = new CrossTypeRevisionChangesReaderImpl( this, verCfg ); + } - private void checkSession() { - if (!session.isOpen()) { - throw new IllegalStateException("The associated entity manager is closed!"); - } - } - - public SessionImplementor getSessionImplementor() { - return sessionImplementor; - } - - public Session getSession() { - return session; - } - - public FirstLevelCache getFirstLevelCache() { - return firstLevelCache; - } - - public T find(Class cls, Object primaryKey, Number revision) throws - IllegalArgumentException, NotAuditedException, IllegalStateException { - cls = getTargetClassIfProxied(cls); - return this.find(cls, cls.getName(), primaryKey, revision); - } - - public T find(Class cls, String entityName, Object primaryKey, Number revision) - throws IllegalArgumentException, NotAuditedException, IllegalStateException { - return this.find(cls, entityName, primaryKey, revision, false); - } - - @SuppressWarnings({"unchecked"}) - public T find(Class cls, String entityName, Object primaryKey, Number revision, - boolean includeDeletions) throws - IllegalArgumentException, NotAuditedException, IllegalStateException { - cls = getTargetClassIfProxied(cls); - checkNotNull(cls, "Entity class"); - checkNotNull(entityName, "Entity name"); - checkNotNull(primaryKey, "Primary key"); - checkNotNull(revision, "Entity revision"); - checkPositive(revision, "Entity revision"); - checkSession(); - - if (!verCfg.getEntCfg().isVersioned(entityName)) { - throw new NotAuditedException(entityName, entityName + " is not versioned!"); - } - - if (firstLevelCache.contains(entityName, revision, primaryKey)) { - return (T) firstLevelCache.get(entityName, revision, primaryKey); - } - - Object result; - try { - // The result is put into the cache by the entity instantiator called from the query - result = createQuery().forEntitiesAtRevision(cls, entityName, revision, includeDeletions) - .add(AuditEntity.id().eq(primaryKey)).getSingleResult(); - } catch (NoResultException e) { - result = null; - } catch (NonUniqueResultException e) { - throw new AuditException(e); - } - - return (T) result; - } - - public List getRevisions(Class cls, Object primaryKey) - throws IllegalArgumentException, NotAuditedException, IllegalStateException { - cls = getTargetClassIfProxied(cls); - return this.getRevisions(cls, cls.getName(), primaryKey); - } - - @SuppressWarnings({"unchecked"}) - public List getRevisions(Class cls, String entityName, Object primaryKey) - throws IllegalArgumentException, NotAuditedException, IllegalStateException { - // todo: if a class is not versioned from the beginning, there's a missing ADD rev - what then? - cls = getTargetClassIfProxied(cls); - checkNotNull(cls, "Entity class"); - checkNotNull(entityName, "Entity name"); - checkNotNull(primaryKey, "Primary key"); - checkSession(); - - if (!verCfg.getEntCfg().isVersioned(entityName)) { - throw new NotAuditedException(entityName, entityName + " is not versioned!"); - } - - return createQuery().forRevisionsOfEntity(cls, entityName, false, true) - .addProjection(AuditEntity.revisionNumber()) - .addOrder(AuditEntity.revisionNumber().asc()) - .add(AuditEntity.id().eq(primaryKey)) - .getResultList(); - } - - public Date getRevisionDate(Number revision) throws IllegalArgumentException, RevisionDoesNotExistException, - IllegalStateException{ - checkNotNull(revision, "Entity revision"); - checkPositive(revision, "Entity revision"); - checkSession(); - - Criteria query = verCfg.getRevisionInfoQueryCreator().getRevisionDateQuery(session, revision); - - try { - Object timestampObject = query.uniqueResult(); - if (timestampObject == null) { - throw new RevisionDoesNotExistException(revision); - } - - // The timestamp object is either a date or a long - return timestampObject instanceof Date ? (Date) timestampObject : new Date((Long) timestampObject); - } catch (NonUniqueResultException e) { - throw new AuditException(e); - } - } - - public Number getRevisionNumberForDate(Date date) { - checkNotNull(date, "Date of revision"); - checkSession(); - - Criteria query = verCfg.getRevisionInfoQueryCreator().getRevisionNumberForDateQuery(session, date); - - try { - Number res = (Number) query.uniqueResult(); - if (res == null) { - throw new RevisionDoesNotExistException(date); - } - - return res; - } catch (NonUniqueResultException e) { - throw new AuditException(e); - } - } - - @SuppressWarnings({"unchecked"}) - public T findRevision(Class revisionEntityClass, Number revision) throws IllegalArgumentException, - RevisionDoesNotExistException, IllegalStateException { - revisionEntityClass = getTargetClassIfProxied(revisionEntityClass); - checkNotNull(revision, "Entity revision"); - checkPositive(revision, "Entity revision"); - checkSession(); - - Set revisions = new HashSet(1); - revisions.add(revision); - Criteria query = verCfg.getRevisionInfoQueryCreator().getRevisionsQuery(session, revisions); - - try { - T revisionData = (T) query.uniqueResult(); - - if (revisionData == null) { - throw new RevisionDoesNotExistException(revision); - } - - return revisionData; - } catch (NonUniqueResultException e) { - throw new AuditException(e); - } - } - - @SuppressWarnings({"unchecked"}) - public Map findRevisions(Class revisionEntityClass, Set revisions) throws IllegalArgumentException, - IllegalStateException { - revisionEntityClass = getTargetClassIfProxied(revisionEntityClass); - Map result = new HashMap(revisions.size()); - - for (Number revision : revisions) { - checkNotNull(revision, "Entity revision"); - checkPositive(revision, "Entity revision"); + private void checkSession() { + if ( !session.isOpen() ) { + throw new IllegalStateException( "The associated entity manager is closed!" ); } - checkSession(); + } - Criteria query = verCfg.getRevisionInfoQueryCreator().getRevisionsQuery(session, revisions); + @Override + public SessionImplementor getSessionImplementor() { + return sessionImplementor; + } - try { - List revisionList = query.list(); - for (T revision : revisionList) { - Number revNo = verCfg.getRevisionInfoNumberReader().getRevisionNumber(revision); - result.put(revNo, revision); + @Override + public Session getSession() { + return session; + } + + @Override + public FirstLevelCache getFirstLevelCache() { + return firstLevelCache; + } + + @Override + public T find(Class cls, Object primaryKey, Number revision) throws + IllegalArgumentException, NotAuditedException, IllegalStateException { + cls = getTargetClassIfProxied( cls ); + return this.find( cls, cls.getName(), primaryKey, revision ); + } + + @Override + public T find(Class cls, String entityName, Object primaryKey, Number revision) + throws IllegalArgumentException, NotAuditedException, IllegalStateException { + return this.find( cls, entityName, primaryKey, revision, false ); + } + + @Override + @SuppressWarnings({"unchecked"}) + public T find( + Class cls, + String entityName, + Object primaryKey, + Number revision, + boolean includeDeletions) throws IllegalArgumentException, NotAuditedException, IllegalStateException { + cls = getTargetClassIfProxied( cls ); + checkNotNull( cls, "Entity class" ); + checkNotNull( entityName, "Entity name" ); + checkNotNull( primaryKey, "Primary key" ); + checkNotNull( revision, "Entity revision" ); + checkPositive( revision, "Entity revision" ); + checkSession(); + + if ( !verCfg.getEntCfg().isVersioned( entityName ) ) { + throw new NotAuditedException( entityName, entityName + " is not versioned!" ); + } + + if ( firstLevelCache.contains( entityName, revision, primaryKey ) ) { + return (T) firstLevelCache.get( entityName, revision, primaryKey ); + } + + Object result; + try { + // The result is put into the cache by the entity instantiator called from the query + result = createQuery().forEntitiesAtRevision( cls, entityName, revision, includeDeletions ) + .add( AuditEntity.id().eq( primaryKey ) ).getSingleResult(); + } + catch (NoResultException e) { + result = null; + } + catch (NonUniqueResultException e) { + throw new AuditException( e ); + } + + return (T) result; + } + + @Override + public List getRevisions(Class cls, Object primaryKey) + throws IllegalArgumentException, NotAuditedException, IllegalStateException { + cls = getTargetClassIfProxied( cls ); + return this.getRevisions( cls, cls.getName(), primaryKey ); + } + + @Override + @SuppressWarnings({"unchecked"}) + public List getRevisions(Class cls, String entityName, Object primaryKey) + throws IllegalArgumentException, NotAuditedException, IllegalStateException { + // todo: if a class is not versioned from the beginning, there's a missing ADD rev - what then? + cls = getTargetClassIfProxied( cls ); + checkNotNull( cls, "Entity class" ); + checkNotNull( entityName, "Entity name" ); + checkNotNull( primaryKey, "Primary key" ); + checkSession(); + + if ( !verCfg.getEntCfg().isVersioned( entityName ) ) { + throw new NotAuditedException( entityName, entityName + " is not versioned!" ); + } + + return createQuery().forRevisionsOfEntity( cls, entityName, false, true ) + .addProjection( AuditEntity.revisionNumber() ) + .addOrder( AuditEntity.revisionNumber().asc() ) + .add( AuditEntity.id().eq( primaryKey ) ) + .getResultList(); + } + + @Override + public Date getRevisionDate(Number revision) + throws IllegalArgumentException, RevisionDoesNotExistException, IllegalStateException { + checkNotNull( revision, "Entity revision" ); + checkPositive( revision, "Entity revision" ); + checkSession(); + + final Criteria query = verCfg.getRevisionInfoQueryCreator().getRevisionDateQuery( session, revision ); + + try { + final Object timestampObject = query.uniqueResult(); + if ( timestampObject == null ) { + throw new RevisionDoesNotExistException( revision ); } - return result; - } catch (HibernateException e) { - throw new AuditException(e); - } - } + // The timestamp object is either a date or a long + return timestampObject instanceof Date ? (Date) timestampObject : new Date( (Long) timestampObject ); + } + catch (NonUniqueResultException e) { + throw new AuditException( e ); + } + } - public CrossTypeRevisionChangesReader getCrossTypeRevisionChangesReader() throws AuditException { - if (!verCfg.getGlobalCfg().isTrackEntitiesChangedInRevision()) { - throw new AuditException("This API is designed for Envers default mechanism of tracking entities modified in a given revision." - + " Extend DefaultTrackingModifiedEntitiesRevisionEntity, utilize @ModifiedEntityNames annotation or set " - + "'org.hibernate.envers.track_entities_changed_in_revision' parameter to true."); - } - return crossTypeRevisionChangesReader; - } + @Override + public Number getRevisionNumberForDate(Date date) { + checkNotNull( date, "Date of revision" ); + checkSession(); + final Criteria query = verCfg.getRevisionInfoQueryCreator().getRevisionNumberForDateQuery( session, date ); + + try { + final Number res = (Number) query.uniqueResult(); + if ( res == null ) { + throw new RevisionDoesNotExistException( date ); + } + + return res; + } + catch (NonUniqueResultException e) { + throw new AuditException( e ); + } + } + + @Override + @SuppressWarnings({"unchecked"}) + public T findRevision(Class revisionEntityClass, Number revision) + throws IllegalArgumentException, RevisionDoesNotExistException, IllegalStateException { + revisionEntityClass = getTargetClassIfProxied( revisionEntityClass ); + checkNotNull( revision, "Entity revision" ); + checkPositive( revision, "Entity revision" ); + checkSession(); + + final Set revisions = new HashSet( 1 ); + revisions.add( revision ); + final Criteria query = verCfg.getRevisionInfoQueryCreator().getRevisionsQuery( session, revisions ); + + try { + final T revisionData = (T) query.uniqueResult(); + + if ( revisionData == null ) { + throw new RevisionDoesNotExistException( revision ); + } + + return revisionData; + } + catch (NonUniqueResultException e) { + throw new AuditException( e ); + } + } + + @Override + @SuppressWarnings({"unchecked"}) + public Map findRevisions(Class revisionEntityClass, Set revisions) + throws IllegalArgumentException, + IllegalStateException { + revisionEntityClass = getTargetClassIfProxied( revisionEntityClass ); + final Map result = new HashMap( revisions.size() ); + + for ( Number revision : revisions ) { + checkNotNull( revision, "Entity revision" ); + checkPositive( revision, "Entity revision" ); + } + checkSession(); + + final Criteria query = verCfg.getRevisionInfoQueryCreator().getRevisionsQuery( session, revisions ); + + try { + final List revisionList = query.list(); + for ( T revision : revisionList ) { + final Number revNo = verCfg.getRevisionInfoNumberReader().getRevisionNumber( revision ); + result.put( revNo, revision ); + } + + return result; + } + catch (HibernateException e) { + throw new AuditException( e ); + } + } + + @Override + public CrossTypeRevisionChangesReader getCrossTypeRevisionChangesReader() throws AuditException { + if ( !verCfg.getGlobalCfg().isTrackEntitiesChangedInRevision() ) { + throw new AuditException( + "This API is designed for Envers default mechanism of tracking entities modified in a given revision." + + " Extend DefaultTrackingModifiedEntitiesRevisionEntity, utilize @ModifiedEntityNames annotation or set " + + "'org.hibernate.envers.track_entities_changed_in_revision' parameter to true." + ); + } + return crossTypeRevisionChangesReader; + } + + @Override @SuppressWarnings({"unchecked"}) public T getCurrentRevision(Class revisionEntityClass, boolean persist) { - revisionEntityClass = getTargetClassIfProxied(revisionEntityClass); - if (!(session instanceof EventSource)) { - throw new IllegalArgumentException("The provided session is not an EventSource!"); + revisionEntityClass = getTargetClassIfProxied( revisionEntityClass ); + if ( !(session instanceof EventSource) ) { + throw new IllegalArgumentException( "The provided session is not an EventSource!" ); } // Obtaining the current audit sync - AuditProcess auditProcess = verCfg.getSyncManager().get((EventSource) session); + final AuditProcess auditProcess = verCfg.getSyncManager().get( (EventSource) session ); // And getting the current revision data - return (T) auditProcess.getCurrentRevisionData(session, persist); + return (T) auditProcess.getCurrentRevisionData( session, persist ); } + @Override public AuditQueryCreator createQuery() { - return new AuditQueryCreator(verCfg, this); - } - - public boolean isEntityClassAudited(Class entityClass) { - entityClass = getTargetClassIfProxied(entityClass); - return this.isEntityNameAudited(entityClass.getName()); - } + return new AuditQueryCreator( verCfg, this ); + } + + @Override + public boolean isEntityClassAudited(Class entityClass) { + entityClass = getTargetClassIfProxied( entityClass ); + return this.isEntityNameAudited( entityClass.getName() ); + } + @Override public boolean isEntityNameAudited(String entityName) { - checkNotNull(entityName, "Entity name"); - checkSession(); - return (verCfg.getEntCfg().isVersioned(entityName)); - } + checkNotNull( entityName, "Entity name" ); + checkSession(); + return (verCfg.getEntCfg().isVersioned( entityName )); + } - - public String getEntityName(Object primaryKey, Number revision ,Object entity) throws HibernateException{ - checkNotNull(primaryKey, "Primary key"); - checkNotNull(revision, "Entity revision"); - checkPositive(revision, "Entity revision"); - checkNotNull(entity, "Entity"); - checkSession(); + @Override + public String getEntityName(Object primaryKey, Number revision, Object entity) throws HibernateException { + checkNotNull( primaryKey, "Primary key" ); + checkNotNull( revision, "Entity revision" ); + checkPositive( revision, "Entity revision" ); + checkNotNull( entity, "Entity" ); + checkSession(); // Unwrap if necessary - if(entity instanceof HibernateProxy) { - entity = ((HibernateProxy)entity).getHibernateLazyInitializer().getImplementation(); + if ( entity instanceof HibernateProxy ) { + entity = ((HibernateProxy) entity).getHibernateLazyInitializer().getImplementation(); } - if(firstLevelCache.containsEntityName(primaryKey, revision, entity)) { + if ( firstLevelCache.containsEntityName( primaryKey, revision, entity ) ) { // it's on envers FLC! - return firstLevelCache.getFromEntityNameCache(primaryKey, revision, entity); - } else { + return firstLevelCache.getFromEntityNameCache( primaryKey, revision, entity ); + } + else { throw new HibernateException( - "Envers can't resolve entityName for historic entity. The id, revision and entity is not on envers first level cache."); - } -} + "Envers can't resolve entityName for historic entity. The id, revision and entity is not on envers first level cache." + ); + } + } } \ No newline at end of file diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/reader/AuditReaderImplementor.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/reader/AuditReaderImplementor.java index bacd9dd813..ce98112daf 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/reader/AuditReaderImplementor.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/reader/AuditReaderImplementor.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,16 +22,20 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.internal.reader; + import org.hibernate.Session; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.envers.AuditReader; /** * An interface exposed by a VersionsReader to library-facing classes. + * * @author Adam Warski (adam at warski dot org) */ public interface AuditReaderImplementor extends AuditReader { - SessionImplementor getSessionImplementor(); - Session getSession(); - FirstLevelCache getFirstLevelCache(); + SessionImplementor getSessionImplementor(); + + Session getSession(); + + FirstLevelCache getFirstLevelCache(); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/reader/CrossTypeRevisionChangesReaderImpl.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/reader/CrossTypeRevisionChangesReaderImpl.java index 1f4cbbc0ab..6b4ab9619b 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/reader/CrossTypeRevisionChangesReaderImpl.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/reader/CrossTypeRevisionChangesReaderImpl.java @@ -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.internal.reader; import java.util.ArrayList; @@ -25,86 +48,115 @@ import static org.hibernate.envers.internal.tools.ArgumentsTools.checkPositive; * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public class CrossTypeRevisionChangesReaderImpl implements CrossTypeRevisionChangesReader { - private final AuditReaderImplementor auditReaderImplementor; - private final AuditConfiguration verCfg; + private final AuditReaderImplementor auditReaderImplementor; + private final AuditConfiguration verCfg; - public CrossTypeRevisionChangesReaderImpl(AuditReaderImplementor auditReaderImplementor, AuditConfiguration verCfg) { - this.auditReaderImplementor = auditReaderImplementor; - this.verCfg = verCfg; - } + public CrossTypeRevisionChangesReaderImpl( + AuditReaderImplementor auditReaderImplementor, + AuditConfiguration verCfg) { + this.auditReaderImplementor = auditReaderImplementor; + this.verCfg = verCfg; + } - @SuppressWarnings({"unchecked"}) - public List findEntities(Number revision) throws IllegalStateException, IllegalArgumentException { - Set> entityTypes = findEntityTypes(revision); - List result = new ArrayList(); - for (Pair type : entityTypes) { - result.addAll(auditReaderImplementor.createQuery().forEntitiesModifiedAtRevision(type.getSecond(), type.getFirst(), revision) - .getResultList()); - } - return result; - } + @Override + @SuppressWarnings({"unchecked"}) + public List findEntities(Number revision) throws IllegalStateException, IllegalArgumentException { + final Set> entityTypes = findEntityTypes( revision ); + final List result = new ArrayList(); + for ( Pair type : entityTypes ) { + result.addAll( + auditReaderImplementor.createQuery().forEntitiesModifiedAtRevision( + type.getSecond(), + type.getFirst(), + revision + ) + .getResultList() + ); + } + return result; + } - @SuppressWarnings({"unchecked"}) - public List findEntities(Number revision, RevisionType revisionType) throws IllegalStateException, - IllegalArgumentException { - Set> entityTypes = findEntityTypes(revision); - List result = new ArrayList(); - for (Pair type : entityTypes) { - result.addAll(auditReaderImplementor.createQuery().forEntitiesModifiedAtRevision(type.getSecond(), type.getFirst(), revision) - .add(new RevisionTypeAuditExpression(revisionType, "=")).getResultList()); - } - return result; - } + @Override + @SuppressWarnings({"unchecked"}) + public List findEntities(Number revision, RevisionType revisionType) + throws IllegalStateException, IllegalArgumentException { + final Set> entityTypes = findEntityTypes( revision ); + final List result = new ArrayList(); + for ( Pair type : entityTypes ) { + result.addAll( + auditReaderImplementor.createQuery().forEntitiesModifiedAtRevision( + type.getSecond(), + type.getFirst(), + revision + ) + .add( new RevisionTypeAuditExpression( revisionType, "=" ) ).getResultList() + ); + } + return result; + } - @SuppressWarnings({"unchecked"}) - public Map> findEntitiesGroupByRevisionType(Number revision) throws IllegalStateException, - IllegalArgumentException { - Set> entityTypes = findEntityTypes(revision); - Map> result = new HashMap>(); - for (RevisionType revisionType : RevisionType.values()) { - result.put(revisionType, new ArrayList()); - for (Pair type : entityTypes) { - List list = auditReaderImplementor.createQuery().forEntitiesModifiedAtRevision(type.getSecond(), type.getFirst(), revision) - .add(new RevisionTypeAuditExpression(revisionType, "=")).getResultList(); - result.get(revisionType).addAll(list); - } - } - return result; - } + @Override + @SuppressWarnings({"unchecked"}) + public Map> findEntitiesGroupByRevisionType(Number revision) + throws IllegalStateException, IllegalArgumentException { + final Set> entityTypes = findEntityTypes( revision ); + final Map> result = new HashMap>(); + for ( RevisionType revisionType : RevisionType.values() ) { + result.put( revisionType, new ArrayList() ); + for ( Pair type : entityTypes ) { + final List list = auditReaderImplementor.createQuery() + .forEntitiesModifiedAtRevision( type.getSecond(), type.getFirst(), revision ) + .add( new RevisionTypeAuditExpression( revisionType, "=" ) ) + .getResultList(); + result.get( revisionType ).addAll( list ); + } + } + return result; + } - @SuppressWarnings({"unchecked"}) - public Set> findEntityTypes(Number revision) throws IllegalStateException, IllegalArgumentException { - checkNotNull(revision, "Entity revision"); - checkPositive(revision, "Entity revision"); - checkSession(); + @Override + @SuppressWarnings({"unchecked"}) + public Set> findEntityTypes(Number revision) + throws IllegalStateException, IllegalArgumentException { + checkNotNull( revision, "Entity revision" ); + checkPositive( revision, "Entity revision" ); + checkSession(); - Session session = auditReaderImplementor.getSession(); - SessionImplementor sessionImplementor = auditReaderImplementor.getSessionImplementor(); + final Session session = auditReaderImplementor.getSession(); + final SessionImplementor sessionImplementor = auditReaderImplementor.getSessionImplementor(); - Set revisions = new HashSet(1); - revisions.add(revision); - Criteria query = verCfg.getRevisionInfoQueryCreator().getRevisionsQuery(session, revisions); - Object revisionInfo = query.uniqueResult(); + final Set revisions = new HashSet( 1 ); + revisions.add( revision ); + final Criteria query = verCfg.getRevisionInfoQueryCreator().getRevisionsQuery( session, revisions ); + final Object revisionInfo = query.uniqueResult(); - if (revisionInfo != null) { - // If revision exists. - Set entityNames = verCfg.getModifiedEntityNamesReader().getModifiedEntityNames(revisionInfo); - if (entityNames != null) { - // Generate result that contains entity names and corresponding Java classes. - Set> result = new HashSet>(); - for (String entityName : entityNames) { - result.add(Pair.make(entityName, EntityTools.getEntityClass(sessionImplementor, session, entityName))); - } - return result; - } - } + if ( revisionInfo != null ) { + // If revision exists. + final Set entityNames = verCfg.getModifiedEntityNamesReader().getModifiedEntityNames( revisionInfo ); + if ( entityNames != null ) { + // Generate result that contains entity names and corresponding Java classes. + final Set> result = new HashSet>(); + for ( String entityName : entityNames ) { + result.add( + Pair.make( + entityName, EntityTools.getEntityClass( + sessionImplementor, + session, + entityName + ) + ) + ); + } + return result; + } + } - return Collections.EMPTY_SET; - } + return Collections.EMPTY_SET; + } - private void checkSession() { - if (!auditReaderImplementor.getSession().isOpen()) { - throw new IllegalStateException("The associated entity manager is closed!"); - } - } + private void checkSession() { + if ( !auditReaderImplementor.getSession().isOpen() ) { + throw new IllegalStateException( "The associated entity manager is closed!" ); + } + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/reader/FirstLevelCache.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/reader/FirstLevelCache.java index db9a4a4ab6..1ad3511956 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/reader/FirstLevelCache.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/reader/FirstLevelCache.java @@ -1,7 +1,7 @@ /* * Hibernate, Relational Persistence for Idiomatic Java * - * Copyright (c) 2008-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. @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.internal.reader; + import java.util.Map; import org.jboss.logging.Logger; @@ -35,82 +36,101 @@ import static org.hibernate.envers.internal.tools.Triple.make; /** * First level cache for versioned entities, versions reader-scoped. Each entity is uniquely identified by a * revision number and entity id. + * * @author Adam Warski (adam at warski dot org) * @author Hernán Chanfreau */ public class FirstLevelCache { + private static final EnversMessageLogger LOG = Logger.getMessageLogger( + EnversMessageLogger.class, + FirstLevelCache.class.getName() + ); - public static final EnversMessageLogger LOG = Logger.getMessageLogger(EnversMessageLogger.class, FirstLevelCache.class.getName()); + /** + * cache for resolve an object for a given id, revision and entityName. + */ + private final Map, Object> cache; - /** - * cache for resolve an object for a given id, revision and entityName. - */ - private final Map, Object> cache; + /** + * used to resolve the entityName for a given id, revision and entity. + */ + private final Map, String> entityNameCache; - /** - * used to resolve the entityName for a given id, revision and entity. - */ - private final Map, String> entityNameCache; + public FirstLevelCache() { + cache = newHashMap(); + entityNameCache = newHashMap(); + } - public FirstLevelCache() { - cache = newHashMap(); - entityNameCache = newHashMap(); - } + public Object get(String entityName, Number revision, Object id) { + LOG.debugf( + "Resolving object from First Level Cache: EntityName:%s - primaryKey:%s - revision:%s", + entityName, + id, + revision + ); + return cache.get( make( entityName, revision, id ) ); + } - public Object get(String entityName, Number revision, Object id) { - LOG.debugf("Resolving object from First Level Cache: EntityName:%s - primaryKey:%s - revision:%s", entityName, id, revision); - return cache.get(make(entityName, revision, id)); - } + public void put(String entityName, Number revision, Object id, Object entity) { + LOG.debugf( + "Caching entity on First Level Cache: - primaryKey:%s - revision:%s - entityName:%s", + id, + revision, + entityName + ); + cache.put( make( entityName, revision, id ), entity ); + } - public void put(String entityName, Number revision, Object id, Object entity) { - LOG.debugf("Caching entity on First Level Cache: - primaryKey:%s - revision:%s - entityName:%s", id, revision, entityName); - cache.put(make(entityName, revision, id), entity); - } + public boolean contains(String entityName, Number revision, Object id) { + return cache.containsKey( make( entityName, revision, id ) ); + } - public boolean contains(String entityName, Number revision, Object id) { - return cache.containsKey(make(entityName, revision, id)); - } - - /** - * Adds the entityName into the cache. The key is a triple make with primaryKey, revision and entity - * @param id primaryKey - * @param revision revision number - * @param entity object retrieved by envers - * @param entityName value of the cache - */ - public void putOnEntityNameCache(Object id, Number revision, Object entity, String entityName) { - LOG.debugf("Caching entityName on First Level Cache: - primaryKey:%s - revision:%s - entity:%s -> entityName:%s", - id, - revision, - entity.getClass().getName(), - entityName); - entityNameCache.put(make(id, revision, entity), entityName); - } - - /** - * Gets the entityName from the cache. The key is a triple make with primaryKey, revision and entity + /** + * Adds the entityName into the cache. The key is a triple make with primaryKey, revision and entity * - * @param id primaryKey - * @param revision revision number - * @param entity object retrieved by envers + * @param id primaryKey + * @param revision revision number + * @param entity object retrieved by envers + * @param entityName value of the cache + */ + public void putOnEntityNameCache(Object id, Number revision, Object entity, String entityName) { + LOG.debugf( + "Caching entityName on First Level Cache: - primaryKey:%s - revision:%s - entity:%s -> entityName:%s", + id, + revision, + entity.getClass().getName(), + entityName + ); + entityNameCache.put( make( id, revision, entity ), entityName ); + } + + /** + * Gets the entityName from the cache. The key is a triple make with primaryKey, revision and entity + * + * @param id primaryKey + * @param revision revision number + * @param entity object retrieved by envers * * @return The appropriate entity name - */ - public String getFromEntityNameCache(Object id, Number revision, Object entity) { - LOG.debugf("Trying to resolve entityName from First Level Cache: - primaryKey:%s - revision:%s - entity:%s", - id, - revision, - entity); - return entityNameCache.get(make(id, revision, entity)); - } + */ + public String getFromEntityNameCache(Object id, Number revision, Object entity) { + LOG.debugf( + "Trying to resolve entityName from First Level Cache: - primaryKey:%s - revision:%s - entity:%s", + id, + revision, + entity + ); + return entityNameCache.get( make( id, revision, entity ) ); + } /** * @param id primaryKey * @param revision revision number * @param entity object retrieved by envers + * * @return true if entityNameCache contains the triple */ - public boolean containsEntityName(Object id, Number revision, Object entity) { - return entityNameCache.containsKey(make(id, revision, entity)); - } + public boolean containsEntityName(Object id, Number revision, Object entity) { + return entityNameCache.containsKey( make( id, revision, entity ) ); + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/revisioninfo/DefaultRevisionInfoGenerator.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/revisioninfo/DefaultRevisionInfoGenerator.java index b3d480c71a..df36426cc6 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/revisioninfo/DefaultRevisionInfoGenerator.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/revisioninfo/DefaultRevisionInfoGenerator.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 @@ -43,70 +43,88 @@ import org.hibernate.property.Setter; * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public class DefaultRevisionInfoGenerator implements RevisionInfoGenerator { - private final String revisionInfoEntityName; - private final RevisionListener listener; - private final Setter revisionTimestampSetter; - private final boolean timestampAsDate; - private final Class revisionInfoClass; - private final SessionCacheCleaner sessionCacheCleaner; + private final String revisionInfoEntityName; + private final RevisionListener listener; + private final Setter revisionTimestampSetter; + private final boolean timestampAsDate; + private final Class revisionInfoClass; + private final SessionCacheCleaner sessionCacheCleaner; - public DefaultRevisionInfoGenerator(String revisionInfoEntityName, Class revisionInfoClass, - Class listenerClass, - PropertyData revisionInfoTimestampData, - boolean timestampAsDate) { - this.revisionInfoEntityName = revisionInfoEntityName; - this.revisionInfoClass = revisionInfoClass; - this.timestampAsDate = timestampAsDate; + public DefaultRevisionInfoGenerator( + String revisionInfoEntityName, Class revisionInfoClass, + Class listenerClass, + PropertyData revisionInfoTimestampData, + boolean timestampAsDate) { + this.revisionInfoEntityName = revisionInfoEntityName; + this.revisionInfoClass = revisionInfoClass; + this.timestampAsDate = timestampAsDate; - revisionTimestampSetter = ReflectionTools.getSetter(revisionInfoClass, revisionInfoTimestampData); + revisionTimestampSetter = ReflectionTools.getSetter( revisionInfoClass, revisionInfoTimestampData ); - if (!listenerClass.equals(RevisionListener.class)) { - // This is not the default value. - try { - listener = (RevisionListener) ReflectHelper.getDefaultConstructor(listenerClass).newInstance(); - } catch (InstantiationException e) { - throw new MappingException(e); - } catch (IllegalAccessException e) { - throw new MappingException(e); - } catch (InvocationTargetException e) { - throw new MappingException(e); - } - } else { - // Default listener - none - listener = null; - } + if ( !listenerClass.equals( RevisionListener.class ) ) { + // This is not the default value. + try { + listener = (RevisionListener) ReflectHelper.getDefaultConstructor( listenerClass ).newInstance(); + } + catch (InstantiationException e) { + throw new MappingException( e ); + } + catch (IllegalAccessException e) { + throw new MappingException( e ); + } + catch (InvocationTargetException e) { + throw new MappingException( e ); + } + } + else { + // Default listener - none + listener = null; + } - sessionCacheCleaner = new SessionCacheCleaner(); - } - - public void saveRevisionData(Session session, Object revisionData) { - session.save(revisionInfoEntityName, revisionData); - sessionCacheCleaner.scheduleAuditDataRemoval(session, revisionData); + sessionCacheCleaner = new SessionCacheCleaner(); } - public Object generate() { + @Override + public void saveRevisionData(Session session, Object revisionData) { + session.save( revisionInfoEntityName, revisionData ); + sessionCacheCleaner.scheduleAuditDataRemoval( session, revisionData ); + } + + @Override + public Object generate() { Object revisionInfo; - try { - revisionInfo = ReflectHelper.getDefaultConstructor(revisionInfoClass).newInstance(); - } catch (Exception e) { - throw new RuntimeException(e); - } + try { + revisionInfo = ReflectHelper.getDefaultConstructor( revisionInfoClass ).newInstance(); + } + catch (Exception e) { + throw new RuntimeException( e ); + } - long timestamp = System.currentTimeMillis(); - revisionTimestampSetter.set(revisionInfo, timestampAsDate ? new Date(timestamp) : timestamp, null); + final long timestamp = System.currentTimeMillis(); + revisionTimestampSetter.set( revisionInfo, timestampAsDate ? new Date( timestamp ) : timestamp, null ); - if (listener != null) { - listener.newRevision(revisionInfo); - } + if ( listener != null ) { + listener.newRevision( revisionInfo ); + } - return revisionInfo; - } + return revisionInfo; + } - public void entityChanged(Class entityClass, String entityName, Serializable entityId, RevisionType revisionType, - Object revisionInfo) { - if (listener instanceof EntityTrackingRevisionListener) { - ((EntityTrackingRevisionListener) listener).entityChanged(entityClass, entityName, entityId, revisionType, - revisionInfo); - } - } + @Override + public void entityChanged( + Class entityClass, + String entityName, + Serializable entityId, + RevisionType revisionType, + Object revisionInfo) { + if ( listener instanceof EntityTrackingRevisionListener ) { + ( (EntityTrackingRevisionListener) listener ).entityChanged( + entityClass, + entityName, + entityId, + revisionType, + revisionInfo + ); + } + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/revisioninfo/DefaultTrackingModifiedEntitiesRevisionInfoGenerator.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/revisioninfo/DefaultTrackingModifiedEntitiesRevisionInfoGenerator.java index f3da3f4d1a..328bc8f28d 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/revisioninfo/DefaultTrackingModifiedEntitiesRevisionInfoGenerator.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/revisioninfo/DefaultTrackingModifiedEntitiesRevisionInfoGenerator.java @@ -1,11 +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.internal.revisioninfo; import java.io.Serializable; import java.util.HashSet; import java.util.Set; -import org.hibernate.envers.DefaultTrackingModifiedEntitiesRevisionEntity; -import org.hibernate.envers.ModifiedEntityNames; import org.hibernate.envers.RevisionListener; import org.hibernate.envers.RevisionType; import org.hibernate.envers.internal.entities.PropertyData; @@ -15,33 +36,40 @@ import org.hibernate.property.Setter; /** * Automatically adds entity names, that have been changed during current revision, to revision entity. - * @see ModifiedEntityNames - * @see DefaultTrackingModifiedEntitiesRevisionEntity + * * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) + * + * @see org.hibernate.envers.ModifiedEntityNames + * @see org.hibernate.envers.DefaultTrackingModifiedEntitiesRevisionEntity */ public class DefaultTrackingModifiedEntitiesRevisionInfoGenerator extends DefaultRevisionInfoGenerator { - private final Setter modifiedEntityNamesSetter; - private final Getter modifiedEntityNamesGetter; + private final Setter modifiedEntityNamesSetter; + private final Getter modifiedEntityNamesGetter; - public DefaultTrackingModifiedEntitiesRevisionInfoGenerator(String revisionInfoEntityName, Class revisionInfoClass, - Class listenerClass, - PropertyData revisionInfoTimestampData, boolean timestampAsDate, - PropertyData modifiedEntityNamesData) { - super(revisionInfoEntityName, revisionInfoClass, listenerClass, revisionInfoTimestampData, timestampAsDate); - modifiedEntityNamesSetter = ReflectionTools.getSetter(revisionInfoClass, modifiedEntityNamesData); - modifiedEntityNamesGetter = ReflectionTools.getGetter(revisionInfoClass, modifiedEntityNamesData); - } + public DefaultTrackingModifiedEntitiesRevisionInfoGenerator( + String revisionInfoEntityName, Class revisionInfoClass, + Class listenerClass, + PropertyData revisionInfoTimestampData, boolean timestampAsDate, + PropertyData modifiedEntityNamesData) { + super( revisionInfoEntityName, revisionInfoClass, listenerClass, revisionInfoTimestampData, timestampAsDate ); + modifiedEntityNamesSetter = ReflectionTools.getSetter( revisionInfoClass, modifiedEntityNamesData ); + modifiedEntityNamesGetter = ReflectionTools.getGetter( revisionInfoClass, modifiedEntityNamesData ); + } - @Override - @SuppressWarnings({"unchecked"}) - public void entityChanged(Class entityClass, String entityName, Serializable entityId, RevisionType revisionType, - Object revisionEntity) { - super.entityChanged(entityClass, entityName, entityId, revisionType, revisionEntity); - Set modifiedEntityNames = (Set) modifiedEntityNamesGetter.get(revisionEntity); - if (modifiedEntityNames == null) { - modifiedEntityNames = new HashSet(); - modifiedEntityNamesSetter.set(revisionEntity, modifiedEntityNames, null); - } - modifiedEntityNames.add(entityName); - } + @Override + @SuppressWarnings({"unchecked"}) + public void entityChanged( + Class entityClass, + String entityName, + Serializable entityId, + RevisionType revisionType, + Object revisionEntity) { + super.entityChanged( entityClass, entityName, entityId, revisionType, revisionEntity ); + Set modifiedEntityNames = (Set) modifiedEntityNamesGetter.get( revisionEntity ); + if ( modifiedEntityNames == null ) { + modifiedEntityNames = new HashSet(); + modifiedEntityNamesSetter.set( revisionEntity, modifiedEntityNames, null ); + } + modifiedEntityNames.add( entityName ); + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/revisioninfo/ModifiedEntityNamesReader.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/revisioninfo/ModifiedEntityNamesReader.java index f29f6846d4..eeeaf41fdc 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/revisioninfo/ModifiedEntityNamesReader.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/revisioninfo/ModifiedEntityNamesReader.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.internal.revisioninfo; import java.util.Set; @@ -8,17 +31,18 @@ import org.hibernate.property.Getter; /** * Returns modified entity names from a persisted revision info entity. + * * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public class ModifiedEntityNamesReader { - private final Getter modifiedEntityNamesGetter; + private final Getter modifiedEntityNamesGetter; - public ModifiedEntityNamesReader(Class revisionInfoClass, PropertyData modifiedEntityNamesData) { - modifiedEntityNamesGetter = ReflectionTools.getGetter(revisionInfoClass, modifiedEntityNamesData); - } + public ModifiedEntityNamesReader(Class revisionInfoClass, PropertyData modifiedEntityNamesData) { + modifiedEntityNamesGetter = ReflectionTools.getGetter( revisionInfoClass, modifiedEntityNamesData ); + } - @SuppressWarnings({"unchecked"}) - public Set getModifiedEntityNames(Object revisionEntity) { - return (Set) modifiedEntityNamesGetter.get(revisionEntity); - } + @SuppressWarnings({"unchecked"}) + public Set getModifiedEntityNames(Object revisionEntity) { + return (Set) modifiedEntityNamesGetter.get( revisionEntity ); + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/revisioninfo/RevisionInfoGenerator.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/revisioninfo/RevisionInfoGenerator.java index cef1a14a3b..30fa321d36 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/revisioninfo/RevisionInfoGenerator.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/revisioninfo/RevisionInfoGenerator.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 @@ -34,11 +34,13 @@ import org.hibernate.envers.RevisionType; */ public interface RevisionInfoGenerator { void saveRevisionData(Session session, Object revisionData); - Object generate(); - /** - * @see EntityTrackingRevisionListener#entityChanged(Class, String, Serializable, RevisionType, Object) - */ - void entityChanged(Class entityClass, String entityName, Serializable entityId, RevisionType revisionType, - Object revisionEntity); + Object generate(); + + /** + * @see EntityTrackingRevisionListener#entityChanged(Class, String, Serializable, RevisionType, Object) + */ + void entityChanged( + Class entityClass, String entityName, Serializable entityId, RevisionType revisionType, + Object revisionEntity); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/revisioninfo/RevisionInfoNumberReader.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/revisioninfo/RevisionInfoNumberReader.java index 69f17ad8fb..a19d2667c7 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/revisioninfo/RevisionInfoNumberReader.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/revisioninfo/RevisionInfoNumberReader.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,21 +22,24 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.internal.revisioninfo; + import org.hibernate.envers.internal.entities.PropertyData; import org.hibernate.envers.internal.tools.ReflectionTools; import org.hibernate.property.Getter; /** * Gets a revision number from a persisted revision info entity. + * * @author Adam Warski (adam at warski dot org) */ public class RevisionInfoNumberReader { - private final Getter revisionIdGetter; - public RevisionInfoNumberReader(Class revisionInfoClass, PropertyData revisionInfoIdData) { - revisionIdGetter = ReflectionTools.getGetter(revisionInfoClass, revisionInfoIdData); - } + private final Getter revisionIdGetter; - public Number getRevisionNumber(Object revision) { - return (Number) revisionIdGetter.get(revision); - } + public RevisionInfoNumberReader(Class revisionInfoClass, PropertyData revisionInfoIdData) { + revisionIdGetter = ReflectionTools.getGetter( revisionInfoClass, revisionInfoIdData ); + } + + public Number getRevisionNumber(Object revision) { + return (Number) revisionIdGetter.get( revision ); + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/revisioninfo/RevisionInfoQueryCreator.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/revisioninfo/RevisionInfoQueryCreator.java index 005d29db58..202d7f5eed 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/revisioninfo/RevisionInfoQueryCreator.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/revisioninfo/RevisionInfoQueryCreator.java @@ -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 @@ -36,30 +36,35 @@ import org.hibernate.criterion.Restrictions; * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public class RevisionInfoQueryCreator { - private final String revisionInfoEntityName; - private final String revisionInfoIdName; - private final String revisionInfoTimestampName; - private final boolean timestampAsDate; + private final String revisionInfoEntityName; + private final String revisionInfoIdName; + private final String revisionInfoTimestampName; + private final boolean timestampAsDate; - public RevisionInfoQueryCreator(String revisionInfoEntityName, String revisionInfoIdName, - String revisionInfoTimestampName, boolean timestampAsDate) { - this.revisionInfoEntityName = revisionInfoEntityName; - this.revisionInfoIdName = revisionInfoIdName; - this.revisionInfoTimestampName = revisionInfoTimestampName; - this.timestampAsDate = timestampAsDate; - } + public RevisionInfoQueryCreator( + String revisionInfoEntityName, String revisionInfoIdName, + String revisionInfoTimestampName, boolean timestampAsDate) { + this.revisionInfoEntityName = revisionInfoEntityName; + this.revisionInfoIdName = revisionInfoIdName; + this.revisionInfoTimestampName = revisionInfoTimestampName; + this.timestampAsDate = timestampAsDate; + } - public Criteria getRevisionDateQuery(Session session, Number revision) { - return session.createCriteria(revisionInfoEntityName).setProjection(Projections.property(revisionInfoTimestampName)) - .add(Restrictions.eq(revisionInfoIdName, revision)); - } + public Criteria getRevisionDateQuery(Session session, Number revision) { + return session.createCriteria( revisionInfoEntityName ).setProjection( + Projections.property( + revisionInfoTimestampName + ) + ) + .add( Restrictions.eq( revisionInfoIdName, revision ) ); + } - public Criteria getRevisionNumberForDateQuery(Session session, Date date) { - return session.createCriteria(revisionInfoEntityName).setProjection(Projections.max(revisionInfoIdName)) - .add(Restrictions.le(revisionInfoTimestampName, timestampAsDate ? date : date.getTime())); - } + public Criteria getRevisionNumberForDateQuery(Session session, Date date) { + return session.createCriteria( revisionInfoEntityName ).setProjection( Projections.max( revisionInfoIdName ) ) + .add( Restrictions.le( revisionInfoTimestampName, timestampAsDate ? date : date.getTime() ) ); + } - public Criteria getRevisionsQuery(Session session, Set revisions) { - return session.createCriteria(revisionInfoEntityName).add(Restrictions.in(revisionInfoIdName, revisions)); - } + public Criteria getRevisionsQuery(Session session, Set revisions) { + return session.createCriteria( revisionInfoEntityName ).add( Restrictions.in( revisionInfoIdName, revisions ) ); + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/AuditProcess.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/AuditProcess.java index d8e79979b6..709eef5002 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/AuditProcess.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/AuditProcess.java @@ -1,7 +1,7 @@ /* * Hibernate, Relational Persistence for Idiomatic Java * - * Copyright (c) 2010, 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. @@ -41,121 +41,127 @@ import org.hibernate.envers.tools.Pair; * @author Adam Warski (adam at warski dot org) */ public class AuditProcess implements BeforeTransactionCompletionProcess { - private final RevisionInfoGenerator revisionInfoGenerator; - private final SessionImplementor session; + private final RevisionInfoGenerator revisionInfoGenerator; + private final SessionImplementor session; - private final LinkedList workUnits; - private final Queue undoQueue; - private final Map, AuditWorkUnit> usedIds; - private final EntityChangeNotifier entityChangeNotifier; + private final LinkedList workUnits; + private final Queue undoQueue; + private final Map, AuditWorkUnit> usedIds; + private final EntityChangeNotifier entityChangeNotifier; - private Object revisionData; + private Object revisionData; - public AuditProcess(RevisionInfoGenerator revisionInfoGenerator, SessionImplementor session) { - this.revisionInfoGenerator = revisionInfoGenerator; - this.session = session; + public AuditProcess(RevisionInfoGenerator revisionInfoGenerator, SessionImplementor session) { + this.revisionInfoGenerator = revisionInfoGenerator; + this.session = session; - workUnits = new LinkedList(); - undoQueue = new LinkedList(); - usedIds = new HashMap, AuditWorkUnit>(); - entityChangeNotifier = new EntityChangeNotifier(revisionInfoGenerator, session); - } + workUnits = new LinkedList(); + undoQueue = new LinkedList(); + usedIds = new HashMap, AuditWorkUnit>(); + entityChangeNotifier = new EntityChangeNotifier( revisionInfoGenerator, session ); + } - private void removeWorkUnit(AuditWorkUnit vwu) { - workUnits.remove(vwu); - if (vwu.isPerformed()) { - // If this work unit has already been performed, it must be deleted (undone) first. - undoQueue.offer(vwu); - } - } + private void removeWorkUnit(AuditWorkUnit vwu) { + workUnits.remove( vwu ); + if ( vwu.isPerformed() ) { + // If this work unit has already been performed, it must be deleted (undone) first. + undoQueue.offer( vwu ); + } + } - public void addWorkUnit(AuditWorkUnit vwu) { - if (vwu.containsWork()) { - Object entityId = vwu.getEntityId(); + public void addWorkUnit(AuditWorkUnit vwu) { + if ( vwu.containsWork() ) { + final Object entityId = vwu.getEntityId(); - if (entityId == null) { - // Just adding the work unit - it's not associated with any persistent entity. - workUnits.offer(vwu); - } else { - String entityName = vwu.getEntityName(); - Pair usedIdsKey = Pair.make(entityName, entityId); + if ( entityId == null ) { + // Just adding the work unit - it's not associated with any persistent entity. + workUnits.offer( vwu ); + } + else { + final String entityName = vwu.getEntityName(); + final Pair usedIdsKey = Pair.make( entityName, entityId ); - if (usedIds.containsKey(usedIdsKey)) { - AuditWorkUnit other = usedIds.get(usedIdsKey); + if ( usedIds.containsKey( usedIdsKey ) ) { + final AuditWorkUnit other = usedIds.get( usedIdsKey ); + final AuditWorkUnit result = vwu.dispatch( other ); - AuditWorkUnit result = vwu.dispatch(other); + if ( result != other ) { + removeWorkUnit( other ); - if (result != other) { - removeWorkUnit(other); + if ( result != null ) { + usedIds.put( usedIdsKey, result ); + workUnits.offer( result ); + } + // else: a null result means that no work unit should be kept + } + // else: the result is the same as the work unit already added. No need to do anything. + } + else { + usedIds.put( usedIdsKey, vwu ); + workUnits.offer( vwu ); + } + } + } + } - if (result != null) { - usedIds.put(usedIdsKey, result); - workUnits.offer(result); - } // else: a null result means that no work unit should be kept - } // else: the result is the same as the work unit already added. No need to do anything. - } else { - usedIds.put(usedIdsKey, vwu); - workUnits.offer(vwu); - } - } - } - } - - private void executeInSession(Session session) { + private void executeInSession(Session session) { // Making sure the revision data is persisted. - Object currentRevisionData = getCurrentRevisionData(session, true); + final Object currentRevisionData = getCurrentRevisionData( session, true ); - AuditWorkUnit vwu; + AuditWorkUnit vwu; - // First undoing any performed work units - while ((vwu = undoQueue.poll()) != null) { - vwu.undo(session); - } + // First undoing any performed work units + while ( (vwu = undoQueue.poll()) != null ) { + vwu.undo( session ); + } - while ((vwu = workUnits.poll()) != null) { - vwu.perform(session, revisionData); - entityChangeNotifier.entityChanged(session, currentRevisionData, vwu); - } - } + while ( (vwu = workUnits.poll()) != null ) { + vwu.perform( session, revisionData ); + entityChangeNotifier.entityChanged( session, currentRevisionData, vwu ); + } + } public Object getCurrentRevisionData(Session session, boolean persist) { // Generating the revision data if not yet generated - if (revisionData == null) { - revisionData = revisionInfoGenerator.generate(); - } + if ( revisionData == null ) { + revisionData = revisionInfoGenerator.generate(); + } // Saving the revision data, if not yet saved and persist is true - if (!session.contains(revisionData) && persist) { - revisionInfoGenerator.saveRevisionData(session, revisionData); + if ( !session.contains( revisionData ) && persist ) { + revisionInfoGenerator.saveRevisionData( session, revisionData ); } return revisionData; } - public void doBeforeTransactionCompletion(SessionImplementor session) { - if (workUnits.size() == 0 && undoQueue.size() == 0) { - return; - } + @Override + public void doBeforeTransactionCompletion(SessionImplementor session) { + if ( workUnits.size() == 0 && undoQueue.size() == 0 ) { + return; + } - // see: http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4178431 - if (FlushMode.isManualFlushMode(session.getFlushMode())) { - Session temporarySession = null; - try { - temporarySession = ((Session) session).sessionWithOptions().transactionContext().autoClose(false) - .connectionReleaseMode(ConnectionReleaseMode.AFTER_TRANSACTION) - .openSession(); - executeInSession(temporarySession); - temporarySession.flush(); - } finally { - if (temporarySession != null) { - temporarySession.close(); - } - } - } else { - executeInSession((Session) session); + // see: http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4178431 + if ( FlushMode.isManualFlushMode( session.getFlushMode() ) ) { + Session temporarySession = null; + try { + temporarySession = ((Session) session).sessionWithOptions().transactionContext().autoClose( false ) + .connectionReleaseMode( ConnectionReleaseMode.AFTER_TRANSACTION ) + .openSession(); + executeInSession( temporarySession ); + temporarySession.flush(); + } + finally { + if ( temporarySession != null ) { + temporarySession.close(); + } + } + } + else { + executeInSession( (Session) session ); - // Explicitly flushing the session, as the auto-flush may have already happened. - session.flush(); - } - } + // Explicitly flushing the session, as the auto-flush may have already happened. + session.flush(); + } + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/AuditProcessManager.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/AuditProcessManager.java index 7786d0970e..5e3b577495 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/AuditProcessManager.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/AuditProcessManager.java @@ -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.internal.synchronization; + import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -36,23 +37,23 @@ import org.hibernate.event.spi.EventSource; * @author Adam Warski (adam at warski dot org) */ public class AuditProcessManager { - private final Map auditProcesses; - private final RevisionInfoGenerator revisionInfoGenerator; + private final Map auditProcesses; + private final RevisionInfoGenerator revisionInfoGenerator; - public AuditProcessManager(RevisionInfoGenerator revisionInfoGenerator) { - auditProcesses = new ConcurrentHashMap(); + public AuditProcessManager(RevisionInfoGenerator revisionInfoGenerator) { + auditProcesses = new ConcurrentHashMap(); - this.revisionInfoGenerator = revisionInfoGenerator; - } + this.revisionInfoGenerator = revisionInfoGenerator; + } - public AuditProcess get(EventSource session) { - final Transaction transaction = session.getTransaction(); - - AuditProcess auditProcess = auditProcesses.get(transaction); - if (auditProcess == null) { - // No worries about registering a transaction twice - a transaction is single thread - auditProcess = new AuditProcess(revisionInfoGenerator, session); - auditProcesses.put(transaction, auditProcess); + public AuditProcess get(EventSource session) { + final Transaction transaction = session.getTransaction(); + + AuditProcess auditProcess = auditProcesses.get( transaction ); + if ( auditProcess == null ) { + // No worries about registering a transaction twice - a transaction is single thread + auditProcess = new AuditProcess( revisionInfoGenerator, session ); + auditProcesses.put( transaction, auditProcess ); session.getActionQueue().registerProcess( new BeforeTransactionCompletionProcess() { @@ -65,13 +66,15 @@ public class AuditProcessManager { } ); - session.getActionQueue().registerProcess(new AfterTransactionCompletionProcess() { - public void doAfterTransactionCompletion(boolean success, SessionImplementor session) { - auditProcesses.remove(transaction); - } - }); - } + session.getActionQueue().registerProcess( + new AfterTransactionCompletionProcess() { + public void doAfterTransactionCompletion(boolean success, SessionImplementor session) { + auditProcesses.remove( transaction ); + } + } + ); + } - return auditProcess; - } + return auditProcess; + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/EntityChangeNotifier.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/EntityChangeNotifier.java index c9dc6cad76..a8744b8ac1 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/EntityChangeNotifier.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/EntityChangeNotifier.java @@ -1,10 +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.internal.synchronization; import java.io.Serializable; import org.hibernate.Session; import org.hibernate.engine.spi.SessionImplementor; -import org.hibernate.envers.RevisionType; import org.hibernate.envers.internal.revisioninfo.RevisionInfoGenerator; import org.hibernate.envers.internal.synchronization.work.AuditWorkUnit; import org.hibernate.envers.internal.synchronization.work.PersistentCollectionChangeWorkUnit; @@ -12,32 +34,40 @@ import org.hibernate.envers.internal.tools.EntityTools; /** * Notifies {@link RevisionInfoGenerator} about changes made in the current revision. + * * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public class EntityChangeNotifier { - private final RevisionInfoGenerator revisionInfoGenerator; - private final SessionImplementor sessionImplementor; + private final RevisionInfoGenerator revisionInfoGenerator; + private final SessionImplementor sessionImplementor; - public EntityChangeNotifier(RevisionInfoGenerator revisionInfoGenerator, SessionImplementor sessionImplementor) { - this.revisionInfoGenerator = revisionInfoGenerator; - this.sessionImplementor = sessionImplementor; - } + public EntityChangeNotifier(RevisionInfoGenerator revisionInfoGenerator, SessionImplementor sessionImplementor) { + this.revisionInfoGenerator = revisionInfoGenerator; + this.sessionImplementor = sessionImplementor; + } - /** - * Notifies {@link RevisionInfoGenerator} about changes made in the current revision. Provides information - * about modified entity class, entity name and its id, as well as {@link RevisionType} and revision log entity. - * @param session Active session. - * @param currentRevisionData Revision log entity. - * @param vwu Performed work unit. - */ - public void entityChanged(Session session, Object currentRevisionData, AuditWorkUnit vwu) { - Serializable entityId = vwu.getEntityId(); - if (entityId instanceof PersistentCollectionChangeWorkUnit.PersistentCollectionChangeWorkUnitId) { - // Notify about a change in collection owner entity. - entityId = ((PersistentCollectionChangeWorkUnit.PersistentCollectionChangeWorkUnitId) entityId).getOwnerId(); - } - Class entityClass = EntityTools.getEntityClass(sessionImplementor, session, vwu.getEntityName()); - revisionInfoGenerator.entityChanged(entityClass, vwu.getEntityName(), entityId, vwu.getRevisionType(), - currentRevisionData); - } + /** + * Notifies {@link RevisionInfoGenerator} about changes made in the current revision. Provides information + * about modified entity class, entity name and its id, as well as {@link org.hibernate.envers.RevisionType} + * and revision log entity. + * + * @param session Active session. + * @param currentRevisionData Revision log entity. + * @param vwu Performed work unit. + */ + public void entityChanged(Session session, Object currentRevisionData, AuditWorkUnit vwu) { + Serializable entityId = vwu.getEntityId(); + if ( entityId instanceof PersistentCollectionChangeWorkUnit.PersistentCollectionChangeWorkUnitId ) { + // Notify about a change in collection owner entity. + entityId = ((PersistentCollectionChangeWorkUnit.PersistentCollectionChangeWorkUnitId) entityId).getOwnerId(); + } + final Class entityClass = EntityTools.getEntityClass( sessionImplementor, session, vwu.getEntityName() ); + revisionInfoGenerator.entityChanged( + entityClass, + vwu.getEntityName(), + entityId, + vwu.getRevisionType(), + currentRevisionData + ); + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/SessionCacheCleaner.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/SessionCacheCleaner.java index 4c9c8c40fe..ed465a3707 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/SessionCacheCleaner.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/SessionCacheCleaner.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.internal.synchronization; import org.hibernate.Session; @@ -8,22 +31,26 @@ import org.hibernate.event.spi.EventSource; /** * Class responsible for evicting audit data entries that have been stored in the session level cache. * This operation increases Envers performance in case of massive entity updates without clearing persistence context. + * * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public class SessionCacheCleaner { - /** - * Schedules audit data removal from session level cache after transaction completion. The operation is performed - * regardless of commit success. - * @param session Active Hibernate session. - * @param data Audit data that shall be evicted (e.g. revision data or entity snapshot) - */ - public void scheduleAuditDataRemoval(final Session session, final Object data) { - ((EventSource) session).getActionQueue().registerProcess(new AfterTransactionCompletionProcess() { - public void doAfterTransactionCompletion(boolean success, SessionImplementor session) { - if (!session.isClosed()) { - ((Session) session).evict(data); - } - } - }); - } + /** + * Schedules audit data removal from session level cache after transaction completion. The operation is performed + * regardless of commit success. + * + * @param session Active Hibernate session. + * @param data Audit data that shall be evicted (e.g. revision data or entity snapshot) + */ + public void scheduleAuditDataRemoval(final Session session, final Object data) { + ((EventSource) session).getActionQueue().registerProcess( + new AfterTransactionCompletionProcess() { + public void doAfterTransactionCompletion(boolean success, SessionImplementor session) { + if ( !session.isClosed() ) { + ((Session) session).evict( data ); + } + } + } + ); + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/AbstractAuditWorkUnit.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/AbstractAuditWorkUnit.java index 29bd8ce032..4c58b34f46 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/AbstractAuditWorkUnit.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/AbstractAuditWorkUnit.java @@ -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 @@ -41,67 +41,73 @@ import org.hibernate.envers.strategy.AuditStrategy; */ public abstract class AbstractAuditWorkUnit implements AuditWorkUnit { protected final SessionImplementor sessionImplementor; - protected final AuditConfiguration verCfg; - protected final Serializable id; - protected final String entityName; - protected final AuditStrategy auditStrategy; - protected final RevisionType revisionType; + protected final AuditConfiguration verCfg; + protected final Serializable id; + protected final String entityName; + protected final AuditStrategy auditStrategy; + protected final RevisionType revisionType; - private Object performedData; + private Object performedData; - protected AbstractAuditWorkUnit(SessionImplementor sessionImplementor, String entityName, AuditConfiguration verCfg, - Serializable id, RevisionType revisionType) { + protected AbstractAuditWorkUnit( + SessionImplementor sessionImplementor, String entityName, AuditConfiguration verCfg, + Serializable id, RevisionType revisionType) { this.sessionImplementor = sessionImplementor; - this.verCfg = verCfg; - this.id = id; - this.entityName = entityName; - this.revisionType = revisionType; - this.auditStrategy = verCfg.getAuditStrategy(); - } + this.verCfg = verCfg; + this.id = id; + this.entityName = entityName; + this.revisionType = revisionType; + this.auditStrategy = verCfg.getAuditStrategy(); + } - protected void fillDataWithId(Map data, Object revision) { - AuditEntitiesConfiguration entitiesCfg = verCfg.getAuditEntCfg(); + protected void fillDataWithId(Map data, Object revision) { + final AuditEntitiesConfiguration entitiesCfg = verCfg.getAuditEntCfg(); - Map originalId = new HashMap(); - originalId.put(entitiesCfg.getRevisionFieldName(), revision); + final Map originalId = new HashMap(); + originalId.put( entitiesCfg.getRevisionFieldName(), revision ); - verCfg.getEntCfg().get(getEntityName()).getIdMapper().mapToMapFromId(originalId, id); - data.put(entitiesCfg.getRevisionTypePropName(), revisionType); - data.put(entitiesCfg.getOriginalIdPropName(), originalId); - } + verCfg.getEntCfg().get( getEntityName() ).getIdMapper().mapToMapFromId( originalId, id ); + data.put( entitiesCfg.getRevisionTypePropName(), revisionType ); + data.put( entitiesCfg.getOriginalIdPropName(), originalId ); + } - public void perform(Session session, Object revisionData) { - Map data = generateData(revisionData); + @Override + public void perform(Session session, Object revisionData) { + final Map data = generateData( revisionData ); - auditStrategy.perform(session, getEntityName(), verCfg, id, data, revisionData); + auditStrategy.perform( session, getEntityName(), verCfg, id, data, revisionData ); - setPerformed(data); - } + setPerformed( data ); + } - public Serializable getEntityId() { - return id; - } + @Override + public Serializable getEntityId() { + return id; + } - public boolean isPerformed() { - return performedData != null; - } + @Override + public boolean isPerformed() { + return performedData != null; + } - public String getEntityName() { - return entityName; - } + @Override + public String getEntityName() { + return entityName; + } - protected void setPerformed(Object performedData) { - this.performedData = performedData; - } + protected void setPerformed(Object performedData) { + this.performedData = performedData; + } - public void undo(Session session) { - if (isPerformed()) { - session.delete(verCfg.getAuditEntCfg().getAuditEntityName(getEntityName()), performedData); - session.flush(); - } - } + public void undo(Session session) { + if ( isPerformed() ) { + session.delete( verCfg.getAuditEntCfg().getAuditEntityName( getEntityName() ), performedData ); + session.flush(); + } + } - public RevisionType getRevisionType() { - return revisionType; - } + @Override + public RevisionType getRevisionType() { + return revisionType; + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/AddWorkUnit.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/AddWorkUnit.java index 2650661ae7..e36a021665 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/AddWorkUnit.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/AddWorkUnit.java @@ -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 @@ -38,63 +38,77 @@ import org.hibernate.persister.entity.EntityPersister; * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public class AddWorkUnit extends AbstractAuditWorkUnit implements AuditWorkUnit { - private final Object[] state; - private final Map data; + private final Object[] state; + private final Map data; - public AddWorkUnit(SessionImplementor sessionImplementor, String entityName, AuditConfiguration verCfg, - Serializable id, EntityPersister entityPersister, Object[] state) { - super(sessionImplementor, entityName, verCfg, id, RevisionType.ADD); + public AddWorkUnit( + SessionImplementor sessionImplementor, String entityName, AuditConfiguration verCfg, + Serializable id, EntityPersister entityPersister, Object[] state) { + super( sessionImplementor, entityName, verCfg, id, RevisionType.ADD ); - this.data = new HashMap(); - this.state = state; - this.verCfg.getEntCfg().get(getEntityName()).getPropertyMapper().map(sessionImplementor, data, - entityPersister.getPropertyNames(), state, null); - } + this.data = new HashMap(); + this.state = state; + this.verCfg.getEntCfg().get( getEntityName() ).getPropertyMapper().map( + sessionImplementor, data, + entityPersister.getPropertyNames(), state, null + ); + } - public AddWorkUnit(SessionImplementor sessionImplementor, String entityName, AuditConfiguration verCfg, - Serializable id, Map data) { - super(sessionImplementor, entityName, verCfg, id, RevisionType.ADD); + public AddWorkUnit( + SessionImplementor sessionImplementor, String entityName, AuditConfiguration verCfg, + Serializable id, Map data) { + super( sessionImplementor, entityName, verCfg, id, RevisionType.ADD ); - this.data = data; - final String[] propertyNames = sessionImplementor.getFactory().getEntityPersister(getEntityName()).getPropertyNames(); - this.state = ArraysTools.mapToArray(data, propertyNames); - } + this.data = data; + final String[] propertyNames = sessionImplementor.getFactory() + .getEntityPersister( getEntityName() ) + .getPropertyNames(); + this.state = ArraysTools.mapToArray( data, propertyNames ); + } - public boolean containsWork() { - return true; - } + @Override + public boolean containsWork() { + return true; + } - public Map generateData(Object revisionData) { - fillDataWithId(data, revisionData); - return data; - } + @Override + public Map generateData(Object revisionData) { + fillDataWithId( data, revisionData ); + return data; + } - public Object[] getState() { - return state; - } + public Object[] getState() { + return state; + } - public AuditWorkUnit merge(AddWorkUnit second) { - return second; - } + @Override + public AuditWorkUnit merge(AddWorkUnit second) { + return second; + } - public AuditWorkUnit merge(ModWorkUnit second) { - return new AddWorkUnit(sessionImplementor, entityName, verCfg, id, second.getData()); - } + @Override + public AuditWorkUnit merge(ModWorkUnit second) { + return new AddWorkUnit( sessionImplementor, entityName, verCfg, id, second.getData() ); + } - public AuditWorkUnit merge(DelWorkUnit second) { - return null; - } + @Override + public AuditWorkUnit merge(DelWorkUnit second) { + return null; + } - public AuditWorkUnit merge(CollectionChangeWorkUnit second) { - second.mergeCollectionModifiedData(data); + @Override + public AuditWorkUnit merge(CollectionChangeWorkUnit second) { + second.mergeCollectionModifiedData( data ); return this; } - public AuditWorkUnit merge(FakeBidirectionalRelationWorkUnit second) { - return FakeBidirectionalRelationWorkUnit.merge(second, this, second.getNestedWorkUnit()); - } + @Override + public AuditWorkUnit merge(FakeBidirectionalRelationWorkUnit second) { + return FakeBidirectionalRelationWorkUnit.merge( second, this, second.getNestedWorkUnit() ); + } - public AuditWorkUnit dispatch(WorkUnitMergeVisitor first) { - return first.merge(this); - } + @Override + public AuditWorkUnit dispatch(WorkUnitMergeVisitor first) { + return first.merge( this ); + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/AuditWorkUnit.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/AuditWorkUnit.java index f247f21bee..1912b51353 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/AuditWorkUnit.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/AuditWorkUnit.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.internal.synchronization.work; + import java.io.Serializable; import java.util.Map; @@ -30,34 +31,39 @@ import org.hibernate.envers.RevisionType; /** * TODO: refactor constructors into factory methods + * * @author Adam Warski (adam at warski dot org) */ public interface AuditWorkUnit extends WorkUnitMergeVisitor, WorkUnitMergeDispatcher { - Serializable getEntityId(); - String getEntityName(); - - boolean containsWork(); + Serializable getEntityId(); - boolean isPerformed(); + String getEntityName(); - /** - * Perform this work unit in the given session. - * @param session Session, in which the work unit should be performed. - * @param revisionData The current revision data, which will be used to populate the work unit with the correct - * revision relation. - */ - void perform(Session session, Object revisionData); - void undo(Session session); + boolean containsWork(); - /** - * @param revisionData The current revision data, which will be used to populate the work unit with the correct - * revision relation. - * @return Generates data that should be saved when performing this work unit. - */ - Map generateData(Object revisionData); + boolean isPerformed(); - /** - * @return Performed modification type. - */ - RevisionType getRevisionType(); + /** + * Perform this work unit in the given session. + * + * @param session Session, in which the work unit should be performed. + * @param revisionData The current revision data, which will be used to populate the work unit with the correct + * revision relation. + */ + void perform(Session session, Object revisionData); + + void undo(Session session); + + /** + * @param revisionData The current revision data, which will be used to populate the work unit with the correct + * revision relation. + * + * @return Generates data that should be saved when performing this work unit. + */ + Map generateData(Object revisionData); + + /** + * @return Performed modification type. + */ + RevisionType getRevisionType(); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/CollectionChangeWorkUnit.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/CollectionChangeWorkUnit.java index eb06f1f8c1..3bc9cb0aed 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/CollectionChangeWorkUnit.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/CollectionChangeWorkUnit.java @@ -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 @@ -36,64 +36,74 @@ import org.hibernate.envers.configuration.spi.AuditConfiguration; * @author Michal Skowronek (mskowr at o2 dot pl) */ public class CollectionChangeWorkUnit extends AbstractAuditWorkUnit implements AuditWorkUnit { - private Object entity; + private Object entity; private final String collectionPropertyName; private final Map data = new HashMap(); - public CollectionChangeWorkUnit(SessionImplementor session, String entityName, String collectionPropertyName, - AuditConfiguration verCfg, Serializable id, Object entity) { - super(session, entityName, verCfg, id, RevisionType.MOD); + public CollectionChangeWorkUnit( + SessionImplementor session, String entityName, String collectionPropertyName, + AuditConfiguration verCfg, Serializable id, Object entity) { + super( session, entityName, verCfg, id, RevisionType.MOD ); - this.entity = entity; + this.entity = entity; this.collectionPropertyName = collectionPropertyName; - } - - public boolean containsWork() { - return true; - } - - public Map generateData(Object revisionData) { - fillDataWithId(data, revisionData); - Map preGenerateData = new HashMap(data); - verCfg.getEntCfg().get(getEntityName()).getPropertyMapper() - .mapToMapFromEntity(sessionImplementor, data, entity, null); - verCfg.getEntCfg().get(getEntityName()).getPropertyMapper() - .mapModifiedFlagsToMapFromEntity(sessionImplementor, data, entity, entity); - verCfg.getEntCfg().get(getEntityName()).getPropertyMapper() - .mapModifiedFlagsToMapForCollectionChange(collectionPropertyName, data); - data.putAll(preGenerateData); - return data; - } - - public void mergeCollectionModifiedData(Map data) { - verCfg.getEntCfg().get(getEntityName()).getPropertyMapper() - .mapModifiedFlagsToMapForCollectionChange( - collectionPropertyName, data); } + @Override + public boolean containsWork() { + return true; + } + + @Override + public Map generateData(Object revisionData) { + fillDataWithId( data, revisionData ); + final Map preGenerateData = new HashMap( data ); + verCfg.getEntCfg().get( getEntityName() ).getPropertyMapper() + .mapToMapFromEntity( sessionImplementor, data, entity, null ); + verCfg.getEntCfg().get( getEntityName() ).getPropertyMapper() + .mapModifiedFlagsToMapFromEntity( sessionImplementor, data, entity, entity ); + verCfg.getEntCfg().get( getEntityName() ).getPropertyMapper() + .mapModifiedFlagsToMapForCollectionChange( collectionPropertyName, data ); + data.putAll( preGenerateData ); + return data; + } + + public void mergeCollectionModifiedData(Map data) { + verCfg.getEntCfg().get( getEntityName() ).getPropertyMapper().mapModifiedFlagsToMapForCollectionChange( + collectionPropertyName, + data + ); + } + + @Override public AuditWorkUnit merge(AddWorkUnit second) { - return second; - } + return second; + } - public AuditWorkUnit merge(ModWorkUnit second) { - mergeCollectionModifiedData(second.getData()); - return second; - } + @Override + public AuditWorkUnit merge(ModWorkUnit second) { + mergeCollectionModifiedData( second.getData() ); + return second; + } - public AuditWorkUnit merge(DelWorkUnit second) { - return second; - } + @Override + public AuditWorkUnit merge(DelWorkUnit second) { + return second; + } - public AuditWorkUnit merge(CollectionChangeWorkUnit second) { - second.mergeCollectionModifiedData(data); - return this; - } + @Override + public AuditWorkUnit merge(CollectionChangeWorkUnit second) { + second.mergeCollectionModifiedData( data ); + return this; + } - public AuditWorkUnit merge(FakeBidirectionalRelationWorkUnit second) { - return second; - } + @Override + public AuditWorkUnit merge(FakeBidirectionalRelationWorkUnit second) { + return second; + } - public AuditWorkUnit dispatch(WorkUnitMergeVisitor first) { - return first.merge(this); - } + @Override + public AuditWorkUnit dispatch(WorkUnitMergeVisitor first) { + return first.merge( this ); + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/DelWorkUnit.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/DelWorkUnit.java index 2f131f8375..04902e3477 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/DelWorkUnit.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/DelWorkUnit.java @@ -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 @@ -38,62 +38,83 @@ import org.hibernate.persister.entity.EntityPersister; * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public class DelWorkUnit extends AbstractAuditWorkUnit implements AuditWorkUnit { - private final Object[] state; - private final EntityPersister entityPersister; - private final String[] propertyNames; + private final Object[] state; + private final EntityPersister entityPersister; + private final String[] propertyNames; - public DelWorkUnit(SessionImplementor sessionImplementor, String entityName, AuditConfiguration verCfg, - Serializable id, EntityPersister entityPersister, Object[] state) { - super(sessionImplementor, entityName, verCfg, id, RevisionType.DEL); + public DelWorkUnit( + SessionImplementor sessionImplementor, String entityName, AuditConfiguration verCfg, + Serializable id, EntityPersister entityPersister, Object[] state) { + super( sessionImplementor, entityName, verCfg, id, RevisionType.DEL ); - this.state = state; - this.entityPersister = entityPersister; - this.propertyNames = entityPersister.getPropertyNames(); - } + this.state = state; + this.entityPersister = entityPersister; + this.propertyNames = entityPersister.getPropertyNames(); + } - public boolean containsWork() { - return true; - } + @Override + public boolean containsWork() { + return true; + } - public Map generateData(Object revisionData) { - Map data = new HashMap(); - fillDataWithId(data, revisionData); + @Override + public Map generateData(Object revisionData) { + final Map data = new HashMap(); + fillDataWithId( data, revisionData ); - if (verCfg.getGlobalCfg().isStoreDataAtDelete()) { - verCfg.getEntCfg().get(getEntityName()).getPropertyMapper().map(sessionImplementor, data, - propertyNames, state, state); - } else { - verCfg.getEntCfg().get(getEntityName()).getPropertyMapper().map(sessionImplementor, data, - propertyNames, null, state); + if ( verCfg.getGlobalCfg().isStoreDataAtDelete() ) { + verCfg.getEntCfg().get( getEntityName() ).getPropertyMapper().map( + sessionImplementor, + data, + propertyNames, + state, + state + ); + } + else { + verCfg.getEntCfg().get( getEntityName() ).getPropertyMapper().map( + sessionImplementor, + data, + propertyNames, + null, + state + ); } - return data; - } + return data; + } - public AuditWorkUnit merge(AddWorkUnit second) { - if (ArraysTools.arraysEqual(second.getState(), state)) { - return null; // Return null if object's state has not changed. - } - return new ModWorkUnit(sessionImplementor, entityName, verCfg, id, entityPersister, second.getState(), state); - } + @Override + public AuditWorkUnit merge(AddWorkUnit second) { + if ( ArraysTools.arraysEqual( second.getState(), state ) ) { + // Return null if object's state has not changed. + return null; + } + return new ModWorkUnit( sessionImplementor, entityName, verCfg, id, entityPersister, second.getState(), state ); + } - public AuditWorkUnit merge(ModWorkUnit second) { - return null; - } + @Override + public AuditWorkUnit merge(ModWorkUnit second) { + return null; + } - public AuditWorkUnit merge(DelWorkUnit second) { - return this; - } + @Override + public AuditWorkUnit merge(DelWorkUnit second) { + return this; + } - public AuditWorkUnit merge(CollectionChangeWorkUnit second) { - return this; - } + @Override + public AuditWorkUnit merge(CollectionChangeWorkUnit second) { + return this; + } - public AuditWorkUnit merge(FakeBidirectionalRelationWorkUnit second) { - return this; - } + @Override + public AuditWorkUnit merge(FakeBidirectionalRelationWorkUnit second) { + return this; + } - public AuditWorkUnit dispatch(WorkUnitMergeVisitor first) { - return first.merge(this); - } + @Override + public AuditWorkUnit dispatch(WorkUnitMergeVisitor first) { + return first.merge( this ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/FakeBidirectionalRelationWorkUnit.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/FakeBidirectionalRelationWorkUnit.java index f5c5f58e3d..2a915c8bbf 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/FakeBidirectionalRelationWorkUnit.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/FakeBidirectionalRelationWorkUnit.java @@ -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.internal.synchronization.work; + import java.io.Serializable; import java.util.HashMap; import java.util.HashSet; @@ -13,174 +37,211 @@ import org.hibernate.envers.internal.entities.RelationDescription; /** * A work unit that handles "fake" bidirectional one-to-many relations (mapped with {@code @OneToMany+@JoinColumn} and * {@code @ManyToOne+@Column(insertable=false, updatable=false)}. + * * @author Adam Warski (adam at warski dot org) */ public class FakeBidirectionalRelationWorkUnit extends AbstractAuditWorkUnit implements AuditWorkUnit { - private final Map fakeRelationChanges; + private final Map fakeRelationChanges; - /* - * The work unit responsible for generating the "raw" entity data to be saved. - */ - private final AuditWorkUnit nestedWorkUnit; + /* + * The work unit responsible for generating the "raw" entity data to be saved. + */ + private final AuditWorkUnit nestedWorkUnit; - public FakeBidirectionalRelationWorkUnit(SessionImplementor sessionImplementor, String entityName, - AuditConfiguration verCfg, Serializable id, - String referencingPropertyName, Object owningEntity, - RelationDescription rd, RevisionType revisionType, - Object index, - AuditWorkUnit nestedWorkUnit) { - super(sessionImplementor, entityName, verCfg, id, revisionType); - this.nestedWorkUnit = nestedWorkUnit; + public FakeBidirectionalRelationWorkUnit( + SessionImplementor sessionImplementor, String entityName, + AuditConfiguration verCfg, Serializable id, + String referencingPropertyName, Object owningEntity, + RelationDescription rd, RevisionType revisionType, + Object index, + AuditWorkUnit nestedWorkUnit) { + super( sessionImplementor, entityName, verCfg, id, revisionType ); + this.nestedWorkUnit = nestedWorkUnit; - // Adding the change for the relation. - fakeRelationChanges = new HashMap(); - fakeRelationChanges.put(referencingPropertyName, new FakeRelationChange(owningEntity, rd, revisionType, index)); - } + // Adding the change for the relation. + fakeRelationChanges = new HashMap(); + fakeRelationChanges.put( + referencingPropertyName, new FakeRelationChange( + owningEntity, + rd, + revisionType, + index + ) + ); + } - public FakeBidirectionalRelationWorkUnit(FakeBidirectionalRelationWorkUnit original, - Map fakeRelationChanges, - AuditWorkUnit nestedWorkUnit) { - super(original.sessionImplementor, original.entityName, original.verCfg, original.id, original.revisionType); + public FakeBidirectionalRelationWorkUnit( + FakeBidirectionalRelationWorkUnit original, + Map fakeRelationChanges, + AuditWorkUnit nestedWorkUnit) { + super( original.sessionImplementor, original.entityName, original.verCfg, original.id, original.revisionType ); - this.fakeRelationChanges = fakeRelationChanges; - this.nestedWorkUnit = nestedWorkUnit; - } + this.fakeRelationChanges = fakeRelationChanges; + this.nestedWorkUnit = nestedWorkUnit; + } - public FakeBidirectionalRelationWorkUnit(FakeBidirectionalRelationWorkUnit original, AuditWorkUnit nestedWorkUnit) { - super(original.sessionImplementor, original.entityName, original.verCfg, original.id, original.revisionType); + public FakeBidirectionalRelationWorkUnit(FakeBidirectionalRelationWorkUnit original, AuditWorkUnit nestedWorkUnit) { + super( original.sessionImplementor, original.entityName, original.verCfg, original.id, original.revisionType ); - this.nestedWorkUnit = nestedWorkUnit; + this.nestedWorkUnit = nestedWorkUnit; - fakeRelationChanges = new HashMap(original.getFakeRelationChanges()); - } + fakeRelationChanges = new HashMap( original.getFakeRelationChanges() ); + } - public AuditWorkUnit getNestedWorkUnit() { - return nestedWorkUnit; - } + public AuditWorkUnit getNestedWorkUnit() { + return nestedWorkUnit; + } - public Map getFakeRelationChanges() { - return fakeRelationChanges; - } + public Map getFakeRelationChanges() { + return fakeRelationChanges; + } - public boolean containsWork() { - return true; - } + @Override + public boolean containsWork() { + return true; + } - public Map generateData(Object revisionData) { - // Generating data with the nested work unit. This data contains all data except the fake relation. - // Making a defensive copy not to modify the data held by the nested work unit. - Map nestedData = new HashMap(nestedWorkUnit.generateData(revisionData)); + @Override + public Map generateData(Object revisionData) { + // Generating data with the nested work unit. This data contains all data except the fake relation. + // Making a defensive copy not to modify the data held by the nested work unit. + final Map nestedData = new HashMap( nestedWorkUnit.generateData( revisionData ) ); - // Now adding data for all fake relations. - for (FakeRelationChange fakeRelationChange : fakeRelationChanges.values()) { - fakeRelationChange.generateData(sessionImplementor, nestedData); - } + // Now adding data for all fake relations. + for ( FakeRelationChange fakeRelationChange : fakeRelationChanges.values() ) { + fakeRelationChange.generateData( sessionImplementor, nestedData ); + } - return nestedData; - } + return nestedData; + } - public AuditWorkUnit merge(AddWorkUnit second) { - return merge(this, nestedWorkUnit, second); - } + @Override + public AuditWorkUnit merge(AddWorkUnit second) { + return merge( this, nestedWorkUnit, second ); + } - public AuditWorkUnit merge(ModWorkUnit second) { - return merge(this, nestedWorkUnit, second); - } + @Override + public AuditWorkUnit merge(ModWorkUnit second) { + return merge( this, nestedWorkUnit, second ); + } - public AuditWorkUnit merge(DelWorkUnit second) { - return second; - } + @Override + public AuditWorkUnit merge(DelWorkUnit second) { + return second; + } - public AuditWorkUnit merge(CollectionChangeWorkUnit second) { - return this; - } + @Override + public AuditWorkUnit merge(CollectionChangeWorkUnit second) { + return this; + } - public AuditWorkUnit merge(FakeBidirectionalRelationWorkUnit second) { - // First merging the nested work units. - AuditWorkUnit mergedNested = second.getNestedWorkUnit().dispatch(nestedWorkUnit); + @Override + public AuditWorkUnit merge(FakeBidirectionalRelationWorkUnit second) { + // First merging the nested work units. + final AuditWorkUnit mergedNested = second.getNestedWorkUnit().dispatch( nestedWorkUnit ); - // Now merging the fake relation changes from both work units. - Map secondFakeRelationChanges = second.getFakeRelationChanges(); - Map mergedFakeRelationChanges = new HashMap(); - Set allPropertyNames = new HashSet(fakeRelationChanges.keySet()); - allPropertyNames.addAll(secondFakeRelationChanges.keySet()); + // Now merging the fake relation changes from both work units. + final Map secondFakeRelationChanges = second.getFakeRelationChanges(); + final Map mergedFakeRelationChanges = new HashMap(); + final Set allPropertyNames = new HashSet( fakeRelationChanges.keySet() ); + allPropertyNames.addAll( secondFakeRelationChanges.keySet() ); - for (String propertyName : allPropertyNames) { - mergedFakeRelationChanges.put(propertyName, - FakeRelationChange.merge( - fakeRelationChanges.get(propertyName), - secondFakeRelationChanges.get(propertyName))); - } + for ( String propertyName : allPropertyNames ) { + mergedFakeRelationChanges.put( + propertyName, + FakeRelationChange.merge( + fakeRelationChanges.get( propertyName ), + secondFakeRelationChanges.get( propertyName ) + ) + ); + } - return new FakeBidirectionalRelationWorkUnit(this, mergedFakeRelationChanges, mergedNested); - } + return new FakeBidirectionalRelationWorkUnit( this, mergedFakeRelationChanges, mergedNested ); + } - public AuditWorkUnit dispatch(WorkUnitMergeVisitor first) { - return first.merge(this); - } + @Override + public AuditWorkUnit dispatch(WorkUnitMergeVisitor first) { + return first.merge( this ); + } - public static AuditWorkUnit merge(FakeBidirectionalRelationWorkUnit frwu, AuditWorkUnit nestedFirst, - AuditWorkUnit nestedSecond) { - AuditWorkUnit nestedMerged = nestedSecond.dispatch(nestedFirst); + public static AuditWorkUnit merge( + FakeBidirectionalRelationWorkUnit frwu, + AuditWorkUnit nestedFirst, + AuditWorkUnit nestedSecond) { + final AuditWorkUnit nestedMerged = nestedSecond.dispatch( nestedFirst ); - // Creating a new fake relation work unit with the nested merged data - return new FakeBidirectionalRelationWorkUnit(frwu, nestedMerged); - } + // Creating a new fake relation work unit with the nested merged data + return new FakeBidirectionalRelationWorkUnit( frwu, nestedMerged ); + } - /** - * Describes a change to a single fake bidirectional relation. - */ - private static class FakeRelationChange { - private final Object owningEntity; - private final RelationDescription rd; - private final RevisionType revisionType; - private final Object index; + /** + * Describes a change to a single fake bidirectional relation. + */ + private static class FakeRelationChange { + private final Object owningEntity; + private final RelationDescription rd; + private final RevisionType revisionType; + private final Object index; - public FakeRelationChange(Object owningEntity, RelationDescription rd, RevisionType revisionType, - Object index) { - this.owningEntity = owningEntity; - this.rd = rd; - this.revisionType = revisionType; - this.index = index; - } + public FakeRelationChange( + Object owningEntity, RelationDescription rd, RevisionType revisionType, + Object index) { + this.owningEntity = owningEntity; + this.rd = rd; + this.revisionType = revisionType; + this.index = index; + } - public RevisionType getRevisionType() { - return revisionType; - } + public RevisionType getRevisionType() { + return revisionType; + } - public void generateData(SessionImplementor sessionImplementor, Map data) { - // If the revision type is "DEL", it means that the object is removed from the collection. Then the - // new owner will in fact be null. - rd.getFakeBidirectionalRelationMapper().mapToMapFromEntity(sessionImplementor, data, - revisionType == RevisionType.DEL ? null : owningEntity, null); - rd.getFakeBidirectionalRelationMapper().mapModifiedFlagsToMapFromEntity(sessionImplementor, data, - revisionType == RevisionType.DEL ? null : owningEntity, null); + public void generateData(SessionImplementor sessionImplementor, Map data) { + // If the revision type is "DEL", it means that the object is removed from the collection. Then the + // new owner will in fact be null. + rd.getFakeBidirectionalRelationMapper().mapToMapFromEntity( + sessionImplementor, data, + revisionType == RevisionType.DEL ? null : owningEntity, null + ); + rd.getFakeBidirectionalRelationMapper().mapModifiedFlagsToMapFromEntity( + sessionImplementor, data, + revisionType == RevisionType.DEL ? null : owningEntity, null + ); // Also mapping the index, if the collection is indexed. - if (rd.getFakeBidirectionalRelationIndexMapper() != null) { - rd.getFakeBidirectionalRelationIndexMapper().mapToMapFromEntity(sessionImplementor, data, - revisionType == RevisionType.DEL ? null : index, null); - rd.getFakeBidirectionalRelationIndexMapper().mapModifiedFlagsToMapFromEntity(sessionImplementor, data, - revisionType == RevisionType.DEL ? null : index, null); - } - } + if ( rd.getFakeBidirectionalRelationIndexMapper() != null ) { + rd.getFakeBidirectionalRelationIndexMapper().mapToMapFromEntity( + sessionImplementor, data, + revisionType == RevisionType.DEL ? null : index, null + ); + rd.getFakeBidirectionalRelationIndexMapper().mapModifiedFlagsToMapFromEntity( + sessionImplementor, data, + revisionType == RevisionType.DEL ? null : index, null + ); + } + } - public static FakeRelationChange merge(FakeRelationChange first, FakeRelationChange second) { - if (first == null) { return second; } - if (second == null) { return first; } + public static FakeRelationChange merge(FakeRelationChange first, FakeRelationChange second) { + if ( first == null ) { + return second; + } + if ( second == null ) { + return first; + } /* - * The merging rules are the following (revision types of the first and second changes): + * The merging rules are the following (revision types of the first and second changes): * - DEL, DEL - return any (the work units are the same) * - DEL, ADD - return ADD (points to new owner) * - ADD, DEL - return ADD (points to new owner) * - ADD, ADD - return second (points to newer owner) */ - if (first.getRevisionType() == RevisionType.DEL || second.getRevisionType() == RevisionType.ADD) { - return second; - } else { - return first; - } - } - } + if ( first.getRevisionType() == RevisionType.DEL || second.getRevisionType() == RevisionType.ADD ) { + return second; + } + else { + return first; + } + } + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/ModWorkUnit.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/ModWorkUnit.java index 77129d9c6a..c8c2f7731c 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/ModWorkUnit.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/ModWorkUnit.java @@ -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 @@ -36,66 +36,77 @@ import org.hibernate.persister.entity.EntityPersister; * @author Adam Warski (adam at warski dot org) */ public class ModWorkUnit extends AbstractAuditWorkUnit implements AuditWorkUnit { - private final Map data; - private final boolean changes; + private final Map data; + private final boolean changes; - private final EntityPersister entityPersister; - private final Object[] oldState; - private final Object[] newState; + private final EntityPersister entityPersister; + private final Object[] oldState; + private final Object[] newState; - public ModWorkUnit(SessionImplementor sessionImplementor, String entityName, AuditConfiguration verCfg, - Serializable id, EntityPersister entityPersister, Object[] newState, Object[] oldState) { - super(sessionImplementor, entityName, verCfg, id, RevisionType.MOD); + public ModWorkUnit( + SessionImplementor sessionImplementor, String entityName, AuditConfiguration verCfg, + Serializable id, EntityPersister entityPersister, Object[] newState, Object[] oldState) { + super( sessionImplementor, entityName, verCfg, id, RevisionType.MOD ); - this.entityPersister = entityPersister; - this.oldState = oldState; - this.newState = newState; - data = new HashMap(); - changes = verCfg.getEntCfg().get(getEntityName()).getPropertyMapper().map(sessionImplementor, data, - entityPersister.getPropertyNames(), newState, oldState); - } + this.entityPersister = entityPersister; + this.oldState = oldState; + this.newState = newState; + data = new HashMap(); + changes = verCfg.getEntCfg().get( getEntityName() ).getPropertyMapper().map( + sessionImplementor, data, + entityPersister.getPropertyNames(), newState, oldState + ); + } - public boolean containsWork() { - return changes; - } + public Map getData() { + return data; + } - public Map generateData(Object revisionData) { - fillDataWithId(data, revisionData); + @Override + public boolean containsWork() { + return changes; + } - return data; - } + @Override + public Map generateData(Object revisionData) { + fillDataWithId( data, revisionData ); - public Map getData() { - return data; - } + return data; + } - public AuditWorkUnit merge(AddWorkUnit second) { - return this; - } + @Override + public AuditWorkUnit merge(AddWorkUnit second) { + return this; + } - public AuditWorkUnit merge(ModWorkUnit second) { - // In case of multiple subsequent flushes within single transaction, modification flags need to be - // recalculated against initial and final state of the given entity. - return new ModWorkUnit( - second.sessionImplementor, second.getEntityName(), second.verCfg, second.id, - second.entityPersister, second.newState, this.oldState - ); - } + @Override + public AuditWorkUnit merge(ModWorkUnit second) { + // In case of multiple subsequent flushes within single transaction, modification flags need to be + // recalculated against initial and final state of the given entity. + return new ModWorkUnit( + second.sessionImplementor, second.getEntityName(), second.verCfg, second.id, + second.entityPersister, second.newState, this.oldState + ); + } - public AuditWorkUnit merge(DelWorkUnit second) { - return second; - } + @Override + public AuditWorkUnit merge(DelWorkUnit second) { + return second; + } - public AuditWorkUnit merge(CollectionChangeWorkUnit second) { - second.mergeCollectionModifiedData(data); - return this; - } + @Override + public AuditWorkUnit merge(CollectionChangeWorkUnit second) { + second.mergeCollectionModifiedData( data ); + return this; + } - public AuditWorkUnit merge(FakeBidirectionalRelationWorkUnit second) { - return FakeBidirectionalRelationWorkUnit.merge(second, this, second.getNestedWorkUnit()); - } + @Override + public AuditWorkUnit merge(FakeBidirectionalRelationWorkUnit second) { + return FakeBidirectionalRelationWorkUnit.merge( second, this, second.getNestedWorkUnit() ); + } - public AuditWorkUnit dispatch(WorkUnitMergeVisitor first) { - return first.merge(this); - } + @Override + public AuditWorkUnit dispatch(WorkUnitMergeVisitor first) { + return first.merge( this ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/PersistentCollectionChangeWorkUnit.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/PersistentCollectionChangeWorkUnit.java index 6f87f1d19b..73a9125c72 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/PersistentCollectionChangeWorkUnit.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/PersistentCollectionChangeWorkUnit.java @@ -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 @@ -42,171 +42,212 @@ import org.hibernate.envers.internal.entities.mapper.PersistentCollectionChangeD * @author Adam Warski (adam at warski dot org) */ public class PersistentCollectionChangeWorkUnit extends AbstractAuditWorkUnit implements AuditWorkUnit { - private final List collectionChanges; - private final String referencingPropertyName; + private final List collectionChanges; + private final String referencingPropertyName; - public PersistentCollectionChangeWorkUnit(SessionImplementor sessionImplementor, String entityName, - AuditConfiguration auditCfg, PersistentCollection collection, - CollectionEntry collectionEntry, Serializable snapshot, Serializable id, - String referencingPropertyName) { - super(sessionImplementor, entityName, auditCfg, new PersistentCollectionChangeWorkUnitId(id, collectionEntry.getRole()), RevisionType.MOD); + public PersistentCollectionChangeWorkUnit( + SessionImplementor sessionImplementor, String entityName, + AuditConfiguration auditCfg, PersistentCollection collection, + CollectionEntry collectionEntry, Serializable snapshot, Serializable id, + String referencingPropertyName) { + super( + sessionImplementor, entityName, auditCfg, new PersistentCollectionChangeWorkUnitId( + id, + collectionEntry.getRole() + ), RevisionType.MOD + ); this.referencingPropertyName = referencingPropertyName; - collectionChanges = auditCfg.getEntCfg().get(getEntityName()).getPropertyMapper() - .mapCollectionChanges(sessionImplementor, referencingPropertyName, collection, snapshot, id); - } + collectionChanges = auditCfg.getEntCfg().get( getEntityName() ).getPropertyMapper() + .mapCollectionChanges( sessionImplementor, referencingPropertyName, collection, snapshot, id ); + } - public PersistentCollectionChangeWorkUnit(SessionImplementor sessionImplementor, String entityName, - AuditConfiguration verCfg, Serializable id, - List collectionChanges, - String referencingPropertyName) { - super(sessionImplementor, entityName, verCfg, id, RevisionType.MOD); + public PersistentCollectionChangeWorkUnit( + SessionImplementor sessionImplementor, String entityName, + AuditConfiguration verCfg, Serializable id, + List collectionChanges, + String referencingPropertyName) { + super( sessionImplementor, entityName, verCfg, id, RevisionType.MOD ); - this.collectionChanges = collectionChanges; - this.referencingPropertyName = referencingPropertyName; - } + this.collectionChanges = collectionChanges; + this.referencingPropertyName = referencingPropertyName; + } - public boolean containsWork() { - return collectionChanges != null && collectionChanges.size() != 0; - } + @Override + public boolean containsWork() { + return collectionChanges != null && collectionChanges.size() != 0; + } - public Map generateData(Object revisionData) { - throw new UnsupportedOperationException("Cannot generate data for a collection change work unit!"); - } + @Override + public Map generateData(Object revisionData) { + throw new UnsupportedOperationException( "Cannot generate data for a collection change work unit!" ); + } - @SuppressWarnings({"unchecked"}) - public void perform(Session session, Object revisionData) { - AuditEntitiesConfiguration entitiesCfg = verCfg.getAuditEntCfg(); + @Override + @SuppressWarnings({"unchecked"}) + public void perform(Session session, Object revisionData) { + final AuditEntitiesConfiguration entitiesCfg = verCfg.getAuditEntCfg(); - for (PersistentCollectionChangeData persistentCollectionChangeData : collectionChanges) { - // Setting the revision number - ((Map) persistentCollectionChangeData.getData().get(entitiesCfg.getOriginalIdPropName())) - .put(entitiesCfg.getRevisionFieldName(), revisionData); + for ( PersistentCollectionChangeData persistentCollectionChangeData : collectionChanges ) { + // Setting the revision number + ((Map) persistentCollectionChangeData.getData().get( entitiesCfg.getOriginalIdPropName() )) + .put( entitiesCfg.getRevisionFieldName(), revisionData ); - auditStrategy.performCollectionChange(session, getEntityName(), referencingPropertyName, verCfg, persistentCollectionChangeData, revisionData); - } - } + auditStrategy.performCollectionChange( + session, + getEntityName(), + referencingPropertyName, + verCfg, + persistentCollectionChangeData, + revisionData + ); + } + } - public String getReferencingPropertyName() { - return referencingPropertyName; - } + public String getReferencingPropertyName() { + return referencingPropertyName; + } - public List getCollectionChanges() { - return collectionChanges; - } + public List getCollectionChanges() { + return collectionChanges; + } - public AuditWorkUnit merge(AddWorkUnit second) { - return null; - } + @Override + public AuditWorkUnit merge(AddWorkUnit second) { + return null; + } - public AuditWorkUnit merge(ModWorkUnit second) { - return null; - } + @Override + public AuditWorkUnit merge(ModWorkUnit second) { + return null; + } - public AuditWorkUnit merge(DelWorkUnit second) { - return null; - } + @Override + public AuditWorkUnit merge(DelWorkUnit second) { + return null; + } - public AuditWorkUnit merge(CollectionChangeWorkUnit second) { - return null; - } + @Override + public AuditWorkUnit merge(CollectionChangeWorkUnit second) { + return null; + } - public AuditWorkUnit merge(FakeBidirectionalRelationWorkUnit second) { - return null; - } + @Override + public AuditWorkUnit merge(FakeBidirectionalRelationWorkUnit second) { + return null; + } - public AuditWorkUnit dispatch(WorkUnitMergeVisitor first) { - if (first instanceof PersistentCollectionChangeWorkUnit) { - PersistentCollectionChangeWorkUnit original = (PersistentCollectionChangeWorkUnit) first; + @Override + public AuditWorkUnit dispatch(WorkUnitMergeVisitor first) { + if ( first instanceof PersistentCollectionChangeWorkUnit ) { + final PersistentCollectionChangeWorkUnit original = (PersistentCollectionChangeWorkUnit) first; - // Merging the collection changes in both work units. + // Merging the collection changes in both work units. - // First building a map from the ids of the collection-entry-entities from the "second" collection changes, - // to the PCCD objects. That way, we will be later able to check if an "original" collection change - // should be added, or if it is overshadowed by a new one. - Map newChangesIdMap = new HashMap(); - for (PersistentCollectionChangeData persistentCollectionChangeData : getCollectionChanges()) { - newChangesIdMap.put( - getOriginalId(persistentCollectionChangeData), - persistentCollectionChangeData); - } + // First building a map from the ids of the collection-entry-entities from the "second" collection changes, + // to the PCCD objects. That way, we will be later able to check if an "original" collection change + // should be added, or if it is overshadowed by a new one. + final Map newChangesIdMap = new HashMap(); + for ( PersistentCollectionChangeData persistentCollectionChangeData : getCollectionChanges() ) { + newChangesIdMap.put( + getOriginalId( persistentCollectionChangeData ), + persistentCollectionChangeData + ); + } - // This will be the list with the resulting (merged) changes. - List mergedChanges = new ArrayList(); + // This will be the list with the resulting (merged) changes. + final List mergedChanges = new ArrayList(); - // Including only those original changes, which are not overshadowed by new ones. - for (PersistentCollectionChangeData originalCollectionChangeData : original.getCollectionChanges()) { - Object originalOriginalId = getOriginalId(originalCollectionChangeData); - if (!newChangesIdMap.containsKey(originalOriginalId)) { - mergedChanges.add(originalCollectionChangeData); - } else { - // If the changes collide, checking if the first one isn't a DEL, and the second a subsequent ADD - // If so, removing the change alltogether. - String revTypePropName = verCfg.getAuditEntCfg().getRevisionTypePropName(); - if (RevisionType.ADD.equals(newChangesIdMap.get(originalOriginalId).getData().get( - revTypePropName)) && RevisionType.DEL.equals(originalCollectionChangeData.getData().get( - revTypePropName))) { - newChangesIdMap.remove(originalOriginalId); - } - } - } + // Including only those original changes, which are not overshadowed by new ones. + for ( PersistentCollectionChangeData originalCollectionChangeData : original.getCollectionChanges() ) { + final Object originalOriginalId = getOriginalId( originalCollectionChangeData ); + if ( !newChangesIdMap.containsKey( originalOriginalId ) ) { + mergedChanges.add( originalCollectionChangeData ); + } + else { + // If the changes collide, checking if the first one isn't a DEL, and the second a subsequent ADD + // If so, removing the change alltogether. + final String revTypePropName = verCfg.getAuditEntCfg().getRevisionTypePropName(); + if ( RevisionType.ADD.equals( newChangesIdMap.get( originalOriginalId ).getData().get( revTypePropName ) ) + && RevisionType.DEL.equals( originalCollectionChangeData.getData().get( revTypePropName ) ) ) { + newChangesIdMap.remove( originalOriginalId ); + } + } + } - // Finally adding all of the new changes to the end of the list (the map values may differ from - // getCollectionChanges() because of the last operation above). - mergedChanges.addAll(newChangesIdMap.values()); + // Finally adding all of the new changes to the end of the list (the map values may differ from + // getCollectionChanges() because of the last operation above). + mergedChanges.addAll( newChangesIdMap.values() ); - return new PersistentCollectionChangeWorkUnit(sessionImplementor, entityName, verCfg, id, mergedChanges, - referencingPropertyName); - } else { - throw new RuntimeException("Trying to merge a " + first + " with a PersitentCollectionChangeWorkUnit. " + - "This is not really possible."); - } - } + return new PersistentCollectionChangeWorkUnit( + sessionImplementor, + entityName, + verCfg, + id, + mergedChanges, + referencingPropertyName + ); + } + else { + throw new RuntimeException( + "Trying to merge a " + first + " with a PersitentCollectionChangeWorkUnit. " + + "This is not really possible." + ); + } + } - private Object getOriginalId(PersistentCollectionChangeData persistentCollectionChangeData) { - return persistentCollectionChangeData.getData().get(verCfg.getAuditEntCfg().getOriginalIdPropName()); - } + private Object getOriginalId(PersistentCollectionChangeData persistentCollectionChangeData) { + return persistentCollectionChangeData.getData().get( verCfg.getAuditEntCfg().getOriginalIdPropName() ); + } - /** - * A unique identifier for a collection work unit. Consists of an id of the owning entity and the name of - * the entity plus the name of the field (the role). This is needed because such collections aren't entities - * in the "normal" mapping, but they are entities for Envers. - */ - public static class PersistentCollectionChangeWorkUnitId implements Serializable { - private static final long serialVersionUID = -8007831518629167537L; - - private final Serializable ownerId; - private final String role; + /** + * A unique identifier for a collection work unit. Consists of an id of the owning entity and the name of + * the entity plus the name of the field (the role). This is needed because such collections aren't entities + * in the "normal" mapping, but they are entities for Envers. + */ + public static class PersistentCollectionChangeWorkUnitId implements Serializable { + private static final long serialVersionUID = -8007831518629167537L; - public PersistentCollectionChangeWorkUnitId(Serializable ownerId, String role) { - this.ownerId = ownerId; - this.role = role; - } + private final Serializable ownerId; + private final String role; - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + public PersistentCollectionChangeWorkUnitId(Serializable ownerId, String role) { + this.ownerId = ownerId; + this.role = role; + } - PersistentCollectionChangeWorkUnitId that = (PersistentCollectionChangeWorkUnitId) o; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } - if (ownerId != null ? !ownerId.equals(that.ownerId) : that.ownerId != null) return false; - //noinspection RedundantIfStatement - if (role != null ? !role.equals(that.role) : that.role != null) return false; + final PersistentCollectionChangeWorkUnitId that = (PersistentCollectionChangeWorkUnitId) o; - return true; - } + if ( ownerId != null ? !ownerId.equals( that.ownerId ) : that.ownerId != null ) { + return false; + } + //noinspection RedundantIfStatement + if ( role != null ? !role.equals( that.role ) : that.role != null ) { + return false; + } - @Override - public int hashCode() { - int result = ownerId != null ? ownerId.hashCode() : 0; - result = 31 * result + (role != null ? role.hashCode() : 0); - return result; - } + return true; + } - public Serializable getOwnerId() { - return ownerId; - } - } + @Override + public int hashCode() { + int result = ownerId != null ? ownerId.hashCode() : 0; + result = 31 * result + (role != null ? role.hashCode() : 0); + return result; + } + + public Serializable getOwnerId() { + return ownerId; + } + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/WorkUnitMergeDispatcher.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/WorkUnitMergeDispatcher.java index 0359343771..7047bc6c5b 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/WorkUnitMergeDispatcher.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/WorkUnitMergeDispatcher.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 @@ -26,13 +26,16 @@ package org.hibernate.envers.internal.synchronization.work; /** * Visitor patter dispatcher. + * * @author Adam Warski (adam at warski dot org) */ public interface WorkUnitMergeDispatcher { - /** - * Should be invoked on the second work unit. - * @param first First work unit (that is, the one added earlier). - * @return The work unit that is the result of the merge. - */ - AuditWorkUnit dispatch(WorkUnitMergeVisitor first); + /** + * Should be invoked on the second work unit. + * + * @param first First work unit (that is, the one added earlier). + * + * @return The work unit that is the result of the merge. + */ + AuditWorkUnit dispatch(WorkUnitMergeVisitor first); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/WorkUnitMergeVisitor.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/WorkUnitMergeVisitor.java index c47840ed00..9d5acf2af8 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/WorkUnitMergeVisitor.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/synchronization/work/WorkUnitMergeVisitor.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 @@ -26,12 +26,17 @@ package org.hibernate.envers.internal.synchronization.work; /** * Visitor pattern visitor. All methods should be invoked on the first work unit. + * * @author Adam Warski (adam at warski dot org) */ public interface WorkUnitMergeVisitor { - AuditWorkUnit merge(AddWorkUnit second); - AuditWorkUnit merge(ModWorkUnit second); - AuditWorkUnit merge(DelWorkUnit second); - AuditWorkUnit merge(CollectionChangeWorkUnit second); - AuditWorkUnit merge(FakeBidirectionalRelationWorkUnit second); + AuditWorkUnit merge(AddWorkUnit second); + + AuditWorkUnit merge(ModWorkUnit second); + + AuditWorkUnit merge(DelWorkUnit second); + + AuditWorkUnit merge(CollectionChangeWorkUnit second); + + AuditWorkUnit merge(FakeBidirectionalRelationWorkUnit second); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/ArgumentsTools.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/ArgumentsTools.java index d4d50ca54c..8f481b70a0 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/ArgumentsTools.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/ArgumentsTools.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 diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/ArraysTools.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/ArraysTools.java index 8b3e5d4b71..5671ff2af1 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/ArraysTools.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/ArraysTools.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 @@ -56,13 +56,15 @@ public abstract class ArraysTools { /** * Converts map's value set to an array. {@code keys} parameter specifies requested elements and their order. + * * @param data Source map. * @param keys Array of keys that represent requested map values. + * * @return Array of values stored in the map under specified keys. If map does not contain requested key, * {@code null} is inserted. */ public static Object[] mapToArray(Map data, String[] keys) { - Object[] ret = new Object[keys.length]; + final Object[] ret = new Object[keys.length]; for ( int i = 0; i < keys.length; ++i ) { ret[i] = data.get( keys[i] ); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/EntityTools.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/EntityTools.java index f0d36f41d1..25cca6bab4 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/EntityTools.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/EntityTools.java @@ -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.internal.tools; import javassist.util.proxy.ProxyFactory; @@ -13,8 +36,8 @@ import org.hibernate.proxy.HibernateProxy; */ public abstract class EntityTools { public static boolean entitiesEqual(SessionImplementor session, String entityName, Object obj1, Object obj2) { - Object id1 = getIdentifier( session, entityName, obj1 ); - Object id2 = getIdentifier( session, entityName, obj2 ); + final Object id1 = getIdentifier( session, entityName, obj1 ); + final Object id2 = getIdentifier( session, entityName, obj2 ); return Tools.objectsEqual( id1, id2 ); } @@ -25,7 +48,7 @@ public abstract class EntityTools { } if ( obj instanceof HibernateProxy ) { - HibernateProxy hibernateProxy = (HibernateProxy) obj; + final HibernateProxy hibernateProxy = (HibernateProxy) obj; return hibernateProxy.getHibernateLazyInitializer().getIdentifier(); } @@ -37,16 +60,15 @@ public abstract class EntityTools { return proxy.getHibernateLazyInitializer().getImplementation(); } - SessionImplementor sessionImplementor = proxy.getHibernateLazyInitializer().getSession(); - Session tempSession = sessionImplementor == null + final SessionImplementor sessionImplementor = proxy.getHibernateLazyInitializer().getSession(); + final Session tempSession = sessionImplementor == null ? sessionFactoryImplementor.openTemporarySession() : sessionImplementor.getFactory().openTemporarySession(); try { - Object target = tempSession.get( + return tempSession.get( proxy.getHibernateLazyInitializer().getEntityName(), proxy.getHibernateLazyInitializer().getIdentifier() ); - return target; } finally { tempSession.close(); @@ -54,17 +76,18 @@ public abstract class EntityTools { } private static boolean activeProxySession(HibernateProxy proxy) { - Session session = (Session) proxy.getHibernateLazyInitializer().getSession(); + final Session session = (Session) proxy.getHibernateLazyInitializer().getSession(); return session != null && session.isOpen() && session.isConnected(); } /** * @param clazz Class wrapped with a proxy or not. * @param Class type. + * * @return Returns target class in case it has been wrapped with a proxy. If {@code null} reference is passed, * method returns {@code null}. */ - @SuppressWarnings({ "unchecked" }) + @SuppressWarnings({"unchecked"}) public static Class getTargetClassIfProxied(Class clazz) { if ( clazz == null ) { return null; @@ -80,7 +103,7 @@ public abstract class EntityTools { * @return Java class mapped to specified entity name. */ public static Class getEntityClass(SessionImplementor sessionImplementor, Session session, String entityName) { - EntityPersister entityPersister = sessionImplementor.getFactory().getEntityPersister( entityName ); + final EntityPersister entityPersister = sessionImplementor.getFactory().getEntityPersister( entityName ); return entityPersister.getMappedClass(); } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/MappingTools.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/MappingTools.java index 5060e96eb5..d91cbe3364 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/MappingTools.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/MappingTools.java @@ -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.internal.tools; import org.hibernate.mapping.Collection; @@ -29,13 +52,13 @@ public abstract class MappingTools { public static String getReferencedEntityName(Value value) { if ( value instanceof ToOne ) { - return ( (ToOne) value ).getReferencedEntityName(); + return ((ToOne) value).getReferencedEntityName(); } else if ( value instanceof OneToMany ) { - return ( (OneToMany) value ).getReferencedEntityName(); + return ((OneToMany) value).getReferencedEntityName(); } else if ( value instanceof Collection ) { - return getReferencedEntityName( ( (Collection) value ).getElement() ); + return getReferencedEntityName( ((Collection) value).getElement() ); } return null; diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/MutableBoolean.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/MutableBoolean.java index d0db6c9220..614b85e7a0 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/MutableBoolean.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/MutableBoolean.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 @@ -28,24 +28,24 @@ package org.hibernate.envers.internal.tools; * @author Adam Warski (adam at warski dot org) */ public class MutableBoolean { - private boolean value; + private boolean value; - public MutableBoolean() { - } + public MutableBoolean() { + } - public MutableBoolean(boolean value) { - this.value = value; - } + public MutableBoolean(boolean value) { + this.value = value; + } - public boolean isSet() { - return value; - } + public boolean isSet() { + return value; + } - public void set() { - value = true; - } + public void set() { + value = true; + } - public void unset() { - value = false; - } + public void unset() { + value = false; + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/MutableInteger.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/MutableInteger.java index 4b658ba9ad..6b1c79fb21 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/MutableInteger.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/MutableInteger.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 @@ -27,32 +27,32 @@ package org.hibernate.envers.internal.tools; * @author Adam Warski (adam at warski dot org) */ public class MutableInteger { - private int value = 0; + private int value = 0; - public MutableInteger() { - } + public MutableInteger() { + } - public MutableInteger(int value) { - this.value = value; - } + public MutableInteger(int value) { + this.value = value; + } public MutableInteger deepCopy() { return new MutableInteger( value ); } - public int getAndIncrease() { - return value++; - } + public int getAndIncrease() { + return value++; + } - public int get() { - return value; - } + public int get() { + return value; + } - public void set(int value) { - this.value = value; - } + public void set(int value) { + this.value = value; + } - public void increase() { - ++value; - } + public void increase() { + ++value; + } } \ No newline at end of file diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/ReflectionTools.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/ReflectionTools.java index 653013aafe..9db7c3a23d 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/ReflectionTools.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/ReflectionTools.java @@ -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 @@ -44,14 +44,16 @@ import org.hibernate.property.Setter; * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public abstract class ReflectionTools { - private static final Map, Getter> getterCache = - new ConcurrentReferenceHashMap, Getter>( - 10, ConcurrentReferenceHashMap.ReferenceType.SOFT, ConcurrentReferenceHashMap.ReferenceType.SOFT - ); - private static final Map, Setter> setterCache = - new ConcurrentReferenceHashMap, Setter>( - 10, ConcurrentReferenceHashMap.ReferenceType.SOFT, ConcurrentReferenceHashMap.ReferenceType.SOFT - ); + private static final Map, Getter> GETTER_CACHE = new ConcurrentReferenceHashMap, Getter>( + 10, + ConcurrentReferenceHashMap.ReferenceType.SOFT, + ConcurrentReferenceHashMap.ReferenceType.SOFT + ); + private static final Map, Setter> SETTER_CACHE = new ConcurrentReferenceHashMap, Setter>( + 10, + ConcurrentReferenceHashMap.ReferenceType.SOFT, + ConcurrentReferenceHashMap.ReferenceType.SOFT + ); private static PropertyAccessor getAccessor(String accessorType) { return PropertyAccessorFactory.getPropertyAccessor( accessorType ); @@ -62,12 +64,12 @@ public abstract class ReflectionTools { } public static Getter getGetter(Class cls, String propertyName, String accessorType) { - Pair key = Pair.make( cls, propertyName ); - Getter value = getterCache.get( key ); + final Pair key = Pair.make( cls, propertyName ); + Getter value = GETTER_CACHE.get( key ); if ( value == null ) { value = getAccessor( accessorType ).getGetter( cls, propertyName ); // It's ok if two getters are generated concurrently - getterCache.put( key, value ); + GETTER_CACHE.put( key, value ); } return value; @@ -78,12 +80,12 @@ public abstract class ReflectionTools { } private static Setter getSetter(Class cls, String propertyName, String accessorType) { - Pair key = Pair.make( cls, propertyName ); - Setter value = setterCache.get( key ); + final Pair key = Pair.make( cls, propertyName ); + Setter value = SETTER_CACHE.get( key ); if ( value == null ) { value = getAccessor( accessorType ).getSetter( cls, propertyName ); // It's ok if two setters are generated concurrently - setterCache.put( key, value ); + SETTER_CACHE.put( key, value ); } return value; @@ -92,6 +94,7 @@ public abstract class ReflectionTools { /** * @param clazz Source class. * @param propertyName Property name. + * * @return Property object or {@code null} if none with expected name has been found. */ public static XProperty getProperty(XClass clazz, String propertyName) { @@ -106,6 +109,7 @@ public abstract class ReflectionTools { * @param clazz Source class. * @param propertyName Property name. * @param accessType Expected access type. Legal values are field and property. + * * @return Property object or {@code null} if none with expected name and access type has been found. */ public static XProperty getProperty(XClass clazz, String propertyName, String accessType) { @@ -119,14 +123,18 @@ public abstract class ReflectionTools { /** * Locate class with a given name. + * * @param name Fully qualified class name. * @param classLoaderService Class loading service. Passing {@code null} reference - * in case of {@link AuditConfiguration#getFor(Configuration)} usage. + * in case of {@link AuditConfiguration#getFor(Configuration)} usage. + * * @return The cass reference. + * * @throws ClassLoadingException Indicates the class could not be found. */ @SuppressWarnings("unchecked") - public static Class loadClass(String name, ClassLoaderService classLoaderService) throws ClassLoadingException { + public static Class loadClass(String name, ClassLoaderService classLoaderService) + throws ClassLoadingException { try { if ( classLoaderService != null ) { return classLoaderService.classForName( name ); @@ -135,7 +143,7 @@ public abstract class ReflectionTools { return (Class) Thread.currentThread().getContextClassLoader().loadClass( name ); } } - catch ( Exception e ) { + catch (Exception e) { throw new ClassLoadingException( "Unable to load class [" + name + "]", e ); } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/StringTools.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/StringTools.java index e44d78f3e2..a583f3ff54 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/StringTools.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/StringTools.java @@ -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 @@ -47,7 +47,7 @@ public abstract class StringTools { if ( s == null ) { return null; } - int lastDot = s.lastIndexOf( "." ); + final int lastDot = s.lastIndexOf( "." ); if ( lastDot == -1 ) { return s; } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/Tools.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/Tools.java index da7e29937e..0fafa83c1d 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/Tools.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/Tools.java @@ -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 @@ -61,7 +61,7 @@ public abstract class Tools { } public static List iteratorToList(Iterator iter) { - List ret = new ArrayList(); + final List ret = new ArrayList(); while ( iter.hasNext() ) { ret.add( iter.next() ); } @@ -92,8 +92,8 @@ public abstract class Tools { * @return A list of pairs: ((0, element_at_index_0), (1, element_at_index_1), ...) */ public static List> listToIndexElementPairList(List list) { - List> ret = new ArrayList>(); - Iterator listIter = list.iterator(); + final List> ret = new ArrayList>(); + final Iterator listIter = list.iterator(); for ( int i = 0; i < list.size(); i++ ) { ret.add( Pair.make( i, listIter.next() ) ); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/Triple.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/Triple.java index c63c30f560..171203010d 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/Triple.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/Triple.java @@ -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 @@ -23,58 +23,65 @@ */ package org.hibernate.envers.internal.tools; +import org.hibernate.internal.util.compare.EqualsHelper; + /** * A triple of objects. + * * @param * @param * @param + * * @author Adam Warski (adamw@aster.pl) */ public class Triple { - private T1 obj1; - private T2 obj2; - private T3 obj3; + private T1 obj1; + private T2 obj2; + private T3 obj3; - public Triple(T1 obj1, T2 obj2, T3 obj3) { - this.obj1 = obj1; - this.obj2 = obj2; - this.obj3 = obj3; - } + public Triple(T1 obj1, T2 obj2, T3 obj3) { + this.obj1 = obj1; + this.obj2 = obj2; + this.obj3 = obj3; + } - public T1 getFirst() { - return obj1; - } + public T1 getFirst() { + return obj1; + } - public T2 getSecond() { - return obj2; - } + public T2 getSecond() { + return obj2; + } - public T3 getThird() { - return obj3; - } + public T3 getThird() { + return obj3; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof Triple)) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof Triple) ) { + return false; + } - Triple triple = (Triple) o; + final Triple other = (Triple) o; + return EqualsHelper.equals( obj1, other.obj1 ) + && EqualsHelper.equals( obj2, other.obj2 ) + && EqualsHelper.equals( obj3, other.obj3 ); + } - if (obj1 != null ? !obj1.equals(triple.obj1) : triple.obj1 != null) return false; - if (obj2 != null ? !obj2.equals(triple.obj2) : triple.obj2 != null) return false; - if (obj3 != null ? !obj3.equals(triple.obj3) : triple.obj3 != null) return false; + @Override + public int hashCode() { + int result; + result = (obj1 != null ? obj1.hashCode() : 0); + result = 31 * result + (obj2 != null ? obj2.hashCode() : 0); + result = 31 * result + (obj3 != null ? obj3.hashCode() : 0); + return result; + } - return true; - } - - public int hashCode() { - int result; - result = (obj1 != null ? obj1.hashCode() : 0); - result = 31 * result + (obj2 != null ? obj2.hashCode() : 0); - result = 31 * result + (obj3 != null ? obj3.hashCode() : 0); - return result; - } - - public static Triple make(T1 obj1, T2 obj2, T3 obj3) { - return new Triple(obj1, obj2, obj3); - } + public static Triple make(T1 obj1, T2 obj2, T3 obj3) { + return new Triple( obj1, obj2, obj3 ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/graph/GraphDefiner.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/graph/GraphDefiner.java index 81856b16cd..1cf4de91e7 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/graph/GraphDefiner.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/graph/GraphDefiner.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,16 +22,21 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.internal.tools.graph; + import java.util.List; /** * Defines a graph, where each vertex has a representation, which identifies uniquely a value. * Representations are comparable, values - not. + * * @author Adam Warski (adam at warski dot org) */ public interface GraphDefiner { - R getRepresentation(V v); - V getValue(R r); - List getNeighbours(V v); - List getValues(); + R getRepresentation(V v); + + V getValue(R r); + + List getNeighbours(V v); + + List getValues(); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/graph/GraphTopologicalSort.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/graph/GraphTopologicalSort.java index bd79f46540..99e3da169e 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/graph/GraphTopologicalSort.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/graph/GraphTopologicalSort.java @@ -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.internal.tools.graph; + import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -31,37 +32,40 @@ import java.util.Map; * @author Adam Warski (adam at warski dot org) */ public class GraphTopologicalSort { - /** - * Sorts a graph topologically. - * @param definer Defines a graph (values and representations) to sort. - * @return Values of the graph, sorted topologically. - */ - public static List sort(GraphDefiner definer) { - List values = definer.getValues(); - Map> vertices = new HashMap>(); + /** + * Sorts a graph topologically. + * + * @param definer Defines a graph (values and representations) to sort. + * + * @return Values of the graph, sorted topologically. + */ + public static List sort(GraphDefiner definer) { + final List values = definer.getValues(); + final Map> vertices = new HashMap>(); - // Creating a vertex for each representation - for (V v : values) { - R rep = definer.getRepresentation(v); - vertices.put(rep, new Vertex(rep)); - } + // Creating a vertex for each representation + for ( V v : values ) { + final R rep = definer.getRepresentation( v ); + vertices.put( rep, new Vertex( rep ) ); + } - // Connecting neighbourhooding vertices - for (V v : values) { - for (V vn : definer.getNeighbours(v)) { - vertices.get(definer.getRepresentation(v)).addNeighbour(vertices.get(definer.getRepresentation(vn))); - } - } + // Connecting neighbourhooding vertices + for ( V v : values ) { + for ( V vn : definer.getNeighbours( v ) ) { + vertices.get( definer.getRepresentation( v ) ) + .addNeighbour( vertices.get( definer.getRepresentation( vn ) ) ); + } + } - // Sorting the representations - List sortedReps = new TopologicalSort().sort(vertices.values()); + // Sorting the representations + final List sortedReps = new TopologicalSort().sort( vertices.values() ); - // Transforming the sorted representations to sorted values - List sortedValues = new ArrayList(sortedReps.size()); - for (R rep : sortedReps) { - sortedValues.add(definer.getValue(rep)); - } + // Transforming the sorted representations to sorted values + final List sortedValues = new ArrayList( sortedReps.size() ); + for ( R rep : sortedReps ) { + sortedValues.add( definer.getValue( rep ) ); + } - return sortedValues; - } + return sortedValues; + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/graph/TopologicalSort.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/graph/TopologicalSort.java index da68cdebea..840b3c87e5 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/graph/TopologicalSort.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/graph/TopologicalSort.java @@ -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.internal.tools.graph; + import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -29,42 +30,43 @@ import java.util.List; /** * Topological sorting of a graph - based on DFS. + * * @author Adam Warski (adam at warski dot org) */ public class TopologicalSort { - private List sorted; - private int time; + private List sorted; + private int time; - private void process(Vertex v) { - if (v.getStartTime() != 0) { - // alread processed - return; - } + private void process(Vertex v) { + if ( v.getStartTime() != 0 ) { + // alread processed + return; + } - v.setStartTime(time++); + v.setStartTime( time++ ); - for (Vertex n : v.getNeighbours()) { - process(n); - } + for ( Vertex n : v.getNeighbours() ) { + process( n ); + } - v.setEndTime(time++); + v.setEndTime( time++ ); - sorted.add(v.getRepresentation()); - } + sorted.add( v.getRepresentation() ); + } - public List sort(Collection> vertices) { - sorted = new ArrayList(vertices.size()); - - time = 1; + public List sort(Collection> vertices) { + sorted = new ArrayList( vertices.size() ); - for (Vertex v : vertices) { - if (v.getEndTime() == 0) { - process(v); - } - } + time = 1; - Collections.reverse(sorted); + for ( Vertex v : vertices ) { + if ( v.getEndTime() == 0 ) { + process( v ); + } + } - return sorted; - } + Collections.reverse( sorted ); + + return sorted; + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/graph/Vertex.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/graph/Vertex.java index c15035d7b7..92857d80c5 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/graph/Vertex.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/graph/Vertex.java @@ -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,52 +22,54 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.internal.tools.graph; + import java.util.ArrayList; import java.util.List; /** * A graph vertex - stores its representation, neighbours, start and end time in (D|B)FS. + * * @author Adam Warski (adam at warski dot org) */ public class Vertex { - private final R representation; - private final List> neighbours; - - private int startTime; - private int endTime; + private final R representation; + private final List> neighbours; - public Vertex(R representation) { - this.representation = representation; - this.neighbours = new ArrayList>(); - this.startTime = 0; - this.endTime = 0; - } + private int startTime; + private int endTime; - public R getRepresentation() { - return representation; - } + public Vertex(R representation) { + this.representation = representation; + this.neighbours = new ArrayList>(); + this.startTime = 0; + this.endTime = 0; + } - public List> getNeighbours() { - return neighbours; - } + public R getRepresentation() { + return representation; + } - public void addNeighbour(Vertex n) { - neighbours.add(n); - } + public List> getNeighbours() { + return neighbours; + } - public int getStartTime() { - return startTime; - } + public void addNeighbour(Vertex n) { + neighbours.add( n ); + } - public void setStartTime(int startTime) { - this.startTime = startTime; - } + public int getStartTime() { + return startTime; + } - public int getEndTime() { - return endTime; - } + public void setStartTime(int startTime) { + this.startTime = startTime; + } - public void setEndTime(int endTime) { - this.endTime = endTime; - } + public int getEndTime() { + return endTime; + } + + public void setEndTime(int endTime) { + this.endTime = endTime; + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/query/Parameters.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/query/Parameters.java index 08a7a30275..18caf91982 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/query/Parameters.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/query/Parameters.java @@ -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.internal.tools.query; + import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -32,52 +33,53 @@ import org.hibernate.envers.internal.tools.MutableInteger; /** * Parameters of a query, built using {@link QueryBuilder}. + * * @author Adam Warski (adam at warski dot org) */ public class Parameters { - public final static String AND = "and"; - public final static String OR = "or"; - - /** - * Main alias of the entity. - */ - private final String alias; - /** - * Connective between these parameters - "and" or "or". - */ - private final String connective; - /** - * For use by the parameter generator. Must be the same in all "child" (and parent) parameters. - */ - private final MutableInteger queryParamCounter; + public final static String AND = "and"; + public final static String OR = "or"; - /** - * A list of sub-parameters (parameters with a different connective). - */ - private final List subParameters; - /** - * A list of negated parameters. - */ - private final List negatedParameters; - /** - * A list of complete where-expressions. - */ - private final List expressions; - /** - * Values of parameters used in expressions. - */ - private final Map localQueryParamValues; + /** + * Main alias of the entity. + */ + private final String alias; + /** + * Connective between these parameters - "and" or "or". + */ + private final String connective; + /** + * For use by the parameter generator. Must be the same in all "child" (and parent) parameters. + */ + private final MutableInteger queryParamCounter; - Parameters(String alias, String connective, MutableInteger queryParamCounter) { - this.alias = alias; - this.connective = connective; - this.queryParamCounter = queryParamCounter; + /** + * A list of sub-parameters (parameters with a different connective). + */ + private final List subParameters; + /** + * A list of negated parameters. + */ + private final List negatedParameters; + /** + * A list of complete where-expressions. + */ + private final List expressions; + /** + * Values of parameters used in expressions. + */ + private final Map localQueryParamValues; - subParameters = new ArrayList(); - negatedParameters = new ArrayList(); - expressions = new ArrayList(); - localQueryParamValues = new HashMap(); - } + Parameters(String alias, String connective, MutableInteger queryParamCounter) { + this.alias = alias; + this.connective = connective; + this.queryParamCounter = queryParamCounter; + + subParameters = new ArrayList(); + negatedParameters = new ArrayList(); + expressions = new ArrayList(); + localQueryParamValues = new HashMap(); + } // Only for deep copy purpose. private Parameters(Parameters other) { @@ -101,181 +103,193 @@ public class Parameters { return new Parameters( this ); } - private String generateQueryParam() { - return "_p" + queryParamCounter.getAndIncrease(); - } + private String generateQueryParam() { + return "_p" + queryParamCounter.getAndIncrease(); + } - /** - * Adds sub-parameters with a new connective. That is, the parameters will be grouped in parentheses in the - * generated query, e.g.: ... and (exp1 or exp2) and ..., assuming the old connective is "and", and the - * new connective is "or". - * @param newConnective New connective of the parameters. - * @return Sub-parameters with the given connective. - */ - public Parameters addSubParameters(String newConnective) { - if (connective.equals(newConnective)) { - return this; - } else { - Parameters newParams = new Parameters(alias, newConnective, queryParamCounter); - subParameters.add(newParams); - return newParams; - } - } + /** + * Adds sub-parameters with a new connective. That is, the parameters will be grouped in parentheses in the + * generated query, e.g.: ... and (exp1 or exp2) and ..., assuming the old connective is "and", and the + * new connective is "or". + * + * @param newConnective New connective of the parameters. + * + * @return Sub-parameters with the given connective. + */ + public Parameters addSubParameters(String newConnective) { + if ( connective.equals( newConnective ) ) { + return this; + } + else { + final Parameters newParams = new Parameters( alias, newConnective, queryParamCounter ); + subParameters.add( newParams ); + return newParams; + } + } - /** - * Adds negated parameters, by default with the "and" connective. These paremeters will be grouped in parentheses - * in the generated query and negated, e.g. ... not (exp1 and exp2) ... - * @return Negated sub paremters. - */ - public Parameters addNegatedParameters() { - Parameters newParams = new Parameters(alias, AND, queryParamCounter); - negatedParameters.add(newParams); - return newParams; - } + /** + * Adds negated parameters, by default with the "and" connective. These paremeters will be grouped in parentheses + * in the generated query and negated, e.g. ... not (exp1 and exp2) ... + * + * @return Negated sub paremters. + */ + public Parameters addNegatedParameters() { + final Parameters newParams = new Parameters( alias, AND, queryParamCounter ); + negatedParameters.add( newParams ); + return newParams; + } - public void addWhere(String left, String op, String right) { - addWhere(left, true, op, right, true); - } + public void addWhere(String left, String op, String right) { + addWhere( left, true, op, right, true ); + } - /** - * Adds IS NULL restriction. - * @param propertyName Property name. - * @param addAlias Positive if an alias to property name shall be added. - */ - public void addNullRestriction(String propertyName, boolean addAlias) { - addWhere(propertyName, addAlias, "is", "null", false); - } + /** + * Adds IS NULL restriction. + * + * @param propertyName Property name. + * @param addAlias Positive if an alias to property name shall be added. + */ + public void addNullRestriction(String propertyName, boolean addAlias) { + addWhere( propertyName, addAlias, "is", "null", false ); + } - /** - * Adds IS NOT NULL restriction. - * @param propertyName Property name. - * @param addAlias Positive if an alias to property name shall be added. - */ - public void addNotNullRestriction(String propertyName, boolean addAlias) { - addWhere(propertyName, addAlias, "is not", "null", false); - } + /** + * Adds IS NOT NULL restriction. + * + * @param propertyName Property name. + * @param addAlias Positive if an alias to property name shall be added. + */ + public void addNotNullRestriction(String propertyName, boolean addAlias) { + addWhere( propertyName, addAlias, "is not", "null", false ); + } - public void addWhere(String left, boolean addAliasLeft, String op, String right, boolean addAliasRight) { - StringBuilder expression = new StringBuilder(); + public void addWhere(String left, boolean addAliasLeft, String op, String right, boolean addAliasRight) { + final StringBuilder expression = new StringBuilder(); - if (addAliasLeft) { expression.append(alias).append("."); } - expression.append(left); + if ( addAliasLeft ) { + expression.append( alias ).append( "." ); + } + expression.append( left ); - expression.append(" ").append(op).append(" "); + expression.append( " " ).append( op ).append( " " ); - if (addAliasRight) { expression.append(alias).append("."); } - expression.append(right); + if ( addAliasRight ) { + expression.append( alias ).append( "." ); + } + expression.append( right ); - expressions.add(expression.toString()); - } + expressions.add( expression.toString() ); + } - public void addWhereWithParam(String left, String op, Object paramValue) { - addWhereWithParam(left, true, op, paramValue); - } + public void addWhereWithParam(String left, String op, Object paramValue) { + addWhereWithParam( left, true, op, paramValue ); + } - public void addWhereWithParam(String left, boolean addAlias, String op, Object paramValue) { - String paramName = generateQueryParam(); - localQueryParamValues.put(paramName, paramValue); + public void addWhereWithParam(String left, boolean addAlias, String op, Object paramValue) { + final String paramName = generateQueryParam(); + localQueryParamValues.put( paramName, paramValue ); - addWhereWithNamedParam(left, addAlias, op, paramName); - } + addWhereWithNamedParam( left, addAlias, op, paramName ); + } - public void addWhereWithNamedParam(String left, String op, String paramName) { - addWhereWithNamedParam(left, true, op, paramName); - } + public void addWhereWithNamedParam(String left, String op, String paramName) { + addWhereWithNamedParam( left, true, op, paramName ); + } - public void addWhereWithNamedParam(String left, boolean addAlias, String op, String paramName) { - StringBuilder expression = new StringBuilder(); + public void addWhereWithNamedParam(String left, boolean addAlias, String op, String paramName) { + final StringBuilder expression = new StringBuilder(); - if (addAlias) { expression.append(alias).append("."); } - expression.append(left); - expression.append(" ").append(op).append(" "); - expression.append(":").append(paramName); + if ( addAlias ) { + expression.append( alias ).append( "." ); + } + expression.append( left ); + expression.append( " " ).append( op ).append( " " ); + expression.append( ":" ).append( paramName ); - expressions.add(expression.toString()); - } + expressions.add( expression.toString() ); + } - public void addWhereWithParams(String left, String opStart, Object[] paramValues, String opEnd) { - StringBuilder expression = new StringBuilder(); + public void addWhereWithParams(String left, String opStart, Object[] paramValues, String opEnd) { + final StringBuilder expression = new StringBuilder(); - expression.append(alias).append(".").append(left).append(" ").append(opStart); + expression.append( alias ).append( "." ).append( left ).append( " " ).append( opStart ); - for (int i=0; i queryParamValues) { - MutableBoolean isFirst = new MutableBoolean(true); + boolean isEmpty() { + return expressions.size() == 0 && subParameters.size() == 0 && negatedParameters.size() == 0; + } - for (String expression : expressions) { - append(sb, expression, isFirst); - } + void build(StringBuilder sb, Map queryParamValues) { + final MutableBoolean isFirst = new MutableBoolean( true ); - for (Parameters sub : subParameters) { - if (!subParameters.isEmpty()) { - append(sb, "(", isFirst); - sub.build(sb, queryParamValues); - sb.append(")"); - } - } + for ( String expression : expressions ) { + append( sb, expression, isFirst ); + } - for (Parameters negated : negatedParameters) { - if (!negatedParameters.isEmpty()) { - append(sb, "not (", isFirst); - negated.build(sb, queryParamValues); - sb.append(")"); - } - } + for ( Parameters sub : subParameters ) { + if ( !subParameters.isEmpty() ) { + append( sb, "(", isFirst ); + sub.build( sb, queryParamValues ); + sb.append( ")" ); + } + } - queryParamValues.putAll(localQueryParamValues); - } + for ( Parameters negated : negatedParameters ) { + if ( !negatedParameters.isEmpty() ) { + append( sb, "not (", isFirst ); + negated.build( sb, queryParamValues ); + sb.append( ")" ); + } + } + + queryParamValues.putAll( localQueryParamValues ); + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/query/QueryBuilder.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/query/QueryBuilder.java index 6377318a05..0a75c65a8c 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/query/QueryBuilder.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/query/QueryBuilder.java @@ -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 @@ -35,63 +35,63 @@ import org.hibernate.envers.internal.tools.StringTools; import org.hibernate.envers.tools.Pair; /** - * A class for incrementaly building a HQL query. + * A class for incrementally building a HQL query. + * * @author Adam Warski (adam at warski dot org) */ public class QueryBuilder { - private final String entityName; - private final String alias; + private final String entityName; + private final String alias; - /** - * For use by alias generator (in case an alias is not provided by the user). - */ - private final MutableInteger aliasCounter; - /** - * For use by parameter generator, in {@link Parameters}. This counter must be - * the same in all parameters and sub-queries of this query. - */ - private final MutableInteger paramCounter; - /** - * Main "where" parameters for this query. - */ - private final Parameters rootParameters; + /** + * For use by alias generator (in case an alias is not provided by the user). + */ + private final MutableInteger aliasCounter; + /** + * For use by parameter generator, in {@link Parameters}. This counter must be + * the same in all parameters and sub-queries of this query. + */ + private final MutableInteger paramCounter; + /** + * Main "where" parameters for this query. + */ + private final Parameters rootParameters; - /** - * A list of pairs (from entity name, alias name). - */ - private final List> froms; - /** - * A list of pairs (property name, order ascending?). - */ - private final List> orders; - /** - * A list of complete projection definitions: either a sole property name, or a function(property name). - */ - private final List projections; + /** + * A list of pairs (from entity name, alias name). + */ + private final List> froms; + /** + * A list of pairs (property name, order ascending?). + */ + private final List> orders; + /** + * A list of complete projection definitions: either a sole property name, or a function(property name). + */ + private final List projections; - /** - * - * @param entityName Main entity which should be selected. - * @param alias Alias of the entity - */ - public QueryBuilder(String entityName, String alias) { - this(entityName, alias, new MutableInteger(), new MutableInteger()); - } + /** + * @param entityName Main entity which should be selected. + * @param alias Alias of the entity + */ + public QueryBuilder(String entityName, String alias) { + this( entityName, alias, new MutableInteger(), new MutableInteger() ); + } - private QueryBuilder(String entityName, String alias, MutableInteger aliasCounter, MutableInteger paramCounter) { - this.entityName = entityName; - this.alias = alias; - this.aliasCounter = aliasCounter; - this.paramCounter = paramCounter; + private QueryBuilder(String entityName, String alias, MutableInteger aliasCounter, MutableInteger paramCounter) { + this.entityName = entityName; + this.alias = alias; + this.aliasCounter = aliasCounter; + this.paramCounter = paramCounter; - rootParameters = new Parameters(alias, "and", paramCounter); + rootParameters = new Parameters( alias, "and", paramCounter ); - froms = new ArrayList>(); - orders = new ArrayList>(); - projections = new ArrayList(); + froms = new ArrayList>(); + orders = new ArrayList>(); + projections = new ArrayList(); - addFrom(entityName, alias); - } + addFrom( entityName, alias ); + } // Only for deep copy purpose. private QueryBuilder(QueryBuilder other) { @@ -110,129 +110,138 @@ public class QueryBuilder { return new QueryBuilder( this ); } - /** - * Add an entity from which to select. - * @param entityName Name of the entity from which to select. - * @param alias Alias of the entity. Should be different than all other aliases. - */ - public void addFrom(String entityName, String alias) { - froms.add(Pair.make(entityName, alias)); - } + /** + * Add an entity from which to select. + * + * @param entityName Name of the entity from which to select. + * @param alias Alias of the entity. Should be different than all other aliases. + */ + public void addFrom(String entityName, String alias) { + froms.add( Pair.make( entityName, alias ) ); + } - private String generateAlias() { - return "_e" + aliasCounter.getAndIncrease(); - } + private String generateAlias() { + return "_e" + aliasCounter.getAndIncrease(); + } - /** - * @return A sub-query builder for the same entity (with an auto-generated alias). The sub-query can - * be later used as a value of a parameter. - */ - public QueryBuilder newSubQueryBuilder() { - return newSubQueryBuilder(entityName, generateAlias()); - } + /** + * @return A sub-query builder for the same entity (with an auto-generated alias). The sub-query can + * be later used as a value of a parameter. + */ + public QueryBuilder newSubQueryBuilder() { + return newSubQueryBuilder( entityName, generateAlias() ); + } - /** - * @param entityName Entity name, which will be the main entity for the sub-query. - * @param alias Alias of the entity, which can later be used in parameters. - * @return A sub-query builder for the given entity, with the given alias. The sub-query can - * be later used as a value of a parameter. - */ - public QueryBuilder newSubQueryBuilder(String entityName, String alias) { - return new QueryBuilder(entityName, alias, aliasCounter, paramCounter); - } + /** + * @param entityName Entity name, which will be the main entity for the sub-query. + * @param alias Alias of the entity, which can later be used in parameters. + * + * @return A sub-query builder for the given entity, with the given alias. The sub-query can + * be later used as a value of a parameter. + */ + public QueryBuilder newSubQueryBuilder(String entityName, String alias) { + return new QueryBuilder( entityName, alias, aliasCounter, paramCounter ); + } - public Parameters getRootParameters() { - return rootParameters; - } + public Parameters getRootParameters() { + return rootParameters; + } - public void addOrder(String propertyName, boolean ascending) { - orders.add(Pair.make(propertyName, ascending)); - } + public void addOrder(String propertyName, boolean ascending) { + orders.add( Pair.make( propertyName, ascending ) ); + } - public void addProjection(String function, String propertyName, boolean distinct) { - addProjection(function, propertyName, distinct, true); - } + public void addProjection(String function, String propertyName, boolean distinct) { + addProjection( function, propertyName, distinct, true ); + } - public void addProjection(String function, String propertyName, boolean distinct, boolean addAlias) { - if (function == null) { - projections.add((distinct ? "distinct " : "") + (addAlias ? alias+ "." : "") + propertyName); - } else { - projections.add(function + "(" + (distinct ? "distinct " : "") + (addAlias ? alias + "." : "") + propertyName + ")"); - } - } + public void addProjection(String function, String propertyName, boolean distinct, boolean addAlias) { + if ( function == null ) { + projections.add( (distinct ? "distinct " : "") + (addAlias ? alias + "." : "") + propertyName ); + } + else { + projections.add( + function + "(" + (distinct ? "distinct " : "") + (addAlias ? + alias + "." : + "") + propertyName + ")" + ); + } + } - /** - * Builds the given query, appending results to the given string buffer, and adding all query parameter values - * that are used to the map provided. - * @param sb String builder to which the query will be appended. - * @param queryParamValues Map to which name and values of parameters used in the query should be added. - */ - public void build(StringBuilder sb, Map queryParamValues) { - sb.append("select "); - if (projections.size() > 0) { - // all projections separated with commas - StringTools.append(sb, projections.iterator(), ", "); - } else { - // all aliases separated with commas - StringTools.append(sb, getAliasList().iterator(), ", "); - } - sb.append(" from "); - // all from entities with aliases, separated with commas - StringTools.append(sb, getFromList().iterator(), ", "); - // where part - rootParameters - if (!rootParameters.isEmpty()) { - sb.append(" where "); - rootParameters.build(sb, queryParamValues); - } - // orders - if (orders.size() > 0) { - sb.append(" order by "); - StringTools.append(sb, getOrderList().iterator(), ", "); - } - } + /** + * Builds the given query, appending results to the given string buffer, and adding all query parameter values + * that are used to the map provided. + * + * @param sb String builder to which the query will be appended. + * @param queryParamValues Map to which name and values of parameters used in the query should be added. + */ + public void build(StringBuilder sb, Map queryParamValues) { + sb.append( "select " ); + if ( projections.size() > 0 ) { + // all projections separated with commas + StringTools.append( sb, projections.iterator(), ", " ); + } + else { + // all aliases separated with commas + StringTools.append( sb, getAliasList().iterator(), ", " ); + } + sb.append( " from " ); + // all from entities with aliases, separated with commas + StringTools.append( sb, getFromList().iterator(), ", " ); + // where part - rootParameters + if ( !rootParameters.isEmpty() ) { + sb.append( " where " ); + rootParameters.build( sb, queryParamValues ); + } + // orders + if ( orders.size() > 0 ) { + sb.append( " order by " ); + StringTools.append( sb, getOrderList().iterator(), ", " ); + } + } - private List getAliasList() { - List aliasList = new ArrayList(); - for (Pair from : froms) { - aliasList.add(from.getSecond()); - } + private List getAliasList() { + final List aliasList = new ArrayList(); + for ( Pair from : froms ) { + aliasList.add( from.getSecond() ); + } - return aliasList; - } + return aliasList; + } public String getRootAlias() { return alias; } - private List getFromList() { - List fromList = new ArrayList(); - for (Pair from : froms) { - fromList.add(from.getFirst() + " " + from.getSecond()); - } + private List getFromList() { + final List fromList = new ArrayList(); + for ( Pair from : froms ) { + fromList.add( from.getFirst() + " " + from.getSecond() ); + } - return fromList; - } + return fromList; + } - private List getOrderList() { - List orderList = new ArrayList(); - for (Pair order : orders) { - orderList.add(alias + "." + order.getFirst() + " " + (order.getSecond() ? "asc" : "desc")); - } + private List getOrderList() { + final List orderList = new ArrayList(); + for ( Pair order : orders ) { + orderList.add( alias + "." + order.getFirst() + " " + (order.getSecond() ? "asc" : "desc") ); + } - return orderList; - } + return orderList; + } - public Query toQuery(Session session) { - StringBuilder querySb = new StringBuilder(); - Map queryParamValues = new HashMap(); + public Query toQuery(Session session) { + final StringBuilder querySb = new StringBuilder(); + final Map queryParamValues = new HashMap(); - build(querySb, queryParamValues); + build( querySb, queryParamValues ); - Query query = session.createQuery(querySb.toString()); - for (Map.Entry paramValue : queryParamValues.entrySet()) { - query.setParameter(paramValue.getKey(), paramValue.getValue()); - } + final Query query = session.createQuery( querySb.toString() ); + for ( Map.Entry paramValue : queryParamValues.entrySet() ) { + query.setParameter( paramValue.getKey(), paramValue.getValue() ); + } - return query; - } + return query; + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/query/UpdateBuilder.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/query/UpdateBuilder.java index 99729fd1eb..f790e78fc3 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/query/UpdateBuilder.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/query/UpdateBuilder.java @@ -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.internal.tools.query; import java.util.HashMap; @@ -11,66 +34,66 @@ import org.hibernate.envers.internal.tools.MutableInteger; * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public class UpdateBuilder { - private final String entityName; - private final String alias; - private final MutableInteger paramCounter; - private final Parameters rootParameters; - private final Map updates; + private final String entityName; + private final String alias; + private final MutableInteger paramCounter; + private final Parameters rootParameters; + private final Map updates; - public UpdateBuilder(String entityName, String alias) { - this(entityName, alias, new MutableInteger()); - } + public UpdateBuilder(String entityName, String alias) { + this( entityName, alias, new MutableInteger() ); + } - private UpdateBuilder(String entityName, String alias, MutableInteger paramCounter) { - this.entityName = entityName; - this.alias = alias; - this.paramCounter = paramCounter; - rootParameters = new Parameters(alias, "and", paramCounter); - updates = new HashMap(); - } + private UpdateBuilder(String entityName, String alias, MutableInteger paramCounter) { + this.entityName = entityName; + this.alias = alias; + this.paramCounter = paramCounter; + rootParameters = new Parameters( alias, "and", paramCounter ); + updates = new HashMap(); + } - public Parameters getRootParameters() { - return rootParameters; - } + public Parameters getRootParameters() { + return rootParameters; + } - public void updateValue(String propertyName, Object value) { - updates.put(propertyName, value); - } + public void updateValue(String propertyName, Object value) { + updates.put( propertyName, value ); + } - public void build(StringBuilder sb, Map updateParamValues) { - sb.append("update ").append(entityName).append(" ").append(alias); - sb.append(" set "); - int i = 1; - for (String property : updates.keySet()) { - final String paramName = generateParameterName(); - sb.append(alias).append(".").append(property).append(" = ").append(":").append(paramName); - updateParamValues.put(paramName, updates.get(property)); - if (i < updates.size()) { - sb.append(", "); - } - ++i; - } - if (!rootParameters.isEmpty()) { - sb.append(" where "); - rootParameters.build(sb, updateParamValues); - } - } + public void build(StringBuilder sb, Map updateParamValues) { + sb.append( "update " ).append( entityName ).append( " " ).append( alias ); + sb.append( " set " ); + int i = 1; + for ( String property : updates.keySet() ) { + final String paramName = generateParameterName(); + sb.append( alias ).append( "." ).append( property ).append( " = " ).append( ":" ).append( paramName ); + updateParamValues.put( paramName, updates.get( property ) ); + if ( i < updates.size() ) { + sb.append( ", " ); + } + ++i; + } + if ( !rootParameters.isEmpty() ) { + sb.append( " where " ); + rootParameters.build( sb, updateParamValues ); + } + } - private String generateParameterName() { - return "_u" + paramCounter.getAndIncrease(); - } + private String generateParameterName() { + return "_u" + paramCounter.getAndIncrease(); + } - public Query toQuery(Session session) { - StringBuilder querySb = new StringBuilder(); - Map queryParamValues = new HashMap(); + public Query toQuery(Session session) { + final StringBuilder querySb = new StringBuilder(); + final Map queryParamValues = new HashMap(); - build(querySb, queryParamValues); + build( querySb, queryParamValues ); - Query query = session.createQuery(querySb.toString()); - for (Map.Entry paramValue : queryParamValues.entrySet()) { - query.setParameter(paramValue.getKey(), paramValue.getValue()); - } + final Query query = session.createQuery( querySb.toString() ); + for ( Map.Entry paramValue : queryParamValues.entrySet() ) { + query.setParameter( paramValue.getKey(), paramValue.getValue() ); + } - return query; - } + return query; + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/AuditEntity.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/AuditEntity.java index a6df9c09e3..5b6e67dc7d 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/AuditEntity.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/AuditEntity.java @@ -40,77 +40,82 @@ import org.hibernate.envers.query.internal.property.RevisionTypePropertyName; /** * TODO: ilike + * * @author Adam Warski (adam at warski dot org) * @see Restrictions */ @SuppressWarnings({"JavaDoc"}) public class AuditEntity { - private AuditEntity() { } - - public static AuditId id() { - return new AuditId(); - } - - /** - * Create restrictions, projections and specify order for a property of an audited entity. - * @param propertyName Name of the property. - */ - public static AuditProperty property(String propertyName) { - return new AuditProperty(new EntityPropertyName(propertyName)); - } - - /** - * Create restrictions, projections and specify order for the revision number, corresponding to an - * audited entity. - */ - public static AuditProperty revisionNumber() { - return new AuditProperty(new RevisionNumberPropertyName()); - } - - /** - * Create restrictions, projections and specify order for a property of the revision entity, - * corresponding to an audited entity. - * @param propertyName Name of the property. - */ - public static AuditProperty revisionProperty(String propertyName) { - return new AuditProperty(new RevisionPropertyPropertyName(propertyName)); - } - - /** - * Create restrictions, projections and specify order for the revision type, corresponding to an - * audited entity. - */ - public static AuditProperty revisionType() { - return new AuditProperty(new RevisionTypePropertyName()); - } - - /** - * Create restrictions on an id of a related entity. - * @param propertyName Name of the property, which is the relation. - */ - public static AuditRelatedId relatedId(String propertyName) { - return new AuditRelatedId(new EntityPropertyName(propertyName)); + private AuditEntity() { } - /** + public static AuditId id() { + return new AuditId(); + } + + /** + * Create restrictions, projections and specify order for a property of an audited entity. + * + * @param propertyName Name of the property. + */ + public static AuditProperty property(String propertyName) { + return new AuditProperty( new EntityPropertyName( propertyName ) ); + } + + /** + * Create restrictions, projections and specify order for the revision number, corresponding to an + * audited entity. + */ + public static AuditProperty revisionNumber() { + return new AuditProperty( new RevisionNumberPropertyName() ); + } + + /** + * Create restrictions, projections and specify order for a property of the revision entity, + * corresponding to an audited entity. + * + * @param propertyName Name of the property. + */ + public static AuditProperty revisionProperty(String propertyName) { + return new AuditProperty( new RevisionPropertyPropertyName( propertyName ) ); + } + + /** + * Create restrictions, projections and specify order for the revision type, corresponding to an + * audited entity. + */ + public static AuditProperty revisionType() { + return new AuditProperty( new RevisionTypePropertyName() ); + } + + /** + * Create restrictions on an id of a related entity. + * + * @param propertyName Name of the property, which is the relation. + */ + public static AuditRelatedId relatedId(String propertyName) { + return new AuditRelatedId( new EntityPropertyName( propertyName ) ); + } + + /** * Return the conjuction of two criterions. */ public static AuditCriterion and(AuditCriterion lhs, AuditCriterion rhs) { - return new LogicalAuditExpression(lhs, rhs, "and"); + return new LogicalAuditExpression( lhs, rhs, "and" ); } - /** + /** * Return the disjuction of two criterions. */ public static AuditCriterion or(AuditCriterion lhs, AuditCriterion rhs) { - return new LogicalAuditExpression(lhs, rhs, "or"); + return new LogicalAuditExpression( lhs, rhs, "or" ); } - /** + /** * Return the negation of a criterion. */ public static AuditCriterion not(AuditCriterion expression) { - return new NotAuditExpression(expression); + return new NotAuditExpression( expression ); } /** diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/AuditQuery.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/AuditQuery.java index 72717d93a0..6ac16e51f6 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/AuditQuery.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/AuditQuery.java @@ -22,9 +22,10 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.query; -import java.util.List; + import javax.persistence.NoResultException; import javax.persistence.NonUniqueResultException; +import java.util.List; import org.hibernate.CacheMode; import org.hibernate.FlushMode; @@ -39,31 +40,31 @@ import org.hibernate.envers.query.projection.AuditProjection; * @see org.hibernate.Criteria */ public interface AuditQuery { - List getResultList() throws AuditException; + List getResultList() throws AuditException; - Object getSingleResult() throws AuditException, NonUniqueResultException, NoResultException; + Object getSingleResult() throws AuditException, NonUniqueResultException, NoResultException; - AuditQuery add(AuditCriterion criterion); + AuditQuery add(AuditCriterion criterion); - AuditQuery addProjection(AuditProjection projection); + AuditQuery addProjection(AuditProjection projection); - AuditQuery addOrder(AuditOrder order); + AuditQuery addOrder(AuditOrder order); - AuditQuery setMaxResults(int maxResults); + AuditQuery setMaxResults(int maxResults); AuditQuery setFirstResult(int firstResult); - AuditQuery setCacheable(boolean cacheable); + AuditQuery setCacheable(boolean cacheable); - AuditQuery setCacheRegion(String cacheRegion); + AuditQuery setCacheRegion(String cacheRegion); - AuditQuery setComment(String comment); + AuditQuery setComment(String comment); - AuditQuery setFlushMode(FlushMode flushMode); + AuditQuery setFlushMode(FlushMode flushMode); - AuditQuery setCacheMode(CacheMode cacheMode); + AuditQuery setCacheMode(CacheMode cacheMode); - AuditQuery setTimeout(int timeout); + AuditQuery setTimeout(int timeout); - AuditQuery setLockMode(LockMode lockMode); + AuditQuery setLockMode(LockMode lockMode); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/AuditQueryCreator.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/AuditQueryCreator.java index a682cc8dd6..958be1e6cf 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/AuditQueryCreator.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/AuditQueryCreator.java @@ -39,150 +39,188 @@ import static org.hibernate.envers.internal.tools.EntityTools.getTargetClassIfPr * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public class AuditQueryCreator { - private final AuditConfiguration auditCfg; - private final AuditReaderImplementor auditReaderImplementor; + private final AuditConfiguration auditCfg; + private final AuditReaderImplementor auditReaderImplementor; - public AuditQueryCreator(AuditConfiguration auditCfg, AuditReaderImplementor auditReaderImplementor) { - this.auditCfg = auditCfg; - this.auditReaderImplementor = auditReaderImplementor; - } + public AuditQueryCreator(AuditConfiguration auditCfg, AuditReaderImplementor auditReaderImplementor) { + this.auditCfg = auditCfg; + this.auditReaderImplementor = auditReaderImplementor; + } - /** - * Creates a query, which will return entities satisfying some conditions (specified later), - * at a given revision. Deleted entities are not included. - * @param c Class of the entities for which to query. - * @param revision Revision number at which to execute the query. - * @return A query for entities at a given revision, to which conditions can be added and which - * can then be executed. The result of the query will be a list of entities (beans), unless a - * projection is added. - */ - public AuditQuery forEntitiesAtRevision(Class c, Number revision) { - checkNotNull(revision, "Entity revision"); - checkPositive(revision, "Entity revision"); - c = getTargetClassIfProxied(c); - return new EntitiesAtRevisionQuery(auditCfg, auditReaderImplementor, c, revision, false); - } - - /** - * Creates a query, which will return entities satisfying some conditions (specified later), - * at a given revision and a given entityName. Deleted entities are not included. - * @param c Class of the entities for which to query. - * @param entityName Name of the entity (if can't be guessed basing on the {@code c}). - * @param revision Revision number at which to execute the query. - * @return A query for entities at a given revision, to which conditions can be added and which - * can then be executed. The result of the query will be a list of entities (beans), unless a - * projection is added. - */ - public AuditQuery forEntitiesAtRevision(Class c, String entityName, Number revision) { - return forEntitiesAtRevision(c, entityName, revision, false); - } + /** + * Creates a query, which will return entities satisfying some conditions (specified later), + * at a given revision. Deleted entities are not included. + * + * @param c Class of the entities for which to query. + * @param revision Revision number at which to execute the query. + * + * @return A query for entities at a given revision, to which conditions can be added and which + * can then be executed. The result of the query will be a list of entities (beans), unless a + * projection is added. + */ + public AuditQuery forEntitiesAtRevision(Class c, Number revision) { + checkNotNull( revision, "Entity revision" ); + checkPositive( revision, "Entity revision" ); + c = getTargetClassIfProxied( c ); + return new EntitiesAtRevisionQuery( auditCfg, auditReaderImplementor, c, revision, false ); + } - /** - * Creates a query, which will return entities satisfying some conditions (specified later), - * at a given revision and a given entityName. Deleted entities may be optionally - * included. - * @param c Class of the entities for which to query. - * @param entityName Name of the entity (if can't be guessed basing on the {@code c}). - * @param revision Revision number at which to execute the query. - * @param includeDeletions Whether to include deleted entities in the search. - * @return A query for entities at a given revision, to which conditions can be added and which - * can then be executed. The result of the query will be a list of entities (beans), unless a - * projection is added. - */ - public AuditQuery forEntitiesAtRevision(Class c, String entityName, Number revision, boolean includeDeletions) { - checkNotNull(revision, "Entity revision"); - checkPositive(revision, "Entity revision"); - c = getTargetClassIfProxied(c); - return new EntitiesAtRevisionQuery(auditCfg, auditReaderImplementor, c, entityName, revision, includeDeletions); - } + /** + * Creates a query, which will return entities satisfying some conditions (specified later), + * at a given revision and a given entityName. Deleted entities are not included. + * + * @param c Class of the entities for which to query. + * @param entityName Name of the entity (if can't be guessed basing on the {@code c}). + * @param revision Revision number at which to execute the query. + * + * @return A query for entities at a given revision, to which conditions can be added and which + * can then be executed. The result of the query will be a list of entities (beans), unless a + * projection is added. + */ + public AuditQuery forEntitiesAtRevision(Class c, String entityName, Number revision) { + return forEntitiesAtRevision( c, entityName, revision, false ); + } - /** - * Creates a query, which will return entities modified at the specified revision. - * - * In comparison, the {@link #forEntitiesAtRevision(Class, String, Number)} query takes into all entities - * which were present at a given revision, even if they were not modified. - * - * @param c Class of the entities for which to query. - * @param entityName Name of the entity (if can't be guessed basing on the {@code c}). - * @param revision Revision number at which to execute the query. - * @return A query for entities changed at a given revision, to which conditions can be added and which - * can then be executed. - * @see #forEntitiesAtRevision(Class, String, Number) - */ - public AuditQuery forEntitiesModifiedAtRevision(Class c, String entityName, Number revision) { - checkNotNull(revision, "Entity revision"); - checkPositive(revision, "Entity revision"); - c = getTargetClassIfProxied(c); - return new EntitiesModifiedAtRevisionQuery(auditCfg, auditReaderImplementor, c, entityName, revision); - } + /** + * Creates a query, which will return entities satisfying some conditions (specified later), + * at a given revision and a given entityName. Deleted entities may be optionally + * included. + * + * @param c Class of the entities for which to query. + * @param entityName Name of the entity (if can't be guessed basing on the {@code c}). + * @param revision Revision number at which to execute the query. + * @param includeDeletions Whether to include deleted entities in the search. + * + * @return A query for entities at a given revision, to which conditions can be added and which + * can then be executed. The result of the query will be a list of entities (beans), unless a + * projection is added. + */ + public AuditQuery forEntitiesAtRevision(Class c, String entityName, Number revision, boolean includeDeletions) { + checkNotNull( revision, "Entity revision" ); + checkPositive( revision, "Entity revision" ); + c = getTargetClassIfProxied( c ); + return new EntitiesAtRevisionQuery( + auditCfg, + auditReaderImplementor, + c, + entityName, + revision, + includeDeletions + ); + } - /** - * Creates a query, which will return entities modified at the specified revision. - * - * In comparison, the {@link #forEntitiesAtRevision(Class, String, Number)} query takes into all entities - * which were present at a given revision, even if they were not modified. - * - * @param c Class of the entities for which to query. - * @param revision Revision number at which to execute the query. - * @return A query for entities changed at a given revision, to which conditions can be added and which - * can then be executed. - * @see #forEntitiesAtRevision(Class, Number) - */ - public AuditQuery forEntitiesModifiedAtRevision(Class c, Number revision) { - checkNotNull(revision, "Entity revision"); - checkPositive(revision, "Entity revision"); - c = getTargetClassIfProxied(c); - return new EntitiesModifiedAtRevisionQuery(auditCfg, auditReaderImplementor, c, revision); - } + /** + * Creates a query, which will return entities modified at the specified revision. + *

+ * In comparison, the {@link #forEntitiesAtRevision(Class, String, Number)} query takes into all entities + * which were present at a given revision, even if they were not modified. + * + * @param c Class of the entities for which to query. + * @param entityName Name of the entity (if can't be guessed basing on the {@code c}). + * @param revision Revision number at which to execute the query. + * + * @return A query for entities changed at a given revision, to which conditions can be added and which + * can then be executed. + * + * @see #forEntitiesAtRevision(Class, String, Number) + */ + public AuditQuery forEntitiesModifiedAtRevision(Class c, String entityName, Number revision) { + checkNotNull( revision, "Entity revision" ); + checkPositive( revision, "Entity revision" ); + c = getTargetClassIfProxied( c ); + return new EntitiesModifiedAtRevisionQuery( auditCfg, auditReaderImplementor, c, entityName, revision ); + } - /** - * Creates a query, which selects the revisions, at which the given entity was modified. - * Unless an explicit projection is set, the result will be a list of three-element arrays, containing: - *

    - *
  1. the entity instance
  2. - *
  3. revision entity, corresponding to the revision at which the entity was modified. If no custom - * revision entity is used, this will be an instance of {@link org.hibernate.envers.DefaultRevisionEntity}
  4. - *
  5. type of the revision (an enum instance of class {@link org.hibernate.envers.RevisionType})
  6. . - *
- * Additional conditions that the results must satisfy may be specified. - * @param c Class of the entities for which to query. - * @param selectEntitiesOnly If true, instead of a list of three-element arrays, a list of entites will be - * returned as a result of executing this query. - * @param selectDeletedEntities If true, also revisions where entities were deleted will be returned. The additional - * entities will have revision type "delete", and contain no data (all fields null), except for the id field. - * @return A query for revisions at which instances of the given entity were modified, to which - * conditions can be added (for example - a specific id of an entity of class c), and which - * can then be executed. The results of the query will be sorted in ascending order by the revision number, - * unless an order or projection is added. - */ - public AuditQuery forRevisionsOfEntity(Class c, boolean selectEntitiesOnly, boolean selectDeletedEntities) { - c = getTargetClassIfProxied(c); - return new RevisionsOfEntityQuery(auditCfg, auditReaderImplementor, c, selectEntitiesOnly,selectDeletedEntities); - } - - /** - * Creates a query, which selects the revisions, at which the given entity was modified and with a given entityName. - * Unless an explicit projection is set, the result will be a list of three-element arrays, containing: - *
    - *
  1. the entity instance
  2. - *
  3. revision entity, corresponding to the revision at which the entity was modified. If no custom - * revision entity is used, this will be an instance of {@link org.hibernate.envers.DefaultRevisionEntity}
  4. - *
  5. type of the revision (an enum instance of class {@link org.hibernate.envers.RevisionType})
  6. . - *
- * Additional conditions that the results must satisfy may be specified. - * @param c Class of the entities for which to query. - * @param entityName Name of the entity (if can't be guessed basing on the {@code c}). - * @param selectEntitiesOnly If true, instead of a list of three-element arrays, a list of entites will be - * returned as a result of executing this query. - * @param selectDeletedEntities If true, also revisions where entities were deleted will be returned. The additional - * entities will have revision type "delete", and contain no data (all fields null), except for the id field. - * @return A query for revisions at which instances of the given entity were modified, to which - * conditions can be added (for example - a specific id of an entity of class c), and which - * can then be executed. The results of the query will be sorted in ascending order by the revision number, - * unless an order or projection is added. - */ - public AuditQuery forRevisionsOfEntity(Class c, String entityName, boolean selectEntitiesOnly, boolean selectDeletedEntities) { - c = getTargetClassIfProxied(c); - return new RevisionsOfEntityQuery(auditCfg, auditReaderImplementor, c, entityName, selectEntitiesOnly,selectDeletedEntities); - } + /** + * Creates a query, which will return entities modified at the specified revision. + *

+ * In comparison, the {@link #forEntitiesAtRevision(Class, String, Number)} query takes into all entities + * which were present at a given revision, even if they were not modified. + * + * @param c Class of the entities for which to query. + * @param revision Revision number at which to execute the query. + * + * @return A query for entities changed at a given revision, to which conditions can be added and which + * can then be executed. + * + * @see #forEntitiesAtRevision(Class, Number) + */ + public AuditQuery forEntitiesModifiedAtRevision(Class c, Number revision) { + checkNotNull( revision, "Entity revision" ); + checkPositive( revision, "Entity revision" ); + c = getTargetClassIfProxied( c ); + return new EntitiesModifiedAtRevisionQuery( auditCfg, auditReaderImplementor, c, revision ); + } + + /** + * Creates a query, which selects the revisions, at which the given entity was modified. + * Unless an explicit projection is set, the result will be a list of three-element arrays, containing: + *

    + *
  1. the entity instance
  2. + *
  3. revision entity, corresponding to the revision at which the entity was modified. If no custom + * revision entity is used, this will be an instance of {@link org.hibernate.envers.DefaultRevisionEntity}
  4. + *
  5. type of the revision (an enum instance of class {@link org.hibernate.envers.RevisionType})
  6. . + *
+ * Additional conditions that the results must satisfy may be specified. + * + * @param c Class of the entities for which to query. + * @param selectEntitiesOnly If true, instead of a list of three-element arrays, a list of entites will be + * returned as a result of executing this query. + * @param selectDeletedEntities If true, also revisions where entities were deleted will be returned. The additional + * entities will have revision type "delete", and contain no data (all fields null), except for the id field. + * + * @return A query for revisions at which instances of the given entity were modified, to which + * conditions can be added (for example - a specific id of an entity of class c), and which + * can then be executed. The results of the query will be sorted in ascending order by the revision number, + * unless an order or projection is added. + */ + public AuditQuery forRevisionsOfEntity(Class c, boolean selectEntitiesOnly, boolean selectDeletedEntities) { + c = getTargetClassIfProxied( c ); + return new RevisionsOfEntityQuery( + auditCfg, + auditReaderImplementor, + c, + selectEntitiesOnly, + selectDeletedEntities + ); + } + + /** + * Creates a query, which selects the revisions, at which the given entity was modified and with a given entityName. + * Unless an explicit projection is set, the result will be a list of three-element arrays, containing: + *
    + *
  1. the entity instance
  2. + *
  3. revision entity, corresponding to the revision at which the entity was modified. If no custom + * revision entity is used, this will be an instance of {@link org.hibernate.envers.DefaultRevisionEntity}
  4. + *
  5. type of the revision (an enum instance of class {@link org.hibernate.envers.RevisionType})
  6. . + *
+ * Additional conditions that the results must satisfy may be specified. + * + * @param c Class of the entities for which to query. + * @param entityName Name of the entity (if can't be guessed basing on the {@code c}). + * @param selectEntitiesOnly If true, instead of a list of three-element arrays, a list of entites will be + * returned as a result of executing this query. + * @param selectDeletedEntities If true, also revisions where entities were deleted will be returned. The additional + * entities will have revision type "delete", and contain no data (all fields null), except for the id field. + * + * @return A query for revisions at which instances of the given entity were modified, to which + * conditions can be added (for example - a specific id of an entity of class c), and which + * can then be executed. The results of the query will be sorted in ascending order by the revision number, + * unless an order or projection is added. + */ + public AuditQuery forRevisionsOfEntity( + Class c, + String entityName, + boolean selectEntitiesOnly, + boolean selectDeletedEntities) { + c = getTargetClassIfProxied( c ); + return new RevisionsOfEntityQuery( + auditCfg, + auditReaderImplementor, + c, + entityName, + selectEntitiesOnly, + selectDeletedEntities + ); + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AggregatedAuditExpression.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AggregatedAuditExpression.java index 1bd81eae31..ac232152a5 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AggregatedAuditExpression.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AggregatedAuditExpression.java @@ -38,53 +38,59 @@ import org.hibernate.envers.query.internal.property.PropertyNameGetter; * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public class AggregatedAuditExpression implements AuditCriterion, ExtendableCriterion { - private PropertyNameGetter propertyNameGetter; - private AggregatedMode mode; + private PropertyNameGetter propertyNameGetter; + private AggregatedMode mode; private boolean correlate = false; // Correlate subquery with outer query by entity id. - private List criterions; + private List criterions; - public AggregatedAuditExpression(PropertyNameGetter propertyNameGetter, AggregatedMode mode) { - this.propertyNameGetter = propertyNameGetter; - this.mode = mode; - criterions = new ArrayList(); - } + public AggregatedAuditExpression(PropertyNameGetter propertyNameGetter, AggregatedMode mode) { + this.propertyNameGetter = propertyNameGetter; + this.mode = mode; + criterions = new ArrayList(); + } - public static enum AggregatedMode { - MAX, - MIN - } + public static enum AggregatedMode { + MAX, + MIN + } - public AggregatedAuditExpression add(AuditCriterion criterion) { - criterions.add(criterion); - return this; - } + public AggregatedAuditExpression add(AuditCriterion criterion) { + criterions.add( criterion ); + return this; + } - public void addToQuery(AuditConfiguration auditCfg, AuditReaderImplementor versionsReader, String entityName, - QueryBuilder qb, Parameters parameters) { - String propertyName = CriteriaTools.determinePropertyName( auditCfg, versionsReader, entityName, propertyNameGetter ); + public void addToQuery( + AuditConfiguration auditCfg, AuditReaderImplementor versionsReader, String entityName, + QueryBuilder qb, Parameters parameters) { + String propertyName = CriteriaTools.determinePropertyName( + auditCfg, + versionsReader, + entityName, + propertyNameGetter + ); - CriteriaTools.checkPropertyNotARelation(auditCfg, entityName, propertyName); + CriteriaTools.checkPropertyNotARelation( auditCfg, entityName, propertyName ); - // Make sure our conditions are ANDed together even if the parent Parameters have a different connective - Parameters subParams = parameters.addSubParameters(Parameters.AND); - // This will be the aggregated query, containing all the specified conditions - QueryBuilder subQb = qb.newSubQueryBuilder(); + // Make sure our conditions are ANDed together even if the parent Parameters have a different connective + Parameters subParams = parameters.addSubParameters( Parameters.AND ); + // This will be the aggregated query, containing all the specified conditions + QueryBuilder subQb = qb.newSubQueryBuilder(); - // Adding all specified conditions both to the main query, as well as to the - // aggregated one. - for (AuditCriterion versionsCriteria : criterions) { - versionsCriteria.addToQuery(auditCfg, versionsReader, entityName, qb, subParams); - versionsCriteria.addToQuery(auditCfg, versionsReader, entityName, subQb, subQb.getRootParameters()); - } + // Adding all specified conditions both to the main query, as well as to the + // aggregated one. + for ( AuditCriterion versionsCriteria : criterions ) { + versionsCriteria.addToQuery( auditCfg, versionsReader, entityName, qb, subParams ); + versionsCriteria.addToQuery( auditCfg, versionsReader, entityName, subQb, subQb.getRootParameters() ); + } - // Setting the desired projection of the aggregated query - switch (mode) { - case MIN: - subQb.addProjection("min", propertyName, false); - break; - case MAX: - subQb.addProjection("max", propertyName, false); - } + // Setting the desired projection of the aggregated query + switch ( mode ) { + case MIN: + subQb.addProjection( "min", propertyName, false ); + break; + case MAX: + subQb.addProjection( "max", propertyName, false ); + } // Correlating subquery with the outer query by entity id. See JIRA HHH-7827. if ( correlate ) { @@ -96,14 +102,15 @@ public class AggregatedAuditExpression implements AuditCriterion, ExtendableCrit ); } - // Adding the constrain on the result of the aggregated criteria - subParams.addWhere(propertyName, "=", subQb); - } + // Adding the constrain on the result of the aggregated criteria + subParams.addWhere( propertyName, "=", subQb ); + } /** * Compute aggregated expression in the context of each entity instance separately. Useful for retrieving latest * revisions of all entities of a particular type.
* Implementation note: Correlates subquery with the outer query by entity id. + * * @return this (for method chaining). */ public AggregatedAuditExpression computeAggregationInInstanceContext() { diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AuditConjunction.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AuditConjunction.java index 88db0426c5..4caa107934 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AuditConjunction.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AuditConjunction.java @@ -35,27 +35,29 @@ import org.hibernate.envers.internal.tools.query.QueryBuilder; * @author Adam Warski (adam at warski dot org) */ public class AuditConjunction implements AuditCriterion, ExtendableCriterion { - private List criterions; + private List criterions; - public AuditConjunction() { - criterions = new ArrayList(); - } + public AuditConjunction() { + criterions = new ArrayList(); + } - public AuditConjunction add(AuditCriterion criterion) { - criterions.add(criterion); - return this; - } + public AuditConjunction add(AuditCriterion criterion) { + criterions.add( criterion ); + return this; + } - public void addToQuery(AuditConfiguration verCfg, AuditReaderImplementor versionsReader, String entityName, - QueryBuilder qb, Parameters parameters) { - Parameters andParameters = parameters.addSubParameters(Parameters.AND); + public void addToQuery( + AuditConfiguration verCfg, AuditReaderImplementor versionsReader, String entityName, + QueryBuilder qb, Parameters parameters) { + Parameters andParameters = parameters.addSubParameters( Parameters.AND ); - if (criterions.size() == 0) { - andParameters.addWhere("1", false, "=", "1", false); - } else { - for (AuditCriterion criterion : criterions) { - criterion.addToQuery(verCfg, versionsReader, entityName, qb, andParameters); - } - } - } + if ( criterions.size() == 0 ) { + andParameters.addWhere( "1", false, "=", "1", false ); + } + else { + for ( AuditCriterion criterion : criterions ) { + criterion.addToQuery( verCfg, versionsReader, entityName, qb, andParameters ); + } + } + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AuditCriterion.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AuditCriterion.java index 5be631cb23..e71e099c6c 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AuditCriterion.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AuditCriterion.java @@ -32,6 +32,7 @@ import org.hibernate.envers.internal.tools.query.QueryBuilder; * @author Adam Warski (adam at warski dot org) */ public interface AuditCriterion { - void addToQuery(AuditConfiguration auditCfg, AuditReaderImplementor versionsReader, String entityName, - QueryBuilder qb, Parameters parameters); + void addToQuery( + AuditConfiguration auditCfg, AuditReaderImplementor versionsReader, String entityName, + QueryBuilder qb, Parameters parameters); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AuditDisjunction.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AuditDisjunction.java index 4693f6374c..c7c6ed13d6 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AuditDisjunction.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AuditDisjunction.java @@ -35,27 +35,29 @@ import org.hibernate.envers.internal.tools.query.QueryBuilder; * @author Adam Warski (adam at warski dot org) */ public class AuditDisjunction implements AuditCriterion, ExtendableCriterion { - private List criterions; + private List criterions; - public AuditDisjunction() { - criterions = new ArrayList(); - } + public AuditDisjunction() { + criterions = new ArrayList(); + } - public AuditDisjunction add(AuditCriterion criterion) { - criterions.add(criterion); - return this; - } + public AuditDisjunction add(AuditCriterion criterion) { + criterions.add( criterion ); + return this; + } - public void addToQuery(AuditConfiguration verCfg, AuditReaderImplementor versionsReader, String entityName, - QueryBuilder qb, Parameters parameters) { - Parameters orParameters = parameters.addSubParameters(Parameters.OR); + public void addToQuery( + AuditConfiguration verCfg, AuditReaderImplementor versionsReader, String entityName, + QueryBuilder qb, Parameters parameters) { + Parameters orParameters = parameters.addSubParameters( Parameters.OR ); - if (criterions.size() == 0) { - orParameters.addWhere("0", false, "=", "1", false); - } else { - for (AuditCriterion criterion : criterions) { - criterion.addToQuery(verCfg, versionsReader, entityName, qb, orParameters); - } - } - } + if ( criterions.size() == 0 ) { + orParameters.addWhere( "0", false, "=", "1", false ); + } + else { + for ( AuditCriterion criterion : criterions ) { + criterion.addToQuery( verCfg, versionsReader, entityName, qb, orParameters ); + } + } + } } \ No newline at end of file diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AuditId.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AuditId.java index 08e5f138b4..6ffcc4cd45 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AuditId.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AuditId.java @@ -24,11 +24,11 @@ package org.hibernate.envers.query.criteria; import org.hibernate.envers.query.criteria.internal.IdentifierEqAuditExpression; -import org.hibernate.envers.query.projection.AuditProjection; -import org.hibernate.envers.query.projection.internal.PropertyAuditProjection; import org.hibernate.envers.query.internal.property.EntityPropertyName; import org.hibernate.envers.query.internal.property.OriginalIdPropertyName; import org.hibernate.envers.query.internal.property.PropertyNameGetter; +import org.hibernate.envers.query.projection.AuditProjection; +import org.hibernate.envers.query.projection.internal.PropertyAuditProjection; /** * Create restrictions and projections for the id of an audited entity. @@ -36,7 +36,7 @@ import org.hibernate.envers.query.internal.property.PropertyNameGetter; * @author Adam Warski (adam at warski dot org) * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ -@SuppressWarnings({ "JavaDoc" }) +@SuppressWarnings({"JavaDoc"}) public class AuditId extends AuditProperty { public static final String IDENTIFIER_PLACEHOLDER = "$$id$$"; private static final PropertyNameGetter identifierPropertyGetter = new EntityPropertyName( IDENTIFIER_PLACEHOLDER ); diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AuditProperty.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AuditProperty.java index a7824ea494..5e0f05be36 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AuditProperty.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AuditProperty.java @@ -34,246 +34,247 @@ import org.hibernate.envers.query.criteria.internal.NotNullAuditExpression; import org.hibernate.envers.query.criteria.internal.NullAuditExpression; import org.hibernate.envers.query.criteria.internal.PropertyAuditExpression; import org.hibernate.envers.query.criteria.internal.SimpleAuditExpression; +import org.hibernate.envers.query.internal.property.ModifiedFlagPropertyName; +import org.hibernate.envers.query.internal.property.PropertyNameGetter; import org.hibernate.envers.query.order.AuditOrder; import org.hibernate.envers.query.order.internal.PropertyAuditOrder; import org.hibernate.envers.query.projection.AuditProjection; import org.hibernate.envers.query.projection.internal.PropertyAuditProjection; -import org.hibernate.envers.query.internal.property.ModifiedFlagPropertyName; -import org.hibernate.envers.query.internal.property.PropertyNameGetter; /** * Create restrictions, projections and specify order for a property of an audited entity. + * * @author Adam Warski (adam at warski dot org) * @author Michal Skowronek (mskowr at o2 dot pl) */ @SuppressWarnings({"JavaDoc"}) public class AuditProperty implements AuditProjection { - private final PropertyNameGetter propertyNameGetter; + private final PropertyNameGetter propertyNameGetter; - public AuditProperty(PropertyNameGetter propertyNameGetter) { - this.propertyNameGetter = propertyNameGetter; - } + public AuditProperty(PropertyNameGetter propertyNameGetter) { + this.propertyNameGetter = propertyNameGetter; + } public AuditCriterion hasChanged() { - return new SimpleAuditExpression(new ModifiedFlagPropertyName(propertyNameGetter), true, "="); + return new SimpleAuditExpression( new ModifiedFlagPropertyName( propertyNameGetter ), true, "=" ); } public AuditCriterion hasNotChanged() { - return new SimpleAuditExpression(new ModifiedFlagPropertyName(propertyNameGetter), false, "="); + return new SimpleAuditExpression( new ModifiedFlagPropertyName( propertyNameGetter ), false, "=" ); } /** * Apply an "equal" constraint */ public AuditCriterion eq(T value) { - return new SimpleAuditExpression(propertyNameGetter, value, "="); + return new SimpleAuditExpression( propertyNameGetter, value, "=" ); } - /** + /** * Apply a "not equal" constraint */ public AuditCriterion ne(T value) { - return new SimpleAuditExpression(propertyNameGetter, value, "<>"); + return new SimpleAuditExpression( propertyNameGetter, value, "<>" ); } - /** + /** * Apply a "like" constraint */ public AuditCriterion like(T value) { - return new SimpleAuditExpression(propertyNameGetter, value, " like "); + return new SimpleAuditExpression( propertyNameGetter, value, " like " ); } - /** + /** * Apply a "like" constraint */ public AuditCriterion like(String value, MatchMode matchMode) { - return new SimpleAuditExpression(propertyNameGetter, matchMode.toMatchString(value), " like " ); + return new SimpleAuditExpression( propertyNameGetter, matchMode.toMatchString( value ), " like " ); } - /** + /** * Apply a "greater than" constraint */ public AuditCriterion gt(T value) { - return new SimpleAuditExpression(propertyNameGetter, value, ">"); + return new SimpleAuditExpression( propertyNameGetter, value, ">" ); } - /** + /** * Apply a "less than" constraint */ public AuditCriterion lt(T value) { - return new SimpleAuditExpression(propertyNameGetter, value, "<"); + return new SimpleAuditExpression( propertyNameGetter, value, "<" ); } - /** + /** * Apply a "less than or equal" constraint */ public AuditCriterion le(T value) { - return new SimpleAuditExpression(propertyNameGetter, value, "<="); + return new SimpleAuditExpression( propertyNameGetter, value, "<=" ); } - /** + /** * Apply a "greater than or equal" constraint */ public AuditCriterion ge(T value) { - return new SimpleAuditExpression(propertyNameGetter, value, ">="); + return new SimpleAuditExpression( propertyNameGetter, value, ">=" ); } - /** + /** * Apply a "between" constraint */ public AuditCriterion between(T lo, T hi) { - return new BetweenAuditExpression(propertyNameGetter, lo, hi); + return new BetweenAuditExpression( propertyNameGetter, lo, hi ); } - /** + /** * Apply an "in" constraint */ public AuditCriterion in(T[] values) { - return new InAuditExpression(propertyNameGetter, values); + return new InAuditExpression( propertyNameGetter, values ); } - /** + /** * Apply an "in" constraint */ public AuditCriterion in(Collection values) { - return new InAuditExpression(propertyNameGetter, values.toArray()); + return new InAuditExpression( propertyNameGetter, values.toArray() ); } - /** + /** * Apply an "is null" constraint */ public AuditCriterion isNull() { - return new NullAuditExpression(propertyNameGetter); + return new NullAuditExpression( propertyNameGetter ); } - /** + /** * Apply an "equal" constraint to another property */ public AuditCriterion eqProperty(String otherPropertyName) { - return new PropertyAuditExpression(propertyNameGetter, otherPropertyName, "="); + return new PropertyAuditExpression( propertyNameGetter, otherPropertyName, "=" ); } - /** + /** * Apply a "not equal" constraint to another property */ public AuditCriterion neProperty(String otherPropertyName) { - return new PropertyAuditExpression(propertyNameGetter, otherPropertyName, "<>"); + return new PropertyAuditExpression( propertyNameGetter, otherPropertyName, "<>" ); } - /** + /** * Apply a "less than" constraint to another property */ public AuditCriterion ltProperty(String otherPropertyName) { - return new PropertyAuditExpression(propertyNameGetter, otherPropertyName, "<"); + return new PropertyAuditExpression( propertyNameGetter, otherPropertyName, "<" ); } - /** + /** * Apply a "less than or equal" constraint to another property */ public AuditCriterion leProperty(String otherPropertyName) { - return new PropertyAuditExpression(propertyNameGetter, otherPropertyName, "<="); + return new PropertyAuditExpression( propertyNameGetter, otherPropertyName, "<=" ); } - /** + /** * Apply a "greater than" constraint to another property */ public AuditCriterion gtProperty(String otherPropertyName) { - return new PropertyAuditExpression(propertyNameGetter, otherPropertyName, ">"); + return new PropertyAuditExpression( propertyNameGetter, otherPropertyName, ">" ); } - /** + /** * Apply a "greater than or equal" constraint to another property */ public AuditCriterion geProperty(String otherPropertyName) { - return new PropertyAuditExpression(propertyNameGetter, otherPropertyName, ">="); + return new PropertyAuditExpression( propertyNameGetter, otherPropertyName, ">=" ); } - /** + /** * Apply an "is not null" constraint to the another property */ public AuditCriterion isNotNull() { - return new NotNullAuditExpression(propertyNameGetter); + return new NotNullAuditExpression( propertyNameGetter ); } - /** - * Apply a "maximalize" constraint, with the ability to specify further constraints on the maximized - * property - */ - public AggregatedAuditExpression maximize() { - return new AggregatedAuditExpression(propertyNameGetter, AggregatedAuditExpression.AggregatedMode.MAX); - } + /** + * Apply a "maximalize" constraint, with the ability to specify further constraints on the maximized + * property + */ + public AggregatedAuditExpression maximize() { + return new AggregatedAuditExpression( propertyNameGetter, AggregatedAuditExpression.AggregatedMode.MAX ); + } - /** - * Apply a "minimize" constraint, with the ability to specify further constraints on the minimized - * property - */ - public AggregatedAuditExpression minimize() { - return new AggregatedAuditExpression(propertyNameGetter, AggregatedAuditExpression.AggregatedMode.MIN); - } + /** + * Apply a "minimize" constraint, with the ability to specify further constraints on the minimized + * property + */ + public AggregatedAuditExpression minimize() { + return new AggregatedAuditExpression( propertyNameGetter, AggregatedAuditExpression.AggregatedMode.MIN ); + } - // Projections + // Projections - /** - * Projection on the maximum value - */ - public AuditProjection max() { - return new PropertyAuditProjection(propertyNameGetter, "max", false); - } + /** + * Projection on the maximum value + */ + public AuditProjection max() { + return new PropertyAuditProjection( propertyNameGetter, "max", false ); + } - /** - * Projection on the minimum value - */ - public AuditProjection min() { - return new PropertyAuditProjection(propertyNameGetter, "min", false); - } + /** + * Projection on the minimum value + */ + public AuditProjection min() { + return new PropertyAuditProjection( propertyNameGetter, "min", false ); + } - /** - * Projection counting the values - */ - public AuditProjection count() { - return new PropertyAuditProjection(propertyNameGetter, "count", false); - } + /** + * Projection counting the values + */ + public AuditProjection count() { + return new PropertyAuditProjection( propertyNameGetter, "count", false ); + } - /** - * Projection counting distinct values - */ - public AuditProjection countDistinct() { - return new PropertyAuditProjection(propertyNameGetter, "count", true); - } + /** + * Projection counting distinct values + */ + public AuditProjection countDistinct() { + return new PropertyAuditProjection( propertyNameGetter, "count", true ); + } - /** - * Projection on distinct values - */ - public AuditProjection distinct() { - return new PropertyAuditProjection(propertyNameGetter, null, true); - } + /** + * Projection on distinct values + */ + public AuditProjection distinct() { + return new PropertyAuditProjection( propertyNameGetter, null, true ); + } - /** - * Projection using a custom function - */ - public AuditProjection function(String functionName) { - return new PropertyAuditProjection(propertyNameGetter, functionName, false); - } + /** + * Projection using a custom function + */ + public AuditProjection function(String functionName) { + return new PropertyAuditProjection( propertyNameGetter, functionName, false ); + } - // Projection on this property + // Projection on this property - public Triple getData(AuditConfiguration auditCfg) { - return Triple.make(null, propertyNameGetter.get(auditCfg), false); - } + public Triple getData(AuditConfiguration auditCfg) { + return Triple.make( null, propertyNameGetter.get( auditCfg ), false ); + } - // Order + // Order - /** - * Sort the results by the property in ascending order - */ - public AuditOrder asc() { - return new PropertyAuditOrder(propertyNameGetter, true); - } + /** + * Sort the results by the property in ascending order + */ + public AuditOrder asc() { + return new PropertyAuditOrder( propertyNameGetter, true ); + } - /** - * Sort the results by the property in descending order - */ - public AuditOrder desc() { - return new PropertyAuditOrder(propertyNameGetter, false); - } + /** + * Sort the results by the property in descending order + */ + public AuditOrder desc() { + return new PropertyAuditOrder( propertyNameGetter, false ); + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AuditRelatedId.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AuditRelatedId.java index c18cac02eb..da90c6d1b0 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AuditRelatedId.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AuditRelatedId.java @@ -28,27 +28,28 @@ import org.hibernate.envers.query.internal.property.PropertyNameGetter; /** * Create restrictions on an id of an entity related to an audited entity. + * * @author Adam Warski (adam at warski dot org) */ @SuppressWarnings({"JavaDoc"}) public class AuditRelatedId { - private final PropertyNameGetter propertyNameGetter; + private final PropertyNameGetter propertyNameGetter; - public AuditRelatedId(PropertyNameGetter propertyNameGetter) { - this.propertyNameGetter = propertyNameGetter; - } + public AuditRelatedId(PropertyNameGetter propertyNameGetter) { + this.propertyNameGetter = propertyNameGetter; + } - /** + /** * Apply an "equal" constraint */ public AuditCriterion eq(Object id) { - return new RelatedAuditExpression(propertyNameGetter, id, true); + return new RelatedAuditExpression( propertyNameGetter, id, true ); } - /** + /** * Apply a "not equal" constraint */ public AuditCriterion ne(Object id) { - return new RelatedAuditExpression(propertyNameGetter, id, false); + return new RelatedAuditExpression( propertyNameGetter, id, false ); } } \ No newline at end of file diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/ExtendableCriterion.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/ExtendableCriterion.java index b79c60bd79..35cc1fbbc6 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/ExtendableCriterion.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/ExtendableCriterion.java @@ -28,5 +28,5 @@ package org.hibernate.envers.query.criteria; * @author Adam Warski (adam at warski dot org) */ public interface ExtendableCriterion { - public ExtendableCriterion add(AuditCriterion criterion); + public ExtendableCriterion add(AuditCriterion criterion); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/BetweenAuditExpression.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/BetweenAuditExpression.java index e86e65744b..90a2a95a97 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/BetweenAuditExpression.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/BetweenAuditExpression.java @@ -34,23 +34,29 @@ import org.hibernate.envers.query.internal.property.PropertyNameGetter; * @author Adam Warski (adam at warski dot org) */ public class BetweenAuditExpression implements AuditCriterion { - private PropertyNameGetter propertyNameGetter; - private Object lo; - private Object hi; + private PropertyNameGetter propertyNameGetter; + private Object lo; + private Object hi; - public BetweenAuditExpression(PropertyNameGetter propertyNameGetter, Object lo, Object hi) { - this.propertyNameGetter = propertyNameGetter; - this.lo = lo; - this.hi = hi; - } + public BetweenAuditExpression(PropertyNameGetter propertyNameGetter, Object lo, Object hi) { + this.propertyNameGetter = propertyNameGetter; + this.lo = lo; + this.hi = hi; + } - public void addToQuery(AuditConfiguration auditCfg, AuditReaderImplementor versionsReader, String entityName, - QueryBuilder qb, Parameters parameters) { - String propertyName = CriteriaTools.determinePropertyName( auditCfg, versionsReader, entityName, propertyNameGetter ); - CriteriaTools.checkPropertyNotARelation(auditCfg, entityName, propertyName); - - Parameters subParams = parameters.addSubParameters(Parameters.AND); - subParams.addWhereWithParam(propertyName, ">=", lo); - subParams.addWhereWithParam(propertyName, "<=", hi); - } + public void addToQuery( + AuditConfiguration auditCfg, AuditReaderImplementor versionsReader, String entityName, + QueryBuilder qb, Parameters parameters) { + String propertyName = CriteriaTools.determinePropertyName( + auditCfg, + versionsReader, + entityName, + propertyNameGetter + ); + CriteriaTools.checkPropertyNotARelation( auditCfg, entityName, propertyName ); + + Parameters subParams = parameters.addSubParameters( Parameters.AND ); + subParams.addWhereWithParam( propertyName, ">=", lo ); + subParams.addWhereWithParam( propertyName, "<=", hi ); + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/CriteriaTools.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/CriteriaTools.java index 6bf447f165..c49e766417 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/CriteriaTools.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/CriteriaTools.java @@ -35,35 +35,42 @@ import org.hibernate.envers.query.internal.property.PropertyNameGetter; * @author Adam Warski (adam at warski dot org) */ public abstract class CriteriaTools { - public static void checkPropertyNotARelation(AuditConfiguration verCfg, String entityName, - String propertyName) throws AuditException { - if (verCfg.getEntCfg().get(entityName).isRelation(propertyName)) { - throw new AuditException("This criterion cannot be used on a property that is " + - "a relation to another property."); - } - } + public static void checkPropertyNotARelation( + AuditConfiguration verCfg, String entityName, + String propertyName) throws AuditException { + if ( verCfg.getEntCfg().get( entityName ).isRelation( propertyName ) ) { + throw new AuditException( + "This criterion cannot be used on a property that is " + + "a relation to another property." + ); + } + } - public static RelationDescription getRelatedEntity(AuditConfiguration verCfg, String entityName, - String propertyName) throws AuditException { - RelationDescription relationDesc = verCfg.getEntCfg().getRelationDescription(entityName, propertyName); + public static RelationDescription getRelatedEntity( + AuditConfiguration verCfg, String entityName, + String propertyName) throws AuditException { + RelationDescription relationDesc = verCfg.getEntCfg().getRelationDescription( entityName, propertyName ); - if (relationDesc == null) { - return null; - } + if ( relationDesc == null ) { + return null; + } - if (relationDesc.getRelationType() == RelationType.TO_ONE) { - return relationDesc; - } + if ( relationDesc.getRelationType() == RelationType.TO_ONE ) { + return relationDesc; + } - throw new AuditException("This type of relation (" + entityName + "." + propertyName + - ") isn't supported and can't be used in queries."); - } + throw new AuditException( + "This type of relation (" + entityName + "." + propertyName + + ") isn't supported and can't be used in queries." + ); + } /** * @see #determinePropertyName(AuditConfiguration, AuditReaderImplementor, String, String) */ - public static String determinePropertyName(AuditConfiguration auditCfg, AuditReaderImplementor versionsReader, - String entityName, PropertyNameGetter propertyNameGetter) { + public static String determinePropertyName( + AuditConfiguration auditCfg, AuditReaderImplementor versionsReader, + String entityName, PropertyNameGetter propertyNameGetter) { return determinePropertyName( auditCfg, versionsReader, entityName, propertyNameGetter.get( auditCfg ) ); } @@ -72,12 +79,17 @@ public abstract class CriteriaTools { * @param versionsReader Versions reader. * @param entityName Original entity name (not audited). * @param propertyName Property name or placeholder. + * * @return Path to property. Handles identifier placeholder used by {@link org.hibernate.envers.query.criteria.AuditId}. */ - public static String determinePropertyName(AuditConfiguration auditCfg, AuditReaderImplementor versionsReader, - String entityName, String propertyName) { + public static String determinePropertyName( + AuditConfiguration auditCfg, AuditReaderImplementor versionsReader, + String entityName, String propertyName) { if ( AuditId.IDENTIFIER_PLACEHOLDER.equals( propertyName ) ) { - final String identifierPropertyName = versionsReader.getSessionImplementor().getFactory().getEntityPersister( entityName ).getIdentifierPropertyName(); + final String identifierPropertyName = versionsReader.getSessionImplementor() + .getFactory() + .getEntityPersister( entityName ) + .getIdentifierPropertyName(); propertyName = auditCfg.getAuditEntCfg().getOriginalIdPropName() + "." + identifierPropertyName; } return propertyName; diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/IdentifierEqAuditExpression.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/IdentifierEqAuditExpression.java index 1e916c987c..6f81d26b01 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/IdentifierEqAuditExpression.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/IdentifierEqAuditExpression.java @@ -31,20 +31,22 @@ import org.hibernate.envers.query.criteria.AuditCriterion; /** * A criterion that expresses that the id of an entity is equal or not equal to some specified value. + * * @author Adam Warski (adam at warski dot org) */ public class IdentifierEqAuditExpression implements AuditCriterion { - private final Object id; - private final boolean equals; + private final Object id; + private final boolean equals; - public IdentifierEqAuditExpression(Object id, boolean equals) { - this.id = id; - this.equals = equals; - } + public IdentifierEqAuditExpression(Object id, boolean equals) { + this.id = id; + this.equals = equals; + } - public void addToQuery(AuditConfiguration verCfg, AuditReaderImplementor versionsReader, String entityName, - QueryBuilder qb, Parameters parameters) { - verCfg.getEntCfg().get(entityName).getIdMapper() - .addIdEqualsToQuery(parameters, id, verCfg.getAuditEntCfg().getOriginalIdPropName(), equals); - } + public void addToQuery( + AuditConfiguration verCfg, AuditReaderImplementor versionsReader, String entityName, + QueryBuilder qb, Parameters parameters) { + verCfg.getEntCfg().get( entityName ).getIdMapper() + .addIdEqualsToQuery( parameters, id, verCfg.getAuditEntCfg().getOriginalIdPropName(), equals ); + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/InAuditExpression.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/InAuditExpression.java index ea009093e4..8e9aca71a9 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/InAuditExpression.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/InAuditExpression.java @@ -28,25 +28,30 @@ import org.hibernate.envers.internal.reader.AuditReaderImplementor; import org.hibernate.envers.internal.tools.query.Parameters; import org.hibernate.envers.internal.tools.query.QueryBuilder; import org.hibernate.envers.query.criteria.AuditCriterion; -import org.hibernate.envers.query.criteria.internal.CriteriaTools; import org.hibernate.envers.query.internal.property.PropertyNameGetter; /** * @author Adam Warski (adam at warski dot org) */ public class InAuditExpression implements AuditCriterion { - private PropertyNameGetter propertyNameGetter; - private Object[] values; + private PropertyNameGetter propertyNameGetter; + private Object[] values; - public InAuditExpression(PropertyNameGetter propertyNameGetter, Object[] values) { - this.propertyNameGetter = propertyNameGetter; - this.values = values; - } + public InAuditExpression(PropertyNameGetter propertyNameGetter, Object[] values) { + this.propertyNameGetter = propertyNameGetter; + this.values = values; + } - public void addToQuery(AuditConfiguration auditCfg, AuditReaderImplementor versionsReader, String entityName, - QueryBuilder qb, Parameters parameters) { - String propertyName = CriteriaTools.determinePropertyName( auditCfg, versionsReader, entityName, propertyNameGetter ); - CriteriaTools.checkPropertyNotARelation(auditCfg, entityName, propertyName); - parameters.addWhereWithParams(propertyName, "in (", values, ")"); - } + public void addToQuery( + AuditConfiguration auditCfg, AuditReaderImplementor versionsReader, String entityName, + QueryBuilder qb, Parameters parameters) { + String propertyName = CriteriaTools.determinePropertyName( + auditCfg, + versionsReader, + entityName, + propertyNameGetter + ); + CriteriaTools.checkPropertyNotARelation( auditCfg, entityName, propertyName ); + parameters.addWhereWithParams( propertyName, "in (", values, ")" ); + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/LogicalAuditExpression.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/LogicalAuditExpression.java index d0f213965e..3888ac120d 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/LogicalAuditExpression.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/LogicalAuditExpression.java @@ -33,21 +33,22 @@ import org.hibernate.envers.query.criteria.AuditCriterion; * @author Adam Warski (adam at warski dot org) */ public class LogicalAuditExpression implements AuditCriterion { - private AuditCriterion lhs; - private AuditCriterion rhs; - private String op; + private AuditCriterion lhs; + private AuditCriterion rhs; + private String op; - public LogicalAuditExpression(AuditCriterion lhs, AuditCriterion rhs, String op) { - this.lhs = lhs; - this.rhs = rhs; - this.op = op; - } + public LogicalAuditExpression(AuditCriterion lhs, AuditCriterion rhs, String op) { + this.lhs = lhs; + this.rhs = rhs; + this.op = op; + } - public void addToQuery(AuditConfiguration verCfg, AuditReaderImplementor versionsReader, String entityName, - QueryBuilder qb, Parameters parameters) { - Parameters opParameters = parameters.addSubParameters(op); + public void addToQuery( + AuditConfiguration verCfg, AuditReaderImplementor versionsReader, String entityName, + QueryBuilder qb, Parameters parameters) { + Parameters opParameters = parameters.addSubParameters( op ); - lhs.addToQuery(verCfg, versionsReader, entityName, qb, opParameters.addSubParameters("and")); - rhs.addToQuery(verCfg, versionsReader, entityName, qb, opParameters.addSubParameters("and")); - } + lhs.addToQuery( verCfg, versionsReader, entityName, qb, opParameters.addSubParameters( "and" ) ); + rhs.addToQuery( verCfg, versionsReader, entityName, qb, opParameters.addSubParameters( "and" ) ); + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/NotAuditExpression.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/NotAuditExpression.java index cfb5d016ba..95075d29c5 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/NotAuditExpression.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/NotAuditExpression.java @@ -33,14 +33,15 @@ import org.hibernate.envers.query.criteria.AuditCriterion; * @author Adam Warski (adam at warski dot org) */ public class NotAuditExpression implements AuditCriterion { - private AuditCriterion criterion; + private AuditCriterion criterion; - public NotAuditExpression(AuditCriterion criterion) { - this.criterion = criterion; - } + public NotAuditExpression(AuditCriterion criterion) { + this.criterion = criterion; + } - public void addToQuery(AuditConfiguration verCfg, AuditReaderImplementor versionsReader, String entityName, - QueryBuilder qb, Parameters parameters) { - criterion.addToQuery(verCfg, versionsReader, entityName, qb, parameters.addNegatedParameters()); - } + public void addToQuery( + AuditConfiguration verCfg, AuditReaderImplementor versionsReader, String entityName, + QueryBuilder qb, Parameters parameters) { + criterion.addToQuery( verCfg, versionsReader, entityName, qb, parameters.addNegatedParameters() ); + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/NotNullAuditExpression.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/NotNullAuditExpression.java index 1a3bfc855e..b0d3c1f87b 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/NotNullAuditExpression.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/NotNullAuditExpression.java @@ -35,21 +35,28 @@ import org.hibernate.envers.query.internal.property.PropertyNameGetter; * @author Adam Warski (adam at warski dot org) */ public class NotNullAuditExpression implements AuditCriterion { - private PropertyNameGetter propertyNameGetter; + private PropertyNameGetter propertyNameGetter; - public NotNullAuditExpression(PropertyNameGetter propertyNameGetter) { - this.propertyNameGetter = propertyNameGetter; - } + public NotNullAuditExpression(PropertyNameGetter propertyNameGetter) { + this.propertyNameGetter = propertyNameGetter; + } - public void addToQuery(AuditConfiguration auditCfg, AuditReaderImplementor versionsReader, String entityName, - QueryBuilder qb, Parameters parameters) { - String propertyName = CriteriaTools.determinePropertyName( auditCfg, versionsReader, entityName, propertyNameGetter ); - RelationDescription relatedEntity = CriteriaTools.getRelatedEntity(auditCfg, entityName, propertyName); + public void addToQuery( + AuditConfiguration auditCfg, AuditReaderImplementor versionsReader, String entityName, + QueryBuilder qb, Parameters parameters) { + String propertyName = CriteriaTools.determinePropertyName( + auditCfg, + versionsReader, + entityName, + propertyNameGetter + ); + RelationDescription relatedEntity = CriteriaTools.getRelatedEntity( auditCfg, entityName, propertyName ); - if (relatedEntity == null) { - parameters.addNotNullRestriction(propertyName, true); - } else { - relatedEntity.getIdMapper().addIdEqualsToQuery(parameters, null, null, false); - } - } + if ( relatedEntity == null ) { + parameters.addNotNullRestriction( propertyName, true ); + } + else { + relatedEntity.getIdMapper().addIdEqualsToQuery( parameters, null, null, false ); + } + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/NullAuditExpression.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/NullAuditExpression.java index 5bfa5d97db..5caa070226 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/NullAuditExpression.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/NullAuditExpression.java @@ -35,21 +35,28 @@ import org.hibernate.envers.query.internal.property.PropertyNameGetter; * @author Adam Warski (adam at warski dot org) */ public class NullAuditExpression implements AuditCriterion { - private PropertyNameGetter propertyNameGetter; + private PropertyNameGetter propertyNameGetter; - public NullAuditExpression(PropertyNameGetter propertyNameGetter) { - this.propertyNameGetter = propertyNameGetter; - } + public NullAuditExpression(PropertyNameGetter propertyNameGetter) { + this.propertyNameGetter = propertyNameGetter; + } - public void addToQuery(AuditConfiguration auditCfg, AuditReaderImplementor versionsReader, String entityName, - QueryBuilder qb, Parameters parameters) { - String propertyName = CriteriaTools.determinePropertyName( auditCfg, versionsReader, entityName, propertyNameGetter ); - RelationDescription relatedEntity = CriteriaTools.getRelatedEntity(auditCfg, entityName, propertyName); + public void addToQuery( + AuditConfiguration auditCfg, AuditReaderImplementor versionsReader, String entityName, + QueryBuilder qb, Parameters parameters) { + String propertyName = CriteriaTools.determinePropertyName( + auditCfg, + versionsReader, + entityName, + propertyNameGetter + ); + RelationDescription relatedEntity = CriteriaTools.getRelatedEntity( auditCfg, entityName, propertyName ); - if (relatedEntity == null) { - parameters.addNullRestriction(propertyName, true); - } else { - relatedEntity.getIdMapper().addIdEqualsToQuery(parameters, null, null, true); - } - } + if ( relatedEntity == null ) { + parameters.addNullRestriction( propertyName, true ); + } + else { + relatedEntity.getIdMapper().addIdEqualsToQuery( parameters, null, null, true ); + } + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/PropertyAuditExpression.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/PropertyAuditExpression.java index ba2e6d741d..71f0402336 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/PropertyAuditExpression.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/PropertyAuditExpression.java @@ -34,21 +34,27 @@ import org.hibernate.envers.query.internal.property.PropertyNameGetter; * @author Adam Warski (adam at warski dot org) */ public class PropertyAuditExpression implements AuditCriterion { - private PropertyNameGetter propertyNameGetter; - private String otherPropertyName; - private String op; + private PropertyNameGetter propertyNameGetter; + private String otherPropertyName; + private String op; - public PropertyAuditExpression(PropertyNameGetter propertyNameGetter, String otherPropertyName, String op) { - this.propertyNameGetter = propertyNameGetter; - this.otherPropertyName = otherPropertyName; - this.op = op; - } + public PropertyAuditExpression(PropertyNameGetter propertyNameGetter, String otherPropertyName, String op) { + this.propertyNameGetter = propertyNameGetter; + this.otherPropertyName = otherPropertyName; + this.op = op; + } - public void addToQuery(AuditConfiguration auditCfg, AuditReaderImplementor versionsReader, String entityName, - QueryBuilder qb, Parameters parameters) { - String propertyName = CriteriaTools.determinePropertyName( auditCfg, versionsReader, entityName, propertyNameGetter ); - CriteriaTools.checkPropertyNotARelation(auditCfg, entityName, propertyName); - CriteriaTools.checkPropertyNotARelation(auditCfg, entityName, otherPropertyName); - parameters.addWhere(propertyName, op, otherPropertyName); - } + public void addToQuery( + AuditConfiguration auditCfg, AuditReaderImplementor versionsReader, String entityName, + QueryBuilder qb, Parameters parameters) { + String propertyName = CriteriaTools.determinePropertyName( + auditCfg, + versionsReader, + entityName, + propertyNameGetter + ); + CriteriaTools.checkPropertyNotARelation( auditCfg, entityName, propertyName ); + CriteriaTools.checkPropertyNotARelation( auditCfg, entityName, otherPropertyName ); + parameters.addWhere( propertyName, op, otherPropertyName ); + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/RelatedAuditExpression.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/RelatedAuditExpression.java index 8feefad4ac..b0c66db63a 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/RelatedAuditExpression.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/RelatedAuditExpression.java @@ -36,27 +36,36 @@ import org.hibernate.envers.query.internal.property.PropertyNameGetter; * @author Adam Warski (adam at warski dot org) */ public class RelatedAuditExpression implements AuditCriterion { - private final PropertyNameGetter propertyNameGetter; - private final Object id; - private final boolean equals; + private final PropertyNameGetter propertyNameGetter; + private final Object id; + private final boolean equals; - public RelatedAuditExpression(PropertyNameGetter propertyNameGetter, Object id, boolean equals) { - this.propertyNameGetter = propertyNameGetter; - this.id = id; - this.equals = equals; - } + public RelatedAuditExpression(PropertyNameGetter propertyNameGetter, Object id, boolean equals) { + this.propertyNameGetter = propertyNameGetter; + this.id = id; + this.equals = equals; + } - public void addToQuery(AuditConfiguration auditCfg, AuditReaderImplementor versionsReader, String entityName, - QueryBuilder qb, Parameters parameters) { - String propertyName = CriteriaTools.determinePropertyName( auditCfg, versionsReader, entityName, propertyNameGetter ); - - RelationDescription relatedEntity = CriteriaTools.getRelatedEntity(auditCfg, entityName, propertyName); + public void addToQuery( + AuditConfiguration auditCfg, AuditReaderImplementor versionsReader, String entityName, + QueryBuilder qb, Parameters parameters) { + String propertyName = CriteriaTools.determinePropertyName( + auditCfg, + versionsReader, + entityName, + propertyNameGetter + ); - if (relatedEntity == null) { - throw new AuditException("This criterion can only be used on a property that is " + - "a relation to another property."); - } else { - relatedEntity.getIdMapper().addIdEqualsToQuery(parameters, id, null, equals); - } - } + RelationDescription relatedEntity = CriteriaTools.getRelatedEntity( auditCfg, entityName, propertyName ); + + if ( relatedEntity == null ) { + throw new AuditException( + "This criterion can only be used on a property that is " + + "a relation to another property." + ); + } + else { + relatedEntity.getIdMapper().addIdEqualsToQuery( parameters, id, null, equals ); + } + } } \ No newline at end of file diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/RevisionTypeAuditExpression.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/RevisionTypeAuditExpression.java index 59f7b1b802..b08f371c3f 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/RevisionTypeAuditExpression.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/RevisionTypeAuditExpression.java @@ -33,16 +33,17 @@ import org.hibernate.envers.query.criteria.AuditCriterion; * @author Adam Warski (adam at warski dot org) */ public class RevisionTypeAuditExpression implements AuditCriterion { - private Object value; - private String op; + private Object value; + private String op; - public RevisionTypeAuditExpression(Object value, String op) { - this.value = value; - this.op = op; - } + public RevisionTypeAuditExpression(Object value, String op) { + this.value = value; + this.op = op; + } - public void addToQuery(AuditConfiguration verCfg, AuditReaderImplementor versionsReader, String entityName, - QueryBuilder qb, Parameters parameters) { - parameters.addWhereWithParam(verCfg.getAuditEntCfg().getRevisionTypePropName(), op, value); - } + public void addToQuery( + AuditConfiguration verCfg, AuditReaderImplementor versionsReader, String entityName, + QueryBuilder qb, Parameters parameters) { + parameters.addWhereWithParam( verCfg.getAuditEntCfg().getRevisionTypePropName(), op, value ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/SimpleAuditExpression.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/SimpleAuditExpression.java index 8307a90654..4fa8a076d3 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/SimpleAuditExpression.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/SimpleAuditExpression.java @@ -36,33 +36,42 @@ import org.hibernate.envers.query.internal.property.PropertyNameGetter; * @author Adam Warski (adam at warski dot org) */ public class SimpleAuditExpression implements AuditCriterion { - private PropertyNameGetter propertyNameGetter; - private Object value; - private String op; + private PropertyNameGetter propertyNameGetter; + private Object value; + private String op; - public SimpleAuditExpression(PropertyNameGetter propertyNameGetter, Object value, String op) { - this.propertyNameGetter = propertyNameGetter; - this.value = value; - this.op = op; - } + public SimpleAuditExpression(PropertyNameGetter propertyNameGetter, Object value, String op) { + this.propertyNameGetter = propertyNameGetter; + this.value = value; + this.op = op; + } - public void addToQuery(AuditConfiguration auditCfg, AuditReaderImplementor versionsReader, String entityName, - QueryBuilder qb, Parameters parameters) { - String propertyName = CriteriaTools.determinePropertyName( auditCfg, versionsReader, entityName, propertyNameGetter ); + public void addToQuery( + AuditConfiguration auditCfg, AuditReaderImplementor versionsReader, String entityName, + QueryBuilder qb, Parameters parameters) { + String propertyName = CriteriaTools.determinePropertyName( + auditCfg, + versionsReader, + entityName, + propertyNameGetter + ); - RelationDescription relatedEntity = CriteriaTools.getRelatedEntity(auditCfg, entityName, propertyName); + RelationDescription relatedEntity = CriteriaTools.getRelatedEntity( auditCfg, entityName, propertyName ); - if (relatedEntity == null) { - parameters.addWhereWithParam(propertyName, op, value); - } else { - if (!"=".equals(op) && !"<>".equals(op)) { - throw new AuditException("This type of operation: " + op + " (" + entityName + "." + propertyName + - ") isn't supported and can't be used in queries."); - } + if ( relatedEntity == null ) { + parameters.addWhereWithParam( propertyName, op, value ); + } + else { + if ( !"=".equals( op ) && !"<>".equals( op ) ) { + throw new AuditException( + "This type of operation: " + op + " (" + entityName + "." + propertyName + + ") isn't supported and can't be used in queries." + ); + } - Object id = relatedEntity.getIdMapper().mapToIdFromEntity(value); + Object id = relatedEntity.getIdMapper().mapToIdFromEntity( value ); - relatedEntity.getIdMapper().addIdEqualsToQuery(parameters, id, null, "=".equals(op)); - } - } + relatedEntity.getIdMapper().addIdEqualsToQuery( parameters, id, null, "=".equals( op ) ); + } + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/AbstractAuditQuery.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/AbstractAuditQuery.java index ec891363a0..ddcc1f3301 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/AbstractAuditQuery.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/AbstractAuditQuery.java @@ -23,10 +23,10 @@ */ package org.hibernate.envers.query.internal.impl; -import java.util.ArrayList; -import java.util.List; import javax.persistence.NoResultException; import javax.persistence.NonUniqueResultException; +import java.util.ArrayList; +import java.util.List; import org.hibernate.CacheMode; import org.hibernate.FlushMode; @@ -53,179 +53,214 @@ import static org.hibernate.envers.internal.entities.mapper.relation.query.Query * @author HernпїЅn Chanfreau */ public abstract class AbstractAuditQuery implements AuditQuery { - protected EntityInstantiator entityInstantiator; - protected List criterions; + protected EntityInstantiator entityInstantiator; + protected List criterions; - protected String entityName; - protected String entityClassName; - protected String versionsEntityName; - protected QueryBuilder qb; + protected String entityName; + protected String entityClassName; + protected String versionsEntityName; + protected QueryBuilder qb; - protected boolean hasProjection; - protected boolean hasOrder; + protected boolean hasProjection; + protected boolean hasOrder; - protected final AuditConfiguration verCfg; - protected final AuditReaderImplementor versionsReader; + protected final AuditConfiguration verCfg; + protected final AuditReaderImplementor versionsReader; - protected AbstractAuditQuery(AuditConfiguration verCfg, AuditReaderImplementor versionsReader, - Class cls) { - this(verCfg, versionsReader, cls, cls.getName()); - } + protected AbstractAuditQuery( + AuditConfiguration verCfg, AuditReaderImplementor versionsReader, + Class cls) { + this( verCfg, versionsReader, cls, cls.getName() ); + } - protected AbstractAuditQuery(AuditConfiguration verCfg, - AuditReaderImplementor versionsReader, Class cls, String entityName) { + protected AbstractAuditQuery( + AuditConfiguration verCfg, + AuditReaderImplementor versionsReader, Class cls, String entityName) { this.verCfg = verCfg; this.versionsReader = versionsReader; criterions = new ArrayList(); - entityInstantiator = new EntityInstantiator(verCfg, versionsReader); + entityInstantiator = new EntityInstantiator( verCfg, versionsReader ); entityClassName = cls.getName(); this.entityName = entityName; versionsEntityName = verCfg.getAuditEntCfg().getAuditEntityName( - entityName); + entityName + ); - qb = new QueryBuilder(versionsEntityName, REFERENCED_ENTITY_ALIAS); + qb = new QueryBuilder( versionsEntityName, REFERENCED_ENTITY_ALIAS ); } - - protected Query buildQuery() { - Query query = qb.toQuery(versionsReader.getSession()); - setQueryProperties(query); - return query; - } - + + protected Query buildQuery() { + Query query = qb.toQuery( versionsReader.getSession() ); + setQueryProperties( query ); + return query; + } + protected List buildAndExecuteQuery() { - Query query = buildQuery(); + Query query = buildQuery(); - return query.list(); - } + return query.list(); + } - public abstract List list() throws AuditException; + public abstract List list() throws AuditException; - public List getResultList() throws AuditException { - return list(); - } + public List getResultList() throws AuditException { + return list(); + } - public Object getSingleResult() throws AuditException, NonUniqueResultException, NoResultException { - List result = list(); + public Object getSingleResult() throws AuditException, NonUniqueResultException, NoResultException { + List result = list(); - if (result == null || result.size() == 0) { - throw new NoResultException(); - } + if ( result == null || result.size() == 0 ) { + throw new NoResultException(); + } - if (result.size() > 1) { - throw new NonUniqueResultException(); - } + if ( result.size() > 1 ) { + throw new NonUniqueResultException(); + } - return result.get(0); - } + return result.get( 0 ); + } - public AuditQuery add(AuditCriterion criterion) { - criterions.add(criterion); - return this; - } + public AuditQuery add(AuditCriterion criterion) { + criterions.add( criterion ); + return this; + } - // Projection and order + // Projection and order - public AuditQuery addProjection(AuditProjection projection) { - Triple projectionData = projection.getData(verCfg); - hasProjection = true; - String propertyName = CriteriaTools.determinePropertyName( verCfg, versionsReader, entityName, projectionData.getSecond() ); - qb.addProjection(projectionData.getFirst(), propertyName, projectionData.getThird()); - return this; - } + public AuditQuery addProjection(AuditProjection projection) { + Triple projectionData = projection.getData( verCfg ); + hasProjection = true; + String propertyName = CriteriaTools.determinePropertyName( + verCfg, + versionsReader, + entityName, + projectionData.getSecond() + ); + qb.addProjection( projectionData.getFirst(), propertyName, projectionData.getThird() ); + return this; + } - public AuditQuery addOrder(AuditOrder order) { - hasOrder = true; - Pair orderData = order.getData(verCfg); - String propertyName = CriteriaTools.determinePropertyName( verCfg, versionsReader, entityName, orderData.getFirst() ); - qb.addOrder(propertyName, orderData.getSecond()); - return this; - } + public AuditQuery addOrder(AuditOrder order) { + hasOrder = true; + Pair orderData = order.getData( verCfg ); + String propertyName = CriteriaTools.determinePropertyName( + verCfg, + versionsReader, + entityName, + orderData.getFirst() + ); + qb.addOrder( propertyName, orderData.getSecond() ); + return this; + } - // Query properties + // Query properties - private Integer maxResults; - private Integer firstResult; - private Boolean cacheable; - private String cacheRegion; - private String comment; - private FlushMode flushMode; - private CacheMode cacheMode; - private Integer timeout; - private LockOptions lockOptions = new LockOptions(LockMode.NONE); + private Integer maxResults; + private Integer firstResult; + private Boolean cacheable; + private String cacheRegion; + private String comment; + private FlushMode flushMode; + private CacheMode cacheMode; + private Integer timeout; + private LockOptions lockOptions = new LockOptions( LockMode.NONE ); - public AuditQuery setMaxResults(int maxResults) { - this.maxResults = maxResults; - return this; - } + public AuditQuery setMaxResults(int maxResults) { + this.maxResults = maxResults; + return this; + } - public AuditQuery setFirstResult(int firstResult) { - this.firstResult = firstResult; - return this; - } + public AuditQuery setFirstResult(int firstResult) { + this.firstResult = firstResult; + return this; + } - public AuditQuery setCacheable(boolean cacheable) { - this.cacheable = cacheable; - return this; - } + public AuditQuery setCacheable(boolean cacheable) { + this.cacheable = cacheable; + return this; + } - public AuditQuery setCacheRegion(String cacheRegion) { - this.cacheRegion = cacheRegion; - return this; - } + public AuditQuery setCacheRegion(String cacheRegion) { + this.cacheRegion = cacheRegion; + return this; + } - public AuditQuery setComment(String comment) { - this.comment = comment; - return this; - } + public AuditQuery setComment(String comment) { + this.comment = comment; + return this; + } - public AuditQuery setFlushMode(FlushMode flushMode) { - this.flushMode = flushMode; - return this; - } + public AuditQuery setFlushMode(FlushMode flushMode) { + this.flushMode = flushMode; + return this; + } - public AuditQuery setCacheMode(CacheMode cacheMode) { - this.cacheMode = cacheMode; - return this; - } + public AuditQuery setCacheMode(CacheMode cacheMode) { + this.cacheMode = cacheMode; + return this; + } - public AuditQuery setTimeout(int timeout) { - this.timeout = timeout; - return this; - } + public AuditQuery setTimeout(int timeout) { + this.timeout = timeout; + return this; + } /** * Set lock mode + * * @param lockMode The {@link LockMode} used for this query. + * * @return this object + * * @deprecated Instead use setLockOptions */ - public AuditQuery setLockMode(LockMode lockMode) { - lockOptions.setLockMode(lockMode); - return this; - } + public AuditQuery setLockMode(LockMode lockMode) { + lockOptions.setLockMode( lockMode ); + return this; + } /** * Set lock options + * * @param lockOptions The @{link LockOptions} used for this query. + * * @return this object */ public AuditQuery setLockOptions(LockOptions lockOptions) { - LockOptions.copy(lockOptions, this.lockOptions); + LockOptions.copy( lockOptions, this.lockOptions ); return this; } - protected void setQueryProperties(Query query) { - if (maxResults != null) query.setMaxResults(maxResults); - if (firstResult != null) query.setFirstResult(firstResult); - if (cacheable != null) query.setCacheable(cacheable); - if (cacheRegion != null) query.setCacheRegion(cacheRegion); - if (comment != null) query.setComment(comment); - if (flushMode != null) query.setFlushMode(flushMode); - if (cacheMode != null) query.setCacheMode(cacheMode); - if (timeout != null) query.setTimeout(timeout); - if (lockOptions != null && lockOptions.getLockMode() != LockMode.NONE) { - query.setLockMode(REFERENCED_ENTITY_ALIAS, lockOptions.getLockMode()); - } - } + + protected void setQueryProperties(Query query) { + if ( maxResults != null ) { + query.setMaxResults( maxResults ); + } + if ( firstResult != null ) { + query.setFirstResult( firstResult ); + } + if ( cacheable != null ) { + query.setCacheable( cacheable ); + } + if ( cacheRegion != null ) { + query.setCacheRegion( cacheRegion ); + } + if ( comment != null ) { + query.setComment( comment ); + } + if ( flushMode != null ) { + query.setFlushMode( flushMode ); + } + if ( cacheMode != null ) { + query.setCacheMode( cacheMode ); + } + if ( timeout != null ) { + query.setTimeout( timeout ); + } + if ( lockOptions != null && lockOptions.getLockMode() != LockMode.NONE ) { + query.setLockMode( REFERENCED_ENTITY_ALIAS, lockOptions.getLockMode() ); + } + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/EntitiesAtRevisionQuery.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/EntitiesAtRevisionQuery.java index 8f3930f29a..2bdbd2a7eb 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/EntitiesAtRevisionQuery.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/EntitiesAtRevisionQuery.java @@ -44,28 +44,30 @@ import static org.hibernate.envers.internal.entities.mapper.relation.query.Query * @author HernпїЅn Chanfreau */ public class EntitiesAtRevisionQuery extends AbstractAuditQuery { - private final Number revision; - private final boolean includeDeletions; + private final Number revision; + private final boolean includeDeletions; - public EntitiesAtRevisionQuery(AuditConfiguration verCfg, - AuditReaderImplementor versionsReader, Class cls, - Number revision, boolean includeDeletions) { - super(verCfg, versionsReader, cls); - this.revision = revision; - this.includeDeletions = includeDeletions; - } + public EntitiesAtRevisionQuery( + AuditConfiguration verCfg, + AuditReaderImplementor versionsReader, Class cls, + Number revision, boolean includeDeletions) { + super( verCfg, versionsReader, cls ); + this.revision = revision; + this.includeDeletions = includeDeletions; + } - public EntitiesAtRevisionQuery(AuditConfiguration verCfg, - AuditReaderImplementor versionsReader, Class cls, - String entityName, Number revision, boolean includeDeletions) { - super(verCfg, versionsReader, cls, entityName); - this.revision = revision; - this.includeDeletions = includeDeletions; - } - - @SuppressWarnings({"unchecked"}) - public List list() { - /* + public EntitiesAtRevisionQuery( + AuditConfiguration verCfg, + AuditReaderImplementor versionsReader, Class cls, + String entityName, Number revision, boolean includeDeletions) { + super( verCfg, versionsReader, cls, entityName ); + this.revision = revision; + this.includeDeletions = includeDeletions; + } + + @SuppressWarnings({"unchecked"}) + public List list() { + /* * The query that we need to create: * SELECT new list(e) FROM versionsReferencedEntity e * WHERE @@ -82,44 +84,58 @@ public class EntitiesAtRevisionQuery extends AbstractAuditQuery { * (only non-deleted entities) * e.revision_type != DEL */ - AuditEntitiesConfiguration verEntCfg = verCfg.getAuditEntCfg(); - String revisionPropertyPath = verEntCfg.getRevisionNumberPath(); - String originalIdPropertyName = verEntCfg.getOriginalIdPropName(); + AuditEntitiesConfiguration verEntCfg = verCfg.getAuditEntCfg(); + String revisionPropertyPath = verEntCfg.getRevisionNumberPath(); + String originalIdPropertyName = verEntCfg.getOriginalIdPropName(); - MiddleIdData referencedIdData = new MiddleIdData(verEntCfg, verCfg.getEntCfg().get(entityName).getIdMappingData(), - null, entityName, verCfg.getEntCfg().isVersioned(entityName)); + MiddleIdData referencedIdData = new MiddleIdData( + verEntCfg, verCfg.getEntCfg().get( entityName ).getIdMappingData(), + null, entityName, verCfg.getEntCfg().isVersioned( entityName ) + ); - // (selecting e entities at revision :revision) - // --> based on auditStrategy (see above) - verCfg.getAuditStrategy().addEntityAtRevisionRestriction(verCfg.getGlobalCfg(), qb, qb.getRootParameters(), - revisionPropertyPath, verEntCfg.getRevisionEndFieldName(), true, referencedIdData, - revisionPropertyPath, originalIdPropertyName, REFERENCED_ENTITY_ALIAS, REFERENCED_ENTITY_ALIAS_DEF_AUD_STR, true); + // (selecting e entities at revision :revision) + // --> based on auditStrategy (see above) + verCfg.getAuditStrategy().addEntityAtRevisionRestriction( + verCfg.getGlobalCfg(), + qb, + qb.getRootParameters(), + revisionPropertyPath, + verEntCfg.getRevisionEndFieldName(), + true, + referencedIdData, + revisionPropertyPath, + originalIdPropertyName, + REFERENCED_ENTITY_ALIAS, + REFERENCED_ENTITY_ALIAS_DEF_AUD_STR, + true + ); - if (!includeDeletions) { - // e.revision_type != DEL - qb.getRootParameters().addWhereWithParam(verEntCfg.getRevisionTypePropName(), "<>", RevisionType.DEL); - } + if ( !includeDeletions ) { + // e.revision_type != DEL + qb.getRootParameters().addWhereWithParam( verEntCfg.getRevisionTypePropName(), "<>", RevisionType.DEL ); + } - // all specified conditions - for (AuditCriterion criterion : criterions) { - criterion.addToQuery(verCfg, versionsReader, entityName, qb, qb.getRootParameters()); - } - - Query query = buildQuery(); - // add named parameter (only used for ValidAuditTimeStrategy) - List params = Arrays.asList(query.getNamedParameters()); - if (params.contains(REVISION_PARAMETER)) { - query.setParameter(REVISION_PARAMETER, revision); - } - List queryResult = query.list(); + // all specified conditions + for ( AuditCriterion criterion : criterions ) { + criterion.addToQuery( verCfg, versionsReader, entityName, qb, qb.getRootParameters() ); + } - if (hasProjection) { - return queryResult; - } else { - List result = new ArrayList(); - entityInstantiator.addInstancesFromVersionsEntities(entityName, result, queryResult, revision); + Query query = buildQuery(); + // add named parameter (only used for ValidAuditTimeStrategy) + List params = Arrays.asList( query.getNamedParameters() ); + if ( params.contains( REVISION_PARAMETER ) ) { + query.setParameter( REVISION_PARAMETER, revision ); + } + List queryResult = query.list(); - return result; - } - } + if ( hasProjection ) { + return queryResult; + } + else { + List result = new ArrayList(); + entityInstantiator.addInstancesFromVersionsEntities( entityName, result, queryResult, revision ); + + return result; + } + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/EntitiesModifiedAtRevisionQuery.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/EntitiesModifiedAtRevisionQuery.java index deb8f41b06..cd1dce0d68 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/EntitiesModifiedAtRevisionQuery.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/EntitiesModifiedAtRevisionQuery.java @@ -12,52 +12,56 @@ import org.hibernate.envers.query.criteria.AuditCriterion; /** * In comparison to {@link EntitiesAtRevisionQuery} this query returns an empty collection if an entity * of a certain type has not been changed in a given revision. - * @see EntitiesAtRevisionQuery + * * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) + * @see EntitiesAtRevisionQuery */ public class EntitiesModifiedAtRevisionQuery extends AbstractAuditQuery { - private final Number revision; + private final Number revision; - public EntitiesModifiedAtRevisionQuery(AuditConfiguration verCfg, AuditReaderImplementor versionsReader, - Class cls, Number revision) { - super(verCfg, versionsReader, cls); - this.revision = revision; - } + public EntitiesModifiedAtRevisionQuery( + AuditConfiguration verCfg, AuditReaderImplementor versionsReader, + Class cls, Number revision) { + super( verCfg, versionsReader, cls ); + this.revision = revision; + } - public EntitiesModifiedAtRevisionQuery(AuditConfiguration verCfg, AuditReaderImplementor versionsReader, - Class cls, String entityName, Number revision) { - super(verCfg, versionsReader, cls, entityName); - this.revision = revision; - } + public EntitiesModifiedAtRevisionQuery( + AuditConfiguration verCfg, AuditReaderImplementor versionsReader, + Class cls, String entityName, Number revision) { + super( verCfg, versionsReader, cls, entityName ); + this.revision = revision; + } - @SuppressWarnings({"unchecked"}) - public List list() { - /* + @SuppressWarnings({"unchecked"}) + public List list() { + /* * The query that we need to create: * SELECT new list(e) FROM versionsReferencedEntity e * WHERE * (all specified conditions, transformed, on the "e" entity) AND * e.revision = :revision */ - AuditEntitiesConfiguration verEntCfg = verCfg.getAuditEntCfg(); - String revisionPropertyPath = verEntCfg.getRevisionNumberPath(); - qb.getRootParameters().addWhereWithParam(revisionPropertyPath, "=", revision); + AuditEntitiesConfiguration verEntCfg = verCfg.getAuditEntCfg(); + String revisionPropertyPath = verEntCfg.getRevisionNumberPath(); + qb.getRootParameters().addWhereWithParam( revisionPropertyPath, "=", revision ); - // all specified conditions - for (AuditCriterion criterion : criterions) { - criterion.addToQuery(verCfg, versionsReader, entityName, qb, qb.getRootParameters()); - } + // all specified conditions + for ( AuditCriterion criterion : criterions ) { + criterion.addToQuery( verCfg, versionsReader, entityName, qb, qb.getRootParameters() ); + } - Query query = buildQuery(); - List queryResult = query.list(); + Query query = buildQuery(); + List queryResult = query.list(); - if (hasProjection) { - return queryResult; - } else { - List result = new ArrayList(); - entityInstantiator.addInstancesFromVersionsEntities(entityName, result, queryResult, revision); + if ( hasProjection ) { + return queryResult; + } + else { + List result = new ArrayList(); + entityInstantiator.addInstancesFromVersionsEntities( entityName, result, queryResult, revision ); - return result; - } - } + return result; + } + } } \ No newline at end of file diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/RevisionsOfEntityQuery.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/RevisionsOfEntityQuery.java index 93ca0742d3..b60bff02c5 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/RevisionsOfEntityQuery.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/RevisionsOfEntityQuery.java @@ -40,108 +40,124 @@ import org.hibernate.proxy.HibernateProxy; * @author HernпїЅn Chanfreau */ public class RevisionsOfEntityQuery extends AbstractAuditQuery { - private final boolean selectEntitiesOnly; - private final boolean selectDeletedEntities; + private final boolean selectEntitiesOnly; + private final boolean selectDeletedEntities; - public RevisionsOfEntityQuery(AuditConfiguration verCfg, - AuditReaderImplementor versionsReader, - Class cls, boolean selectEntitiesOnly, - boolean selectDeletedEntities) { - super(verCfg, versionsReader, cls); - - this.selectEntitiesOnly = selectEntitiesOnly; - this.selectDeletedEntities = selectDeletedEntities; - } - - public RevisionsOfEntityQuery(AuditConfiguration verCfg, - AuditReaderImplementor versionsReader, Class cls, String entityName, - boolean selectEntitiesOnly, boolean selectDeletedEntities) { - super(verCfg, versionsReader, cls, entityName); + public RevisionsOfEntityQuery( + AuditConfiguration verCfg, + AuditReaderImplementor versionsReader, + Class cls, boolean selectEntitiesOnly, + boolean selectDeletedEntities) { + super( verCfg, versionsReader, cls ); this.selectEntitiesOnly = selectEntitiesOnly; this.selectDeletedEntities = selectDeletedEntities; } - - private Number getRevisionNumber(Map versionsEntity) { - AuditEntitiesConfiguration verEntCfg = verCfg.getAuditEntCfg(); - String originalId = verEntCfg.getOriginalIdPropName(); - String revisionPropertyName = verEntCfg.getRevisionFieldName(); + public RevisionsOfEntityQuery( + AuditConfiguration verCfg, + AuditReaderImplementor versionsReader, Class cls, String entityName, + boolean selectEntitiesOnly, boolean selectDeletedEntities) { + super( verCfg, versionsReader, cls, entityName ); - Object revisionInfoObject = ((Map) versionsEntity.get(originalId)).get(revisionPropertyName); + this.selectEntitiesOnly = selectEntitiesOnly; + this.selectDeletedEntities = selectDeletedEntities; + } - if (revisionInfoObject instanceof HibernateProxy) { - return (Number) ((HibernateProxy) revisionInfoObject).getHibernateLazyInitializer().getIdentifier(); - } else { - // Not a proxy - must be read from cache or with a join - return verCfg.getRevisionInfoNumberReader().getRevisionNumber(revisionInfoObject); - } - } + private Number getRevisionNumber(Map versionsEntity) { + AuditEntitiesConfiguration verEntCfg = verCfg.getAuditEntCfg(); - @SuppressWarnings({"unchecked"}) - public List list() throws AuditException { - AuditEntitiesConfiguration verEntCfg = verCfg.getAuditEntCfg(); + String originalId = verEntCfg.getOriginalIdPropName(); + String revisionPropertyName = verEntCfg.getRevisionFieldName(); + + Object revisionInfoObject = ((Map) versionsEntity.get( originalId )).get( revisionPropertyName ); + + if ( revisionInfoObject instanceof HibernateProxy ) { + return (Number) ((HibernateProxy) revisionInfoObject).getHibernateLazyInitializer().getIdentifier(); + } + else { + // Not a proxy - must be read from cache or with a join + return verCfg.getRevisionInfoNumberReader().getRevisionNumber( revisionInfoObject ); + } + } + + @SuppressWarnings({"unchecked"}) + public List list() throws AuditException { + AuditEntitiesConfiguration verEntCfg = verCfg.getAuditEntCfg(); /* - The query that should be executed in the versions table: + The query that should be executed in the versions table: SELECT e (unless another projection is specified) FROM ent_ver e, rev_entity r WHERE e.revision_type != DEL (if selectDeletedEntities == false) AND e.revision = r.revision AND (all specified conditions, transformed, on the "e" entity) ORDER BY e.revision ASC (unless another order or projection is specified) - */ - if (!selectDeletedEntities) { - // e.revision_type != DEL AND - qb.getRootParameters().addWhereWithParam(verEntCfg.getRevisionTypePropName(), "<>", RevisionType.DEL); - } + */ + if ( !selectDeletedEntities ) { + // e.revision_type != DEL AND + qb.getRootParameters().addWhereWithParam( verEntCfg.getRevisionTypePropName(), "<>", RevisionType.DEL ); + } - // all specified conditions, transformed - for (AuditCriterion criterion : criterions) { - criterion.addToQuery(verCfg, versionsReader, entityName, qb, qb.getRootParameters()); - } + // all specified conditions, transformed + for ( AuditCriterion criterion : criterions ) { + criterion.addToQuery( verCfg, versionsReader, entityName, qb, qb.getRootParameters() ); + } - if (!hasProjection && !hasOrder) { - String revisionPropertyPath = verEntCfg.getRevisionNumberPath(); - qb.addOrder(revisionPropertyPath, true); - } + if ( !hasProjection && !hasOrder ) { + String revisionPropertyPath = verEntCfg.getRevisionNumberPath(); + qb.addOrder( revisionPropertyPath, true ); + } - if (!selectEntitiesOnly) { - qb.addFrom(verCfg.getAuditEntCfg().getRevisionInfoEntityName(), "r"); - qb.getRootParameters().addWhere(verCfg.getAuditEntCfg().getRevisionNumberPath(), true, "=", "r.id", false); - } + if ( !selectEntitiesOnly ) { + qb.addFrom( verCfg.getAuditEntCfg().getRevisionInfoEntityName(), "r" ); + qb.getRootParameters().addWhere( + verCfg.getAuditEntCfg().getRevisionNumberPath(), + true, + "=", + "r.id", + false + ); + } - List queryResult = buildAndExecuteQuery(); - if (hasProjection) { - return queryResult; - } else { - List entities = new ArrayList(); - String revisionTypePropertyName = verEntCfg.getRevisionTypePropName(); + List queryResult = buildAndExecuteQuery(); + if ( hasProjection ) { + return queryResult; + } + else { + List entities = new ArrayList(); + String revisionTypePropertyName = verEntCfg.getRevisionTypePropName(); - for (Object resultRow : queryResult) { - Map versionsEntity; - Object revisionData; + for ( Object resultRow : queryResult ) { + Map versionsEntity; + Object revisionData; - if (selectEntitiesOnly) { - versionsEntity = (Map) resultRow; - revisionData = null; - } else { - Object[] arrayResultRow = (Object[]) resultRow; - versionsEntity = (Map) arrayResultRow[0]; - revisionData = arrayResultRow[1]; - } + if ( selectEntitiesOnly ) { + versionsEntity = (Map) resultRow; + revisionData = null; + } + else { + Object[] arrayResultRow = (Object[]) resultRow; + versionsEntity = (Map) arrayResultRow[0]; + revisionData = arrayResultRow[1]; + } - Number revision = getRevisionNumber(versionsEntity); - - Object entity = entityInstantiator.createInstanceFromVersionsEntity(entityName, versionsEntity, revision); + Number revision = getRevisionNumber( versionsEntity ); - if (!selectEntitiesOnly) { - entities.add(new Object[] { entity, revisionData, versionsEntity.get(revisionTypePropertyName) }); - } else { - entities.add(entity); - } - } + Object entity = entityInstantiator.createInstanceFromVersionsEntity( + entityName, + versionsEntity, + revision + ); - return entities; - } - } + if ( !selectEntitiesOnly ) { + entities.add( new Object[] {entity, revisionData, versionsEntity.get( revisionTypePropertyName )} ); + } + else { + entities.add( entity ); + } + } + + return entities; + } + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/EntityPropertyName.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/EntityPropertyName.java index 7174136bca..daa6d925bf 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/EntityPropertyName.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/EntityPropertyName.java @@ -27,16 +27,17 @@ import org.hibernate.envers.configuration.spi.AuditConfiguration; /** * Used for specifying restrictions on a property of an audited entity. + * * @author Adam Warski (adam at warski dot org) */ public class EntityPropertyName implements PropertyNameGetter { - private final String propertyName; + private final String propertyName; - public EntityPropertyName(String propertyName) { - this.propertyName = propertyName; - } + public EntityPropertyName(String propertyName) { + this.propertyName = propertyName; + } - public String get(AuditConfiguration auditCfg) { - return propertyName; - } + public String get(AuditConfiguration auditCfg) { + return propertyName; + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/ModifiedFlagPropertyName.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/ModifiedFlagPropertyName.java index de4cedef35..902ddeebcb 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/ModifiedFlagPropertyName.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/ModifiedFlagPropertyName.java @@ -28,18 +28,20 @@ import org.hibernate.envers.configuration.spi.AuditConfiguration; /** * PropertyNameGetter for modified flags + * * @author Michal Skowronek (mskowr at o2 dot pl) */ public class ModifiedFlagPropertyName implements PropertyNameGetter { - private final PropertyNameGetter propertyNameGetter; + private final PropertyNameGetter propertyNameGetter; - public ModifiedFlagPropertyName(PropertyNameGetter propertyNameGetter) { - this.propertyNameGetter = propertyNameGetter; - } + public ModifiedFlagPropertyName(PropertyNameGetter propertyNameGetter) { + this.propertyNameGetter = propertyNameGetter; + } - public String get(AuditConfiguration auditCfg) { + public String get(AuditConfiguration auditCfg) { return MetadataTools.getModifiedFlagPropertyName( - propertyNameGetter.get(auditCfg), - auditCfg.getGlobalCfg().getModifiedFlagSuffix()); - } + propertyNameGetter.get( auditCfg ), + auditCfg.getGlobalCfg().getModifiedFlagSuffix() + ); + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/OriginalIdPropertyName.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/OriginalIdPropertyName.java index a6cbcbd462..5187efc0e2 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/OriginalIdPropertyName.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/OriginalIdPropertyName.java @@ -29,18 +29,17 @@ import org.hibernate.envers.query.criteria.AuditId; /** * Used for specifying restrictions on the identifier. * - * @deprecated To be removed together with {@link AuditId#count(String)} in version 5.0. - * * @author Adam Warski (adam at warski dot org) + * @deprecated To be removed together with {@link AuditId#count(String)} in version 5.0. */ public class OriginalIdPropertyName implements PropertyNameGetter { - private final String idPropertyName; + private final String idPropertyName; - public OriginalIdPropertyName(String idPropertyName) { - this.idPropertyName = idPropertyName; - } + public OriginalIdPropertyName(String idPropertyName) { + this.idPropertyName = idPropertyName; + } - public String get(AuditConfiguration auditCfg) { - return auditCfg.getAuditEntCfg().getOriginalIdPropName() + "." + idPropertyName; - } + public String get(AuditConfiguration auditCfg) { + return auditCfg.getAuditEntCfg().getOriginalIdPropName() + "." + idPropertyName; + } } \ No newline at end of file diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/PropertyNameGetter.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/PropertyNameGetter.java index e49475e23e..b8ce13b04a 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/PropertyNameGetter.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/PropertyNameGetter.java @@ -27,12 +27,14 @@ import org.hibernate.envers.configuration.spi.AuditConfiguration; /** * Provides a function to get the name of a property, which is used in a query, to apply some restrictions on it. + * * @author Adam Warski (adam at warski dot org) */ public interface PropertyNameGetter { - /** - * @param auditCfg Audit configuration. - * @return Name of the property, to be used in a query. - */ - public String get(AuditConfiguration auditCfg); + /** + * @param auditCfg Audit configuration. + * + * @return Name of the property, to be used in a query. + */ + public String get(AuditConfiguration auditCfg); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/RevisionNumberPropertyName.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/RevisionNumberPropertyName.java index 60530df288..640afaeb13 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/RevisionNumberPropertyName.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/RevisionNumberPropertyName.java @@ -27,10 +27,11 @@ import org.hibernate.envers.configuration.spi.AuditConfiguration; /** * Used for specifying restrictions on the revision number, corresponding to an audit entity. + * * @author Adam Warski (adam at warski dot org) */ public class RevisionNumberPropertyName implements PropertyNameGetter { - public String get(AuditConfiguration auditCfg) { - return auditCfg.getAuditEntCfg().getRevisionNumberPath(); - } + public String get(AuditConfiguration auditCfg) { + return auditCfg.getAuditEntCfg().getRevisionNumberPath(); + } } \ No newline at end of file diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/RevisionPropertyPropertyName.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/RevisionPropertyPropertyName.java index 93d300e223..64d4f15427 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/RevisionPropertyPropertyName.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/RevisionPropertyPropertyName.java @@ -27,16 +27,17 @@ import org.hibernate.envers.configuration.spi.AuditConfiguration; /** * Used for specifying restrictions on a property of the revision entity, which is associated with an audit entity. + * * @author Adam Warski (adam at warski dot org) */ public class RevisionPropertyPropertyName implements PropertyNameGetter { - private final String propertyName; + private final String propertyName; - public RevisionPropertyPropertyName(String propertyName) { - this.propertyName = propertyName; - } + public RevisionPropertyPropertyName(String propertyName) { + this.propertyName = propertyName; + } - public String get(AuditConfiguration auditCfg) { - return auditCfg.getAuditEntCfg().getRevisionPropPath(propertyName); - } + public String get(AuditConfiguration auditCfg) { + return auditCfg.getAuditEntCfg().getRevisionPropPath( propertyName ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/RevisionTypePropertyName.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/RevisionTypePropertyName.java index 772015d0ee..33b99d78ae 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/RevisionTypePropertyName.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/property/RevisionTypePropertyName.java @@ -27,10 +27,11 @@ import org.hibernate.envers.configuration.spi.AuditConfiguration; /** * Used for specifying restrictions on the revision number, corresponding to an audit entity. + * * @author Adam Warski (adam at warski dot org) */ public class RevisionTypePropertyName implements PropertyNameGetter { - public String get(AuditConfiguration auditCfg) { - return auditCfg.getAuditEntCfg().getRevisionTypePropName(); - } + public String get(AuditConfiguration auditCfg) { + return auditCfg.getAuditEntCfg().getRevisionTypePropName(); + } } \ No newline at end of file diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/order/AuditOrder.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/order/AuditOrder.java index 8575fc7115..d7c00b5eeb 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/order/AuditOrder.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/order/AuditOrder.java @@ -30,9 +30,10 @@ import org.hibernate.envers.tools.Pair; * @author Adam Warski (adam at warski dot org) */ public interface AuditOrder { - /** - * @param auditCfg Configuration. - * @return A pair: (property name, ascending?). - */ - Pair getData(AuditConfiguration auditCfg); + /** + * @param auditCfg Configuration. + * + * @return A pair: (property name, ascending?). + */ + Pair getData(AuditConfiguration auditCfg); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/order/internal/PropertyAuditOrder.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/order/internal/PropertyAuditOrder.java index 77ec0470f1..f1764f9c96 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/order/internal/PropertyAuditOrder.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/order/internal/PropertyAuditOrder.java @@ -32,15 +32,15 @@ import org.hibernate.envers.tools.Pair; * @author Adam Warski (adam at warski dot org) */ public class PropertyAuditOrder implements AuditOrder { - private final PropertyNameGetter propertyNameGetter; - private final boolean asc; + private final PropertyNameGetter propertyNameGetter; + private final boolean asc; - public PropertyAuditOrder(PropertyNameGetter propertyNameGetter, boolean asc) { - this.propertyNameGetter = propertyNameGetter; - this.asc = asc; - } + public PropertyAuditOrder(PropertyNameGetter propertyNameGetter, boolean asc) { + this.propertyNameGetter = propertyNameGetter; + this.asc = asc; + } - public Pair getData(AuditConfiguration auditCfg) { - return Pair.make(propertyNameGetter.get(auditCfg), asc); - } + public Pair getData(AuditConfiguration auditCfg) { + return Pair.make( propertyNameGetter.get( auditCfg ), asc ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/projection/AuditProjection.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/projection/AuditProjection.java index 469909787c..a1be2c6a63 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/projection/AuditProjection.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/projection/AuditProjection.java @@ -30,9 +30,10 @@ import org.hibernate.envers.internal.tools.Triple; * @author Adam Warski (adam at warski dot org) */ public interface AuditProjection { - /** - * @param auditCfg Configuration. - * @return A triple: (function name - possibly null, property name, add distinct?). - */ - Triple getData(AuditConfiguration auditCfg); + /** + * @param auditCfg Configuration. + * + * @return A triple: (function name - possibly null, property name, add distinct?). + */ + Triple getData(AuditConfiguration auditCfg); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/projection/internal/PropertyAuditProjection.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/projection/internal/PropertyAuditProjection.java index 9e3a4ee2a6..1f5b889749 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/projection/internal/PropertyAuditProjection.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/projection/internal/PropertyAuditProjection.java @@ -32,19 +32,19 @@ import org.hibernate.envers.query.projection.AuditProjection; * @author Adam Warski (adam at warski dot org) */ public class PropertyAuditProjection implements AuditProjection { - private final PropertyNameGetter propertyNameGetter; - private final String function; - private final boolean distinct; + private final PropertyNameGetter propertyNameGetter; + private final String function; + private final boolean distinct; - public PropertyAuditProjection(PropertyNameGetter propertyNameGetter, String function, boolean distinct) { - this.propertyNameGetter = propertyNameGetter; - this.function = function; - this.distinct = distinct; - } + public PropertyAuditProjection(PropertyNameGetter propertyNameGetter, String function, boolean distinct) { + this.propertyNameGetter = propertyNameGetter; + this.function = function; + this.distinct = distinct; + } - public Triple getData(AuditConfiguration auditCfg) { - String propertyName = propertyNameGetter.get(auditCfg); + public Triple getData(AuditConfiguration auditCfg) { + String propertyName = propertyNameGetter.get( auditCfg ); - return Triple.make(function, propertyName, distinct); - } + return Triple.make( function, propertyName, distinct ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/strategy/AuditStrategy.java b/hibernate-envers/src/main/java/org/hibernate/envers/strategy/AuditStrategy.java index 46ab08105d..7dedd7eb78 100755 --- a/hibernate-envers/src/main/java/org/hibernate/envers/strategy/AuditStrategy.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/strategy/AuditStrategy.java @@ -14,85 +14,97 @@ import org.hibernate.envers.internal.tools.query.QueryBuilder; /** * Behaviours of different audit strategy for populating audit data. - * + * * @author Stephanie Pau * @author Adam Warski (adam at warski dot org) */ public interface AuditStrategy { - /** - * Perform the persistence of audited data for regular entities. - * - * @param session Session, which can be used to persist the data. - * @param entityName Name of the entity, in which the audited change happens - * @param auditCfg Audit configuration - * @param id Id of the entity. - * @param data Audit data to persist - * @param revision Current revision data - */ - void perform(Session session, String entityName, AuditConfiguration auditCfg, Serializable id, Object data, - Object revision); + /** + * Perform the persistence of audited data for regular entities. + * + * @param session Session, which can be used to persist the data. + * @param entityName Name of the entity, in which the audited change happens + * @param auditCfg Audit configuration + * @param id Id of the entity. + * @param data Audit data to persist + * @param revision Current revision data + */ + void perform( + Session session, String entityName, AuditConfiguration auditCfg, Serializable id, Object data, + Object revision); - /** - * Perform the persistence of audited data for collection ("middle") entities. - * - * @param session Session, which can be used to persist the data. + /** + * Perform the persistence of audited data for collection ("middle") entities. + * + * @param session Session, which can be used to persist the data. * @param entityName Name of the entity, in which the audited change happens. * @param propertyName The name of the property holding the {@link PersistentCollection}. - * @param auditCfg Audit configuration - * @param persistentCollectionChangeData Collection change data to be persisted. - * @param revision Current revision data - */ - void performCollectionChange(Session session, String entityName, String propertyName, AuditConfiguration auditCfg, - PersistentCollectionChangeData persistentCollectionChangeData, Object revision); - + * @param auditCfg Audit configuration + * @param persistentCollectionChangeData Collection change data to be persisted. + * @param revision Current revision data + */ + void performCollectionChange( + Session session, String entityName, String propertyName, AuditConfiguration auditCfg, + PersistentCollectionChangeData persistentCollectionChangeData, Object revision); - /** + + /** * Update the rootQueryBuilder with an extra WHERE clause to restrict the revision for a two-entity relation. * This WHERE clause depends on the AuditStrategy, as follows: *
    - *
  • For {@link DefaultAuditStrategy} a subquery is created: + *
  • For {@link DefaultAuditStrategy} a subquery is created: *

    e.revision = (SELECT max(...) ...)

    *
  • - *
  • for {@link ValidityAuditStrategy} the revision-end column is used: + *
  • for {@link ValidityAuditStrategy} the revision-end column is used: *

    e.revision <= :revision and (e.endRevision > :revision or e.endRevision is null)

    *
  • *
- * + * * @param globalCfg the {@link GlobalConfiguration} - * @param rootQueryBuilder the {@link QueryBuilder} that will be updated - * @param parameters root parameters to which restrictions shall be added - * @param revisionProperty property of the revision column - * @param revisionEndProperty property of the revisionEnd column (only used for {@link ValidityAuditStrategy}) - * @param addAlias {@code boolean} indicator if a left alias is needed - * @param idData id-information for the two-entity relation (only used for {@link DefaultAuditStrategy}) - * @param revisionPropertyPath path of the revision property (only used for {@link ValidityAuditStrategy}) - * @param originalIdPropertyName name of the id property (only used for {@link ValidityAuditStrategy}) - * @param alias1 an alias used for subquery (only used for {@link ValidityAuditStrategy}) - * @param alias2 an alias used for subquery (only used for {@link ValidityAuditStrategy}) - * @param inclusive indicates whether revision number shall be treated as inclusive or exclusive - */ - void addEntityAtRevisionRestriction(GlobalConfiguration globalCfg, QueryBuilder rootQueryBuilder, Parameters parameters, - String revisionProperty, String revisionEndProperty, boolean addAlias, MiddleIdData idData, - String revisionPropertyPath, String originalIdPropertyName, String alias1, String alias2, boolean inclusive); - - /** - * Update the rootQueryBuilder with an extra WHERE clause to restrict the revision for a middle-entity - * association. This WHERE clause depends on the AuditStrategy, as follows: - *
    - *
  • For {@link DefaultAuditStrategy} a subquery is created: - *

    e.revision = (SELECT max(...) ...)

    - *
  • - *
  • for {@link ValidityAuditStrategy} the revision-end column is used: - *

    e.revision <= :revision and (e.endRevision > :revision or e.endRevision is null)

    - *
  • - *
- * * @param rootQueryBuilder the {@link QueryBuilder} that will be updated * @param parameters root parameters to which restrictions shall be added - * @param revisionProperty property of the revision column - * @param revisionEndProperty property of the revisionEnd column (only used for {@link ValidityAuditStrategy}) - * @param addAlias {@code boolean} indicator if a left alias is needed - * @param referencingIdData id-information for the middle-entity association (only used for {@link DefaultAuditStrategy}) + * @param revisionProperty property of the revision column + * @param revisionEndProperty property of the revisionEnd column (only used for {@link ValidityAuditStrategy}) + * @param addAlias {@code boolean} indicator if a left alias is needed + * @param idData id-information for the two-entity relation (only used for {@link DefaultAuditStrategy}) + * @param revisionPropertyPath path of the revision property (only used for {@link ValidityAuditStrategy}) + * @param originalIdPropertyName name of the id property (only used for {@link ValidityAuditStrategy}) + * @param alias1 an alias used for subquery (only used for {@link ValidityAuditStrategy}) + * @param alias2 an alias used for subquery (only used for {@link ValidityAuditStrategy}) + * @param inclusive indicates whether revision number shall be treated as inclusive or exclusive + */ + void addEntityAtRevisionRestriction( + GlobalConfiguration globalCfg, + QueryBuilder rootQueryBuilder, + Parameters parameters, + String revisionProperty, + String revisionEndProperty, + boolean addAlias, + MiddleIdData idData, + String revisionPropertyPath, + String originalIdPropertyName, + String alias1, + String alias2, + boolean inclusive); + + /** + * Update the rootQueryBuilder with an extra WHERE clause to restrict the revision for a middle-entity + * association. This WHERE clause depends on the AuditStrategy, as follows: + *
    + *
  • For {@link DefaultAuditStrategy} a subquery is created: + *

    e.revision = (SELECT max(...) ...)

    + *
  • + *
  • for {@link ValidityAuditStrategy} the revision-end column is used: + *

    e.revision <= :revision and (e.endRevision > :revision or e.endRevision is null)

    + *
  • + *
+ * + * @param rootQueryBuilder the {@link QueryBuilder} that will be updated + * @param parameters root parameters to which restrictions shall be added + * @param revisionProperty property of the revision column + * @param revisionEndProperty property of the revisionEnd column (only used for {@link ValidityAuditStrategy}) + * @param addAlias {@code boolean} indicator if a left alias is needed + * @param referencingIdData id-information for the middle-entity association (only used for {@link DefaultAuditStrategy}) * @param versionsMiddleEntityName name of the middle-entity * @param eeOriginalIdPropertyPath name of the id property (only used for {@link ValidityAuditStrategy}) * @param revisionPropertyPath path of the revision property (only used for {@link ValidityAuditStrategy}) @@ -101,8 +113,9 @@ public interface AuditStrategy { * @param inclusive indicates whether revision number shall be treated as inclusive or exclusive * @param componentDatas information about the middle-entity relation */ - void addAssociationAtRevisionRestriction(QueryBuilder rootQueryBuilder, Parameters parameters, String revisionProperty, - String revisionEndProperty, boolean addAlias, MiddleIdData referencingIdData, + void addAssociationAtRevisionRestriction( + QueryBuilder rootQueryBuilder, Parameters parameters, String revisionProperty, + String revisionEndProperty, boolean addAlias, MiddleIdData referencingIdData, String versionsMiddleEntityName, String eeOriginalIdPropertyPath, String revisionPropertyPath, String originalIdPropertyName, String alias1, boolean inclusive, MiddleComponentData... componentDatas); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/strategy/DefaultAuditStrategy.java b/hibernate-envers/src/main/java/org/hibernate/envers/strategy/DefaultAuditStrategy.java index 775cd39660..139fa7e3a3 100755 --- a/hibernate-envers/src/main/java/org/hibernate/envers/strategy/DefaultAuditStrategy.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/strategy/DefaultAuditStrategy.java @@ -22,65 +22,102 @@ import static org.hibernate.envers.internal.entities.mapper.relation.query.Query * @author Stephanie Pau */ public class DefaultAuditStrategy implements AuditStrategy { - private final SessionCacheCleaner sessionCacheCleaner; + private final SessionCacheCleaner sessionCacheCleaner; - public DefaultAuditStrategy() { - sessionCacheCleaner = new SessionCacheCleaner(); - } - - public void perform(Session session, String entityName, AuditConfiguration auditCfg, Serializable id, Object data, - Object revision) { - session.save(auditCfg.getAuditEntCfg().getAuditEntityName(entityName), data); - sessionCacheCleaner.scheduleAuditDataRemoval(session, data); - } - - public void performCollectionChange(Session session, String entityName, String propertyName, AuditConfiguration auditCfg, - PersistentCollectionChangeData persistentCollectionChangeData, Object revision) { - session.save(persistentCollectionChangeData.getEntityName(), persistentCollectionChangeData.getData()); - sessionCacheCleaner.scheduleAuditDataRemoval(session, persistentCollectionChangeData.getData()); - } - - - public void addEntityAtRevisionRestriction(GlobalConfiguration globalCfg, QueryBuilder rootQueryBuilder, Parameters parameters, - String revisionProperty, String revisionEndProperty, boolean addAlias, MiddleIdData idData, String revisionPropertyPath, - String originalIdPropertyName, String alias1, String alias2, boolean inclusive) { - // create a subquery builder - // SELECT max(e.revision) FROM versionsReferencedEntity e2 - QueryBuilder maxERevQb = rootQueryBuilder.newSubQueryBuilder(idData.getAuditEntityName(), alias2); - maxERevQb.addProjection("max", revisionPropertyPath, false); - // WHERE - Parameters maxERevQbParameters = maxERevQb.getRootParameters(); - // e2.revision <= :revision - maxERevQbParameters.addWhereWithNamedParam(revisionPropertyPath, inclusive ? "<=" : "<", REVISION_PARAMETER); - // e2.id_ref_ed = e.id_ref_ed - idData.getOriginalMapper().addIdsEqualToQuery(maxERevQbParameters, - alias1 + "." + originalIdPropertyName, alias2 +"." + originalIdPropertyName); - - // add subquery to rootParameters - String subqueryOperator = globalCfg.getCorrelatedSubqueryOperator(); - parameters.addWhere(revisionProperty, addAlias, subqueryOperator, maxERevQb); + public DefaultAuditStrategy() { + sessionCacheCleaner = new SessionCacheCleaner(); } - public void addAssociationAtRevisionRestriction(QueryBuilder rootQueryBuilder, Parameters parameters, String revisionProperty, - String revisionEndProperty, boolean addAlias, MiddleIdData referencingIdData, String versionsMiddleEntityName, - String eeOriginalIdPropertyPath, String revisionPropertyPath, String originalIdPropertyName, String alias1, - boolean inclusive, MiddleComponentData... componentDatas) { - // SELECT max(ee2.revision) FROM middleEntity ee2 - QueryBuilder maxEeRevQb = rootQueryBuilder.newSubQueryBuilder(versionsMiddleEntityName, MIDDLE_ENTITY_ALIAS_DEF_AUD_STR); - maxEeRevQb.addProjection("max", revisionPropertyPath, false); - // WHERE - Parameters maxEeRevQbParameters = maxEeRevQb.getRootParameters(); - // ee2.revision <= :revision - maxEeRevQbParameters.addWhereWithNamedParam(revisionPropertyPath, inclusive ? "<=" : "<", REVISION_PARAMETER); - // ee2.originalId.* = ee.originalId.* - String ee2OriginalIdPropertyPath = MIDDLE_ENTITY_ALIAS_DEF_AUD_STR + "." + originalIdPropertyName; - referencingIdData.getPrefixedMapper().addIdsEqualToQuery(maxEeRevQbParameters, eeOriginalIdPropertyPath, ee2OriginalIdPropertyPath); - for (MiddleComponentData componentData : componentDatas) { - componentData.getComponentMapper().addMiddleEqualToQuery(maxEeRevQbParameters, eeOriginalIdPropertyPath, alias1, ee2OriginalIdPropertyPath, MIDDLE_ENTITY_ALIAS_DEF_AUD_STR); - } + public void perform( + Session session, String entityName, AuditConfiguration auditCfg, Serializable id, Object data, + Object revision) { + session.save( auditCfg.getAuditEntCfg().getAuditEntityName( entityName ), data ); + sessionCacheCleaner.scheduleAuditDataRemoval( session, data ); + } + + public void performCollectionChange( + Session session, String entityName, String propertyName, AuditConfiguration auditCfg, + PersistentCollectionChangeData persistentCollectionChangeData, Object revision) { + session.save( persistentCollectionChangeData.getEntityName(), persistentCollectionChangeData.getData() ); + sessionCacheCleaner.scheduleAuditDataRemoval( session, persistentCollectionChangeData.getData() ); + } + + + public void addEntityAtRevisionRestriction( + GlobalConfiguration globalCfg, + QueryBuilder rootQueryBuilder, + Parameters parameters, + String revisionProperty, + String revisionEndProperty, + boolean addAlias, + MiddleIdData idData, + String revisionPropertyPath, + String originalIdPropertyName, + String alias1, + String alias2, + boolean inclusive) { + // create a subquery builder + // SELECT max(e.revision) FROM versionsReferencedEntity e2 + QueryBuilder maxERevQb = rootQueryBuilder.newSubQueryBuilder( idData.getAuditEntityName(), alias2 ); + maxERevQb.addProjection( "max", revisionPropertyPath, false ); + // WHERE + Parameters maxERevQbParameters = maxERevQb.getRootParameters(); + // e2.revision <= :revision + maxERevQbParameters.addWhereWithNamedParam( revisionPropertyPath, inclusive ? "<=" : "<", REVISION_PARAMETER ); + // e2.id_ref_ed = e.id_ref_ed + idData.getOriginalMapper().addIdsEqualToQuery( + maxERevQbParameters, + alias1 + "." + originalIdPropertyName, alias2 + "." + originalIdPropertyName + ); // add subquery to rootParameters - parameters.addWhere(revisionProperty, addAlias, "=", maxEeRevQb); + String subqueryOperator = globalCfg.getCorrelatedSubqueryOperator(); + parameters.addWhere( revisionProperty, addAlias, subqueryOperator, maxERevQb ); + } + + public void addAssociationAtRevisionRestriction( + QueryBuilder rootQueryBuilder, + Parameters parameters, + String revisionProperty, + String revisionEndProperty, + boolean addAlias, + MiddleIdData referencingIdData, + String versionsMiddleEntityName, + String eeOriginalIdPropertyPath, + String revisionPropertyPath, + String originalIdPropertyName, + String alias1, + boolean inclusive, + MiddleComponentData... componentDatas) { + // SELECT max(ee2.revision) FROM middleEntity ee2 + QueryBuilder maxEeRevQb = rootQueryBuilder.newSubQueryBuilder( + versionsMiddleEntityName, + MIDDLE_ENTITY_ALIAS_DEF_AUD_STR + ); + maxEeRevQb.addProjection( "max", revisionPropertyPath, false ); + // WHERE + Parameters maxEeRevQbParameters = maxEeRevQb.getRootParameters(); + // ee2.revision <= :revision + maxEeRevQbParameters.addWhereWithNamedParam( revisionPropertyPath, inclusive ? "<=" : "<", REVISION_PARAMETER ); + // ee2.originalId.* = ee.originalId.* + String ee2OriginalIdPropertyPath = MIDDLE_ENTITY_ALIAS_DEF_AUD_STR + "." + originalIdPropertyName; + referencingIdData.getPrefixedMapper().addIdsEqualToQuery( + maxEeRevQbParameters, + eeOriginalIdPropertyPath, + ee2OriginalIdPropertyPath + ); + for ( MiddleComponentData componentData : componentDatas ) { + componentData.getComponentMapper().addMiddleEqualToQuery( + maxEeRevQbParameters, + eeOriginalIdPropertyPath, + alias1, + ee2OriginalIdPropertyPath, + MIDDLE_ENTITY_ALIAS_DEF_AUD_STR + ); + } + + // add subquery to rootParameters + parameters.addWhere( revisionProperty, addAlias, "=", maxEeRevQb ); } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/strategy/ValidTimeAuditStrategy.java b/hibernate-envers/src/main/java/org/hibernate/envers/strategy/ValidTimeAuditStrategy.java index bcb790b42f..2d641a0229 100755 --- a/hibernate-envers/src/main/java/org/hibernate/envers/strategy/ValidTimeAuditStrategy.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/strategy/ValidTimeAuditStrategy.java @@ -1,4 +1,5 @@ package org.hibernate.envers.strategy; + import org.jboss.logging.Logger; import org.hibernate.envers.internal.EnversMessageLogger; @@ -8,19 +9,21 @@ import org.hibernate.envers.internal.EnversMessageLogger; * * @author Stephanie Pau * @author Adam Warski (adam at warski dot org) - * * @deprecated use {@link ValidityAuditStrategy} instead. */ @Deprecated public class ValidTimeAuditStrategy extends ValidityAuditStrategy { - public static final EnversMessageLogger LOG = Logger.getMessageLogger(EnversMessageLogger.class, ValidTimeAuditStrategy.class.getName()); + public static final EnversMessageLogger LOG = Logger.getMessageLogger( + EnversMessageLogger.class, + ValidTimeAuditStrategy.class.getName() + ); /** * Default constructor. Log a warn message that this class is deprecated. */ public ValidTimeAuditStrategy() { - LOG.validTimeAuditStrategyDeprecated(); + LOG.validTimeAuditStrategyDeprecated(); } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/strategy/ValidityAuditStrategy.java b/hibernate-envers/src/main/java/org/hibernate/envers/strategy/ValidityAuditStrategy.java index c434feea8f..7de16d118b 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/strategy/ValidityAuditStrategy.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/strategy/ValidityAuditStrategy.java @@ -45,24 +45,24 @@ import static org.hibernate.envers.internal.entities.mapper.relation.query.Query import static org.hibernate.envers.internal.entities.mapper.relation.query.QueryConstants.REVISION_PARAMETER; /** - * Audit strategy which persists and retrieves audit information using a validity algorithm, based on the - * start-revision and end-revision of a row in the audit tables. - *

This algorithm works as follows: - *

    - *
  • For a new row that is persisted in an audit table, only the start-revision column of that row is set
  • - *
  • At the same time the end-revision field of the previous audit row is set to this revision
  • - *
  • Queries are retrieved using 'between start and end revision', instead of a subquery.
  • - *
- *

- * - *

- * This has a few important consequences that need to be judged against against each other: - *

    - *
  • Persisting audit information is a bit slower, because an extra row is updated
  • - *
  • Retrieving audit information is a lot faster
  • - *
- *

- * + * Audit strategy which persists and retrieves audit information using a validity algorithm, based on the + * start-revision and end-revision of a row in the audit tables. + *

This algorithm works as follows: + *

    + *
  • For a new row that is persisted in an audit table, only the start-revision column of that row is set
  • + *
  • At the same time the end-revision field of the previous audit row is set to this revision
  • + *
  • Queries are retrieved using 'between start and end revision', instead of a subquery.
  • + *
+ *

+ *

+ *

+ * This has a few important consequences that need to be judged against against each other: + *

    + *
  • Persisting audit information is a bit slower, because an extra row is updated
  • + *
  • Retrieving audit information is a lot faster
  • + *
+ *

+ * * @author Stephanie Pau * @author Adam Warski (adam at warski dot org) * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) @@ -70,38 +70,46 @@ import static org.hibernate.envers.internal.entities.mapper.relation.query.Query public class ValidityAuditStrategy implements AuditStrategy { private static final Logger log = Logger.getLogger( ValidityAuditStrategy.class ); - /** getter for the revision entity field annotated with @RevisionTimestamp */ - private Getter revisionTimestampGetter = null; + /** + * getter for the revision entity field annotated with @RevisionTimestamp + */ + private Getter revisionTimestampGetter = null; - private final SessionCacheCleaner sessionCacheCleaner; + private final SessionCacheCleaner sessionCacheCleaner; - public ValidityAuditStrategy() { - sessionCacheCleaner = new SessionCacheCleaner(); - } + public ValidityAuditStrategy() { + sessionCacheCleaner = new SessionCacheCleaner(); + } - public void perform( + public void perform( final Session session, String entityName, final AuditConfiguration auditCfg, final Serializable id, Object data, final Object revision) { - final AuditEntitiesConfiguration audEntitiesCfg = auditCfg.getAuditEntCfg(); - final String auditedEntityName = audEntitiesCfg.getAuditEntityName( entityName ); + final AuditEntitiesConfiguration audEntitiesCfg = auditCfg.getAuditEntCfg(); + final String auditedEntityName = audEntitiesCfg.getAuditEntityName( entityName ); final String revisionInfoEntityName = auditCfg.getAuditEntCfg().getRevisionInfoEntityName(); final SessionImplementor sessionImplementor = (SessionImplementor) session; final Dialect dialect = sessionImplementor.getFactory().getDialect(); - // Save the audit data - session.save(auditedEntityName, data); - sessionCacheCleaner.scheduleAuditDataRemoval(session, data); + // Save the audit data + session.save( auditedEntityName, data ); + sessionCacheCleaner.scheduleAuditDataRemoval( session, data ); - // Update the end date of the previous row if this operation is expected to have a previous row - if (getRevisionType(auditCfg, data) != RevisionType.ADD) { + // Update the end date of the previous row if this operation is expected to have a previous row + if ( getRevisionType( auditCfg, data ) != RevisionType.ADD ) { final Queryable productionEntityQueryable = getQueryable( entityName, sessionImplementor ); - final Queryable rootProductionEntityQueryable = getQueryable( productionEntityQueryable.getRootEntityName(), sessionImplementor ); + final Queryable rootProductionEntityQueryable = getQueryable( + productionEntityQueryable.getRootEntityName(), + sessionImplementor + ); final Queryable auditedEntityQueryable = getQueryable( auditedEntityName, sessionImplementor ); - final Queryable rootAuditedEntityQueryable = getQueryable( auditedEntityQueryable.getRootEntityName(), sessionImplementor ); + final Queryable rootAuditedEntityQueryable = getQueryable( + auditedEntityQueryable.getRootEntityName(), + sessionImplementor + ); final Queryable revisionInfoEntityQueryable = getQueryable( revisionInfoEntityName, sessionImplementor ); final String updateTableName; @@ -127,7 +135,10 @@ public class ValidityAuditStrategy implements AuditStrategy { final Type revisionInfoIdType = sessionImplementor.getFactory() .getEntityPersister( revisionInfoEntityName ) .getIdentifierType(); - final String revEndColumnName = rootAuditedEntityQueryable.toColumns( auditCfg.getAuditEntCfg().getRevisionEndFieldName() )[0]; + final String revEndColumnName = rootAuditedEntityQueryable.toColumns( + auditCfg.getAuditEntCfg() + .getRevisionEndFieldName() + )[0]; final boolean isRevisionEndTimestampEnabled = auditCfg.getAuditEntCfg().isRevisionEndTimestampEnabled(); @@ -163,14 +174,24 @@ public class ValidityAuditStrategy implements AuditStrategy { new ReturningWork() { @Override public Integer execute(Connection connection) throws SQLException { - PreparedStatement preparedStatement = sessionImplementor.getTransactionCoordinator().getJdbcCoordinator().getStatementPreparer().prepareStatement( updateSql ); + PreparedStatement preparedStatement = sessionImplementor.getTransactionCoordinator() + .getJdbcCoordinator() + .getStatementPreparer() + .prepareStatement( updateSql ); try { int index = 1; // set REVEND = ? - final Number revisionNumber = auditCfg.getRevisionInfoNumberReader().getRevisionNumber( revision ); - revisionInfoIdType.nullSafeSet( preparedStatement, revisionNumber, index, sessionImplementor ); + final Number revisionNumber = auditCfg.getRevisionInfoNumberReader().getRevisionNumber( + revision + ); + revisionInfoIdType.nullSafeSet( + preparedStatement, + revisionNumber, + index, + sessionImplementor + ); index += revisionInfoIdType.getColumnSpan( sessionImplementor.getFactory() ); // set [, REVEND_TSTMP = ?] @@ -180,7 +201,12 @@ public class ValidityAuditStrategy implements AuditStrategy { final Type revEndTsType = rootAuditedEntityQueryable.getPropertyType( auditCfg.getAuditEntCfg().getRevisionEndTimestampFieldName() ); - revEndTsType.nullSafeSet( preparedStatement, revisionEndTimestamp, index, sessionImplementor ); + revEndTsType.nullSafeSet( + preparedStatement, + revisionEndTimestamp, + index, + sessionImplementor + ); index += revEndTsType.getColumnSpan( sessionImplementor.getFactory() ); } @@ -198,10 +224,15 @@ public class ValidityAuditStrategy implements AuditStrategy { // where REVEND is null // nothing to bind.... - return sessionImplementor.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().executeUpdate( preparedStatement ); + return sessionImplementor.getTransactionCoordinator() + .getJdbcCoordinator() + .getResultSetReturn() + .executeUpdate( preparedStatement ); } finally { - sessionImplementor.getTransactionCoordinator().getJdbcCoordinator().release( preparedStatement ); + sessionImplementor.getTransactionCoordinator().getJdbcCoordinator().release( + preparedStatement + ); } } } @@ -213,7 +244,7 @@ public class ValidityAuditStrategy implements AuditStrategy { ); } } - } + } private Queryable getQueryable(String entityName, SessionImplementor sessionImplementor) { return (Queryable) sessionImplementor.getFactory().getEntityPersister( entityName ); @@ -236,25 +267,30 @@ public class ValidityAuditStrategy implements AuditStrategy { } } - @SuppressWarnings({"unchecked"}) - public void performCollectionChange(Session session, String entityName, String propertyName, AuditConfiguration auditCfg, - PersistentCollectionChangeData persistentCollectionChangeData, Object revision) { - final QueryBuilder qb = new QueryBuilder(persistentCollectionChangeData.getEntityName(), MIDDLE_ENTITY_ALIAS); + @SuppressWarnings({"unchecked"}) + public void performCollectionChange( + Session session, String entityName, String propertyName, AuditConfiguration auditCfg, + PersistentCollectionChangeData persistentCollectionChangeData, Object revision) { + final QueryBuilder qb = new QueryBuilder( persistentCollectionChangeData.getEntityName(), MIDDLE_ENTITY_ALIAS ); - final String originalIdPropName = auditCfg.getAuditEntCfg().getOriginalIdPropName(); - final Map originalId = (Map) persistentCollectionChangeData.getData().get(originalIdPropName); + final String originalIdPropName = auditCfg.getAuditEntCfg().getOriginalIdPropName(); + final Map originalId = (Map) persistentCollectionChangeData.getData().get( + originalIdPropName + ); final String revisionFieldName = auditCfg.getAuditEntCfg().getRevisionFieldName(); final String revisionTypePropName = auditCfg.getAuditEntCfg().getRevisionTypePropName(); // Adding a parameter for each id component, except the rev number and type. - for (Map.Entry originalIdEntry : originalId.entrySet()) { - if (!revisionFieldName.equals(originalIdEntry.getKey()) && !revisionTypePropName.equals(originalIdEntry.getKey())) { - qb.getRootParameters().addWhereWithParam(originalIdPropName + "." + originalIdEntry.getKey(), - true, "=", originalIdEntry.getValue()); - } - } + for ( Map.Entry originalIdEntry : originalId.entrySet() ) { + if ( !revisionFieldName.equals( originalIdEntry.getKey() ) && !revisionTypePropName.equals( originalIdEntry.getKey() ) ) { + qb.getRootParameters().addWhereWithParam( + originalIdPropName + "." + originalIdEntry.getKey(), + true, "=", originalIdEntry.getValue() + ); + } + } - final SessionFactoryImplementor sessionFactory = ( (SessionImplementor) session ).getFactory(); + final SessionFactoryImplementor sessionFactory = ((SessionImplementor) session).getFactory(); final Type propertyType = sessionFactory.getEntityPersister( entityName ).getPropertyType( propertyName ); if ( propertyType.isCollectionType() ) { CollectionType collectionPropertyType = (CollectionType) propertyType; @@ -269,92 +305,109 @@ public class ValidityAuditStrategy implements AuditStrategy { } } - addEndRevisionNullRestriction(auditCfg, qb.getRootParameters()); + addEndRevisionNullRestriction( auditCfg, qb.getRootParameters() ); - final List l = qb.toQuery(session).setLockOptions(LockOptions.UPGRADE).list(); + final List l = qb.toQuery( session ).setLockOptions( LockOptions.UPGRADE ).list(); - // Update the last revision if one exists. - // HHH-5967: with collections, the same element can be added and removed multiple times. So even if it's an - // ADD, we may need to update the last revision. - if (l.size() > 0) { - updateLastRevision(session, auditCfg, l, originalId, persistentCollectionChangeData.getEntityName(), revision); - } + // Update the last revision if one exists. + // HHH-5967: with collections, the same element can be added and removed multiple times. So even if it's an + // ADD, we may need to update the last revision. + if ( l.size() > 0 ) { + updateLastRevision( + session, + auditCfg, + l, + originalId, + persistentCollectionChangeData.getEntityName(), + revision + ); + } - // Save the audit data - session.save(persistentCollectionChangeData.getEntityName(), persistentCollectionChangeData.getData()); - sessionCacheCleaner.scheduleAuditDataRemoval(session, persistentCollectionChangeData.getData()); - } - - private void addEndRevisionNullRestriction(AuditConfiguration auditCfg, Parameters rootParameters) { - rootParameters.addWhere(auditCfg.getAuditEntCfg().getRevisionEndFieldName(), true, "is", "null", false); - } - - public void addEntityAtRevisionRestriction(GlobalConfiguration globalCfg, QueryBuilder rootQueryBuilder, - Parameters parameters, String revisionProperty,String revisionEndProperty, boolean addAlias, - MiddleIdData idData, String revisionPropertyPath, String originalIdPropertyName, - String alias1, String alias2, boolean inclusive) { - addRevisionRestriction(parameters, revisionProperty, revisionEndProperty, addAlias, inclusive); + // Save the audit data + session.save( persistentCollectionChangeData.getEntityName(), persistentCollectionChangeData.getData() ); + sessionCacheCleaner.scheduleAuditDataRemoval( session, persistentCollectionChangeData.getData() ); } - - public void addAssociationAtRevisionRestriction(QueryBuilder rootQueryBuilder, Parameters parameters, String revisionProperty, - String revisionEndProperty, boolean addAlias, MiddleIdData referencingIdData, - String versionsMiddleEntityName, String eeOriginalIdPropertyPath, String revisionPropertyPath, - String originalIdPropertyName, String alias1, boolean inclusive, MiddleComponentData... componentDatas) { - addRevisionRestriction(parameters, revisionProperty, revisionEndProperty, addAlias, inclusive); + + private void addEndRevisionNullRestriction(AuditConfiguration auditCfg, Parameters rootParameters) { + rootParameters.addWhere( auditCfg.getAuditEntCfg().getRevisionEndFieldName(), true, "is", "null", false ); } - + + public void addEntityAtRevisionRestriction( + GlobalConfiguration globalCfg, QueryBuilder rootQueryBuilder, + Parameters parameters, String revisionProperty, String revisionEndProperty, boolean addAlias, + MiddleIdData idData, String revisionPropertyPath, String originalIdPropertyName, + String alias1, String alias2, boolean inclusive) { + addRevisionRestriction( parameters, revisionProperty, revisionEndProperty, addAlias, inclusive ); + } + + public void addAssociationAtRevisionRestriction( + QueryBuilder rootQueryBuilder, Parameters parameters, String revisionProperty, + String revisionEndProperty, boolean addAlias, MiddleIdData referencingIdData, + String versionsMiddleEntityName, String eeOriginalIdPropertyPath, String revisionPropertyPath, + String originalIdPropertyName, String alias1, boolean inclusive, MiddleComponentData... componentDatas) { + addRevisionRestriction( parameters, revisionProperty, revisionEndProperty, addAlias, inclusive ); + } + public void setRevisionTimestampGetter(Getter revisionTimestampGetter) { this.revisionTimestampGetter = revisionTimestampGetter; } - private void addRevisionRestriction(Parameters rootParameters, String revisionProperty, String revisionEndProperty, - boolean addAlias, boolean inclusive) { + private void addRevisionRestriction( + Parameters rootParameters, String revisionProperty, String revisionEndProperty, + boolean addAlias, boolean inclusive) { // e.revision <= _revision and (e.endRevision > _revision or e.endRevision is null) - Parameters subParm = rootParameters.addSubParameters("or"); - rootParameters.addWhereWithNamedParam(revisionProperty, addAlias, inclusive ? "<=" : "<", REVISION_PARAMETER); - subParm.addWhereWithNamedParam(revisionEndProperty + ".id", addAlias, inclusive ? ">" : ">=", REVISION_PARAMETER); - subParm.addWhere(revisionEndProperty, addAlias, "is", "null", false); + Parameters subParm = rootParameters.addSubParameters( "or" ); + rootParameters.addWhereWithNamedParam( revisionProperty, addAlias, inclusive ? "<=" : "<", REVISION_PARAMETER ); + subParm.addWhereWithNamedParam( + revisionEndProperty + ".id", + addAlias, + inclusive ? ">" : ">=", + REVISION_PARAMETER + ); + subParm.addWhere( revisionEndProperty, addAlias, "is", "null", false ); } - @SuppressWarnings({"unchecked"}) - private RevisionType getRevisionType(AuditConfiguration auditCfg, Object data) { - return (RevisionType) ((Map) data).get(auditCfg.getAuditEntCfg().getRevisionTypePropName()); - } + @SuppressWarnings({"unchecked"}) + private RevisionType getRevisionType(AuditConfiguration auditCfg, Object data) { + return (RevisionType) ((Map) data).get( auditCfg.getAuditEntCfg().getRevisionTypePropName() ); + } - @SuppressWarnings({"unchecked"}) - private void updateLastRevision(Session session, AuditConfiguration auditCfg, List l, - Object id, String auditedEntityName, Object revision) { - // There should be one entry - if (l.size() == 1) { - // Setting the end revision to be the current rev - Object previousData = l.get(0); - String revisionEndFieldName = auditCfg.getAuditEntCfg().getRevisionEndFieldName(); - ((Map) previousData).put(revisionEndFieldName, revision); + @SuppressWarnings({"unchecked"}) + private void updateLastRevision( + Session session, AuditConfiguration auditCfg, List l, + Object id, String auditedEntityName, Object revision) { + // There should be one entry + if ( l.size() == 1 ) { + // Setting the end revision to be the current rev + Object previousData = l.get( 0 ); + String revisionEndFieldName = auditCfg.getAuditEntCfg().getRevisionEndFieldName(); + ((Map) previousData).put( revisionEndFieldName, revision ); - if (auditCfg.getAuditEntCfg().isRevisionEndTimestampEnabled()) { - // Determine the value of the revision property annotated with @RevisionTimestamp - String revEndTimestampFieldName = auditCfg.getAuditEntCfg().getRevisionEndTimestampFieldName(); - Object revEndTimestampObj = this.revisionTimestampGetter.get(revision); - Date revisionEndTimestamp = convertRevEndTimestampToDate(revEndTimestampObj); + if ( auditCfg.getAuditEntCfg().isRevisionEndTimestampEnabled() ) { + // Determine the value of the revision property annotated with @RevisionTimestamp + String revEndTimestampFieldName = auditCfg.getAuditEntCfg().getRevisionEndTimestampFieldName(); + Object revEndTimestampObj = this.revisionTimestampGetter.get( revision ); + Date revisionEndTimestamp = convertRevEndTimestampToDate( revEndTimestampObj ); - // Setting the end revision timestamp - ((Map) previousData).put(revEndTimestampFieldName, revisionEndTimestamp); - } - - // Saving the previous version - session.save(auditedEntityName, previousData); - sessionCacheCleaner.scheduleAuditDataRemoval(session, previousData); - } else { - throw new RuntimeException("Cannot find previous revision for entity " + auditedEntityName + " and id " + id); - } - } + // Setting the end revision timestamp + ((Map) previousData).put( revEndTimestampFieldName, revisionEndTimestamp ); + } - private Date convertRevEndTimestampToDate(Object revEndTimestampObj) { - // convert to a java.util.Date - if (revEndTimestampObj instanceof Date) { - return (Date) revEndTimestampObj; - } - return new Date((Long) revEndTimestampObj); - } + // Saving the previous version + session.save( auditedEntityName, previousData ); + sessionCacheCleaner.scheduleAuditDataRemoval( session, previousData ); + } + else { + throw new RuntimeException( "Cannot find previous revision for entity " + auditedEntityName + " and id " + id ); + } + } + + private Date convertRevEndTimestampToDate(Object revEndTimestampObj) { + // convert to a java.util.Date + if ( revEndTimestampObj instanceof Date ) { + return (Date) revEndTimestampObj; + } + return new Date( (Long) revEndTimestampObj ); + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/tools/Pair.java b/hibernate-envers/src/main/java/org/hibernate/envers/tools/Pair.java index 6edfdc14fa..bad86c8214 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/tools/Pair.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/tools/Pair.java @@ -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 @@ -25,47 +25,59 @@ package org.hibernate.envers.tools; /** * A pair of objects. + * * @param * @param + * * @author Adam Warski (adamw@aster.pl) */ public class Pair { - private final T1 obj1; - private final T2 obj2; + private final T1 obj1; + private final T2 obj2; - public Pair(T1 obj1, T2 obj2) { - this.obj1 = obj1; - this.obj2 = obj2; - } + public Pair(T1 obj1, T2 obj2) { + this.obj1 = obj1; + this.obj2 = obj2; + } - public T1 getFirst() { - return obj1; - } + public T1 getFirst() { + return obj1; + } - public T2 getSecond() { - return obj2; - } + public T2 getSecond() { + return obj2; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof Pair)) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof Pair) ) { + return false; + } - Pair pair = (Pair) o; + final Pair pair = (Pair) o; - if (obj1 != null ? !obj1.equals(pair.obj1) : pair.obj1 != null) return false; - if (obj2 != null ? !obj2.equals(pair.obj2) : pair.obj2 != null) return false; + if ( obj1 != null ? !obj1.equals( pair.obj1 ) : pair.obj1 != null ) { + return false; + } + if ( obj2 != null ? !obj2.equals( pair.obj2 ) : pair.obj2 != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (obj1 != null ? obj1.hashCode() : 0); - result = 31 * result + (obj2 != null ? obj2.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result; + result = (obj1 != null ? obj1.hashCode() : 0); + result = 31 * result + (obj2 != null ? obj2.hashCode() : 0); + return result; + } - public static Pair make(T1 obj1, T2 obj2) { - return new Pair(obj1, obj2); - } + public static Pair make(T1 obj1, T2 obj2) { + return new Pair( obj1, obj2 ); + } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/tools/hbm2ddl/EnversSchemaGenerator.java b/hibernate-envers/src/main/java/org/hibernate/envers/tools/hbm2ddl/EnversSchemaGenerator.java index de20ea4463..62d8d23269 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/tools/hbm2ddl/EnversSchemaGenerator.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/tools/hbm2ddl/EnversSchemaGenerator.java @@ -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.tools.hbm2ddl; import java.sql.Connection; @@ -13,35 +36,35 @@ import org.hibernate.tool.hbm2ddl.SchemaExport; * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public class EnversSchemaGenerator { - private final SchemaExport export; + private final SchemaExport export; - public EnversSchemaGenerator(ServiceRegistry serviceRegistry, Configuration configuration) { - configuration = configureAuditing(configuration); - export = new SchemaExport(serviceRegistry, configuration); - } + public EnversSchemaGenerator(ServiceRegistry serviceRegistry, Configuration configuration) { + configuration = configureAuditing( configuration ); + export = new SchemaExport( serviceRegistry, configuration ); + } - public EnversSchemaGenerator(Configuration configuration) { - configuration = configureAuditing(configuration); - export = new SchemaExport(configuration); - } + public EnversSchemaGenerator(Configuration configuration) { + configuration = configureAuditing( configuration ); + export = new SchemaExport( configuration ); + } - public EnversSchemaGenerator(Configuration configuration, Properties properties) throws HibernateException { - configuration = configureAuditing(configuration); - export = new SchemaExport(configuration, properties); - } + public EnversSchemaGenerator(Configuration configuration, Properties properties) throws HibernateException { + configuration = configureAuditing( configuration ); + export = new SchemaExport( configuration, properties ); + } - public EnversSchemaGenerator(Configuration configuration, Connection connection) throws HibernateException { - configuration = configureAuditing(configuration); - export = new SchemaExport(configuration, connection); - } + public EnversSchemaGenerator(Configuration configuration, Connection connection) throws HibernateException { + configuration = configureAuditing( configuration ); + export = new SchemaExport( configuration, connection ); + } - public SchemaExport export() { - return export; - } + public SchemaExport export() { + return export; + } - private Configuration configureAuditing(Configuration configuration) { - configuration.buildMappings(); - AuditConfiguration.getFor(configuration); - return configuration; - } + private Configuration configureAuditing(Configuration configuration) { + configuration.buildMappings(); + AuditConfiguration.getFor( configuration ); + return configuration; + } } diff --git a/hibernate-envers/src/test/java/ee/estonia/entities/Child.java b/hibernate-envers/src/test/java/ee/estonia/entities/Child.java index 97b7e8aa69..915f36b08d 100644 --- a/hibernate-envers/src/test/java/ee/estonia/entities/Child.java +++ b/hibernate-envers/src/test/java/ee/estonia/entities/Child.java @@ -1,9 +1,9 @@ package ee.estonia.entities; -import java.io.Serializable; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; +import java.io.Serializable; import org.hibernate.envers.Audited; @@ -13,62 +13,70 @@ import org.hibernate.envers.Audited; @Entity @Audited public class Child implements Serializable { - @Id - @GeneratedValue - private Long id; + @Id + @GeneratedValue + private Long id; - private String data; + private String data; - public Child() { - } + public Child() { + } - public Child(String data) { - this.data = data; - } + public Child(String data) { + this.data = data; + } - public Child(String data, Long id) { - this.id = id; - this.data = data; - } + public Child(String data, Long id) { + this.id = id; + this.data = data; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof Child)) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof Child) ) { + return false; + } - Child that = (Child) o; + Child that = (Child) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - int result = id != null ? id.hashCode() : 0; - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = id != null ? id.hashCode() : 0; + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - @Override - public String toString() { - return "Child(id = " + id + ", data = " + data + ")"; - } + @Override + public String toString() { + return "Child(id = " + id + ", data = " + data + ")"; + } - public Long getId() { - return id; - } + public Long getId() { + return id; + } - public void setId(Long id) { - this.id = id; - } + public void setId(Long id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/ee/estonia/entities/Parent.java b/hibernate-envers/src/test/java/ee/estonia/entities/Parent.java index c449dc2cd4..a1b63ecbb8 100644 --- a/hibernate-envers/src/test/java/ee/estonia/entities/Parent.java +++ b/hibernate-envers/src/test/java/ee/estonia/entities/Parent.java @@ -1,12 +1,12 @@ package ee.estonia.entities; -import java.io.Serializable; -import java.util.HashSet; -import java.util.Set; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.OneToMany; +import java.io.Serializable; +import java.util.HashSet; +import java.util.Set; import org.hibernate.envers.Audited; @@ -16,73 +16,81 @@ import org.hibernate.envers.Audited; @Entity @Audited public class Parent implements Serializable { - @Id - @GeneratedValue - private Long id; + @Id + @GeneratedValue + private Long id; - private String data; + private String data; - @OneToMany - private Set collection = new HashSet(); + @OneToMany + private Set collection = new HashSet(); - public Parent() { - } + public Parent() { + } - public Parent(String data) { - this.data = data; - } + public Parent(String data) { + this.data = data; + } - public Parent(String data, Long id) { - this.id = id; - this.data = data; - } + public Parent(String data, Long id) { + this.id = id; + this.data = data; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof Parent)) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof Parent) ) { + return false; + } - Parent that = (Parent) o; + Parent that = (Parent) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - int result = id != null ? id.hashCode() : 0; - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = id != null ? id.hashCode() : 0; + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - @Override - public String toString() { - return "Parent(id = " + id + ", data = " + data + ")"; - } + @Override + public String toString() { + return "Parent(id = " + id + ", data = " + data + ")"; + } - public Long getId() { - return id; - } + public Long getId() { + return id; + } - public void setId(Long id) { - this.id = id; - } + public void setId(Long id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public Set getCollection() { - return collection; - } + public Set getCollection() { + return collection; + } - public void setCollection(Set collection) { - this.collection = collection; - } + public void setCollection(Set collection) { + this.collection = collection; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/AbstractEnversTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/AbstractEnversTest.java index 6fd640e5fa..85bc1c052f 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/AbstractEnversTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/AbstractEnversTest.java @@ -8,22 +8,26 @@ import org.junit.runners.Parameterized; /** * An abstract Envers test which runs the tests using two audit strategies. + * * @author Adam Warski (adam at warski dot org) */ @RunWith(EnversRunner.class) public abstract class AbstractEnversTest { - private String auditStrategy; + private String auditStrategy; - @Parameterized.Parameters - public static List data() { - return Arrays.asList(new Object[]{null}, new Object[]{"org.hibernate.envers.strategy.ValidityAuditStrategy"}); - } + @Parameterized.Parameters + public static List data() { + return Arrays.asList( + new Object[] {null}, + new Object[] {"org.hibernate.envers.strategy.ValidityAuditStrategy"} + ); + } - public void setTestData(Object[] data) { - auditStrategy = (String) data[0]; - } + public void setTestData(Object[] data) { + auditStrategy = (String) data[0]; + } - public String getAuditStrategy() { - return auditStrategy; - } + public String getAuditStrategy() { + return auditStrategy; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/AbstractOneSessionTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/AbstractOneSessionTest.java index 9ece4924be..f8359434e3 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/AbstractOneSessionTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/AbstractOneSessionTest.java @@ -4,8 +4,6 @@ import java.io.File; import java.net.URISyntaxException; import java.net.URL; -import org.junit.Before; - import org.hibernate.MappingException; import org.hibernate.Session; import org.hibernate.SessionFactory; @@ -15,6 +13,9 @@ import org.hibernate.envers.AuditReader; import org.hibernate.envers.AuditReaderFactory; import org.hibernate.envers.configuration.EnversSettings; import org.hibernate.service.ServiceRegistry; + +import org.junit.Before; + import org.hibernate.testing.AfterClassOnce; import org.hibernate.testing.BeforeClassOnce; import org.hibernate.testing.ServiceRegistryBuilder; @@ -24,9 +25,8 @@ import org.hibernate.testing.ServiceRegistryBuilder; * auditReader must be used for the hole test. * * @author Hernán Chanfreau - * */ -public abstract class AbstractOneSessionTest extends AbstractEnversTest { +public abstract class AbstractOneSessionTest extends AbstractEnversTest { protected Configuration config; private ServiceRegistry serviceRegistry; private SessionFactory sessionFactory; @@ -34,41 +34,42 @@ public abstract class AbstractOneSessionTest extends AbstractEnversTest { private AuditReader auditReader; @BeforeClassOnce - public void init() throws URISyntaxException { - config = new Configuration(); - URL url = Thread.currentThread().getContextClassLoader().getResource(getHibernateConfigurationFileName()); - config.configure(new File(url.toURI())); + public void init() throws URISyntaxException { + config = new Configuration(); + URL url = Thread.currentThread().getContextClassLoader().getResource( getHibernateConfigurationFileName() ); + config.configure( new File( url.toURI() ) ); - String auditStrategy = getAuditStrategy(); - if (auditStrategy != null && !"".equals(auditStrategy)) { - config.setProperty(EnversSettings.AUDIT_STRATEGY, auditStrategy); - } - config.setProperty( Environment.USE_NEW_ID_GENERATOR_MAPPINGS, "true" ); - config.setProperty(EnversSettings.USE_REVISION_ENTITY_WITH_NATIVE_ID, "false"); - addProperties(config); + String auditStrategy = getAuditStrategy(); + if ( auditStrategy != null && !"".equals( auditStrategy ) ) { + config.setProperty( EnversSettings.AUDIT_STRATEGY, auditStrategy ); + } + config.setProperty( Environment.USE_NEW_ID_GENERATOR_MAPPINGS, "true" ); + config.setProperty( EnversSettings.USE_REVISION_ENTITY_WITH_NATIVE_ID, "false" ); + addProperties( config ); - this.initMappings(); + this.initMappings(); - serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( config.getProperties() ); + serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( config.getProperties() ); sessionFactory = config.buildSessionFactory( serviceRegistry ); - } + } - protected abstract void initMappings() throws MappingException, URISyntaxException ; + protected abstract void initMappings() throws MappingException, URISyntaxException; - protected void addProperties(Configuration configuration) {} + protected void addProperties(Configuration configuration) { + } - protected String getHibernateConfigurationFileName(){ + protected String getHibernateConfigurationFileName() { return "hibernate.test.session-cfg.xml"; } - private SessionFactory getSessionFactory(){ + private SessionFactory getSessionFactory() { return sessionFactory; - } + } @AfterClassOnce public void closeSessionFactory() { try { - sessionFactory.close(); + sessionFactory.close(); } finally { if ( serviceRegistry != null ) { @@ -84,9 +85,9 @@ public abstract class AbstractOneSessionTest extends AbstractEnversTest { */ @Before public void initializeSession() { - if (getSession() == null) { - session = getSessionFactory().openSession(); - auditReader = AuditReaderFactory.get(session); + if ( getSession() == null ) { + session = getSessionFactory().openSession(); + auditReader = AuditReaderFactory.get( session ); } } @@ -94,8 +95,8 @@ public abstract class AbstractOneSessionTest extends AbstractEnversTest { * Creates a new session and auditReader. */ public void forceNewSession() { - session = getSessionFactory().openSession(); - auditReader = AuditReaderFactory.get(session); + session = getSessionFactory().openSession(); + auditReader = AuditReaderFactory.get( session ); } protected Session getSession() { @@ -103,11 +104,9 @@ public abstract class AbstractOneSessionTest extends AbstractEnversTest { } - protected AuditReader getAuditReader() { return auditReader; } - } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/BaseEnversFunctionalTestCase.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/BaseEnversFunctionalTestCase.java index e6b91a26f5..104725455e 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/BaseEnversFunctionalTestCase.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/BaseEnversFunctionalTestCase.java @@ -3,14 +3,15 @@ package org.hibernate.envers.test; import java.util.Arrays; import java.util.List; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - import org.hibernate.Session; import org.hibernate.cfg.Configuration; import org.hibernate.envers.AuditReader; import org.hibernate.envers.AuditReaderFactory; import org.hibernate.envers.configuration.EnversSettings; + +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; /** @@ -23,8 +24,8 @@ public abstract class BaseEnversFunctionalTestCase extends BaseCoreFunctionalTes @Parameterized.Parameters public static List data() { return Arrays.asList( - new Object[] { null }, - new Object[] { "org.hibernate.envers.strategy.ValidityAuditStrategy" } + new Object[] {null}, + new Object[] {"org.hibernate.envers.strategy.ValidityAuditStrategy"} ); } @@ -43,18 +44,18 @@ public abstract class BaseEnversFunctionalTestCase extends BaseCoreFunctionalTes return session; } - protected AuditReader getAuditReader(){ + protected AuditReader getAuditReader() { return AuditReaderFactory.get( getSession() ); } - @Override - protected Configuration constructConfiguration() { - Configuration configuration = super.constructConfiguration(); - configuration.setProperty(EnversSettings.USE_REVISION_ENTITY_WITH_NATIVE_ID, "false"); - return configuration; - } + @Override + protected Configuration constructConfiguration() { + Configuration configuration = super.constructConfiguration(); + configuration.setProperty( EnversSettings.USE_REVISION_ENTITY_WITH_NATIVE_ID, "false" ); + return configuration; + } - @Override + @Override protected String getBaseForMappings() { return ""; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/BaseEnversJPAFunctionalTestCase.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/BaseEnversJPAFunctionalTestCase.java index 0590352301..0bb267cbc6 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/BaseEnversJPAFunctionalTestCase.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/BaseEnversJPAFunctionalTestCase.java @@ -23,16 +23,15 @@ */ package org.hibernate.envers.test; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.transaction.SystemException; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.Map; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; -import javax.transaction.SystemException; import org.jboss.logging.Logger; -import org.junit.After; import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl; import org.hibernate.cfg.Configuration; @@ -50,6 +49,9 @@ import org.hibernate.jpa.boot.spi.Bootstrap; import org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor; import org.hibernate.jpa.internal.EntityManagerFactoryImpl; import org.hibernate.jpa.test.PersistenceUnitDescriptorAdapter; + +import org.junit.After; + import org.hibernate.testing.AfterClassOnce; import org.hibernate.testing.BeforeClassOnce; import org.hibernate.testing.jta.TestingJtaPlatformImpl; @@ -88,7 +90,7 @@ public abstract class BaseEnversJPAFunctionalTestCase extends AbstractEnversTest } @BeforeClassOnce - @SuppressWarnings({ "UnusedDeclaration" }) + @SuppressWarnings({"UnusedDeclaration"}) public void buildEntityManagerFactory() throws Exception { log.trace( "Building EntityManagerFactory" ); @@ -117,7 +119,7 @@ public abstract class BaseEnversJPAFunctionalTestCase extends AbstractEnversTest settings.put( org.hibernate.cfg.AvailableSettings.HBM2DDL_AUTO, "create-drop" ); final String secondSchemaName = createSecondSchema(); if ( StringHelper.isNotEmpty( secondSchemaName ) ) { - if ( !( getDialect() instanceof H2Dialect ) ) { + if ( !(getDialect() instanceof H2Dialect) ) { throw new UnsupportedOperationException( "Only H2 dialect supports creation of second schema." ); } Helper.createH2Schema( secondSchemaName, settings ); @@ -128,7 +130,7 @@ public abstract class BaseEnversJPAFunctionalTestCase extends AbstractEnversTest settings.put( EnversSettings.AUDIT_STRATEGY, getAuditStrategy() ); } - if ( ! autoRegisterListeners() ) { + if ( !autoRegisterListeners() ) { settings.put( EnversIntegrator.AUTO_REGISTER, "false" ); } @@ -195,7 +197,7 @@ public abstract class BaseEnversJPAFunctionalTestCase extends AbstractEnversTest } public String[] getEjb3DD() { - return new String[] { }; + return new String[] {}; } protected void afterEntityManagerFactoryBuilt() { @@ -207,6 +209,7 @@ public abstract class BaseEnversJPAFunctionalTestCase extends AbstractEnversTest /** * Feature supported only by H2 dialect. + * * @return Provide not empty name to create second schema. */ protected String createSecondSchema() { @@ -218,14 +221,14 @@ public abstract class BaseEnversJPAFunctionalTestCase extends AbstractEnversTest } @AfterClassOnce - public void releaseEntityManagerFactory(){ + public void releaseEntityManagerFactory() { if ( entityManagerFactory != null && entityManagerFactory.isOpen() ) { entityManagerFactory.close(); } } @After - @SuppressWarnings({ "UnusedDeclaration" }) + @SuppressWarnings({"UnusedDeclaration"}) public void releaseUnclosedEntityManagers() { releaseUnclosedEntityManager( this.em ); auditReader = null; @@ -250,13 +253,13 @@ public abstract class BaseEnversJPAFunctionalTestCase extends AbstractEnversTest catch (SystemException ignored) { } } - try{ + try { if ( em.getTransaction().isActive() ) { em.getTransaction().rollback(); log.warn( "You left an open transaction! Fix your test case. For now, we are closing it for you." ); } } - catch ( IllegalStateException e ) { + catch (IllegalStateException e) { } if ( em.isOpen() ) { // as we open an EM before the test runs, it will still be open if the test uses a custom EM. @@ -265,9 +268,11 @@ public abstract class BaseEnversJPAFunctionalTestCase extends AbstractEnversTest log.warn( "The EntityManager is not closed. Closing it." ); } } - protected EntityManager getEntityManager(){ + + protected EntityManager getEntityManager() { return getOrCreateEntityManager(); } + protected EntityManager getOrCreateEntityManager() { if ( em == null || !em.isOpen() ) { em = entityManagerFactory.createEntityManager(); @@ -275,8 +280,8 @@ public abstract class BaseEnversJPAFunctionalTestCase extends AbstractEnversTest return em; } - protected AuditReader getAuditReader(){ - if(auditReader!=null){ + protected AuditReader getAuditReader() { + if ( auditReader != null ) { return auditReader; } return auditReader = AuditReaderFactory.get( getOrCreateEntityManager() ); diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/EnversRunner.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/EnversRunner.java index 50c2905a4c..75cca41898 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/EnversRunner.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/EnversRunner.java @@ -18,13 +18,14 @@ import org.hibernate.testing.junit4.CustomRunner; /** * Copied & modified from {@link org.junit.runners.Parameterized}. - * + *

* The modification is that the generated runners extend {@link CustomRunner} instead of the default * {@code TestClassRunnerForParameters}. - * + *

* The runner itself sets the data using a setter instead of a constructor, and creates only one test instance. Moreover * it doesn't override {@code classBlock} which causes the custom {@code @BeforeClassOnce} and {@code @AfterClassOnce} * annotations to work. + * * @author Adam Warski (adam at warski dot org) */ public class EnversRunner extends Suite { @@ -34,74 +35,88 @@ public class EnversRunner extends Suite { private final List fParameterList; TestClassCustomRunnerForParameters(Class type, List parameterList, int i) - throws InitializationError, NoTestsRemainException { - super(type); - fParameterList= parameterList; - fParameterSetNumber= i; + throws InitializationError, NoTestsRemainException { + super( type ); + fParameterList = parameterList; + fParameterSetNumber = i; } - @Override - protected Object getTestInstance() throws Exception { - Object testInstance = super.getTestInstance(); - if ( AbstractEnversTest.class.isInstance( testInstance ) ) { - ( (AbstractEnversTest) testInstance ).setTestData( computeParams() ); - } - else if ( BaseEnversFunctionalTestCase.class.isInstance( testInstance ) ) { - ( (BaseEnversFunctionalTestCase) testInstance ).setTestData( computeParams() ); - } - return testInstance; - } + @Override + protected Object getTestInstance() throws Exception { + Object testInstance = super.getTestInstance(); + if ( AbstractEnversTest.class.isInstance( testInstance ) ) { + ((AbstractEnversTest) testInstance).setTestData( computeParams() ); + } + else if ( BaseEnversFunctionalTestCase.class.isInstance( testInstance ) ) { + ((BaseEnversFunctionalTestCase) testInstance).setTestData( computeParams() ); + } + return testInstance; + } private Object[] computeParams() throws Exception { try { - return fParameterList.get(fParameterSetNumber); - } catch (ClassCastException e) { - throw new Exception(String.format( - "%s.%s() must return a Collection of arrays.", - getTestClass().getName(), getParametersMethod( - getTestClass()).getName())); + return fParameterList.get( fParameterSetNumber ); + } + catch (ClassCastException e) { + throw new Exception( + String.format( + "%s.%s() must return a Collection of arrays.", + getTestClass().getName(), getParametersMethod( + getTestClass() + ).getName() + ) + ); } } @Override protected String getName() { - return String.format("[%s]", fParameterSetNumber); + return String.format( "[%s]", fParameterSetNumber ); } @Override protected String testName(final FrameworkMethod method) { - return String.format("%s[%s]", method.getName(), - fParameterSetNumber); + return String.format( + "%s[%s]", method.getName(), + fParameterSetNumber + ); } @Override protected void sortMethods(List computedTestMethods) { super.sortMethods( computedTestMethods ); - Collections.sort(computedTestMethods, new Comparator() { + Collections.sort( + computedTestMethods, new Comparator() { private int getPriority(FrameworkMethod fm) { - Priority p = fm.getAnnotation(Priority.class); + Priority p = fm.getAnnotation( Priority.class ); return p == null ? 0 : p.value(); } @Override public int compare(FrameworkMethod fm1, FrameworkMethod fm2) { - return getPriority(fm2) - getPriority(fm1); + return getPriority( fm2 ) - getPriority( fm1 ); } - }); + } + ); } - } + } - private final ArrayList runners= new ArrayList(); + private final ArrayList runners = new ArrayList(); /** * Only called reflectively. Do not use programmatically. */ public EnversRunner(Class klass) throws Throwable { - super(klass, Collections.emptyList()); - List parametersList= getParametersList(getTestClass()); - for (int i= 0; i < parametersList.size(); i++) - runners.add(new TestClassCustomRunnerForParameters(getTestClass().getJavaClass(), - parametersList, i)); + super( klass, Collections.emptyList() ); + List parametersList = getParametersList( getTestClass() ); + for ( int i = 0; i < parametersList.size(); i++ ) { + runners.add( + new TestClassCustomRunnerForParameters( + getTestClass().getJavaClass(), + parametersList, i + ) + ); + } } @Override @@ -112,22 +127,26 @@ public class EnversRunner extends Suite { @SuppressWarnings("unchecked") private List getParametersList(TestClass klass) throws Throwable { - return (List) getParametersMethod(klass).invokeExplosively( - null); + return (List) getParametersMethod( klass ).invokeExplosively( + null + ); } private FrameworkMethod getParametersMethod(TestClass testClass) throws Exception { - List methods= testClass.getAnnotatedMethods(Parameterized.Parameters.class); + List methods = testClass.getAnnotatedMethods( Parameterized.Parameters.class ); - for (FrameworkMethod each : methods) { - int modifiers= each.getMethod().getModifiers(); - if (Modifier.isStatic(modifiers) && Modifier.isPublic(modifiers)) + for ( FrameworkMethod each : methods ) { + int modifiers = each.getMethod().getModifiers(); + if ( Modifier.isStatic( modifiers ) && Modifier.isPublic( modifiers ) ) { return each; + } } - throw new Exception("No public static parameters method on class " - + testClass.getName()); + throw new Exception( + "No public static parameters method on class " + + testClass.getName() + ); } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/Priority.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/Priority.java index f18f9d9b8d..0120b55b7f 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/Priority.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/Priority.java @@ -8,10 +8,11 @@ import java.lang.annotation.Target; /** * An annotation for specifyfing test method priority. Methods with higher priorities execute earlier. * If the annotation is not present priority 0 is assumed. + * * @author Adam Warski (adam at warski dot org) */ @Retention(RetentionPolicy.RUNTIME) -@Target({ ElementType.METHOD, ElementType.TYPE }) +@Target({ElementType.METHOD, ElementType.TYPE}) public @interface Priority { int value(); } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/IntNoAutoIdTestEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/IntNoAutoIdTestEntity.java index d5af7eb797..5a4891f322 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/IntNoAutoIdTestEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/IntNoAutoIdTestEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities; + import javax.persistence.Entity; import javax.persistence.Id; @@ -32,61 +33,69 @@ import org.hibernate.envers.Audited; */ @Entity public class IntNoAutoIdTestEntity { - @Id - private Integer id; + @Id + private Integer id; - @Audited - private Integer numVal; + @Audited + private Integer numVal; - public IntNoAutoIdTestEntity() { - } + public IntNoAutoIdTestEntity() { + } - public IntNoAutoIdTestEntity(Integer numVal, Integer id) { - this.id = id; - this.numVal = numVal; - } + public IntNoAutoIdTestEntity(Integer numVal, Integer id) { + this.id = id; + this.numVal = numVal; + } - public IntNoAutoIdTestEntity(Integer numVal) { - this.numVal = numVal; - } + public IntNoAutoIdTestEntity(Integer numVal) { + this.numVal = numVal; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public Integer getNumVal() { - return numVal; - } + public Integer getNumVal() { + return numVal; + } - public void setNumVal(Integer numVal) { - this.numVal = numVal; - } + public void setNumVal(Integer numVal) { + this.numVal = numVal; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof IntNoAutoIdTestEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof IntNoAutoIdTestEntity) ) { + return false; + } - IntNoAutoIdTestEntity that = (IntNoAutoIdTestEntity) o; + IntNoAutoIdTestEntity that = (IntNoAutoIdTestEntity) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; - //noinspection RedundantIfStatement - if (numVal != null ? !numVal.equals(that.numVal) : that.numVal != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } + //noinspection RedundantIfStatement + if ( numVal != null ? !numVal.equals( that.numVal ) : that.numVal != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (numVal != null ? numVal.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (numVal != null ? numVal.hashCode() : 0); + return result; + } - public String toString() { - return "INATE(id = " + id + ", numVal = " + numVal + ")"; - } + public String toString() { + return "INATE(id = " + id + ", numVal = " + numVal + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/IntTestEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/IntTestEntity.java index 3fbd16b2d3..9d73c06ccd 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/IntTestEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/IntTestEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities; + import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -34,61 +35,69 @@ import org.hibernate.envers.Audited; */ @Entity public class IntTestEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - @Audited - @Column(name = "NUMERIC_VALUE") - private Integer number; + @Audited + @Column(name = "NUMERIC_VALUE") + private Integer number; - public IntTestEntity() { - } + public IntTestEntity() { + } - public IntTestEntity(Integer number, Integer id) { - this.id = id; - this.number = number; - } + public IntTestEntity(Integer number, Integer id) { + this.id = id; + this.number = number; + } - public IntTestEntity(Integer number) { - this.number = number; - } + public IntTestEntity(Integer number) { + this.number = number; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public Integer getNumber() { - return number; - } + public Integer getNumber() { + return number; + } - public void setNumber(Integer number) { - this.number = number; - } + public void setNumber(Integer number) { + this.number = number; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof IntTestEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof IntTestEntity) ) { + return false; + } - IntTestEntity that = (IntTestEntity) o; + IntTestEntity that = (IntTestEntity) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; - if (number != null ? !number.equals(that.number) : that.number != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } + if ( number != null ? !number.equals( that.number ) : that.number != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result = (id != null ? id.hashCode() : 0); - result = 31 * result + (number != null ? number.hashCode() : 0); - return result; - } + public int hashCode() { + int result = (id != null ? id.hashCode() : 0); + result = 31 * result + (number != null ? number.hashCode() : 0); + return result; + } - public String toString() { - return "ITE(id = " + id + ", number = " + number + ")"; - } + public String toString() { + return "ITE(id = " + id + ", number = " + number + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/IntTestPrivSeqEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/IntTestPrivSeqEntity.java index ec1f202242..0aa2592d08 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/IntTestPrivSeqEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/IntTestPrivSeqEntity.java @@ -11,67 +11,76 @@ import org.hibernate.envers.Audited; /** * Duplicate of {@link IntTestEntity} but with private sequence generator. + * * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ @Entity public class IntTestPrivSeqEntity { - @Id - @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "IntTestPrivSeq") - @SequenceGenerator(name = "IntTestPrivSeq", sequenceName="INTTESTPRIV_SEQ", - allocationSize = 1, initialValue = 1) - private Integer id; + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "IntTestPrivSeq") + @SequenceGenerator(name = "IntTestPrivSeq", sequenceName = "INTTESTPRIV_SEQ", + allocationSize = 1, initialValue = 1) + private Integer id; - @Audited - @Column(name = "NUMERIC_VALUE") - private Integer number; + @Audited + @Column(name = "NUMERIC_VALUE") + private Integer number; - public IntTestPrivSeqEntity() { - } + public IntTestPrivSeqEntity() { + } - public IntTestPrivSeqEntity(Integer number, Integer id) { - this.id = id; - this.number = number; - } + public IntTestPrivSeqEntity(Integer number, Integer id) { + this.id = id; + this.number = number; + } - public IntTestPrivSeqEntity(Integer number) { - this.number = number; - } + public IntTestPrivSeqEntity(Integer number) { + this.number = number; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public Integer getNumber() { - return number; - } + public Integer getNumber() { + return number; + } - public void setNumber(Integer number) { - this.number = number; - } + public void setNumber(Integer number) { + this.number = number; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof IntTestPrivSeqEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof IntTestPrivSeqEntity) ) { + return false; + } - IntTestPrivSeqEntity that = (IntTestPrivSeqEntity) o; + IntTestPrivSeqEntity that = (IntTestPrivSeqEntity) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; - if (number != null ? !number.equals(that.number) : that.number != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } + if ( number != null ? !number.equals( that.number ) : that.number != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result = (id != null ? id.hashCode() : 0); - result = 31 * result + (number != null ? number.hashCode() : 0); - return result; - } + public int hashCode() { + int result = (id != null ? id.hashCode() : 0); + result = 31 * result + (number != null ? number.hashCode() : 0); + return result; + } - public String toString() { - return "ITPSE(id = " + id + ", number = " + number + ")"; - } + public String toString() { + return "ITPSE(id = " + id + ", number = " + number + ")"; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/PrimitiveTestEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/PrimitiveTestEntity.java index df383049a7..07a9f9524a 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/PrimitiveTestEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/PrimitiveTestEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; @@ -33,17 +34,17 @@ import org.hibernate.envers.Audited; */ @Entity public class PrimitiveTestEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - @Audited - private int numVal1; + @Audited + private int numVal1; private int numVal2; - public PrimitiveTestEntity() { - } + public PrimitiveTestEntity() { + } public PrimitiveTestEntity(int numVal1, int numVal2) { this.numVal1 = numVal1; @@ -57,20 +58,20 @@ public class PrimitiveTestEntity { } public Integer getId() { - return id; - } + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public Integer getNumVal1() { - return numVal1; - } + public Integer getNumVal1() { + return numVal1; + } - public void setNumVal1(Integer numVal1) { - this.numVal1 = numVal1; - } + public void setNumVal1(Integer numVal1) { + this.numVal1 = numVal1; + } public int getNumVal2() { return numVal2; @@ -82,14 +83,24 @@ public class PrimitiveTestEntity { @Override public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof PrimitiveTestEntity)) return false; + if ( this == o ) { + return true; + } + if ( !(o instanceof PrimitiveTestEntity) ) { + return false; + } PrimitiveTestEntity that = (PrimitiveTestEntity) o; - if (numVal1 != that.numVal1) return false; - if (numVal2 != that.numVal2) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( numVal1 != that.numVal1 ) { + return false; + } + if ( numVal2 != that.numVal2 ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } return true; } @@ -103,6 +114,6 @@ public class PrimitiveTestEntity { } public String toString() { - return "PTE(id = " + id + ", numVal1 = " + numVal1 + ", numVal2 = " + numVal2 + ")"; - } + return "PTE(id = " + id + ", numVal1 = " + numVal1 + ", numVal2 = " + numVal2 + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/StrIntTestEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/StrIntTestEntity.java index aad2ee8f2d..ce1e08bff2 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/StrIntTestEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/StrIntTestEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities; + import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -34,77 +35,87 @@ import org.hibernate.envers.Audited; */ @Entity public class StrIntTestEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - @Audited - private String str1; + @Audited + private String str1; - @Audited - @Column(name = "NUM_VAL") - private Integer number; + @Audited + @Column(name = "NUM_VAL") + private Integer number; - public StrIntTestEntity() { - } + public StrIntTestEntity() { + } - public StrIntTestEntity(String str1, Integer number, Integer id) { - this.id = id; - this.str1 = str1; - this.number = number; - } + public StrIntTestEntity(String str1, Integer number, Integer id) { + this.id = id; + this.str1 = str1; + this.number = number; + } - public StrIntTestEntity(String str1, Integer number) { - this.str1 = str1; - this.number = number; - } + public StrIntTestEntity(String str1, Integer number) { + this.str1 = str1; + this.number = number; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getStr1() { - return str1; - } + public String getStr1() { + return str1; + } - public void setStr1(String str1) { - this.str1 = str1; - } + public void setStr1(String str1) { + this.str1 = str1; + } - public Integer getNumber() { - return number; - } + public Integer getNumber() { + return number; + } - public void setNumber(Integer number) { - this.number = number; - } + public void setNumber(Integer number) { + this.number = number; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof StrIntTestEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof StrIntTestEntity) ) { + return false; + } - StrIntTestEntity that = (StrIntTestEntity) o; + StrIntTestEntity that = (StrIntTestEntity) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; - if (number != null ? !number.equals(that.number) : that.number != null) return false; - if (str1 != null ? !str1.equals(that.str1) : that.str1 != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } + if ( number != null ? !number.equals( that.number ) : that.number != null ) { + return false; + } + if ( str1 != null ? !str1.equals( that.str1 ) : that.str1 != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (str1 != null ? str1.hashCode() : 0); - result = 31 * result + (number != null ? number.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (str1 != null ? str1.hashCode() : 0); + result = 31 * result + (number != null ? number.hashCode() : 0); + return result; + } - public String toString() { - return "SITE(id = " + id + ", str1 = " + str1 + ", number = " + number + ")"; - } + public String toString() { + return "SITE(id = " + id + ", str1 = " + str1 + ", number = " + number + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/StrTestEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/StrTestEntity.java index aa268f4cde..ad55283b47 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/StrTestEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/StrTestEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; @@ -35,61 +36,69 @@ import org.hibernate.envers.Audited; @Entity @Table(name = "STR_TEST") public class StrTestEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - @Audited - private String str; + @Audited + private String str; - public StrTestEntity() { - } + public StrTestEntity() { + } - public StrTestEntity(String str, Integer id) { - this.str = str; - this.id = id; - } + public StrTestEntity(String str, Integer id) { + this.str = str; + this.id = id; + } - public StrTestEntity(String str) { - this.str = str; - } + public StrTestEntity(String str) { + this.str = str; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getStr() { - return str; - } + public String getStr() { + return str; + } - public void setStr(String str) { - this.str = str; - } + public void setStr(String str) { + this.str = str; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof StrTestEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof StrTestEntity) ) { + return false; + } - StrTestEntity that = (StrTestEntity) o; + StrTestEntity that = (StrTestEntity) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; - if (str != null ? !str.equals(that.str) : that.str != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } + if ( str != null ? !str.equals( that.str ) : that.str != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (str != null ? str.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (str != null ? str.hashCode() : 0); + return result; + } - public String toString() { - return "STE(id = " + id + ", str = " + str + ")"; - } + public String toString() { + return "STE(id = " + id + ", str = " + str + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/StrTestEntityComparator.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/StrTestEntityComparator.java index 5954cc8842..8f8ce8ef41 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/StrTestEntityComparator.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/StrTestEntityComparator.java @@ -3,10 +3,10 @@ package org.hibernate.envers.test.entities; import java.util.Comparator; public class StrTestEntityComparator implements Comparator { - public static final StrTestEntityComparator INSTANCE = new StrTestEntityComparator(); + public static final StrTestEntityComparator INSTANCE = new StrTestEntityComparator(); - @Override - public int compare(StrTestEntity o1, StrTestEntity o2) { - return o1.getStr().compareTo(o2.getStr()); - } + @Override + public int compare(StrTestEntity o1, StrTestEntity o2) { + return o1.getStr().compareTo( o2.getStr() ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/StrTestNoProxyEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/StrTestNoProxyEntity.java index 7a1ef0fb09..14d0b26e1f 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/StrTestNoProxyEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/StrTestNoProxyEntity.java @@ -23,11 +23,11 @@ */ package org.hibernate.envers.test.entities; -import java.io.Serializable; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.Table; +import java.io.Serializable; import org.hibernate.annotations.Proxy; import org.hibernate.envers.Audited; @@ -75,20 +75,28 @@ public class StrTestNoProxyEntity implements Serializable { } public boolean equals(Object o) { - if ( this == o ) return true; - if ( !( o instanceof StrTestNoProxyEntity ) ) return false; + if ( this == o ) { + return true; + } + if ( !(o instanceof StrTestNoProxyEntity) ) { + return false; + } StrTestNoProxyEntity that = (StrTestNoProxyEntity) o; - if ( id != null ? !id.equals( that.id ) : that.id != null ) return false; - if ( str != null ? !str.equals( that.str ) : that.str != null ) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } + if ( str != null ? !str.equals( that.str ) : that.str != null ) { + return false; + } return true; } public int hashCode() { - int result = ( id != null ? id.hashCode() : 0 ); - result = 31 * result + ( str != null ? str.hashCode() : 0 ); + int result = (id != null ? id.hashCode() : 0); + result = 31 * result + (str != null ? str.hashCode() : 0); return result; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/StrTestPrivSeqEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/StrTestPrivSeqEntity.java index 5f39679322..ff67fe54f9 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/StrTestPrivSeqEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/StrTestPrivSeqEntity.java @@ -11,68 +11,77 @@ import org.hibernate.envers.Audited; /** * Duplicate of {@link StrTestEntity} but with private sequence generator. + * * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ @Entity @Table(name = "STRSEQ") public class StrTestPrivSeqEntity { - @Id - @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "StrTestPrivSeq") - @SequenceGenerator(name = "StrTestPrivSeq", sequenceName="STRTESTPRIV_SEQ", - allocationSize = 1, initialValue = 1) - private Integer id; + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "StrTestPrivSeq") + @SequenceGenerator(name = "StrTestPrivSeq", sequenceName = "STRTESTPRIV_SEQ", + allocationSize = 1, initialValue = 1) + private Integer id; - @Audited - private String str; + @Audited + private String str; - public StrTestPrivSeqEntity() { - } + public StrTestPrivSeqEntity() { + } - public StrTestPrivSeqEntity(String str, Integer id) { - this.str = str; - this.id = id; - } + public StrTestPrivSeqEntity(String str, Integer id) { + this.str = str; + this.id = id; + } - public StrTestPrivSeqEntity(String str) { - this.str = str; - } + public StrTestPrivSeqEntity(String str) { + this.str = str; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getStr() { - return str; - } + public String getStr() { + return str; + } - public void setStr(String str) { - this.str = str; - } + public void setStr(String str) { + this.str = str; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof StrTestPrivSeqEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof StrTestPrivSeqEntity) ) { + return false; + } - StrTestPrivSeqEntity that = (StrTestPrivSeqEntity) o; + StrTestPrivSeqEntity that = (StrTestPrivSeqEntity) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; - if (str != null ? !str.equals(that.str) : that.str != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } + if ( str != null ? !str.equals( that.str ) : that.str != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (str != null ? str.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (str != null ? str.hashCode() : 0); + return result; + } - public String toString() { - return "STPSE(id = " + id + ", str = " + str + ")"; - } + public String toString() { + return "STPSE(id = " + id + ", str = " + str + ")"; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/UnversionedEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/UnversionedEntity.java index ac128fefdb..24335d37ef 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/UnversionedEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/UnversionedEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities; + import javax.persistence.Basic; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -36,73 +37,83 @@ import org.hibernate.envers.NotAudited; @Entity @Audited public class UnversionedEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - @Basic - private String data1; + @Basic + private String data1; - @Basic - @NotAudited - private String data2; + @Basic + @NotAudited + private String data2; - public UnversionedEntity() { - } + public UnversionedEntity() { + } - public UnversionedEntity(String data1, String data2) { - this.data1 = data1; - this.data2 = data2; - } + public UnversionedEntity(String data1, String data2) { + this.data1 = data1; + this.data2 = data2; + } - public UnversionedEntity(Integer id, String data1, String data2) { - this.id = id; - this.data1 = data1; - this.data2 = data2; - } + public UnversionedEntity(Integer id, String data1, String data2) { + this.id = id; + this.data1 = data1; + this.data2 = data2; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData1() { - return data1; - } + public String getData1() { + return data1; + } - public void setData1(String data1) { - this.data1 = data1; - } + public void setData1(String data1) { + this.data1 = data1; + } - public String getData2() { - return data2; - } + public String getData2() { + return data2; + } - public void setData2(String data2) { - this.data2 = data2; - } + public void setData2(String data2) { + this.data2 = data2; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof UnversionedEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof UnversionedEntity) ) { + return false; + } - UnversionedEntity that = (UnversionedEntity) o; + UnversionedEntity that = (UnversionedEntity) o; - if (data1 != null ? !data1.equals(that.data1) : that.data1 != null) return false; - if (data2 != null ? !data2.equals(that.data2) : that.data2 != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data1 != null ? !data1.equals( that.data1 ) : that.data1 != null ) { + return false; + } + if ( data2 != null ? !data2.equals( that.data2 ) : that.data2 != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data1 != null ? data1.hashCode() : 0); - result = 31 * result + (data2 != null ? data2.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data1 != null ? data1.hashCode() : 0); + result = 31 * result + (data2 != null ? data2.hashCode() : 0); + return result; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/UnversionedStrTestEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/UnversionedStrTestEntity.java index e4f0d80d6c..a21a157c36 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/UnversionedStrTestEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/UnversionedStrTestEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; @@ -33,60 +34,68 @@ import javax.persistence.Table; @Entity @Table(name = "UNVER_DATA") public class UnversionedStrTestEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - private String str; + private String str; - public UnversionedStrTestEntity() { - } + public UnversionedStrTestEntity() { + } - public UnversionedStrTestEntity(String str, Integer id) { - this.str = str; - this.id = id; - } + public UnversionedStrTestEntity(String str, Integer id) { + this.str = str; + this.id = id; + } - public UnversionedStrTestEntity(String str) { - this.str = str; - } + public UnversionedStrTestEntity(String str) { + this.str = str; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getStr() { - return str; - } + public String getStr() { + return str; + } - public void setStr(String str) { - this.str = str; - } + public void setStr(String str) { + this.str = str; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof UnversionedStrTestEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof UnversionedStrTestEntity) ) { + return false; + } - UnversionedStrTestEntity that = (UnversionedStrTestEntity) o; + UnversionedStrTestEntity that = (UnversionedStrTestEntity) o; - if (id != null ? !id.equals(that.getId()) : that.getId() != null) return false; - if (str != null ? !str.equals(that.getStr()) : that.getStr() != null) return false; + if ( id != null ? !id.equals( that.getId() ) : that.getId() != null ) { + return false; + } + if ( str != null ? !str.equals( that.getStr() ) : that.getStr() != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (str != null ? str.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (str != null ? str.hashCode() : 0); + return result; + } - public String toString() { - return "USTE(id = " + id + ", str = " + str + ")"; - } + public String toString() { + return "USTE(id = " + id + ", str = " + str + ")"; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/EmbeddableListEntity1.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/EmbeddableListEntity1.java index 8b93599693..ed01a9c864 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/EmbeddableListEntity1.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/EmbeddableListEntity1.java @@ -23,8 +23,6 @@ */ package org.hibernate.envers.test.entities.collection; -import java.util.ArrayList; -import java.util.List; import javax.persistence.CollectionTable; import javax.persistence.ElementCollection; import javax.persistence.Entity; @@ -32,6 +30,8 @@ import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.OrderColumn; import javax.persistence.Table; +import java.util.ArrayList; +import java.util.List; import org.hibernate.envers.Audited; import org.hibernate.envers.test.entities.components.Component3; @@ -82,18 +82,24 @@ public class EmbeddableListEntity1 { } public boolean equals(Object o) { - if ( this == o ) return true; - if ( !( o instanceof EmbeddableListEntity1 ) ) return false; + if ( this == o ) { + return true; + } + if ( !(o instanceof EmbeddableListEntity1) ) { + return false; + } EmbeddableListEntity1 that = (EmbeddableListEntity1) o; - if ( id != null ? !id.equals( that.id ) : that.id != null ) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } return true; } public int hashCode() { - return ( id != null ? id.hashCode() : 0 ); + return (id != null ? id.hashCode() : 0); } public String toString() { diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/EmbeddableListEntity2.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/EmbeddableListEntity2.java index 82029ab6fa..05b7ebd577 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/EmbeddableListEntity2.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/EmbeddableListEntity2.java @@ -23,8 +23,6 @@ */ package org.hibernate.envers.test.entities.collection; -import java.util.ArrayList; -import java.util.List; import javax.persistence.CollectionTable; import javax.persistence.ElementCollection; import javax.persistence.Entity; @@ -32,6 +30,8 @@ import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.OrderColumn; import javax.persistence.Table; +import java.util.ArrayList; +import java.util.List; import org.hibernate.envers.Audited; import org.hibernate.envers.test.entities.components.relations.ManyToOneEagerComponent; @@ -74,18 +74,24 @@ public class EmbeddableListEntity2 { } public boolean equals(Object o) { - if ( this == o ) return true; - if ( !( o instanceof EmbeddableListEntity2 ) ) return false; + if ( this == o ) { + return true; + } + if ( !(o instanceof EmbeddableListEntity2) ) { + return false; + } EmbeddableListEntity2 that = (EmbeddableListEntity2) o; - if ( id != null ? !id.equals( that.id ) : that.id != null ) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } return true; } public int hashCode() { - return ( id != null ? id.hashCode() : 0 ); + return (id != null ? id.hashCode() : 0); } public String toString() { diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/EmbeddableMapEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/EmbeddableMapEntity.java index 7e59ce4cce..7f2083558f 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/EmbeddableMapEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/EmbeddableMapEntity.java @@ -23,8 +23,6 @@ */ package org.hibernate.envers.test.entities.collection; -import java.util.HashMap; -import java.util.Map; import javax.persistence.CollectionTable; import javax.persistence.ElementCollection; import javax.persistence.Entity; @@ -32,6 +30,8 @@ import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.MapKeyColumn; import javax.persistence.Table; +import java.util.HashMap; +import java.util.Map; import org.hibernate.envers.Audited; import org.hibernate.envers.test.entities.components.Component3; @@ -73,18 +73,24 @@ public class EmbeddableMapEntity { } public boolean equals(Object o) { - if ( this == o ) return true; - if ( !( o instanceof EmbeddableMapEntity ) ) return false; + if ( this == o ) { + return true; + } + if ( !(o instanceof EmbeddableMapEntity) ) { + return false; + } EmbeddableMapEntity that = (EmbeddableMapEntity) o; - if ( id != null ? !id.equals( that.id ) : that.id != null ) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } return true; } public int hashCode() { - return ( id != null ? id.hashCode() : 0 ); + return (id != null ? id.hashCode() : 0); } public String toString() { diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/EmbeddableSetEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/EmbeddableSetEntity.java index e5a09afadf..0c7b8087cc 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/EmbeddableSetEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/EmbeddableSetEntity.java @@ -23,14 +23,14 @@ */ package org.hibernate.envers.test.entities.collection; -import java.util.HashSet; -import java.util.Set; import javax.persistence.CollectionTable; import javax.persistence.ElementCollection; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.Table; +import java.util.HashSet; +import java.util.Set; import org.hibernate.envers.Audited; import org.hibernate.envers.test.entities.components.Component3; @@ -70,18 +70,24 @@ public class EmbeddableSetEntity { } public boolean equals(Object o) { - if ( this == o ) return true; - if ( !( o instanceof EmbeddableSetEntity ) ) return false; + if ( this == o ) { + return true; + } + if ( !(o instanceof EmbeddableSetEntity) ) { + return false; + } EmbeddableSetEntity that = (EmbeddableSetEntity) o; - if ( id != null ? !id.equals( that.id ) : that.id != null ) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } return true; } public int hashCode() { - return ( id != null ? id.hashCode() : 0 ); + return (id != null ? id.hashCode() : 0); } public String toString() { diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/EnumSetEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/EnumSetEntity.java index f0d3efae39..3d7cecf751 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/EnumSetEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/EnumSetEntity.java @@ -22,14 +22,15 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.collection; -import java.util.HashSet; -import java.util.Set; + import javax.persistence.ElementCollection; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; import javax.persistence.GeneratedValue; import javax.persistence.Id; +import java.util.HashSet; +import java.util.Set; import org.hibernate.envers.Audited; @@ -38,68 +39,75 @@ import org.hibernate.envers.Audited; */ @Entity public class EnumSetEntity { - public static enum E1 { X, Y } - public static enum E2 { A, B } + public static enum E1 {X, Y} - @Id - @GeneratedValue - private Integer id; + public static enum E2 {A, B} - @Audited - @ElementCollection - @Enumerated(EnumType.STRING) - private Set enums1; + @Id + @GeneratedValue + private Integer id; - @Audited - @ElementCollection - @Enumerated(EnumType.ORDINAL) - private Set enums2; + @Audited + @ElementCollection + @Enumerated(EnumType.STRING) + private Set enums1; - public EnumSetEntity() { - enums1 = new HashSet(); - enums2 = new HashSet(); - } + @Audited + @ElementCollection + @Enumerated(EnumType.ORDINAL) + private Set enums2; - public Integer getId() { - return id; - } + public EnumSetEntity() { + enums1 = new HashSet(); + enums2 = new HashSet(); + } - public void setId(Integer id) { - this.id = id; - } + public Integer getId() { + return id; + } - public Set getEnums1() { - return enums1; - } + public void setId(Integer id) { + this.id = id; + } - public void setEnums1(Set enums1) { - this.enums1 = enums1; - } + public Set getEnums1() { + return enums1; + } - public Set getEnums2() { - return enums2; - } + public void setEnums1(Set enums1) { + this.enums1 = enums1; + } - public void setEnums2(Set enums2) { - this.enums2 = enums2; - } + public Set getEnums2() { + return enums2; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof EnumSetEntity)) return false; + public void setEnums2(Set enums2) { + this.enums2 = enums2; + } - EnumSetEntity that = (EnumSetEntity) o; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof EnumSetEntity) ) { + return false; + } - if (id != null ? !id.equals(that.id) : that.id != null) return false; + EnumSetEntity that = (EnumSetEntity) o; - return true; - } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - public int hashCode() { - return (id != null ? id.hashCode() : 0); - } + return true; + } - public String toString() { - return "ESE(id = " + id + ", enums1 = " + enums1 + ", enums2 = " + enums2 + ")"; - } + public int hashCode() { + return (id != null ? id.hashCode() : 0); + } + + public String toString() { + return "ESE(id = " + id + ", enums1 = " + enums1 + ", enums2 = " + enums2 + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/MultipleCollectionEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/MultipleCollectionEntity.java index 443b143ec5..79ed9e7b36 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/MultipleCollectionEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/MultipleCollectionEntity.java @@ -1,8 +1,5 @@ package org.hibernate.envers.test.entities.collection; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; @@ -13,6 +10,9 @@ import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.OneToMany; import javax.persistence.Version; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import org.hibernate.envers.AuditJoinTable; import org.hibernate.envers.Audited; @@ -59,27 +59,27 @@ public class MultipleCollectionEntity { } public List getRefEntities1() { - return Collections.unmodifiableList(refEntities1); + return Collections.unmodifiableList( refEntities1 ); } public void addRefEntity1(MultipleCollectionRefEntity1 refEntity1) { - refEntities1.add(refEntity1); + refEntities1.add( refEntity1 ); } public void removeRefEntity1(MultipleCollectionRefEntity1 refEntity1) { - refEntities1.remove(refEntity1); + refEntities1.remove( refEntity1 ); } public List getRefEntities2() { - return Collections.unmodifiableList(refEntities2); + return Collections.unmodifiableList( refEntities2 ); } public void addRefEntity2(MultipleCollectionRefEntity2 refEntity2) { - refEntities2.add(refEntity2); + refEntities2.add( refEntity2 ); } public void removeRefEntity2(MultipleCollectionRefEntity2 refEntity2) { - refEntities2.remove(refEntity2); + refEntities2.remove( refEntity2 ); } /** @@ -108,7 +108,7 @@ public class MultipleCollectionEntity { if ( this == o ) { return true; } - if ( ! ( o instanceof MultipleCollectionEntity ) ) { + if ( !(o instanceof MultipleCollectionEntity) ) { return false; } @@ -130,8 +130,8 @@ public class MultipleCollectionEntity { @Override public int hashCode() { int result = text != null ? text.hashCode() : 0; - result = 31 * result + ( refEntities1 != null ? refEntities1.hashCode() : 0 ); - result = 31 * result + ( refEntities2 != null ? refEntities2.hashCode() : 0 ); + result = 31 * result + (refEntities1 != null ? refEntities1.hashCode() : 0); + result = 31 * result + (refEntities2 != null ? refEntities2.hashCode() : 0); return result; } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/MultipleCollectionRefEntity1.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/MultipleCollectionRefEntity1.java index dcc1673874..462762552f 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/MultipleCollectionRefEntity1.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/MultipleCollectionRefEntity1.java @@ -82,7 +82,7 @@ public class MultipleCollectionRefEntity1 { if ( this == o ) { return true; } - if ( ! ( o instanceof MultipleCollectionRefEntity1 ) ) { + if ( !(o instanceof MultipleCollectionRefEntity1) ) { return false; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/MultipleCollectionRefEntity2.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/MultipleCollectionRefEntity2.java index a2df6456b7..a9c7dc283e 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/MultipleCollectionRefEntity2.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/MultipleCollectionRefEntity2.java @@ -82,7 +82,7 @@ public class MultipleCollectionRefEntity2 { if ( this == o ) { return true; } - if ( ! ( o instanceof MultipleCollectionRefEntity2 ) ) { + if ( !(o instanceof MultipleCollectionRefEntity2) ) { return false; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/StringListEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/StringListEntity.java index de0301f099..7fb7669c26 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/StringListEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/StringListEntity.java @@ -22,12 +22,13 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.collection; -import java.util.ArrayList; -import java.util.List; + import javax.persistence.ElementCollection; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; +import java.util.ArrayList; +import java.util.List; import org.hibernate.annotations.IndexColumn; import org.hibernate.envers.Audited; @@ -37,51 +38,57 @@ import org.hibernate.envers.Audited; */ @Entity public class StringListEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - @Audited - @ElementCollection - @IndexColumn(name = "list_index") - private List strings; + @Audited + @ElementCollection + @IndexColumn(name = "list_index") + private List strings; - public StringListEntity() { - strings = new ArrayList(); - } + public StringListEntity() { + strings = new ArrayList(); + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public List getStrings() { - return strings; - } + public List getStrings() { + return strings; + } - public void setStrings(List strings) { - this.strings = strings; - } + public void setStrings(List strings) { + this.strings = strings; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof StringListEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof StringListEntity) ) { + return false; + } - StringListEntity that = (StringListEntity) o; + StringListEntity that = (StringListEntity) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - return (id != null ? id.hashCode() : 0); - } + public int hashCode() { + return (id != null ? id.hashCode() : 0); + } - public String toString() { - return "SLE(id = " + id + ", strings = " + strings + ")"; - } + public String toString() { + return "SLE(id = " + id + ", strings = " + strings + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/StringMapEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/StringMapEntity.java index 5dd510d50a..717cf13472 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/StringMapEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/StringMapEntity.java @@ -22,13 +22,14 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.collection; -import java.util.HashMap; -import java.util.Map; + import javax.persistence.ElementCollection; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.MapKeyColumn; +import java.util.HashMap; +import java.util.Map; import org.hibernate.envers.Audited; @@ -37,51 +38,57 @@ import org.hibernate.envers.Audited; */ @Entity public class StringMapEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - @Audited - @ElementCollection - @MapKeyColumn(nullable=false) - private Map strings; + @Audited + @ElementCollection + @MapKeyColumn(nullable = false) + private Map strings; - public StringMapEntity() { - strings = new HashMap(); - } + public StringMapEntity() { + strings = new HashMap(); + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public Map getStrings() { - return strings; - } + public Map getStrings() { + return strings; + } - public void setStrings(Map strings) { - this.strings = strings; - } + public void setStrings(Map strings) { + this.strings = strings; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof StringMapEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof StringMapEntity) ) { + return false; + } - StringMapEntity that = (StringMapEntity) o; + StringMapEntity that = (StringMapEntity) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - return (id != null ? id.hashCode() : 0); - } + public int hashCode() { + return (id != null ? id.hashCode() : 0); + } - public String toString() { - return "SME(id = " + id + ", strings = " + strings + ")"; - } + public String toString() { + return "SME(id = " + id + ", strings = " + strings + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/StringSetEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/StringSetEntity.java index 2a8e75391b..20c3695a25 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/StringSetEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/collection/StringSetEntity.java @@ -22,12 +22,13 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.collection; -import java.util.HashSet; -import java.util.Set; + import javax.persistence.ElementCollection; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; +import java.util.HashSet; +import java.util.Set; import org.hibernate.envers.Audited; @@ -36,50 +37,56 @@ import org.hibernate.envers.Audited; */ @Entity public class StringSetEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - @Audited - @ElementCollection - private Set strings; + @Audited + @ElementCollection + private Set strings; - public StringSetEntity() { - strings = new HashSet(); - } + public StringSetEntity() { + strings = new HashSet(); + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public Set getStrings() { - return strings; - } + public Set getStrings() { + return strings; + } - public void setStrings(Set strings) { - this.strings = strings; - } + public void setStrings(Set strings) { + this.strings = strings; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof StringSetEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof StringSetEntity) ) { + return false; + } - StringSetEntity that = (StringSetEntity) o; + StringSetEntity that = (StringSetEntity) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - return (id != null ? id.hashCode() : 0); - } + public int hashCode() { + return (id != null ? id.hashCode() : 0); + } - public String toString() { - return "SSE(id = " + id + ", strings = " + strings + ")"; - } + public String toString() { + return "SSE(id = " + id + ", strings = " + strings + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/Component1.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/Component1.java index dbbd7cd8cd..5019b94186 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/Component1.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/Component1.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.components; + import javax.persistence.Embeddable; /** @@ -29,54 +30,62 @@ import javax.persistence.Embeddable; */ @Embeddable public class Component1 { - private String str1; + private String str1; - private String str2; + private String str2; - public Component1(String str1, String str2) { - this.str1 = str1; - this.str2 = str2; - } + public Component1(String str1, String str2) { + this.str1 = str1; + this.str2 = str2; + } - public Component1() { - } + public Component1() { + } - public String getStr2() { - return str2; - } + public String getStr2() { + return str2; + } - public void setStr2(String str2) { - this.str2 = str2; - } + public void setStr2(String str2) { + this.str2 = str2; + } - public String getStr1() { - return str1; - } + public String getStr1() { + return str1; + } - public void setStr1(String str1) { - this.str1 = str1; - } + public void setStr1(String str1) { + this.str1 = str1; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof Component1)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof Component1) ) { + return false; + } - Component1 that = (Component1) o; + Component1 that = (Component1) o; - if (str1 != null ? !str1.equals(that.str1) : that.str1 != null) return false; - if (str2 != null ? !str2.equals(that.str2) : that.str2 != null) return false; + if ( str1 != null ? !str1.equals( that.str1 ) : that.str1 != null ) { + return false; + } + if ( str2 != null ? !str2.equals( that.str2 ) : that.str2 != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (str1 != null ? str1.hashCode() : 0); - result = 31 * result + (str2 != null ? str2.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (str1 != null ? str1.hashCode() : 0); + result = 31 * result + (str2 != null ? str2.hashCode() : 0); + return result; + } - public String toString() { - return "Comp1(str1 = " + str1 + ", " + str2 + ")"; - } + public String toString() { + return "Comp1(str1 = " + str1 + ", " + str2 + ")"; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/Component2.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/Component2.java index b0dbf7b22b..72287abb86 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/Component2.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/Component2.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.components; + import javax.persistence.Embeddable; /** @@ -29,54 +30,62 @@ import javax.persistence.Embeddable; */ @Embeddable public class Component2 { - private String str5; + private String str5; - private String str6; + private String str6; - public Component2(String str5, String str6) { - this.str5 = str5; - this.str6 = str6; - } + public Component2(String str5, String str6) { + this.str5 = str5; + this.str6 = str6; + } - public Component2() { - } + public Component2() { + } - public String getStr5() { - return str5; - } + public String getStr5() { + return str5; + } - public void setStr5(String str5) { - this.str5 = str5; - } + public void setStr5(String str5) { + this.str5 = str5; + } - public String getStr6() { - return str6; - } + public String getStr6() { + return str6; + } - public void setStr6(String str6) { - this.str6 = str6; - } + public void setStr6(String str6) { + this.str6 = str6; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof Component2)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof Component2) ) { + return false; + } - Component2 that = (Component2) o; + Component2 that = (Component2) o; - if (str5 != null ? !str5.equals(that.str5) : that.str5 != null) return false; - if (str6 != null ? !str6.equals(that.str6) : that.str6 != null) return false; + if ( str5 != null ? !str5.equals( that.str5 ) : that.str5 != null ) { + return false; + } + if ( str6 != null ? !str6.equals( that.str6 ) : that.str6 != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (str5 != null ? str5.hashCode() : 0); - result = 31 * result + (str6 != null ? str6.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (str5 != null ? str5.hashCode() : 0); + result = 31 * result + (str6 != null ? str6.hashCode() : 0); + return result; + } - public String toString() { - return "Comp2(str1 = " + str5 + ", " + str6 + ")"; - } + public String toString() { + return "Comp2(str1 = " + str5 + ", " + str6 + ")"; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/Component3.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/Component3.java index ac6f956b8c..f23351a94b 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/Component3.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/Component3.java @@ -43,18 +43,19 @@ public class Component3 { private String str1; @AttributeOverrides({ - @AttributeOverride(name = "key", column = @Column(name = "audComp_key")), - @AttributeOverride(name = "value", column = @Column(name = "audComp_value")), - @AttributeOverride(name = "description", column = @Column(name = "audComp_description")) - }) + @AttributeOverride(name = "key", column = @Column(name = "audComp_key")), + @AttributeOverride(name = "value", column = @Column(name = "audComp_value")), + @AttributeOverride(name = "description", column = @Column(name = "audComp_description")) + }) private Component4 auditedComponent; @NotAudited @AttributeOverrides({ - @AttributeOverride(name = "key", column = @Column(name = "notAudComp_key")), - @AttributeOverride(name = "value", column = @Column(name = "notAudComp_value")), - @AttributeOverride(name = "description", column = @Column(name = "notAudComp_description")) - }) + @AttributeOverride(name = "key", column = @Column(name = "notAudComp_key")), + @AttributeOverride(name = "value", column = @Column(name = "notAudComp_value")), + @AttributeOverride(name = "description", + column = @Column(name = "notAudComp_description")) + }) private Component4 nonAuditedComponent; public Component3() { @@ -94,20 +95,30 @@ public class Component3 { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ( ( auditedComponent == null ) ? 0 : auditedComponent.hashCode() ); - result = prime * result + ( ( str1 == null ) ? 0 : str1.hashCode() ); + result = prime * result + ((auditedComponent == null) ? 0 : auditedComponent.hashCode()); + result = prime * result + ((str1 == null) ? 0 : str1.hashCode()); return result; } @Override public boolean equals(Object obj) { - if ( this == obj ) return true; - if ( !( obj instanceof Component3 ) ) return false; + if ( this == obj ) { + return true; + } + if ( !(obj instanceof Component3) ) { + return false; + } Component3 other = (Component3) obj; - if ( auditedComponent != null ? !auditedComponent.equals( other.auditedComponent ) : other.auditedComponent != null ) return false; - if ( str1 != null ? !str1.equals( other.str1 ) : other.str1 != null ) return false; + if ( auditedComponent != null ? + !auditedComponent.equals( other.auditedComponent ) : + other.auditedComponent != null ) { + return false; + } + if ( str1 != null ? !str1.equals( other.str1 ) : other.str1 != null ) { + return false; + } return true; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/Component4.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/Component4.java index 20924c577d..e18bc7e329 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/Component4.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/Component4.java @@ -77,22 +77,32 @@ public class Component4 { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ( ( description == null ) ? 0 : description.hashCode() ); - result = prime * result + ( ( key == null ) ? 0 : key.hashCode() ); - result = prime * result + ( ( value == null ) ? 0 : value.hashCode() ); + result = prime * result + ((description == null) ? 0 : description.hashCode()); + result = prime * result + ((key == null) ? 0 : key.hashCode()); + result = prime * result + ((value == null) ? 0 : value.hashCode()); return result; } @Override public boolean equals(Object obj) { - if ( this == obj ) return true; - if ( !( obj instanceof Component4 ) ) return false; + if ( this == obj ) { + return true; + } + if ( !(obj instanceof Component4) ) { + return false; + } Component4 other = (Component4) obj; - if ( description != null ? !description.equals( other.description ) : other.description != null ) return false; - if ( key != null ? !key.equals( other.key ) : other.key != null ) return false; - if ( value != null ? !value.equals( other.value ) : other.value != null ) return false; + if ( description != null ? !description.equals( other.description ) : other.description != null ) { + return false; + } + if ( key != null ? !key.equals( other.key ) : other.key != null ) { + return false; + } + if ( value != null ? !value.equals( other.value ) : other.value != null ) { + return false; + } return true; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/ComponentSetTestEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/ComponentSetTestEntity.java index e38661ad7b..a9f0e7d634 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/ComponentSetTestEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/ComponentSetTestEntity.java @@ -22,12 +22,13 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.components; -import java.util.HashSet; -import java.util.Set; + import javax.persistence.Embedded; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; +import java.util.HashSet; +import java.util.Set; import org.hibernate.envers.Audited; @@ -37,13 +38,13 @@ import org.hibernate.envers.Audited; @Entity @Audited public class ComponentSetTestEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - @Embedded - @Audited - private Set comps = new HashSet(); + @Embedded + @Audited + private Set comps = new HashSet(); public ComponentSetTestEntity() { } @@ -53,12 +54,12 @@ public class ComponentSetTestEntity { } public Integer getId() { - return id; - } + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } public Set getComps() { return comps; @@ -70,13 +71,21 @@ public class ComponentSetTestEntity { @Override public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ComponentSetTestEntity)) return false; + if ( this == o ) { + return true; + } + if ( !(o instanceof ComponentSetTestEntity) ) { + return false; + } ComponentSetTestEntity that = (ComponentSetTestEntity) o; - if (comps != null ? !comps.equals(that.comps) : that.comps != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( comps != null ? !comps.equals( that.comps ) : that.comps != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } return true; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/ComponentTestEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/ComponentTestEntity.java index f27640ae0d..56b79c1104 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/ComponentTestEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/ComponentTestEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.components; + import javax.persistence.Embedded; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -36,77 +37,87 @@ import org.hibernate.envers.Audited; @Entity @Table(name = "CompTest") public class ComponentTestEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - @Embedded - @Audited - private Component1 comp1; + @Embedded + @Audited + private Component1 comp1; - @Embedded - private Component2 comp2; + @Embedded + private Component2 comp2; - public ComponentTestEntity() { - } + public ComponentTestEntity() { + } - public ComponentTestEntity(Integer id, Component1 comp1, Component2 comp2) { - this.id = id; - this.comp1 = comp1; - this.comp2 = comp2; - } + public ComponentTestEntity(Integer id, Component1 comp1, Component2 comp2) { + this.id = id; + this.comp1 = comp1; + this.comp2 = comp2; + } - public ComponentTestEntity(Component1 comp1, Component2 comp2) { - this.comp1 = comp1; - this.comp2 = comp2; - } + public ComponentTestEntity(Component1 comp1, Component2 comp2) { + this.comp1 = comp1; + this.comp2 = comp2; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public Component1 getComp1() { - return comp1; - } + public Component1 getComp1() { + return comp1; + } - public void setComp1(Component1 comp1) { - this.comp1 = comp1; - } + public void setComp1(Component1 comp1) { + this.comp1 = comp1; + } - public Component2 getComp2() { - return comp2; - } + public Component2 getComp2() { + return comp2; + } - public void setComp2(Component2 comp2) { - this.comp2 = comp2; - } + public void setComp2(Component2 comp2) { + this.comp2 = comp2; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ComponentTestEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ComponentTestEntity) ) { + return false; + } - ComponentTestEntity that = (ComponentTestEntity) o; + ComponentTestEntity that = (ComponentTestEntity) o; - if (comp1 != null ? !comp1.equals(that.comp1) : that.comp1 != null) return false; - if (comp2 != null ? !comp2.equals(that.comp2) : that.comp2 != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( comp1 != null ? !comp1.equals( that.comp1 ) : that.comp1 != null ) { + return false; + } + if ( comp2 != null ? !comp2.equals( that.comp2 ) : that.comp2 != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (comp1 != null ? comp1.hashCode() : 0); - result = 31 * result + (comp2 != null ? comp2.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (comp1 != null ? comp1.hashCode() : 0); + result = 31 * result + (comp2 != null ? comp2.hashCode() : 0); + return result; + } - public String toString() { - return "CTE(id = " + id + ", comp1 = " + comp1 + ", comp2 = " + comp2 + ")"; - } + public String toString() { + return "CTE(id = " + id + ", comp1 = " + comp1 + ", comp2 = " + comp2 + ")"; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/DefaultValueComponent1.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/DefaultValueComponent1.java index 15a63e6342..753f04dfce 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/DefaultValueComponent1.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/DefaultValueComponent1.java @@ -1,10 +1,9 @@ package org.hibernate.envers.test.entities.components; + import javax.persistence.Embedded; /** - * * @author Erik-Berndt Scheper - * */ public class DefaultValueComponent1 { @@ -13,11 +12,12 @@ public class DefaultValueComponent1 { @Embedded private DefaultValueComponent2 comp2 = new DefaultValueComponent2(); - public static final DefaultValueComponent1 of(String str1, + public static final DefaultValueComponent1 of( + String str1, DefaultValueComponent2 comp2) { DefaultValueComponent1 instance = new DefaultValueComponent1(); - instance.setStr1(str1); - instance.setComp2(comp2); + instance.setStr1( str1 ); + instance.setComp2( comp2 ); return instance; } @@ -38,17 +38,21 @@ public class DefaultValueComponent1 { } public boolean equals(Object o) { - if (this == o) + if ( this == o ) { return true; - if (!(o instanceof DefaultValueComponent1)) + } + if ( !(o instanceof DefaultValueComponent1) ) { return false; + } DefaultValueComponent1 that = (DefaultValueComponent1) o; - if (str1 != null ? !str1.equals(that.str1) : that.str1 != null) + if ( str1 != null ? !str1.equals( that.str1 ) : that.str1 != null ) { return false; - if (comp2 != null ? !comp2.equals(that.comp2) : that.comp2 != null) + } + if ( comp2 != null ? !comp2.equals( that.comp2 ) : that.comp2 != null ) { return false; + } return true; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/DefaultValueComponent2.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/DefaultValueComponent2.java index 3418c4e620..d84b532043 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/DefaultValueComponent2.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/DefaultValueComponent2.java @@ -2,9 +2,7 @@ package org.hibernate.envers.test.entities.components; /** - * * @author Erik-Berndt Scheper - * */ public class DefaultValueComponent2 { @@ -14,8 +12,8 @@ public class DefaultValueComponent2 { public static final DefaultValueComponent2 of(String str1, String str2) { DefaultValueComponent2 instance = new DefaultValueComponent2(); - instance.setStr1(str1); - instance.setStr2(str2); + instance.setStr1( str1 ); + instance.setStr2( str2 ); return instance; } @@ -36,17 +34,21 @@ public class DefaultValueComponent2 { } public boolean equals(Object o) { - if (this == o) + if ( this == o ) { return true; - if (!(o instanceof DefaultValueComponent2)) + } + if ( !(o instanceof DefaultValueComponent2) ) { return false; + } DefaultValueComponent2 that = (DefaultValueComponent2) o; - if (str1 != null ? !str1.equals(that.str1) : that.str1 != null) + if ( str1 != null ? !str1.equals( that.str1 ) : that.str1 != null ) { return false; - if (str2 != null ? !str2.equals(that.str2) : that.str2 != null) + } + if ( str2 != null ? !str2.equals( that.str2 ) : that.str2 != null ) { return false; + } return true; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/DefaultValueComponentTestEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/DefaultValueComponentTestEntity.java index d6afac3556..4df4c6b4d2 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/DefaultValueComponentTestEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/DefaultValueComponentTestEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.components; + import javax.persistence.AttributeOverride; import javax.persistence.AttributeOverrides; import javax.persistence.Column; @@ -46,7 +47,7 @@ public class DefaultValueComponentTestEntity { @Embedded @Audited - @AttributeOverrides( { @AttributeOverride(name = "comp2.str1", column = @Column(name = "COMP2_STR1")) }) + @AttributeOverrides({@AttributeOverride(name = "comp2.str1", column = @Column(name = "COMP2_STR1"))}) private DefaultValueComponent1 comp1 = null; public DefaultValueComponentTestEntity() { @@ -55,15 +56,16 @@ public class DefaultValueComponentTestEntity { public static DefaultValueComponentTestEntity of( DefaultValueComponent1 comp1) { DefaultValueComponentTestEntity instance = new DefaultValueComponentTestEntity(); - instance.setComp1(comp1); + instance.setComp1( comp1 ); return instance; } - public static DefaultValueComponentTestEntity of(Integer id, + public static DefaultValueComponentTestEntity of( + Integer id, DefaultValueComponent1 comp1) { DefaultValueComponentTestEntity instance = new DefaultValueComponentTestEntity(); - instance.setId(id); - instance.setComp1(comp1); + instance.setId( id ); + instance.setComp1( comp1 ); return instance; } @@ -84,17 +86,21 @@ public class DefaultValueComponentTestEntity { } public boolean equals(Object o) { - if (this == o) + if ( this == o ) { return true; - if (!(o instanceof DefaultValueComponentTestEntity)) + } + if ( !(o instanceof DefaultValueComponentTestEntity) ) { return false; + } DefaultValueComponentTestEntity that = (DefaultValueComponentTestEntity) o; - if (comp1 != null ? !comp1.equals(that.comp1) : that.comp1 != null) + if ( comp1 != null ? !comp1.equals( that.comp1 ) : that.comp1 != null ) { return false; - if (id != null ? !id.equals(that.id) : that.id != null) + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { return false; + } return true; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/UniquePropsEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/UniquePropsEntity.java index 7540dd0a09..afea99ee51 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/UniquePropsEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/UniquePropsEntity.java @@ -9,66 +9,76 @@ import org.hibernate.envers.Audited; */ @Audited public class UniquePropsEntity implements Serializable { - private Long id; - private String data1; - private String data2; + private Long id; + private String data1; + private String data2; - public UniquePropsEntity() { - } + public UniquePropsEntity() { + } - public UniquePropsEntity(Long id, String data1, String data2) { - this.id = id; - this.data1 = data1; - this.data2 = data2; - } + public UniquePropsEntity(Long id, String data1, String data2) { + this.id = id; + this.data1 = data1; + this.data2 = data2; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } - UniquePropsEntity that = (UniquePropsEntity) o; + UniquePropsEntity that = (UniquePropsEntity) o; - if (data1 != null ? !data1.equals(that.data1) : that.data1 != null) return false; - if (data2 != null ? !data2.equals(that.data2) : that.data2 != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data1 != null ? !data1.equals( that.data1 ) : that.data1 != null ) { + return false; + } + if ( data2 != null ? !data2.equals( that.data2 ) : that.data2 != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - int result = id != null ? id.hashCode() : 0; - result = 31 * result + (data1 != null ? data1.hashCode() : 0); - result = 31 * result + (data2 != null ? data2.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = id != null ? id.hashCode() : 0; + result = 31 * result + (data1 != null ? data1.hashCode() : 0); + result = 31 * result + (data2 != null ? data2.hashCode() : 0); + return result; + } - public String toString() { - return "UniquePropsEntity(id = " + id + ", data1 = " + data1 + ", data2 = " + data2 + ")"; - } + public String toString() { + return "UniquePropsEntity(id = " + id + ", data1 = " + data1 + ", data2 = " + data2 + ")"; + } - public Long getId() { - return id; - } + public Long getId() { + return id; + } - public void setId(Long id) { - this.id = id; - } + public void setId(Long id) { + this.id = id; + } - public String getData1() { - return data1; - } + public String getData1() { + return data1; + } - public void setData1(String data1) { - this.data1 = data1; - } + public void setData1(String data1) { + this.data1 = data1; + } - public String getData2() { - return data2; - } + public String getData2() { + return data2; + } - public void setData2(String data2) { - this.data2 = data2; - } + public void setData2(String data2) { + this.data2 = data2; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/UniquePropsNotAuditedEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/UniquePropsNotAuditedEntity.java index cb034843de..8cf82e3647 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/UniquePropsNotAuditedEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/UniquePropsNotAuditedEntity.java @@ -8,67 +8,77 @@ import org.hibernate.envers.NotAudited; */ @Audited public class UniquePropsNotAuditedEntity { - private Long id; - private String data1; - private String data2; + private Long id; + private String data1; + private String data2; - public UniquePropsNotAuditedEntity() { - } + public UniquePropsNotAuditedEntity() { + } - public UniquePropsNotAuditedEntity(Long id, String data1, String data2) { - this.id = id; - this.data1 = data1; - this.data2 = data2; - } + public UniquePropsNotAuditedEntity(Long id, String data1, String data2) { + this.id = id; + this.data1 = data1; + this.data2 = data2; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } - UniquePropsNotAuditedEntity that = (UniquePropsNotAuditedEntity) o; + UniquePropsNotAuditedEntity that = (UniquePropsNotAuditedEntity) o; - if (data1 != null ? !data1.equals(that.data1) : that.data1 != null) return false; - if (data2 != null ? !data2.equals(that.data2) : that.data2 != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data1 != null ? !data1.equals( that.data1 ) : that.data1 != null ) { + return false; + } + if ( data2 != null ? !data2.equals( that.data2 ) : that.data2 != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - int result = id != null ? id.hashCode() : 0; - result = 31 * result + (data1 != null ? data1.hashCode() : 0); - result = 31 * result + (data2 != null ? data2.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = id != null ? id.hashCode() : 0; + result = 31 * result + (data1 != null ? data1.hashCode() : 0); + result = 31 * result + (data2 != null ? data2.hashCode() : 0); + return result; + } - public String toString() { - return "UniquePropsNotAuditedEntity(id = " + id + ", data1 = " + data1 + ", data2 = " + data2 + ")"; - } + public String toString() { + return "UniquePropsNotAuditedEntity(id = " + id + ", data1 = " + data1 + ", data2 = " + data2 + ")"; + } - public Long getId() { - return id; - } + public Long getId() { + return id; + } - public void setId(Long id) { - this.id = id; - } + public void setId(Long id) { + this.id = id; + } - public String getData1() { - return data1; - } + public String getData1() { + return data1; + } - public void setData1(String data1) { - this.data1 = data1; - } + public void setData1(String data1) { + this.data1 = data1; + } - @NotAudited - public String getData2() { - return data2; - } + @NotAudited + public String getData2() { + return data2; + } - public void setData2(String data2) { - this.data2 = data2; - } + public void setData2(String data2) { + this.data2 = data2; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/relations/ManyToOneComponent.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/relations/ManyToOneComponent.java index 2dd415791f..f3d9d1c8ad 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/relations/ManyToOneComponent.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/relations/ManyToOneComponent.java @@ -36,25 +36,25 @@ import org.hibernate.envers.test.entities.StrTestEntity; @Table(name = "ManyToOneCompEmb") public class ManyToOneComponent { @ManyToOne - private StrTestEntity entity; + private StrTestEntity entity; - private String data; + private String data; public ManyToOneComponent(StrTestEntity entity, String data) { - this.entity = entity; - this.data = data; - } + this.entity = entity; + this.data = data; + } - public ManyToOneComponent() { - } + public ManyToOneComponent() { + } public String getData() { - return data; - } + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } public StrTestEntity getEntity() { return entity; @@ -66,13 +66,21 @@ public class ManyToOneComponent { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } ManyToOneComponent that = (ManyToOneComponent) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (entity != null ? !entity.equals(that.entity) : that.entity != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( entity != null ? !entity.equals( that.entity ) : that.entity != null ) { + return false; + } return true; } @@ -85,6 +93,6 @@ public class ManyToOneComponent { } public String toString() { - return "ManyToOneComponent(str1 = " + data + ")"; - } + return "ManyToOneComponent(str1 = " + data + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/relations/ManyToOneComponentTestEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/relations/ManyToOneComponentTestEntity.java index f5bb47b34c..a0bf0ebf99 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/relations/ManyToOneComponentTestEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/relations/ManyToOneComponentTestEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.components.relations; + import javax.persistence.Embedded; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -36,51 +37,59 @@ import org.hibernate.envers.Audited; @Entity @Table(name = "ManyToOneCompEnt") public class ManyToOneComponentTestEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - @Embedded - @Audited - private ManyToOneComponent comp1; + @Embedded + @Audited + private ManyToOneComponent comp1; - public ManyToOneComponentTestEntity() { - } + public ManyToOneComponentTestEntity() { + } - public ManyToOneComponentTestEntity(Integer id, ManyToOneComponent comp1) { - this.id = id; - this.comp1 = comp1; - } + public ManyToOneComponentTestEntity(Integer id, ManyToOneComponent comp1) { + this.id = id; + this.comp1 = comp1; + } - public ManyToOneComponentTestEntity(ManyToOneComponent comp1) { - this.comp1 = comp1; - } + public ManyToOneComponentTestEntity(ManyToOneComponent comp1) { + this.comp1 = comp1; + } public Integer getId() { - return id; - } + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public ManyToOneComponent getComp1() { - return comp1; - } + public ManyToOneComponent getComp1() { + return comp1; + } - public void setComp1(ManyToOneComponent comp1) { - this.comp1 = comp1; - } + public void setComp1(ManyToOneComponent comp1) { + this.comp1 = comp1; + } @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } ManyToOneComponentTestEntity that = (ManyToOneComponentTestEntity) o; - if (comp1 != null ? !comp1.equals(that.comp1) : that.comp1 != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( comp1 != null ? !comp1.equals( that.comp1 ) : that.comp1 != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } return true; } @@ -93,6 +102,6 @@ public class ManyToOneComponentTestEntity { } public String toString() { - return "MTOCTE(id = " + id + ", comp1 = " + comp1 + ")"; - } + return "MTOCTE(id = " + id + ", comp1 = " + comp1 + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/relations/ManyToOneEagerComponent.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/relations/ManyToOneEagerComponent.java index 9de66b66ca..490ef371a5 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/relations/ManyToOneEagerComponent.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/relations/ManyToOneEagerComponent.java @@ -70,13 +70,21 @@ public class ManyToOneEagerComponent { @Override public boolean equals(Object o) { - if ( this == o ) return true; - if ( !( o instanceof ManyToOneEagerComponent ) ) return false; + if ( this == o ) { + return true; + } + if ( !(o instanceof ManyToOneEagerComponent) ) { + return false; + } ManyToOneEagerComponent that = (ManyToOneEagerComponent) o; - if ( data != null ? !data.equals( that.data ) : that.data != null ) return false; - if ( entity != null ? !entity.equals( that.entity ) : that.entity != null ) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( entity != null ? !entity.equals( that.entity ) : that.entity != null ) { + return false; + } return true; } @@ -84,7 +92,7 @@ public class ManyToOneEagerComponent { @Override public int hashCode() { int result = entity != null ? entity.hashCode() : 0; - result = 31 * result + ( data != null ? data.hashCode() : 0 ); + result = 31 * result + (data != null ? data.hashCode() : 0); return result; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/relations/NotAuditedManyToOneComponent.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/relations/NotAuditedManyToOneComponent.java index d98be4cd53..267513638a 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/relations/NotAuditedManyToOneComponent.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/relations/NotAuditedManyToOneComponent.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.components.relations; + import javax.persistence.Embeddable; import javax.persistence.ManyToOne; import javax.persistence.Table; @@ -37,25 +38,25 @@ import org.hibernate.envers.test.entities.UnversionedStrTestEntity; public class NotAuditedManyToOneComponent { @ManyToOne @NotAudited - private UnversionedStrTestEntity entity; + private UnversionedStrTestEntity entity; - private String data; + private String data; public NotAuditedManyToOneComponent(UnversionedStrTestEntity entity, String data) { - this.entity = entity; - this.data = data; - } + this.entity = entity; + this.data = data; + } - public NotAuditedManyToOneComponent() { - } + public NotAuditedManyToOneComponent() { + } public String getData() { - return data; - } + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } public UnversionedStrTestEntity getEntity() { return entity; @@ -67,13 +68,21 @@ public class NotAuditedManyToOneComponent { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } NotAuditedManyToOneComponent that = (NotAuditedManyToOneComponent) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (entity != null ? !entity.equals(that.entity) : that.entity != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( entity != null ? !entity.equals( that.entity ) : that.entity != null ) { + return false; + } return true; } @@ -86,6 +95,6 @@ public class NotAuditedManyToOneComponent { } public String toString() { - return "NotAuditedManyToOneComponent(str1 = " + data + ")"; - } + return "NotAuditedManyToOneComponent(str1 = " + data + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/relations/NotAuditedManyToOneComponentTestEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/relations/NotAuditedManyToOneComponentTestEntity.java index 335802ae9a..7cf7d7191f 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/relations/NotAuditedManyToOneComponentTestEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/relations/NotAuditedManyToOneComponentTestEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.components.relations; + import javax.persistence.Embedded; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -36,51 +37,59 @@ import org.hibernate.envers.Audited; @Entity @Table(name = "NotAudM2OCompEnt") public class NotAuditedManyToOneComponentTestEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - @Embedded - @Audited - private NotAuditedManyToOneComponent comp1; + @Embedded + @Audited + private NotAuditedManyToOneComponent comp1; - public NotAuditedManyToOneComponentTestEntity() { - } + public NotAuditedManyToOneComponentTestEntity() { + } - public NotAuditedManyToOneComponentTestEntity(Integer id, NotAuditedManyToOneComponent comp1) { - this.id = id; - this.comp1 = comp1; - } + public NotAuditedManyToOneComponentTestEntity(Integer id, NotAuditedManyToOneComponent comp1) { + this.id = id; + this.comp1 = comp1; + } - public NotAuditedManyToOneComponentTestEntity(NotAuditedManyToOneComponent comp1) { - this.comp1 = comp1; - } + public NotAuditedManyToOneComponentTestEntity(NotAuditedManyToOneComponent comp1) { + this.comp1 = comp1; + } public Integer getId() { - return id; - } + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public NotAuditedManyToOneComponent getComp1() { - return comp1; - } + public NotAuditedManyToOneComponent getComp1() { + return comp1; + } - public void setComp1(NotAuditedManyToOneComponent comp1) { - this.comp1 = comp1; - } + public void setComp1(NotAuditedManyToOneComponent comp1) { + this.comp1 = comp1; + } @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } NotAuditedManyToOneComponentTestEntity that = (NotAuditedManyToOneComponentTestEntity) o; - if (comp1 != null ? !comp1.equals(that.comp1) : that.comp1 != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( comp1 != null ? !comp1.equals( that.comp1 ) : that.comp1 != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } return true; } @@ -93,6 +102,6 @@ public class NotAuditedManyToOneComponentTestEntity { } public String toString() { - return "NAMTOCTE(id = " + id + ", comp1 = " + comp1 + ")"; - } + return "NAMTOCTE(id = " + id + ", comp1 = " + comp1 + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/relations/OneToManyComponent.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/relations/OneToManyComponent.java index 7be3aa3123..ffbc740e91 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/relations/OneToManyComponent.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/relations/OneToManyComponent.java @@ -22,10 +22,11 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.components.relations; -import java.util.HashSet; -import java.util.Set; + import javax.persistence.Embeddable; import javax.persistence.OneToMany; +import java.util.HashSet; +import java.util.Set; import org.hibernate.envers.test.entities.StrTestEntity; @@ -35,24 +36,24 @@ import org.hibernate.envers.test.entities.StrTestEntity; @Embeddable public class OneToManyComponent { @OneToMany - private Set entities = new HashSet(); + private Set entities = new HashSet(); - private String data; + private String data; public OneToManyComponent(String data) { - this.data = data; - } + this.data = data; + } - public OneToManyComponent() { - } + public OneToManyComponent() { + } public String getData() { - return data; - } + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } public Set getEntities() { return entities; @@ -64,13 +65,21 @@ public class OneToManyComponent { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } OneToManyComponent that = (OneToManyComponent) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (entities != null ? !entities.equals(that.entities) : that.entities != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( entities != null ? !entities.equals( that.entities ) : that.entities != null ) { + return false; + } return true; } @@ -83,6 +92,6 @@ public class OneToManyComponent { } public String toString() { - return "OneToManyComponent(data = " + data + ")"; - } + return "OneToManyComponent(data = " + data + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/relations/OneToManyComponentTestEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/relations/OneToManyComponentTestEntity.java index 6669c97a24..e3c4e780d4 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/relations/OneToManyComponentTestEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/components/relations/OneToManyComponentTestEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.components.relations; + import javax.persistence.Embedded; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -36,51 +37,59 @@ import org.hibernate.envers.Audited; @Entity @Table(name = "OneToManyComp") public class OneToManyComponentTestEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - @Embedded - @Audited - private OneToManyComponent comp1; + @Embedded + @Audited + private OneToManyComponent comp1; - public OneToManyComponentTestEntity() { - } + public OneToManyComponentTestEntity() { + } - public OneToManyComponentTestEntity(Integer id, OneToManyComponent comp1) { - this.id = id; - this.comp1 = comp1; - } + public OneToManyComponentTestEntity(Integer id, OneToManyComponent comp1) { + this.id = id; + this.comp1 = comp1; + } - public OneToManyComponentTestEntity(OneToManyComponent comp1) { - this.comp1 = comp1; - } + public OneToManyComponentTestEntity(OneToManyComponent comp1) { + this.comp1 = comp1; + } public Integer getId() { - return id; - } + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public OneToManyComponent getComp1() { - return comp1; - } + public OneToManyComponent getComp1() { + return comp1; + } - public void setComp1(OneToManyComponent comp1) { - this.comp1 = comp1; - } + public void setComp1(OneToManyComponent comp1) { + this.comp1 = comp1; + } @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } OneToManyComponentTestEntity that = (OneToManyComponentTestEntity) o; - if (comp1 != null ? !comp1.equals(that.comp1) : that.comp1 != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( comp1 != null ? !comp1.equals( that.comp1 ) : that.comp1 != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } return true; } @@ -93,6 +102,6 @@ public class OneToManyComponentTestEntity { } public String toString() { - return "OTMCTE(id = " + id + ", comp1 = " + comp1 + ")"; - } + return "OTMCTE(id = " + id + ", comp1 = " + comp1 + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/customtype/Component.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/customtype/Component.java index 3ac71e0430..c839fc5daa 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/customtype/Component.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/customtype/Component.java @@ -22,55 +22,64 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.customtype; + import java.io.Serializable; /** * @author Adam Warski (adam at warski dot org) */ public class Component implements Serializable { - private String prop1; - private int prop2; + private String prop1; + private int prop2; - public Component(String prop1, int prop2) { - this.prop1 = prop1; - this.prop2 = prop2; - } + public Component(String prop1, int prop2) { + this.prop1 = prop1; + this.prop2 = prop2; + } - public Component() { - } + public Component() { + } - public String getProp1() { - return prop1; - } + public String getProp1() { + return prop1; + } - public void setProp1(String prop1) { - this.prop1 = prop1; - } + public void setProp1(String prop1) { + this.prop1 = prop1; + } - public int getProp2() { - return prop2; - } + public int getProp2() { + return prop2; + } - public void setProp2(int prop2) { - this.prop2 = prop2; - } + public void setProp2(int prop2) { + this.prop2 = prop2; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof Component)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof Component) ) { + return false; + } - Component that = (Component) o; + Component that = (Component) o; - if (prop2 != that.prop2) return false; - if (prop1 != null ? !prop1.equals(that.prop1) : that.prop1 != null) return false; + if ( prop2 != that.prop2 ) { + return false; + } + if ( prop1 != null ? !prop1.equals( that.prop1 ) : that.prop1 != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (prop1 != null ? prop1.hashCode() : 0); - result = 31 * result + prop2; - return result; - } + public int hashCode() { + int result; + result = (prop1 != null ? prop1.hashCode() : 0); + result = 31 * result + prop2; + return result; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/customtype/CompositeCustomTypeEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/customtype/CompositeCustomTypeEntity.java index d6b38feb38..37a6c73536 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/customtype/CompositeCustomTypeEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/customtype/CompositeCustomTypeEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.customtype; + import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -38,59 +39,67 @@ import org.hibernate.envers.Audited; @Entity @TypeDef(name = "comp", typeClass = CompositeTestUserType.class) public class CompositeCustomTypeEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - @Audited - @Type(type = "comp") - @Columns(columns = { @Column(name = "str"), @Column(name = "num") }) - private Component component; + @Audited + @Type(type = "comp") + @Columns(columns = {@Column(name = "str"), @Column(name = "num")}) + private Component component; - public CompositeCustomTypeEntity() { - } + public CompositeCustomTypeEntity() { + } - public CompositeCustomTypeEntity(Integer id, Component component) { - this.id = id; - this.component = component; - } + public CompositeCustomTypeEntity(Integer id, Component component) { + this.id = id; + this.component = component; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public Component getComponent() { - return component; - } + public Component getComponent() { + return component; + } - public void setComponent(Component component) { - this.component = component; - } + public void setComponent(Component component) { + this.component = component; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof CompositeCustomTypeEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof CompositeCustomTypeEntity) ) { + return false; + } - CompositeCustomTypeEntity that = (CompositeCustomTypeEntity) o; + CompositeCustomTypeEntity that = (CompositeCustomTypeEntity) o; - if (component != null ? !component.equals(that.component) : that.component != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( component != null ? !component.equals( that.component ) : that.component != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (component != null ? component.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (component != null ? component.hashCode() : 0); + return result; + } - public String toString() { - return "CCTE(id = " + id + ", component = " + component + ")"; - } + public String toString() { + return "CCTE(id = " + id + ", component = " + component + ")"; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/customtype/CompositeTestUserType.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/customtype/CompositeTestUserType.java index 1ff0db637c..410896771a 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/customtype/CompositeTestUserType.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/customtype/CompositeTestUserType.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.customtype; + import java.io.Serializable; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -39,99 +40,106 @@ import org.hibernate.usertype.CompositeUserType; * @author Adam Warski (adam at warski dot org) */ public class CompositeTestUserType implements CompositeUserType { - public String[] getPropertyNames() { - return new String[] { "prop1", "prop2" }; - } + public String[] getPropertyNames() { + return new String[] {"prop1", "prop2"}; + } - public Type[] getPropertyTypes() { - return new Type[] { StringType.INSTANCE, IntegerType.INSTANCE }; - } + public Type[] getPropertyTypes() { + return new Type[] {StringType.INSTANCE, IntegerType.INSTANCE}; + } - public Object getPropertyValue(final Object component, final int property) throws HibernateException { - Component comp = (Component) component; - if (property == 0) { - return comp.getProp1(); - } else { - return comp.getProp2(); - } - } + public Object getPropertyValue(final Object component, final int property) throws HibernateException { + Component comp = (Component) component; + if ( property == 0 ) { + return comp.getProp1(); + } + else { + return comp.getProp2(); + } + } - public void setPropertyValue(final Object component, final int property, final Object value) throws HibernateException { - Component comp = (Component) component; - if (property == 0) { - comp.setProp1((String) value); - } else { - comp.setProp2((Integer) value); - } - } + public void setPropertyValue(final Object component, final int property, final Object value) + throws HibernateException { + Component comp = (Component) component; + if ( property == 0 ) { + comp.setProp1( (String) value ); + } + else { + comp.setProp2( (Integer) value ); + } + } - public Class returnedClass() { - return Component.class; - } + public Class returnedClass() { + return Component.class; + } - public boolean equals(final Object x, final Object y) throws HibernateException { - //noinspection ObjectEquality - if (x == y) { - return true; - } + public boolean equals(final Object x, final Object y) throws HibernateException { + //noinspection ObjectEquality + if ( x == y ) { + return true; + } - if (x == null || y == null) { - return false; - } + if ( x == null || y == null ) { + return false; + } - return x.equals(y); - } + return x.equals( y ); + } - public int hashCode(final Object x) throws HibernateException { - return x.hashCode(); - } + public int hashCode(final Object x) throws HibernateException { + return x.hashCode(); + } - public Object nullSafeGet(final ResultSet rs, final String[] names, - final SessionImplementor session, - final Object owner) throws HibernateException, SQLException { - final String prop1 = rs.getString(names[0]); - if (prop1 == null) { - return null; - } - final int prop2 = rs.getInt(names[1]); - - return new Component(prop1, prop2); - } + public Object nullSafeGet( + final ResultSet rs, final String[] names, + final SessionImplementor session, + final Object owner) throws HibernateException, SQLException { + final String prop1 = rs.getString( names[0] ); + if ( prop1 == null ) { + return null; + } + final int prop2 = rs.getInt( names[1] ); - public void nullSafeSet(final PreparedStatement st, final Object value, - final int index, final SessionImplementor session) - throws HibernateException, SQLException - { - if (value == null) { - st.setNull(index, StringType.INSTANCE.sqlType()); - st.setNull(index + 1, IntegerType.INSTANCE.sqlType()); - } else { - final Component comp = (Component) value; - st.setString(index, comp.getProp1()); - st.setInt(index + 1, comp.getProp2()); - } - } + return new Component( prop1, prop2 ); + } - public Object deepCopy(final Object value) throws HibernateException { - Component comp = (Component) value; - return new Component(comp.getProp1(), comp.getProp2()); - } + public void nullSafeSet( + final PreparedStatement st, final Object value, + final int index, final SessionImplementor session) + throws HibernateException, SQLException { + if ( value == null ) { + st.setNull( index, StringType.INSTANCE.sqlType() ); + st.setNull( index + 1, IntegerType.INSTANCE.sqlType() ); + } + else { + final Component comp = (Component) value; + st.setString( index, comp.getProp1() ); + st.setInt( index + 1, comp.getProp2() ); + } + } - public boolean isMutable() { - return true; - } + public Object deepCopy(final Object value) throws HibernateException { + Component comp = (Component) value; + return new Component( comp.getProp1(), comp.getProp2() ); + } - public Serializable disassemble(final Object value, final SessionImplementor session) throws HibernateException { - return (Serializable) value; - } + public boolean isMutable() { + return true; + } - public Object assemble(final Serializable cached, final SessionImplementor session, - final Object owner) throws HibernateException { - return cached; - } + public Serializable disassemble(final Object value, final SessionImplementor session) throws HibernateException { + return (Serializable) value; + } - public Object replace(Object original, Object target, - SessionImplementor session, Object owner) throws HibernateException { - return original; - } + public Object assemble( + final Serializable cached, final SessionImplementor session, + final Object owner) throws HibernateException { + return cached; + } + + public Object replace( + Object original, Object target, + SessionImplementor session, Object owner) throws HibernateException { + return original; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/customtype/EnumTypeEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/customtype/EnumTypeEntity.java index 570a34cf85..c84c95e6b3 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/customtype/EnumTypeEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/customtype/EnumTypeEntity.java @@ -14,8 +14,9 @@ import org.hibernate.envers.Audited; @Entity @Audited public class EnumTypeEntity { - public static enum E1 { X, Y } - public static enum E2 { A, B } + public static enum E1 {X, Y} + + public static enum E2 {A, B} @Id @GeneratedValue @@ -43,14 +44,24 @@ public class EnumTypeEntity { @Override public boolean equals(Object o) { - if ( this == o ) return true; - if ( ! ( o instanceof EnumTypeEntity ) ) return false; + if ( this == o ) { + return true; + } + if ( !(o instanceof EnumTypeEntity) ) { + return false; + } EnumTypeEntity that = (EnumTypeEntity) o; - if ( enum1 != that.enum1 ) return false; - if ( enum2 != that.enum2 ) return false; - if ( id != null ? !id.equals( that.id ) : that.id != null ) return false; + if ( enum1 != that.enum1 ) { + return false; + } + if ( enum2 != that.enum2 ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } return true; } @@ -58,8 +69,8 @@ public class EnumTypeEntity { @Override public int hashCode() { int result = id != null ? id.hashCode() : 0; - result = 31 * result + ( enum1 != null ? enum1.hashCode() : 0 ); - result = 31 * result + ( enum2 != null ? enum2.hashCode() : 0 ); + result = 31 * result + (enum1 != null ? enum1.hashCode() : 0); + result = 31 * result + (enum2 != null ? enum2.hashCode() : 0); return result; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/customtype/ParametrizedCustomTypeEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/customtype/ParametrizedCustomTypeEntity.java index 3aa9579dcf..a0620ab1d7 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/customtype/ParametrizedCustomTypeEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/customtype/ParametrizedCustomTypeEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.customtype; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; @@ -37,61 +38,69 @@ import org.hibernate.envers.Audited; */ @Entity @TypeDef(name = "param", typeClass = ParametrizedTestUserType.class, - parameters = { @Parameter(name="param1", value = "x"), @Parameter(name="param2", value = "y") }) + parameters = {@Parameter(name = "param1", value = "x"), @Parameter(name = "param2", value = "y")}) @Table(name = "ParamCustType") public class ParametrizedCustomTypeEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - @Audited - @Type(type = "param") - private String str; + @Audited + @Type(type = "param") + private String str; - public ParametrizedCustomTypeEntity() { - } + public ParametrizedCustomTypeEntity() { + } - public ParametrizedCustomTypeEntity(Integer id, String str) { - this.id = id; - this.str = str; - } + public ParametrizedCustomTypeEntity(Integer id, String str) { + this.id = id; + this.str = str; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getStr() { - return str; - } + public String getStr() { + return str; + } - public void setStr(String str) { - this.str = str; - } + public void setStr(String str) { + this.str = str; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ParametrizedCustomTypeEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ParametrizedCustomTypeEntity) ) { + return false; + } - ParametrizedCustomTypeEntity that = (ParametrizedCustomTypeEntity) o; + ParametrizedCustomTypeEntity that = (ParametrizedCustomTypeEntity) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; - if (str != null ? !str.equals(that.str) : that.str != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } + if ( str != null ? !str.equals( that.str ) : that.str != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (str != null ? str.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (str != null ? str.hashCode() : 0); + return result; + } - public String toString() { - return "PCTE(id = " + id + ", str = " + str + ")"; - } + public String toString() { + return "PCTE(id = " + id + ", str = " + str + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/customtype/ParametrizedTestUserType.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/customtype/ParametrizedTestUserType.java index 04d108b262..89999fa8d3 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/customtype/ParametrizedTestUserType.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/customtype/ParametrizedTestUserType.java @@ -40,78 +40,80 @@ import org.hibernate.usertype.UserType; * @author Adam Warski (adam at warski dot org) */ public class ParametrizedTestUserType implements UserType, ParameterizedType { - private static final int[] TYPES = new int[] { Types.VARCHAR }; + private static final int[] TYPES = new int[] {Types.VARCHAR}; - private String param1; - private String param2; + private String param1; + private String param2; - public void setParameterValues(Properties parameters) { - param1 = parameters.getProperty("param1"); - param2 = parameters.getProperty("param2"); - } + public void setParameterValues(Properties parameters) { + param1 = parameters.getProperty( "param1" ); + param2 = parameters.getProperty( "param2" ); + } - public Class returnedClass() { - return String.class; - } + public Class returnedClass() { + return String.class; + } - public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException { - return StringType.INSTANCE.nullSafeGet( rs, names[0], session ); - } + public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) + throws HibernateException, SQLException { + return StringType.INSTANCE.nullSafeGet( rs, names[0], session ); + } - public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException { - if (value != null) { - String v = (String) value; - if (!v.startsWith(param1)) { - v = param1 + v; - } - if (!v.endsWith(param2)) { - v = v + param2; - } - StringType.INSTANCE.nullSafeSet(st, v, index, session); - } + public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) + throws HibernateException, SQLException { + if ( value != null ) { + String v = (String) value; + if ( !v.startsWith( param1 ) ) { + v = param1 + v; + } + if ( !v.endsWith( param2 ) ) { + v = v + param2; + } + StringType.INSTANCE.nullSafeSet( st, v, index, session ); + } else { - StringType.INSTANCE.nullSafeSet( st, null, index, session ); - } - } + StringType.INSTANCE.nullSafeSet( st, null, index, session ); + } + } - public int[] sqlTypes() { - return TYPES; - } + public int[] sqlTypes() { + return TYPES; + } - public Object assemble(Serializable cached, Object owner) throws HibernateException { - return cached; - } + public Object assemble(Serializable cached, Object owner) throws HibernateException { + return cached; + } - public Object deepCopy(Object value) throws HibernateException { - return value; - } + public Object deepCopy(Object value) throws HibernateException { + return value; + } - public Serializable disassemble(Object value) throws HibernateException { - return (Serializable) value; - } + public Serializable disassemble(Object value) throws HibernateException { + return (Serializable) value; + } - public boolean equals(Object x, Object y) throws HibernateException { - //noinspection ObjectEquality - if (x == y) { - return true; - } + public boolean equals(Object x, Object y) throws HibernateException { + //noinspection ObjectEquality + if ( x == y ) { + return true; + } - if (x == null || y == null) { - return false; - } + if ( x == null || y == null ) { + return false; + } - return x.equals(y); - } + return x.equals( y ); + } - public int hashCode(Object x) throws HibernateException { - return x.hashCode(); - } + public int hashCode(Object x) throws HibernateException { + return x.hashCode(); + } - public boolean isMutable() { - return false; - } + public boolean isMutable() { + return false; + } - public Object replace(Object original, Object target, Object owner) throws HibernateException { - return original; - } + public Object replace(Object original, Object target, Object owner) throws HibernateException { + return original; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/customtype/UnspecifiedEnumTypeEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/customtype/UnspecifiedEnumTypeEntity.java index c0e8c95a52..04fcc5b818 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/customtype/UnspecifiedEnumTypeEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/customtype/UnspecifiedEnumTypeEntity.java @@ -9,8 +9,9 @@ import org.hibernate.envers.Audited; */ @Audited public class UnspecifiedEnumTypeEntity implements Serializable { - public static enum E1 { X, Y } - public static enum E2 { A, B } + public static enum E1 {X, Y} + + public static enum E2 {A, B} private Long id; @@ -34,14 +35,24 @@ public class UnspecifiedEnumTypeEntity implements Serializable { @Override public boolean equals(Object o) { - if ( this == o ) return true; - if ( ! ( o instanceof UnspecifiedEnumTypeEntity ) ) return false; + if ( this == o ) { + return true; + } + if ( !(o instanceof UnspecifiedEnumTypeEntity) ) { + return false; + } UnspecifiedEnumTypeEntity that = (UnspecifiedEnumTypeEntity) o; - if ( enum1 != that.enum1 ) return false; - if ( enum2 != that.enum2 ) return false; - if ( id != null ? !id.equals( that.id ) : that.id != null ) return false; + if ( enum1 != that.enum1 ) { + return false; + } + if ( enum2 != that.enum2 ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } return true; } @@ -49,8 +60,8 @@ public class UnspecifiedEnumTypeEntity implements Serializable { @Override public int hashCode() { int result = id != null ? id.hashCode() : 0; - result = 31 * result + ( enum1 != null ? enum1.hashCode() : 0 ); - result = 31 * result + ( enum2 != null ? enum2.hashCode() : 0 ); + result = 31 * result + (enum1 != null ? enum1.hashCode() : 0); + result = 31 * result + (enum2 != null ? enum2.hashCode() : 0); return result; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/CompositeDateIdTestEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/CompositeDateIdTestEntity.java index 06d3f0a0ad..7e111edaf2 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/CompositeDateIdTestEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/CompositeDateIdTestEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.ids; + import javax.persistence.EmbeddedId; import javax.persistence.Entity; @@ -32,57 +33,65 @@ import org.hibernate.envers.Audited; */ @Entity public class CompositeDateIdTestEntity { - @EmbeddedId - private DateEmbId id; + @EmbeddedId + private DateEmbId id; - @Audited - private String str1; + @Audited + private String str1; - public CompositeDateIdTestEntity() { - } + public CompositeDateIdTestEntity() { + } - public CompositeDateIdTestEntity(String str1) { - this.str1 = str1; - } + public CompositeDateIdTestEntity(String str1) { + this.str1 = str1; + } - public CompositeDateIdTestEntity(DateEmbId id, String str1) { - this.id = id; - this.str1 = str1; - } + public CompositeDateIdTestEntity(DateEmbId id, String str1) { + this.id = id; + this.str1 = str1; + } - public DateEmbId getId() { - return id; - } + public DateEmbId getId() { + return id; + } - public void setId(DateEmbId id) { - this.id = id; - } + public void setId(DateEmbId id) { + this.id = id; + } - public String getStr1() { - return str1; - } + public String getStr1() { + return str1; + } - public void setStr1(String str1) { - this.str1 = str1; - } + public void setStr1(String str1) { + this.str1 = str1; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } - CompositeDateIdTestEntity that = (CompositeDateIdTestEntity) o; + CompositeDateIdTestEntity that = (CompositeDateIdTestEntity) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; - if (str1 != null ? !str1.equals(that.str1) : that.str1 != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } + if ( str1 != null ? !str1.equals( that.str1 ) : that.str1 != null ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - int result = id != null ? id.hashCode() : 0; - result = 31 * result + (str1 != null ? str1.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = id != null ? id.hashCode() : 0; + result = 31 * result + (str1 != null ? str1.hashCode() : 0); + return result; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/CustomEnum.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/CustomEnum.java index 68e7107353..3616ea079c 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/CustomEnum.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/CustomEnum.java @@ -28,14 +28,14 @@ package org.hibernate.envers.test.entities.ids; * @author Slawek Garwol (slawekgarwol at gmail dot com) */ public enum CustomEnum { - YES, - NO; + YES, + NO; - public String toYesNo() { - return this == YES ? "Y" : "N"; - } + public String toYesNo() { + return this == YES ? "Y" : "N"; + } - public static CustomEnum fromYesNo(String value) { - return "Y".equals(value) ? YES : NO; - } + public static CustomEnum fromYesNo(String value) { + return "Y".equals( value ) ? YES : NO; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/CustomEnumUserType.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/CustomEnumUserType.java index 22713d59a3..359683ea99 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/CustomEnumUserType.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/CustomEnumUserType.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.ids; + import java.io.Serializable; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -36,64 +37,67 @@ import org.hibernate.usertype.UserType; * @author Slawek Garwol (slawekgarwol at gmail dot com) */ public class CustomEnumUserType implements UserType { - private static final int[] SQL_TYPES = {Types.VARCHAR}; + private static final int[] SQL_TYPES = {Types.VARCHAR}; - public int[] sqlTypes() { - return SQL_TYPES; - } + public int[] sqlTypes() { + return SQL_TYPES; + } - public Class returnedClass() { - return CustomEnum.class; - } + public Class returnedClass() { + return CustomEnum.class; + } - public boolean equals(Object x, Object y) throws HibernateException { - if (x == y) { - return true; - } - if ((x == null) || (y == null)) { - return false; - } - return x.equals(y); - } + public boolean equals(Object x, Object y) throws HibernateException { + if ( x == y ) { + return true; + } + if ( (x == null) || (y == null) ) { + return false; + } + return x.equals( y ); + } - public int hashCode(Object x) throws HibernateException { - return (x == null) ? 0 : x.hashCode(); - } + public int hashCode(Object x) throws HibernateException { + return (x == null) ? 0 : x.hashCode(); + } - public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException { - String name = rs.getString(names[0]); - if (rs.wasNull()) { - return null; - } - return CustomEnum.fromYesNo(name); - } + public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) + throws HibernateException, SQLException { + String name = rs.getString( names[0] ); + if ( rs.wasNull() ) { + return null; + } + return CustomEnum.fromYesNo( name ); + } - public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException { - CustomEnum val = (CustomEnum) value; - if (val == null) { - st.setNull(index, Types.VARCHAR); - } else { - st.setString(index, val.toYesNo()); - } - } + public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) + throws HibernateException, SQLException { + CustomEnum val = (CustomEnum) value; + if ( val == null ) { + st.setNull( index, Types.VARCHAR ); + } + else { + st.setString( index, val.toYesNo() ); + } + } - public Object deepCopy(Object value) throws HibernateException { - return value; - } + public Object deepCopy(Object value) throws HibernateException { + return value; + } - public boolean isMutable() { - return false; - } + public boolean isMutable() { + return false; + } - public Serializable disassemble(Object value) throws HibernateException { - return (Serializable) value; - } + public Serializable disassemble(Object value) throws HibernateException { + return (Serializable) value; + } - public Object assemble(Serializable cached, Object owner) throws HibernateException { - return cached; - } + public Object assemble(Serializable cached, Object owner) throws HibernateException { + return cached; + } - public Object replace(Object original, Object target, Object owner) throws HibernateException { - return original; - } + public Object replace(Object original, Object target, Object owner) throws HibernateException { + return original; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/DateEmbId.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/DateEmbId.java index 9cbf78aa56..8c47f5420b 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/DateEmbId.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/DateEmbId.java @@ -22,62 +22,71 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.ids; + +import javax.persistence.Embeddable; import java.io.Serializable; import java.util.Date; -import javax.persistence.Embeddable; /** * @author Adam Warski (adam at warski dot org) */ @Embeddable public class DateEmbId implements Serializable { - private Date x; - private Date y; + private Date x; + private Date y; - public DateEmbId() { - } + public DateEmbId() { + } - public DateEmbId(Date x, Date y) { - this.x = x; - this.y = y; - } + public DateEmbId(Date x, Date y) { + this.x = x; + this.y = y; + } - public Date getX() { - return x; - } + public Date getX() { + return x; + } - public void setX(Date x) { - this.x = x; - } + public void setX(Date x) { + this.x = x; + } - public Date getY() { - return y; - } + public Date getY() { + return y; + } - public void setY(Date y) { - this.y = y; - } + public void setY(Date y) { + this.y = y; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof DateEmbId)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof DateEmbId) ) { + return false; + } - DateEmbId embId = (DateEmbId) o; + DateEmbId embId = (DateEmbId) o; - if (x != null ? !x.equals(embId.x) : embId.x != null) return false; - if (y != null ? !y.equals(embId.y) : embId.y != null) return false; + if ( x != null ? !x.equals( embId.x ) : embId.x != null ) { + return false; + } + if ( y != null ? !y.equals( embId.y ) : embId.y != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (x != null ? x.hashCode() : 0); - result = 31 * result + (y != null ? y.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (x != null ? x.hashCode() : 0); + result = 31 * result + (y != null ? y.hashCode() : 0); + return result; + } - public String toString() { - return "DateEmbId(" + x + ", " + y + ")"; - } + public String toString() { + return "DateEmbId(" + x + ", " + y + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/DateIdTestEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/DateIdTestEntity.java index 5796d15957..db7e5ec4c8 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/DateIdTestEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/DateIdTestEntity.java @@ -22,9 +22,10 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.ids; -import java.util.Date; + import javax.persistence.Entity; import javax.persistence.Id; +import java.util.Date; import org.hibernate.envers.Audited; @@ -33,57 +34,65 @@ import org.hibernate.envers.Audited; */ @Entity public class DateIdTestEntity { - @Id - private Date id; + @Id + private Date id; - @Audited - private String str1; + @Audited + private String str1; - public DateIdTestEntity() { - } + public DateIdTestEntity() { + } - public DateIdTestEntity(String str1) { - this.str1 = str1; - } + public DateIdTestEntity(String str1) { + this.str1 = str1; + } - public DateIdTestEntity(Date id, String str1) { - this.id = id; - this.str1 = str1; - } + public DateIdTestEntity(Date id, String str1) { + this.id = id; + this.str1 = str1; + } - public Date getId() { - return id; - } + public Date getId() { + return id; + } - public void setId(Date id) { - this.id = id; - } + public void setId(Date id) { + this.id = id; + } - public String getStr1() { - return str1; - } + public String getStr1() { + return str1; + } - public void setStr1(String str1) { - this.str1 = str1; - } + public void setStr1(String str1) { + this.str1 = str1; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } - DateIdTestEntity that = (DateIdTestEntity) o; + DateIdTestEntity that = (DateIdTestEntity) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; - if (str1 != null ? !str1.equals(that.str1) : that.str1 != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } + if ( str1 != null ? !str1.equals( that.str1 ) : that.str1 != null ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - int result = id != null ? id.hashCode() : 0; - result = 31 * result + (str1 != null ? str1.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = id != null ? id.hashCode() : 0; + result = 31 * result + (str1 != null ? str1.hashCode() : 0); + return result; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/EmbId.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/EmbId.java index 86d6c8b04a..bec79425ed 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/EmbId.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/EmbId.java @@ -22,61 +22,70 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.ids; -import java.io.Serializable; + import javax.persistence.Embeddable; +import java.io.Serializable; /** * @author Adam Warski (adam at warski dot org) */ @Embeddable public class EmbId implements Serializable { - private Integer x; - private Integer y; + private Integer x; + private Integer y; - public EmbId() { - } + public EmbId() { + } - public EmbId(Integer x, Integer y) { - this.x = x; - this.y = y; - } + public EmbId(Integer x, Integer y) { + this.x = x; + this.y = y; + } - public Integer getX() { - return x; - } + public Integer getX() { + return x; + } - public void setX(Integer x) { - this.x = x; - } + public void setX(Integer x) { + this.x = x; + } - public Integer getY() { - return y; - } + public Integer getY() { + return y; + } - public void setY(Integer y) { - this.y = y; - } + public void setY(Integer y) { + this.y = y; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof EmbId)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof EmbId) ) { + return false; + } - EmbId embId = (EmbId) o; + EmbId embId = (EmbId) o; - if (x != null ? !x.equals(embId.x) : embId.x != null) return false; - if (y != null ? !y.equals(embId.y) : embId.y != null) return false; + if ( x != null ? !x.equals( embId.x ) : embId.x != null ) { + return false; + } + if ( y != null ? !y.equals( embId.y ) : embId.y != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (x != null ? x.hashCode() : 0); - result = 31 * result + (y != null ? y.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (x != null ? x.hashCode() : 0); + result = 31 * result + (y != null ? y.hashCode() : 0); + return result; + } - public String toString() { - return "EmbId(" + x + ", " + y + ")"; - } + public String toString() { + return "EmbId(" + x + ", " + y + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/EmbIdTestEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/EmbIdTestEntity.java index 695bcbdfb4..9632429a3a 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/EmbIdTestEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/EmbIdTestEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.ids; + import javax.persistence.EmbeddedId; import javax.persistence.Entity; import javax.persistence.Table; @@ -34,56 +35,64 @@ import org.hibernate.envers.Audited; @Entity @Table(name = "EmbIdEnt") public class EmbIdTestEntity { - @EmbeddedId - private EmbId id; + @EmbeddedId + private EmbId id; - @Audited - private String str1; + @Audited + private String str1; - public EmbIdTestEntity() { - } + public EmbIdTestEntity() { + } - public EmbIdTestEntity(String str1) { - this.str1 = str1; - } + public EmbIdTestEntity(String str1) { + this.str1 = str1; + } - public EmbIdTestEntity(EmbId id, String str1) { - this.id = id; - this.str1 = str1; - } + public EmbIdTestEntity(EmbId id, String str1) { + this.id = id; + this.str1 = str1; + } - public EmbId getId() { - return id; - } + public EmbId getId() { + return id; + } - public void setId(EmbId id) { - this.id = id; - } + public void setId(EmbId id) { + this.id = id; + } - public String getStr1() { - return str1; - } + public String getStr1() { + return str1; + } - public void setStr1(String str1) { - this.str1 = str1; - } + public void setStr1(String str1) { + this.str1 = str1; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof EmbIdTestEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof EmbIdTestEntity) ) { + return false; + } - EmbIdTestEntity that = (EmbIdTestEntity) o; + EmbIdTestEntity that = (EmbIdTestEntity) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; - if (str1 != null ? !str1.equals(that.str1) : that.str1 != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } + if ( str1 != null ? !str1.equals( that.str1 ) : that.str1 != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (str1 != null ? str1.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (str1 != null ? str1.hashCode() : 0); + return result; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/EmbIdWithCustomType.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/EmbIdWithCustomType.java index d815d1ce98..03efc0cdec 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/EmbIdWithCustomType.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/EmbIdWithCustomType.java @@ -22,8 +22,9 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.ids; -import java.io.Serializable; + import javax.persistence.Embeddable; +import java.io.Serializable; import org.hibernate.annotations.Type; import org.hibernate.annotations.TypeDef; @@ -34,53 +35,61 @@ import org.hibernate.annotations.TypeDef; @Embeddable @TypeDef(name = "customEnum", typeClass = CustomEnumUserType.class) public class EmbIdWithCustomType implements Serializable { - private Integer x; + private Integer x; - @Type(type = "customEnum") - private CustomEnum customEnum; + @Type(type = "customEnum") + private CustomEnum customEnum; - public EmbIdWithCustomType() { - } + public EmbIdWithCustomType() { + } - public EmbIdWithCustomType(Integer x, CustomEnum customEnum) { - this.x = x; - this.customEnum = customEnum; - } + public EmbIdWithCustomType(Integer x, CustomEnum customEnum) { + this.x = x; + this.customEnum = customEnum; + } - public Integer getX() { - return x; - } + public Integer getX() { + return x; + } - public void setX(Integer x) { - this.x = x; - } + public void setX(Integer x) { + this.x = x; + } - public CustomEnum getCustomEnum() { - return customEnum; - } + public CustomEnum getCustomEnum() { + return customEnum; + } - public void setCustomEnum(CustomEnum customEnum) { - this.customEnum = customEnum; - } + public void setCustomEnum(CustomEnum customEnum) { + this.customEnum = customEnum; + } - @Override - public boolean equals(Object obj) { - if (this == obj) return true; - if (!(obj instanceof EmbIdWithCustomType)) return false; + @Override + public boolean equals(Object obj) { + if ( this == obj ) { + return true; + } + if ( !(obj instanceof EmbIdWithCustomType) ) { + return false; + } - EmbIdWithCustomType that = (EmbIdWithCustomType) obj; + EmbIdWithCustomType that = (EmbIdWithCustomType) obj; - if (x != null ? !x.equals(that.x) : that.x != null) return false; - if (customEnum != that.customEnum) return false; + if ( x != null ? !x.equals( that.x ) : that.x != null ) { + return false; + } + if ( customEnum != that.customEnum ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - int result; - result = (x != null ? x.hashCode() : 0); - result = 31 * result + (customEnum != null ? customEnum.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result; + result = (x != null ? x.hashCode() : 0); + result = 31 * result + (customEnum != null ? customEnum.hashCode() : 0); + return result; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/EmbIdWithCustomTypeTestEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/EmbIdWithCustomTypeTestEntity.java index 3d95df4448..54c7dda35b 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/EmbIdWithCustomTypeTestEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/EmbIdWithCustomTypeTestEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.ids; + import javax.persistence.EmbeddedId; import javax.persistence.Entity; import javax.persistence.Table; @@ -34,51 +35,59 @@ import org.hibernate.envers.Audited; @Entity @Table(name = "EmbIdWithCustType") public class EmbIdWithCustomTypeTestEntity { - @EmbeddedId - private EmbIdWithCustomType id; + @EmbeddedId + private EmbIdWithCustomType id; - @Audited - private String str1; + @Audited + private String str1; - public EmbIdWithCustomTypeTestEntity() { - } + public EmbIdWithCustomTypeTestEntity() { + } - public EmbIdWithCustomTypeTestEntity(EmbIdWithCustomType id, String str1) { - this.id = id; - this.str1 = str1; - } + public EmbIdWithCustomTypeTestEntity(EmbIdWithCustomType id, String str1) { + this.id = id; + this.str1 = str1; + } - public EmbIdWithCustomType getId() { - return id; - } + public EmbIdWithCustomType getId() { + return id; + } - public void setId(EmbIdWithCustomType id) { - this.id = id; - } + public void setId(EmbIdWithCustomType id) { + this.id = id; + } - public String getStr1() { - return str1; - } + public String getStr1() { + return str1; + } - public void setStr1(String str1) { - this.str1 = str1; - } + public void setStr1(String str1) { + this.str1 = str1; + } - public boolean equals(Object obj) { - if (this == obj) return true; - if (!(obj instanceof EmbIdWithCustomTypeTestEntity)) return false; + public boolean equals(Object obj) { + if ( this == obj ) { + return true; + } + if ( !(obj instanceof EmbIdWithCustomTypeTestEntity) ) { + return false; + } - EmbIdWithCustomTypeTestEntity that = (EmbIdWithCustomTypeTestEntity) obj; - if (id != null ? !id.equals(that.id) : that.id != null) return false; - if (str1 != null ? !str1.equals(that.str1) : that.str1 != null) return false; + EmbIdWithCustomTypeTestEntity that = (EmbIdWithCustomTypeTestEntity) obj; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } + if ( str1 != null ? !str1.equals( that.str1 ) : that.str1 != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (str1 != null ? str1.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (str1 != null ? str1.hashCode() : 0); + return result; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/ManyToOneIdNotAuditedTestEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/ManyToOneIdNotAuditedTestEntity.java index 5749ec3860..3be38b2150 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/ManyToOneIdNotAuditedTestEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/ManyToOneIdNotAuditedTestEntity.java @@ -1,8 +1,9 @@ package org.hibernate.envers.test.entities.ids; -import java.io.Serializable; + import javax.persistence.EmbeddedId; import javax.persistence.Entity; import javax.persistence.Table; +import java.io.Serializable; /** * @author Adam Warski (adam at warski dot org) @@ -10,47 +11,55 @@ import javax.persistence.Table; @Entity @Table(name = "ManyToOneIdNotAud") public class ManyToOneIdNotAuditedTestEntity implements Serializable { - @EmbeddedId - private ManyToOneNotAuditedEmbId id; + @EmbeddedId + private ManyToOneNotAuditedEmbId id; - private String data; + private String data; - public ManyToOneIdNotAuditedTestEntity() { - } + public ManyToOneIdNotAuditedTestEntity() { + } - public ManyToOneNotAuditedEmbId getId() { - return id; - } + public ManyToOneNotAuditedEmbId getId() { + return id; + } - public void setId(ManyToOneNotAuditedEmbId id) { - this.id = id; - } + public void setId(ManyToOneNotAuditedEmbId id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } - ManyToOneIdNotAuditedTestEntity that = (ManyToOneIdNotAuditedTestEntity) o; + ManyToOneIdNotAuditedTestEntity that = (ManyToOneIdNotAuditedTestEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - int result = id != null ? id.hashCode() : 0; - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = id != null ? id.hashCode() : 0; + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/ManyToOneNotAuditedEmbId.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/ManyToOneNotAuditedEmbId.java index 68e2581740..0786b40490 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/ManyToOneNotAuditedEmbId.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/ManyToOneNotAuditedEmbId.java @@ -1,7 +1,8 @@ package org.hibernate.envers.test.entities.ids; -import java.io.Serializable; + import javax.persistence.Embeddable; import javax.persistence.ManyToOne; +import java.io.Serializable; import org.hibernate.envers.test.entities.UnversionedStrTestEntity; @@ -10,38 +11,44 @@ import org.hibernate.envers.test.entities.UnversionedStrTestEntity; */ @Embeddable public class ManyToOneNotAuditedEmbId implements Serializable { - @ManyToOne(optional = false) - private UnversionedStrTestEntity id; + @ManyToOne(optional = false) + private UnversionedStrTestEntity id; - public ManyToOneNotAuditedEmbId() { - } + public ManyToOneNotAuditedEmbId() { + } - public ManyToOneNotAuditedEmbId(UnversionedStrTestEntity id) { - this.id = id; - } + public ManyToOneNotAuditedEmbId(UnversionedStrTestEntity id) { + this.id = id; + } - public UnversionedStrTestEntity getId() { - return id; - } + public UnversionedStrTestEntity getId() { + return id; + } - public void setId(UnversionedStrTestEntity id) { - this.id = id; - } + public void setId(UnversionedStrTestEntity id) { + this.id = id; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } - ManyToOneNotAuditedEmbId that = (ManyToOneNotAuditedEmbId) o; + ManyToOneNotAuditedEmbId that = (ManyToOneNotAuditedEmbId) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - return id != null ? id.hashCode() : 0; - } + @Override + public int hashCode() { + return id != null ? id.hashCode() : 0; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/MulId.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/MulId.java index 18973e11a0..07a9c3a398 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/MulId.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/MulId.java @@ -22,60 +22,69 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.ids; + import java.io.Serializable; /** * @author Adam Warski (adam at warski dot org) */ public class MulId implements Serializable { - private Integer id1; + private Integer id1; - private Integer id2; + private Integer id2; - public MulId() { - } + public MulId() { + } - public MulId(Integer id1, Integer id2) { - this.id1 = id1; - this.id2 = id2; - } + public MulId(Integer id1, Integer id2) { + this.id1 = id1; + this.id2 = id2; + } - public Integer getId1() { - return id1; - } + public Integer getId1() { + return id1; + } - public void setId1(Integer id1) { - this.id1 = id1; - } + public void setId1(Integer id1) { + this.id1 = id1; + } - public Integer getId2() { - return id2; - } + public Integer getId2() { + return id2; + } - public void setId2(Integer id2) { - this.id2 = id2; - } + public void setId2(Integer id2) { + this.id2 = id2; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof MulId)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof MulId) ) { + return false; + } - MulId mulId = (MulId) o; + MulId mulId = (MulId) o; - if (id1 != null ? !id1.equals(mulId.id1) : mulId.id1 != null) return false; - if (id2 != null ? !id2.equals(mulId.id2) : mulId.id2 != null) return false; + if ( id1 != null ? !id1.equals( mulId.id1 ) : mulId.id1 != null ) { + return false; + } + if ( id2 != null ? !id2.equals( mulId.id2 ) : mulId.id2 != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id1 != null ? id1.hashCode() : 0); - result = 31 * result + (id2 != null ? id2.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id1 != null ? id1.hashCode() : 0); + result = 31 * result + (id2 != null ? id2.hashCode() : 0); + return result; + } - public String toString() { - return "MulId(" + id1 + ", " + id2 + ")"; - } + public String toString() { + return "MulId(" + id1 + ", " + id2 + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/MulIdTestEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/MulIdTestEntity.java index 13ff15114e..dafd2174fb 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/MulIdTestEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/MulIdTestEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.ids; + import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.IdClass; @@ -36,70 +37,80 @@ import org.hibernate.envers.Audited; @Table(name = "MulId") @IdClass(MulId.class) public class MulIdTestEntity { - @Id - private Integer id1; + @Id + private Integer id1; - @Id - private Integer id2; + @Id + private Integer id2; - @Audited - private String str1; + @Audited + private String str1; - public MulIdTestEntity() { - } + public MulIdTestEntity() { + } - public MulIdTestEntity(String str1) { - this.str1 = str1; - } + public MulIdTestEntity(String str1) { + this.str1 = str1; + } - public MulIdTestEntity(Integer id1, Integer id2, String str1) { - this.id1 = id1; - this.id2 = id2; - this.str1 = str1; - } + public MulIdTestEntity(Integer id1, Integer id2, String str1) { + this.id1 = id1; + this.id2 = id2; + this.str1 = str1; + } - public Integer getId1() { - return id1; - } + public Integer getId1() { + return id1; + } - public void setId1(Integer id1) { - this.id1 = id1; - } + public void setId1(Integer id1) { + this.id1 = id1; + } - public Integer getId2() { - return id2; - } + public Integer getId2() { + return id2; + } - public void setId2(Integer id2) { - this.id2 = id2; - } + public void setId2(Integer id2) { + this.id2 = id2; + } - public String getStr1() { - return str1; - } + public String getStr1() { + return str1; + } - public void setStr1(String str1) { - this.str1 = str1; - } + public void setStr1(String str1) { + this.str1 = str1; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof MulIdTestEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof MulIdTestEntity) ) { + return false; + } - MulIdTestEntity that = (MulIdTestEntity) o; + MulIdTestEntity that = (MulIdTestEntity) o; - if (id1 != null ? !id1.equals(that.id1) : that.id1 != null) return false; - if (id2 != null ? !id2.equals(that.id2) : that.id2 != null) return false; - if (str1 != null ? !str1.equals(that.str1) : that.str1 != null) return false; + if ( id1 != null ? !id1.equals( that.id1 ) : that.id1 != null ) { + return false; + } + if ( id2 != null ? !id2.equals( that.id2 ) : that.id2 != null ) { + return false; + } + if ( str1 != null ? !str1.equals( that.str1 ) : that.str1 != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id1 != null ? id1.hashCode() : 0); - result = 31 * result + (id2 != null ? id2.hashCode() : 0); - result = 31 * result + (str1 != null ? str1.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id1 != null ? id1.hashCode() : 0); + result = 31 * result + (id2 != null ? id2.hashCode() : 0); + result = 31 * result + (str1 != null ? str1.hashCode() : 0); + return result; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/UnusualIdNamingEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/UnusualIdNamingEntity.java index 98f72c4024..fea52af286 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/UnusualIdNamingEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/ids/UnusualIdNamingEntity.java @@ -1,8 +1,8 @@ package org.hibernate.envers.test.entities.ids; -import java.io.Serializable; import javax.persistence.Entity; import javax.persistence.Id; +import java.io.Serializable; import org.hibernate.envers.Audited; @@ -27,13 +27,21 @@ public class UnusualIdNamingEntity implements Serializable { @Override public boolean equals(Object o) { - if ( this == o ) return true; - if ( !( o instanceof UnusualIdNamingEntity) ) return false; + if ( this == o ) { + return true; + } + if ( !(o instanceof UnusualIdNamingEntity) ) { + return false; + } UnusualIdNamingEntity that = (UnusualIdNamingEntity) o; - if ( uniqueField != null ? !uniqueField.equals( that.uniqueField ) : that.uniqueField != null ) return false; - if ( variousData != null ? !variousData.equals( that.variousData ) : that.variousData != null ) return false; + if ( uniqueField != null ? !uniqueField.equals( that.uniqueField ) : that.uniqueField != null ) { + return false; + } + if ( variousData != null ? !variousData.equals( that.variousData ) : that.variousData != null ) { + return false; + } return true; } @@ -41,7 +49,7 @@ public class UnusualIdNamingEntity implements Serializable { @Override public int hashCode() { int result = uniqueField != null ? uniqueField.hashCode() : 0; - result = 31 * result + ( variousData != null ? variousData.hashCode() : 0 ); + result = 31 * result + (variousData != null ? variousData.hashCode() : 0); return result; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/ListOwnedEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/ListOwnedEntity.java index 16fe4b88e7..5550512808 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/ListOwnedEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/ListOwnedEntity.java @@ -22,87 +22,97 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.manytomany; -import java.util.List; + import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.ManyToMany; import javax.persistence.Table; +import java.util.List; import org.hibernate.envers.Audited; /** * Many-to-many not-owning entity + * * @author Adam Warski (adam at warski dot org) */ @Entity @Table(name = "ListOwned") public class ListOwnedEntity { - @Id - private Integer id; + @Id + private Integer id; - @Audited - private String data; + @Audited + private String data; - @Audited - @ManyToMany(mappedBy="references") - private List referencing; + @Audited + @ManyToMany(mappedBy = "references") + private List referencing; - public ListOwnedEntity() { - } + public ListOwnedEntity() { + } - public ListOwnedEntity(Integer id, String data) { - this.id = id; - this.data = data; - } + public ListOwnedEntity(Integer id, String data) { + this.id = id; + this.data = data; + } - public ListOwnedEntity(String data) { - this.data = data; - } + public ListOwnedEntity(String data) { + this.data = data; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public List getReferencing() { - return referencing; - } + public List getReferencing() { + return referencing; + } - public void setReferencing(List referencing) { - this.referencing = referencing; - } + public void setReferencing(List referencing) { + this.referencing = referencing; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ListOwnedEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ListOwnedEntity) ) { + return false; + } - ListOwnedEntity that = (ListOwnedEntity) o; + ListOwnedEntity that = (ListOwnedEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "SetOwnedEntity(id = " + id + ", data = " + data + ")"; - } + public String toString() { + return "SetOwnedEntity(id = " + id + ", data = " + data + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/ListOwningEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/ListOwningEntity.java index 3548b6c53a..81df629409 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/ListOwningEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/ListOwningEntity.java @@ -22,86 +22,97 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.manytomany; -import java.util.List; + import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.ManyToMany; import javax.persistence.Table; +import java.util.List; import org.hibernate.envers.Audited; /** * Entity owning the many-to-many relation + * * @author Adam Warski (adam at warski dot org) */ @Entity @Table(name = "ListOwning") public class ListOwningEntity { - @Id - private Integer id; + @Id + private Integer id; - @Audited - private String data; + @Audited + private String data; - @Audited - @ManyToMany - private List references; + @Audited + @ManyToMany + private List references; - public ListOwningEntity() { } + public ListOwningEntity() { + } - public ListOwningEntity(Integer id, String data) { - this.id = id; - this.data = data; - } + public ListOwningEntity(Integer id, String data) { + this.id = id; + this.data = data; + } - public ListOwningEntity(String data) { - this.data = data; - } + public ListOwningEntity(String data) { + this.data = data; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public List getReferences() { - return references; - } + public List getReferences() { + return references; + } - public void setReferences(List references) { - this.references = references; - } + public void setReferences(List references) { + this.references = references; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ListOwningEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ListOwningEntity) ) { + return false; + } - ListOwningEntity that = (ListOwningEntity) o; + ListOwningEntity that = (ListOwningEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "SetOwningEntity(id = " + id + ", data = " + data + ")"; - } + public String toString() { + return "SetOwningEntity(id = " + id + ", data = " + data + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/MapOwnedEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/MapOwnedEntity.java index bf1167ff4c..b41612541e 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/MapOwnedEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/MapOwnedEntity.java @@ -22,87 +22,97 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.manytomany; -import java.util.Set; + import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.ManyToMany; import javax.persistence.Table; +import java.util.Set; import org.hibernate.envers.Audited; /** * Many-to-many not-owning entity + * * @author Adam Warski (adam at warski dot org) */ @Entity @Table(name = "MapOwned") public class MapOwnedEntity { - @Id - private Integer id; + @Id + private Integer id; - @Audited - private String data; + @Audited + private String data; - @Audited - @ManyToMany(mappedBy="references") - private Set referencing; + @Audited + @ManyToMany(mappedBy = "references") + private Set referencing; - public MapOwnedEntity() { - } + public MapOwnedEntity() { + } - public MapOwnedEntity(Integer id, String data) { - this.id = id; - this.data = data; - } + public MapOwnedEntity(Integer id, String data) { + this.id = id; + this.data = data; + } - public MapOwnedEntity(String data) { - this.data = data; - } + public MapOwnedEntity(String data) { + this.data = data; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public Set getReferencing() { - return referencing; - } + public Set getReferencing() { + return referencing; + } - public void setReferencing(Set referencing) { - this.referencing = referencing; - } + public void setReferencing(Set referencing) { + this.referencing = referencing; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof MapOwnedEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof MapOwnedEntity) ) { + return false; + } - MapOwnedEntity that = (MapOwnedEntity) o; + MapOwnedEntity that = (MapOwnedEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "MapOwnedEntity(id = " + id + ", data = " + data + ")"; - } + public String toString() { + return "MapOwnedEntity(id = " + id + ", data = " + data + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/MapOwningEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/MapOwningEntity.java index 07b0d1ffc1..4cd90c822b 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/MapOwningEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/MapOwningEntity.java @@ -22,89 +22,100 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.manytomany; -import java.util.HashMap; -import java.util.Map; + import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.ManyToMany; import javax.persistence.MapKeyColumn; import javax.persistence.Table; +import java.util.HashMap; +import java.util.Map; import org.hibernate.envers.Audited; /** * Entity owning the many-to-many relation + * * @author Adam Warski (adam at warski dot org) */ @Entity @Table(name = "MapOwning") public class MapOwningEntity { - @Id - private Integer id; + @Id + private Integer id; - @Audited - private String data; + @Audited + private String data; - @Audited - @ManyToMany - @MapKeyColumn(nullable=false) - private Map references = new HashMap(); + @Audited + @ManyToMany + @MapKeyColumn(nullable = false) + private Map references = new HashMap(); - public MapOwningEntity() { } + public MapOwningEntity() { + } - public MapOwningEntity(Integer id, String data) { - this.id = id; - this.data = data; - } + public MapOwningEntity(Integer id, String data) { + this.id = id; + this.data = data; + } - public MapOwningEntity(String data) { - this.data = data; - } + public MapOwningEntity(String data) { + this.data = data; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public Map getReferences() { - return references; - } + public Map getReferences() { + return references; + } - public void setReferences(Map references) { - this.references = references; - } + public void setReferences(Map references) { + this.references = references; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof MapOwningEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof MapOwningEntity) ) { + return false; + } - MapOwningEntity that = (MapOwningEntity) o; + MapOwningEntity that = (MapOwningEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "MapOwningEntity(id = " + id + ", data = " + data + ")"; - } + public String toString() { + return "MapOwningEntity(id = " + id + ", data = " + data + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/SetOwnedEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/SetOwnedEntity.java index c7fc832665..262ec1c3ad 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/SetOwnedEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/SetOwnedEntity.java @@ -22,87 +22,97 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.manytomany; -import java.util.Set; + import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.ManyToMany; import javax.persistence.Table; +import java.util.Set; import org.hibernate.envers.Audited; /** * Many-to-many not-owning entity + * * @author Adam Warski (adam at warski dot org) */ @Entity @Table(name = "SetOwned") public class SetOwnedEntity { - @Id - private Integer id; + @Id + private Integer id; - @Audited - private String data; + @Audited + private String data; - @Audited - @ManyToMany(mappedBy="references") - private Set referencing; + @Audited + @ManyToMany(mappedBy = "references") + private Set referencing; - public SetOwnedEntity() { - } + public SetOwnedEntity() { + } - public SetOwnedEntity(Integer id, String data) { - this.id = id; - this.data = data; - } + public SetOwnedEntity(Integer id, String data) { + this.id = id; + this.data = data; + } - public SetOwnedEntity(String data) { - this.data = data; - } + public SetOwnedEntity(String data) { + this.data = data; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public Set getReferencing() { - return referencing; - } + public Set getReferencing() { + return referencing; + } - public void setReferencing(Set referencing) { - this.referencing = referencing; - } + public void setReferencing(Set referencing) { + this.referencing = referencing; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof SetOwnedEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof SetOwnedEntity) ) { + return false; + } - SetOwnedEntity that = (SetOwnedEntity) o; + SetOwnedEntity that = (SetOwnedEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "SetOwnedEntity(id = " + id + ", data = " + data + ")"; - } + public String toString() { + return "SetOwnedEntity(id = " + id + ", data = " + data + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/SetOwningEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/SetOwningEntity.java index ab351bfbb7..22a0f210ca 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/SetOwningEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/SetOwningEntity.java @@ -22,86 +22,97 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.manytomany; -import java.util.Set; + import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.ManyToMany; import javax.persistence.Table; +import java.util.Set; import org.hibernate.envers.Audited; /** * Entity owning the many-to-many relation + * * @author Adam Warski (adam at warski dot org) */ @Entity @Table(name = "SetOwning") public class SetOwningEntity { - @Id - private Integer id; + @Id + private Integer id; - @Audited - private String data; + @Audited + private String data; - @Audited - @ManyToMany - private Set references; + @Audited + @ManyToMany + private Set references; - public SetOwningEntity() { } + public SetOwningEntity() { + } - public SetOwningEntity(Integer id, String data) { - this.id = id; - this.data = data; - } + public SetOwningEntity(Integer id, String data) { + this.id = id; + this.data = data; + } - public SetOwningEntity(String data) { - this.data = data; - } + public SetOwningEntity(String data) { + this.data = data; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public Set getReferences() { - return references; - } + public Set getReferences() { + return references; + } - public void setReferences(Set references) { - this.references = references; - } + public void setReferences(Set references) { + this.references = references; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof SetOwningEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof SetOwningEntity) ) { + return false; + } - SetOwningEntity that = (SetOwningEntity) o; + SetOwningEntity that = (SetOwningEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "SetOwningEntity(id = " + id + ", data = " + data + ")"; - } + public String toString() { + return "SetOwningEntity(id = " + id + ", data = " + data + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/SortedSetEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/SortedSetEntity.java index 1e0f22efd1..f88dcf09fa 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/SortedSetEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/SortedSetEntity.java @@ -23,15 +23,15 @@ */ package org.hibernate.envers.test.entities.manytomany; -import java.util.SortedMap; -import java.util.SortedSet; -import java.util.TreeMap; -import java.util.TreeSet; import javax.persistence.ElementCollection; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.ManyToMany; import javax.persistence.MapKeyJoinColumn; +import java.util.SortedMap; +import java.util.SortedSet; +import java.util.TreeMap; +import java.util.TreeSet; import org.hibernate.annotations.Sort; import org.hibernate.annotations.SortType; @@ -46,57 +46,57 @@ import org.hibernate.envers.test.entities.StrTestEntityComparator; */ @Entity public class SortedSetEntity { - @Id - private Integer id; + @Id + private Integer id; - @Audited - private String data; + @Audited + private String data; - @Audited - @ManyToMany - @Sort(type = SortType.COMPARATOR, comparator = StrTestEntityComparator.class) - private SortedSet sortedSet = new TreeSet(StrTestEntityComparator.INSTANCE); - @Audited + @Audited + @ManyToMany + @Sort(type = SortType.COMPARATOR, comparator = StrTestEntityComparator.class) + private SortedSet sortedSet = new TreeSet( StrTestEntityComparator.INSTANCE ); + @Audited @ElementCollection @MapKeyJoinColumn - @Sort(type = SortType.COMPARATOR, comparator = StrTestEntityComparator.class) - private SortedMap sortedMap = new TreeMap(StrTestEntityComparator.INSTANCE); + @Sort(type = SortType.COMPARATOR, comparator = StrTestEntityComparator.class) + private SortedMap sortedMap = new TreeMap( StrTestEntityComparator.INSTANCE ); - public SortedSetEntity() { - } + public SortedSetEntity() { + } - public SortedSetEntity(Integer id, String data) { - this.id = id; - this.data = data; - } + public SortedSetEntity(Integer id, String data) { + this.id = id; + this.data = data; + } - public SortedSetEntity(String data) { - this.data = data; - } + public SortedSetEntity(String data) { + this.data = data; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public SortedSet getSortedSet() { - return sortedSet; - } + public SortedSet getSortedSet() { + return sortedSet; + } - public void setSortedSet(SortedSet sortedSet) { - this.sortedSet = sortedSet; - } + public void setSortedSet(SortedSet sortedSet) { + this.sortedSet = sortedSet; + } public SortedMap getSortedMap() { return sortedMap; @@ -107,22 +107,28 @@ public class SortedSetEntity { } public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof SortedSetEntity)) return false; + if ( this == o ) { + return true; + } + if ( !(o instanceof SortedSetEntity) ) { + return false; + } - SortedSetEntity that = (SortedSetEntity) o; + SortedSetEntity that = (SortedSetEntity) o; - return !(data != null ? !data.equals(that.data) : that.data != null) && !(id != null ? !id.equals(that.id) : that.id != null); + return !(data != null ? !data.equals( that.data ) : that.data != null) && !(id != null ? + !id.equals( that.id ) : + that.id != null); } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "SetOwnedEntity(id = " + id + ", data = " + data + ")"; - } + public String toString() { + return "SetOwnedEntity(id = " + id + ", data = " + data + ")"; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/WhereJoinTableEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/WhereJoinTableEntity.java index 7df21a862e..35998cef89 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/WhereJoinTableEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/WhereJoinTableEntity.java @@ -1,11 +1,12 @@ package org.hibernate.envers.test.entities.manytomany; -import java.util.List; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; import javax.persistence.ManyToMany; +import java.util.List; import org.hibernate.annotations.WhereJoinTable; import org.hibernate.envers.Audited; @@ -17,84 +18,92 @@ import org.hibernate.envers.test.entities.IntNoAutoIdTestEntity; @Entity @Audited public class WhereJoinTableEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - private String data; + private String data; - @ManyToMany - @JoinTable( - name = "wjte_ite_join", - joinColumns = @JoinColumn(name = "wjte_id"), - inverseJoinColumns = @JoinColumn(name = "ite_id") - ) - @WhereJoinTable(clause = "ite_id < 20") - private List references1; + @ManyToMany + @JoinTable( + name = "wjte_ite_join", + joinColumns = @JoinColumn(name = "wjte_id"), + inverseJoinColumns = @JoinColumn(name = "ite_id") + ) + @WhereJoinTable(clause = "ite_id < 20") + private List references1; - @ManyToMany - @JoinTable( - name = "wjte_ite_join", - joinColumns = @JoinColumn(name = "wjte_id"), - inverseJoinColumns = @JoinColumn(name = "ite_id") - ) - @WhereJoinTable(clause = "ite_id >= 20") - private List references2; + @ManyToMany + @JoinTable( + name = "wjte_ite_join", + joinColumns = @JoinColumn(name = "wjte_id"), + inverseJoinColumns = @JoinColumn(name = "ite_id") + ) + @WhereJoinTable(clause = "ite_id >= 20") + private List references2; - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public List getReferences1() { - return references1; - } + public List getReferences1() { + return references1; + } - public void setReferences1(List references1) { - this.references1 = references1; - } + public void setReferences1(List references1) { + this.references1 = references1; + } - public List getReferences2() { - return references2; - } + public List getReferences2() { + return references2; + } - public void setReferences2(List references2) { - this.references2 = references2; - } + public void setReferences2(List references2) { + this.references2 = references2; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } - WhereJoinTableEntity that = (WhereJoinTableEntity) o; + WhereJoinTableEntity that = (WhereJoinTableEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - //noinspection RedundantIfStatement - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + //noinspection RedundantIfStatement + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - int result = id != null ? id.hashCode() : 0; - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = id != null ? id.hashCode() : 0; + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "WJTE(id = " + id + ", data = " + data + ")"; - } + public String toString() { + return "WJTE(id = " + id + ", data = " + data + ")"; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/biowned/ListBiowning1Entity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/biowned/ListBiowning1Entity.java index 13f2984fe7..dc9c9716cb 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/biowned/ListBiowning1Entity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/biowned/ListBiowning1Entity.java @@ -22,94 +22,105 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.manytomany.biowned; -import java.util.ArrayList; -import java.util.List; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; import javax.persistence.ManyToMany; +import java.util.ArrayList; +import java.util.List; import org.hibernate.envers.Audited; /** * Entity owning a many-to-many relation, where the other entity also owns the relation. + * * @author Adam Warski (adam at warski dot org) */ @Entity @Audited public class ListBiowning1Entity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - private String data; + private String data; - @ManyToMany - @JoinTable( - name = "biowning", - joinColumns = @JoinColumn(name = "biowning1_id"), - inverseJoinColumns = @JoinColumn(name = "biowning2_id", insertable = false, updatable = false) + @ManyToMany + @JoinTable( + name = "biowning", + joinColumns = @JoinColumn(name = "biowning1_id"), + inverseJoinColumns = @JoinColumn(name = "biowning2_id", insertable = false, updatable = false) ) - private List references = new ArrayList(); + private List references = new ArrayList(); - public ListBiowning1Entity() { } + public ListBiowning1Entity() { + } - public ListBiowning1Entity(Integer id, String data) { - this.id = id; - this.data = data; - } + public ListBiowning1Entity(Integer id, String data) { + this.id = id; + this.data = data; + } - public ListBiowning1Entity(String data) { - this.data = data; - } + public ListBiowning1Entity(String data) { + this.data = data; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public List getReferences() { - return references; - } + public List getReferences() { + return references; + } - public void setReferences(List references) { - this.references = references; - } + public void setReferences(List references) { + this.references = references; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ListBiowning1Entity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ListBiowning1Entity) ) { + return false; + } - ListBiowning1Entity that = (ListBiowning1Entity) o; + ListBiowning1Entity that = (ListBiowning1Entity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - //noinspection RedundantIfStatement - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + //noinspection RedundantIfStatement + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "ListBiowning1Entity(id = " + id + ", data = " + data + ")"; - } + public String toString() { + return "ListBiowning1Entity(id = " + id + ", data = " + data + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/biowned/ListBiowning2Entity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/biowned/ListBiowning2Entity.java index d17322d98a..e341a9ff0a 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/biowned/ListBiowning2Entity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/biowned/ListBiowning2Entity.java @@ -22,94 +22,105 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.manytomany.biowned; -import java.util.ArrayList; -import java.util.List; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; import javax.persistence.ManyToMany; +import java.util.ArrayList; +import java.util.List; import org.hibernate.envers.Audited; /** * Entity owning a many-to-many relation, where the other entity also owns the relation. + * * @author Adam Warski (adam at warski dot org) */ @Entity @Audited public class ListBiowning2Entity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - private String data; + private String data; - @ManyToMany - @JoinTable( - name = "biowning", - joinColumns = @JoinColumn(name = "biowning2_id"), - inverseJoinColumns = @JoinColumn(name = "biowning1_id", insertable = false, updatable = false) + @ManyToMany + @JoinTable( + name = "biowning", + joinColumns = @JoinColumn(name = "biowning2_id"), + inverseJoinColumns = @JoinColumn(name = "biowning1_id", insertable = false, updatable = false) ) - private List references = new ArrayList(); + private List references = new ArrayList(); - public ListBiowning2Entity() { } + public ListBiowning2Entity() { + } - public ListBiowning2Entity(Integer id, String data) { - this.id = id; - this.data = data; - } + public ListBiowning2Entity(Integer id, String data) { + this.id = id; + this.data = data; + } - public ListBiowning2Entity(String data) { - this.data = data; - } + public ListBiowning2Entity(String data) { + this.data = data; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public List getReferences() { - return references; - } + public List getReferences() { + return references; + } - public void setReferences(List references) { - this.references = references; - } + public void setReferences(List references) { + this.references = references; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ListBiowning2Entity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ListBiowning2Entity) ) { + return false; + } - ListBiowning2Entity that = (ListBiowning2Entity) o; + ListBiowning2Entity that = (ListBiowning2Entity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - //noinspection RedundantIfStatement - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + //noinspection RedundantIfStatement + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "ListBiowning2Entity(id = " + id + ", data = " + data + ")"; - } + public String toString() { + return "ListBiowning2Entity(id = " + id + ", data = " + data + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/sametable/Child1Entity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/sametable/Child1Entity.java index 9b4a70ed78..fb05746f06 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/sametable/Child1Entity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/sametable/Child1Entity.java @@ -1,6 +1,5 @@ package org.hibernate.envers.test.entities.manytomany.sametable; -import java.util.ArrayList; -import java.util.List; + import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; @@ -8,6 +7,8 @@ import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; import javax.persistence.ManyToMany; +import java.util.ArrayList; +import java.util.List; import org.hibernate.annotations.WhereJoinTable; import org.hibernate.envers.Audited; @@ -18,79 +19,87 @@ import org.hibernate.envers.Audited; @Entity @Audited public class Child1Entity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - private String child1Data; + private String child1Data; - public Child1Entity() { - } + public Child1Entity() { + } - public Child1Entity(String child1Data) { - this.child1Data = child1Data; - } + public Child1Entity(String child1Data) { + this.child1Data = child1Data; + } - public Child1Entity(String child1Data, Integer id) { - this.child1Data = child1Data; - this.id = id; - } + public Child1Entity(String child1Data, Integer id) { + this.child1Data = child1Data; + this.id = id; + } - @ManyToMany(fetch = FetchType.LAZY) + @ManyToMany(fetch = FetchType.LAZY) @JoinTable( - name = "children", - joinColumns = @JoinColumn(name = "child1_id"), - inverseJoinColumns = @JoinColumn(name = "parent_id", insertable = false, updatable = false) + name = "children", + joinColumns = @JoinColumn(name = "child1_id"), + inverseJoinColumns = @JoinColumn(name = "parent_id", insertable = false, updatable = false) ) @WhereJoinTable(clause = "child1_id is not null") private List parents = new ArrayList(); - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getChild1Data() { - return child1Data; - } + public String getChild1Data() { + return child1Data; + } - public void setChild1Data(String child1Data) { - this.child1Data = child1Data; - } + public void setChild1Data(String child1Data) { + this.child1Data = child1Data; + } - public List getParents() { - return parents; - } + public List getParents() { + return parents; + } - public void setParents(List parents) { - this.parents = parents; - } + public void setParents(List parents) { + this.parents = parents; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } - Child1Entity that = (Child1Entity) o; + Child1Entity that = (Child1Entity) o; - if (child1Data != null ? !child1Data.equals(that.child1Data) : that.child1Data != null) return false; - //noinspection RedundantIfStatement - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( child1Data != null ? !child1Data.equals( that.child1Data ) : that.child1Data != null ) { + return false; + } + //noinspection RedundantIfStatement + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - int result = id != null ? id.hashCode() : 0; - result = 31 * result + (child1Data != null ? child1Data.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = id != null ? id.hashCode() : 0; + result = 31 * result + (child1Data != null ? child1Data.hashCode() : 0); + return result; + } - public String toString() { - return "C1E(id = " + id + ", child1Data = " + child1Data + ")"; - } + public String toString() { + return "C1E(id = " + id + ", child1Data = " + child1Data + ")"; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/sametable/Child2Entity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/sametable/Child2Entity.java index 4a2db0fd35..87963f4251 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/sametable/Child2Entity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/sametable/Child2Entity.java @@ -1,6 +1,5 @@ package org.hibernate.envers.test.entities.manytomany.sametable; -import java.util.ArrayList; -import java.util.List; + import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; @@ -8,6 +7,8 @@ import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; import javax.persistence.ManyToMany; +import java.util.ArrayList; +import java.util.List; import org.hibernate.annotations.WhereJoinTable; import org.hibernate.envers.Audited; @@ -18,79 +19,87 @@ import org.hibernate.envers.Audited; @Entity @Audited public class Child2Entity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - private String child2Data; + private String child2Data; - public Child2Entity() { - } + public Child2Entity() { + } - public Child2Entity(String child2Data) { - this.child2Data = child2Data; - } + public Child2Entity(String child2Data) { + this.child2Data = child2Data; + } - public Child2Entity(Integer id, String child2Data) { - this.id = id; - this.child2Data = child2Data; - } + public Child2Entity(Integer id, String child2Data) { + this.id = id; + this.child2Data = child2Data; + } - @ManyToMany(fetch = FetchType.LAZY) + @ManyToMany(fetch = FetchType.LAZY) @JoinTable( - name = "children", - joinColumns = @JoinColumn(name = "child2_id"), - inverseJoinColumns = @JoinColumn(name = "parent_id", insertable = false, updatable = false) + name = "children", + joinColumns = @JoinColumn(name = "child2_id"), + inverseJoinColumns = @JoinColumn(name = "parent_id", insertable = false, updatable = false) ) @WhereJoinTable(clause = "child2_id is not null") private List parents = new ArrayList(); - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getChild2Data() { - return child2Data; - } + public String getChild2Data() { + return child2Data; + } - public void setChild2Data(String child2Data) { - this.child2Data = child2Data; - } + public void setChild2Data(String child2Data) { + this.child2Data = child2Data; + } - public List getParents() { - return parents; - } + public List getParents() { + return parents; + } - public void setParents(List parents) { - this.parents = parents; - } + public void setParents(List parents) { + this.parents = parents; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } - Child2Entity that = (Child2Entity) o; + Child2Entity that = (Child2Entity) o; - if (child2Data != null ? !child2Data.equals(that.child2Data) : that.child2Data != null) return false; - //noinspection RedundantIfStatement - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( child2Data != null ? !child2Data.equals( that.child2Data ) : that.child2Data != null ) { + return false; + } + //noinspection RedundantIfStatement + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - int result = id != null ? id.hashCode() : 0; - result = 31 * result + (child2Data != null ? child2Data.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = id != null ? id.hashCode() : 0; + result = 31 * result + (child2Data != null ? child2Data.hashCode() : 0); + return result; + } - public String toString() { - return "C2E(id = " + id + ", child2Data = " + child2Data + ")"; - } + public String toString() { + return "C2E(id = " + id + ", child2Data = " + child2Data + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/sametable/ParentEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/sametable/ParentEntity.java index 8442bdd882..c75a4fd021 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/sametable/ParentEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/sametable/ParentEntity.java @@ -1,6 +1,5 @@ package org.hibernate.envers.test.entities.manytomany.sametable; -import java.util.ArrayList; -import java.util.List; + import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; @@ -8,6 +7,8 @@ import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; import javax.persistence.ManyToMany; +import java.util.ArrayList; +import java.util.List; import org.hibernate.annotations.WhereJoinTable; import org.hibernate.envers.Audited; @@ -18,96 +19,104 @@ import org.hibernate.envers.Audited; @Entity @Audited public class ParentEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - private String parentData; + private String parentData; - public ParentEntity() { - } + public ParentEntity() { + } - public ParentEntity(String parentData) { - this.parentData = parentData; - } + public ParentEntity(String parentData) { + this.parentData = parentData; + } - public ParentEntity(Integer id, String parentData) { - this.id = id; - this.parentData = parentData; - } + public ParentEntity(Integer id, String parentData) { + this.id = id; + this.parentData = parentData; + } - @ManyToMany(fetch = FetchType.LAZY) + @ManyToMany(fetch = FetchType.LAZY) @JoinTable( - name = "children", - joinColumns = @JoinColumn(name = "parent_id"), - inverseJoinColumns = @JoinColumn(name = "child1_id", insertable = false, updatable = false) + name = "children", + joinColumns = @JoinColumn(name = "parent_id"), + inverseJoinColumns = @JoinColumn(name = "child1_id", insertable = false, updatable = false) ) @WhereJoinTable(clause = "child1_id is not null") private List children1 = new ArrayList(); - @ManyToMany(fetch = FetchType.LAZY) + @ManyToMany(fetch = FetchType.LAZY) @JoinTable( - name = "children", - joinColumns = @JoinColumn(name = "parent_id"), - inverseJoinColumns = @JoinColumn(name = "child2_id", insertable = false, updatable = false) + name = "children", + joinColumns = @JoinColumn(name = "parent_id"), + inverseJoinColumns = @JoinColumn(name = "child2_id", insertable = false, updatable = false) ) @WhereJoinTable(clause = "child2_id is not null") private List children2 = new ArrayList(); - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getParentData() { - return parentData; - } + public String getParentData() { + return parentData; + } - public void setParentData(String parentData) { - this.parentData = parentData; - } + public void setParentData(String parentData) { + this.parentData = parentData; + } - public List getChildren1() { - return children1; - } + public List getChildren1() { + return children1; + } - public void setChildren1(List children1) { - this.children1 = children1; - } + public void setChildren1(List children1) { + this.children1 = children1; + } - public List getChildren2() { - return children2; - } + public List getChildren2() { + return children2; + } - public void setChildren2(List children2) { - this.children2 = children2; - } + public void setChildren2(List children2) { + this.children2 = children2; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } - ParentEntity that = (ParentEntity) o; + ParentEntity that = (ParentEntity) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; - //noinspection RedundantIfStatement - if (parentData != null ? !parentData.equals(that.parentData) : that.parentData != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } + //noinspection RedundantIfStatement + if ( parentData != null ? !parentData.equals( that.parentData ) : that.parentData != null ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - int result = id != null ? id.hashCode() : 0; - result = 31 * result + (parentData != null ? parentData.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = id != null ? id.hashCode() : 0; + result = 31 * result + (parentData != null ? parentData.hashCode() : 0); + return result; + } - public String toString() { - return "PE(id = " + id + ", parentData = " + parentData + ")"; - } + public String toString() { + return "PE(id = " + id + ", parentData = " + parentData + ")"; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/unidirectional/JoinTableEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/unidirectional/JoinTableEntity.java index 1e5c162b08..916e2220e1 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/unidirectional/JoinTableEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/unidirectional/JoinTableEntity.java @@ -1,14 +1,14 @@ package org.hibernate.envers.test.entities.manytomany.unidirectional; -import java.io.Serializable; -import java.util.HashSet; -import java.util.Set; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; import javax.persistence.ManyToMany; +import java.io.Serializable; +import java.util.HashSet; +import java.util.Set; import org.hibernate.envers.Audited; import org.hibernate.envers.test.entities.StrTestEntity; @@ -27,8 +27,8 @@ public class JoinTableEntity implements Serializable { @ManyToMany @JoinTable(name = "test_join_table", - joinColumns = @JoinColumn(name = "assoc_id1"), - inverseJoinColumns = @JoinColumn(name = "assoc_id2") + joinColumns = @JoinColumn(name = "assoc_id1"), + inverseJoinColumns = @JoinColumn(name = "assoc_id2") ) private Set references = new HashSet(); @@ -46,13 +46,21 @@ public class JoinTableEntity implements Serializable { @Override public boolean equals(Object o) { - if ( this == o ) return true; - if ( !( o instanceof JoinTableEntity ) ) return false; + if ( this == o ) { + return true; + } + if ( !(o instanceof JoinTableEntity) ) { + return false; + } JoinTableEntity that = (JoinTableEntity) o; - if ( data != null ? !data.equals( that.data ) : that.data != null ) return false; - if ( id != null ? !id.equals( that.id ) : that.id != null ) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } return true; } @@ -60,7 +68,7 @@ public class JoinTableEntity implements Serializable { @Override public int hashCode() { int result = id != null ? id.hashCode() : 0; - result = 31 * result + ( data != null ? data.hashCode() : 0 ); + result = 31 * result + (data != null ? data.hashCode() : 0); return result; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/unidirectional/ListUniEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/unidirectional/ListUniEntity.java index 7c3b78ef64..52b846e1a3 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/unidirectional/ListUniEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/unidirectional/ListUniEntity.java @@ -22,85 +22,96 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.manytomany.unidirectional; -import java.util.List; + import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.ManyToMany; +import java.util.List; import org.hibernate.envers.Audited; import org.hibernate.envers.test.entities.StrTestEntity; /** * Entity owning the many-to-many relation + * * @author Adam Warski (adam at warski dot org) */ @Entity public class ListUniEntity { - @Id - private Integer id; + @Id + private Integer id; - @Audited - private String data; + @Audited + private String data; - @Audited - @ManyToMany - private List references; + @Audited + @ManyToMany + private List references; - public ListUniEntity() { } + public ListUniEntity() { + } - public ListUniEntity(Integer id, String data) { - this.id = id; - this.data = data; - } + public ListUniEntity(Integer id, String data) { + this.id = id; + this.data = data; + } - public ListUniEntity(String data) { - this.data = data; - } + public ListUniEntity(String data) { + this.data = data; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public List getReferences() { - return references; - } + public List getReferences() { + return references; + } - public void setReferences(List references) { - this.references = references; - } + public void setReferences(List references) { + this.references = references; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ListUniEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ListUniEntity) ) { + return false; + } - ListUniEntity that = (ListUniEntity) o; + ListUniEntity that = (ListUniEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "ListUniEntity(id = " + id + ", data = " + data + ")"; - } + public String toString() { + return "ListUniEntity(id = " + id + ", data = " + data + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/unidirectional/M2MIndexedListTargetNotAuditedEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/unidirectional/M2MIndexedListTargetNotAuditedEntity.java index 1b36f14a4b..2caa3a8540 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/unidirectional/M2MIndexedListTargetNotAuditedEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/unidirectional/M2MIndexedListTargetNotAuditedEntity.java @@ -1,12 +1,13 @@ package org.hibernate.envers.test.entities.manytomany.unidirectional; -import java.util.ArrayList; -import java.util.List; + import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.Id; import javax.persistence.ManyToMany; import javax.persistence.OrderColumn; import javax.persistence.Table; +import java.util.ArrayList; +import java.util.List; import org.hibernate.envers.Audited; import org.hibernate.envers.RelationTargetAuditMode; @@ -19,79 +20,85 @@ import org.hibernate.envers.test.entities.UnversionedStrTestEntity; @Table(name = "M2M_IDX_LIST") public class M2MIndexedListTargetNotAuditedEntity { - @Id - private Integer id; + @Id + private Integer id; - @Audited - private String data; + @Audited + private String data; - @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED) - @OrderColumn(name = "sortOrder") - @ManyToMany(fetch = FetchType.LAZY) - private List references = new ArrayList(); + @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED) + @OrderColumn(name = "sortOrder") + @ManyToMany(fetch = FetchType.LAZY) + private List references = new ArrayList(); - public M2MIndexedListTargetNotAuditedEntity() { - } + public M2MIndexedListTargetNotAuditedEntity() { + } - public M2MIndexedListTargetNotAuditedEntity(Integer id, String data) { - this.id = id; - this.data = data; - } + public M2MIndexedListTargetNotAuditedEntity(Integer id, String data) { + this.id = id; + this.data = data; + } - public M2MIndexedListTargetNotAuditedEntity(Integer id, String data, List references) { - this.id = id; - this.data = data; - this.references = references; - } + public M2MIndexedListTargetNotAuditedEntity(Integer id, String data, List references) { + this.id = id; + this.data = data; + this.references = references; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public List getReferences() { - return references; - } + public List getReferences() { + return references; + } - public void setReferences(List references) { - this.references = references; - } + public void setReferences(List references) { + this.references = references; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } - M2MIndexedListTargetNotAuditedEntity that = (M2MIndexedListTargetNotAuditedEntity) o; + M2MIndexedListTargetNotAuditedEntity that = (M2MIndexedListTargetNotAuditedEntity) o; - //noinspection RedundantIfStatement - if (data != null ? !data.equals(that.data) : that.data != null) return false; + //noinspection RedundantIfStatement + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - return data != null ? data.hashCode() : 0; - } + @Override + public int hashCode() { + return data != null ? data.hashCode() : 0; + } - @Override - public String toString() { + @Override + public String toString() { return "M2MIndexedListTargetNotAuditedEntity(id = " + id + ", data = " + data + ")"; - } + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/unidirectional/M2MTargetNotAuditedEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/unidirectional/M2MTargetNotAuditedEntity.java index aa9f13b296..ae8e52117f 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/unidirectional/M2MTargetNotAuditedEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/unidirectional/M2MTargetNotAuditedEntity.java @@ -22,12 +22,13 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.manytomany.unidirectional; -import java.util.List; + import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.Id; import javax.persistence.ManyToMany; import javax.persistence.Table; +import java.util.List; import org.hibernate.envers.Audited; import org.hibernate.envers.RelationTargetAuditMode; @@ -35,6 +36,7 @@ import org.hibernate.envers.test.entities.UnversionedStrTestEntity; /** * Audited entity with a many-to-many-reference to not audited entity. + * * @author Toamsz Bech * @author Adam Warski */ @@ -51,7 +53,8 @@ public class M2MTargetNotAuditedEntity { @ManyToMany(fetch = FetchType.LAZY) private List references; - public M2MTargetNotAuditedEntity() { } + public M2MTargetNotAuditedEntity() { + } public M2MTargetNotAuditedEntity(Integer id, String data, List references) { this.id = id; @@ -85,23 +88,31 @@ public class M2MTargetNotAuditedEntity { this.data = data; } - public List getReferences() { - return references; - } + public List getReferences() { + return references; + } - public void setReferences(List references) { - this.references = references; - } + public void setReferences(List references) { + this.references = references; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof M2MTargetNotAuditedEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof M2MTargetNotAuditedEntity) ) { + return false; + } M2MTargetNotAuditedEntity that = (M2MTargetNotAuditedEntity) o; - if (data != null ? !data.equals(that.getData()) : that.getData() != null) return false; - //noinspection RedundantIfStatement - if (id != null ? !id.equals(that.getId()) : that.getId() != null) return false; + if ( data != null ? !data.equals( that.getData() ) : that.getData() != null ) { + return false; + } + //noinspection RedundantIfStatement + if ( id != null ? !id.equals( that.getId() ) : that.getId() != null ) { + return false; + } return true; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/unidirectional/MapUniEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/unidirectional/MapUniEntity.java index 9ea50a77bd..e1430e39f0 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/unidirectional/MapUniEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/unidirectional/MapUniEntity.java @@ -22,88 +22,98 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.manytomany.unidirectional; -import java.util.Map; + import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.ManyToMany; import javax.persistence.MapKeyColumn; +import java.util.Map; import org.hibernate.envers.Audited; import org.hibernate.envers.test.entities.StrTestEntity; /** * Entity with a map from a string to an entity + * * @author Adam Warski (adam at warski dot org) */ @Entity public class MapUniEntity { - @Id - private Integer id; + @Id + private Integer id; - @Audited - private String data; + @Audited + private String data; - @Audited - @ManyToMany - @MapKeyColumn(nullable=false) - private Map map; + @Audited + @ManyToMany + @MapKeyColumn(nullable = false) + private Map map; - public MapUniEntity() { - } + public MapUniEntity() { + } - public MapUniEntity(Integer id, String data) { - this.id = id; - this.data = data; - } + public MapUniEntity(Integer id, String data) { + this.id = id; + this.data = data; + } - public MapUniEntity(String data) { - this.data = data; - } + public MapUniEntity(String data) { + this.data = data; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public Map getMap() { - return map; - } + public Map getMap() { + return map; + } - public void setMap(Map map) { - this.map = map; - } + public void setMap(Map map) { + this.map = map; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof MapUniEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof MapUniEntity) ) { + return false; + } - MapUniEntity that = (MapUniEntity) o; + MapUniEntity that = (MapUniEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "MapUniEntity(id = " + id + ", data = " + data + ")"; - } + public String toString() { + return "MapUniEntity(id = " + id + ", data = " + data + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/unidirectional/SetUniEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/unidirectional/SetUniEntity.java index a53c4284ee..7454725161 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/unidirectional/SetUniEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/unidirectional/SetUniEntity.java @@ -22,85 +22,96 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.manytomany.unidirectional; -import java.util.Set; + import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.ManyToMany; +import java.util.Set; import org.hibernate.envers.Audited; import org.hibernate.envers.test.entities.StrTestEntity; /** * Entity owning the many-to-many relation + * * @author Adam Warski (adam at warski dot org) */ @Entity public class SetUniEntity { - @Id - private Integer id; + @Id + private Integer id; - @Audited - private String data; + @Audited + private String data; - @Audited - @ManyToMany - private Set references; + @Audited + @ManyToMany + private Set references; - public SetUniEntity() { } + public SetUniEntity() { + } - public SetUniEntity(Integer id, String data) { - this.id = id; - this.data = data; - } + public SetUniEntity(Integer id, String data) { + this.id = id; + this.data = data; + } - public SetUniEntity(String data) { - this.data = data; - } + public SetUniEntity(String data) { + this.data = data; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public Set getReferences() { - return references; - } + public Set getReferences() { + return references; + } - public void setReferences(Set references) { - this.references = references; - } + public void setReferences(Set references) { + this.references = references; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof SetUniEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof SetUniEntity) ) { + return false; + } - SetUniEntity that = (SetUniEntity) o; + SetUniEntity that = (SetUniEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "SetUniEntity(id = " + id + ", data = " + data + ")"; - } + public String toString() { + return "SetUniEntity(id = " + id + ", data = " + data + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytoone/unidirectional/TargetNotAuditedEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytoone/unidirectional/TargetNotAuditedEntity.java index 6b2578964f..d655e605d5 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytoone/unidirectional/TargetNotAuditedEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytoone/unidirectional/TargetNotAuditedEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.manytoone.unidirectional; + import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.Id; @@ -33,6 +34,7 @@ import org.hibernate.envers.test.entities.UnversionedStrTestEntity; /** * Audited entity with a reference to not audited entity. + * * @author Toamsz Bech */ @Entity @@ -47,7 +49,8 @@ public class TargetNotAuditedEntity { @ManyToOne(fetch = FetchType.LAZY) private UnversionedStrTestEntity reference; - public TargetNotAuditedEntity() { } + public TargetNotAuditedEntity() { + } public TargetNotAuditedEntity(Integer id, String data, UnversionedStrTestEntity reference) { this.id = id; @@ -90,13 +93,21 @@ public class TargetNotAuditedEntity { } public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof TargetNotAuditedEntity)) return false; + if ( this == o ) { + return true; + } + if ( !(o instanceof TargetNotAuditedEntity) ) { + return false; + } TargetNotAuditedEntity that = (TargetNotAuditedEntity) o; - if (data != null ? !data.equals(that.getData()) : that.getData() != null) return false; - if (id != null ? !id.equals(that.getId()) : that.getId() != null) return false; + if ( data != null ? !data.equals( that.getData() ) : that.getData() != null ) { + return false; + } + if ( id != null ? !id.equals( that.getId() ) : that.getId() != null ) { + return false; + } return true; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/CollectionRefEdEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/CollectionRefEdEntity.java index cedf8e4b57..8e6baedddd 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/CollectionRefEdEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/CollectionRefEdEntity.java @@ -22,88 +22,98 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.onetomany; -import java.io.Serializable; -import java.util.Collection; + import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.OneToMany; +import java.io.Serializable; +import java.util.Collection; import org.hibernate.envers.Audited; /** * ReferencEd entity + * * @author Adam Warski (adam at warski dot org) */ @Entity public class CollectionRefEdEntity implements Serializable { private static final long serialVersionUID = -1694020123633796683L; - @Id - private Integer id; + @Id + private Integer id; - @Audited - private String data; + @Audited + private String data; - @Audited - @OneToMany(mappedBy="reference") - private Collection reffering; + @Audited + @OneToMany(mappedBy = "reference") + private Collection reffering; public CollectionRefEdEntity() { - } + } - public CollectionRefEdEntity(Integer id, String data) { - this.id = id; - this.data = data; - } + public CollectionRefEdEntity(Integer id, String data) { + this.id = id; + this.data = data; + } - public CollectionRefEdEntity(String data) { - this.data = data; - } + public CollectionRefEdEntity(String data) { + this.data = data; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public Collection getReffering() { - return reffering; - } + public Collection getReffering() { + return reffering; + } - public void setReffering(Collection reffering) { - this.reffering = reffering; - } + public void setReffering(Collection reffering) { + this.reffering = reffering; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof CollectionRefEdEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof CollectionRefEdEntity) ) { + return false; + } - CollectionRefEdEntity that = (CollectionRefEdEntity) o; + CollectionRefEdEntity that = (CollectionRefEdEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "CollectionRefEdEntity(id = " + id + ", data = " + data + ")"; - } + public String toString() { + return "CollectionRefEdEntity(id = " + id + ", data = " + data + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/CollectionRefIngEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/CollectionRefIngEntity.java index 6242faf02b..67992c838b 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/CollectionRefIngEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/CollectionRefIngEntity.java @@ -22,88 +22,99 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.onetomany; -import java.io.Serializable; + import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.ManyToOne; +import java.io.Serializable; import org.hibernate.envers.Audited; /** * ReferencIng entity + * * @author Adam Warski (adam at warski dot org) */ @Entity public class CollectionRefIngEntity implements Serializable { private static final long serialVersionUID = -9019967223928425707L; - - @Id - private Integer id; - @Audited - private String data; + @Id + private Integer id; - @Audited - @ManyToOne - private CollectionRefEdEntity reference; + @Audited + private String data; - public CollectionRefIngEntity() { } + @Audited + @ManyToOne + private CollectionRefEdEntity reference; - public CollectionRefIngEntity(Integer id, String data, CollectionRefEdEntity reference) { - this.id = id; - this.data = data; - this.reference = reference; - } + public CollectionRefIngEntity() { + } - public CollectionRefIngEntity(String data, CollectionRefEdEntity reference) { - this.data = data; - this.reference = reference; - } + public CollectionRefIngEntity(Integer id, String data, CollectionRefEdEntity reference) { + this.id = id; + this.data = data; + this.reference = reference; + } - public Integer getId() { - return id; - } + public CollectionRefIngEntity(String data, CollectionRefEdEntity reference) { + this.data = data; + this.reference = reference; + } - public void setId(Integer id) { - this.id = id; - } + public Integer getId() { + return id; + } - public String getData() { - return data; - } + public void setId(Integer id) { + this.id = id; + } - public void setData(String data) { - this.data = data; - } + public String getData() { + return data; + } - public CollectionRefEdEntity getReference() { - return reference; - } + public void setData(String data) { + this.data = data; + } - public void setReference(CollectionRefEdEntity reference) { - this.reference = reference; - } + public CollectionRefEdEntity getReference() { + return reference; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof CollectionRefIngEntity)) return false; + public void setReference(CollectionRefEdEntity reference) { + this.reference = reference; + } - CollectionRefIngEntity that = (CollectionRefIngEntity) o; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof CollectionRefIngEntity) ) { + return false; + } - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + CollectionRefIngEntity that = (CollectionRefIngEntity) o; - return true; - } + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + return true; + } - public String toString() { - return "CollectionRefIngEntity(id = " + id + ", data = " + data + ")"; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } + + public String toString() { + return "CollectionRefIngEntity(id = " + id + ", data = " + data + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/ListRefEdEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/ListRefEdEntity.java index b1ea8ff8d0..446d38801c 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/ListRefEdEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/ListRefEdEntity.java @@ -22,85 +22,95 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.onetomany; -import java.util.List; + import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.OneToMany; +import java.util.List; import org.hibernate.envers.Audited; /** * ReferencEd entity + * * @author Adam Warski (adam at warski dot org) */ @Entity public class ListRefEdEntity { - @Id - private Integer id; + @Id + private Integer id; - @Audited - private String data; + @Audited + private String data; - @Audited - @OneToMany(mappedBy="reference") - private List reffering; + @Audited + @OneToMany(mappedBy = "reference") + private List reffering; - public ListRefEdEntity() { - } + public ListRefEdEntity() { + } - public ListRefEdEntity(Integer id, String data) { - this.id = id; - this.data = data; - } + public ListRefEdEntity(Integer id, String data) { + this.id = id; + this.data = data; + } - public ListRefEdEntity(String data) { - this.data = data; - } + public ListRefEdEntity(String data) { + this.data = data; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public List getReffering() { - return reffering; - } + public List getReffering() { + return reffering; + } - public void setReffering(List reffering) { - this.reffering = reffering; - } + public void setReffering(List reffering) { + this.reffering = reffering; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ListRefEdEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ListRefEdEntity) ) { + return false; + } - ListRefEdEntity that = (ListRefEdEntity) o; + ListRefEdEntity that = (ListRefEdEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "ListRefEdEntity(id = " + id + ", data = " + data + ")"; - } + public String toString() { + return "ListRefEdEntity(id = " + id + ", data = " + data + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/ListRefIngEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/ListRefIngEntity.java index 49ab705301..e20c8974ca 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/ListRefIngEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/ListRefIngEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.onetomany; + import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.ManyToOne; @@ -30,77 +31,87 @@ import org.hibernate.envers.Audited; /** * ReferencIng entity + * * @author Adam Warski (adam at warski dot org) */ @Entity public class ListRefIngEntity { - @Id - private Integer id; + @Id + private Integer id; - @Audited - private String data; + @Audited + private String data; - @Audited - @ManyToOne - private ListRefEdEntity reference; + @Audited + @ManyToOne + private ListRefEdEntity reference; - public ListRefIngEntity() { } + public ListRefIngEntity() { + } - public ListRefIngEntity(Integer id, String data, ListRefEdEntity reference) { - this.id = id; - this.data = data; - this.reference = reference; - } + public ListRefIngEntity(Integer id, String data, ListRefEdEntity reference) { + this.id = id; + this.data = data; + this.reference = reference; + } - public ListRefIngEntity(String data, ListRefEdEntity reference) { - this.data = data; - this.reference = reference; - } + public ListRefIngEntity(String data, ListRefEdEntity reference) { + this.data = data; + this.reference = reference; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public ListRefEdEntity getReference() { - return reference; - } + public ListRefEdEntity getReference() { + return reference; + } - public void setReference(ListRefEdEntity reference) { - this.reference = reference; - } + public void setReference(ListRefEdEntity reference) { + this.reference = reference; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ListRefIngEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ListRefIngEntity) ) { + return false; + } - ListRefIngEntity that = (ListRefIngEntity) o; + ListRefIngEntity that = (ListRefIngEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "ListRefIngEntity(id = " + id + ", data = " + data + ")"; - } + public String toString() { + return "ListRefIngEntity(id = " + id + ", data = " + data + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/SetRefEdEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/SetRefEdEntity.java index ce479b3ca7..1551ee9f77 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/SetRefEdEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/SetRefEdEntity.java @@ -22,85 +22,95 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.onetomany; -import java.util.Set; + import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.OneToMany; +import java.util.Set; import org.hibernate.envers.Audited; /** * ReferencEd entity + * * @author Adam Warski (adam at warski dot org) */ @Entity public class SetRefEdEntity { - @Id - private Integer id; + @Id + private Integer id; - @Audited - private String data; + @Audited + private String data; - @Audited - @OneToMany(mappedBy="reference") - private Set reffering; + @Audited + @OneToMany(mappedBy = "reference") + private Set reffering; - public SetRefEdEntity() { - } + public SetRefEdEntity() { + } - public SetRefEdEntity(Integer id, String data) { - this.id = id; - this.data = data; - } + public SetRefEdEntity(Integer id, String data) { + this.id = id; + this.data = data; + } - public SetRefEdEntity(String data) { - this.data = data; - } + public SetRefEdEntity(String data) { + this.data = data; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public Set getReffering() { - return reffering; - } + public Set getReffering() { + return reffering; + } - public void setReffering(Set reffering) { - this.reffering = reffering; - } + public void setReffering(Set reffering) { + this.reffering = reffering; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof SetRefEdEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof SetRefEdEntity) ) { + return false; + } - SetRefEdEntity that = (SetRefEdEntity) o; + SetRefEdEntity that = (SetRefEdEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "SetRefEdEntity(id = " + id + ", data = " + data + ")"; - } + public String toString() { + return "SetRefEdEntity(id = " + id + ", data = " + data + ")"; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/SetRefIngEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/SetRefIngEntity.java index 0d03282fc4..11d96f0b9e 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/SetRefIngEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/SetRefIngEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.onetomany; + import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.ManyToOne; @@ -30,82 +31,92 @@ import org.hibernate.envers.Audited; /** * ReferencIng entity + * * @author Adam Warski (adam at warski dot org) */ @Entity public class SetRefIngEntity { - @Id - private Integer id; + @Id + private Integer id; - @Audited - private String data; + @Audited + private String data; - @Audited - @ManyToOne - private SetRefEdEntity reference; + @Audited + @ManyToOne + private SetRefEdEntity reference; - public SetRefIngEntity() { } + public SetRefIngEntity() { + } - public SetRefIngEntity(Integer id, String data, SetRefEdEntity reference) { - this.id = id; - this.data = data; - this.reference = reference; - } + public SetRefIngEntity(Integer id, String data, SetRefEdEntity reference) { + this.id = id; + this.data = data; + this.reference = reference; + } - public SetRefIngEntity(String data, SetRefEdEntity reference) { - this.data = data; - this.reference = reference; - } + public SetRefIngEntity(String data, SetRefEdEntity reference) { + this.data = data; + this.reference = reference; + } - public SetRefIngEntity(Integer id, String data) { - this.id = id; - this.data = data; - } + public SetRefIngEntity(Integer id, String data) { + this.id = id; + this.data = data; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public SetRefEdEntity getReference() { - return reference; - } + public SetRefEdEntity getReference() { + return reference; + } - public void setReference(SetRefEdEntity reference) { - this.reference = reference; - } + public void setReference(SetRefEdEntity reference) { + this.reference = reference; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof SetRefIngEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof SetRefIngEntity) ) { + return false; + } - SetRefIngEntity that = (SetRefIngEntity) o; + SetRefIngEntity that = (SetRefIngEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "SetRefIngEntity(id = " + id + ", data = " + data + ")"; - } + public String toString() { + return "SetRefIngEntity(id = " + id + ", data = " + data + ")"; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/DoubleListJoinColumnBidirectionalRefEdEntity1.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/DoubleListJoinColumnBidirectionalRefEdEntity1.java index e159870ce7..707e9a8889 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/DoubleListJoinColumnBidirectionalRefEdEntity1.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/DoubleListJoinColumnBidirectionalRefEdEntity1.java @@ -1,4 +1,5 @@ package org.hibernate.envers.test.entities.onetomany.detached; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; @@ -11,80 +12,95 @@ import org.hibernate.envers.Audited; /** * Entity for {@link org.hibernate.envers.test.integration.onetomany.detached.DoubleJoinColumnBidirectionalList} test. * Owned side of the first relation. + * * @author Adam Warski (adam at warski dot org) */ @Entity @Table(name = "DoubleJoinColBiRefEd1") @Audited public class DoubleListJoinColumnBidirectionalRefEdEntity1 { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - private String data; + private String data; - @ManyToOne - @JoinColumn(name = "some_join_column_1", insertable = false, updatable = false) - private DoubleListJoinColumnBidirectionalRefIngEntity owner; + @ManyToOne + @JoinColumn(name = "some_join_column_1", insertable = false, updatable = false) + private DoubleListJoinColumnBidirectionalRefIngEntity owner; - public DoubleListJoinColumnBidirectionalRefEdEntity1() { } + public DoubleListJoinColumnBidirectionalRefEdEntity1() { + } - public DoubleListJoinColumnBidirectionalRefEdEntity1(Integer id, String data, DoubleListJoinColumnBidirectionalRefIngEntity owner) { - this.id = id; - this.data = data; - this.owner = owner; - } + public DoubleListJoinColumnBidirectionalRefEdEntity1( + Integer id, + String data, + DoubleListJoinColumnBidirectionalRefIngEntity owner) { + this.id = id; + this.data = data; + this.owner = owner; + } - public DoubleListJoinColumnBidirectionalRefEdEntity1(String data, DoubleListJoinColumnBidirectionalRefIngEntity owner) { - this.data = data; - this.owner = owner; - } + public DoubleListJoinColumnBidirectionalRefEdEntity1( + String data, + DoubleListJoinColumnBidirectionalRefIngEntity owner) { + this.data = data; + this.owner = owner; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public DoubleListJoinColumnBidirectionalRefIngEntity getOwner() { - return owner; - } + public DoubleListJoinColumnBidirectionalRefIngEntity getOwner() { + return owner; + } - public void setOwner(DoubleListJoinColumnBidirectionalRefIngEntity owner) { - this.owner = owner; - } + public void setOwner(DoubleListJoinColumnBidirectionalRefIngEntity owner) { + this.owner = owner; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof DoubleListJoinColumnBidirectionalRefEdEntity1)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof DoubleListJoinColumnBidirectionalRefEdEntity1) ) { + return false; + } - DoubleListJoinColumnBidirectionalRefEdEntity1 that = (DoubleListJoinColumnBidirectionalRefEdEntity1) o; + DoubleListJoinColumnBidirectionalRefEdEntity1 that = (DoubleListJoinColumnBidirectionalRefEdEntity1) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - //noinspection RedundantIfStatement - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + //noinspection RedundantIfStatement + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "DoubleListJoinColumnBidirectionalRefIngEntity1(id = " + id + ", data = " + data + ")"; - } + public String toString() { + return "DoubleListJoinColumnBidirectionalRefIngEntity1(id = " + id + ", data = " + data + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/DoubleListJoinColumnBidirectionalRefEdEntity2.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/DoubleListJoinColumnBidirectionalRefEdEntity2.java index df19877308..8d2103dbe1 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/DoubleListJoinColumnBidirectionalRefEdEntity2.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/DoubleListJoinColumnBidirectionalRefEdEntity2.java @@ -1,4 +1,5 @@ package org.hibernate.envers.test.entities.onetomany.detached; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; @@ -11,80 +12,95 @@ import org.hibernate.envers.Audited; /** * Entity for {@link org.hibernate.envers.test.integration.onetomany.detached.DoubleJoinColumnBidirectionalList} test. * Owned side of the second relation. + * * @author Adam Warski (adam at warski dot org) */ @Entity @Table(name = "DoubleJoinColBiRefEd2") @Audited public class DoubleListJoinColumnBidirectionalRefEdEntity2 { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - private String data; + private String data; - @ManyToOne - @JoinColumn(name = "some_join_column_2", insertable = false, updatable = false) - private DoubleListJoinColumnBidirectionalRefIngEntity owner; + @ManyToOne + @JoinColumn(name = "some_join_column_2", insertable = false, updatable = false) + private DoubleListJoinColumnBidirectionalRefIngEntity owner; - public DoubleListJoinColumnBidirectionalRefEdEntity2() { } + public DoubleListJoinColumnBidirectionalRefEdEntity2() { + } - public DoubleListJoinColumnBidirectionalRefEdEntity2(Integer id, String data, DoubleListJoinColumnBidirectionalRefIngEntity owner) { - this.id = id; - this.data = data; - this.owner = owner; - } + public DoubleListJoinColumnBidirectionalRefEdEntity2( + Integer id, + String data, + DoubleListJoinColumnBidirectionalRefIngEntity owner) { + this.id = id; + this.data = data; + this.owner = owner; + } - public DoubleListJoinColumnBidirectionalRefEdEntity2(String data, DoubleListJoinColumnBidirectionalRefIngEntity owner) { - this.data = data; - this.owner = owner; - } + public DoubleListJoinColumnBidirectionalRefEdEntity2( + String data, + DoubleListJoinColumnBidirectionalRefIngEntity owner) { + this.data = data; + this.owner = owner; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public DoubleListJoinColumnBidirectionalRefIngEntity getOwner() { - return owner; - } + public DoubleListJoinColumnBidirectionalRefIngEntity getOwner() { + return owner; + } - public void setOwner(DoubleListJoinColumnBidirectionalRefIngEntity owner) { - this.owner = owner; - } + public void setOwner(DoubleListJoinColumnBidirectionalRefIngEntity owner) { + this.owner = owner; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof DoubleListJoinColumnBidirectionalRefEdEntity2)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof DoubleListJoinColumnBidirectionalRefEdEntity2) ) { + return false; + } - DoubleListJoinColumnBidirectionalRefEdEntity2 that = (DoubleListJoinColumnBidirectionalRefEdEntity2) o; + DoubleListJoinColumnBidirectionalRefEdEntity2 that = (DoubleListJoinColumnBidirectionalRefEdEntity2) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - //noinspection RedundantIfStatement - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + //noinspection RedundantIfStatement + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "DoubleListJoinColumnBidirectionalRefIngEntity2(id = " + id + ", data = " + data + ")"; - } + public String toString() { + return "DoubleListJoinColumnBidirectionalRefIngEntity2(id = " + id + ", data = " + data + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/DoubleListJoinColumnBidirectionalRefIngEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/DoubleListJoinColumnBidirectionalRefIngEntity.java index 89a8682e84..9d787f299d 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/DoubleListJoinColumnBidirectionalRefIngEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/DoubleListJoinColumnBidirectionalRefIngEntity.java @@ -1,12 +1,13 @@ package org.hibernate.envers.test.entities.onetomany.detached; -import java.util.ArrayList; -import java.util.List; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.OneToMany; import javax.persistence.Table; +import java.util.ArrayList; +import java.util.List; import org.hibernate.envers.AuditMappedBy; import org.hibernate.envers.Audited; @@ -14,92 +15,102 @@ import org.hibernate.envers.Audited; /** * Entity for {@link org.hibernate.envers.test.integration.onetomany.detached.DoubleJoinColumnBidirectionalList} test. * Owning side of the relations. + * * @author Adam Warski (adam at warski dot org) */ @Entity @Table(name = "DoubleJoinColBiRefIng") @Audited public class DoubleListJoinColumnBidirectionalRefIngEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - private String data; + private String data; - @OneToMany - @JoinColumn(name = "some_join_column_1") - @AuditMappedBy(mappedBy = "owner") - private List references1 = new ArrayList(); + @OneToMany + @JoinColumn(name = "some_join_column_1") + @AuditMappedBy(mappedBy = "owner") + private List references1 = new ArrayList(); - @OneToMany - @JoinColumn(name = "some_join_column_2") - @AuditMappedBy(mappedBy = "owner") - private List references2 = new ArrayList(); + @OneToMany + @JoinColumn(name = "some_join_column_2") + @AuditMappedBy(mappedBy = "owner") + private List references2 = new ArrayList(); - public DoubleListJoinColumnBidirectionalRefIngEntity() { } + public DoubleListJoinColumnBidirectionalRefIngEntity() { + } - public DoubleListJoinColumnBidirectionalRefIngEntity(Integer id, String data) { - this.id = id; - this.data = data; - } + public DoubleListJoinColumnBidirectionalRefIngEntity(Integer id, String data) { + this.id = id; + this.data = data; + } - public DoubleListJoinColumnBidirectionalRefIngEntity(String data) { - this(null, data); - } + public DoubleListJoinColumnBidirectionalRefIngEntity(String data) { + this( null, data ); + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public List getReferences1() { - return references1; - } + public List getReferences1() { + return references1; + } - public void setReferences1(List references1) { - this.references1 = references1; - } + public void setReferences1(List references1) { + this.references1 = references1; + } - public List getReferences2() { - return references2; - } + public List getReferences2() { + return references2; + } - public void setReferences2(List references2) { - this.references2 = references2; - } + public void setReferences2(List references2) { + this.references2 = references2; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof DoubleListJoinColumnBidirectionalRefIngEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof DoubleListJoinColumnBidirectionalRefIngEntity) ) { + return false; + } - DoubleListJoinColumnBidirectionalRefIngEntity that = (DoubleListJoinColumnBidirectionalRefIngEntity) o; + DoubleListJoinColumnBidirectionalRefIngEntity that = (DoubleListJoinColumnBidirectionalRefIngEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - //noinspection RedundantIfStatement - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + //noinspection RedundantIfStatement + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "DoubleListJoinColumnBidirectionalRefIngEntity(id = " + id + ", data = " + data + ")"; - } + public String toString() { + return "DoubleListJoinColumnBidirectionalRefIngEntity(id = " + id + ", data = " + data + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/DoubleSetRefCollEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/DoubleSetRefCollEntity.java index bdb30bccbd..4f2290cf2a 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/DoubleSetRefCollEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/DoubleSetRefCollEntity.java @@ -22,101 +22,111 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.onetomany.detached; -import java.util.Set; + import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.JoinTable; import javax.persistence.OneToMany; +import java.util.Set; import org.hibernate.envers.Audited; import org.hibernate.envers.test.entities.StrTestEntity; /** * Set collection of references entity + * * @author Adam Warski (adam at warski dot org) */ @Entity public class DoubleSetRefCollEntity { - @Id - private Integer id; + @Id + private Integer id; - @Audited - private String data; + @Audited + private String data; - @Audited - @OneToMany - @JoinTable(name = "DOUBLE_STR_1") - private Set collection; + @Audited + @OneToMany + @JoinTable(name = "DOUBLE_STR_1") + private Set collection; - @Audited - @OneToMany - @JoinTable(name = "DOUBLE_STR_2") - private Set collection2; + @Audited + @OneToMany + @JoinTable(name = "DOUBLE_STR_2") + private Set collection2; - public DoubleSetRefCollEntity() { - } + public DoubleSetRefCollEntity() { + } - public DoubleSetRefCollEntity(Integer id, String data) { - this.id = id; - this.data = data; - } + public DoubleSetRefCollEntity(Integer id, String data) { + this.id = id; + this.data = data; + } - public DoubleSetRefCollEntity(String data) { - this.data = data; - } + public DoubleSetRefCollEntity(String data) { + this.data = data; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public Set getCollection() { - return collection; - } + public Set getCollection() { + return collection; + } - public void setCollection(Set collection) { - this.collection = collection; - } + public void setCollection(Set collection) { + this.collection = collection; + } - public Set getCollection2() { - return collection2; - } + public Set getCollection2() { + return collection2; + } - public void setCollection2(Set collection2) { - this.collection2 = collection2; - } + public void setCollection2(Set collection2) { + this.collection2 = collection2; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof DoubleSetRefCollEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof DoubleSetRefCollEntity) ) { + return false; + } - DoubleSetRefCollEntity that = (DoubleSetRefCollEntity) o; + DoubleSetRefCollEntity that = (DoubleSetRefCollEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "DoubleSetRefEdEntity(id = " + id + ", data = " + data + ")"; - } + public String toString() { + return "DoubleSetRefEdEntity(id = " + id + ", data = " + data + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/IndexedListJoinColumnBidirectionalRefEdEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/IndexedListJoinColumnBidirectionalRefEdEntity.java index b53e4056a8..57a6fd3a80 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/IndexedListJoinColumnBidirectionalRefEdEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/IndexedListJoinColumnBidirectionalRefEdEntity.java @@ -1,4 +1,5 @@ package org.hibernate.envers.test.entities.onetomany.detached; + import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -12,91 +13,106 @@ import org.hibernate.envers.Audited; /** * Entity for {@link org.hibernate.envers.test.integration.onetomany.detached.IndexedJoinColumnBidirectionalList} test. * Owned side of the relation. + * * @author Adam Warski (adam at warski dot org) */ @Entity @Table(name = "IdxListJoinColBiRefEd") @Audited public class IndexedListJoinColumnBidirectionalRefEdEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - private String data; + private String data; - @Column(name = "indexed_index", insertable = false, updatable = false) - private Integer position; + @Column(name = "indexed_index", insertable = false, updatable = false) + private Integer position; - @ManyToOne - @JoinColumn(name = "indexed_join_column", insertable = false, updatable = false) - private IndexedListJoinColumnBidirectionalRefIngEntity owner; + @ManyToOne + @JoinColumn(name = "indexed_join_column", insertable = false, updatable = false) + private IndexedListJoinColumnBidirectionalRefIngEntity owner; - public IndexedListJoinColumnBidirectionalRefEdEntity() { } + public IndexedListJoinColumnBidirectionalRefEdEntity() { + } - public IndexedListJoinColumnBidirectionalRefEdEntity(Integer id, String data, IndexedListJoinColumnBidirectionalRefIngEntity owner) { - this.id = id; - this.data = data; - this.owner = owner; - } + public IndexedListJoinColumnBidirectionalRefEdEntity( + Integer id, + String data, + IndexedListJoinColumnBidirectionalRefIngEntity owner) { + this.id = id; + this.data = data; + this.owner = owner; + } - public IndexedListJoinColumnBidirectionalRefEdEntity(String data, IndexedListJoinColumnBidirectionalRefIngEntity owner) { - this.data = data; - this.owner = owner; - } + public IndexedListJoinColumnBidirectionalRefEdEntity( + String data, + IndexedListJoinColumnBidirectionalRefIngEntity owner) { + this.data = data; + this.owner = owner; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public IndexedListJoinColumnBidirectionalRefIngEntity getOwner() { - return owner; - } + public IndexedListJoinColumnBidirectionalRefIngEntity getOwner() { + return owner; + } - public void setOwner(IndexedListJoinColumnBidirectionalRefIngEntity owner) { - this.owner = owner; - } + public void setOwner(IndexedListJoinColumnBidirectionalRefIngEntity owner) { + this.owner = owner; + } - public Integer getPosition() { - return position; - } + public Integer getPosition() { + return position; + } - public void setPosition(Integer position) { - this.position = position; - } + public void setPosition(Integer position) { + this.position = position; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof IndexedListJoinColumnBidirectionalRefEdEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof IndexedListJoinColumnBidirectionalRefEdEntity) ) { + return false; + } - IndexedListJoinColumnBidirectionalRefEdEntity that = (IndexedListJoinColumnBidirectionalRefEdEntity) o; + IndexedListJoinColumnBidirectionalRefEdEntity that = (IndexedListJoinColumnBidirectionalRefEdEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - //noinspection RedundantIfStatement - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + //noinspection RedundantIfStatement + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "IndexedListJoinColumnBidirectionalRefEdEntity(id = " + id + ", data = " + data + ")"; - } + public String toString() { + return "IndexedListJoinColumnBidirectionalRefEdEntity(id = " + id + ", data = " + data + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/IndexedListJoinColumnBidirectionalRefIngEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/IndexedListJoinColumnBidirectionalRefIngEntity.java index df5e1869ff..712838b824 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/IndexedListJoinColumnBidirectionalRefIngEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/IndexedListJoinColumnBidirectionalRefIngEntity.java @@ -1,13 +1,14 @@ package org.hibernate.envers.test.entities.onetomany.detached; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.OneToMany; import javax.persistence.Table; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import org.hibernate.annotations.IndexColumn; import org.hibernate.envers.AuditMappedBy; @@ -16,82 +17,97 @@ import org.hibernate.envers.Audited; /** * Entity for {@link org.hibernate.envers.test.integration.onetomany.detached.IndexedJoinColumnBidirectionalList} test. * Owning side of the relation. + * * @author Adam Warski (adam at warski dot org) */ @Entity @Table(name = "IdxListJoinColBiRefIng") @Audited public class IndexedListJoinColumnBidirectionalRefIngEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - private String data; + private String data; - @OneToMany - @JoinColumn(name = "indexed_join_column") - @IndexColumn(name = "indexed_index") - @AuditMappedBy(mappedBy = "owner", positionMappedBy = "position") - private List references; + @OneToMany + @JoinColumn(name = "indexed_join_column") + @IndexColumn(name = "indexed_index") + @AuditMappedBy(mappedBy = "owner", positionMappedBy = "position") + private List references; - public IndexedListJoinColumnBidirectionalRefIngEntity() { } + public IndexedListJoinColumnBidirectionalRefIngEntity() { + } - public IndexedListJoinColumnBidirectionalRefIngEntity(Integer id, String data, IndexedListJoinColumnBidirectionalRefEdEntity... references) { - this.id = id; - this.data = data; - this.references = new ArrayList(); - this.references.addAll(Arrays.asList(references)); - } + public IndexedListJoinColumnBidirectionalRefIngEntity( + Integer id, + String data, + IndexedListJoinColumnBidirectionalRefEdEntity... references) { + this.id = id; + this.data = data; + this.references = new ArrayList(); + this.references.addAll( Arrays.asList( references ) ); + } - public IndexedListJoinColumnBidirectionalRefIngEntity(String data, IndexedListJoinColumnBidirectionalRefEdEntity... references) { - this(null, data, references); - } + public IndexedListJoinColumnBidirectionalRefIngEntity( + String data, + IndexedListJoinColumnBidirectionalRefEdEntity... references) { + this( null, data, references ); + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public List getReferences() { - return references; - } + public List getReferences() { + return references; + } - public void setReferences(List references) { - this.references = references; - } + public void setReferences(List references) { + this.references = references; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof IndexedListJoinColumnBidirectionalRefIngEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof IndexedListJoinColumnBidirectionalRefIngEntity) ) { + return false; + } - IndexedListJoinColumnBidirectionalRefIngEntity that = (IndexedListJoinColumnBidirectionalRefIngEntity) o; + IndexedListJoinColumnBidirectionalRefIngEntity that = (IndexedListJoinColumnBidirectionalRefIngEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - //noinspection RedundantIfStatement - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + //noinspection RedundantIfStatement + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "IndexedListJoinColumnBidirectionalRefIngEntity(id = " + id + ", data = " + data + ")"; - } + public String toString() { + return "IndexedListJoinColumnBidirectionalRefIngEntity(id = " + id + ", data = " + data + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/ListJoinColumnBidirectionalInheritanceRefEdChildEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/ListJoinColumnBidirectionalInheritanceRefEdChildEntity.java index 3ffa9004be..7d315ac867 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/ListJoinColumnBidirectionalInheritanceRefEdChildEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/ListJoinColumnBidirectionalInheritanceRefEdChildEntity.java @@ -1,4 +1,5 @@ package org.hibernate.envers.test.entities.onetomany.detached; + import javax.persistence.DiscriminatorValue; import javax.persistence.Entity; import javax.persistence.Table; @@ -8,58 +9,76 @@ import org.hibernate.envers.Audited; /** * Entity for {@link org.hibernate.envers.test.integration.onetomany.detached.JoinColumnBidirectionalListWithInheritance} test. * Owned child side of the relation. + * * @author Adam Warski (adam at warski dot org) */ @Entity @Table(name = "ListJoinColBiInhRefEdChild") @DiscriminatorValue("2") @Audited -public class ListJoinColumnBidirectionalInheritanceRefEdChildEntity extends ListJoinColumnBidirectionalInheritanceRefEdParentEntity { - private String childData; +public class ListJoinColumnBidirectionalInheritanceRefEdChildEntity + extends ListJoinColumnBidirectionalInheritanceRefEdParentEntity { + private String childData; - public ListJoinColumnBidirectionalInheritanceRefEdChildEntity() { } + public ListJoinColumnBidirectionalInheritanceRefEdChildEntity() { + } - public ListJoinColumnBidirectionalInheritanceRefEdChildEntity(Integer id, String parentData, ListJoinColumnBidirectionalInheritanceRefIngEntity owner, String childData) { - super(id, parentData, owner); - this.childData = childData; - } + public ListJoinColumnBidirectionalInheritanceRefEdChildEntity( + Integer id, + String parentData, + ListJoinColumnBidirectionalInheritanceRefIngEntity owner, + String childData) { + super( id, parentData, owner ); + this.childData = childData; + } - public ListJoinColumnBidirectionalInheritanceRefEdChildEntity(String parentData, ListJoinColumnBidirectionalInheritanceRefIngEntity owner, String childData) { - super(parentData, owner); - this.childData = childData; - } + public ListJoinColumnBidirectionalInheritanceRefEdChildEntity( + String parentData, + ListJoinColumnBidirectionalInheritanceRefIngEntity owner, + String childData) { + super( parentData, owner ); + this.childData = childData; + } - public String getChildData() { - return childData; - } + public String getChildData() { + return childData; + } - public void setChildData(String childData) { - this.childData = childData; - } + public void setChildData(String childData) { + this.childData = childData; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - if (!super.equals(o)) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } + if ( !super.equals( o ) ) { + return false; + } - ListJoinColumnBidirectionalInheritanceRefEdChildEntity that = (ListJoinColumnBidirectionalInheritanceRefEdChildEntity) o; + ListJoinColumnBidirectionalInheritanceRefEdChildEntity that = (ListJoinColumnBidirectionalInheritanceRefEdChildEntity) o; - //noinspection RedundantIfStatement - if (childData != null ? !childData.equals(that.childData) : that.childData != null) return false; + //noinspection RedundantIfStatement + if ( childData != null ? !childData.equals( that.childData ) : that.childData != null ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - int result = super.hashCode(); - result = 31 * result + (childData != null ? childData.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (childData != null ? childData.hashCode() : 0); + return result; + } - public String toString() { - return "ListJoinColumnBidirectionalInheritanceRefEdChildEntity(id = " + getId() + - ", parentData = " + getParentData() + ", childData = " + childData + ")"; - } + public String toString() { + return "ListJoinColumnBidirectionalInheritanceRefEdChildEntity(id = " + getId() + + ", parentData = " + getParentData() + ", childData = " + childData + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/ListJoinColumnBidirectionalInheritanceRefEdParentEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/ListJoinColumnBidirectionalInheritanceRefEdParentEntity.java index 801f8648a9..29698315a8 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/ListJoinColumnBidirectionalInheritanceRefEdParentEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/ListJoinColumnBidirectionalInheritanceRefEdParentEntity.java @@ -1,4 +1,5 @@ package org.hibernate.envers.test.entities.onetomany.detached; + import javax.persistence.DiscriminatorColumn; import javax.persistence.DiscriminatorType; import javax.persistence.DiscriminatorValue; @@ -16,6 +17,7 @@ import org.hibernate.envers.Audited; /** * Entity for {@link org.hibernate.envers.test.integration.onetomany.detached.JoinColumnBidirectionalListWithInheritance} test. * Owned parent side of the relation. + * * @author Adam Warski (adam at warski dot org) */ @Entity @@ -25,74 +27,88 @@ import org.hibernate.envers.Audited; @DiscriminatorValue("1") @Audited public class ListJoinColumnBidirectionalInheritanceRefEdParentEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - private String parentData; + private String parentData; - @ManyToOne - @JoinColumn(name = "some_join_column", insertable = false, updatable = false) - private ListJoinColumnBidirectionalInheritanceRefIngEntity owner; + @ManyToOne + @JoinColumn(name = "some_join_column", insertable = false, updatable = false) + private ListJoinColumnBidirectionalInheritanceRefIngEntity owner; - public ListJoinColumnBidirectionalInheritanceRefEdParentEntity() { } + public ListJoinColumnBidirectionalInheritanceRefEdParentEntity() { + } - public ListJoinColumnBidirectionalInheritanceRefEdParentEntity(Integer id, String parentData, ListJoinColumnBidirectionalInheritanceRefIngEntity owner) { - this.id = id; - this.parentData = parentData; - this.owner = owner; - } + public ListJoinColumnBidirectionalInheritanceRefEdParentEntity( + Integer id, + String parentData, + ListJoinColumnBidirectionalInheritanceRefIngEntity owner) { + this.id = id; + this.parentData = parentData; + this.owner = owner; + } - public ListJoinColumnBidirectionalInheritanceRefEdParentEntity(String parentData, ListJoinColumnBidirectionalInheritanceRefIngEntity owner) { - this.parentData = parentData; - this.owner = owner; - } + public ListJoinColumnBidirectionalInheritanceRefEdParentEntity( + String parentData, + ListJoinColumnBidirectionalInheritanceRefIngEntity owner) { + this.parentData = parentData; + this.owner = owner; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public ListJoinColumnBidirectionalInheritanceRefIngEntity getOwner() { - return owner; - } + public ListJoinColumnBidirectionalInheritanceRefIngEntity getOwner() { + return owner; + } - public void setOwner(ListJoinColumnBidirectionalInheritanceRefIngEntity owner) { - this.owner = owner; - } + public void setOwner(ListJoinColumnBidirectionalInheritanceRefIngEntity owner) { + this.owner = owner; + } - public String getParentData() { - return parentData; - } + public String getParentData() { + return parentData; + } - public void setParentData(String parentData) { - this.parentData = parentData; - } + public void setParentData(String parentData) { + this.parentData = parentData; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ListJoinColumnBidirectionalInheritanceRefEdParentEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ListJoinColumnBidirectionalInheritanceRefEdParentEntity) ) { + return false; + } - ListJoinColumnBidirectionalInheritanceRefEdParentEntity that = (ListJoinColumnBidirectionalInheritanceRefEdParentEntity) o; + ListJoinColumnBidirectionalInheritanceRefEdParentEntity that = (ListJoinColumnBidirectionalInheritanceRefEdParentEntity) o; - if (parentData != null ? !parentData.equals(that.parentData) : that.parentData != null) return false; - //noinspection RedundantIfStatement - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( parentData != null ? !parentData.equals( that.parentData ) : that.parentData != null ) { + return false; + } + //noinspection RedundantIfStatement + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (parentData != null ? parentData.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (parentData != null ? parentData.hashCode() : 0); + return result; + } - public String toString() { - return "ListJoinColumnBidirectionalInheritanceRefEdParentEntity(id = " + id + ", parentData = " + parentData + ")"; - } + public String toString() { + return "ListJoinColumnBidirectionalInheritanceRefEdParentEntity(id = " + id + ", parentData = " + parentData + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/ListJoinColumnBidirectionalInheritanceRefIngEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/ListJoinColumnBidirectionalInheritanceRefIngEntity.java index ede9812a4d..04a02eebd3 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/ListJoinColumnBidirectionalInheritanceRefIngEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/ListJoinColumnBidirectionalInheritanceRefIngEntity.java @@ -1,13 +1,14 @@ package org.hibernate.envers.test.entities.onetomany.detached; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.OneToMany; import javax.persistence.Table; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import org.hibernate.envers.AuditMappedBy; import org.hibernate.envers.Audited; @@ -15,81 +16,96 @@ import org.hibernate.envers.Audited; /** * Entity for {@link org.hibernate.envers.test.integration.onetomany.detached.JoinColumnBidirectionalListWithInheritance} test. * Owning side of the relation. + * * @author Adam Warski (adam at warski dot org) */ @Entity @Table(name = "ListJoinColBiInhRefIng") @Audited public class ListJoinColumnBidirectionalInheritanceRefIngEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - private String data; + private String data; - @OneToMany - @JoinColumn(name = "some_join_column") - @AuditMappedBy(mappedBy = "owner") - private List references; + @OneToMany + @JoinColumn(name = "some_join_column") + @AuditMappedBy(mappedBy = "owner") + private List references; - public ListJoinColumnBidirectionalInheritanceRefIngEntity() { } + public ListJoinColumnBidirectionalInheritanceRefIngEntity() { + } - public ListJoinColumnBidirectionalInheritanceRefIngEntity(Integer id, String data, ListJoinColumnBidirectionalInheritanceRefEdParentEntity... references) { - this.id = id; - this.data = data; - this.references = new ArrayList(); - this.references.addAll(Arrays.asList(references)); - } + public ListJoinColumnBidirectionalInheritanceRefIngEntity( + Integer id, + String data, + ListJoinColumnBidirectionalInheritanceRefEdParentEntity... references) { + this.id = id; + this.data = data; + this.references = new ArrayList(); + this.references.addAll( Arrays.asList( references ) ); + } - public ListJoinColumnBidirectionalInheritanceRefIngEntity(String data, ListJoinColumnBidirectionalInheritanceRefEdParentEntity... references) { - this(null, data, references); - } + public ListJoinColumnBidirectionalInheritanceRefIngEntity( + String data, + ListJoinColumnBidirectionalInheritanceRefEdParentEntity... references) { + this( null, data, references ); + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public List getReferences() { - return references; - } + public List getReferences() { + return references; + } - public void setReferences(List references) { - this.references = references; - } + public void setReferences(List references) { + this.references = references; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ListJoinColumnBidirectionalInheritanceRefIngEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ListJoinColumnBidirectionalInheritanceRefIngEntity) ) { + return false; + } - ListJoinColumnBidirectionalInheritanceRefIngEntity that = (ListJoinColumnBidirectionalInheritanceRefIngEntity) o; + ListJoinColumnBidirectionalInheritanceRefIngEntity that = (ListJoinColumnBidirectionalInheritanceRefIngEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - //noinspection RedundantIfStatement - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + //noinspection RedundantIfStatement + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "ListJoinColumnBidirectionalInheritanceRefIngEntity(id = " + id + ", data = " + data + ")"; - } + public String toString() { + return "ListJoinColumnBidirectionalInheritanceRefIngEntity(id = " + id + ", data = " + data + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/ListJoinColumnBidirectionalRefEdEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/ListJoinColumnBidirectionalRefEdEntity.java index eb41598caa..e5abbbb177 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/ListJoinColumnBidirectionalRefEdEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/ListJoinColumnBidirectionalRefEdEntity.java @@ -1,4 +1,5 @@ package org.hibernate.envers.test.entities.onetomany.detached; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; @@ -11,80 +12,93 @@ import org.hibernate.envers.Audited; /** * Entity for {@link org.hibernate.envers.test.integration.onetomany.detached.JoinColumnBidirectionalList} test. * Owned side of the relation. + * * @author Adam Warski (adam at warski dot org) */ @Entity @Table(name = "ListJoinColBiRefEd") @Audited public class ListJoinColumnBidirectionalRefEdEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - private String data; + private String data; - @ManyToOne - @JoinColumn(name = "some_join_column", insertable = false, updatable = false) - private ListJoinColumnBidirectionalRefIngEntity owner; + @ManyToOne + @JoinColumn(name = "some_join_column", insertable = false, updatable = false) + private ListJoinColumnBidirectionalRefIngEntity owner; - public ListJoinColumnBidirectionalRefEdEntity() { } + public ListJoinColumnBidirectionalRefEdEntity() { + } - public ListJoinColumnBidirectionalRefEdEntity(Integer id, String data, ListJoinColumnBidirectionalRefIngEntity owner) { - this.id = id; - this.data = data; - this.owner = owner; - } + public ListJoinColumnBidirectionalRefEdEntity( + Integer id, + String data, + ListJoinColumnBidirectionalRefIngEntity owner) { + this.id = id; + this.data = data; + this.owner = owner; + } - public ListJoinColumnBidirectionalRefEdEntity(String data, ListJoinColumnBidirectionalRefIngEntity owner) { - this.data = data; - this.owner = owner; - } + public ListJoinColumnBidirectionalRefEdEntity(String data, ListJoinColumnBidirectionalRefIngEntity owner) { + this.data = data; + this.owner = owner; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public ListJoinColumnBidirectionalRefIngEntity getOwner() { - return owner; - } + public ListJoinColumnBidirectionalRefIngEntity getOwner() { + return owner; + } - public void setOwner(ListJoinColumnBidirectionalRefIngEntity owner) { - this.owner = owner; - } + public void setOwner(ListJoinColumnBidirectionalRefIngEntity owner) { + this.owner = owner; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ListJoinColumnBidirectionalRefEdEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ListJoinColumnBidirectionalRefEdEntity) ) { + return false; + } - ListJoinColumnBidirectionalRefEdEntity that = (ListJoinColumnBidirectionalRefEdEntity) o; + ListJoinColumnBidirectionalRefEdEntity that = (ListJoinColumnBidirectionalRefEdEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - //noinspection RedundantIfStatement - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + //noinspection RedundantIfStatement + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "ListJoinColumnBidirectionalRefEdEntity(id = " + id + ", data = " + data + ")"; - } + public String toString() { + return "ListJoinColumnBidirectionalRefEdEntity(id = " + id + ", data = " + data + ")"; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/ListJoinColumnBidirectionalRefIngEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/ListJoinColumnBidirectionalRefIngEntity.java index f99a9900b0..dbd393ace4 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/ListJoinColumnBidirectionalRefIngEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/ListJoinColumnBidirectionalRefIngEntity.java @@ -1,13 +1,14 @@ package org.hibernate.envers.test.entities.onetomany.detached; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.OneToMany; import javax.persistence.Table; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import org.hibernate.envers.AuditMappedBy; import org.hibernate.envers.Audited; @@ -15,81 +16,94 @@ import org.hibernate.envers.Audited; /** * Entity for {@link org.hibernate.envers.test.integration.onetomany.detached.JoinColumnBidirectionalList} test. * Owning side of the relation. + * * @author Adam Warski (adam at warski dot org) */ @Entity @Table(name = "ListJoinColBiRefIng") @Audited public class ListJoinColumnBidirectionalRefIngEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - private String data; + private String data; - @OneToMany - @JoinColumn(name = "some_join_column") - @AuditMappedBy(mappedBy = "owner") - private List references; + @OneToMany + @JoinColumn(name = "some_join_column") + @AuditMappedBy(mappedBy = "owner") + private List references; - public ListJoinColumnBidirectionalRefIngEntity() { } + public ListJoinColumnBidirectionalRefIngEntity() { + } - public ListJoinColumnBidirectionalRefIngEntity(Integer id, String data, ListJoinColumnBidirectionalRefEdEntity... references) { - this.id = id; - this.data = data; - this.references = new ArrayList(); - this.references.addAll(Arrays.asList(references)); - } + public ListJoinColumnBidirectionalRefIngEntity( + Integer id, + String data, + ListJoinColumnBidirectionalRefEdEntity... references) { + this.id = id; + this.data = data; + this.references = new ArrayList(); + this.references.addAll( Arrays.asList( references ) ); + } - public ListJoinColumnBidirectionalRefIngEntity(String data, ListJoinColumnBidirectionalRefEdEntity... references) { - this(null, data, references); - } + public ListJoinColumnBidirectionalRefIngEntity(String data, ListJoinColumnBidirectionalRefEdEntity... references) { + this( null, data, references ); + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public List getReferences() { - return references; - } + public List getReferences() { + return references; + } - public void setReferences(List references) { - this.references = references; - } + public void setReferences(List references) { + this.references = references; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ListJoinColumnBidirectionalRefIngEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ListJoinColumnBidirectionalRefIngEntity) ) { + return false; + } - ListJoinColumnBidirectionalRefIngEntity that = (ListJoinColumnBidirectionalRefIngEntity) o; + ListJoinColumnBidirectionalRefIngEntity that = (ListJoinColumnBidirectionalRefIngEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - //noinspection RedundantIfStatement - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + //noinspection RedundantIfStatement + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "ListJoinColumnBidirectionalRefIngEntity(id = " + id + ", data = " + data + ")"; - } + public String toString() { + return "ListJoinColumnBidirectionalRefIngEntity(id = " + id + ", data = " + data + ")"; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/ListRefCollEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/ListRefCollEntity.java index dade398587..3ca3999d26 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/ListRefCollEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/ListRefCollEntity.java @@ -22,86 +22,96 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.onetomany.detached; -import java.util.List; + import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.OneToMany; +import java.util.List; import org.hibernate.envers.Audited; import org.hibernate.envers.test.entities.StrTestEntity; /** * Set collection of references entity + * * @author Adam Warski (adam at warski dot org) */ @Entity public class ListRefCollEntity { - @Id - private Integer id; + @Id + private Integer id; - @Audited - private String data; + @Audited + private String data; - @Audited - @OneToMany - private List collection; + @Audited + @OneToMany + private List collection; - public ListRefCollEntity() { - } + public ListRefCollEntity() { + } - public ListRefCollEntity(Integer id, String data) { - this.id = id; - this.data = data; - } + public ListRefCollEntity(Integer id, String data) { + this.id = id; + this.data = data; + } - public ListRefCollEntity(String data) { - this.data = data; - } + public ListRefCollEntity(String data) { + this.data = data; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public List getCollection() { - return collection; - } + public List getCollection() { + return collection; + } - public void setCollection(List collection) { - this.collection = collection; - } + public void setCollection(List collection) { + this.collection = collection; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ListRefCollEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ListRefCollEntity) ) { + return false; + } - ListRefCollEntity that = (ListRefCollEntity) o; + ListRefCollEntity that = (ListRefCollEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "SetRefEdEntity(id = " + id + ", data = " + data + ")"; - } + public String toString() { + return "SetRefEdEntity(id = " + id + ", data = " + data + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/SetJoinColumnRefCollEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/SetJoinColumnRefCollEntity.java index 3c3ff051b2..171a245446 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/SetJoinColumnRefCollEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/SetJoinColumnRefCollEntity.java @@ -22,12 +22,13 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.onetomany.detached; -import java.util.Set; + import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.OneToMany; import javax.persistence.Table; +import java.util.Set; import org.hibernate.envers.AuditJoinTable; import org.hibernate.envers.Audited; @@ -35,79 +36,88 @@ import org.hibernate.envers.test.entities.StrTestEntity; /** * A detached relation to another entity, with a @OneToMany+@JoinColumn mapping. + * * @author Adam Warski (adam at warski dot org) */ @Entity @Table(name = "SetJoinColRefColl") public class SetJoinColumnRefCollEntity { - @Id - private Integer id; + @Id + private Integer id; - @Audited - private String data; + @Audited + private String data; - @Audited - @OneToMany - @JoinColumn(name = "SJCR_ID") - @AuditJoinTable(name = "SetJoinColRefColl_StrTest_AUD") - private Set collection; + @Audited + @OneToMany + @JoinColumn(name = "SJCR_ID") + @AuditJoinTable(name = "SetJoinColRefColl_StrTest_AUD") + private Set collection; - public SetJoinColumnRefCollEntity() { - } + public SetJoinColumnRefCollEntity() { + } - public SetJoinColumnRefCollEntity(Integer id, String data) { - this.id = id; - this.data = data; - } + public SetJoinColumnRefCollEntity(Integer id, String data) { + this.id = id; + this.data = data; + } - public SetJoinColumnRefCollEntity(String data) { - this.data = data; - } + public SetJoinColumnRefCollEntity(String data) { + this.data = data; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public Set getCollection() { - return collection; - } + public Set getCollection() { + return collection; + } - public void setCollection(Set collection) { - this.collection = collection; - } + public void setCollection(Set collection) { + this.collection = collection; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof SetJoinColumnRefCollEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof SetJoinColumnRefCollEntity) ) { + return false; + } - SetJoinColumnRefCollEntity that = (SetJoinColumnRefCollEntity) o; + SetJoinColumnRefCollEntity that = (SetJoinColumnRefCollEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "SetJoinColumnRefCollEntity(id = " + id + ", data = " + data + ")"; - } + public String toString() { + return "SetJoinColumnRefCollEntity(id = " + id + ", data = " + data + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/SetRefCollEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/SetRefCollEntity.java index 5ae7ef49ab..17477d9c14 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/SetRefCollEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/SetRefCollEntity.java @@ -22,86 +22,96 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.onetomany.detached; -import java.util.Set; + import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.OneToMany; +import java.util.Set; import org.hibernate.envers.Audited; import org.hibernate.envers.test.entities.StrTestEntity; /** * Set collection of references entity + * * @author Adam Warski (adam at warski dot org) */ @Entity public class SetRefCollEntity { - @Id - private Integer id; + @Id + private Integer id; - @Audited - private String data; + @Audited + private String data; - @Audited - @OneToMany - private Set collection; + @Audited + @OneToMany + private Set collection; - public SetRefCollEntity() { - } + public SetRefCollEntity() { + } - public SetRefCollEntity(Integer id, String data) { - this.id = id; - this.data = data; - } + public SetRefCollEntity(Integer id, String data) { + this.id = id; + this.data = data; + } - public SetRefCollEntity(String data) { - this.data = data; - } + public SetRefCollEntity(String data) { + this.data = data; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public Set getCollection() { - return collection; - } + public Set getCollection() { + return collection; + } - public void setCollection(Set collection) { - this.collection = collection; - } + public void setCollection(Set collection) { + this.collection = collection; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof SetRefCollEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof SetRefCollEntity) ) { + return false; + } - SetRefCollEntity that = (SetRefCollEntity) o; + SetRefCollEntity that = (SetRefCollEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "SetRefEdEntity(id = " + id + ", data = " + data + ")"; - } + public String toString() { + return "SetRefEdEntity(id = " + id + ", data = " + data + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/ids/SetRefCollEntityEmbId.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/ids/SetRefCollEntityEmbId.java index 3261064e46..d96d0190ca 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/ids/SetRefCollEntityEmbId.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/ids/SetRefCollEntityEmbId.java @@ -22,11 +22,12 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.onetomany.detached.ids; -import java.util.Set; + import javax.persistence.EmbeddedId; import javax.persistence.Entity; import javax.persistence.OneToMany; import javax.persistence.Table; +import java.util.Set; import org.hibernate.envers.Audited; import org.hibernate.envers.test.entities.ids.EmbId; @@ -34,77 +35,86 @@ import org.hibernate.envers.test.entities.ids.EmbIdTestEntity; /** * Set collection of references entity + * * @author Adam Warski (adam at warski dot org) */ @Entity @Table(name = "SetRefCollEmbId") public class SetRefCollEntityEmbId { - @EmbeddedId - private EmbId id; + @EmbeddedId + private EmbId id; - @Audited - private String data; + @Audited + private String data; - @Audited - @OneToMany - private Set collection; + @Audited + @OneToMany + private Set collection; - public SetRefCollEntityEmbId() { - } + public SetRefCollEntityEmbId() { + } - public SetRefCollEntityEmbId(EmbId id, String data) { - this.id = id; - this.data = data; - } + public SetRefCollEntityEmbId(EmbId id, String data) { + this.id = id; + this.data = data; + } - public SetRefCollEntityEmbId(String data) { - this.data = data; - } + public SetRefCollEntityEmbId(String data) { + this.data = data; + } - public EmbId getId() { - return id; - } + public EmbId getId() { + return id; + } - public void setId(EmbId id) { - this.id = id; - } + public void setId(EmbId id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public Set getCollection() { - return collection; - } + public Set getCollection() { + return collection; + } - public void setCollection(Set collection) { - this.collection = collection; - } + public void setCollection(Set collection) { + this.collection = collection; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof SetRefCollEntityEmbId)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof SetRefCollEntityEmbId) ) { + return false; + } - SetRefCollEntityEmbId that = (SetRefCollEntityEmbId) o; + SetRefCollEntityEmbId that = (SetRefCollEntityEmbId) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "SetRefCollEntityEmbId(id = " + id + ", data = " + data + ")"; - } + public String toString() { + return "SetRefCollEntityEmbId(id = " + id + ", data = " + data + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/ids/SetRefCollEntityMulId.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/ids/SetRefCollEntityMulId.java index 1234647dc3..28cfc0cb03 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/ids/SetRefCollEntityMulId.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/ids/SetRefCollEntityMulId.java @@ -22,12 +22,13 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.onetomany.detached.ids; -import java.util.Set; + import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.IdClass; import javax.persistence.OneToMany; import javax.persistence.Table; +import java.util.Set; import org.hibernate.envers.Audited; import org.hibernate.envers.test.entities.ids.MulId; @@ -35,92 +36,103 @@ import org.hibernate.envers.test.entities.ids.MulIdTestEntity; /** * Set collection of references entity + * * @author Adam Warski (adam at warski dot org) */ @Entity @Table(name = "SetRefCollMulId") @IdClass(MulId.class) public class SetRefCollEntityMulId { - @Id - private Integer id1; + @Id + private Integer id1; - @Id - private Integer id2; + @Id + private Integer id2; - @Audited - private String data; + @Audited + private String data; - @Audited - @OneToMany - private Set collection; + @Audited + @OneToMany + private Set collection; - public SetRefCollEntityMulId() { - } + public SetRefCollEntityMulId() { + } - public SetRefCollEntityMulId(Integer id1, Integer id2, String data) { - this.id1 = id1; - this.id2 = id2; - this.data = data; - } + public SetRefCollEntityMulId(Integer id1, Integer id2, String data) { + this.id1 = id1; + this.id2 = id2; + this.data = data; + } - public SetRefCollEntityMulId(String data) { - this.data = data; - } + public SetRefCollEntityMulId(String data) { + this.data = data; + } - public Integer getId1() { - return id1; - } + public Integer getId1() { + return id1; + } - public void setId1(Integer id1) { - this.id1 = id1; - } + public void setId1(Integer id1) { + this.id1 = id1; + } - public Integer getId2() { - return id2; - } + public Integer getId2() { + return id2; + } - public void setId2(Integer id2) { - this.id2 = id2; - } + public void setId2(Integer id2) { + this.id2 = id2; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public Set getCollection() { - return collection; - } + public Set getCollection() { + return collection; + } - public void setCollection(Set collection) { - this.collection = collection; - } + public void setCollection(Set collection) { + this.collection = collection; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof SetRefCollEntityMulId)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof SetRefCollEntityMulId) ) { + return false; + } - SetRefCollEntityMulId that = (SetRefCollEntityMulId) o; + SetRefCollEntityMulId that = (SetRefCollEntityMulId) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id1 != null ? !id1.equals(that.id1) : that.id1 != null) return false; - if (id2 != null ? !id2.equals(that.id2) : that.id2 != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id1 != null ? !id1.equals( that.id1 ) : that.id1 != null ) { + return false; + } + if ( id2 != null ? !id2.equals( that.id2 ) : that.id2 != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id1 != null ? id1.hashCode() : 0); - result = 31 * result + (id2 != null ? id2.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id1 != null ? id1.hashCode() : 0); + result = 31 * result + (id2 != null ? id2.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "SetRefCollEntityMulId(id1 = " + id1 + ", id2 = " + id2 + ", data = " + data + ")"; - } + public String toString() { + return "SetRefCollEntityMulId(id1 = " + id1 + ", id2 = " + id2 + ", data = " + data + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/inheritance/ChildIndexedListJoinColumnBidirectionalRefIngEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/inheritance/ChildIndexedListJoinColumnBidirectionalRefIngEntity.java index 08dc43820c..43780b43df 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/inheritance/ChildIndexedListJoinColumnBidirectionalRefIngEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/inheritance/ChildIndexedListJoinColumnBidirectionalRefIngEntity.java @@ -1,4 +1,5 @@ package org.hibernate.envers.test.entities.onetomany.detached.inheritance; + import javax.persistence.Entity; import javax.persistence.Table; @@ -7,56 +8,73 @@ import org.hibernate.envers.Audited; /** * Entity for {@link org.hibernate.envers.test.integration.onetomany.detached.InheritanceIndexedJoinColumnBidirectionalList} test. * Child, owning side of the relation. + * * @author Adam Warski (adam at warski dot org) */ @Entity @Table(name = "ChildIdxJoinColBiRefIng") @Audited -public class ChildIndexedListJoinColumnBidirectionalRefIngEntity extends ParentIndexedListJoinColumnBidirectionalRefIngEntity { - private String data2; +public class ChildIndexedListJoinColumnBidirectionalRefIngEntity + extends ParentIndexedListJoinColumnBidirectionalRefIngEntity { + private String data2; - public ChildIndexedListJoinColumnBidirectionalRefIngEntity() { - } + public ChildIndexedListJoinColumnBidirectionalRefIngEntity() { + } - public ChildIndexedListJoinColumnBidirectionalRefIngEntity(Integer id, String data, String data2, ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity... references) { - super(id, data, references); - this.data2 = data2; - } + public ChildIndexedListJoinColumnBidirectionalRefIngEntity( + Integer id, + String data, + String data2, + ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity... references) { + super( id, data, references ); + this.data2 = data2; + } - public ChildIndexedListJoinColumnBidirectionalRefIngEntity(String data, String data2, ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity... references) { - super(data, references); - this.data2 = data2; - } + public ChildIndexedListJoinColumnBidirectionalRefIngEntity( + String data, + String data2, + ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity... references) { + super( data, references ); + this.data2 = data2; + } - public String getData2() { - return data2; - } + public String getData2() { + return data2; + } - public void setData2(String data2) { - this.data2 = data2; - } + public void setData2(String data2) { + this.data2 = data2; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ChildIndexedListJoinColumnBidirectionalRefIngEntity)) return false; - if (!super.equals(o)) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ChildIndexedListJoinColumnBidirectionalRefIngEntity) ) { + return false; + } + if ( !super.equals( o ) ) { + return false; + } - ChildIndexedListJoinColumnBidirectionalRefIngEntity that = (ChildIndexedListJoinColumnBidirectionalRefIngEntity) o; + ChildIndexedListJoinColumnBidirectionalRefIngEntity that = (ChildIndexedListJoinColumnBidirectionalRefIngEntity) o; - if (data2 != null ? !data2.equals(that.data2) : that.data2 != null) return false; + if ( data2 != null ? !data2.equals( that.data2 ) : that.data2 != null ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - int result = super.hashCode(); - result = 31 * result + (data2 != null ? data2.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (data2 != null ? data2.hashCode() : 0); + return result; + } - public String toString() { - return "ChildIndexedListJoinColumnBidirectionalRefIngEntity(id = " + getId() + ", data = " + getData() + ", data2 = " + data2 + ")"; - } + public String toString() { + return "ChildIndexedListJoinColumnBidirectionalRefIngEntity(id = " + getId() + ", data = " + getData() + ", data2 = " + data2 + ")"; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/inheritance/ParentIndexedListJoinColumnBidirectionalRefIngEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/inheritance/ParentIndexedListJoinColumnBidirectionalRefIngEntity.java index 6d9bbaf52d..2f37ff3986 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/inheritance/ParentIndexedListJoinColumnBidirectionalRefIngEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/inheritance/ParentIndexedListJoinColumnBidirectionalRefIngEntity.java @@ -1,7 +1,5 @@ package org.hibernate.envers.test.entities.onetomany.detached.inheritance; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; @@ -10,6 +8,9 @@ import javax.persistence.InheritanceType; import javax.persistence.JoinColumn; import javax.persistence.OneToMany; import javax.persistence.Table; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import org.hibernate.annotations.IndexColumn; import org.hibernate.envers.AuditMappedBy; @@ -18,6 +19,7 @@ import org.hibernate.envers.Audited; /** * Entity for {@link org.hibernate.envers.test.integration.onetomany.detached.InheritanceIndexedJoinColumnBidirectionalList} test. * Parent, owning side of the relation. + * * @author Adam Warski (adam at warski dot org) */ @Entity @@ -25,76 +27,90 @@ import org.hibernate.envers.Audited; @Table(name = "ParentIdxJoinColBiRefIng") @Inheritance(strategy = InheritanceType.JOINED) public abstract class ParentIndexedListJoinColumnBidirectionalRefIngEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - private String data; + private String data; - @OneToMany - @JoinColumn(name = "indexed_join_column") - @IndexColumn(name = "indexed_index") - @AuditMappedBy(mappedBy = "owner", positionMappedBy = "position") - private List references; + @OneToMany + @JoinColumn(name = "indexed_join_column") + @IndexColumn(name = "indexed_index") + @AuditMappedBy(mappedBy = "owner", positionMappedBy = "position") + private List references; - public ParentIndexedListJoinColumnBidirectionalRefIngEntity() { } + public ParentIndexedListJoinColumnBidirectionalRefIngEntity() { + } - public ParentIndexedListJoinColumnBidirectionalRefIngEntity(Integer id, String data, ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity... references) { - this.id = id; - this.data = data; - this.references = new ArrayList(); - this.references.addAll(Arrays.asList(references)); - } + public ParentIndexedListJoinColumnBidirectionalRefIngEntity( + Integer id, + String data, + ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity... references) { + this.id = id; + this.data = data; + this.references = new ArrayList(); + this.references.addAll( Arrays.asList( references ) ); + } - public ParentIndexedListJoinColumnBidirectionalRefIngEntity(String data, ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity... references) { - this(null, data, references); - } + public ParentIndexedListJoinColumnBidirectionalRefIngEntity( + String data, + ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity... references) { + this( null, data, references ); + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public List getReferences() { - return references; - } + public List getReferences() { + return references; + } - public void setReferences(List references) { - this.references = references; - } + public void setReferences(List references) { + this.references = references; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ParentIndexedListJoinColumnBidirectionalRefIngEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ParentIndexedListJoinColumnBidirectionalRefIngEntity) ) { + return false; + } - ParentIndexedListJoinColumnBidirectionalRefIngEntity that = (ParentIndexedListJoinColumnBidirectionalRefIngEntity) o; + ParentIndexedListJoinColumnBidirectionalRefIngEntity that = (ParentIndexedListJoinColumnBidirectionalRefIngEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - //noinspection RedundantIfStatement - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + //noinspection RedundantIfStatement + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "ParentIndexedListJoinColumnBidirectionalRefIngEntity(id = " + id + ", data = " + data + ")"; - } + public String toString() { + return "ParentIndexedListJoinColumnBidirectionalRefIngEntity(id = " + id + ", data = " + data + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/inheritance/ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/inheritance/ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.java index caacfedcd8..ee41f89d20 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/inheritance/ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/detached/inheritance/ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.java @@ -1,4 +1,5 @@ package org.hibernate.envers.test.entities.onetomany.detached.inheritance; + import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -12,91 +13,106 @@ import org.hibernate.envers.Audited; /** * Entity for {@link org.hibernate.envers.test.integration.onetomany.detached.InheritanceIndexedJoinColumnBidirectionalList} test. * Owned side of the relation. + * * @author Adam Warski (adam at warski dot org) */ @Entity @Table(name = "ParOwnedIdxJoinColBiRefEd") @Audited public class ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - private String data; + private String data; - @Column(name = "indexed_index", insertable = false, updatable = false) - private Integer position; + @Column(name = "indexed_index", insertable = false, updatable = false) + private Integer position; - @ManyToOne - @JoinColumn(name = "indexed_join_column", insertable = false, updatable = false) - private ParentIndexedListJoinColumnBidirectionalRefIngEntity owner; + @ManyToOne + @JoinColumn(name = "indexed_join_column", insertable = false, updatable = false) + private ParentIndexedListJoinColumnBidirectionalRefIngEntity owner; - public ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity() { } + public ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity() { + } - public ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity(Integer id, String data, ParentIndexedListJoinColumnBidirectionalRefIngEntity owner) { - this.id = id; - this.data = data; - this.owner = owner; - } + public ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity( + Integer id, + String data, + ParentIndexedListJoinColumnBidirectionalRefIngEntity owner) { + this.id = id; + this.data = data; + this.owner = owner; + } - public ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity(String data, ParentIndexedListJoinColumnBidirectionalRefIngEntity owner) { - this.data = data; - this.owner = owner; - } + public ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity( + String data, + ParentIndexedListJoinColumnBidirectionalRefIngEntity owner) { + this.data = data; + this.owner = owner; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public ParentIndexedListJoinColumnBidirectionalRefIngEntity getOwner() { - return owner; - } + public ParentIndexedListJoinColumnBidirectionalRefIngEntity getOwner() { + return owner; + } - public void setOwner(ParentIndexedListJoinColumnBidirectionalRefIngEntity owner) { - this.owner = owner; - } + public void setOwner(ParentIndexedListJoinColumnBidirectionalRefIngEntity owner) { + this.owner = owner; + } - public Integer getPosition() { - return position; - } + public Integer getPosition() { + return position; + } - public void setPosition(Integer position) { - this.position = position; - } + public void setPosition(Integer position) { + this.position = position; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity) ) { + return false; + } - ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity that = (ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity) o; + ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity that = (ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - //noinspection RedundantIfStatement - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + //noinspection RedundantIfStatement + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity(id = " + id + ", data = " + data + ")"; - } + public String toString() { + return "ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity(id = " + id + ", data = " + data + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/ids/SetRefEdEmbIdEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/ids/SetRefEdEmbIdEntity.java index 4d3664456f..cb1bf03436 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/ids/SetRefEdEmbIdEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/ids/SetRefEdEmbIdEntity.java @@ -22,86 +22,96 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.onetomany.ids; -import java.util.Set; + import javax.persistence.EmbeddedId; import javax.persistence.Entity; import javax.persistence.OneToMany; +import java.util.Set; import org.hibernate.envers.Audited; import org.hibernate.envers.test.entities.ids.EmbId; /** * ReferencEd entity + * * @author Adam Warski (adam at warski dot org) */ @Entity public class SetRefEdEmbIdEntity { - @EmbeddedId - private EmbId id; + @EmbeddedId + private EmbId id; - @Audited - private String data; + @Audited + private String data; - @Audited - @OneToMany(mappedBy="reference") - private Set reffering; + @Audited + @OneToMany(mappedBy = "reference") + private Set reffering; - public SetRefEdEmbIdEntity() { - } + public SetRefEdEmbIdEntity() { + } - public SetRefEdEmbIdEntity(EmbId id, String data) { - this.id = id; - this.data = data; - } + public SetRefEdEmbIdEntity(EmbId id, String data) { + this.id = id; + this.data = data; + } - public SetRefEdEmbIdEntity(String data) { - this.data = data; - } + public SetRefEdEmbIdEntity(String data) { + this.data = data; + } - public EmbId getId() { - return id; - } + public EmbId getId() { + return id; + } - public void setId(EmbId id) { - this.id = id; - } + public void setId(EmbId id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public Set getReffering() { - return reffering; - } + public Set getReffering() { + return reffering; + } - public void setReffering(Set reffering) { - this.reffering = reffering; - } + public void setReffering(Set reffering) { + this.reffering = reffering; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof SetRefEdEmbIdEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof SetRefEdEmbIdEntity) ) { + return false; + } - SetRefEdEmbIdEntity that = (SetRefEdEmbIdEntity) o; + SetRefEdEmbIdEntity that = (SetRefEdEmbIdEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "SetRefEdEmbIdEntity(id = " + id + ", data = " + data + ")"; - } + public String toString() { + return "SetRefEdEmbIdEntity(id = " + id + ", data = " + data + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/ids/SetRefEdMulIdEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/ids/SetRefEdMulIdEntity.java index 833bd94f0e..810d6509b7 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/ids/SetRefEdMulIdEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/ids/SetRefEdMulIdEntity.java @@ -22,108 +22,120 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.onetomany.ids; -import java.util.Set; + import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.IdClass; import javax.persistence.OneToMany; +import java.util.Set; import org.hibernate.envers.Audited; import org.hibernate.envers.test.entities.ids.MulId; /** * ReferencEd entity + * * @author Adam Warski (adam at warski dot org) */ @Entity @IdClass(MulId.class) public class SetRefEdMulIdEntity { - @Id - private Integer id1; + @Id + private Integer id1; - @Id - private Integer id2; + @Id + private Integer id2; - @Audited - private String data; + @Audited + private String data; - @Audited - @OneToMany(mappedBy="reference") - private Set reffering; + @Audited + @OneToMany(mappedBy = "reference") + private Set reffering; - public SetRefEdMulIdEntity() { - } + public SetRefEdMulIdEntity() { + } - public SetRefEdMulIdEntity(MulId id, String data) { - this.id1 = id.getId1(); - this.id2 = id.getId2(); - this.data = data; - } + public SetRefEdMulIdEntity(MulId id, String data) { + this.id1 = id.getId1(); + this.id2 = id.getId2(); + this.data = data; + } - public SetRefEdMulIdEntity(Integer id1, Integer id2, String data) { - this.id1 = id1; - this.id2 = id2; - this.data = data; - } + public SetRefEdMulIdEntity(Integer id1, Integer id2, String data) { + this.id1 = id1; + this.id2 = id2; + this.data = data; + } - public SetRefEdMulIdEntity(String data) { - this.data = data; - } + public SetRefEdMulIdEntity(String data) { + this.data = data; + } - public Integer getId1() { - return id1; - } + public Integer getId1() { + return id1; + } - public void setId1(Integer id1) { - this.id1 = id1; - } + public void setId1(Integer id1) { + this.id1 = id1; + } - public Integer getId2() { - return id2; - } + public Integer getId2() { + return id2; + } - public void setId2(Integer id2) { - this.id2 = id2; - } + public void setId2(Integer id2) { + this.id2 = id2; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public Set getReffering() { - return reffering; - } + public Set getReffering() { + return reffering; + } - public void setReffering(Set reffering) { - this.reffering = reffering; - } + public void setReffering(Set reffering) { + this.reffering = reffering; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof SetRefEdMulIdEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof SetRefEdMulIdEntity) ) { + return false; + } - SetRefEdMulIdEntity that = (SetRefEdMulIdEntity) o; + SetRefEdMulIdEntity that = (SetRefEdMulIdEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id1 != null ? !id1.equals(that.id1) : that.id1 != null) return false; - if (id2 != null ? !id2.equals(that.id2) : that.id2 != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id1 != null ? !id1.equals( that.id1 ) : that.id1 != null ) { + return false; + } + if ( id2 != null ? !id2.equals( that.id2 ) : that.id2 != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id1 != null ? id1.hashCode() : 0); - result = 31 * result + (id2 != null ? id2.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id1 != null ? id1.hashCode() : 0); + result = 31 * result + (id2 != null ? id2.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "SetRefEdMulIdEntity(id1 = " + id1 + ", id2 = " + id2 + ", data = " + data + ")"; - } + public String toString() { + return "SetRefEdMulIdEntity(id1 = " + id1 + ", id2 = " + id2 + ", data = " + data + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/ids/SetRefIngEmbIdEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/ids/SetRefIngEmbIdEntity.java index f3e15fe22e..1b2791629e 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/ids/SetRefIngEmbIdEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/ids/SetRefIngEmbIdEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.onetomany.ids; + import javax.persistence.EmbeddedId; import javax.persistence.Entity; import javax.persistence.ManyToOne; @@ -31,77 +32,87 @@ import org.hibernate.envers.test.entities.ids.EmbId; /** * ReferencIng entity + * * @author Adam Warski (adam at warski dot org) */ @Entity public class SetRefIngEmbIdEntity { - @EmbeddedId - private EmbId id; + @EmbeddedId + private EmbId id; - @Audited - private String data; + @Audited + private String data; - @Audited - @ManyToOne - private SetRefEdEmbIdEntity reference; + @Audited + @ManyToOne + private SetRefEdEmbIdEntity reference; - public SetRefIngEmbIdEntity() { } + public SetRefIngEmbIdEntity() { + } - public SetRefIngEmbIdEntity(EmbId id, String data, SetRefEdEmbIdEntity reference) { - this.id = id; - this.data = data; - this.reference = reference; - } + public SetRefIngEmbIdEntity(EmbId id, String data, SetRefEdEmbIdEntity reference) { + this.id = id; + this.data = data; + this.reference = reference; + } - public SetRefIngEmbIdEntity(String data, SetRefEdEmbIdEntity reference) { - this.data = data; - this.reference = reference; - } + public SetRefIngEmbIdEntity(String data, SetRefEdEmbIdEntity reference) { + this.data = data; + this.reference = reference; + } - public EmbId getId() { - return id; - } + public EmbId getId() { + return id; + } - public void setId(EmbId id) { - this.id = id; - } + public void setId(EmbId id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public SetRefEdEmbIdEntity getReference() { - return reference; - } + public SetRefEdEmbIdEntity getReference() { + return reference; + } - public void setReference(SetRefEdEmbIdEntity reference) { - this.reference = reference; - } + public void setReference(SetRefEdEmbIdEntity reference) { + this.reference = reference; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof SetRefIngEmbIdEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof SetRefIngEmbIdEntity) ) { + return false; + } - SetRefIngEmbIdEntity that = (SetRefIngEmbIdEntity) o; + SetRefIngEmbIdEntity that = (SetRefIngEmbIdEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "SetRefIngEmbIdEntity(id = " + id + ", data = " + data + ")"; - } + public String toString() { + return "SetRefIngEmbIdEntity(id = " + id + ", data = " + data + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/ids/SetRefIngMulIdEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/ids/SetRefIngMulIdEntity.java index e4ffefcd16..a02967d611 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/ids/SetRefIngMulIdEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetomany/ids/SetRefIngMulIdEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.onetomany.ids; + import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.IdClass; @@ -32,99 +33,111 @@ import org.hibernate.envers.test.entities.ids.MulId; /** * ReferencIng entity + * * @author Adam Warski (adam at warski dot org) */ @Entity @IdClass(MulId.class) public class SetRefIngMulIdEntity { - @Id - private Integer id1; + @Id + private Integer id1; - @Id - private Integer id2; + @Id + private Integer id2; - @Audited - private String data; + @Audited + private String data; - @Audited - @ManyToOne - private SetRefEdMulIdEntity reference; + @Audited + @ManyToOne + private SetRefEdMulIdEntity reference; - public SetRefIngMulIdEntity() { } + public SetRefIngMulIdEntity() { + } - public SetRefIngMulIdEntity(MulId id, String data, SetRefEdMulIdEntity reference) { - this.id1 = id.getId1(); - this.id2 = id.getId2(); - this.data = data; - this.reference = reference; - } + public SetRefIngMulIdEntity(MulId id, String data, SetRefEdMulIdEntity reference) { + this.id1 = id.getId1(); + this.id2 = id.getId2(); + this.data = data; + this.reference = reference; + } - public SetRefIngMulIdEntity(Integer id1, Integer id2, String data, SetRefEdMulIdEntity reference) { - this.id1 = id1; - this.id2 = id2; - this.data = data; - this.reference = reference; - } + public SetRefIngMulIdEntity(Integer id1, Integer id2, String data, SetRefEdMulIdEntity reference) { + this.id1 = id1; + this.id2 = id2; + this.data = data; + this.reference = reference; + } - public SetRefIngMulIdEntity(String data, SetRefEdMulIdEntity reference) { - this.data = data; - this.reference = reference; - } + public SetRefIngMulIdEntity(String data, SetRefEdMulIdEntity reference) { + this.data = data; + this.reference = reference; + } - public Integer getId1() { - return id1; - } + public Integer getId1() { + return id1; + } - public void setId1(Integer id1) { - this.id1 = id1; - } + public void setId1(Integer id1) { + this.id1 = id1; + } - public Integer getId2() { - return id2; - } + public Integer getId2() { + return id2; + } - public void setId2(Integer id2) { - this.id2 = id2; - } + public void setId2(Integer id2) { + this.id2 = id2; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public SetRefEdMulIdEntity getReference() { - return reference; - } + public SetRefEdMulIdEntity getReference() { + return reference; + } - public void setReference(SetRefEdMulIdEntity reference) { - this.reference = reference; - } + public void setReference(SetRefEdMulIdEntity reference) { + this.reference = reference; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof SetRefIngMulIdEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof SetRefIngMulIdEntity) ) { + return false; + } - SetRefIngMulIdEntity that = (SetRefIngMulIdEntity) o; + SetRefIngMulIdEntity that = (SetRefIngMulIdEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id1 != null ? !id1.equals(that.id1) : that.id1 != null) return false; - if (id2 != null ? !id2.equals(that.id2) : that.id2 != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id1 != null ? !id1.equals( that.id1 ) : that.id1 != null ) { + return false; + } + if ( id2 != null ? !id2.equals( that.id2 ) : that.id2 != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id1 != null ? id1.hashCode() : 0); - result = 31 * result + (id2 != null ? id2.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id1 != null ? id1.hashCode() : 0); + result = 31 * result + (id2 != null ? id2.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "SetRefIngMulIdEntity(id1 = " + id1 + ", id2 = " + id2 + ", data = " + data + ")"; - } + public String toString() { + return "SetRefIngMulIdEntity(id1 = " + id1 + ", id2 = " + id2 + ", data = " + data + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetoone/BidirectionalEagerAnnotationRefEdOneToOne.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetoone/BidirectionalEagerAnnotationRefEdOneToOne.java index 8f483bd275..6e04c65e5c 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetoone/BidirectionalEagerAnnotationRefEdOneToOne.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetoone/BidirectionalEagerAnnotationRefEdOneToOne.java @@ -39,7 +39,7 @@ import org.hibernate.envers.NotAudited; */ @Entity @Audited -@Proxy(lazy=false) +@Proxy(lazy = false) // Class name is too long of an identifier for Oracle. @Table(name = "EdOneToOne") public final class BidirectionalEagerAnnotationRefEdOneToOne { @@ -64,13 +64,21 @@ public final class BidirectionalEagerAnnotationRefEdOneToOne { @Override public boolean equals(Object o) { - if ( this == o ) return true; - if ( ! ( o instanceof BidirectionalEagerAnnotationRefEdOneToOne ) ) return false; + if ( this == o ) { + return true; + } + if ( !(o instanceof BidirectionalEagerAnnotationRefEdOneToOne) ) { + return false; + } BidirectionalEagerAnnotationRefEdOneToOne that = (BidirectionalEagerAnnotationRefEdOneToOne) o; - if ( data != null ? !data.equals( that.data ) : that.data != null ) return false; - if ( id != null ? !id.equals( that.id ) : that.id != null ) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } return true; } @@ -78,7 +86,7 @@ public final class BidirectionalEagerAnnotationRefEdOneToOne { @Override public int hashCode() { int result = id != null ? id.hashCode() : 0; - result = 31 * result + ( data != null ? data.hashCode() : 0 ); + result = 31 * result + (data != null ? data.hashCode() : 0); return result; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetoone/BidirectionalEagerAnnotationRefIngOneToOne.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetoone/BidirectionalEagerAnnotationRefIngOneToOne.java index 3431d29ddd..fae36c712a 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetoone/BidirectionalEagerAnnotationRefIngOneToOne.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetoone/BidirectionalEagerAnnotationRefIngOneToOne.java @@ -40,7 +40,7 @@ import org.hibernate.envers.Audited; */ @Entity @Audited -@Proxy(lazy=false) +@Proxy(lazy = false) //Class name is too long of an identifier for Oracle. @Table(name = "IngOneToOne") public final class BidirectionalEagerAnnotationRefIngOneToOne { @@ -72,13 +72,21 @@ public final class BidirectionalEagerAnnotationRefIngOneToOne { @Override public boolean equals(Object o) { - if ( this == o ) return true; - if ( ! ( o instanceof BidirectionalEagerAnnotationRefIngOneToOne ) ) return false; + if ( this == o ) { + return true; + } + if ( !(o instanceof BidirectionalEagerAnnotationRefIngOneToOne) ) { + return false; + } BidirectionalEagerAnnotationRefIngOneToOne that = (BidirectionalEagerAnnotationRefIngOneToOne) o; - if ( data != null ? !data.equals( that.data ) : that.data != null ) return false; - if ( id != null ? !id.equals( that.id ) : that.id != null ) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } return true; } @@ -86,7 +94,7 @@ public final class BidirectionalEagerAnnotationRefIngOneToOne { @Override public int hashCode() { int result = id != null ? id.hashCode() : 0; - result = 31 * result + ( data != null ? data.hashCode() : 0 ); + result = 31 * result + (data != null ? data.hashCode() : 0); return result; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetoone/BidirectionalEagerHbmRefEdPK.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetoone/BidirectionalEagerHbmRefEdPK.java index ee3ae95aea..46d3242b22 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetoone/BidirectionalEagerHbmRefEdPK.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetoone/BidirectionalEagerHbmRefEdPK.java @@ -31,7 +31,8 @@ public class BidirectionalEagerHbmRefEdPK { private String data; private BidirectionalEagerHbmRefIngPK referencing; - public BidirectionalEagerHbmRefEdPK() {} + public BidirectionalEagerHbmRefEdPK() { + } public BidirectionalEagerHbmRefEdPK(String data) { this.data = data; @@ -63,21 +64,29 @@ public class BidirectionalEagerHbmRefEdPK { @Override public boolean equals(Object o) { - if ( this == o ) return true; - if ( ! ( o instanceof BidirectionalEagerHbmRefEdPK ) ) return false; + if ( this == o ) { + return true; + } + if ( !(o instanceof BidirectionalEagerHbmRefEdPK) ) { + return false; + } BidirectionalEagerHbmRefEdPK that = (BidirectionalEagerHbmRefEdPK) o; - if ( id != that.id ) return false; - if ( data != null ? !data.equals( that.data ) : that.data != null ) return false; + if ( id != that.id ) { + return false; + } + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } return true; } @Override public int hashCode() { - int result = (int) ( id ^ ( id >>> 32 ) ); - result = 31 * result + ( data != null ? data.hashCode() : 0 ); + int result = (int) (id ^ (id >>> 32)); + result = 31 * result + (data != null ? data.hashCode() : 0); return result; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetoone/BidirectionalEagerHbmRefIngPK.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetoone/BidirectionalEagerHbmRefIngPK.java index b7bfa6ce51..991aa89429 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetoone/BidirectionalEagerHbmRefIngPK.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/onetoone/BidirectionalEagerHbmRefIngPK.java @@ -31,7 +31,8 @@ public class BidirectionalEagerHbmRefIngPK { private String data; private BidirectionalEagerHbmRefEdPK reference; - public BidirectionalEagerHbmRefIngPK() {} + public BidirectionalEagerHbmRefIngPK() { + } public BidirectionalEagerHbmRefIngPK(String data) { this.data = data; @@ -63,21 +64,29 @@ public class BidirectionalEagerHbmRefIngPK { @Override public boolean equals(Object o) { - if ( this == o ) return true; - if ( ! ( o instanceof BidirectionalEagerHbmRefIngPK ) ) return false; + if ( this == o ) { + return true; + } + if ( !(o instanceof BidirectionalEagerHbmRefIngPK) ) { + return false; + } BidirectionalEagerHbmRefIngPK that = (BidirectionalEagerHbmRefIngPK) o; - if ( id != that.id ) return false; - if ( data != null ? !data.equals( that.data ) : that.data != null ) return false; + if ( id != that.id ) { + return false; + } + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } return true; } @Override public int hashCode() { - int result = (int) ( id ^ ( id >>> 32 ) ); - result = 31 * result + ( data != null ? data.hashCode() : 0 ); + int result = (int) (id ^ (id >>> 32)); + result = 31 * result + (data != null ? data.hashCode() : 0); return result; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/reventity/CustomDataRevEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/reventity/CustomDataRevEntity.java index 9f5acfc63f..2f6d32945f 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/reventity/CustomDataRevEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/reventity/CustomDataRevEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.reventity; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; @@ -37,40 +38,41 @@ import org.hibernate.envers.RevisionTimestamp; */ @Entity @GenericGenerator(name = "EnversTestingRevisionGenerator", - strategy = "org.hibernate.id.enhanced.TableGenerator", - parameters = {@Parameter(name = "table_name", value = "REVISION_GENERATOR"), - @Parameter(name = "initial_value", value = "1"), - @Parameter(name = "increment_size", value = "1"), - @Parameter(name = "prefer_entity_table_as_segment_value", value = "true") - } + strategy = "org.hibernate.id.enhanced.TableGenerator", + parameters = { + @Parameter(name = "table_name", value = "REVISION_GENERATOR"), + @Parameter(name = "initial_value", value = "1"), + @Parameter(name = "increment_size", value = "1"), + @Parameter(name = "prefer_entity_table_as_segment_value", value = "true") + } ) @RevisionEntity public class CustomDataRevEntity { - @Id - @GeneratedValue(generator = "EnversTestingRevisionGenerator") - @RevisionNumber - private int customId; + @Id + @GeneratedValue(generator = "EnversTestingRevisionGenerator") + @RevisionNumber + private int customId; - @RevisionTimestamp - private long customTimestamp; + @RevisionTimestamp + private long customTimestamp; private String data; - public int getCustomId() { - return customId; - } + public int getCustomId() { + return customId; + } - public void setCustomId(int customId) { - this.customId = customId; - } + public void setCustomId(int customId) { + this.customId = customId; + } - public long getCustomTimestamp() { - return customTimestamp; - } + public long getCustomTimestamp() { + return customTimestamp; + } - public void setCustomTimestamp(long customTimestamp) { - this.customTimestamp = customTimestamp; - } + public void setCustomTimestamp(long customTimestamp) { + this.customTimestamp = customTimestamp; + } public String getData() { return data; @@ -82,14 +84,24 @@ public class CustomDataRevEntity { @Override public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof CustomDataRevEntity)) return false; + if ( this == o ) { + return true; + } + if ( !(o instanceof CustomDataRevEntity) ) { + return false; + } CustomDataRevEntity that = (CustomDataRevEntity) o; - if (customId != that.customId) return false; - if (customTimestamp != that.customTimestamp) return false; - if (data != null ? !data.equals(that.data) : that.data != null) return false; + if ( customId != that.customId ) { + return false; + } + if ( customTimestamp != that.customTimestamp ) { + return false; + } + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } return true; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/reventity/CustomDateRevEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/reventity/CustomDateRevEntity.java index 7e4f957c15..0a988303ef 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/reventity/CustomDateRevEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/reventity/CustomDateRevEntity.java @@ -22,10 +22,11 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.reventity; -import java.util.Date; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; +import java.util.Date; import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.Parameter; @@ -38,57 +39,65 @@ import org.hibernate.envers.RevisionTimestamp; */ @Entity @GenericGenerator(name = "EnversTestingRevisionGenerator", - strategy = "org.hibernate.id.enhanced.TableGenerator", - parameters = {@Parameter(name = "table_name", value = "REVISION_GENERATOR"), - @Parameter(name = "initial_value", value = "1"), - @Parameter(name = "increment_size", value = "1"), - @Parameter(name = "prefer_entity_table_as_segment_value", value = "true") - } + strategy = "org.hibernate.id.enhanced.TableGenerator", + parameters = { + @Parameter(name = "table_name", value = "REVISION_GENERATOR"), + @Parameter(name = "initial_value", value = "1"), + @Parameter(name = "increment_size", value = "1"), + @Parameter(name = "prefer_entity_table_as_segment_value", value = "true") + } ) @RevisionEntity public class CustomDateRevEntity { - @Id - @GeneratedValue(generator = "EnversTestingRevisionGenerator") - @RevisionNumber - private int customId; + @Id + @GeneratedValue(generator = "EnversTestingRevisionGenerator") + @RevisionNumber + private int customId; - @RevisionTimestamp - private Date dateTimestamp; + @RevisionTimestamp + private Date dateTimestamp; - public int getCustomId() { - return customId; - } + public int getCustomId() { + return customId; + } - public void setCustomId(int customId) { - this.customId = customId; - } + public void setCustomId(int customId) { + this.customId = customId; + } - public Date getDateTimestamp() { - return dateTimestamp; - } + public Date getDateTimestamp() { + return dateTimestamp; + } - public void setDateTimestamp(Date dateTimestamp) { - this.dateTimestamp = dateTimestamp; - } + public void setDateTimestamp(Date dateTimestamp) { + this.dateTimestamp = dateTimestamp; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } - CustomDateRevEntity that = (CustomDateRevEntity) o; + CustomDateRevEntity that = (CustomDateRevEntity) o; - if (customId != that.customId) return false; - if (dateTimestamp != null ? !dateTimestamp.equals(that.dateTimestamp) : that.dateTimestamp != null) - return false; + if ( customId != that.customId ) { + return false; + } + if ( dateTimestamp != null ? !dateTimestamp.equals( that.dateTimestamp ) : that.dateTimestamp != null ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - int result = customId; - result = 31 * result + (dateTimestamp != null ? dateTimestamp.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = customId; + result = 31 * result + (dateTimestamp != null ? dateTimestamp.hashCode() : 0); + return result; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/reventity/CustomPropertyAccessRevEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/reventity/CustomPropertyAccessRevEntity.java index dcb297d662..7bd029b680 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/reventity/CustomPropertyAccessRevEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/reventity/CustomPropertyAccessRevEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.reventity; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; @@ -37,55 +38,64 @@ import org.hibernate.envers.RevisionTimestamp; */ @Entity @GenericGenerator(name = "EnversTestingRevisionGenerator", - strategy = "org.hibernate.id.enhanced.TableGenerator", - parameters = {@Parameter(name = "table_name", value = "REVISION_GENERATOR"), - @Parameter(name = "initial_value", value = "1"), - @Parameter(name = "increment_size", value = "1"), - @Parameter(name = "prefer_entity_table_as_segment_value", value = "true") - } + strategy = "org.hibernate.id.enhanced.TableGenerator", + parameters = { + @Parameter(name = "table_name", value = "REVISION_GENERATOR"), + @Parameter(name = "initial_value", value = "1"), + @Parameter(name = "increment_size", value = "1"), + @Parameter(name = "prefer_entity_table_as_segment_value", value = "true") + } ) @RevisionEntity public class CustomPropertyAccessRevEntity { - private int customId; + private int customId; - private long customTimestamp; + private long customTimestamp; - @Id - @GeneratedValue(generator = "EnversTestingRevisionGenerator") - @RevisionNumber - public int getCustomId() { - return customId; - } + @Id + @GeneratedValue(generator = "EnversTestingRevisionGenerator") + @RevisionNumber + public int getCustomId() { + return customId; + } - public void setCustomId(int customId) { - this.customId = customId; - } + public void setCustomId(int customId) { + this.customId = customId; + } - @RevisionTimestamp - public long getCustomTimestamp() { - return customTimestamp; - } + @RevisionTimestamp + public long getCustomTimestamp() { + return customTimestamp; + } - public void setCustomTimestamp(long customTimestamp) { - this.customTimestamp = customTimestamp; - } + public void setCustomTimestamp(long customTimestamp) { + this.customTimestamp = customTimestamp; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof CustomPropertyAccessRevEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof CustomPropertyAccessRevEntity) ) { + return false; + } - CustomPropertyAccessRevEntity that = (CustomPropertyAccessRevEntity) o; + CustomPropertyAccessRevEntity that = (CustomPropertyAccessRevEntity) o; - if (customId != that.customId) return false; - if (customTimestamp != that.customTimestamp) return false; + if ( customId != that.customId ) { + return false; + } + if ( customTimestamp != that.customTimestamp ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = customId; - result = 31 * result + (int) (customTimestamp ^ (customTimestamp >>> 32)); - return result; - } + public int hashCode() { + int result; + result = customId; + result = 31 * result + (int) (customTimestamp ^ (customTimestamp >>> 32)); + return result; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/reventity/CustomRevEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/reventity/CustomRevEntity.java index adbf0a0ea1..b497d22b19 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/reventity/CustomRevEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/reventity/CustomRevEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.reventity; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; @@ -37,55 +38,64 @@ import org.hibernate.envers.RevisionTimestamp; */ @Entity @GenericGenerator(name = "EnversTestingRevisionGenerator", - strategy = "org.hibernate.id.enhanced.TableGenerator", - parameters = {@Parameter(name = "table_name", value = "REVISION_GENERATOR"), - @Parameter(name = "initial_value", value = "1"), - @Parameter(name = "increment_size", value = "1"), - @Parameter(name = "prefer_entity_table_as_segment_value", value = "true") - } + strategy = "org.hibernate.id.enhanced.TableGenerator", + parameters = { + @Parameter(name = "table_name", value = "REVISION_GENERATOR"), + @Parameter(name = "initial_value", value = "1"), + @Parameter(name = "increment_size", value = "1"), + @Parameter(name = "prefer_entity_table_as_segment_value", value = "true") + } ) @RevisionEntity public class CustomRevEntity { - @Id - @GeneratedValue(generator = "EnversTestingRevisionGenerator") - @RevisionNumber - private int customId; + @Id + @GeneratedValue(generator = "EnversTestingRevisionGenerator") + @RevisionNumber + private int customId; - @RevisionTimestamp - private long customTimestamp; + @RevisionTimestamp + private long customTimestamp; - public int getCustomId() { - return customId; - } + public int getCustomId() { + return customId; + } - public void setCustomId(int customId) { - this.customId = customId; - } + public void setCustomId(int customId) { + this.customId = customId; + } - public long getCustomTimestamp() { - return customTimestamp; - } + public long getCustomTimestamp() { + return customTimestamp; + } - public void setCustomTimestamp(long customTimestamp) { - this.customTimestamp = customTimestamp; - } + public void setCustomTimestamp(long customTimestamp) { + this.customTimestamp = customTimestamp; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof CustomRevEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof CustomRevEntity) ) { + return false; + } - CustomRevEntity that = (CustomRevEntity) o; + CustomRevEntity that = (CustomRevEntity) o; - if (customId != that.customId) return false; - if (customTimestamp != that.customTimestamp) return false; + if ( customId != that.customId ) { + return false; + } + if ( customTimestamp != that.customTimestamp ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = customId; - result = 31 * result + (int) (customTimestamp ^ (customTimestamp >>> 32)); - return result; - } + public int hashCode() { + int result; + result = customId; + result = 31 * result + (int) (customTimestamp ^ (customTimestamp >>> 32)); + return result; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/reventity/CustomRevEntityColumnMapping.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/reventity/CustomRevEntityColumnMapping.java index b3f77944f7..6cbdfd2ea0 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/reventity/CustomRevEntityColumnMapping.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/reventity/CustomRevEntityColumnMapping.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.entities.reventity; + import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -38,57 +39,66 @@ import org.hibernate.envers.RevisionTimestamp; */ @Entity @GenericGenerator(name = "EnversTestingRevisionGenerator", - strategy = "org.hibernate.id.enhanced.TableGenerator", - parameters = {@Parameter(name = "table_name", value = "REVISION_GENERATOR"), - @Parameter(name = "initial_value", value = "1"), - @Parameter(name = "increment_size", value = "1"), - @Parameter(name = "prefer_entity_table_as_segment_value", value = "true") - } + strategy = "org.hibernate.id.enhanced.TableGenerator", + parameters = { + @Parameter(name = "table_name", value = "REVISION_GENERATOR"), + @Parameter(name = "initial_value", value = "1"), + @Parameter(name = "increment_size", value = "1"), + @Parameter(name = "prefer_entity_table_as_segment_value", value = "true") + } ) @RevisionEntity public class CustomRevEntityColumnMapping { - @Id - @GeneratedValue(generator = "EnversTestingRevisionGenerator") - @Column(columnDefinition = "int") - @RevisionNumber - private Long customId; + @Id + @GeneratedValue(generator = "EnversTestingRevisionGenerator") + @Column(columnDefinition = "int") + @RevisionNumber + private Long customId; - @RevisionTimestamp - private long customTimestamp; + @RevisionTimestamp + private long customTimestamp; - public Long getCustomId() { - return customId; - } + public Long getCustomId() { + return customId; + } - public void setCustomId(Long customId) { - this.customId = customId; - } + public void setCustomId(Long customId) { + this.customId = customId; + } - public long getCustomTimestamp() { - return customTimestamp; - } + public long getCustomTimestamp() { + return customTimestamp; + } - public void setCustomTimestamp(long customTimestamp) { - this.customTimestamp = customTimestamp; - } + public void setCustomTimestamp(long customTimestamp) { + this.customTimestamp = customTimestamp; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } - CustomRevEntityColumnMapping that = (CustomRevEntityColumnMapping) o; + CustomRevEntityColumnMapping that = (CustomRevEntityColumnMapping) o; - if (customTimestamp != that.customTimestamp) return false; - if (customId != null ? !customId.equals(that.customId) : that.customId != null) return false; + if ( customTimestamp != that.customTimestamp ) { + return false; + } + if ( customId != null ? !customId.equals( that.customId ) : that.customId != null ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - int result = customId != null ? customId.hashCode() : 0; - result = 31 * result + (int) (customTimestamp ^ (customTimestamp >>> 32)); - return result; - } + @Override + public int hashCode() { + int result = customId != null ? customId.hashCode() : 0; + result = 31 * result + (int) (customTimestamp ^ (customTimestamp >>> 32)); + return result; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/reventity/trackmodifiedentities/AnnotatedTrackingRevisionEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/reventity/trackmodifiedentities/AnnotatedTrackingRevisionEntity.java index 89f88a03e8..8101398461 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/reventity/trackmodifiedentities/AnnotatedTrackingRevisionEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/reventity/trackmodifiedentities/AnnotatedTrackingRevisionEntity.java @@ -1,6 +1,5 @@ package org.hibernate.envers.test.entities.reventity.trackmodifiedentities; -import java.util.Set; import javax.persistence.Column; import javax.persistence.ElementCollection; import javax.persistence.Entity; @@ -9,6 +8,7 @@ import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; import javax.persistence.Table; +import java.util.Set; import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.Parameter; @@ -19,80 +19,92 @@ import org.hibernate.envers.RevisionTimestamp; /** * Sample revision entity that uses {@link ModifiedEntityNames} annotation. + * * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ @Entity @Table(name = "AnnotatedTrackRevInfo") @GenericGenerator(name = "EnversTestingRevisionGenerator", - strategy = "org.hibernate.id.enhanced.TableGenerator", - parameters = {@Parameter(name = "table_name", value = "REVISION_GENERATOR"), - @Parameter(name = "initial_value", value = "1"), - @Parameter(name = "increment_size", value = "1"), - @Parameter(name = "prefer_entity_table_as_segment_value", value = "true") - } + strategy = "org.hibernate.id.enhanced.TableGenerator", + parameters = { + @Parameter(name = "table_name", value = "REVISION_GENERATOR"), + @Parameter(name = "initial_value", value = "1"), + @Parameter(name = "increment_size", value = "1"), + @Parameter(name = "prefer_entity_table_as_segment_value", value = "true") + } ) @RevisionEntity public class AnnotatedTrackingRevisionEntity { - @Id - @GeneratedValue(generator = "EnversTestingRevisionGenerator") - @RevisionNumber - private int customId; + @Id + @GeneratedValue(generator = "EnversTestingRevisionGenerator") + @RevisionNumber + private int customId; - @RevisionTimestamp - private long customTimestamp; + @RevisionTimestamp + private long customTimestamp; - @ElementCollection - @JoinTable(name = "REVCHANGES", joinColumns = @JoinColumn(name = "REV")) - @Column(name = "ENTITYNAME") - @ModifiedEntityNames - private Set entityNames; + @ElementCollection + @JoinTable(name = "REVCHANGES", joinColumns = @JoinColumn(name = "REV")) + @Column(name = "ENTITYNAME") + @ModifiedEntityNames + private Set entityNames; - public int getCustomId() { - return customId; - } + public int getCustomId() { + return customId; + } - public void setCustomId(int customId) { - this.customId = customId; - } + public void setCustomId(int customId) { + this.customId = customId; + } - public long getCustomTimestamp() { - return customTimestamp; - } + public long getCustomTimestamp() { + return customTimestamp; + } - public void setCustomTimestamp(long customTimestamp) { - this.customTimestamp = customTimestamp; - } + public void setCustomTimestamp(long customTimestamp) { + this.customTimestamp = customTimestamp; + } - public Set getEntityNames() { - return entityNames; - } + public Set getEntityNames() { + return entityNames; + } - public void setEntityNames(Set entityNames) { - this.entityNames = entityNames; - } + public void setEntityNames(Set entityNames) { + this.entityNames = entityNames; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof AnnotatedTrackingRevisionEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof AnnotatedTrackingRevisionEntity) ) { + return false; + } - AnnotatedTrackingRevisionEntity that = (AnnotatedTrackingRevisionEntity) o; + AnnotatedTrackingRevisionEntity that = (AnnotatedTrackingRevisionEntity) o; - if (customId != that.customId) return false; - if (customTimestamp != that.customTimestamp) return false; - if (entityNames != null ? !entityNames.equals(that.entityNames) : that.entityNames != null) return false; + if ( customId != that.customId ) { + return false; + } + if ( customTimestamp != that.customTimestamp ) { + return false; + } + if ( entityNames != null ? !entityNames.equals( that.entityNames ) : that.entityNames != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result = customId; - result = 31 * result + (int) (customTimestamp ^ (customTimestamp >>> 32)); - result = 31 * result + (entityNames != null ? entityNames.hashCode() : 0); - return result; - } + public int hashCode() { + int result = customId; + result = 31 * result + (int) (customTimestamp ^ (customTimestamp >>> 32)); + result = 31 * result + (entityNames != null ? entityNames.hashCode() : 0); + return result; + } - @Override - public String toString() { - return "AnnotatedTrackingRevisionEntity(customId = " + customId + ", customTimestamp = " + customTimestamp + ", entityNames=" + entityNames + ")"; - } + @Override + public String toString() { + return "AnnotatedTrackingRevisionEntity(customId = " + customId + ", customTimestamp = " + customTimestamp + ", entityNames=" + entityNames + ")"; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/reventity/trackmodifiedentities/CustomTrackingRevisionEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/reventity/trackmodifiedentities/CustomTrackingRevisionEntity.java index 143e4c30fb..65be5c4e1f 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/reventity/trackmodifiedentities/CustomTrackingRevisionEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/reventity/trackmodifiedentities/CustomTrackingRevisionEntity.java @@ -1,13 +1,13 @@ package org.hibernate.envers.test.entities.reventity.trackmodifiedentities; -import java.util.HashSet; -import java.util.Set; import javax.persistence.CascadeType; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.OneToMany; import javax.persistence.Table; +import java.util.HashSet; +import java.util.Set; import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.Parameter; @@ -17,79 +17,89 @@ import org.hibernate.envers.RevisionTimestamp; /** * Revision entity which {@code modifiedEntityTypes} field is manually populated by {@link CustomTrackingRevisionListener}. + * * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ @Entity @Table(name = "CustomTrackRevInfo") @GenericGenerator(name = "EnversTestingRevisionGenerator", - strategy = "org.hibernate.id.enhanced.TableGenerator", - parameters = {@Parameter(name = "table_name", value = "REVISION_GENERATOR"), - @Parameter(name = "initial_value", value = "1"), - @Parameter(name = "increment_size", value = "1"), - @Parameter(name = "prefer_entity_table_as_segment_value", value = "true") - } + strategy = "org.hibernate.id.enhanced.TableGenerator", + parameters = { + @Parameter(name = "table_name", value = "REVISION_GENERATOR"), + @Parameter(name = "initial_value", value = "1"), + @Parameter(name = "increment_size", value = "1"), + @Parameter(name = "prefer_entity_table_as_segment_value", value = "true") + } ) @RevisionEntity(CustomTrackingRevisionListener.class) public class CustomTrackingRevisionEntity { - @Id - @GeneratedValue(generator = "EnversTestingRevisionGenerator") - @RevisionNumber - private int customId; + @Id + @GeneratedValue(generator = "EnversTestingRevisionGenerator") + @RevisionNumber + private int customId; - @RevisionTimestamp - private long customTimestamp; + @RevisionTimestamp + private long customTimestamp; - @OneToMany(mappedBy="revision", cascade={CascadeType.PERSIST, CascadeType.REMOVE}) - private Set modifiedEntityTypes = new HashSet(); + @OneToMany(mappedBy = "revision", cascade = {CascadeType.PERSIST, CascadeType.REMOVE}) + private Set modifiedEntityTypes = new HashSet(); - public int getCustomId() { - return customId; - } + public int getCustomId() { + return customId; + } - public void setCustomId(int customId) { - this.customId = customId; - } + public void setCustomId(int customId) { + this.customId = customId; + } - public long getCustomTimestamp() { - return customTimestamp; - } + public long getCustomTimestamp() { + return customTimestamp; + } - public void setCustomTimestamp(long customTimestamp) { - this.customTimestamp = customTimestamp; - } + public void setCustomTimestamp(long customTimestamp) { + this.customTimestamp = customTimestamp; + } - public Set getModifiedEntityTypes() { - return modifiedEntityTypes; - } + public Set getModifiedEntityTypes() { + return modifiedEntityTypes; + } - public void setModifiedEntityTypes(Set modifiedEntityTypes) { - this.modifiedEntityTypes = modifiedEntityTypes; - } + public void setModifiedEntityTypes(Set modifiedEntityTypes) { + this.modifiedEntityTypes = modifiedEntityTypes; + } - public void addModifiedEntityType(String entityClassName) { - modifiedEntityTypes.add(new ModifiedEntityTypeEntity(this, entityClassName)); - } + public void addModifiedEntityType(String entityClassName) { + modifiedEntityTypes.add( new ModifiedEntityTypeEntity( this, entityClassName ) ); + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof CustomTrackingRevisionEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof CustomTrackingRevisionEntity) ) { + return false; + } - CustomTrackingRevisionEntity that = (CustomTrackingRevisionEntity) o; + CustomTrackingRevisionEntity that = (CustomTrackingRevisionEntity) o; - if (customId != that.customId) return false; - if (customTimestamp != that.customTimestamp) return false; + if ( customId != that.customId ) { + return false; + } + if ( customTimestamp != that.customTimestamp ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result = customId; - result = 31 * result + (int) (customTimestamp ^ (customTimestamp >>> 32)); - return result; - } + public int hashCode() { + int result = customId; + result = 31 * result + (int) (customTimestamp ^ (customTimestamp >>> 32)); + return result; + } - @Override - public String toString() { - return "CustomTrackingRevisionEntity(customId = " + customId + ", customTimestamp = " + customTimestamp + ")"; - } + @Override + public String toString() { + return "CustomTrackingRevisionEntity(customId = " + customId + ", customTimestamp = " + customTimestamp + ")"; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/reventity/trackmodifiedentities/CustomTrackingRevisionListener.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/reventity/trackmodifiedentities/CustomTrackingRevisionListener.java index 510be1a43a..d9507f7964 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/reventity/trackmodifiedentities/CustomTrackingRevisionListener.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/reventity/trackmodifiedentities/CustomTrackingRevisionListener.java @@ -9,13 +9,14 @@ import org.hibernate.envers.RevisionType; * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public class CustomTrackingRevisionListener implements EntityTrackingRevisionListener { - @Override - public void entityChanged(Class entityClass, String entityName, Serializable entityId, RevisionType revisionType, - Object revisionEntity) { - ((CustomTrackingRevisionEntity)revisionEntity).addModifiedEntityType(entityClass.getName()); - } + @Override + public void entityChanged( + Class entityClass, String entityName, Serializable entityId, RevisionType revisionType, + Object revisionEntity) { + ((CustomTrackingRevisionEntity) revisionEntity).addModifiedEntityType( entityClass.getName() ); + } - @Override - public void newRevision(Object revisionEntity) { - } + @Override + public void newRevision(Object revisionEntity) { + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/reventity/trackmodifiedentities/ExtendedRevisionEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/reventity/trackmodifiedentities/ExtendedRevisionEntity.java index 65e838148a..7dbd156917 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/reventity/trackmodifiedentities/ExtendedRevisionEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/reventity/trackmodifiedentities/ExtendedRevisionEntity.java @@ -12,14 +12,14 @@ import org.hibernate.envers.enhanced.SequenceIdTrackingModifiedEntitiesRevisionE @Entity @RevisionEntity(ExtendedRevisionListener.class) public class ExtendedRevisionEntity extends SequenceIdTrackingModifiedEntitiesRevisionEntity { - @Column(name = "USER_COMMENT") - private String comment; + @Column(name = "USER_COMMENT") + private String comment; - public String getComment() { - return comment; - } + public String getComment() { + return comment; + } - public void setComment(String comment) { - this.comment = comment; - } + public void setComment(String comment) { + this.comment = comment; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/reventity/trackmodifiedentities/ExtendedRevisionListener.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/reventity/trackmodifiedentities/ExtendedRevisionListener.java index d78317497a..0e12df227a 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/reventity/trackmodifiedentities/ExtendedRevisionListener.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/reventity/trackmodifiedentities/ExtendedRevisionListener.java @@ -6,9 +6,9 @@ import org.hibernate.envers.RevisionListener; * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public class ExtendedRevisionListener implements RevisionListener { - public static final String COMMENT_VALUE = "Comment"; + public static final String COMMENT_VALUE = "Comment"; - public void newRevision(Object revisionEntity) { - ((ExtendedRevisionEntity)revisionEntity).setComment(COMMENT_VALUE); - } + public void newRevision(Object revisionEntity) { + ((ExtendedRevisionEntity) revisionEntity).setComment( COMMENT_VALUE ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/reventity/trackmodifiedentities/ModifiedEntityTypeEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/reventity/trackmodifiedentities/ModifiedEntityTypeEntity.java index 07092f0c28..4c2a72b6dd 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/reventity/trackmodifiedentities/ModifiedEntityTypeEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/reventity/trackmodifiedentities/ModifiedEntityTypeEntity.java @@ -7,64 +7,73 @@ import javax.persistence.ManyToOne; /** * Custom detail of revision entity. + * * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ @Entity public class ModifiedEntityTypeEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - @ManyToOne - private CustomTrackingRevisionEntity revision; - - private String entityClassName; + @ManyToOne + private CustomTrackingRevisionEntity revision; - public ModifiedEntityTypeEntity() { - } + private String entityClassName; - public ModifiedEntityTypeEntity(String entityClassName) { - this.entityClassName = entityClassName; - } + public ModifiedEntityTypeEntity() { + } - public ModifiedEntityTypeEntity(CustomTrackingRevisionEntity revision, String entityClassName) { - this.revision = revision; - this.entityClassName = entityClassName; - } + public ModifiedEntityTypeEntity(String entityClassName) { + this.entityClassName = entityClassName; + } - public CustomTrackingRevisionEntity getRevision() { - return revision; - } + public ModifiedEntityTypeEntity(CustomTrackingRevisionEntity revision, String entityClassName) { + this.revision = revision; + this.entityClassName = entityClassName; + } - public void setRevision(CustomTrackingRevisionEntity revision) { - this.revision = revision; - } + public CustomTrackingRevisionEntity getRevision() { + return revision; + } - public String getEntityClassName() { - return entityClassName; - } + public void setRevision(CustomTrackingRevisionEntity revision) { + this.revision = revision; + } - public void setEntityClassName(String entityClassName) { - this.entityClassName = entityClassName; - } + public String getEntityClassName() { + return entityClassName; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ModifiedEntityTypeEntity)) return false; + public void setEntityClassName(String entityClassName) { + this.entityClassName = entityClassName; + } - ModifiedEntityTypeEntity that = (ModifiedEntityTypeEntity) o; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ModifiedEntityTypeEntity) ) { + return false; + } - if (entityClassName != null ? !entityClassName.equals(that.entityClassName) : that.entityClassName != null) return false; + ModifiedEntityTypeEntity that = (ModifiedEntityTypeEntity) o; - return true; - } + if ( entityClassName != null ? + !entityClassName.equals( that.entityClassName ) : + that.entityClassName != null ) { + return false; + } - public int hashCode() { - return entityClassName != null ? entityClassName.hashCode() : 0; - } + return true; + } - @Override - public String toString() { - return "CustomTrackingRevisionEntity(entityClassName = " + entityClassName + ")"; - } + public int hashCode() { + return entityClassName != null ? entityClassName.hashCode() : 0; + } + + @Override + public String toString() { + return "CustomTrackingRevisionEntity(entityClassName = " + entityClassName + ")"; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/accesstype/Country.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/accesstype/Country.java index 56fc48ac0a..80a9994713 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/accesstype/Country.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/accesstype/Country.java @@ -1,4 +1,5 @@ package org.hibernate.envers.test.integration.accesstype; + import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; @@ -19,7 +20,8 @@ public class Country { * Default constructor for persistence provider. */ @SuppressWarnings({"UnusedDeclaration"}) - private Country() { } + private Country() { + } private Country(Integer code, String naam) { this.code = code; @@ -35,7 +37,7 @@ public class Country { } public static Country of(Integer code, String name) { - return new Country(code, name); + return new Country( code, name ); } @Override @@ -49,23 +51,32 @@ public class Country { @Override public boolean equals(Object obj) { - if (this == obj) + if ( this == obj ) { return true; - if (obj == null) + } + if ( obj == null ) { return false; - if (getClass() != obj.getClass()) + } + if ( getClass() != obj.getClass() ) { return false; + } Country other = (Country) obj; - if (code == null) { - if (other.code != null) + if ( code == null ) { + if ( other.code != null ) { return false; - } else if (!code.equals(other.code)) + } + } + else if ( !code.equals( other.code ) ) { return false; - if (name == null) { - if (other.name != null) + } + if ( name == null ) { + if ( other.name != null ) { return false; - } else if (!name.equals(other.name)) + } + } + else if ( !name.equals( other.name ) ) { return false; + } return true; } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/accesstype/FieldAccessType.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/accesstype/FieldAccessType.java index 144935b7f3..965e8d6eb3 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/accesstype/FieldAccessType.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/accesstype/FieldAccessType.java @@ -24,52 +24,52 @@ package org.hibernate.envers.test.integration.accesstype; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Assert; -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; +import org.junit.Assert; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class FieldAccessType extends BaseEnversJPAFunctionalTestCase { - private Integer id1; + private Integer id1; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { FieldAccessTypeEntity.class }; - } + return new Class[] {FieldAccessTypeEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); - em.getTransaction().begin(); - FieldAccessTypeEntity fate = new FieldAccessTypeEntity("data"); - em.persist(fate); - id1 = fate.readId(); - em.getTransaction().commit(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); + em.getTransaction().begin(); + FieldAccessTypeEntity fate = new FieldAccessTypeEntity( "data" ); + em.persist( fate ); + id1 = fate.readId(); + em.getTransaction().commit(); - em.getTransaction().begin(); - fate = em.find(FieldAccessTypeEntity.class, id1); - fate.writeData("data2"); - em.getTransaction().commit(); - } + em.getTransaction().begin(); + fate = em.find( FieldAccessTypeEntity.class, id1 ); + fate.writeData( "data2" ); + em.getTransaction().commit(); + } - @Test - public void testRevisionsCounts() { - Assert.assertEquals( Arrays.asList( 1, 2 ), getAuditReader().getRevisions(FieldAccessTypeEntity.class, id1) ); - } + @Test + public void testRevisionsCounts() { + Assert.assertEquals( Arrays.asList( 1, 2 ), getAuditReader().getRevisions( FieldAccessTypeEntity.class, id1 ) ); + } - @Test - public void testHistoryOfId1() { - FieldAccessTypeEntity ver1 = new FieldAccessTypeEntity(id1, "data"); - FieldAccessTypeEntity ver2 = new FieldAccessTypeEntity(id1, "data2"); - Assert.assertEquals(ver1, getAuditReader().find(FieldAccessTypeEntity.class, id1, 1)); - Assert.assertEquals(ver2, getAuditReader().find(FieldAccessTypeEntity.class, id1, 2)); - } + @Test + public void testHistoryOfId1() { + FieldAccessTypeEntity ver1 = new FieldAccessTypeEntity( id1, "data" ); + FieldAccessTypeEntity ver2 = new FieldAccessTypeEntity( id1, "data2" ); + Assert.assertEquals( ver1, getAuditReader().find( FieldAccessTypeEntity.class, id1, 1 ) ); + Assert.assertEquals( ver2, getAuditReader().find( FieldAccessTypeEntity.class, id1, 2 ) ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/accesstype/FieldAccessTypeEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/accesstype/FieldAccessTypeEntity.java index 44a50b9872..5e9bce069c 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/accesstype/FieldAccessTypeEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/accesstype/FieldAccessTypeEntity.java @@ -23,6 +23,7 @@ */ package org.hibernate.envers.test.integration.accesstype; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; @@ -34,65 +35,73 @@ import org.hibernate.envers.Audited; */ @Entity public class FieldAccessTypeEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - @Audited - private String data; + @Audited + private String data; - public FieldAccessTypeEntity() { - } + public FieldAccessTypeEntity() { + } - public FieldAccessTypeEntity(String data) { - this.data = data; - } + public FieldAccessTypeEntity(String data) { + this.data = data; + } - public FieldAccessTypeEntity(Integer id, String data) { - this.id = id; - this.data = data; - } + public FieldAccessTypeEntity(Integer id, String data) { + this.id = id; + this.data = data; + } - public Integer getId() { - throw new RuntimeException(); - } + public Integer getId() { + throw new RuntimeException(); + } - public void setId(Integer id) { - throw new RuntimeException(); - } + public void setId(Integer id) { + throw new RuntimeException(); + } - public String getData() { - throw new RuntimeException(); - } + public String getData() { + throw new RuntimeException(); + } - public void setData(String data) { - throw new RuntimeException(); - } + public void setData(String data) { + throw new RuntimeException(); + } - public Integer readId() { - return id; - } + public Integer readId() { + return id; + } - public void writeData(String data) { - this.data = data; - } + public void writeData(String data) { + this.data = data; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof FieldAccessTypeEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof FieldAccessTypeEntity) ) { + return false; + } - FieldAccessTypeEntity that = (FieldAccessTypeEntity) o; + FieldAccessTypeEntity that = (FieldAccessTypeEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/accesstype/ImmutableClassAccessType.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/accesstype/ImmutableClassAccessType.java index 0a0f8e44d0..87528a1db0 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/accesstype/ImmutableClassAccessType.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/accesstype/ImmutableClassAccessType.java @@ -1,13 +1,13 @@ package org.hibernate.envers.test.integration.accesstype; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; +import org.junit.Test; + import static org.junit.Assert.assertEquals; public class ImmutableClassAccessType extends BaseEnversJPAFunctionalTestCase { @@ -15,38 +15,43 @@ public class ImmutableClassAccessType extends BaseEnversJPAFunctionalTestCase { @Override protected Class[] getAnnotatedClasses() { - return new Class[] { Country.class }; + return new Class[] {Country.class}; } @Test - @Priority(10) + @Priority(10) public void initData() { EntityManager em = getEntityManager(); // Revision 1 em.getTransaction().begin(); - country = Country.of(123, "Germany"); - em.persist(country); + country = Country.of( 123, "Germany" ); + em.persist( country ); em.getTransaction().commit(); } @Test public void testRevisionsCounts() { - assert Arrays.asList(1) + assert Arrays.asList( 1 ) .equals( - getAuditReader().getRevisions(Country.class, - country.getCode())); + getAuditReader().getRevisions( + Country.class, + country.getCode() + ) + ); } @Test public void testHistoryOfId1() { - Country country1 = getEntityManager().find(Country.class, - country.getCode()); - assertEquals(country1, country); + Country country1 = getEntityManager().find( + Country.class, + country.getCode() + ); + assertEquals( country1, country ); - Country history = getAuditReader().find(Country.class, country1.getCode(), 1); - assertEquals(country, history); + Country history = getAuditReader().find( Country.class, country1.getCode(), 1 ); + assertEquals( country, history ); } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/accesstype/MixedAccessType.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/accesstype/MixedAccessType.java index 5e585aef8c..16da037d15 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/accesstype/MixedAccessType.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/accesstype/MixedAccessType.java @@ -23,58 +23,58 @@ */ package org.hibernate.envers.test.integration.accesstype; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class MixedAccessType extends BaseEnversJPAFunctionalTestCase { - private Integer id1; + private Integer id1; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { MixedAccessTypeEntity.class }; - } + return new Class[] {MixedAccessTypeEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); - em.getTransaction().begin(); - MixedAccessTypeEntity mate = new MixedAccessTypeEntity("data"); - em.persist(mate); - id1 = mate.readId(); - em.getTransaction().commit(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); + em.getTransaction().begin(); + MixedAccessTypeEntity mate = new MixedAccessTypeEntity( "data" ); + em.persist( mate ); + id1 = mate.readId(); + em.getTransaction().commit(); - em.getTransaction().begin(); - mate = em.find(MixedAccessTypeEntity.class, id1); - mate.writeData("data2"); - em.getTransaction().commit(); - } + em.getTransaction().begin(); + mate = em.find( MixedAccessTypeEntity.class, id1 ); + mate.writeData( "data2" ); + em.getTransaction().commit(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(MixedAccessTypeEntity.class, id1)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( MixedAccessTypeEntity.class, id1 ) ); + } - @Test - public void testHistoryOfId1() { - MixedAccessTypeEntity ver1 = new MixedAccessTypeEntity(id1, "data"); - MixedAccessTypeEntity ver2 = new MixedAccessTypeEntity(id1, "data2"); + @Test + public void testHistoryOfId1() { + MixedAccessTypeEntity ver1 = new MixedAccessTypeEntity( id1, "data" ); + MixedAccessTypeEntity ver2 = new MixedAccessTypeEntity( id1, "data2" ); - MixedAccessTypeEntity rev1 = getAuditReader().find(MixedAccessTypeEntity.class, id1, 1); - MixedAccessTypeEntity rev2 = getAuditReader().find(MixedAccessTypeEntity.class, id1, 2); + MixedAccessTypeEntity rev1 = getAuditReader().find( MixedAccessTypeEntity.class, id1, 1 ); + MixedAccessTypeEntity rev2 = getAuditReader().find( MixedAccessTypeEntity.class, id1, 2 ); - assert rev1.isDataSet(); - assert rev2.isDataSet(); + assert rev1.isDataSet(); + assert rev2.isDataSet(); - assert rev1.equals(ver1); - assert rev2.equals(ver2); - } + assert rev1.equals( ver1 ); + assert rev2.equals( ver2 ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/accesstype/MixedAccessTypeEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/accesstype/MixedAccessTypeEntity.java index 20a603d342..df867fc111 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/accesstype/MixedAccessTypeEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/accesstype/MixedAccessTypeEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.accesstype; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; @@ -35,76 +36,84 @@ import org.hibernate.envers.Audited; */ @Entity public class MixedAccessTypeEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - @AccessType("property") - private String data; + @AccessType("property") + private String data; - @Transient - private boolean dataSet; + @Transient + private boolean dataSet; - public MixedAccessTypeEntity() { - } + public MixedAccessTypeEntity() { + } - public MixedAccessTypeEntity(String data) { - this.data = data; - } + public MixedAccessTypeEntity(String data) { + this.data = data; + } - public MixedAccessTypeEntity(Integer id, String data) { - this.id = id; - this.data = data; - } + public MixedAccessTypeEntity(Integer id, String data) { + this.id = id; + this.data = data; + } - public Integer getId() { - throw new RuntimeException(); - } + public Integer getId() { + throw new RuntimeException(); + } - public void setId(Integer id) { - throw new RuntimeException(); - } + public void setId(Integer id) { + throw new RuntimeException(); + } - // TODO: this should be on the property. But how to discover in AnnotationsMetadataReader that the - // we should read annotations from fields, even though the access type is "property"? - @Audited - public String getData() { - return data; - } + // TODO: this should be on the property. But how to discover in AnnotationsMetadataReader that the + // we should read annotations from fields, even though the access type is "property"? + @Audited + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - dataSet = true; - } + public void setData(String data) { + this.data = data; + dataSet = true; + } - public boolean isDataSet() { - return dataSet; - } + public boolean isDataSet() { + return dataSet; + } - public Integer readId() { - return id; - } + public Integer readId() { + return id; + } - public void writeData(String data) { - this.data = data; - } + public void writeData(String data) { + this.data = data; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof MixedAccessTypeEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof MixedAccessTypeEntity) ) { + return false; + } - MixedAccessTypeEntity that = (MixedAccessTypeEntity) o; + MixedAccessTypeEntity that = (MixedAccessTypeEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/accesstype/PropertyAccessType.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/accesstype/PropertyAccessType.java index 1a59940222..d8a838037a 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/accesstype/PropertyAccessType.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/accesstype/PropertyAccessType.java @@ -23,61 +23,61 @@ */ package org.hibernate.envers.test.integration.accesstype; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class PropertyAccessType extends BaseEnversJPAFunctionalTestCase { - private Integer id1; + private Integer id1; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { PropertyAccessTypeEntity.class }; - } + return new Class[] {PropertyAccessTypeEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); - em.getTransaction().begin(); - PropertyAccessTypeEntity pate = new PropertyAccessTypeEntity("data"); - em.persist(pate); - id1 = pate.getId(); - em.getTransaction().commit(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); + em.getTransaction().begin(); + PropertyAccessTypeEntity pate = new PropertyAccessTypeEntity( "data" ); + em.persist( pate ); + id1 = pate.getId(); + em.getTransaction().commit(); - em.getTransaction().begin(); - pate = em.find(PropertyAccessTypeEntity.class, id1); - pate.writeData("data2"); - em.getTransaction().commit(); - } + em.getTransaction().begin(); + pate = em.find( PropertyAccessTypeEntity.class, id1 ); + pate.writeData( "data2" ); + em.getTransaction().commit(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(PropertyAccessTypeEntity.class, id1)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( PropertyAccessTypeEntity.class, id1 ) ); + } - @Test - public void testHistoryOfId1() { - PropertyAccessTypeEntity ver1 = new PropertyAccessTypeEntity(id1, "data"); - PropertyAccessTypeEntity ver2 = new PropertyAccessTypeEntity(id1, "data2"); + @Test + public void testHistoryOfId1() { + PropertyAccessTypeEntity ver1 = new PropertyAccessTypeEntity( id1, "data" ); + PropertyAccessTypeEntity ver2 = new PropertyAccessTypeEntity( id1, "data2" ); - PropertyAccessTypeEntity rev1 = getAuditReader().find(PropertyAccessTypeEntity.class, id1, 1); - PropertyAccessTypeEntity rev2 = getAuditReader().find(PropertyAccessTypeEntity.class, id1, 2); + PropertyAccessTypeEntity rev1 = getAuditReader().find( PropertyAccessTypeEntity.class, id1, 1 ); + PropertyAccessTypeEntity rev2 = getAuditReader().find( PropertyAccessTypeEntity.class, id1, 2 ); - assert rev1.isIdSet(); - assert rev2.isIdSet(); + assert rev1.isIdSet(); + assert rev2.isIdSet(); - assert rev1.isDataSet(); - assert rev2.isDataSet(); + assert rev1.isDataSet(); + assert rev2.isDataSet(); - assert rev1.equals(ver1); - assert rev2.equals(ver2); - } + assert rev1.equals( ver1 ); + assert rev2.equals( ver2 ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/accesstype/PropertyAccessTypeEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/accesstype/PropertyAccessTypeEntity.java index 00a051cb85..5de03ec7dc 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/accesstype/PropertyAccessTypeEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/accesstype/PropertyAccessTypeEntity.java @@ -23,6 +23,7 @@ */ package org.hibernate.envers.test.integration.accesstype; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; @@ -35,75 +36,83 @@ import org.hibernate.envers.Audited; */ @Entity public class PropertyAccessTypeEntity { - private Integer id; - private String data; + private Integer id; + private String data; - private boolean idSet; - private boolean dataSet; + private boolean idSet; + private boolean dataSet; - public PropertyAccessTypeEntity() { - } + public PropertyAccessTypeEntity() { + } - public PropertyAccessTypeEntity(String data) { - this.data = data; - } + public PropertyAccessTypeEntity(String data) { + this.data = data; + } - public PropertyAccessTypeEntity(Integer id, String data) { - this.id = id; - this.data = data; - } + public PropertyAccessTypeEntity(Integer id, String data) { + this.id = id; + this.data = data; + } - @Id - @GeneratedValue - public Integer getId() { - return id; - } + @Id + @GeneratedValue + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - idSet = true; - } + public void setId(Integer id) { + this.id = id; + idSet = true; + } - @Audited - public String getData() { - return data; - } + @Audited + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - dataSet = true; - } + public void setData(String data) { + this.data = data; + dataSet = true; + } - @Transient - public boolean isIdSet() { - return idSet; - } + @Transient + public boolean isIdSet() { + return idSet; + } - @Transient - public boolean isDataSet() { - return dataSet; - } + @Transient + public boolean isDataSet() { + return dataSet; + } - public void writeData(String data) { - this.data = data; - } + public void writeData(String data) { + this.data = data; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof PropertyAccessTypeEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof PropertyAccessTypeEntity) ) { + return false; + } - PropertyAccessTypeEntity that = (PropertyAccessTypeEntity) o; + PropertyAccessTypeEntity that = (PropertyAccessTypeEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/auditReader/AuditReaderAPITest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/auditReader/AuditReaderAPITest.java index 86e5ff341d..14479e862f 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/auditReader/AuditReaderAPITest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/auditReader/AuditReaderAPITest.java @@ -23,66 +23,67 @@ */ package org.hibernate.envers.test.integration.auditReader; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.exception.NotAuditedException; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; +import org.junit.Test; + /** * A test which checks the correct behavior of AuditReader.isEntityClassAudited(Class entityClass). - * + * * @author Hernan Chanfreau */ public class AuditReaderAPITest extends BaseEnversJPAFunctionalTestCase { @Override protected Class[] getAnnotatedClasses() { - return new Class[] { AuditedTestEntity.class, NotAuditedTestEntity.class }; - } + return new Class[] {AuditedTestEntity.class, NotAuditedTestEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); - em.getTransaction().begin(); - AuditedTestEntity ent1 = new AuditedTestEntity(1, "str1"); - NotAuditedTestEntity ent2 = new NotAuditedTestEntity(1, "str1"); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); + em.getTransaction().begin(); + AuditedTestEntity ent1 = new AuditedTestEntity( 1, "str1" ); + NotAuditedTestEntity ent2 = new NotAuditedTestEntity( 1, "str1" ); - em.persist(ent1); - em.persist(ent2); - em.getTransaction().commit(); + em.persist( ent1 ); + em.persist( ent2 ); + em.getTransaction().commit(); - em.getTransaction().begin(); - - ent1 = em.find(AuditedTestEntity.class, 1); - ent2 = em.find(NotAuditedTestEntity.class, 1); - ent1.setStr1("str2"); - ent2.setStr1("str2"); - em.getTransaction().commit(); - } + em.getTransaction().begin(); - @Test - public void testIsEntityClassAuditedForAuditedEntity() { - assert getAuditReader().isEntityClassAudited(AuditedTestEntity.class); - - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(AuditedTestEntity.class, 1)); - } + ent1 = em.find( AuditedTestEntity.class, 1 ); + ent2 = em.find( NotAuditedTestEntity.class, 1 ); + ent1.setStr1( "str2" ); + ent2.setStr1( "str2" ); + em.getTransaction().commit(); + } - @Test - public void testIsEntityClassAuditedForNotAuditedEntity() { - - assert !getAuditReader().isEntityClassAudited(NotAuditedTestEntity.class); - - try { - getAuditReader().getRevisions(NotAuditedTestEntity.class, 1); - } catch (NotAuditedException nae) { - // it's ok because the entity is not audited - assert true; + @Test + public void testIsEntityClassAuditedForAuditedEntity() { + assert getAuditReader().isEntityClassAudited( AuditedTestEntity.class ); + + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( AuditedTestEntity.class, 1 ) ); + } + + @Test + public void testIsEntityClassAuditedForNotAuditedEntity() { + + assert !getAuditReader().isEntityClassAudited( NotAuditedTestEntity.class ); + + try { + getAuditReader().getRevisions( NotAuditedTestEntity.class, 1 ); } - } + catch (NotAuditedException nae) { + // it's ok because the entity is not audited + assert true; + } + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/auditReader/AuditedTestEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/auditReader/AuditedTestEntity.java index e918587ae6..c3d23ed8e5 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/auditReader/AuditedTestEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/auditReader/AuditedTestEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.auditReader; + import javax.persistence.Entity; import javax.persistence.Id; @@ -32,56 +33,64 @@ import org.hibernate.envers.Audited; */ @Entity public class AuditedTestEntity { - @Id - private Integer id; + @Id + private Integer id; - @Audited - private String str1; + @Audited + private String str1; - public AuditedTestEntity() { - } + public AuditedTestEntity() { + } - public AuditedTestEntity(String str1) { - this.str1 = str1; - } + public AuditedTestEntity(String str1) { + this.str1 = str1; + } - public AuditedTestEntity(Integer id, String str1) { - this.id = id; - this.str1 = str1; - } + public AuditedTestEntity(Integer id, String str1) { + this.id = id; + this.str1 = str1; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getStr1() { - return str1; - } + public String getStr1() { + return str1; + } - public void setStr1(String str1) { - this.str1 = str1; - } + public void setStr1(String str1) { + this.str1 = str1; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof AuditedTestEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof AuditedTestEntity) ) { + return false; + } - AuditedTestEntity that = (AuditedTestEntity) o; + AuditedTestEntity that = (AuditedTestEntity) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; - if (str1 != null ? !str1.equals(that.str1) : that.str1 != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } + if ( str1 != null ? !str1.equals( that.str1 ) : that.str1 != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (str1 != null ? str1.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (str1 != null ? str1.hashCode() : 0); + return result; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/auditReader/NotAuditedTestEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/auditReader/NotAuditedTestEntity.java index 76f375e63b..4238acabc7 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/auditReader/NotAuditedTestEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/auditReader/NotAuditedTestEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.auditReader; + import javax.persistence.Entity; import javax.persistence.Id; @@ -30,55 +31,63 @@ import javax.persistence.Id; */ @Entity public class NotAuditedTestEntity { - @Id - private Integer id; + @Id + private Integer id; - private String str1; + private String str1; - public NotAuditedTestEntity() { - } + public NotAuditedTestEntity() { + } - public NotAuditedTestEntity(String str1) { - this.str1 = str1; - } + public NotAuditedTestEntity(String str1) { + this.str1 = str1; + } - public NotAuditedTestEntity(Integer id, String str1) { - this.id = id; - this.str1 = str1; - } + public NotAuditedTestEntity(Integer id, String str1) { + this.id = id; + this.str1 = str1; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getStr1() { - return str1; - } + public String getStr1() { + return str1; + } - public void setStr1(String str1) { - this.str1 = str1; - } + public void setStr1(String str1) { + this.str1 = str1; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof NotAuditedTestEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof NotAuditedTestEntity) ) { + return false; + } - NotAuditedTestEntity that = (NotAuditedTestEntity) o; + NotAuditedTestEntity that = (NotAuditedTestEntity) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; - if (str1 != null ? !str1.equals(that.str1) : that.str1 != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } + if ( str1 != null ? !str1.equals( that.str1 ) : that.str1 != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (str1 != null ? str1.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (str1 != null ? str1.hashCode() : 0); + return result; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/BasicTestEntity1.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/BasicTestEntity1.java index 995acdf738..b508300b62 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/BasicTestEntity1.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/BasicTestEntity1.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.basic; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; @@ -33,72 +34,82 @@ import org.hibernate.envers.Audited; */ @Entity public class BasicTestEntity1 { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - @Audited - private String str1; + @Audited + private String str1; - @Audited - private long long1; + @Audited + private long long1; - public BasicTestEntity1() { - } + public BasicTestEntity1() { + } - public BasicTestEntity1(String str1, long long1) { - this.str1 = str1; - this.long1 = long1; - } + public BasicTestEntity1(String str1, long long1) { + this.str1 = str1; + this.long1 = long1; + } - public BasicTestEntity1(Integer id, String str1, long long1) { - this.id = id; - this.str1 = str1; - this.long1 = long1; - } + public BasicTestEntity1(Integer id, String str1, long long1) { + this.id = id; + this.str1 = str1; + this.long1 = long1; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getStr1() { - return str1; - } + public String getStr1() { + return str1; + } - public void setStr1(String str1) { - this.str1 = str1; - } + public void setStr1(String str1) { + this.str1 = str1; + } - public long getLong1() { - return long1; - } + public long getLong1() { + return long1; + } - public void setLong1(long long1) { - this.long1 = long1; - } + public void setLong1(long long1) { + this.long1 = long1; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof BasicTestEntity1)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof BasicTestEntity1) ) { + return false; + } - BasicTestEntity1 that = (BasicTestEntity1) o; + BasicTestEntity1 that = (BasicTestEntity1) o; - if (long1 != that.long1) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; - if (str1 != null ? !str1.equals(that.str1) : that.str1 != null) return false; + if ( long1 != that.long1 ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } + if ( str1 != null ? !str1.equals( that.str1 ) : that.str1 != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (str1 != null ? str1.hashCode() : 0); - result = 31 * result + (int) (long1 ^ (long1 >>> 32)); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (str1 != null ? str1.hashCode() : 0); + result = 31 * result + (int) (long1 ^ (long1 >>> 32)); + return result; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/BasicTestEntity2.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/BasicTestEntity2.java index 81d97855e1..dde40d9b95 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/BasicTestEntity2.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/BasicTestEntity2.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.basic; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; @@ -33,71 +34,81 @@ import org.hibernate.envers.Audited; */ @Entity public class BasicTestEntity2 { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - @Audited - private String str1; + @Audited + private String str1; - private String str2; + private String str2; - public BasicTestEntity2() { - } + public BasicTestEntity2() { + } - public BasicTestEntity2(String str1, String str2) { - this.str1 = str1; - this.str2 = str2; - } + public BasicTestEntity2(String str1, String str2) { + this.str1 = str1; + this.str2 = str2; + } - public BasicTestEntity2(Integer id, String str1, String str2) { - this.id = id; - this.str1 = str1; - this.str2 = str2; - } + public BasicTestEntity2(Integer id, String str1, String str2) { + this.id = id; + this.str1 = str1; + this.str2 = str2; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getStr1() { - return str1; - } + public String getStr1() { + return str1; + } - public void setStr1(String str1) { - this.str1 = str1; - } + public void setStr1(String str1) { + this.str1 = str1; + } - public String getStr2() { - return str2; - } + public String getStr2() { + return str2; + } - public void setStr2(String str2) { - this.str2 = str2; - } + public void setStr2(String str2) { + this.str2 = str2; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof BasicTestEntity2)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof BasicTestEntity2) ) { + return false; + } - BasicTestEntity2 that = (BasicTestEntity2) o; + BasicTestEntity2 that = (BasicTestEntity2) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; - if (str1 != null ? !str1.equals(that.str1) : that.str1 != null) return false; - if (str2 != null ? !str2.equals(that.str2) : that.str2 != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } + if ( str1 != null ? !str1.equals( that.str1 ) : that.str1 != null ) { + return false; + } + if ( str2 != null ? !str2.equals( that.str2 ) : that.str2 != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (str1 != null ? str1.hashCode() : 0); - result = 31 * result + (str2 != null ? str2.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (str1 != null ? str1.hashCode() : 0); + result = 31 * result + (str2 != null ? str2.hashCode() : 0); + return result; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/BasicTestEntity3.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/BasicTestEntity3.java index 9e394b5bb8..5b46fafcaf 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/BasicTestEntity3.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/BasicTestEntity3.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.basic; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; @@ -31,70 +32,80 @@ import javax.persistence.Id; */ @Entity public class BasicTestEntity3 { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - private String str1; + private String str1; - private String str2; + private String str2; - public BasicTestEntity3() { - } + public BasicTestEntity3() { + } - public BasicTestEntity3(String str1, String str2) { - this.str1 = str1; - this.str2 = str2; - } + public BasicTestEntity3(String str1, String str2) { + this.str1 = str1; + this.str2 = str2; + } - public BasicTestEntity3(Integer id, String str1, String str2) { - this.id = id; - this.str1 = str1; - this.str2 = str2; - } + public BasicTestEntity3(Integer id, String str1, String str2) { + this.id = id; + this.str1 = str1; + this.str2 = str2; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getStr1() { - return str1; - } + public String getStr1() { + return str1; + } - public void setStr1(String str1) { - this.str1 = str1; - } + public void setStr1(String str1) { + this.str1 = str1; + } - public String getStr2() { - return str2; - } + public String getStr2() { + return str2; + } - public void setStr2(String str2) { - this.str2 = str2; - } + public void setStr2(String str2) { + this.str2 = str2; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof BasicTestEntity3)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof BasicTestEntity3) ) { + return false; + } - BasicTestEntity3 that = (BasicTestEntity3) o; + BasicTestEntity3 that = (BasicTestEntity3) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; - if (str1 != null ? !str1.equals(that.str1) : that.str1 != null) return false; - if (str2 != null ? !str2.equals(that.str2) : that.str2 != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } + if ( str1 != null ? !str1.equals( that.str1 ) : that.str1 != null ) { + return false; + } + if ( str2 != null ? !str2.equals( that.str2 ) : that.str2 != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (str1 != null ? str1.hashCode() : 0); - result = 31 * result + (str2 != null ? str2.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (str1 != null ? str1.hashCode() : 0); + result = 31 * result + (str2 != null ? str2.hashCode() : 0); + return result; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/BasicTestEntity4.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/BasicTestEntity4.java index 6ad0e7ce8a..29e4282594 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/BasicTestEntity4.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/BasicTestEntity4.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.basic; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; @@ -34,70 +35,80 @@ import org.hibernate.envers.Audited; @Entity @Audited public class BasicTestEntity4 { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - private String str1; + private String str1; - private String str2; + private String str2; - public BasicTestEntity4() { - } + public BasicTestEntity4() { + } - public BasicTestEntity4(String str1, String str2) { - this.str1 = str1; - this.str2 = str2; - } + public BasicTestEntity4(String str1, String str2) { + this.str1 = str1; + this.str2 = str2; + } - public BasicTestEntity4(Integer id, String str1, String str2) { - this.id = id; - this.str1 = str1; - this.str2 = str2; - } + public BasicTestEntity4(Integer id, String str1, String str2) { + this.id = id; + this.str1 = str1; + this.str2 = str2; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getStr1() { - return str1; - } + public String getStr1() { + return str1; + } - public void setStr1(String str1) { - this.str1 = str1; - } + public void setStr1(String str1) { + this.str1 = str1; + } - public String getStr2() { - return str2; - } + public String getStr2() { + return str2; + } - public void setStr2(String str2) { - this.str2 = str2; - } + public void setStr2(String str2) { + this.str2 = str2; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof BasicTestEntity4)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof BasicTestEntity4) ) { + return false; + } - BasicTestEntity4 that = (BasicTestEntity4) o; + BasicTestEntity4 that = (BasicTestEntity4) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; - if (str1 != null ? !str1.equals(that.str1) : that.str1 != null) return false; - if (str2 != null ? !str2.equals(that.str2) : that.str2 != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } + if ( str1 != null ? !str1.equals( that.str1 ) : that.str1 != null ) { + return false; + } + if ( str2 != null ? !str2.equals( that.str2 ) : that.str2 != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (str1 != null ? str1.hashCode() : 0); - result = 31 * result + (str2 != null ? str2.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (str1 != null ? str1.hashCode() : 0); + result = 31 * result + (str2 != null ? str2.hashCode() : 0); + return result; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/ColumnScalePrecisionTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/ColumnScalePrecisionTest.java index 5bd1e4222a..d176ee1e8d 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/ColumnScalePrecisionTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/ColumnScalePrecisionTest.java @@ -1,15 +1,16 @@ package org.hibernate.envers.test.integration.basic; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Assert; -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.mapping.Column; import org.hibernate.mapping.Table; + +import org.junit.Assert; +import org.junit.Test; + import org.hibernate.testing.TestForIssue; /** @@ -17,51 +18,53 @@ import org.hibernate.testing.TestForIssue; */ @TestForIssue(jiraKey = "HHH-7003") public class ColumnScalePrecisionTest extends BaseEnversJPAFunctionalTestCase { - private Table auditTable = null; - private Table originalTable = null; - private Long id = null; + private Table auditTable = null; + private Table originalTable = null; + private Long id = null; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { ScalePrecisionEntity.class }; - } + return new Class[] {ScalePrecisionEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - // Revision 1 - em.getTransaction().begin(); - ScalePrecisionEntity entity = new ScalePrecisionEntity(13.0); - em.persist(entity); - em.getTransaction().commit(); + // Revision 1 + em.getTransaction().begin(); + ScalePrecisionEntity entity = new ScalePrecisionEntity( 13.0 ); + em.persist( entity ); + em.getTransaction().commit(); - id = entity.getId(); - auditTable = getCfg().getClassMapping("org.hibernate.envers.test.integration.basic.ScalePrecisionEntity_AUD").getTable(); - originalTable = getCfg().getClassMapping("org.hibernate.envers.test.integration.basic.ScalePrecisionEntity").getTable(); - } + id = entity.getId(); + auditTable = getCfg().getClassMapping( "org.hibernate.envers.test.integration.basic.ScalePrecisionEntity_AUD" ) + .getTable(); + originalTable = getCfg().getClassMapping( "org.hibernate.envers.test.integration.basic.ScalePrecisionEntity" ) + .getTable(); + } - @Test - public void testColumnScalePrecision() { - Column testColumn = new Column("wholeNumber"); - Column scalePrecisionAuditColumn = auditTable.getColumn(testColumn); - Column scalePrecisionColumn = originalTable.getColumn(testColumn); + @Test + public void testColumnScalePrecision() { + Column testColumn = new Column( "wholeNumber" ); + Column scalePrecisionAuditColumn = auditTable.getColumn( testColumn ); + Column scalePrecisionColumn = originalTable.getColumn( testColumn ); - Assert.assertNotNull(scalePrecisionAuditColumn); - Assert.assertEquals(scalePrecisionColumn.getPrecision(), scalePrecisionAuditColumn.getPrecision()); - Assert.assertEquals(scalePrecisionColumn.getScale(), scalePrecisionAuditColumn.getScale()); - } + Assert.assertNotNull( scalePrecisionAuditColumn ); + Assert.assertEquals( scalePrecisionColumn.getPrecision(), scalePrecisionAuditColumn.getPrecision() ); + Assert.assertEquals( scalePrecisionColumn.getScale(), scalePrecisionAuditColumn.getScale() ); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1).equals(getAuditReader().getRevisions(ScalePrecisionEntity.class, id)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1 ).equals( getAuditReader().getRevisions( ScalePrecisionEntity.class, id ) ); + } - @Test - public void testHistoryOfScalePrecisionEntity() { - ScalePrecisionEntity ver1 = new ScalePrecisionEntity(13.0, id); + @Test + public void testHistoryOfScalePrecisionEntity() { + ScalePrecisionEntity ver1 = new ScalePrecisionEntity( 13.0, id ); - Assert.assertEquals(ver1, getAuditReader().find(ScalePrecisionEntity.class, id, 1)); - } + Assert.assertEquals( ver1, getAuditReader().find( ScalePrecisionEntity.class, id, 1 ) ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/Delete.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/Delete.java index d3589e03cc..d70e6c761b 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/Delete.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/Delete.java @@ -23,116 +23,116 @@ */ package org.hibernate.envers.test.integration.basic; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ -public class Delete extends BaseEnversJPAFunctionalTestCase { - private Integer id1; - private Integer id2; - private Integer id3; +public class Delete extends BaseEnversJPAFunctionalTestCase { + private Integer id1; + private Integer id2; + private Integer id3; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { BasicTestEntity2.class }; - } + return new Class[] {BasicTestEntity2.class}; + } - @Test - @Priority(10) - public void initData() { - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); + @Test + @Priority(10) + public void initData() { + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); - BasicTestEntity2 bte1 = new BasicTestEntity2("x", "a"); - BasicTestEntity2 bte2 = new BasicTestEntity2("y", "b"); - BasicTestEntity2 bte3 = new BasicTestEntity2("z", "c"); - em.persist(bte1); - em.persist(bte2); - em.persist(bte3); + BasicTestEntity2 bte1 = new BasicTestEntity2( "x", "a" ); + BasicTestEntity2 bte2 = new BasicTestEntity2( "y", "b" ); + BasicTestEntity2 bte3 = new BasicTestEntity2( "z", "c" ); + em.persist( bte1 ); + em.persist( bte2 ); + em.persist( bte3 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em = getEntityManager(); - em.getTransaction().begin(); + // Revision 2 + em = getEntityManager(); + em.getTransaction().begin(); - bte1 = em.find(BasicTestEntity2.class, bte1.getId()); - bte2 = em.find(BasicTestEntity2.class, bte2.getId()); - bte3 = em.find(BasicTestEntity2.class, bte3.getId()); - bte1.setStr1("x2"); - bte2.setStr2("b2"); - em.remove(bte3); + bte1 = em.find( BasicTestEntity2.class, bte1.getId() ); + bte2 = em.find( BasicTestEntity2.class, bte2.getId() ); + bte3 = em.find( BasicTestEntity2.class, bte3.getId() ); + bte1.setStr1( "x2" ); + bte2.setStr2( "b2" ); + em.remove( bte3 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 - em = getEntityManager(); - em.getTransaction().begin(); + // Revision 3 + em = getEntityManager(); + em.getTransaction().begin(); - bte2 = em.find(BasicTestEntity2.class, bte2.getId()); - em.remove(bte2); + bte2 = em.find( BasicTestEntity2.class, bte2.getId() ); + em.remove( bte2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 4 - em = getEntityManager(); - em.getTransaction().begin(); + // Revision 4 + em = getEntityManager(); + em.getTransaction().begin(); - bte1 = em.find(BasicTestEntity2.class, bte1.getId()); - em.remove(bte1); + bte1 = em.find( BasicTestEntity2.class, bte1.getId() ); + em.remove( bte1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - id1 = bte1.getId(); - id2 = bte2.getId(); - id3 = bte3.getId(); - } + id1 = bte1.getId(); + id2 = bte2.getId(); + id3 = bte3.getId(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2, 4).equals(getAuditReader().getRevisions(BasicTestEntity2.class, id1)); + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2, 4 ).equals( getAuditReader().getRevisions( BasicTestEntity2.class, id1 ) ); - assert Arrays.asList(1, 3).equals(getAuditReader().getRevisions(BasicTestEntity2.class, id2)); + assert Arrays.asList( 1, 3 ).equals( getAuditReader().getRevisions( BasicTestEntity2.class, id2 ) ); - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(BasicTestEntity2.class, id3)); - } + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( BasicTestEntity2.class, id3 ) ); + } - @Test - public void testHistoryOfId1() { - BasicTestEntity2 ver1 = new BasicTestEntity2(id1, "x", null); - BasicTestEntity2 ver2 = new BasicTestEntity2(id1, "x2", null); + @Test + public void testHistoryOfId1() { + BasicTestEntity2 ver1 = new BasicTestEntity2( id1, "x", null ); + BasicTestEntity2 ver2 = new BasicTestEntity2( id1, "x2", null ); - assert getAuditReader().find(BasicTestEntity2.class, id1, 1).equals(ver1); - assert getAuditReader().find(BasicTestEntity2.class, id1, 2).equals(ver2); - assert getAuditReader().find(BasicTestEntity2.class, id1, 3).equals(ver2); - assert getAuditReader().find(BasicTestEntity2.class, id1, 4) == null; - } + assert getAuditReader().find( BasicTestEntity2.class, id1, 1 ).equals( ver1 ); + assert getAuditReader().find( BasicTestEntity2.class, id1, 2 ).equals( ver2 ); + assert getAuditReader().find( BasicTestEntity2.class, id1, 3 ).equals( ver2 ); + assert getAuditReader().find( BasicTestEntity2.class, id1, 4 ) == null; + } - @Test - public void testHistoryOfId2() { - BasicTestEntity2 ver1 = new BasicTestEntity2(id2, "y", null); + @Test + public void testHistoryOfId2() { + BasicTestEntity2 ver1 = new BasicTestEntity2( id2, "y", null ); - assert getAuditReader().find(BasicTestEntity2.class, id2, 1).equals(ver1); - assert getAuditReader().find(BasicTestEntity2.class, id2, 2).equals(ver1); - assert getAuditReader().find(BasicTestEntity2.class, id2, 3) == null; - assert getAuditReader().find(BasicTestEntity2.class, id2, 4) == null; - } + assert getAuditReader().find( BasicTestEntity2.class, id2, 1 ).equals( ver1 ); + assert getAuditReader().find( BasicTestEntity2.class, id2, 2 ).equals( ver1 ); + assert getAuditReader().find( BasicTestEntity2.class, id2, 3 ) == null; + assert getAuditReader().find( BasicTestEntity2.class, id2, 4 ) == null; + } - @Test - public void testHistoryOfId3() { - BasicTestEntity2 ver1 = new BasicTestEntity2(id3, "z", null); + @Test + public void testHistoryOfId3() { + BasicTestEntity2 ver1 = new BasicTestEntity2( id3, "z", null ); - assert getAuditReader().find(BasicTestEntity2.class, id3, 1).equals(ver1); - assert getAuditReader().find(BasicTestEntity2.class, id3, 2) == null; - assert getAuditReader().find(BasicTestEntity2.class, id3, 3) == null; - assert getAuditReader().find(BasicTestEntity2.class, id3, 4) == null; - } + assert getAuditReader().find( BasicTestEntity2.class, id3, 1 ).equals( ver1 ); + assert getAuditReader().find( BasicTestEntity2.class, id3, 2 ) == null; + assert getAuditReader().find( BasicTestEntity2.class, id3, 3 ) == null; + assert getAuditReader().find( BasicTestEntity2.class, id3, 4 ) == null; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/EmptyStringTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/EmptyStringTest.java index 381c28ea9e..e40866fcba 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/EmptyStringTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/EmptyStringTest.java @@ -1,15 +1,16 @@ package org.hibernate.envers.test.integration.basic; -import java.util.Arrays; import javax.persistence.EntityManager; - -import junit.framework.Assert; -import org.junit.Test; +import java.util.Arrays; import org.hibernate.dialect.Oracle8iDialect; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrTestEntity; + +import org.junit.Test; +import junit.framework.Assert; + import org.hibernate.testing.RequiresDialect; import org.hibernate.testing.TestForIssue; @@ -19,49 +20,49 @@ import org.hibernate.testing.TestForIssue; @TestForIssue(jiraKey = "HHH-7246") @RequiresDialect(Oracle8iDialect.class) public class EmptyStringTest extends BaseEnversJPAFunctionalTestCase { - private Integer emptyId = null; - private Integer nullId = null; + private Integer emptyId = null; + private Integer nullId = null; - @Override - protected Class[] getAnnotatedClasses() { - return new Class[]{StrTestEntity.class}; - } + @Override + protected Class[] getAnnotatedClasses() { + return new Class[] {StrTestEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - // Revision 1 - em.getTransaction().begin(); - StrTestEntity emptyEntity = new StrTestEntity(""); - em.persist(emptyEntity); - StrTestEntity nullEntity = new StrTestEntity(null); - em.persist(nullEntity); - em.getTransaction().commit(); + // Revision 1 + em.getTransaction().begin(); + StrTestEntity emptyEntity = new StrTestEntity( "" ); + em.persist( emptyEntity ); + StrTestEntity nullEntity = new StrTestEntity( null ); + em.persist( nullEntity ); + em.getTransaction().commit(); - emptyId = emptyEntity.getId(); - nullId = nullEntity.getId(); + emptyId = emptyEntity.getId(); + nullId = nullEntity.getId(); - em.close(); - em = getEntityManager(); + em.close(); + em = getEntityManager(); - // Should not generate revision after NULL to "" modification and vice versa on Oracle. - em.getTransaction().begin(); - emptyEntity = em.find(StrTestEntity.class, emptyId); - emptyEntity.setStr(null); - em.merge(emptyEntity); - nullEntity = em.find(StrTestEntity.class, nullId); - nullEntity.setStr(""); - em.merge(nullEntity); - em.getTransaction().commit(); + // Should not generate revision after NULL to "" modification and vice versa on Oracle. + em.getTransaction().begin(); + emptyEntity = em.find( StrTestEntity.class, emptyId ); + emptyEntity.setStr( null ); + em.merge( emptyEntity ); + nullEntity = em.find( StrTestEntity.class, nullId ); + nullEntity.setStr( "" ); + em.merge( nullEntity ); + em.getTransaction().commit(); - em.close(); - } + em.close(); + } - @Test - public void testRevisionsCounts() { - Assert.assertEquals(Arrays.asList(1), getAuditReader().getRevisions(StrTestEntity.class, emptyId)); - Assert.assertEquals(Arrays.asList(1), getAuditReader().getRevisions(StrTestEntity.class, nullId)); - } + @Test + public void testRevisionsCounts() { + Assert.assertEquals( Arrays.asList( 1 ), getAuditReader().getRevisions( StrTestEntity.class, emptyId ) ); + Assert.assertEquals( Arrays.asList( 1 ), getAuditReader().getRevisions( StrTestEntity.class, nullId ) ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/GlobalVersioned.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/GlobalVersioned.java index b323016d17..e51a25816f 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/GlobalVersioned.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/GlobalVersioned.java @@ -23,53 +23,53 @@ */ package org.hibernate.envers.test.integration.basic; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class GlobalVersioned extends BaseEnversJPAFunctionalTestCase { - private Integer id1; + private Integer id1; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { BasicTestEntity4.class }; - } + return new Class[] {BasicTestEntity4.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); - em.getTransaction().begin(); - BasicTestEntity4 bte1 = new BasicTestEntity4("x", "y"); - em.persist(bte1); - id1 = bte1.getId(); - em.getTransaction().commit(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); + em.getTransaction().begin(); + BasicTestEntity4 bte1 = new BasicTestEntity4( "x", "y" ); + em.persist( bte1 ); + id1 = bte1.getId(); + em.getTransaction().commit(); - em.getTransaction().begin(); - bte1 = em.find(BasicTestEntity4.class, id1); - bte1.setStr1("a"); - bte1.setStr2("b"); - em.getTransaction().commit(); - } + em.getTransaction().begin(); + bte1 = em.find( BasicTestEntity4.class, id1 ); + bte1.setStr1( "a" ); + bte1.setStr2( "b" ); + em.getTransaction().commit(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(BasicTestEntity4.class, id1)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( BasicTestEntity4.class, id1 ) ); + } - @Test - public void testHistoryOfId1() { - BasicTestEntity4 ver1 = new BasicTestEntity4(id1, "x", "y"); - BasicTestEntity4 ver2 = new BasicTestEntity4(id1, "a", "b"); + @Test + public void testHistoryOfId1() { + BasicTestEntity4 ver1 = new BasicTestEntity4( id1, "x", "y" ); + BasicTestEntity4 ver2 = new BasicTestEntity4( id1, "a", "b" ); - assert getAuditReader().find(BasicTestEntity4.class, id1, 1).equals(ver1); - assert getAuditReader().find(BasicTestEntity4.class, id1, 2).equals(ver2); - } + assert getAuditReader().find( BasicTestEntity4.class, id1, 1 ).equals( ver1 ); + assert getAuditReader().find( BasicTestEntity4.class, id1, 2 ).equals( ver2 ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/ManyOperationsInTransaction.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/ManyOperationsInTransaction.java index c61fff3dbe..46d928c589 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/ManyOperationsInTransaction.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/ManyOperationsInTransaction.java @@ -23,107 +23,107 @@ */ package org.hibernate.envers.test.integration.basic; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class ManyOperationsInTransaction extends BaseEnversJPAFunctionalTestCase { - private Integer id1; - private Integer id2; - private Integer id3; + private Integer id1; + private Integer id2; + private Integer id3; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { BasicTestEntity1.class }; - } + return new Class[] {BasicTestEntity1.class}; + } - @Test + @Test - @Priority(10) - public void initData() { - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); + @Priority(10) + public void initData() { + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); - BasicTestEntity1 bte1 = new BasicTestEntity1("x", 1); - BasicTestEntity1 bte2 = new BasicTestEntity1("y", 20); - em.persist(bte1); - em.persist(bte2); + BasicTestEntity1 bte1 = new BasicTestEntity1( "x", 1 ); + BasicTestEntity1 bte2 = new BasicTestEntity1( "y", 20 ); + em.persist( bte1 ); + em.persist( bte2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); + // Revision 2 + em.getTransaction().begin(); - bte1 = em.find(BasicTestEntity1.class, bte1.getId()); - bte2 = em.find(BasicTestEntity1.class, bte2.getId()); - BasicTestEntity1 bte3 = new BasicTestEntity1("z", 300); - bte1.setStr1("x2"); - bte2.setLong1(21); - em.persist(bte3); + bte1 = em.find( BasicTestEntity1.class, bte1.getId() ); + bte2 = em.find( BasicTestEntity1.class, bte2.getId() ); + BasicTestEntity1 bte3 = new BasicTestEntity1( "z", 300 ); + bte1.setStr1( "x2" ); + bte2.setLong1( 21 ); + em.persist( bte3 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 - em.getTransaction().begin(); + // Revision 3 + em.getTransaction().begin(); - bte2 = em.find(BasicTestEntity1.class, bte2.getId()); - bte3 = em.find(BasicTestEntity1.class, bte3.getId()); - bte2.setStr1("y3"); - bte2.setLong1(22); - bte3.setStr1("z3"); + bte2 = em.find( BasicTestEntity1.class, bte2.getId() ); + bte3 = em.find( BasicTestEntity1.class, bte3.getId() ); + bte2.setStr1( "y3" ); + bte2.setLong1( 22 ); + bte3.setStr1( "z3" ); - em.getTransaction().commit(); + em.getTransaction().commit(); - id1 = bte1.getId(); - id2 = bte2.getId(); - id3 = bte3.getId(); - } + id1 = bte1.getId(); + id2 = bte2.getId(); + id3 = bte3.getId(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(BasicTestEntity1.class, id1)); + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( BasicTestEntity1.class, id1 ) ); - assert Arrays.asList(1, 2, 3).equals(getAuditReader().getRevisions(BasicTestEntity1.class, id2)); + assert Arrays.asList( 1, 2, 3 ).equals( getAuditReader().getRevisions( BasicTestEntity1.class, id2 ) ); - assert Arrays.asList(2, 3).equals(getAuditReader().getRevisions(BasicTestEntity1.class, id3)); - } + assert Arrays.asList( 2, 3 ).equals( getAuditReader().getRevisions( BasicTestEntity1.class, id3 ) ); + } - @Test - public void testHistoryOfId1() { - BasicTestEntity1 ver1 = new BasicTestEntity1(id1, "x", 1); - BasicTestEntity1 ver2 = new BasicTestEntity1(id1, "x2", 1); + @Test + public void testHistoryOfId1() { + BasicTestEntity1 ver1 = new BasicTestEntity1( id1, "x", 1 ); + BasicTestEntity1 ver2 = new BasicTestEntity1( id1, "x2", 1 ); - assert getAuditReader().find(BasicTestEntity1.class, id1, 1).equals(ver1); - assert getAuditReader().find(BasicTestEntity1.class, id1, 2).equals(ver2); - assert getAuditReader().find(BasicTestEntity1.class, id1, 3).equals(ver2); - } + assert getAuditReader().find( BasicTestEntity1.class, id1, 1 ).equals( ver1 ); + assert getAuditReader().find( BasicTestEntity1.class, id1, 2 ).equals( ver2 ); + assert getAuditReader().find( BasicTestEntity1.class, id1, 3 ).equals( ver2 ); + } - @Test - public void testHistoryOfId2() { - BasicTestEntity1 ver1 = new BasicTestEntity1(id2, "y", 20); - BasicTestEntity1 ver2 = new BasicTestEntity1(id2, "y", 21); - BasicTestEntity1 ver3 = new BasicTestEntity1(id2, "y3", 22); + @Test + public void testHistoryOfId2() { + BasicTestEntity1 ver1 = new BasicTestEntity1( id2, "y", 20 ); + BasicTestEntity1 ver2 = new BasicTestEntity1( id2, "y", 21 ); + BasicTestEntity1 ver3 = new BasicTestEntity1( id2, "y3", 22 ); - assert getAuditReader().find(BasicTestEntity1.class, id2, 1).equals(ver1); - assert getAuditReader().find(BasicTestEntity1.class, id2, 2).equals(ver2); - assert getAuditReader().find(BasicTestEntity1.class, id2, 3).equals(ver3); - } + assert getAuditReader().find( BasicTestEntity1.class, id2, 1 ).equals( ver1 ); + assert getAuditReader().find( BasicTestEntity1.class, id2, 2 ).equals( ver2 ); + assert getAuditReader().find( BasicTestEntity1.class, id2, 3 ).equals( ver3 ); + } - @Test - public void testHistoryOfId3() { - BasicTestEntity1 ver1 = new BasicTestEntity1(id3, "z", 300); - BasicTestEntity1 ver2 = new BasicTestEntity1(id3, "z3", 300); + @Test + public void testHistoryOfId3() { + BasicTestEntity1 ver1 = new BasicTestEntity1( id3, "z", 300 ); + BasicTestEntity1 ver2 = new BasicTestEntity1( id3, "z3", 300 ); - assert getAuditReader().find(BasicTestEntity1.class, id3, 1) == null; - assert getAuditReader().find(BasicTestEntity1.class, id3, 2).equals(ver1); - assert getAuditReader().find(BasicTestEntity1.class, id3, 3).equals(ver2); - } + assert getAuditReader().find( BasicTestEntity1.class, id3, 1 ) == null; + assert getAuditReader().find( BasicTestEntity1.class, id3, 2 ).equals( ver1 ); + assert getAuditReader().find( BasicTestEntity1.class, id3, 3 ).equals( ver2 ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/NoneAudited.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/NoneAudited.java index f294ef5d99..2acf054521 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/NoneAudited.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/NoneAudited.java @@ -27,34 +27,34 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import org.junit.Assert; -import org.junit.Test; - import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.mapping.PersistentClass; +import org.junit.Assert; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class NoneAudited extends BaseEnversJPAFunctionalTestCase { @Override protected Class[] getAnnotatedClasses() { - return new Class[] { BasicTestEntity3.class }; - } + return new Class[] {BasicTestEntity3.class}; + } - @Test - public void testRevisionInfoTableNotCreated() { - @SuppressWarnings({"unchecked"}) List pcs = iteratorToList(getCfg().getClassMappings()); - Assert.assertEquals(1, pcs.size()); - Assert.assertTrue(pcs.get(0).getClassName().contains("BasicTestEntity3")); - } + @Test + public void testRevisionInfoTableNotCreated() { + @SuppressWarnings({"unchecked"}) List pcs = iteratorToList( getCfg().getClassMappings() ); + Assert.assertEquals( 1, pcs.size() ); + Assert.assertTrue( pcs.get( 0 ).getClassName().contains( "BasicTestEntity3" ) ); + } - private List iteratorToList(Iterator it) { - List result = new ArrayList(); - while (it.hasNext()) { - result.add(it.next()); - } + private List iteratorToList(Iterator it) { + List result = new ArrayList(); + while ( it.hasNext() ) { + result.add( it.next() ); + } - return result; - } + return result; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/NotVersioned.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/NotVersioned.java index d9311d97f0..6cd5ee2be6 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/NotVersioned.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/NotVersioned.java @@ -25,47 +25,47 @@ package org.hibernate.envers.test.integration.basic; import javax.persistence.EntityManager; -import org.junit.Test; - import org.hibernate.envers.exception.NotAuditedException; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class NotVersioned extends BaseEnversJPAFunctionalTestCase { - private Integer id1; + private Integer id1; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { BasicTestEntity1.class, BasicTestEntity3.class }; - } + return new Class[] {BasicTestEntity1.class, BasicTestEntity3.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); - em.getTransaction().begin(); - BasicTestEntity3 bte1 = new BasicTestEntity3("x", "y"); - em.persist(bte1); - id1 = bte1.getId(); - em.getTransaction().commit(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); + em.getTransaction().begin(); + BasicTestEntity3 bte1 = new BasicTestEntity3( "x", "y" ); + em.persist( bte1 ); + id1 = bte1.getId(); + em.getTransaction().commit(); - em.getTransaction().begin(); - bte1 = em.find(BasicTestEntity3.class, id1); - bte1.setStr1("a"); - bte1.setStr2("b"); - em.getTransaction().commit(); - } + em.getTransaction().begin(); + bte1 = em.find( BasicTestEntity3.class, id1 ); + bte1.setStr1( "a" ); + bte1.setStr2( "b" ); + em.getTransaction().commit(); + } - @Test(expected = NotAuditedException.class) - public void testRevisionsCounts() { - getAuditReader().getRevisions(BasicTestEntity3.class, id1); - } + @Test(expected = NotAuditedException.class) + public void testRevisionsCounts() { + getAuditReader().getRevisions( BasicTestEntity3.class, id1 ); + } - @Test(expected = NotAuditedException.class) - public void testHistoryOfId1() { - getAuditReader().find(BasicTestEntity3.class, id1, 1); - } + @Test(expected = NotAuditedException.class) + public void testHistoryOfId1() { + getAuditReader().find( BasicTestEntity3.class, id1, 1 ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/NullProperties.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/NullProperties.java index 35e32268d2..b6dc7febd4 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/NullProperties.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/NullProperties.java @@ -23,81 +23,81 @@ */ package org.hibernate.envers.test.integration.basic; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class NullProperties extends BaseEnversJPAFunctionalTestCase { - private Integer id1; - private Integer id2; + private Integer id1; + private Integer id2; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { BasicTestEntity1.class }; - } + return new Class[] {BasicTestEntity1.class}; + } - private Integer addNewEntity(String str, long lng) { - EntityManager em = getEntityManager(); - em.getTransaction().begin(); - BasicTestEntity1 bte1 = new BasicTestEntity1(str, lng); - em.persist(bte1); - em.getTransaction().commit(); + private Integer addNewEntity(String str, long lng) { + EntityManager em = getEntityManager(); + em.getTransaction().begin(); + BasicTestEntity1 bte1 = new BasicTestEntity1( str, lng ); + em.persist( bte1 ); + em.getTransaction().commit(); - return bte1.getId(); - } + return bte1.getId(); + } - private void modifyEntity(Integer id, String str, long lng) { - EntityManager em = getEntityManager(); - em.getTransaction().begin(); - BasicTestEntity1 bte1 = em.find(BasicTestEntity1.class, id); - bte1.setLong1(lng); - bte1.setStr1(str); - em.getTransaction().commit(); - } + private void modifyEntity(Integer id, String str, long lng) { + EntityManager em = getEntityManager(); + em.getTransaction().begin(); + BasicTestEntity1 bte1 = em.find( BasicTestEntity1.class, id ); + bte1.setLong1( lng ); + bte1.setStr1( str ); + em.getTransaction().commit(); + } - @Test - @Priority(10) - public void initData() { - id1 = addNewEntity("x", 1); // rev 1 - id2 = addNewEntity(null, 20); // rev 2 + @Test + @Priority(10) + public void initData() { + id1 = addNewEntity( "x", 1 ); // rev 1 + id2 = addNewEntity( null, 20 ); // rev 2 - modifyEntity(id1, null, 1); // rev 3 - modifyEntity(id2, "y2", 20); // rev 4 - } + modifyEntity( id1, null, 1 ); // rev 3 + modifyEntity( id2, "y2", 20 ); // rev 4 + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 3).equals(getAuditReader().getRevisions(BasicTestEntity1.class, id1)); + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 3 ).equals( getAuditReader().getRevisions( BasicTestEntity1.class, id1 ) ); - assert Arrays.asList(2, 4).equals(getAuditReader().getRevisions(BasicTestEntity1.class, id2)); - } + assert Arrays.asList( 2, 4 ).equals( getAuditReader().getRevisions( BasicTestEntity1.class, id2 ) ); + } - @Test - public void testHistoryOfId1() { - BasicTestEntity1 ver1 = new BasicTestEntity1(id1, "x", 1); - BasicTestEntity1 ver2 = new BasicTestEntity1(id1, null, 1); + @Test + public void testHistoryOfId1() { + BasicTestEntity1 ver1 = new BasicTestEntity1( id1, "x", 1 ); + BasicTestEntity1 ver2 = new BasicTestEntity1( id1, null, 1 ); - assert getAuditReader().find(BasicTestEntity1.class, id1, 1).equals(ver1); - assert getAuditReader().find(BasicTestEntity1.class, id1, 2).equals(ver1); - assert getAuditReader().find(BasicTestEntity1.class, id1, 3).equals(ver2); - assert getAuditReader().find(BasicTestEntity1.class, id1, 4).equals(ver2); - } + assert getAuditReader().find( BasicTestEntity1.class, id1, 1 ).equals( ver1 ); + assert getAuditReader().find( BasicTestEntity1.class, id1, 2 ).equals( ver1 ); + assert getAuditReader().find( BasicTestEntity1.class, id1, 3 ).equals( ver2 ); + assert getAuditReader().find( BasicTestEntity1.class, id1, 4 ).equals( ver2 ); + } - @Test - public void testHistoryOfId2() { - BasicTestEntity1 ver1 = new BasicTestEntity1(id2, null, 20); - BasicTestEntity1 ver2 = new BasicTestEntity1(id2, "y2", 20); + @Test + public void testHistoryOfId2() { + BasicTestEntity1 ver1 = new BasicTestEntity1( id2, null, 20 ); + BasicTestEntity1 ver2 = new BasicTestEntity1( id2, "y2", 20 ); - assert getAuditReader().find(BasicTestEntity1.class, id2, 1) == null; - assert getAuditReader().find(BasicTestEntity1.class, id2, 2).equals(ver1); - assert getAuditReader().find(BasicTestEntity1.class, id2, 3).equals(ver1); - assert getAuditReader().find(BasicTestEntity1.class, id2, 4).equals(ver2); - } + assert getAuditReader().find( BasicTestEntity1.class, id2, 1 ) == null; + assert getAuditReader().find( BasicTestEntity1.class, id2, 2 ).equals( ver1 ); + assert getAuditReader().find( BasicTestEntity1.class, id2, 3 ).equals( ver1 ); + assert getAuditReader().find( BasicTestEntity1.class, id2, 4 ).equals( ver2 ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/OutsideTransactionTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/OutsideTransactionTest.java index 7eeffd735f..32129e1431 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/OutsideTransactionTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/OutsideTransactionTest.java @@ -1,7 +1,5 @@ package org.hibernate.envers.test.integration.basic; -import org.junit.Test; - import org.hibernate.Session; import org.hibernate.cfg.Configuration; import org.hibernate.envers.configuration.EnversSettings; @@ -10,6 +8,9 @@ import org.hibernate.envers.test.BaseEnversFunctionalTestCase; import org.hibernate.envers.test.entities.StrTestEntity; import org.hibernate.envers.test.integration.collection.norevision.Name; import org.hibernate.envers.test.integration.collection.norevision.Person; + +import org.junit.Test; + import org.hibernate.testing.TestForIssue; /** @@ -17,103 +18,103 @@ import org.hibernate.testing.TestForIssue; */ @TestForIssue(jiraKey = "HHH-5565") public class OutsideTransactionTest extends BaseEnversFunctionalTestCase { - @Override - protected Class[] getAnnotatedClasses() { - return new Class[]{StrTestEntity.class, Person.class, Name.class}; - } + @Override + protected Class[] getAnnotatedClasses() { + return new Class[] {StrTestEntity.class, Person.class, Name.class}; + } - @Override - protected void configure(Configuration configuration) { - configuration.setProperty(EnversSettings.STORE_DATA_AT_DELETE, "true"); - configuration.setProperty(EnversSettings.REVISION_ON_COLLECTION_CHANGE, "true"); - } + @Override + protected void configure(Configuration configuration) { + configuration.setProperty( EnversSettings.STORE_DATA_AT_DELETE, "true" ); + configuration.setProperty( EnversSettings.REVISION_ON_COLLECTION_CHANGE, "true" ); + } - @Test(expected = AuditException.class) - public void testInsertOutsideActiveTransaction() { - Session session = openSession(); + @Test(expected = AuditException.class) + public void testInsertOutsideActiveTransaction() { + Session session = openSession(); - // Illegal insertion of entity outside of active transaction. - StrTestEntity entity = new StrTestEntity("data"); - session.persist(entity); - session.flush(); + // Illegal insertion of entity outside of active transaction. + StrTestEntity entity = new StrTestEntity( "data" ); + session.persist( entity ); + session.flush(); - session.close(); - } + session.close(); + } - @Test(expected = AuditException.class) - public void testUpdateOutsideActiveTransaction() { - Session session = openSession(); + @Test(expected = AuditException.class) + public void testUpdateOutsideActiveTransaction() { + Session session = openSession(); - // Revision 1 - session.getTransaction().begin(); - StrTestEntity entity = new StrTestEntity("data"); - session.persist(entity); - session.getTransaction().commit(); + // Revision 1 + session.getTransaction().begin(); + StrTestEntity entity = new StrTestEntity( "data" ); + session.persist( entity ); + session.getTransaction().commit(); - // Illegal modification of entity state outside of active transaction. - entity.setStr("modified data"); - session.update(entity); - session.flush(); + // Illegal modification of entity state outside of active transaction. + entity.setStr( "modified data" ); + session.update( entity ); + session.flush(); - session.close(); - } + session.close(); + } - @Test(expected = AuditException.class) - public void testDeleteOutsideActiveTransaction() { - Session session = openSession(); + @Test(expected = AuditException.class) + public void testDeleteOutsideActiveTransaction() { + Session session = openSession(); - // Revision 1 - session.getTransaction().begin(); - StrTestEntity entity = new StrTestEntity("data"); - session.persist(entity); - session.getTransaction().commit(); + // Revision 1 + session.getTransaction().begin(); + StrTestEntity entity = new StrTestEntity( "data" ); + session.persist( entity ); + session.getTransaction().commit(); - // Illegal removal of entity outside of active transaction. - session.delete(entity); - session.flush(); + // Illegal removal of entity outside of active transaction. + session.delete( entity ); + session.flush(); - session.close(); - } + session.close(); + } - @Test(expected = AuditException.class) - public void testCollectionUpdateOutsideActiveTransaction() { - Session session = openSession(); + @Test(expected = AuditException.class) + public void testCollectionUpdateOutsideActiveTransaction() { + Session session = openSession(); - // Revision 1 - session.getTransaction().begin(); - Person person = new Person(); - Name name = new Name(); - name.setName("Name"); - person.getNames().add(name); - session.saveOrUpdate(person); - session.getTransaction().commit(); + // Revision 1 + session.getTransaction().begin(); + Person person = new Person(); + Name name = new Name(); + name.setName( "Name" ); + person.getNames().add( name ); + session.saveOrUpdate( person ); + session.getTransaction().commit(); - // Illegal collection update outside of active transaction. - person.getNames().remove(name); - session.saveOrUpdate(person); - session.flush(); + // Illegal collection update outside of active transaction. + person.getNames().remove( name ); + session.saveOrUpdate( person ); + session.flush(); - session.close(); - } + session.close(); + } - @Test(expected = AuditException.class) - public void testCollectionRemovalOutsideActiveTransaction() { - Session session = openSession(); + @Test(expected = AuditException.class) + public void testCollectionRemovalOutsideActiveTransaction() { + Session session = openSession(); - // Revision 1 - session.getTransaction().begin(); - Person person = new Person(); - Name name = new Name(); - name.setName("Name"); - person.getNames().add(name); - session.saveOrUpdate(person); - session.getTransaction().commit(); + // Revision 1 + session.getTransaction().begin(); + Person person = new Person(); + Name name = new Name(); + name.setName( "Name" ); + person.getNames().add( name ); + session.saveOrUpdate( person ); + session.getTransaction().commit(); - // Illegal collection removal outside of active transaction. - person.setNames(null); - session.saveOrUpdate(person); - session.flush(); + // Illegal collection removal outside of active transaction. + person.setNames( null ); + session.saveOrUpdate( person ); + session.flush(); - session.close(); - } + session.close(); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/RegisterUserEventListenersTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/RegisterUserEventListenersTest.java index 094a08fb52..3f7a090e18 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/RegisterUserEventListenersTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/RegisterUserEventListenersTest.java @@ -12,23 +12,26 @@ import org.hibernate.event.spi.EventType; import org.hibernate.event.spi.PostInsertEvent; import org.hibernate.event.spi.PostInsertEventListener; import org.hibernate.persister.entity.EntityPersister; -import org.hibernate.testing.TestForIssue; + import org.junit.Assert; import org.junit.Test; +import org.hibernate.testing.TestForIssue; + /** * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public class RegisterUserEventListenersTest extends BaseEnversFunctionalTestCase { @Override protected Class[] getAnnotatedClasses() { - return new Class[] { StrTestEntity.class }; + return new Class[] {StrTestEntity.class}; } @Test - @TestForIssue( jiraKey = "HHH-7478" ) + @TestForIssue(jiraKey = "HHH-7478") public void testTransactionProcessSynchronization() { - final EventListenerRegistry registry = sessionFactory().getServiceRegistry().getService( EventListenerRegistry.class ); + final EventListenerRegistry registry = sessionFactory().getServiceRegistry() + .getService( EventListenerRegistry.class ); final CountingPostInsertTransactionBoundaryListener listener = new CountingPostInsertTransactionBoundaryListener(); registry.getEventListenerGroup( EventType.POST_INSERT ).appendListener( listener ); @@ -52,18 +55,22 @@ public class RegisterUserEventListenersTest extends BaseEnversFunctionalTestCase @Override public void onPostInsert(PostInsertEvent event) { - event.getSession().getActionQueue().registerProcess(new BeforeTransactionCompletionProcess() { - @Override - public void doBeforeTransactionCompletion(SessionImplementor session) { - beforeCounter.increase(); - } - }); - event.getSession().getActionQueue().registerProcess(new AfterTransactionCompletionProcess() { - @Override - public void doAfterTransactionCompletion(boolean success, SessionImplementor session) { - afterCounter.increase(); - } - }); + event.getSession().getActionQueue().registerProcess( + new BeforeTransactionCompletionProcess() { + @Override + public void doBeforeTransactionCompletion(SessionImplementor session) { + beforeCounter.increase(); + } + } + ); + event.getSession().getActionQueue().registerProcess( + new AfterTransactionCompletionProcess() { + @Override + public void doAfterTransactionCompletion(boolean success, SessionImplementor session) { + afterCounter.increase(); + } + } + ); } @Override diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/ScalePrecisionEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/ScalePrecisionEntity.java index 2139e4430b..a3c5a20e14 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/ScalePrecisionEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/ScalePrecisionEntity.java @@ -1,10 +1,10 @@ package org.hibernate.envers.test.integration.basic; -import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; +import java.io.Serializable; import org.hibernate.envers.Audited; @@ -14,63 +14,71 @@ import org.hibernate.envers.Audited; @Entity @Audited public class ScalePrecisionEntity implements Serializable { - @Id - @GeneratedValue - private Long id; + @Id + @GeneratedValue + private Long id; - @Column(precision = 3, scale = 0) - private Double wholeNumber; + @Column(precision = 3, scale = 0) + private Double wholeNumber; - public ScalePrecisionEntity() { - } + public ScalePrecisionEntity() { + } - public ScalePrecisionEntity(Double wholeNumber) { - this.wholeNumber = wholeNumber; - } + public ScalePrecisionEntity(Double wholeNumber) { + this.wholeNumber = wholeNumber; + } - public ScalePrecisionEntity(Double wholeNumber, Long id) { - this.id = id; - this.wholeNumber = wholeNumber; - } + public ScalePrecisionEntity(Double wholeNumber, Long id) { + this.id = id; + this.wholeNumber = wholeNumber; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ScalePrecisionEntity)) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ScalePrecisionEntity) ) { + return false; + } - ScalePrecisionEntity that = (ScalePrecisionEntity) o; + ScalePrecisionEntity that = (ScalePrecisionEntity) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; - if (wholeNumber != null ? !wholeNumber.equals(that.wholeNumber) : that.wholeNumber != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } + if ( wholeNumber != null ? !wholeNumber.equals( that.wholeNumber ) : that.wholeNumber != null ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - int result = id != null ? id.hashCode() : 0; - result = 31 * result + (wholeNumber != null ? wholeNumber.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = id != null ? id.hashCode() : 0; + result = 31 * result + (wholeNumber != null ? wholeNumber.hashCode() : 0); + return result; + } - @Override - public String toString() { - return "ScalePrecisionEntity(id = " + id + ", wholeNumber = " + wholeNumber + ")"; - } + @Override + public String toString() { + return "ScalePrecisionEntity(id = " + id + ", wholeNumber = " + wholeNumber + ")"; + } - public Long getId() { - return id; - } + public Long getId() { + return id; + } - public void setId(Long id) { - this.id = id; - } + public void setId(Long id) { + this.id = id; + } - public Double getWholeNumber() { - return wholeNumber; - } + public Double getWholeNumber() { + return wholeNumber; + } - public void setWholeNumber(Double wholeNumber) { - this.wholeNumber = wholeNumber; - } + public void setWholeNumber(Double wholeNumber) { + this.wholeNumber = wholeNumber; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/Simple.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/Simple.java index 612a276763..757b8c0923 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/Simple.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/Simple.java @@ -23,53 +23,53 @@ */ package org.hibernate.envers.test.integration.basic; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.IntTestEntity; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class Simple extends BaseEnversJPAFunctionalTestCase { - private Integer id1; + private Integer id1; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { IntTestEntity.class }; - } + return new Class[] {IntTestEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); - em.getTransaction().begin(); - IntTestEntity ite = new IntTestEntity(10); - em.persist(ite); - id1 = ite.getId(); - em.getTransaction().commit(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); + em.getTransaction().begin(); + IntTestEntity ite = new IntTestEntity( 10 ); + em.persist( ite ); + id1 = ite.getId(); + em.getTransaction().commit(); - em.getTransaction().begin(); - ite = em.find(IntTestEntity.class, id1); - ite.setNumber(20); - em.getTransaction().commit(); - } + em.getTransaction().begin(); + ite = em.find( IntTestEntity.class, id1 ); + ite.setNumber( 20 ); + em.getTransaction().commit(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(IntTestEntity.class, id1)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( IntTestEntity.class, id1 ) ); + } - @Test - public void testHistoryOfId1() { - IntTestEntity ver1 = new IntTestEntity(10, id1); - IntTestEntity ver2 = new IntTestEntity(20, id1); + @Test + public void testHistoryOfId1() { + IntTestEntity ver1 = new IntTestEntity( 10, id1 ); + IntTestEntity ver2 = new IntTestEntity( 20, id1 ); - assert getAuditReader().find(IntTestEntity.class, id1, 1).equals(ver1); - assert getAuditReader().find(IntTestEntity.class, id1, 2).equals(ver2); - } + assert getAuditReader().find( IntTestEntity.class, id1, 1 ).equals( ver1 ); + assert getAuditReader().find( IntTestEntity.class, id1, 2 ).equals( ver2 ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/SingleOperationInTransaction.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/SingleOperationInTransaction.java index afe4c5f529..8e1b074b4a 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/SingleOperationInTransaction.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/SingleOperationInTransaction.java @@ -23,139 +23,139 @@ */ package org.hibernate.envers.test.integration.basic; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.exception.RevisionDoesNotExistException; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class SingleOperationInTransaction extends BaseEnversJPAFunctionalTestCase { - private Integer id1; - private Integer id2; - private Integer id3; + private Integer id1; + private Integer id2; + private Integer id3; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { BasicTestEntity1.class }; - } + return new Class[] {BasicTestEntity1.class}; + } - private Integer addNewEntity(String str, long lng) { - EntityManager em = getEntityManager(); - em.getTransaction().begin(); - BasicTestEntity1 bte1 = new BasicTestEntity1(str, lng); - em.persist(bte1); - em.getTransaction().commit(); + private Integer addNewEntity(String str, long lng) { + EntityManager em = getEntityManager(); + em.getTransaction().begin(); + BasicTestEntity1 bte1 = new BasicTestEntity1( str, lng ); + em.persist( bte1 ); + em.getTransaction().commit(); - return bte1.getId(); - } + return bte1.getId(); + } - private void modifyEntity(Integer id, String str, long lng) { - EntityManager em = getEntityManager(); - em.getTransaction().begin(); - BasicTestEntity1 bte1 = em.find(BasicTestEntity1.class, id); - bte1.setLong1(lng); - bte1.setStr1(str); - em.getTransaction().commit(); - } + private void modifyEntity(Integer id, String str, long lng) { + EntityManager em = getEntityManager(); + em.getTransaction().begin(); + BasicTestEntity1 bte1 = em.find( BasicTestEntity1.class, id ); + bte1.setLong1( lng ); + bte1.setStr1( str ); + em.getTransaction().commit(); + } - @Test - @Priority(10) - public void initData() { - id1 = addNewEntity("x", 1); // rev 1 - id2 = addNewEntity("y", 20); // rev 2 - id3 = addNewEntity("z", 30); // rev 3 + @Test + @Priority(10) + public void initData() { + id1 = addNewEntity( "x", 1 ); // rev 1 + id2 = addNewEntity( "y", 20 ); // rev 2 + id3 = addNewEntity( "z", 30 ); // rev 3 - modifyEntity(id1, "x2", 2); // rev 4 - modifyEntity(id2, "y2", 20); // rev 5 - modifyEntity(id1, "x3", 3); // rev 6 - modifyEntity(id1, "x3", 3); // no rev - modifyEntity(id2, "y3", 21); // rev 7 - } + modifyEntity( id1, "x2", 2 ); // rev 4 + modifyEntity( id2, "y2", 20 ); // rev 5 + modifyEntity( id1, "x3", 3 ); // rev 6 + modifyEntity( id1, "x3", 3 ); // no rev + modifyEntity( id2, "y3", 21 ); // rev 7 + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 4, 6).equals(getAuditReader().getRevisions(BasicTestEntity1.class, id1)); + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 4, 6 ).equals( getAuditReader().getRevisions( BasicTestEntity1.class, id1 ) ); - assert Arrays.asList(2, 5, 7).equals(getAuditReader().getRevisions(BasicTestEntity1.class, id2)); + assert Arrays.asList( 2, 5, 7 ).equals( getAuditReader().getRevisions( BasicTestEntity1.class, id2 ) ); - assert Arrays.asList(3).equals(getAuditReader().getRevisions(BasicTestEntity1.class, id3)); - } + assert Arrays.asList( 3 ).equals( getAuditReader().getRevisions( BasicTestEntity1.class, id3 ) ); + } - @Test - public void testRevisionsDates() { - for (int i=1; i<7; i++) { - assert getAuditReader().getRevisionDate(i).getTime() <= - getAuditReader().getRevisionDate(i+1).getTime(); - } - } + @Test + public void testRevisionsDates() { + for ( int i = 1; i < 7; i++ ) { + assert getAuditReader().getRevisionDate( i ).getTime() <= + getAuditReader().getRevisionDate( i + 1 ).getTime(); + } + } - @Test(expected = RevisionDoesNotExistException.class) - public void testNotExistingRevision() { - getAuditReader().getRevisionDate(8); - } + @Test(expected = RevisionDoesNotExistException.class) + public void testNotExistingRevision() { + getAuditReader().getRevisionDate( 8 ); + } - @Test(expected = IllegalArgumentException.class) - public void testIllegalRevision() { - getAuditReader().getRevisionDate(0); - } + @Test(expected = IllegalArgumentException.class) + public void testIllegalRevision() { + getAuditReader().getRevisionDate( 0 ); + } - @Test - public void testHistoryOfId1() { - BasicTestEntity1 ver1 = new BasicTestEntity1(id1, "x", 1); - BasicTestEntity1 ver2 = new BasicTestEntity1(id1, "x2", 2); - BasicTestEntity1 ver3 = new BasicTestEntity1(id1, "x3", 3); + @Test + public void testHistoryOfId1() { + BasicTestEntity1 ver1 = new BasicTestEntity1( id1, "x", 1 ); + BasicTestEntity1 ver2 = new BasicTestEntity1( id1, "x2", 2 ); + BasicTestEntity1 ver3 = new BasicTestEntity1( id1, "x3", 3 ); - assert getAuditReader().find(BasicTestEntity1.class, id1, 1).equals(ver1); - assert getAuditReader().find(BasicTestEntity1.class, id1, 2).equals(ver1); - assert getAuditReader().find(BasicTestEntity1.class, id1, 3).equals(ver1); - assert getAuditReader().find(BasicTestEntity1.class, id1, 4).equals(ver2); - assert getAuditReader().find(BasicTestEntity1.class, id1, 5).equals(ver2); - assert getAuditReader().find(BasicTestEntity1.class, id1, 6).equals(ver3); - assert getAuditReader().find(BasicTestEntity1.class, id1, 7).equals(ver3); - } + assert getAuditReader().find( BasicTestEntity1.class, id1, 1 ).equals( ver1 ); + assert getAuditReader().find( BasicTestEntity1.class, id1, 2 ).equals( ver1 ); + assert getAuditReader().find( BasicTestEntity1.class, id1, 3 ).equals( ver1 ); + assert getAuditReader().find( BasicTestEntity1.class, id1, 4 ).equals( ver2 ); + assert getAuditReader().find( BasicTestEntity1.class, id1, 5 ).equals( ver2 ); + assert getAuditReader().find( BasicTestEntity1.class, id1, 6 ).equals( ver3 ); + assert getAuditReader().find( BasicTestEntity1.class, id1, 7 ).equals( ver3 ); + } - @Test - public void testHistoryOfId2() { - BasicTestEntity1 ver1 = new BasicTestEntity1(id2, "y", 20); - BasicTestEntity1 ver2 = new BasicTestEntity1(id2, "y2", 20); - BasicTestEntity1 ver3 = new BasicTestEntity1(id2, "y3", 21); + @Test + public void testHistoryOfId2() { + BasicTestEntity1 ver1 = new BasicTestEntity1( id2, "y", 20 ); + BasicTestEntity1 ver2 = new BasicTestEntity1( id2, "y2", 20 ); + BasicTestEntity1 ver3 = new BasicTestEntity1( id2, "y3", 21 ); - assert getAuditReader().find(BasicTestEntity1.class, id2, 1) == null; - assert getAuditReader().find(BasicTestEntity1.class, id2, 2).equals(ver1); - assert getAuditReader().find(BasicTestEntity1.class, id2, 3).equals(ver1); - assert getAuditReader().find(BasicTestEntity1.class, id2, 4).equals(ver1); - assert getAuditReader().find(BasicTestEntity1.class, id2, 5).equals(ver2); - assert getAuditReader().find(BasicTestEntity1.class, id2, 6).equals(ver2); - assert getAuditReader().find(BasicTestEntity1.class, id2, 7).equals(ver3); - } + assert getAuditReader().find( BasicTestEntity1.class, id2, 1 ) == null; + assert getAuditReader().find( BasicTestEntity1.class, id2, 2 ).equals( ver1 ); + assert getAuditReader().find( BasicTestEntity1.class, id2, 3 ).equals( ver1 ); + assert getAuditReader().find( BasicTestEntity1.class, id2, 4 ).equals( ver1 ); + assert getAuditReader().find( BasicTestEntity1.class, id2, 5 ).equals( ver2 ); + assert getAuditReader().find( BasicTestEntity1.class, id2, 6 ).equals( ver2 ); + assert getAuditReader().find( BasicTestEntity1.class, id2, 7 ).equals( ver3 ); + } - @Test - public void testHistoryOfId3() { - BasicTestEntity1 ver1 = new BasicTestEntity1(id3, "z", 30); + @Test + public void testHistoryOfId3() { + BasicTestEntity1 ver1 = new BasicTestEntity1( id3, "z", 30 ); - assert getAuditReader().find(BasicTestEntity1.class, id3, 1) == null; - assert getAuditReader().find(BasicTestEntity1.class, id3, 2) == null; - assert getAuditReader().find(BasicTestEntity1.class, id3, 3).equals(ver1); - assert getAuditReader().find(BasicTestEntity1.class, id3, 4).equals(ver1); - assert getAuditReader().find(BasicTestEntity1.class, id3, 5).equals(ver1); - assert getAuditReader().find(BasicTestEntity1.class, id3, 6).equals(ver1); - assert getAuditReader().find(BasicTestEntity1.class, id3, 7).equals(ver1); - } + assert getAuditReader().find( BasicTestEntity1.class, id3, 1 ) == null; + assert getAuditReader().find( BasicTestEntity1.class, id3, 2 ) == null; + assert getAuditReader().find( BasicTestEntity1.class, id3, 3 ).equals( ver1 ); + assert getAuditReader().find( BasicTestEntity1.class, id3, 4 ).equals( ver1 ); + assert getAuditReader().find( BasicTestEntity1.class, id3, 5 ).equals( ver1 ); + assert getAuditReader().find( BasicTestEntity1.class, id3, 6 ).equals( ver1 ); + assert getAuditReader().find( BasicTestEntity1.class, id3, 7 ).equals( ver1 ); + } - @Test - public void testHistoryOfNotExistingEntity() { - assert getAuditReader().find(BasicTestEntity1.class, id1+id2+id3, 1) == null; - assert getAuditReader().find(BasicTestEntity1.class, id1+id2+id3, 7) == null; - } + @Test + public void testHistoryOfNotExistingEntity() { + assert getAuditReader().find( BasicTestEntity1.class, id1 + id2 + id3, 1 ) == null; + assert getAuditReader().find( BasicTestEntity1.class, id1 + id2 + id3, 7 ) == null; + } - @Test - public void testRevisionsOfNotExistingEntity() { - assert getAuditReader().getRevisions(BasicTestEntity1.class, id1+id2+id3).size() == 0; - } + @Test + public void testRevisionsOfNotExistingEntity() { + assert getAuditReader().getRevisions( BasicTestEntity1.class, id1 + id2 + id3 ).size() == 0; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/TransactionRollbackBehaviour.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/TransactionRollbackBehaviour.java index 98c0e5cb27..1ea650515f 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/TransactionRollbackBehaviour.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/TransactionRollbackBehaviour.java @@ -1,13 +1,14 @@ package org.hibernate.envers.test.integration.basic; -import java.util.List; import javax.persistence.EntityManager; +import java.util.List; + +import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; +import org.hibernate.envers.test.entities.IntTestEntity; import org.junit.Assert; import org.junit.Test; -import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; -import org.hibernate.envers.test.entities.IntTestEntity; import org.hibernate.testing.TestForIssue; /** @@ -35,12 +36,19 @@ public class TransactionRollbackBehaviour extends BaseEnversJPAFunctionalTestCas List revisionsForSavedClass = getAuditReader().getRevisions( IntTestEntity.class, ite2Id ); Assert.assertEquals( "There should be one revision for inserted entity.", 1, revisionsForSavedClass.size() ); - List revisionsForRolledbackClass = getAuditReader().getRevisions( IntTestEntity.class, rollbackedIteId ); - Assert.assertEquals( "There should be no revision for rolled back transaction.", 0, revisionsForRolledbackClass.size() ); + List revisionsForRolledbackClass = getAuditReader().getRevisions( + IntTestEntity.class, + rollbackedIteId + ); + Assert.assertEquals( + "There should be no revision for rolled back transaction.", + 0, + revisionsForRolledbackClass.size() + ); } @Test - @TestForIssue( jiraKey = "HHH-8189" ) + @TestForIssue(jiraKey = "HHH-8189") public void testFlushedAuditRecordsRollback() { // Given EntityManager em = getEntityManager(); @@ -63,12 +71,19 @@ public class TransactionRollbackBehaviour extends BaseEnversJPAFunctionalTestCas List revisionsForSavedClass = getAuditReader().getRevisions( IntTestEntity.class, ite2Id ); Assert.assertEquals( "There should be one revision for inserted entity.", 1, revisionsForSavedClass.size() ); - List revisionsForRolledbackClass = getAuditReader().getRevisions( IntTestEntity.class, rollbackedIteId ); - Assert.assertEquals( "There should be no revision for rolled back transaction.", 0, revisionsForRolledbackClass.size() ); + List revisionsForRolledbackClass = getAuditReader().getRevisions( + IntTestEntity.class, + rollbackedIteId + ); + Assert.assertEquals( + "There should be no revision for rolled back transaction.", + 0, + revisionsForRolledbackClass.size() + ); } @Override protected Class[] getAnnotatedClasses() { - return new Class[] { IntTestEntity.class }; + return new Class[] {IntTestEntity.class}; } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/UnversionedPropertiesChange.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/UnversionedPropertiesChange.java index 1779f41546..62fcd5f30d 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/UnversionedPropertiesChange.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/UnversionedPropertiesChange.java @@ -23,64 +23,64 @@ */ package org.hibernate.envers.test.integration.basic; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class UnversionedPropertiesChange extends BaseEnversJPAFunctionalTestCase { - private Integer id1; + private Integer id1; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { BasicTestEntity2.class }; - } + return new Class[] {BasicTestEntity2.class}; + } - private Integer addNewEntity(String str1, String str2) { - EntityManager em = getEntityManager(); - em.getTransaction().begin(); - BasicTestEntity2 bte2 = new BasicTestEntity2(str1, str2); - em.persist(bte2); - em.getTransaction().commit(); + private Integer addNewEntity(String str1, String str2) { + EntityManager em = getEntityManager(); + em.getTransaction().begin(); + BasicTestEntity2 bte2 = new BasicTestEntity2( str1, str2 ); + em.persist( bte2 ); + em.getTransaction().commit(); - return bte2.getId(); - } + return bte2.getId(); + } - private void modifyEntity(Integer id, String str1, String str2) { - EntityManager em = getEntityManager(); - em.getTransaction().begin(); - BasicTestEntity2 bte2 = em.find(BasicTestEntity2.class, id); - bte2.setStr1(str1); - bte2.setStr2(str2); - em.getTransaction().commit(); - } + private void modifyEntity(Integer id, String str1, String str2) { + EntityManager em = getEntityManager(); + em.getTransaction().begin(); + BasicTestEntity2 bte2 = em.find( BasicTestEntity2.class, id ); + bte2.setStr1( str1 ); + bte2.setStr2( str2 ); + em.getTransaction().commit(); + } - @Test - @Priority(10) - public void initData() { - id1 = addNewEntity("x", "a"); // rev 1 - modifyEntity(id1, "x", "a"); // no rev - modifyEntity(id1, "y", "b"); // rev 2 - modifyEntity(id1, "y", "c"); // no rev - } + @Test + @Priority(10) + public void initData() { + id1 = addNewEntity( "x", "a" ); // rev 1 + modifyEntity( id1, "x", "a" ); // no rev + modifyEntity( id1, "y", "b" ); // rev 2 + modifyEntity( id1, "y", "c" ); // no rev + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(BasicTestEntity2.class, id1)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( BasicTestEntity2.class, id1 ) ); + } - @Test - public void testHistoryOfId1() { - BasicTestEntity2 ver1 = new BasicTestEntity2(id1, "x", null); - BasicTestEntity2 ver2 = new BasicTestEntity2(id1, "y", null); + @Test + public void testHistoryOfId1() { + BasicTestEntity2 ver1 = new BasicTestEntity2( id1, "x", null ); + BasicTestEntity2 ver2 = new BasicTestEntity2( id1, "y", null ); - assert getAuditReader().find(BasicTestEntity2.class, id1, 1).equals(ver1); - assert getAuditReader().find(BasicTestEntity2.class, id1, 2).equals(ver2); - } + assert getAuditReader().find( BasicTestEntity2.class, id1, 1 ).equals( ver1 ); + assert getAuditReader().find( BasicTestEntity2.class, id1, 2 ).equals( ver2 ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/UnversionedProperty.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/UnversionedProperty.java index 7ecb37da29..f2ca6e0a2c 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/UnversionedProperty.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/basic/UnversionedProperty.java @@ -23,57 +23,57 @@ */ package org.hibernate.envers.test.integration.basic; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.UnversionedEntity; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ -public class UnversionedProperty extends BaseEnversJPAFunctionalTestCase { - private Integer id1; +public class UnversionedProperty extends BaseEnversJPAFunctionalTestCase { + private Integer id1; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { UnversionedEntity.class }; - } + return new Class[] {UnversionedEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - // Rev 1 - em.getTransaction().begin(); - UnversionedEntity ue1 = new UnversionedEntity("a1", "b1"); - em.persist(ue1); - id1 = ue1.getId(); - em.getTransaction().commit(); + // Rev 1 + em.getTransaction().begin(); + UnversionedEntity ue1 = new UnversionedEntity( "a1", "b1" ); + em.persist( ue1 ); + id1 = ue1.getId(); + em.getTransaction().commit(); - // Rev 2 - em.getTransaction().begin(); - ue1 = em.find(UnversionedEntity.class, id1); - ue1.setData1("a2"); - ue1.setData2("b2"); - em.getTransaction().commit(); - } + // Rev 2 + em.getTransaction().begin(); + ue1 = em.find( UnversionedEntity.class, id1 ); + ue1.setData1( "a2" ); + ue1.setData2( "b2" ); + em.getTransaction().commit(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(UnversionedEntity.class, id1)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( UnversionedEntity.class, id1 ) ); + } - @Test - public void testHistoryOfId1() { - UnversionedEntity rev1 = new UnversionedEntity(id1, "a1", null); - UnversionedEntity rev2 = new UnversionedEntity(id1, "a2", null); + @Test + public void testHistoryOfId1() { + UnversionedEntity rev1 = new UnversionedEntity( id1, "a1", null ); + UnversionedEntity rev2 = new UnversionedEntity( id1, "a2", null ); - assert getAuditReader().find(UnversionedEntity.class, id1, 1).equals(rev1); - assert getAuditReader().find(UnversionedEntity.class, id1, 2).equals(rev2); - } + assert getAuditReader().find( UnversionedEntity.class, id1, 1 ).equals( rev1 ); + assert getAuditReader().find( UnversionedEntity.class, id1, 2 ).equals( rev2 ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/cache/OneToManyCache.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/cache/OneToManyCache.java index f680242389..86487781d9 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/cache/OneToManyCache.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/cache/OneToManyCache.java @@ -25,120 +25,120 @@ package org.hibernate.envers.test.integration.cache; import javax.persistence.EntityManager; -import org.junit.Test; - import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.onetomany.SetRefEdEntity; import org.hibernate.envers.test.entities.onetomany.SetRefIngEntity; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ @SuppressWarnings({"ObjectEquality"}) public class OneToManyCache extends BaseEnversJPAFunctionalTestCase { - private Integer ed1_id; - private Integer ed2_id; + private Integer ed1_id; + private Integer ed2_id; - private Integer ing1_id; - private Integer ing2_id; + private Integer ing1_id; + private Integer ing2_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { SetRefEdEntity.class, SetRefIngEntity.class }; - } + return new Class[] {SetRefEdEntity.class, SetRefIngEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - SetRefEdEntity ed1 = new SetRefEdEntity(1, "data_ed_1"); - SetRefEdEntity ed2 = new SetRefEdEntity(2, "data_ed_2"); + SetRefEdEntity ed1 = new SetRefEdEntity( 1, "data_ed_1" ); + SetRefEdEntity ed2 = new SetRefEdEntity( 2, "data_ed_2" ); - SetRefIngEntity ing1 = new SetRefIngEntity(1, "data_ing_1"); - SetRefIngEntity ing2 = new SetRefIngEntity(2, "data_ing_2"); + SetRefIngEntity ing1 = new SetRefIngEntity( 1, "data_ing_1" ); + SetRefIngEntity ing2 = new SetRefIngEntity( 2, "data_ing_2" ); - // Revision 1 - em.getTransaction().begin(); + // Revision 1 + em.getTransaction().begin(); - em.persist(ed1); - em.persist(ed2); + em.persist( ed1 ); + em.persist( ed2 ); - ing1.setReference(ed1); - ing2.setReference(ed1); + ing1.setReference( ed1 ); + ing2.setReference( ed1 ); - em.persist(ing1); - em.persist(ing2); + em.persist( ing1 ); + em.persist( ing2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); + // Revision 2 + em.getTransaction().begin(); - ing1 = em.find(SetRefIngEntity.class, ing1.getId()); - ing2 = em.find(SetRefIngEntity.class, ing2.getId()); - ed2 = em.find(SetRefEdEntity.class, ed2.getId()); + ing1 = em.find( SetRefIngEntity.class, ing1.getId() ); + ing2 = em.find( SetRefIngEntity.class, ing2.getId() ); + ed2 = em.find( SetRefEdEntity.class, ed2.getId() ); - ing1.setReference(ed2); - ing2.setReference(ed2); + ing1.setReference( ed2 ); + ing2.setReference( ed2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // + // - ed1_id = ed1.getId(); - ed2_id = ed2.getId(); + ed1_id = ed1.getId(); + ed2_id = ed2.getId(); - ing1_id = ing1.getId(); - ing2_id = ing2.getId(); - } + ing1_id = ing1.getId(); + ing2_id = ing2.getId(); + } - @Test - public void testCacheReferenceAccessAfterFind() { - SetRefEdEntity ed1_rev1 = getAuditReader().find(SetRefEdEntity.class, ed1_id, 1); + @Test + public void testCacheReferenceAccessAfterFind() { + SetRefEdEntity ed1_rev1 = getAuditReader().find( SetRefEdEntity.class, ed1_id, 1 ); - SetRefIngEntity ing1_rev1 = getAuditReader().find(SetRefIngEntity.class, ing1_id, 1); - SetRefIngEntity ing2_rev1 = getAuditReader().find(SetRefIngEntity.class, ing2_id, 1); + SetRefIngEntity ing1_rev1 = getAuditReader().find( SetRefIngEntity.class, ing1_id, 1 ); + SetRefIngEntity ing2_rev1 = getAuditReader().find( SetRefIngEntity.class, ing2_id, 1 ); - // It should be exactly the same object - assert ing1_rev1.getReference() == ed1_rev1; - assert ing2_rev1.getReference() == ed1_rev1; - } + // It should be exactly the same object + assert ing1_rev1.getReference() == ed1_rev1; + assert ing2_rev1.getReference() == ed1_rev1; + } - @Test - public void testCacheReferenceAccessAfterCollectionAccessRev1() { - SetRefEdEntity ed1_rev1 = getAuditReader().find(SetRefEdEntity.class, ed1_id, 1); + @Test + public void testCacheReferenceAccessAfterCollectionAccessRev1() { + SetRefEdEntity ed1_rev1 = getAuditReader().find( SetRefEdEntity.class, ed1_id, 1 ); - // It should be exactly the same object - assert ed1_rev1.getReffering().size() == 2; - for (SetRefIngEntity setRefIngEntity : ed1_rev1.getReffering()) { - assert setRefIngEntity.getReference() == ed1_rev1; - } - } + // It should be exactly the same object + assert ed1_rev1.getReffering().size() == 2; + for ( SetRefIngEntity setRefIngEntity : ed1_rev1.getReffering() ) { + assert setRefIngEntity.getReference() == ed1_rev1; + } + } - @Test - public void testCacheReferenceAccessAfterCollectionAccessRev2() { - SetRefEdEntity ed2_rev2 = getAuditReader().find(SetRefEdEntity.class, ed2_id, 2); + @Test + public void testCacheReferenceAccessAfterCollectionAccessRev2() { + SetRefEdEntity ed2_rev2 = getAuditReader().find( SetRefEdEntity.class, ed2_id, 2 ); - assert ed2_rev2.getReffering().size() == 2; - for (SetRefIngEntity setRefIngEntity : ed2_rev2.getReffering()) { - assert setRefIngEntity.getReference() == ed2_rev2; - } - } + assert ed2_rev2.getReffering().size() == 2; + for ( SetRefIngEntity setRefIngEntity : ed2_rev2.getReffering() ) { + assert setRefIngEntity.getReference() == ed2_rev2; + } + } - @Test - public void testCacheFindAfterCollectionAccessRev1() { - SetRefEdEntity ed1_rev1 = getAuditReader().find(SetRefEdEntity.class, ed1_id, 1); + @Test + public void testCacheFindAfterCollectionAccessRev1() { + SetRefEdEntity ed1_rev1 = getAuditReader().find( SetRefEdEntity.class, ed1_id, 1 ); - // Reading the collection - assert ed1_rev1.getReffering().size() == 2; + // Reading the collection + assert ed1_rev1.getReffering().size() == 2; - SetRefIngEntity ing1_rev1 = getAuditReader().find(SetRefIngEntity.class, ing1_id, 1); - SetRefIngEntity ing2_rev1 = getAuditReader().find(SetRefIngEntity.class, ing2_id, 1); + SetRefIngEntity ing1_rev1 = getAuditReader().find( SetRefIngEntity.class, ing1_id, 1 ); + SetRefIngEntity ing2_rev1 = getAuditReader().find( SetRefIngEntity.class, ing2_id, 1 ); - for (SetRefIngEntity setRefIngEntity : ed1_rev1.getReffering()) { - assert setRefIngEntity == ing1_rev1 || setRefIngEntity == ing2_rev1; - } - } + for ( SetRefIngEntity setRefIngEntity : ed1_rev1.getReffering() ) { + assert setRefIngEntity == ing1_rev1 || setRefIngEntity == ing2_rev1; + } + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/cache/OneToOneCache.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/cache/OneToOneCache.java index e97f410d25..2e494f14c2 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/cache/OneToOneCache.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/cache/OneToOneCache.java @@ -25,78 +25,78 @@ package org.hibernate.envers.test.integration.cache; import javax.persistence.EntityManager; -import org.junit.Test; - import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.integration.onetoone.bidirectional.BiRefEdEntity; import org.hibernate.envers.test.integration.onetoone.bidirectional.BiRefIngEntity; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ @SuppressWarnings({"ObjectEquality"}) public class OneToOneCache extends BaseEnversJPAFunctionalTestCase { - private Integer ed1_id; - private Integer ed2_id; + private Integer ed1_id; + private Integer ed2_id; - private Integer ing1_id; + private Integer ing1_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { BiRefEdEntity.class, BiRefIngEntity.class }; - } + return new Class[] {BiRefEdEntity.class, BiRefIngEntity.class}; + } - @Test - @Priority(10) - public void initData() { - BiRefEdEntity ed1 = new BiRefEdEntity(1, "data_ed_1"); - BiRefEdEntity ed2 = new BiRefEdEntity(2, "data_ed_2"); + @Test + @Priority(10) + public void initData() { + BiRefEdEntity ed1 = new BiRefEdEntity( 1, "data_ed_1" ); + BiRefEdEntity ed2 = new BiRefEdEntity( 2, "data_ed_2" ); - BiRefIngEntity ing1 = new BiRefIngEntity(3, "data_ing_1"); + BiRefIngEntity ing1 = new BiRefIngEntity( 3, "data_ing_1" ); - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); - ing1.setReference(ed1); + ing1.setReference( ed1 ); - em.persist(ed1); - em.persist(ed2); + em.persist( ed1 ); + em.persist( ed2 ); - em.persist(ing1); + em.persist( ing1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); + // Revision 2 + em.getTransaction().begin(); - ing1 = em.find(BiRefIngEntity.class, ing1.getId()); - ed2 = em.find(BiRefEdEntity.class, ed2.getId()); + ing1 = em.find( BiRefIngEntity.class, ing1.getId() ); + ed2 = em.find( BiRefEdEntity.class, ed2.getId() ); - ing1.setReference(ed2); + ing1.setReference( ed2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - ed1_id = ed1.getId(); - ed2_id = ed2.getId(); + ed1_id = ed1.getId(); + ed2_id = ed2.getId(); - ing1_id = ing1.getId(); - } + ing1_id = ing1.getId(); + } - @Test - public void testCacheReferenceAccessAfterFindRev1() { - BiRefEdEntity ed1_rev1 = getAuditReader().find(BiRefEdEntity.class, ed1_id, 1); - BiRefIngEntity ing1_rev1 = getAuditReader().find(BiRefIngEntity.class, ing1_id, 1); + @Test + public void testCacheReferenceAccessAfterFindRev1() { + BiRefEdEntity ed1_rev1 = getAuditReader().find( BiRefEdEntity.class, ed1_id, 1 ); + BiRefIngEntity ing1_rev1 = getAuditReader().find( BiRefIngEntity.class, ing1_id, 1 ); - assert ing1_rev1.getReference() == ed1_rev1; - } + assert ing1_rev1.getReference() == ed1_rev1; + } - @Test - public void testCacheReferenceAccessAfterFindRev2() { - BiRefEdEntity ed2_rev2 = getAuditReader().find(BiRefEdEntity.class, ed2_id, 2); - BiRefIngEntity ing1_rev2 = getAuditReader().find(BiRefIngEntity.class, ing1_id, 2); + @Test + public void testCacheReferenceAccessAfterFindRev2() { + BiRefEdEntity ed2_rev2 = getAuditReader().find( BiRefEdEntity.class, ed2_id, 2 ); + BiRefIngEntity ing1_rev2 = getAuditReader().find( BiRefIngEntity.class, ing1_id, 2 ); - assert ing1_rev2.getReference() == ed2_rev2; - } + assert ing1_rev2.getReference() == ed2_rev2; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/cache/QueryCache.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/cache/QueryCache.java index 2bf21a3726..1e32fbe6e1 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/cache/QueryCache.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/cache/QueryCache.java @@ -23,66 +23,66 @@ */ package org.hibernate.envers.test.integration.cache; -import java.util.List; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.List; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.IntTestEntity; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ @SuppressWarnings({"ObjectEquality"}) public class QueryCache extends BaseEnversJPAFunctionalTestCase { - private Integer id1; + private Integer id1; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { IntTestEntity.class }; - } + return new Class[] {IntTestEntity.class}; + } - @Test - @Priority(10) - public void initData() { - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); - IntTestEntity ite = new IntTestEntity(10); - em.persist(ite); - id1 = ite.getId(); - em.getTransaction().commit(); + @Test + @Priority(10) + public void initData() { + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); + IntTestEntity ite = new IntTestEntity( 10 ); + em.persist( ite ); + id1 = ite.getId(); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); - ite = em.find(IntTestEntity.class, id1); - ite.setNumber(20); - em.getTransaction().commit(); - } + // Revision 2 + em.getTransaction().begin(); + ite = em.find( IntTestEntity.class, id1 ); + ite.setNumber( 20 ); + em.getTransaction().commit(); + } - @Test - public void testCacheFindAfterRevisionsOfEntityQuery() { - List entsFromQuery = getAuditReader().createQuery() - .forRevisionsOfEntity(IntTestEntity.class, true, false) - .getResultList(); + @Test + public void testCacheFindAfterRevisionsOfEntityQuery() { + List entsFromQuery = getAuditReader().createQuery() + .forRevisionsOfEntity( IntTestEntity.class, true, false ) + .getResultList(); - IntTestEntity entFromFindRev1 = getAuditReader().find(IntTestEntity.class, id1, 1); - IntTestEntity entFromFindRev2 = getAuditReader().find(IntTestEntity.class, id1, 2); + IntTestEntity entFromFindRev1 = getAuditReader().find( IntTestEntity.class, id1, 1 ); + IntTestEntity entFromFindRev2 = getAuditReader().find( IntTestEntity.class, id1, 2 ); - assert entFromFindRev1 == entsFromQuery.get(0); - assert entFromFindRev2 == entsFromQuery.get(1); - } + assert entFromFindRev1 == entsFromQuery.get( 0 ); + assert entFromFindRev2 == entsFromQuery.get( 1 ); + } - @Test - public void testCacheFindAfterEntitiesAtRevisionQuery() { - IntTestEntity entFromQuery = (IntTestEntity) getAuditReader().createQuery() - .forEntitiesAtRevision(IntTestEntity.class, 1) - .getSingleResult(); + @Test + public void testCacheFindAfterEntitiesAtRevisionQuery() { + IntTestEntity entFromQuery = (IntTestEntity) getAuditReader().createQuery() + .forEntitiesAtRevision( IntTestEntity.class, 1 ) + .getSingleResult(); - IntTestEntity entFromFind = getAuditReader().find(IntTestEntity.class, id1, 1); + IntTestEntity entFromFind = getAuditReader().find( IntTestEntity.class, id1, 1 ); - assert entFromFind == entFromQuery; - } + assert entFromFind == entFromQuery; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/DetachedMultipleCollectionChangeTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/DetachedMultipleCollectionChangeTest.java index 1c0e524d28..198d4bcd4d 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/DetachedMultipleCollectionChangeTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/DetachedMultipleCollectionChangeTest.java @@ -1,15 +1,13 @@ package org.hibernate.envers.test.integration.collection; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; import javax.persistence.EntityManager; import javax.persistence.Query; import javax.transaction.Status; import javax.transaction.TransactionManager; - -import org.junit.Test; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; import org.hibernate.dialect.Oracle8iDialect; import org.hibernate.envers.RevisionType; @@ -19,6 +17,9 @@ import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.collection.MultipleCollectionEntity; import org.hibernate.envers.test.entities.collection.MultipleCollectionRefEntity1; import org.hibernate.envers.test.entities.collection.MultipleCollectionRefEntity2; + +import org.junit.Test; + import org.hibernate.testing.SkipForDialect; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.jta.TestingJtaBootstrap; @@ -35,7 +36,7 @@ import static org.junit.Assert.assertNotNull; */ @TestForIssue(jiraKey = "HHH-6349") @SkipForDialect(value = Oracle8iDialect.class, - comment = "Oracle does not support identity key generation") + comment = "Oracle does not support identity key generation") public class DetachedMultipleCollectionChangeTest extends BaseEnversJPAFunctionalTestCase { private TransactionManager tm = null; @@ -276,10 +277,11 @@ public class DetachedMultipleCollectionChangeTest extends BaseEnversJPAFunctiona ); } - private List getAuditJoinTableRows(String middleEntityName, String joinColumnIdName, - String joinColumnIdProp, String inverseJoinColumnIdName, - String inverseJoinColumnIdProp, String revProp, String revIdProp, - String revTypeProp) throws Exception { + private List getAuditJoinTableRows( + String middleEntityName, String joinColumnIdName, + String joinColumnIdProp, String inverseJoinColumnIdName, + String inverseJoinColumnIdProp, String revProp, String revIdProp, + String revTypeProp) throws Exception { StringBuilder qryBuilder = new StringBuilder( "select " ); qryBuilder.append( "aud " ); qryBuilder.append( ", " ).append( joinColumnIdProp ).append( " as joinColumnId" ); @@ -324,9 +326,10 @@ public class DetachedMultipleCollectionChangeTest extends BaseEnversJPAFunctiona private final String inverseJoinColumnName; private final Long inverseJoinColumnId; - private AuditJoinTableInfo(String name, SequenceIdRevisionEntity rev, - RevisionType revType, String joinColumnName, Long joinColumnId, - String inverseJoinColumnName, Long inverseJoinColumnId) { + private AuditJoinTableInfo( + String name, SequenceIdRevisionEntity rev, + RevisionType revType, String joinColumnName, Long joinColumnId, + String inverseJoinColumnName, Long inverseJoinColumnId) { this.name = name; this.revId = rev.getId(); this.revType = revType; @@ -349,13 +352,15 @@ public class DetachedMultipleCollectionChangeTest extends BaseEnversJPAFunctiona if ( this == o ) { return true; } - if ( !( o instanceof AuditJoinTableInfo ) ) { + if ( !(o instanceof AuditJoinTableInfo) ) { return false; } AuditJoinTableInfo that = (AuditJoinTableInfo) o; - if ( inverseJoinColumnId != null ? !inverseJoinColumnId.equals( that.inverseJoinColumnId ) : that.inverseJoinColumnId != null ) { + if ( inverseJoinColumnId != null ? + !inverseJoinColumnId.equals( that.inverseJoinColumnId ) : + that.inverseJoinColumnId != null ) { return false; } if ( joinColumnId != null ? !joinColumnId.equals( that.joinColumnId ) : that.joinColumnId != null ) { @@ -377,10 +382,10 @@ public class DetachedMultipleCollectionChangeTest extends BaseEnversJPAFunctiona @Override public int hashCode() { int result = name != null ? name.hashCode() : 0; - result = 31 * result + ( revId != null ? revId.hashCode() : 0 ); - result = 31 * result + ( revType != null ? revType.hashCode() : 0 ); - result = 31 * result + ( joinColumnId != null ? joinColumnId.hashCode() : 0 ); - result = 31 * result + ( inverseJoinColumnId != null ? inverseJoinColumnId.hashCode() : 0 ); + result = 31 * result + (revId != null ? revId.hashCode() : 0); + result = 31 * result + (revType != null ? revType.hashCode() : 0); + result = 31 * result + (joinColumnId != null ? joinColumnId.hashCode() : 0); + result = 31 * result + (inverseJoinColumnId != null ? inverseJoinColumnId.hashCode() : 0); return result; } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/EnumSet.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/EnumSet.java index 92239ec28c..370a9e10af 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/EnumSet.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/EnumSet.java @@ -23,12 +23,9 @@ */ package org.hibernate.envers.test.integration.collection; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.List; -import javax.persistence.EntityManager; - -import org.junit.Assert; -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; @@ -36,87 +33,95 @@ import org.hibernate.envers.test.entities.collection.EnumSetEntity; import org.hibernate.envers.test.entities.collection.EnumSetEntity.E1; import org.hibernate.envers.test.entities.collection.EnumSetEntity.E2; import org.hibernate.envers.test.tools.TestTools; + +import org.junit.Assert; +import org.junit.Test; + import org.hibernate.testing.TestForIssue; /** * @author Adam Warski (adam at warski dot org) */ -public class EnumSet extends BaseEnversJPAFunctionalTestCase { - private Integer sse1_id; +public class EnumSet extends BaseEnversJPAFunctionalTestCase { + private Integer sse1_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { EnumSetEntity.class }; - } - - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); - - EnumSetEntity sse1 = new EnumSetEntity(); - - // Revision 1 (sse1: initialy 1 element) - em.getTransaction().begin(); - - sse1.getEnums1().add(E1.X); - sse1.getEnums2().add(E2.A); - - em.persist(sse1); - - em.getTransaction().commit(); - - // Revision 2 (sse1: adding 1 element/removing a non-existing element) - em.getTransaction().begin(); - - sse1 = em.find(EnumSetEntity.class, sse1.getId()); - - sse1.getEnums1().add(E1.Y); - sse1.getEnums2().remove(E2.B); - - em.getTransaction().commit(); - - // Revision 3 (sse1: removing 1 element/adding an exisiting element) - em.getTransaction().begin(); - - sse1 = em.find(EnumSetEntity.class, sse1.getId()); - - sse1.getEnums1().remove(E1.X); - sse1.getEnums2().add(E2.A); - - em.getTransaction().commit(); - - // - - sse1_id = sse1.getId(); - } - - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2, 3).equals(getAuditReader().getRevisions(EnumSetEntity.class, sse1_id)); - } - - @Test - public void testHistoryOfSse1() { - EnumSetEntity rev1 = getAuditReader().find(EnumSetEntity.class, sse1_id, 1); - EnumSetEntity rev2 = getAuditReader().find(EnumSetEntity.class, sse1_id, 2); - EnumSetEntity rev3 = getAuditReader().find(EnumSetEntity.class, sse1_id, 3); - - assert rev1.getEnums1().equals(TestTools.makeSet(E1.X)); - assert rev2.getEnums1().equals(TestTools.makeSet(E1.X, E1.Y)); - assert rev3.getEnums1().equals(TestTools.makeSet(E1.Y)); - - assert rev1.getEnums2().equals(TestTools.makeSet(E2.A)); - assert rev2.getEnums2().equals(TestTools.makeSet(E2.A)); - assert rev3.getEnums2().equals(TestTools.makeSet(E2.A)); - } + return new Class[] {EnumSetEntity.class}; + } @Test - @TestForIssue( jiraKey = "HHH-7780" ) + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); + + EnumSetEntity sse1 = new EnumSetEntity(); + + // Revision 1 (sse1: initialy 1 element) + em.getTransaction().begin(); + + sse1.getEnums1().add( E1.X ); + sse1.getEnums2().add( E2.A ); + + em.persist( sse1 ); + + em.getTransaction().commit(); + + // Revision 2 (sse1: adding 1 element/removing a non-existing element) + em.getTransaction().begin(); + + sse1 = em.find( EnumSetEntity.class, sse1.getId() ); + + sse1.getEnums1().add( E1.Y ); + sse1.getEnums2().remove( E2.B ); + + em.getTransaction().commit(); + + // Revision 3 (sse1: removing 1 element/adding an exisiting element) + em.getTransaction().begin(); + + sse1 = em.find( EnumSetEntity.class, sse1.getId() ); + + sse1.getEnums1().remove( E1.X ); + sse1.getEnums2().add( E2.A ); + + em.getTransaction().commit(); + + // + + sse1_id = sse1.getId(); + } + + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2, 3 ).equals( getAuditReader().getRevisions( EnumSetEntity.class, sse1_id ) ); + } + + @Test + public void testHistoryOfSse1() { + EnumSetEntity rev1 = getAuditReader().find( EnumSetEntity.class, sse1_id, 1 ); + EnumSetEntity rev2 = getAuditReader().find( EnumSetEntity.class, sse1_id, 2 ); + EnumSetEntity rev3 = getAuditReader().find( EnumSetEntity.class, sse1_id, 3 ); + + assert rev1.getEnums1().equals( TestTools.makeSet( E1.X ) ); + assert rev2.getEnums1().equals( TestTools.makeSet( E1.X, E1.Y ) ); + assert rev3.getEnums1().equals( TestTools.makeSet( E1.Y ) ); + + assert rev1.getEnums2().equals( TestTools.makeSet( E2.A ) ); + assert rev2.getEnums2().equals( TestTools.makeSet( E2.A ) ); + assert rev3.getEnums2().equals( TestTools.makeSet( E2.A ) ); + } + + @Test + @TestForIssue(jiraKey = "HHH-7780") public void testEnumRepresentation() { EntityManager entityManager = getEntityManager(); - List enums1 = entityManager.createNativeQuery( "SELECT enums1 FROM EnumSetEntity_enums1_AUD ORDER BY rev ASC" ).getResultList(); - List enums2 = entityManager.createNativeQuery( "SELECT enums2 FROM EnumSetEntity_enums2_AUD ORDER BY rev ASC" ).getResultList(); + List enums1 = entityManager.createNativeQuery( + "SELECT enums1 FROM EnumSetEntity_enums1_AUD ORDER BY rev ASC" + ).getResultList(); + List enums2 = entityManager.createNativeQuery( + "SELECT enums2 FROM EnumSetEntity_enums2_AUD ORDER BY rev ASC" + ).getResultList(); entityManager.close(); Assert.assertEquals( Arrays.asList( "X", "Y", "X" ), enums1 ); diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/StringList.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/StringList.java index 0829fb420e..94e05f726a 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/StringList.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/StringList.java @@ -23,104 +23,104 @@ */ package org.hibernate.envers.test.integration.collection; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.Collections; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.collection.StringListEntity; import org.hibernate.envers.test.tools.TestTools; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class StringList extends BaseEnversJPAFunctionalTestCase { - private Integer sle1_id; - private Integer sle2_id; + private Integer sle1_id; + private Integer sle2_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { StringListEntity.class }; - } + return new Class[] {StringListEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - StringListEntity sle1 = new StringListEntity(); - StringListEntity sle2 = new StringListEntity(); + StringListEntity sle1 = new StringListEntity(); + StringListEntity sle2 = new StringListEntity(); - // Revision 1 (sle1: initialy empty, sle2: initialy 2 elements) - em.getTransaction().begin(); + // Revision 1 (sle1: initialy empty, sle2: initialy 2 elements) + em.getTransaction().begin(); - sle2.getStrings().add("sle2_string1"); - sle2.getStrings().add("sle2_string2"); + sle2.getStrings().add( "sle2_string1" ); + sle2.getStrings().add( "sle2_string2" ); - em.persist(sle1); - em.persist(sle2); + em.persist( sle1 ); + em.persist( sle2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 (sle1: adding 2 elements, sle2: adding an existing element) - em.getTransaction().begin(); + // Revision 2 (sle1: adding 2 elements, sle2: adding an existing element) + em.getTransaction().begin(); - sle1 = em.find(StringListEntity.class, sle1.getId()); - sle2 = em.find(StringListEntity.class, sle2.getId()); + sle1 = em.find( StringListEntity.class, sle1.getId() ); + sle2 = em.find( StringListEntity.class, sle2.getId() ); - sle1.getStrings().add("sle1_string1"); - sle1.getStrings().add("sle1_string2"); + sle1.getStrings().add( "sle1_string1" ); + sle1.getStrings().add( "sle1_string2" ); - sle2.getStrings().add("sle2_string1"); + sle2.getStrings().add( "sle2_string1" ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 (sle1: replacing an element at index 0, sle2: removing an element at index 0) - em.getTransaction().begin(); + // Revision 3 (sle1: replacing an element at index 0, sle2: removing an element at index 0) + em.getTransaction().begin(); - sle1 = em.find(StringListEntity.class, sle1.getId()); - sle2 = em.find(StringListEntity.class, sle2.getId()); + sle1 = em.find( StringListEntity.class, sle1.getId() ); + sle2 = em.find( StringListEntity.class, sle2.getId() ); - sle1.getStrings().set(0, "sle1_string3"); + sle1.getStrings().set( 0, "sle1_string3" ); - sle2.getStrings().remove(0); + sle2.getStrings().remove( 0 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // + // - sle1_id = sle1.getId(); - sle2_id = sle2.getId(); - } + sle1_id = sle1.getId(); + sle2_id = sle2.getId(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2, 3).equals(getAuditReader().getRevisions(StringListEntity.class, sle1_id)); - assert Arrays.asList(1, 2, 3).equals(getAuditReader().getRevisions(StringListEntity.class, sle2_id)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2, 3 ).equals( getAuditReader().getRevisions( StringListEntity.class, sle1_id ) ); + assert Arrays.asList( 1, 2, 3 ).equals( getAuditReader().getRevisions( StringListEntity.class, sle2_id ) ); + } - @Test - public void testHistoryOfSle1() { - StringListEntity rev1 = getAuditReader().find(StringListEntity.class, sle1_id, 1); - StringListEntity rev2 = getAuditReader().find(StringListEntity.class, sle1_id, 2); - StringListEntity rev3 = getAuditReader().find(StringListEntity.class, sle1_id, 3); + @Test + public void testHistoryOfSle1() { + StringListEntity rev1 = getAuditReader().find( StringListEntity.class, sle1_id, 1 ); + StringListEntity rev2 = getAuditReader().find( StringListEntity.class, sle1_id, 2 ); + StringListEntity rev3 = getAuditReader().find( StringListEntity.class, sle1_id, 3 ); - assert rev1.getStrings().equals(Collections.EMPTY_LIST); - assert rev2.getStrings().equals(TestTools.makeList("sle1_string1", "sle1_string2")); - assert rev3.getStrings().equals(TestTools.makeList("sle1_string3", "sle1_string2")); - } + assert rev1.getStrings().equals( Collections.EMPTY_LIST ); + assert rev2.getStrings().equals( TestTools.makeList( "sle1_string1", "sle1_string2" ) ); + assert rev3.getStrings().equals( TestTools.makeList( "sle1_string3", "sle1_string2" ) ); + } - @Test - public void testHistoryOfSse2() { - StringListEntity rev1 = getAuditReader().find(StringListEntity.class, sle2_id, 1); - StringListEntity rev2 = getAuditReader().find(StringListEntity.class, sle2_id, 2); - StringListEntity rev3 = getAuditReader().find(StringListEntity.class, sle2_id, 3); + @Test + public void testHistoryOfSse2() { + StringListEntity rev1 = getAuditReader().find( StringListEntity.class, sle2_id, 1 ); + StringListEntity rev2 = getAuditReader().find( StringListEntity.class, sle2_id, 2 ); + StringListEntity rev3 = getAuditReader().find( StringListEntity.class, sle2_id, 3 ); - assert rev1.getStrings().equals(TestTools.makeList("sle2_string1", "sle2_string2")); - assert rev2.getStrings().equals(TestTools.makeList("sle2_string1", "sle2_string2", "sle2_string1")); - assert rev3.getStrings().equals(TestTools.makeList("sle2_string2", "sle2_string1")); - } + assert rev1.getStrings().equals( TestTools.makeList( "sle2_string1", "sle2_string2" ) ); + assert rev2.getStrings().equals( TestTools.makeList( "sle2_string1", "sle2_string2", "sle2_string1" ) ); + assert rev3.getStrings().equals( TestTools.makeList( "sle2_string2", "sle2_string1" ) ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/StringMap.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/StringMap.java index 1888108051..be1f21b619 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/StringMap.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/StringMap.java @@ -23,115 +23,115 @@ */ package org.hibernate.envers.test.integration.collection; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.Collections; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.collection.StringMapEntity; import org.hibernate.envers.test.tools.TestTools; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class StringMap extends BaseEnversJPAFunctionalTestCase { - private Integer sme1_id; - private Integer sme2_id; + private Integer sme1_id; + private Integer sme2_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { StringMapEntity.class }; - } + return new Class[] {StringMapEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - StringMapEntity sme1 = new StringMapEntity(); - StringMapEntity sme2 = new StringMapEntity(); + StringMapEntity sme1 = new StringMapEntity(); + StringMapEntity sme2 = new StringMapEntity(); - // Revision 1 (sme1: initialy empty, sme2: initialy 1 mapping) - em.getTransaction().begin(); + // Revision 1 (sme1: initialy empty, sme2: initialy 1 mapping) + em.getTransaction().begin(); - sme2.getStrings().put("1", "a"); + sme2.getStrings().put( "1", "a" ); - em.persist(sme1); - em.persist(sme2); + em.persist( sme1 ); + em.persist( sme2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 (sme1: adding 2 mappings, sme2: no changes) - em.getTransaction().begin(); + // Revision 2 (sme1: adding 2 mappings, sme2: no changes) + em.getTransaction().begin(); - sme1 = em.find(StringMapEntity.class, sme1.getId()); - sme2 = em.find(StringMapEntity.class, sme2.getId()); + sme1 = em.find( StringMapEntity.class, sme1.getId() ); + sme2 = em.find( StringMapEntity.class, sme2.getId() ); - sme1.getStrings().put("1", "a"); - sme1.getStrings().put("2", "b"); + sme1.getStrings().put( "1", "a" ); + sme1.getStrings().put( "2", "b" ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 (sme1: removing an existing mapping, sme2: replacing a value) - em.getTransaction().begin(); + // Revision 3 (sme1: removing an existing mapping, sme2: replacing a value) + em.getTransaction().begin(); - sme1 = em.find(StringMapEntity.class, sme1.getId()); - sme2 = em.find(StringMapEntity.class, sme2.getId()); + sme1 = em.find( StringMapEntity.class, sme1.getId() ); + sme2 = em.find( StringMapEntity.class, sme2.getId() ); - sme1.getStrings().remove("1"); - sme2.getStrings().put("1", "b"); - - em.getTransaction().commit(); + sme1.getStrings().remove( "1" ); + sme2.getStrings().put( "1", "b" ); - // No revision (sme1: removing a non-existing mapping, sme2: replacing with the same value) - em.getTransaction().begin(); + em.getTransaction().commit(); - sme1 = em.find(StringMapEntity.class, sme1.getId()); - sme2 = em.find(StringMapEntity.class, sme2.getId()); + // No revision (sme1: removing a non-existing mapping, sme2: replacing with the same value) + em.getTransaction().begin(); - sme1.getStrings().remove("3"); - sme2.getStrings().put("1", "b"); + sme1 = em.find( StringMapEntity.class, sme1.getId() ); + sme2 = em.find( StringMapEntity.class, sme2.getId() ); - em.getTransaction().commit(); + sme1.getStrings().remove( "3" ); + sme2.getStrings().put( "1", "b" ); - // + em.getTransaction().commit(); - sme1_id = sme1.getId(); - sme2_id = sme2.getId(); - } + // - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2, 3).equals(getAuditReader().getRevisions(StringMapEntity.class, sme1_id)); - assert Arrays.asList(1, 3).equals(getAuditReader().getRevisions(StringMapEntity.class, sme2_id)); - } + sme1_id = sme1.getId(); + sme2_id = sme2.getId(); + } - @Test - public void testHistoryOfSse1() { - StringMapEntity rev1 = getAuditReader().find(StringMapEntity.class, sme1_id, 1); - StringMapEntity rev2 = getAuditReader().find(StringMapEntity.class, sme1_id, 2); - StringMapEntity rev3 = getAuditReader().find(StringMapEntity.class, sme1_id, 3); - StringMapEntity rev4 = getAuditReader().find(StringMapEntity.class, sme1_id, 4); + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2, 3 ).equals( getAuditReader().getRevisions( StringMapEntity.class, sme1_id ) ); + assert Arrays.asList( 1, 3 ).equals( getAuditReader().getRevisions( StringMapEntity.class, sme2_id ) ); + } - assert rev1.getStrings().equals(Collections.EMPTY_MAP); - assert rev2.getStrings().equals(TestTools.makeMap("1", "a", "2", "b")); - assert rev3.getStrings().equals(TestTools.makeMap("2", "b")); - assert rev4.getStrings().equals(TestTools.makeMap("2", "b")); - } + @Test + public void testHistoryOfSse1() { + StringMapEntity rev1 = getAuditReader().find( StringMapEntity.class, sme1_id, 1 ); + StringMapEntity rev2 = getAuditReader().find( StringMapEntity.class, sme1_id, 2 ); + StringMapEntity rev3 = getAuditReader().find( StringMapEntity.class, sme1_id, 3 ); + StringMapEntity rev4 = getAuditReader().find( StringMapEntity.class, sme1_id, 4 ); - @Test - public void testHistoryOfSse2() { - StringMapEntity rev1 = getAuditReader().find(StringMapEntity.class, sme2_id, 1); - StringMapEntity rev2 = getAuditReader().find(StringMapEntity.class, sme2_id, 2); - StringMapEntity rev3 = getAuditReader().find(StringMapEntity.class, sme2_id, 3); - StringMapEntity rev4 = getAuditReader().find(StringMapEntity.class, sme2_id, 4); + assert rev1.getStrings().equals( Collections.EMPTY_MAP ); + assert rev2.getStrings().equals( TestTools.makeMap( "1", "a", "2", "b" ) ); + assert rev3.getStrings().equals( TestTools.makeMap( "2", "b" ) ); + assert rev4.getStrings().equals( TestTools.makeMap( "2", "b" ) ); + } - assert rev1.getStrings().equals(TestTools.makeMap("1", "a")); - assert rev2.getStrings().equals(TestTools.makeMap("1", "a")); - assert rev3.getStrings().equals(TestTools.makeMap("1", "b")); - assert rev4.getStrings().equals(TestTools.makeMap("1", "b")); - } + @Test + public void testHistoryOfSse2() { + StringMapEntity rev1 = getAuditReader().find( StringMapEntity.class, sme2_id, 1 ); + StringMapEntity rev2 = getAuditReader().find( StringMapEntity.class, sme2_id, 2 ); + StringMapEntity rev3 = getAuditReader().find( StringMapEntity.class, sme2_id, 3 ); + StringMapEntity rev4 = getAuditReader().find( StringMapEntity.class, sme2_id, 4 ); + + assert rev1.getStrings().equals( TestTools.makeMap( "1", "a" ) ); + assert rev2.getStrings().equals( TestTools.makeMap( "1", "a" ) ); + assert rev3.getStrings().equals( TestTools.makeMap( "1", "b" ) ); + assert rev4.getStrings().equals( TestTools.makeMap( "1", "b" ) ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/StringSet.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/StringSet.java index 3aed0aa607..898e4679e4 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/StringSet.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/StringSet.java @@ -23,103 +23,103 @@ */ package org.hibernate.envers.test.integration.collection; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.Collections; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.collection.StringSetEntity; import org.hibernate.envers.test.tools.TestTools; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class StringSet extends BaseEnversJPAFunctionalTestCase { - private Integer sse1_id; - private Integer sse2_id; + private Integer sse1_id; + private Integer sse2_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { StringSetEntity.class }; - } + return new Class[] {StringSetEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - StringSetEntity sse1 = new StringSetEntity(); - StringSetEntity sse2 = new StringSetEntity(); + StringSetEntity sse1 = new StringSetEntity(); + StringSetEntity sse2 = new StringSetEntity(); - // Revision 1 (sse1: initialy empty, sse2: initialy 2 elements) - em.getTransaction().begin(); + // Revision 1 (sse1: initialy empty, sse2: initialy 2 elements) + em.getTransaction().begin(); - sse2.getStrings().add("sse2_string1"); - sse2.getStrings().add("sse2_string2"); + sse2.getStrings().add( "sse2_string1" ); + sse2.getStrings().add( "sse2_string2" ); - em.persist(sse1); - em.persist(sse2); + em.persist( sse1 ); + em.persist( sse2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 (sse1: adding 2 elements, sse2: adding an existing element) - em.getTransaction().begin(); + // Revision 2 (sse1: adding 2 elements, sse2: adding an existing element) + em.getTransaction().begin(); - sse1 = em.find(StringSetEntity.class, sse1.getId()); - sse2 = em.find(StringSetEntity.class, sse2.getId()); + sse1 = em.find( StringSetEntity.class, sse1.getId() ); + sse2 = em.find( StringSetEntity.class, sse2.getId() ); - sse1.getStrings().add("sse1_string1"); - sse1.getStrings().add("sse1_string2"); + sse1.getStrings().add( "sse1_string1" ); + sse1.getStrings().add( "sse1_string2" ); - sse2.getStrings().add("sse2_string1"); + sse2.getStrings().add( "sse2_string1" ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 (sse1: removing a non-existing element, sse2: removing one element) - em.getTransaction().begin(); + // Revision 3 (sse1: removing a non-existing element, sse2: removing one element) + em.getTransaction().begin(); - sse1 = em.find(StringSetEntity.class, sse1.getId()); - sse2 = em.find(StringSetEntity.class, sse2.getId()); + sse1 = em.find( StringSetEntity.class, sse1.getId() ); + sse2 = em.find( StringSetEntity.class, sse2.getId() ); - sse1.getStrings().remove("sse1_string3"); - sse2.getStrings().remove("sse2_string1"); + sse1.getStrings().remove( "sse1_string3" ); + sse2.getStrings().remove( "sse2_string1" ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // + // - sse1_id = sse1.getId(); - sse2_id = sse2.getId(); - } + sse1_id = sse1.getId(); + sse2_id = sse2.getId(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(StringSetEntity.class, sse1_id)); - assert Arrays.asList(1, 3).equals(getAuditReader().getRevisions(StringSetEntity.class, sse2_id)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( StringSetEntity.class, sse1_id ) ); + assert Arrays.asList( 1, 3 ).equals( getAuditReader().getRevisions( StringSetEntity.class, sse2_id ) ); + } - @Test - public void testHistoryOfSse1() { - StringSetEntity rev1 = getAuditReader().find(StringSetEntity.class, sse1_id, 1); - StringSetEntity rev2 = getAuditReader().find(StringSetEntity.class, sse1_id, 2); - StringSetEntity rev3 = getAuditReader().find(StringSetEntity.class, sse1_id, 3); + @Test + public void testHistoryOfSse1() { + StringSetEntity rev1 = getAuditReader().find( StringSetEntity.class, sse1_id, 1 ); + StringSetEntity rev2 = getAuditReader().find( StringSetEntity.class, sse1_id, 2 ); + StringSetEntity rev3 = getAuditReader().find( StringSetEntity.class, sse1_id, 3 ); - assert rev1.getStrings().equals(Collections.EMPTY_SET); - assert rev2.getStrings().equals(TestTools.makeSet("sse1_string1", "sse1_string2")); - assert rev3.getStrings().equals(TestTools.makeSet("sse1_string1", "sse1_string2")); - } + assert rev1.getStrings().equals( Collections.EMPTY_SET ); + assert rev2.getStrings().equals( TestTools.makeSet( "sse1_string1", "sse1_string2" ) ); + assert rev3.getStrings().equals( TestTools.makeSet( "sse1_string1", "sse1_string2" ) ); + } - @Test - public void testHistoryOfSse2() { - StringSetEntity rev1 = getAuditReader().find(StringSetEntity.class, sse2_id, 1); - StringSetEntity rev2 = getAuditReader().find(StringSetEntity.class, sse2_id, 2); - StringSetEntity rev3 = getAuditReader().find(StringSetEntity.class, sse2_id, 3); + @Test + public void testHistoryOfSse2() { + StringSetEntity rev1 = getAuditReader().find( StringSetEntity.class, sse2_id, 1 ); + StringSetEntity rev2 = getAuditReader().find( StringSetEntity.class, sse2_id, 2 ); + StringSetEntity rev3 = getAuditReader().find( StringSetEntity.class, sse2_id, 3 ); - assert rev1.getStrings().equals(TestTools.makeSet("sse2_string1", "sse2_string2")); - assert rev2.getStrings().equals(TestTools.makeSet("sse2_string1", "sse2_string2")); - assert rev3.getStrings().equals(TestTools.makeSet("sse2_string2")); - } + assert rev1.getStrings().equals( TestTools.makeSet( "sse2_string1", "sse2_string2" ) ); + assert rev2.getStrings().equals( TestTools.makeSet( "sse2_string1", "sse2_string2" ) ); + assert rev3.getStrings().equals( TestTools.makeSet( "sse2_string2" ) ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/embeddable/BasicEmbeddableCollection.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/embeddable/BasicEmbeddableCollection.java index 6531197709..b917aeede9 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/embeddable/BasicEmbeddableCollection.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/embeddable/BasicEmbeddableCollection.java @@ -23,26 +23,27 @@ */ package org.hibernate.envers.test.integration.collection.embeddable; -import java.util.Arrays; import javax.persistence.EntityManager; - -import junit.framework.Assert; -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; + +import org.junit.Test; +import junit.framework.Assert; + import org.hibernate.testing.TestForIssue; /** * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ -@TestForIssue( jiraKey = "HHH-6613" ) +@TestForIssue(jiraKey = "HHH-6613") public class BasicEmbeddableCollection extends BaseEnversJPAFunctionalTestCase { private int id = -1; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { DarkCharacter.class }; + return new Class[] {DarkCharacter.class}; } @Test diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/embeddable/DarkCharacter.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/embeddable/DarkCharacter.java index 79db3ff12d..b7ef2afb68 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/embeddable/DarkCharacter.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/embeddable/DarkCharacter.java @@ -23,12 +23,12 @@ */ package org.hibernate.envers.test.integration.collection.embeddable; -import java.io.Serializable; -import java.util.HashSet; -import java.util.Set; import javax.persistence.ElementCollection; import javax.persistence.Entity; import javax.persistence.Id; +import java.io.Serializable; +import java.util.HashSet; +import java.util.Set; import org.hibernate.envers.Audited; @@ -56,13 +56,21 @@ public class DarkCharacter implements Serializable { @Override public boolean equals(Object o) { - if ( this == o ) return true; - if ( ! ( o instanceof DarkCharacter ) ) return false; + if ( this == o ) { + return true; + } + if ( !(o instanceof DarkCharacter) ) { + return false; + } DarkCharacter character = (DarkCharacter) o; - if ( id != character.id ) return false; - if ( kills != character.kills ) return false; + if ( id != character.id ) { + return false; + } + if ( kills != character.kills ) { + return false; + } return true; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/embeddable/EmbeddableList1.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/embeddable/EmbeddableList1.java index 49d207fae8..2de3e23a73 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/embeddable/EmbeddableList1.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/embeddable/EmbeddableList1.java @@ -23,17 +23,18 @@ */ package org.hibernate.envers.test.integration.collection.embeddable; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.Collections; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.collection.EmbeddableListEntity1; import org.hibernate.envers.test.entities.components.Component3; import org.hibernate.envers.test.entities.components.Component4; + +import org.junit.Test; + import org.hibernate.testing.TestForIssue; import static org.junit.Assert.assertEquals; @@ -41,7 +42,7 @@ import static org.junit.Assert.assertEquals; /** * @author Kristoffer Lundberg (kristoffer at cambio dot se) */ -@TestForIssue( jiraKey = "HHH-6613" ) +@TestForIssue(jiraKey = "HHH-6613") public class EmbeddableList1 extends BaseEnversJPAFunctionalTestCase { private Integer ele1_id = null; @@ -52,7 +53,7 @@ public class EmbeddableList1 extends BaseEnversJPAFunctionalTestCase { @Override protected Class[] getAnnotatedClasses() { - return new Class[] { EmbeddableListEntity1.class }; + return new Class[] {EmbeddableListEntity1.class}; } @Test @@ -99,7 +100,12 @@ public class EmbeddableList1 extends BaseEnversJPAFunctionalTestCase { @Test public void testRevisionsCounts() { - assertEquals( Arrays.asList( 1, 2, 3, 4 ), getAuditReader().getRevisions( EmbeddableListEntity1.class, ele1_id ) ); + assertEquals( + Arrays.asList( 1, 2, 3, 4 ), getAuditReader().getRevisions( + EmbeddableListEntity1.class, + ele1_id + ) + ); } @Test diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/embeddable/EmbeddableList2.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/embeddable/EmbeddableList2.java index 7cfc454008..cd10bcfd0a 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/embeddable/EmbeddableList2.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/embeddable/EmbeddableList2.java @@ -23,16 +23,17 @@ */ package org.hibernate.envers.test.integration.collection.embeddable; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrTestNoProxyEntity; import org.hibernate.envers.test.entities.collection.EmbeddableListEntity2; import org.hibernate.envers.test.entities.components.relations.ManyToOneEagerComponent; + +import org.junit.Test; + import org.hibernate.testing.TestForIssue; import static org.junit.Assert.assertEquals; @@ -45,7 +46,7 @@ import static org.junit.Assert.assertTrue; * * @author thiagolrc */ -@TestForIssue( jiraKey = "HHH-6613" ) +@TestForIssue(jiraKey = "HHH-6613") public class EmbeddableList2 extends BaseEnversJPAFunctionalTestCase { private Integer ele_id1 = null; @@ -61,7 +62,7 @@ public class EmbeddableList2 extends BaseEnversJPAFunctionalTestCase { @Override protected Class[] getAnnotatedClasses() { - return new Class[] { EmbeddableListEntity2.class, StrTestNoProxyEntity.class }; + return new Class[] {EmbeddableListEntity2.class, StrTestNoProxyEntity.class}; } @Test @@ -97,7 +98,9 @@ public class EmbeddableList2 extends BaseEnversJPAFunctionalTestCase { ele1 = em.find( EmbeddableListEntity2.class, ele1.getId() ); em.persist( entity3 ); ele1.getComponentList().get( ele1.getComponentList().indexOf( manyToOneComponent2 ) ).setEntity( entity3 ); - ele1.getComponentList().get( ele1.getComponentList().indexOf( manyToOneComponent2 ) ).setData( "dataComponent3" ); + ele1.getComponentList() + .get( ele1.getComponentList().indexOf( manyToOneComponent2 ) ) + .setData( "dataComponent3" ); em.getTransaction().commit(); // Revision 5 (ele1: adding a new many-to-one component) @@ -111,7 +114,10 @@ public class EmbeddableList2 extends BaseEnversJPAFunctionalTestCase { // Revision 6 (ele1: changing the component's entity properties) em.getTransaction().begin(); ele1 = em.find( EmbeddableListEntity2.class, ele1.getId() ); - ele1.getComponentList().get( ele1.getComponentList().indexOf( manyToOneComponent4 ) ).getEntity().setStr( "sat4" ); + ele1.getComponentList() + .get( ele1.getComponentList().indexOf( manyToOneComponent4 ) ) + .getEntity() + .setStr( "sat4" ); em.getTransaction().commit(); // Revision 7 (ele1: removing component) diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/embeddable/EmbeddableMap.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/embeddable/EmbeddableMap.java index 869c908cc2..2fa9be12dd 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/embeddable/EmbeddableMap.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/embeddable/EmbeddableMap.java @@ -23,12 +23,9 @@ */ package org.hibernate.envers.test.integration.collection.embeddable; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.Collections; -import javax.persistence.EntityManager; - -import org.junit.Assert; -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; @@ -36,12 +33,16 @@ import org.hibernate.envers.test.entities.collection.EmbeddableMapEntity; import org.hibernate.envers.test.entities.components.Component3; import org.hibernate.envers.test.entities.components.Component4; import org.hibernate.envers.test.tools.TestTools; + +import org.junit.Assert; +import org.junit.Test; + import org.hibernate.testing.TestForIssue; /** * @author Kristoffer Lundberg (kristoffer at cambio dot se) */ -@TestForIssue( jiraKey = "HHH-6613" ) +@TestForIssue(jiraKey = "HHH-6613") public class EmbeddableMap extends BaseEnversJPAFunctionalTestCase { private Integer eme1_id = null; private Integer eme2_id = null; @@ -53,7 +54,7 @@ public class EmbeddableMap extends BaseEnversJPAFunctionalTestCase { @Override protected Class[] getAnnotatedClasses() { - return new Class[] { EmbeddableMapEntity.class }; + return new Class[] {EmbeddableMapEntity.class}; } @Test @@ -103,8 +104,18 @@ public class EmbeddableMap extends BaseEnversJPAFunctionalTestCase { @Test public void testRevisionsCounts() { - Assert.assertEquals( Arrays.asList( 1, 2, 3 ), getAuditReader().getRevisions( EmbeddableMapEntity.class, eme1_id ) ); - Assert.assertEquals( Arrays.asList( 1, 3 ), getAuditReader().getRevisions( EmbeddableMapEntity.class, eme2_id ) ); + Assert.assertEquals( + Arrays.asList( 1, 2, 3 ), getAuditReader().getRevisions( + EmbeddableMapEntity.class, + eme1_id + ) + ); + Assert.assertEquals( + Arrays.asList( 1, 3 ), getAuditReader().getRevisions( + EmbeddableMapEntity.class, + eme2_id + ) + ); } @Test diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/embeddable/EmbeddableSet.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/embeddable/EmbeddableSet.java index 0243319e9b..3bdb433431 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/embeddable/EmbeddableSet.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/embeddable/EmbeddableSet.java @@ -23,10 +23,8 @@ */ package org.hibernate.envers.test.integration.collection.embeddable; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; @@ -34,6 +32,9 @@ import org.hibernate.envers.test.entities.collection.EmbeddableSetEntity; import org.hibernate.envers.test.entities.components.Component3; import org.hibernate.envers.test.entities.components.Component4; import org.hibernate.envers.test.tools.TestTools; + +import org.junit.Test; + import org.hibernate.testing.TestForIssue; import static org.junit.Assert.assertEquals; @@ -41,7 +42,7 @@ import static org.junit.Assert.assertEquals; /** * @author Kristoffer Lundberg (kristoffer at cambio dot se) */ -@TestForIssue( jiraKey = "HHH-6613" ) +@TestForIssue(jiraKey = "HHH-6613") public class EmbeddableSet extends BaseEnversJPAFunctionalTestCase { private Integer ese1_id = null; @@ -54,7 +55,7 @@ public class EmbeddableSet extends BaseEnversJPAFunctionalTestCase { @Override protected Class[] getAnnotatedClasses() { - return new Class[] { EmbeddableSetEntity.class }; + return new Class[] {EmbeddableSetEntity.class}; } @Test @@ -131,7 +132,12 @@ public class EmbeddableSet extends BaseEnversJPAFunctionalTestCase { @Test public void testRevisionsCounts() { - assertEquals( Arrays.asList( 1, 2, 3, 4, 5, 6, 7 ), getAuditReader().getRevisions( EmbeddableSetEntity.class, ese1_id ) ); + assertEquals( + Arrays.asList( 1, 2, 3, 4, 5, 6, 7 ), getAuditReader().getRevisions( + EmbeddableSetEntity.class, + ese1_id + ) + ); } @Test diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/embeddable/Name.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/embeddable/Name.java index c9581814ff..d46d2a4a2d 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/embeddable/Name.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/embeddable/Name.java @@ -23,8 +23,8 @@ */ package org.hibernate.envers.test.integration.collection.embeddable; -import java.io.Serializable; import javax.persistence.Embeddable; +import java.io.Serializable; import org.hibernate.envers.Audited; @@ -47,12 +47,20 @@ public class Name implements Serializable { @Override public boolean equals(Object o) { - if ( this == o ) return true; - if ( !( o instanceof Name ) ) return false; + if ( this == o ) { + return true; + } + if ( !(o instanceof Name) ) { + return false; + } Name name = (Name) o; - if ( firstName != null ? !firstName.equals( name.firstName ) : name.firstName != null ) return false; - if ( lastName != null ? !lastName.equals( name.lastName ) : name.lastName != null ) return false; + if ( firstName != null ? !firstName.equals( name.firstName ) : name.firstName != null ) { + return false; + } + if ( lastName != null ? !lastName.equals( name.lastName ) : name.lastName != null ) { + return false; + } return true; } @@ -60,7 +68,7 @@ public class Name implements Serializable { @Override public int hashCode() { int result = firstName != null ? firstName.hashCode() : 0; - result = 31 * result + ( lastName != null ? lastName.hashCode() : 0 ); + result = 31 * result + (lastName != null ? lastName.hashCode() : 0); return result; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/mapkey/ComponentMapKey.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/mapkey/ComponentMapKey.java index 827dad8194..c2ba8a0711 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/mapkey/ComponentMapKey.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/mapkey/ComponentMapKey.java @@ -23,10 +23,8 @@ */ package org.hibernate.envers.test.integration.collection.mapkey; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; @@ -35,78 +33,90 @@ import org.hibernate.envers.test.entities.components.Component2; import org.hibernate.envers.test.entities.components.ComponentTestEntity; import org.hibernate.envers.test.tools.TestTools; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class ComponentMapKey extends BaseEnversJPAFunctionalTestCase { - private Integer cmke_id; + private Integer cmke_id; - private Integer cte1_id; - private Integer cte2_id; + private Integer cte1_id; + private Integer cte2_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { ComponentMapKeyEntity.class, ComponentTestEntity.class }; - } + return new Class[] {ComponentMapKeyEntity.class, ComponentTestEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - ComponentMapKeyEntity imke = new ComponentMapKeyEntity(); + ComponentMapKeyEntity imke = new ComponentMapKeyEntity(); - // Revision 1 (intialy 1 mapping) - em.getTransaction().begin(); + // Revision 1 (intialy 1 mapping) + em.getTransaction().begin(); - ComponentTestEntity cte1 = new ComponentTestEntity(new Component1("x1", "y2"), new Component2("a1", "b2")); - ComponentTestEntity cte2 = new ComponentTestEntity(new Component1("x1", "y2"), new Component2("a1", "b2")); + ComponentTestEntity cte1 = new ComponentTestEntity( + new Component1( "x1", "y2" ), new Component2( + "a1", + "b2" + ) + ); + ComponentTestEntity cte2 = new ComponentTestEntity( + new Component1( "x1", "y2" ), new Component2( + "a1", + "b2" + ) + ); - em.persist(cte1); - em.persist(cte2); + em.persist( cte1 ); + em.persist( cte2 ); - imke.getIdmap().put(cte1.getComp1(), cte1); + imke.getIdmap().put( cte1.getComp1(), cte1 ); - em.persist(imke); + em.persist( imke ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 (sse1: adding 1 mapping) - em.getTransaction().begin(); + // Revision 2 (sse1: adding 1 mapping) + em.getTransaction().begin(); - cte2 = em.find(ComponentTestEntity.class, cte2.getId()); - imke = em.find(ComponentMapKeyEntity.class, imke.getId()); + cte2 = em.find( ComponentTestEntity.class, cte2.getId() ); + imke = em.find( ComponentMapKeyEntity.class, imke.getId() ); - imke.getIdmap().put(cte2.getComp1(), cte2); + imke.getIdmap().put( cte2.getComp1(), cte2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // + // - cmke_id = imke.getId(); + cmke_id = imke.getId(); - cte1_id = cte1.getId(); - cte2_id = cte2.getId(); - } + cte1_id = cte1.getId(); + cte2_id = cte2.getId(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(ComponentMapKeyEntity.class, cmke_id)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( ComponentMapKeyEntity.class, cmke_id ) ); + } - @Test - public void testHistoryOfImke() { - ComponentTestEntity cte1 = getEntityManager().find(ComponentTestEntity.class, cte1_id); - ComponentTestEntity cte2 = getEntityManager().find(ComponentTestEntity.class, cte2_id); + @Test + public void testHistoryOfImke() { + ComponentTestEntity cte1 = getEntityManager().find( ComponentTestEntity.class, cte1_id ); + ComponentTestEntity cte2 = getEntityManager().find( ComponentTestEntity.class, cte2_id ); - // These fields are unversioned. - cte1.setComp2(null); - cte2.setComp2(null); + // These fields are unversioned. + cte1.setComp2( null ); + cte2.setComp2( null ); - ComponentMapKeyEntity rev1 = getAuditReader().find(ComponentMapKeyEntity.class, cmke_id, 1); - ComponentMapKeyEntity rev2 = getAuditReader().find(ComponentMapKeyEntity.class, cmke_id, 2); + ComponentMapKeyEntity rev1 = getAuditReader().find( ComponentMapKeyEntity.class, cmke_id, 1 ); + ComponentMapKeyEntity rev2 = getAuditReader().find( ComponentMapKeyEntity.class, cmke_id, 2 ); - assert rev1.getIdmap().equals(TestTools.makeMap(cte1.getComp1(), cte1)); - assert rev2.getIdmap().equals(TestTools.makeMap(cte1.getComp1(), cte1, cte2.getComp1(), cte2)); - } + assert rev1.getIdmap().equals( TestTools.makeMap( cte1.getComp1(), cte1 ) ); + assert rev2.getIdmap().equals( TestTools.makeMap( cte1.getComp1(), cte1, cte2.getComp1(), cte2 ) ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/mapkey/ComponentMapKeyEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/mapkey/ComponentMapKeyEntity.java index cd90b800ab..466024a354 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/mapkey/ComponentMapKeyEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/mapkey/ComponentMapKeyEntity.java @@ -22,14 +22,15 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.collection.mapkey; -import java.util.HashMap; -import java.util.Map; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.ManyToMany; import javax.persistence.MapKey; import javax.persistence.Table; +import java.util.HashMap; +import java.util.Map; import org.hibernate.envers.Audited; import org.hibernate.envers.test.entities.components.Component1; @@ -41,51 +42,57 @@ import org.hibernate.envers.test.entities.components.ComponentTestEntity; @Entity @Table(name = "CompMapKey") public class ComponentMapKeyEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - @Audited - @ManyToMany - @MapKey(name = "comp1") - private Map idmap; + @Audited + @ManyToMany + @MapKey(name = "comp1") + private Map idmap; - public ComponentMapKeyEntity() { - idmap = new HashMap(); - } + public ComponentMapKeyEntity() { + idmap = new HashMap(); + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public Map getIdmap() { - return idmap; - } + public Map getIdmap() { + return idmap; + } - public void setIdmap(Map idmap) { - this.idmap = idmap; - } + public void setIdmap(Map idmap) { + this.idmap = idmap; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ComponentMapKeyEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ComponentMapKeyEntity) ) { + return false; + } - ComponentMapKeyEntity that = (ComponentMapKeyEntity) o; + ComponentMapKeyEntity that = (ComponentMapKeyEntity) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - return (id != null ? id.hashCode() : 0); - } + public int hashCode() { + return (id != null ? id.hashCode() : 0); + } - public String toString() { - return "CMKE(id = " + id + ", idmap = " + idmap + ")"; - } + public String toString() { + return "CMKE(id = " + id + ", idmap = " + idmap + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/mapkey/IdMapKey.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/mapkey/IdMapKey.java index 4a55f6678d..de6288fb4c 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/mapkey/IdMapKey.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/mapkey/IdMapKey.java @@ -23,84 +23,84 @@ */ package org.hibernate.envers.test.integration.collection.mapkey; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrTestEntity; import org.hibernate.envers.test.tools.TestTools; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class IdMapKey extends BaseEnversJPAFunctionalTestCase { - private Integer imke_id; + private Integer imke_id; - private Integer ste1_id; - private Integer ste2_id; + private Integer ste1_id; + private Integer ste2_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { IdMapKeyEntity.class, StrTestEntity.class }; - } + return new Class[] {IdMapKeyEntity.class, StrTestEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - IdMapKeyEntity imke = new IdMapKeyEntity(); + IdMapKeyEntity imke = new IdMapKeyEntity(); - // Revision 1 (intialy 1 mapping) - em.getTransaction().begin(); + // Revision 1 (intialy 1 mapping) + em.getTransaction().begin(); - StrTestEntity ste1 = new StrTestEntity("x"); - StrTestEntity ste2 = new StrTestEntity("y"); + StrTestEntity ste1 = new StrTestEntity( "x" ); + StrTestEntity ste2 = new StrTestEntity( "y" ); - em.persist(ste1); - em.persist(ste2); + em.persist( ste1 ); + em.persist( ste2 ); - imke.getIdmap().put(ste1.getId(), ste1); + imke.getIdmap().put( ste1.getId(), ste1 ); - em.persist(imke); + em.persist( imke ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 (sse1: adding 1 mapping) - em.getTransaction().begin(); + // Revision 2 (sse1: adding 1 mapping) + em.getTransaction().begin(); - ste2 = em.find(StrTestEntity.class, ste2.getId()); - imke = em.find(IdMapKeyEntity.class, imke.getId()); + ste2 = em.find( StrTestEntity.class, ste2.getId() ); + imke = em.find( IdMapKeyEntity.class, imke.getId() ); - imke.getIdmap().put(ste2.getId(), ste2); + imke.getIdmap().put( ste2.getId(), ste2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // + // - imke_id = imke.getId(); + imke_id = imke.getId(); - ste1_id = ste1.getId(); - ste2_id = ste2.getId(); - } + ste1_id = ste1.getId(); + ste2_id = ste2.getId(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(IdMapKeyEntity.class, imke_id)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( IdMapKeyEntity.class, imke_id ) ); + } - @Test - public void testHistoryOfImke() { - StrTestEntity ste1 = getEntityManager().find(StrTestEntity.class, ste1_id); - StrTestEntity ste2 = getEntityManager().find(StrTestEntity.class, ste2_id); + @Test + public void testHistoryOfImke() { + StrTestEntity ste1 = getEntityManager().find( StrTestEntity.class, ste1_id ); + StrTestEntity ste2 = getEntityManager().find( StrTestEntity.class, ste2_id ); - IdMapKeyEntity rev1 = getAuditReader().find(IdMapKeyEntity.class, imke_id, 1); - IdMapKeyEntity rev2 = getAuditReader().find(IdMapKeyEntity.class, imke_id, 2); + IdMapKeyEntity rev1 = getAuditReader().find( IdMapKeyEntity.class, imke_id, 1 ); + IdMapKeyEntity rev2 = getAuditReader().find( IdMapKeyEntity.class, imke_id, 2 ); - assert rev1.getIdmap().equals(TestTools.makeMap(ste1.getId(), ste1)); - assert rev2.getIdmap().equals(TestTools.makeMap(ste1.getId(), ste1, ste2.getId(), ste2)); - } + assert rev1.getIdmap().equals( TestTools.makeMap( ste1.getId(), ste1 ) ); + assert rev2.getIdmap().equals( TestTools.makeMap( ste1.getId(), ste1, ste2.getId(), ste2 ) ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/mapkey/IdMapKeyEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/mapkey/IdMapKeyEntity.java index 50d144bf74..16fc4bd845 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/mapkey/IdMapKeyEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/mapkey/IdMapKeyEntity.java @@ -22,14 +22,15 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.collection.mapkey; -import java.util.HashMap; -import java.util.Map; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.ManyToMany; import javax.persistence.MapKey; import javax.persistence.Table; +import java.util.HashMap; +import java.util.Map; import org.hibernate.envers.Audited; import org.hibernate.envers.test.entities.StrTestEntity; @@ -40,51 +41,57 @@ import org.hibernate.envers.test.entities.StrTestEntity; @Entity @Table(name = "IdMapKey") public class IdMapKeyEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - @Audited - @ManyToMany - @MapKey - private Map idmap; + @Audited + @ManyToMany + @MapKey + private Map idmap; - public IdMapKeyEntity() { - idmap = new HashMap(); - } + public IdMapKeyEntity() { + idmap = new HashMap(); + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public Map getIdmap() { - return idmap; - } + public Map getIdmap() { + return idmap; + } - public void setIdmap(Map idmap) { - this.idmap = idmap; - } + public void setIdmap(Map idmap) { + this.idmap = idmap; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof IdMapKeyEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof IdMapKeyEntity) ) { + return false; + } - IdMapKeyEntity that = (IdMapKeyEntity) o; + IdMapKeyEntity that = (IdMapKeyEntity) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - return (id != null ? id.hashCode() : 0); - } + public int hashCode() { + return (id != null ? id.hashCode() : 0); + } - public String toString() { - return "IMKE(id = " + id + ", idmap = " + idmap + ")"; - } + public String toString() { + return "IMKE(id = " + id + ", idmap = " + idmap + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/AbstractCollectionChangeTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/AbstractCollectionChangeTest.java index 194bf6cbe7..294f109f21 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/AbstractCollectionChangeTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/AbstractCollectionChangeTest.java @@ -2,63 +2,63 @@ package org.hibernate.envers.test.integration.collection.norevision; import java.util.List; -import org.junit.Test; - import org.hibernate.Session; import org.hibernate.cfg.Configuration; import org.hibernate.envers.configuration.EnversSettings; import org.hibernate.envers.test.BaseEnversFunctionalTestCase; import org.hibernate.envers.test.Priority; -public abstract class AbstractCollectionChangeTest extends BaseEnversFunctionalTestCase { - protected Integer personId; +import org.junit.Test; - @Override - protected void configure(Configuration configuration) { - configuration.setProperty(EnversSettings.REVISION_ON_COLLECTION_CHANGE, getCollectionChangeValue()); - } +public abstract class AbstractCollectionChangeTest extends BaseEnversFunctionalTestCase { + protected Integer personId; - @Override - protected Class[] getAnnotatedClasses() { - return new Class[]{Person.class, Name.class}; - } + @Override + protected void configure(Configuration configuration) { + configuration.setProperty( EnversSettings.REVISION_ON_COLLECTION_CHANGE, getCollectionChangeValue() ); + } - protected abstract String getCollectionChangeValue(); + @Override + protected Class[] getAnnotatedClasses() { + return new Class[] {Person.class, Name.class}; + } - protected abstract List getExpectedPersonRevisions(); + protected abstract String getCollectionChangeValue(); - @Test - @Priority(10) - public void initData() { - Session session = openSession(); + protected abstract List getExpectedPersonRevisions(); - // Rev 1 - session.getTransaction().begin(); - Person p = new Person(); - Name n = new Name(); - n.setName("name1"); - p.getNames().add(n); - session.saveOrUpdate(p); - session.getTransaction().commit(); + @Test + @Priority(10) + public void initData() { + Session session = openSession(); - // Rev 2 - session.getTransaction().begin(); - n.setName("Changed name"); - session.saveOrUpdate(p); - session.getTransaction().commit(); + // Rev 1 + session.getTransaction().begin(); + Person p = new Person(); + Name n = new Name(); + n.setName( "name1" ); + p.getNames().add( n ); + session.saveOrUpdate( p ); + session.getTransaction().commit(); - // Rev 3 - session.getTransaction().begin(); - Name n2 = new Name(); - n2.setName("name2"); - p.getNames().add(n2); - session.getTransaction().commit(); + // Rev 2 + session.getTransaction().begin(); + n.setName( "Changed name" ); + session.saveOrUpdate( p ); + session.getTransaction().commit(); - personId = p.getId(); - } + // Rev 3 + session.getTransaction().begin(); + Name n2 = new Name(); + n2.setName( "name2" ); + p.getNames().add( n2 ); + session.getTransaction().commit(); - @Test - public void testPersonRevisionCount() { - assert getAuditReader().getRevisions(Person.class, personId).equals(getExpectedPersonRevisions()); - } + personId = p.getId(); + } + + @Test + public void testPersonRevisionCount() { + assert getAuditReader().getRevisions( Person.class, personId ).equals( getExpectedPersonRevisions() ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/CollectionChangeNoRevisionTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/CollectionChangeNoRevisionTest.java index 58f9f982d9..73d0a4d56a 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/CollectionChangeNoRevisionTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/CollectionChangeNoRevisionTest.java @@ -1,14 +1,15 @@ package org.hibernate.envers.test.integration.collection.norevision; + import java.util.Arrays; import java.util.List; public class CollectionChangeNoRevisionTest extends AbstractCollectionChangeTest { - protected String getCollectionChangeValue() { - return "false"; - } + protected String getCollectionChangeValue() { + return "false"; + } - @Override - protected List getExpectedPersonRevisions() { - return Arrays.asList(1); - } + @Override + protected List getExpectedPersonRevisions() { + return Arrays.asList( 1 ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/CollectionChangeRevisionTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/CollectionChangeRevisionTest.java index 66026527fc..57a98a7b1a 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/CollectionChangeRevisionTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/CollectionChangeRevisionTest.java @@ -1,15 +1,16 @@ package org.hibernate.envers.test.integration.collection.norevision; + import java.util.Arrays; import java.util.List; -public class CollectionChangeRevisionTest extends AbstractCollectionChangeTest { - @Override - protected String getCollectionChangeValue() { - return "true"; - } +public class CollectionChangeRevisionTest extends AbstractCollectionChangeTest { + @Override + protected String getCollectionChangeValue() { + return "true"; + } - @Override - protected List getExpectedPersonRevisions() { - return Arrays.asList(1, 3); - } + @Override + protected List getExpectedPersonRevisions() { + return Arrays.asList( 1, 3 ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/Name.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/Name.java index 9d6fa4ef4d..9427dc0ed3 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/Name.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/Name.java @@ -1,46 +1,47 @@ package org.hibernate.envers.test.integration.collection.norevision; -import java.io.Serializable; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; +import java.io.Serializable; import org.hibernate.envers.Audited; @Audited @Entity public class Name implements Serializable { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - private String name; - @ManyToOne - @JoinColumn(name = "person_id", insertable = false, updatable = false) - private Person person; + private String name; + @ManyToOne + @JoinColumn(name = "person_id", insertable = false, updatable = false) + private Person person; - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getName() { - return name; - } + public String getName() { + return name; + } - public void setName(String name) { - this.name = name; - } + public void setName(String name) { + this.name = name; + } - public Person getPerson() { - return person; - } + public Person getPerson() { + return person; + } - public void setPerson(Person person) { - this.person = person; - } + public void setPerson(Person person) { + this.person = person; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/Person.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/Person.java index 3c01c1f518..bc1c5acd1b 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/Person.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/Person.java @@ -1,13 +1,14 @@ package org.hibernate.envers.test.integration.collection.norevision; -import java.io.Serializable; -import java.util.HashSet; -import java.util.Set; + import javax.persistence.CascadeType; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.OneToMany; +import java.io.Serializable; +import java.util.HashSet; +import java.util.Set; import org.hibernate.envers.AuditMappedBy; import org.hibernate.envers.Audited; @@ -15,30 +16,31 @@ import org.hibernate.envers.Audited; @Audited @Entity public class Person implements Serializable { - @Id @GeneratedValue - private Integer id; - @AuditMappedBy(mappedBy = "person") - @OneToMany(cascade = CascadeType.ALL) - @JoinColumn(name = "person_id") - private Set names; + @Id + @GeneratedValue + private Integer id; + @AuditMappedBy(mappedBy = "person") + @OneToMany(cascade = CascadeType.ALL) + @JoinColumn(name = "person_id") + private Set names; - public Person() { - names = new HashSet(); - } + public Person() { + names = new HashSet(); + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public Set getNames() { - return names; - } + public Set getNames() { + return names; + } - public void setNames(Set names) { - this.names = names; - } + public void setNames(Set names) { + this.names = names; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/Components.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/Components.java index 56ed7f0d76..3e54435d33 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/Components.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/Components.java @@ -23,10 +23,8 @@ */ package org.hibernate.envers.test.integration.components; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; @@ -34,143 +32,155 @@ import org.hibernate.envers.test.entities.components.Component1; import org.hibernate.envers.test.entities.components.Component2; import org.hibernate.envers.test.entities.components.ComponentTestEntity; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ -public class Components extends BaseEnversJPAFunctionalTestCase { - private Integer id1; - private Integer id2; - private Integer id3; - private Integer id4; +public class Components extends BaseEnversJPAFunctionalTestCase { + private Integer id1; + private Integer id2; + private Integer id3; + private Integer id4; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { ComponentTestEntity.class }; - } + return new Class[] {ComponentTestEntity.class}; + } - @Test - @Priority(10) - public void initData() { - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); + @Test + @Priority(10) + public void initData() { + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); - ComponentTestEntity cte1 = new ComponentTestEntity(new Component1("a", "b"), new Component2("x", "y")); - ComponentTestEntity cte2 = new ComponentTestEntity(new Component1("a2", "b2"), new Component2("x2", "y2")); - ComponentTestEntity cte3 = new ComponentTestEntity(new Component1("a3", "b3"), new Component2("x3", "y3")); - ComponentTestEntity cte4 = new ComponentTestEntity(null, null); + ComponentTestEntity cte1 = new ComponentTestEntity( new Component1( "a", "b" ), new Component2( "x", "y" ) ); + ComponentTestEntity cte2 = new ComponentTestEntity( + new Component1( "a2", "b2" ), new Component2( + "x2", + "y2" + ) + ); + ComponentTestEntity cte3 = new ComponentTestEntity( + new Component1( "a3", "b3" ), new Component2( + "x3", + "y3" + ) + ); + ComponentTestEntity cte4 = new ComponentTestEntity( null, null ); - em.persist(cte1); - em.persist(cte2); - em.persist(cte3); - em.persist(cte4); + em.persist( cte1 ); + em.persist( cte2 ); + em.persist( cte3 ); + em.persist( cte4 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em = getEntityManager(); - em.getTransaction().begin(); + // Revision 2 + em = getEntityManager(); + em.getTransaction().begin(); - cte1 = em.find(ComponentTestEntity.class, cte1.getId()); - cte2 = em.find(ComponentTestEntity.class, cte2.getId()); - cte3 = em.find(ComponentTestEntity.class, cte3.getId()); - cte4 = em.find(ComponentTestEntity.class, cte4.getId()); + cte1 = em.find( ComponentTestEntity.class, cte1.getId() ); + cte2 = em.find( ComponentTestEntity.class, cte2.getId() ); + cte3 = em.find( ComponentTestEntity.class, cte3.getId() ); + cte4 = em.find( ComponentTestEntity.class, cte4.getId() ); - cte1.setComp1(new Component1("a'", "b'")); - cte2.getComp1().setStr1("a2'"); - cte3.getComp2().setStr6("y3'"); - cte4.setComp1(new Component1()); - cte4.getComp1().setStr1("n"); - cte4.setComp2(new Component2()); - cte4.getComp2().setStr5("m"); + cte1.setComp1( new Component1( "a'", "b'" ) ); + cte2.getComp1().setStr1( "a2'" ); + cte3.getComp2().setStr6( "y3'" ); + cte4.setComp1( new Component1() ); + cte4.getComp1().setStr1( "n" ); + cte4.setComp2( new Component2() ); + cte4.getComp2().setStr5( "m" ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 - em = getEntityManager(); - em.getTransaction().begin(); + // Revision 3 + em = getEntityManager(); + em.getTransaction().begin(); - cte1 = em.find(ComponentTestEntity.class, cte1.getId()); - cte2 = em.find(ComponentTestEntity.class, cte2.getId()); - cte3 = em.find(ComponentTestEntity.class, cte3.getId()); - cte4 = em.find(ComponentTestEntity.class, cte4.getId()); + cte1 = em.find( ComponentTestEntity.class, cte1.getId() ); + cte2 = em.find( ComponentTestEntity.class, cte2.getId() ); + cte3 = em.find( ComponentTestEntity.class, cte3.getId() ); + cte4 = em.find( ComponentTestEntity.class, cte4.getId() ); - cte1.setComp2(new Component2("x'", "y'")); - cte3.getComp1().setStr2("b3'"); - cte4.setComp1(null); - cte4.setComp2(null); + cte1.setComp2( new Component2( "x'", "y'" ) ); + cte3.getComp1().setStr2( "b3'" ); + cte4.setComp1( null ); + cte4.setComp2( null ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 4 - em = getEntityManager(); - em.getTransaction().begin(); + // Revision 4 + em = getEntityManager(); + em.getTransaction().begin(); - cte2 = em.find(ComponentTestEntity.class, cte2.getId()); + cte2 = em.find( ComponentTestEntity.class, cte2.getId() ); - em.remove(cte2); + em.remove( cte2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - id1 = cte1.getId(); - id2 = cte2.getId(); - id3 = cte3.getId(); - id4 = cte4.getId(); - } + id1 = cte1.getId(); + id2 = cte2.getId(); + id3 = cte3.getId(); + id4 = cte4.getId(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(ComponentTestEntity.class, id1)); + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( ComponentTestEntity.class, id1 ) ); - assert Arrays.asList(1, 2, 4).equals(getAuditReader().getRevisions(ComponentTestEntity.class, id2)); + assert Arrays.asList( 1, 2, 4 ).equals( getAuditReader().getRevisions( ComponentTestEntity.class, id2 ) ); - assert Arrays.asList(1, 3).equals(getAuditReader().getRevisions(ComponentTestEntity.class, id3)); + assert Arrays.asList( 1, 3 ).equals( getAuditReader().getRevisions( ComponentTestEntity.class, id3 ) ); - assert Arrays.asList(1, 2, 3).equals(getAuditReader().getRevisions(ComponentTestEntity.class, id4)); - } + assert Arrays.asList( 1, 2, 3 ).equals( getAuditReader().getRevisions( ComponentTestEntity.class, id4 ) ); + } - @Test - public void testHistoryOfId1() { - ComponentTestEntity ver1 = new ComponentTestEntity(id1, new Component1("a", "b"), null); - ComponentTestEntity ver2 = new ComponentTestEntity(id1, new Component1("a'", "b'"), null); + @Test + public void testHistoryOfId1() { + ComponentTestEntity ver1 = new ComponentTestEntity( id1, new Component1( "a", "b" ), null ); + ComponentTestEntity ver2 = new ComponentTestEntity( id1, new Component1( "a'", "b'" ), null ); - assert getAuditReader().find(ComponentTestEntity.class, id1, 1).equals(ver1); - assert getAuditReader().find(ComponentTestEntity.class, id1, 2).equals(ver2); - assert getAuditReader().find(ComponentTestEntity.class, id1, 3).equals(ver2); - assert getAuditReader().find(ComponentTestEntity.class, id1, 4).equals(ver2); - } + assert getAuditReader().find( ComponentTestEntity.class, id1, 1 ).equals( ver1 ); + assert getAuditReader().find( ComponentTestEntity.class, id1, 2 ).equals( ver2 ); + assert getAuditReader().find( ComponentTestEntity.class, id1, 3 ).equals( ver2 ); + assert getAuditReader().find( ComponentTestEntity.class, id1, 4 ).equals( ver2 ); + } - @Test - public void testHistoryOfId2() { - ComponentTestEntity ver1 = new ComponentTestEntity(id2, new Component1("a2", "b2"), null); - ComponentTestEntity ver2 = new ComponentTestEntity(id2, new Component1("a2'", "b2"), null); + @Test + public void testHistoryOfId2() { + ComponentTestEntity ver1 = new ComponentTestEntity( id2, new Component1( "a2", "b2" ), null ); + ComponentTestEntity ver2 = new ComponentTestEntity( id2, new Component1( "a2'", "b2" ), null ); - assert getAuditReader().find(ComponentTestEntity.class, id2, 1).equals(ver1); - assert getAuditReader().find(ComponentTestEntity.class, id2, 2).equals(ver2); - assert getAuditReader().find(ComponentTestEntity.class, id2, 3).equals(ver2); - assert getAuditReader().find(ComponentTestEntity.class, id2, 4) == null; - } + assert getAuditReader().find( ComponentTestEntity.class, id2, 1 ).equals( ver1 ); + assert getAuditReader().find( ComponentTestEntity.class, id2, 2 ).equals( ver2 ); + assert getAuditReader().find( ComponentTestEntity.class, id2, 3 ).equals( ver2 ); + assert getAuditReader().find( ComponentTestEntity.class, id2, 4 ) == null; + } - @Test - public void testHistoryOfId3() { - ComponentTestEntity ver1 = new ComponentTestEntity(id3, new Component1("a3", "b3"), null); - ComponentTestEntity ver2 = new ComponentTestEntity(id3, new Component1("a3", "b3'"), null); + @Test + public void testHistoryOfId3() { + ComponentTestEntity ver1 = new ComponentTestEntity( id3, new Component1( "a3", "b3" ), null ); + ComponentTestEntity ver2 = new ComponentTestEntity( id3, new Component1( "a3", "b3'" ), null ); - assert getAuditReader().find(ComponentTestEntity.class, id3, 1).equals(ver1); - assert getAuditReader().find(ComponentTestEntity.class, id3, 2).equals(ver1); - assert getAuditReader().find(ComponentTestEntity.class, id3, 3).equals(ver2); - assert getAuditReader().find(ComponentTestEntity.class, id3, 4).equals(ver2); - } + assert getAuditReader().find( ComponentTestEntity.class, id3, 1 ).equals( ver1 ); + assert getAuditReader().find( ComponentTestEntity.class, id3, 2 ).equals( ver1 ); + assert getAuditReader().find( ComponentTestEntity.class, id3, 3 ).equals( ver2 ); + assert getAuditReader().find( ComponentTestEntity.class, id3, 4 ).equals( ver2 ); + } - @Test - public void testHistoryOfId4() { - ComponentTestEntity ver1 = new ComponentTestEntity(id4, null, null); - ComponentTestEntity ver2 = new ComponentTestEntity(id4, new Component1("n", null), null); - ComponentTestEntity ver3 = new ComponentTestEntity(id4, null, null); + @Test + public void testHistoryOfId4() { + ComponentTestEntity ver1 = new ComponentTestEntity( id4, null, null ); + ComponentTestEntity ver2 = new ComponentTestEntity( id4, new Component1( "n", null ), null ); + ComponentTestEntity ver3 = new ComponentTestEntity( id4, null, null ); - assert getAuditReader().find(ComponentTestEntity.class, id4, 1).equals(ver1); - assert getAuditReader().find(ComponentTestEntity.class, id4, 2).equals(ver2); - assert getAuditReader().find(ComponentTestEntity.class, id4, 3).equals(ver3); - assert getAuditReader().find(ComponentTestEntity.class, id4, 4).equals(ver3); - } + assert getAuditReader().find( ComponentTestEntity.class, id4, 1 ).equals( ver1 ); + assert getAuditReader().find( ComponentTestEntity.class, id4, 2 ).equals( ver2 ); + assert getAuditReader().find( ComponentTestEntity.class, id4, 3 ).equals( ver3 ); + assert getAuditReader().find( ComponentTestEntity.class, id4, 4 ).equals( ver3 ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/DefaultValueComponents.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/DefaultValueComponents.java index ab284bfe1f..b35529ce71 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/DefaultValueComponents.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/DefaultValueComponents.java @@ -23,11 +23,10 @@ */ package org.hibernate.envers.test.integration.components; -import java.util.Arrays; import javax.persistence.EntityManager; +import java.util.Arrays; import org.jboss.logging.Logger; -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; @@ -35,14 +34,15 @@ import org.hibernate.envers.test.entities.components.DefaultValueComponent1; import org.hibernate.envers.test.entities.components.DefaultValueComponent2; import org.hibernate.envers.test.entities.components.DefaultValueComponentTestEntity; +import org.junit.Test; + /** * Test class for components with default values. * + * @author Erik-Berndt Scheper * @see * Hibernate JIRA - * - * @author Erik-Berndt Scheper */ public class DefaultValueComponents extends BaseEnversJPAFunctionalTestCase { private static final Logger log = Logger.getLogger( DefaultValueComponents.class ); @@ -57,49 +57,73 @@ public class DefaultValueComponents extends BaseEnversJPAFunctionalTestCase { @Override protected Class[] getAnnotatedClasses() { - return new Class[] { DefaultValueComponentTestEntity.class }; + return new Class[] {DefaultValueComponentTestEntity.class}; } @Test - @Priority(10) + @Priority(10) public void initData() { // Revision 1 EntityManager em = getEntityManager(); em.getTransaction().begin(); DefaultValueComponentTestEntity cte0 = DefaultValueComponentTestEntity - .of(null); + .of( null ); DefaultValueComponentTestEntity cte1 = DefaultValueComponentTestEntity - .of(DefaultValueComponent1.of("c1-str1", null)); + .of( DefaultValueComponent1.of( "c1-str1", null ) ); DefaultValueComponentTestEntity cte2 = DefaultValueComponentTestEntity - .of(DefaultValueComponent1.of("c1-str1", DefaultValueComponent2 - .of("c2-str1", "c2-str2"))); + .of( + DefaultValueComponent1.of( + "c1-str1", DefaultValueComponent2 + .of( "c2-str1", "c2-str2" ) + ) + ); DefaultValueComponentTestEntity cte3 = DefaultValueComponentTestEntity - .of(DefaultValueComponent1.of(null, DefaultValueComponent2.of( - "c2-str1", "c2-str2"))); + .of( + DefaultValueComponent1.of( + null, DefaultValueComponent2.of( + "c2-str1", "c2-str2" + ) + ) + ); DefaultValueComponentTestEntity cte4 = DefaultValueComponentTestEntity - .of(DefaultValueComponent1.of(null, DefaultValueComponent2.of( - null, "c2-str2"))); + .of( + DefaultValueComponent1.of( + null, DefaultValueComponent2.of( + null, "c2-str2" + ) + ) + ); DefaultValueComponentTestEntity cte5 = DefaultValueComponentTestEntity - .of(DefaultValueComponent1.of(null, DefaultValueComponent2.of( - "c2-str1", null))); + .of( + DefaultValueComponent1.of( + null, DefaultValueComponent2.of( + "c2-str1", null + ) + ) + ); DefaultValueComponentTestEntity cte6 = DefaultValueComponentTestEntity - .of(DefaultValueComponent1.of(null, DefaultValueComponent2.of( - null, null))); + .of( + DefaultValueComponent1.of( + null, DefaultValueComponent2.of( + null, null + ) + ) + ); - em.persist(cte0); - em.persist(cte1); - em.persist(cte2); - em.persist(cte3); - em.persist(cte4); - em.persist(cte5); - em.persist(cte6); + em.persist( cte0 ); + em.persist( cte1 ); + em.persist( cte2 ); + em.persist( cte3 ); + em.persist( cte4 ); + em.persist( cte5 ); + em.persist( cte6 ); em.getTransaction().commit(); @@ -107,22 +131,26 @@ public class DefaultValueComponents extends BaseEnversJPAFunctionalTestCase { em = getEntityManager(); em.getTransaction().begin(); - cte0 = em.find(DefaultValueComponentTestEntity.class, cte0.getId()); - cte1 = em.find(DefaultValueComponentTestEntity.class, cte1.getId()); - cte2 = em.find(DefaultValueComponentTestEntity.class, cte2.getId()); - cte3 = em.find(DefaultValueComponentTestEntity.class, cte3.getId()); - cte4 = em.find(DefaultValueComponentTestEntity.class, cte4.getId()); - cte5 = em.find(DefaultValueComponentTestEntity.class, cte5.getId()); - cte6 = em.find(DefaultValueComponentTestEntity.class, cte6.getId()); + cte0 = em.find( DefaultValueComponentTestEntity.class, cte0.getId() ); + cte1 = em.find( DefaultValueComponentTestEntity.class, cte1.getId() ); + cte2 = em.find( DefaultValueComponentTestEntity.class, cte2.getId() ); + cte3 = em.find( DefaultValueComponentTestEntity.class, cte3.getId() ); + cte4 = em.find( DefaultValueComponentTestEntity.class, cte4.getId() ); + cte5 = em.find( DefaultValueComponentTestEntity.class, cte5.getId() ); + cte6 = em.find( DefaultValueComponentTestEntity.class, cte6.getId() ); - cte0.setComp1(DefaultValueComponent1.of("upd-c1-str1", null)); - cte1.setComp1(DefaultValueComponent1.of(null, DefaultValueComponent2 - .of("upd-c2-str1", "upd-c2-str2"))); - cte2.getComp1().getComp2().setStr1("upd-c2-str1"); - cte3.getComp1().getComp2().setStr1("upd-c2-str1"); - cte4.getComp1().getComp2().setStr1("upd-c2-str1"); - cte5.getComp1().getComp2().setStr1("upd-c2-str1"); - cte6.getComp1().getComp2().setStr1("upd-c2-str1"); + cte0.setComp1( DefaultValueComponent1.of( "upd-c1-str1", null ) ); + cte1.setComp1( + DefaultValueComponent1.of( + null, DefaultValueComponent2 + .of( "upd-c2-str1", "upd-c2-str2" ) + ) + ); + cte2.getComp1().getComp2().setStr1( "upd-c2-str1" ); + cte3.getComp1().getComp2().setStr1( "upd-c2-str1" ); + cte4.getComp1().getComp2().setStr1( "upd-c2-str1" ); + cte5.getComp1().getComp2().setStr1( "upd-c2-str1" ); + cte6.getComp1().getComp2().setStr1( "upd-c2-str1" ); em.getTransaction().commit(); @@ -138,243 +166,339 @@ public class DefaultValueComponents extends BaseEnversJPAFunctionalTestCase { @Test public void testRevisionsCounts() { - log.error(getAuditReader().getRevisions( - DefaultValueComponentTestEntity.class, id0).toString()); - log.error(getAuditReader().getRevisions( - DefaultValueComponentTestEntity.class, id1).toString()); - log.error(getAuditReader().getRevisions( - DefaultValueComponentTestEntity.class, id2).toString()); - log.error(getAuditReader().getRevisions( - DefaultValueComponentTestEntity.class, id3).toString()); - log.error(getAuditReader().getRevisions( - DefaultValueComponentTestEntity.class, id4).toString()); - log.error(getAuditReader().getRevisions( - DefaultValueComponentTestEntity.class, id5).toString()); - log.error(getAuditReader().getRevisions( - DefaultValueComponentTestEntity.class, id6).toString()); - - assert Arrays.asList(1, 2).equals( + log.error( getAuditReader().getRevisions( - DefaultValueComponentTestEntity.class, id0)); - - assert Arrays.asList(1, 2).equals( + DefaultValueComponentTestEntity.class, id0 + ).toString() + ); + log.error( getAuditReader().getRevisions( - DefaultValueComponentTestEntity.class, id1)); - - assert Arrays.asList(1, 2).equals( + DefaultValueComponentTestEntity.class, id1 + ).toString() + ); + log.error( getAuditReader().getRevisions( - DefaultValueComponentTestEntity.class, id2)); - - assert Arrays.asList(1, 2).equals( + DefaultValueComponentTestEntity.class, id2 + ).toString() + ); + log.error( getAuditReader().getRevisions( - DefaultValueComponentTestEntity.class, id3)); - - assert Arrays.asList(1, 2).equals( + DefaultValueComponentTestEntity.class, id3 + ).toString() + ); + log.error( getAuditReader().getRevisions( - DefaultValueComponentTestEntity.class, id4)); - - assert Arrays.asList(1, 2).equals( + DefaultValueComponentTestEntity.class, id4 + ).toString() + ); + log.error( getAuditReader().getRevisions( - DefaultValueComponentTestEntity.class, id5)); - - assert Arrays.asList(1, 2).equals( + DefaultValueComponentTestEntity.class, id5 + ).toString() + ); + log.error( getAuditReader().getRevisions( - DefaultValueComponentTestEntity.class, id6)); + DefaultValueComponentTestEntity.class, id6 + ).toString() + ); + + assert Arrays.asList( 1, 2 ).equals( + getAuditReader().getRevisions( + DefaultValueComponentTestEntity.class, id0 + ) + ); + + assert Arrays.asList( 1, 2 ).equals( + getAuditReader().getRevisions( + DefaultValueComponentTestEntity.class, id1 + ) + ); + + assert Arrays.asList( 1, 2 ).equals( + getAuditReader().getRevisions( + DefaultValueComponentTestEntity.class, id2 + ) + ); + + assert Arrays.asList( 1, 2 ).equals( + getAuditReader().getRevisions( + DefaultValueComponentTestEntity.class, id3 + ) + ); + + assert Arrays.asList( 1, 2 ).equals( + getAuditReader().getRevisions( + DefaultValueComponentTestEntity.class, id4 + ) + ); + + assert Arrays.asList( 1, 2 ).equals( + getAuditReader().getRevisions( + DefaultValueComponentTestEntity.class, id5 + ) + ); + + assert Arrays.asList( 1, 2 ).equals( + getAuditReader().getRevisions( + DefaultValueComponentTestEntity.class, id6 + ) + ); } @Test public void testHistoryOfId0() { DefaultValueComponentTestEntity ent1 = getAuditReader().find( - DefaultValueComponentTestEntity.class, id0, 1); + DefaultValueComponentTestEntity.class, id0, 1 + ); DefaultValueComponentTestEntity ent2 = getAuditReader().find( - DefaultValueComponentTestEntity.class, id0, 2); + DefaultValueComponentTestEntity.class, id0, 2 + ); - log.error("------------ id0 -------------"); - log.error(ent1.toString()); - log.error(ent2.toString()); + log.error( "------------ id0 -------------" ); + log.error( ent1.toString() ); + log.error( ent2.toString() ); - checkCorrectlyPersisted(id0, null, null); + checkCorrectlyPersisted( id0, null, null ); DefaultValueComponentTestEntity expectedVer1 = DefaultValueComponentTestEntity - .of(id0, DefaultValueComponent1.of(null, null)); + .of( id0, DefaultValueComponent1.of( null, null ) ); DefaultValueComponentTestEntity expectedVer2 = DefaultValueComponentTestEntity - .of(id0, DefaultValueComponent1.of("upd-c1-str1", null)); + .of( id0, DefaultValueComponent1.of( "upd-c1-str1", null ) ); - assert ent1.equals(expectedVer1); - assert ent2.equals(expectedVer2); + assert ent1.equals( expectedVer1 ); + assert ent2.equals( expectedVer2 ); } @Test public void testHistoryOfId1() { DefaultValueComponentTestEntity ent1 = getAuditReader().find( - DefaultValueComponentTestEntity.class, id1, 1); + DefaultValueComponentTestEntity.class, id1, 1 + ); DefaultValueComponentTestEntity ent2 = getAuditReader().find( - DefaultValueComponentTestEntity.class, id1, 2); + DefaultValueComponentTestEntity.class, id1, 2 + ); - log.error("------------ id1 -------------"); - log.error(ent1.toString()); - log.error(ent2.toString()); + log.error( "------------ id1 -------------" ); + log.error( ent1.toString() ); + log.error( ent2.toString() ); - checkCorrectlyPersisted(id1, null, "upd-c2-str1"); + checkCorrectlyPersisted( id1, null, "upd-c2-str1" ); DefaultValueComponentTestEntity expectedVer1 = DefaultValueComponentTestEntity - .of(id1, DefaultValueComponent1.of("c1-str1", null)); + .of( id1, DefaultValueComponent1.of( "c1-str1", null ) ); DefaultValueComponentTestEntity expectedVer2 = DefaultValueComponentTestEntity - .of(id1, DefaultValueComponent1.of(null, DefaultValueComponent2 - .of("upd-c2-str1", "upd-c2-str2"))); + .of( + id1, DefaultValueComponent1.of( + null, DefaultValueComponent2 + .of( "upd-c2-str1", "upd-c2-str2" ) + ) + ); - assert ent2.equals(expectedVer2); - assert ent1.equals(expectedVer1); + assert ent2.equals( expectedVer2 ); + assert ent1.equals( expectedVer1 ); } @Test public void testHistoryOfId2() { DefaultValueComponentTestEntity ent1 = getAuditReader().find( - DefaultValueComponentTestEntity.class, id2, 1); + DefaultValueComponentTestEntity.class, id2, 1 + ); DefaultValueComponentTestEntity ent2 = getAuditReader().find( - DefaultValueComponentTestEntity.class, id2, 2); + DefaultValueComponentTestEntity.class, id2, 2 + ); - log.error("------------ id2 -------------"); - log.error(ent1.toString()); - log.error(ent2.toString()); + log.error( "------------ id2 -------------" ); + log.error( ent1.toString() ); + log.error( ent2.toString() ); DefaultValueComponentTestEntity expectedVer1 = DefaultValueComponentTestEntity - .of(id2, DefaultValueComponent1.of("c1-str1", - DefaultValueComponent2.of("c2-str1", "c2-str2"))); + .of( + id2, DefaultValueComponent1.of( + "c1-str1", + DefaultValueComponent2.of( "c2-str1", "c2-str2" ) + ) + ); DefaultValueComponentTestEntity expectedVer2 = DefaultValueComponentTestEntity - .of(id2, DefaultValueComponent1.of("c1-str1", - DefaultValueComponent2.of("upd-c2-str1", "c2-str2"))); + .of( + id2, DefaultValueComponent1.of( + "c1-str1", + DefaultValueComponent2.of( "upd-c2-str1", "c2-str2" ) + ) + ); - assert ent1.equals(expectedVer1); - assert ent2.equals(expectedVer2); + assert ent1.equals( expectedVer1 ); + assert ent2.equals( expectedVer2 ); } @Test public void testHistoryOfId3() { DefaultValueComponentTestEntity ent1 = getAuditReader().find( - DefaultValueComponentTestEntity.class, id3, 1); + DefaultValueComponentTestEntity.class, id3, 1 + ); DefaultValueComponentTestEntity ent2 = getAuditReader().find( - DefaultValueComponentTestEntity.class, id3, 2); + DefaultValueComponentTestEntity.class, id3, 2 + ); - log.error("------------ id3 -------------"); - log.error(ent1.toString()); - log.error(ent2.toString()); + log.error( "------------ id3 -------------" ); + log.error( ent1.toString() ); + log.error( ent2.toString() ); DefaultValueComponentTestEntity expectedVer1 = DefaultValueComponentTestEntity - .of(id3, DefaultValueComponent1.of(null, DefaultValueComponent2 - .of("c2-str1", "c2-str2"))); + .of( + id3, DefaultValueComponent1.of( + null, DefaultValueComponent2 + .of( "c2-str1", "c2-str2" ) + ) + ); DefaultValueComponentTestEntity expectedVer2 = DefaultValueComponentTestEntity - .of(id3, DefaultValueComponent1.of(null, DefaultValueComponent2 - .of("upd-c2-str1", "c2-str2"))); + .of( + id3, DefaultValueComponent1.of( + null, DefaultValueComponent2 + .of( "upd-c2-str1", "c2-str2" ) + ) + ); - assert ent1.equals(expectedVer1); - assert ent2.equals(expectedVer2); + assert ent1.equals( expectedVer1 ); + assert ent2.equals( expectedVer2 ); } @Test public void testHistoryOfId4() { DefaultValueComponentTestEntity ent1 = getAuditReader().find( - DefaultValueComponentTestEntity.class, id4, 1); + DefaultValueComponentTestEntity.class, id4, 1 + ); DefaultValueComponentTestEntity ent2 = getAuditReader().find( - DefaultValueComponentTestEntity.class, id4, 2); + DefaultValueComponentTestEntity.class, id4, 2 + ); - log.error("------------ id4 -------------"); - log.error(ent1.toString()); - log.error(ent2.toString()); + log.error( "------------ id4 -------------" ); + log.error( ent1.toString() ); + log.error( ent2.toString() ); DefaultValueComponentTestEntity expectedVer1 = DefaultValueComponentTestEntity - .of(id4, DefaultValueComponent1.of(null, DefaultValueComponent2 - .of(null, "c2-str2"))); + .of( + id4, DefaultValueComponent1.of( + null, DefaultValueComponent2 + .of( null, "c2-str2" ) + ) + ); DefaultValueComponentTestEntity expectedVer2 = DefaultValueComponentTestEntity - .of(id4, DefaultValueComponent1.of(null, DefaultValueComponent2 - .of("upd-c2-str1", "c2-str2"))); + .of( + id4, DefaultValueComponent1.of( + null, DefaultValueComponent2 + .of( "upd-c2-str1", "c2-str2" ) + ) + ); - assert ent1.equals(expectedVer1); - assert ent2.equals(expectedVer2); + assert ent1.equals( expectedVer1 ); + assert ent2.equals( expectedVer2 ); } @Test public void testHistoryOfId5() { DefaultValueComponentTestEntity ent1 = getAuditReader().find( - DefaultValueComponentTestEntity.class, id5, 1); + DefaultValueComponentTestEntity.class, id5, 1 + ); DefaultValueComponentTestEntity ent2 = getAuditReader().find( - DefaultValueComponentTestEntity.class, id5, 2); + DefaultValueComponentTestEntity.class, id5, 2 + ); - log.error("------------ id5 -------------"); - log.error(ent1.toString()); - log.error(ent2.toString()); + log.error( "------------ id5 -------------" ); + log.error( ent1.toString() ); + log.error( ent2.toString() ); DefaultValueComponentTestEntity expectedVer1 = DefaultValueComponentTestEntity - .of(id5, DefaultValueComponent1.of(null, DefaultValueComponent2 - .of("c2-str1", null))); + .of( + id5, DefaultValueComponent1.of( + null, DefaultValueComponent2 + .of( "c2-str1", null ) + ) + ); DefaultValueComponentTestEntity expectedVer2 = DefaultValueComponentTestEntity - .of(id5, DefaultValueComponent1.of(null, DefaultValueComponent2 - .of("upd-c2-str1", null))); + .of( + id5, DefaultValueComponent1.of( + null, DefaultValueComponent2 + .of( "upd-c2-str1", null ) + ) + ); - assert ent1.equals(expectedVer1); - assert ent2.equals(expectedVer2); + assert ent1.equals( expectedVer1 ); + assert ent2.equals( expectedVer2 ); } @Test public void testHistoryOfId6() { DefaultValueComponentTestEntity ent1 = getAuditReader().find( - DefaultValueComponentTestEntity.class, id6, 1); + DefaultValueComponentTestEntity.class, id6, 1 + ); DefaultValueComponentTestEntity ent2 = getAuditReader().find( - DefaultValueComponentTestEntity.class, id6, 2); + DefaultValueComponentTestEntity.class, id6, 2 + ); - log.error("------------ id6 -------------"); - log.error(ent1.toString()); - log.error(ent2.toString()); + log.error( "------------ id6 -------------" ); + log.error( ent1.toString() ); + log.error( ent2.toString() ); DefaultValueComponentTestEntity expectedVer1 = DefaultValueComponentTestEntity - .of(id6, DefaultValueComponent1.of(null, null)); + .of( id6, DefaultValueComponent1.of( null, null ) ); DefaultValueComponentTestEntity expectedVer2 = DefaultValueComponentTestEntity - .of(id6, DefaultValueComponent1.of(null, DefaultValueComponent2 - .of("upd-c2-str1", null))); + .of( + id6, DefaultValueComponent1.of( + null, DefaultValueComponent2 + .of( "upd-c2-str1", null ) + ) + ); - assert ent2.equals(expectedVer2); - assert ent1.equals(expectedVer1); + assert ent2.equals( expectedVer2 ); + assert ent1.equals( expectedVer1 ); } - private void checkCorrectlyPersisted(Integer expectedId, + private void checkCorrectlyPersisted( + Integer expectedId, String expectedComp2Str1Rev1, String expectedComp2Str1Rev2) { // Verify that the entity was correctly persisted EntityManager em = getEntityManager(); em.getTransaction().begin(); Long entCount = (Long) em.createQuery( "select count(s) from DefaultValueComponentTestEntity s where s.id = " - + expectedId.toString()).getSingleResult(); + + expectedId.toString() + ).getSingleResult(); Number auditCount = (Number) em.createNativeQuery( "select count(ID) from DefaultValueComponent_AUD s where s.id = " - + expectedId.toString()).getSingleResult(); + + expectedId.toString() + ).getSingleResult(); String comp2Str1Rev1 = (String) em .createNativeQuery( "select COMP2_STR1 from DefaultValueComponent_AUD s where rev=1 and s.id = " - + expectedId.toString()).getSingleResult(); + + expectedId.toString() + ).getSingleResult(); String comp2Str1Rev2 = (String) em .createNativeQuery( "select COMP2_STR1 from DefaultValueComponent_AUD s where rev=2 and s.id = " - + expectedId.toString()).getSingleResult(); - assert Long.valueOf(1L).equals(entCount); - assert Integer.valueOf(2).equals(auditCount.intValue()); + + expectedId.toString() + ).getSingleResult(); + assert Long.valueOf( 1L ).equals( entCount ); + assert Integer.valueOf( 2 ).equals( auditCount.intValue() ); - if (expectedComp2Str1Rev1 == null) { + if ( expectedComp2Str1Rev1 == null ) { assert comp2Str1Rev1 == null; - } else { - assert expectedComp2Str1Rev1.equals(comp2Str1Rev1); + } + else { + assert expectedComp2Str1Rev1.equals( comp2Str1Rev1 ); } - if (expectedComp2Str1Rev2 == null) { + if ( expectedComp2Str1Rev2 == null ) { assert comp2Str1Rev2 == null; - } else { - assert expectedComp2Str1Rev2.equals(comp2Str1Rev2); + } + else { + assert expectedComp2Str1Rev2.equals( comp2Str1Rev2 ); } em.getTransaction().commit(); } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/PropertiesGroupTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/PropertiesGroupTest.java index 34c6b0e4a6..db70b09c9c 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/PropertiesGroupTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/PropertiesGroupTest.java @@ -1,8 +1,5 @@ package org.hibernate.envers.test.integration.components; -import org.junit.Assert; -import org.junit.Test; - import org.hibernate.Session; import org.hibernate.envers.test.BaseEnversFunctionalTestCase; import org.hibernate.envers.test.Priority; @@ -10,6 +7,10 @@ import org.hibernate.envers.test.entities.components.UniquePropsEntity; import org.hibernate.envers.test.entities.components.UniquePropsNotAuditedEntity; import org.hibernate.mapping.Column; import org.hibernate.mapping.PersistentClass; + +import org.junit.Assert; +import org.junit.Test; + import org.hibernate.testing.TestForIssue; /** @@ -17,63 +18,73 @@ import org.hibernate.testing.TestForIssue; */ @TestForIssue(jiraKey = "HHH-6636") public class PropertiesGroupTest extends BaseEnversFunctionalTestCase { - private PersistentClass uniquePropsAudit = null; - private PersistentClass uniquePropsNotAuditedAudit = null; - private UniquePropsEntity entityRev1 = null; - private UniquePropsNotAuditedEntity entityNotAuditedRev2 = null; + private PersistentClass uniquePropsAudit = null; + private PersistentClass uniquePropsNotAuditedAudit = null; + private UniquePropsEntity entityRev1 = null; + private UniquePropsNotAuditedEntity entityNotAuditedRev2 = null; - @Override - protected String[] getMappings() { - return new String[] { - "mappings/components/UniquePropsEntity.hbm.xml", - "mappings/components/UniquePropsNotAuditedEntity.hbm.xml" - }; - } + @Override + protected String[] getMappings() { + return new String[] { + "mappings/components/UniquePropsEntity.hbm.xml", + "mappings/components/UniquePropsNotAuditedEntity.hbm.xml" + }; + } - @Test - @Priority(10) - public void initData() { - uniquePropsAudit = configuration().getClassMapping("org.hibernate.envers.test.entities.components.UniquePropsEntity_AUD"); - uniquePropsNotAuditedAudit = configuration().getClassMapping("org.hibernate.envers.test.entities.components.UniquePropsNotAuditedEntity_AUD"); + @Test + @Priority(10) + public void initData() { + uniquePropsAudit = configuration().getClassMapping( + "org.hibernate.envers.test.entities.components.UniquePropsEntity_AUD" + ); + uniquePropsNotAuditedAudit = configuration().getClassMapping( + "org.hibernate.envers.test.entities.components.UniquePropsNotAuditedEntity_AUD" + ); - // Revision 1 - Session session = openSession(); - session.getTransaction().begin(); - UniquePropsEntity ent = new UniquePropsEntity(); - ent.setData1("data1"); - ent.setData2("data2"); - session.persist(ent); - session.getTransaction().commit(); + // Revision 1 + Session session = openSession(); + session.getTransaction().begin(); + UniquePropsEntity ent = new UniquePropsEntity(); + ent.setData1( "data1" ); + ent.setData2( "data2" ); + session.persist( ent ); + session.getTransaction().commit(); - entityRev1 = new UniquePropsEntity(ent.getId(), ent.getData1(), ent.getData2()); + entityRev1 = new UniquePropsEntity( ent.getId(), ent.getData1(), ent.getData2() ); - // Revision 2 - session.getTransaction().begin(); - UniquePropsNotAuditedEntity entNotAud = new UniquePropsNotAuditedEntity(); - entNotAud.setData1("data3"); - entNotAud.setData2("data4"); - session.persist(entNotAud); - session.getTransaction().commit(); + // Revision 2 + session.getTransaction().begin(); + UniquePropsNotAuditedEntity entNotAud = new UniquePropsNotAuditedEntity(); + entNotAud.setData1( "data3" ); + entNotAud.setData2( "data4" ); + session.persist( entNotAud ); + session.getTransaction().commit(); - entityNotAuditedRev2 = new UniquePropsNotAuditedEntity(entNotAud.getId(), entNotAud.getData1(), null); - } + entityNotAuditedRev2 = new UniquePropsNotAuditedEntity( entNotAud.getId(), entNotAud.getData1(), null ); + } - @Test - public void testAuditTableColumns() { - Assert.assertNotNull(uniquePropsAudit.getTable().getColumn(new Column("DATA1"))); - Assert.assertNotNull(uniquePropsAudit.getTable().getColumn(new Column("DATA2"))); + @Test + public void testAuditTableColumns() { + Assert.assertNotNull( uniquePropsAudit.getTable().getColumn( new Column( "DATA1" ) ) ); + Assert.assertNotNull( uniquePropsAudit.getTable().getColumn( new Column( "DATA2" ) ) ); - Assert.assertNotNull(uniquePropsNotAuditedAudit.getTable().getColumn(new Column("DATA1"))); - Assert.assertNull(uniquePropsNotAuditedAudit.getTable().getColumn(new Column("DATA2"))); - } + Assert.assertNotNull( uniquePropsNotAuditedAudit.getTable().getColumn( new Column( "DATA1" ) ) ); + Assert.assertNull( uniquePropsNotAuditedAudit.getTable().getColumn( new Column( "DATA2" ) ) ); + } - @Test - public void testHistoryOfUniquePropsEntity() { - Assert.assertEquals(entityRev1, getAuditReader().find(UniquePropsEntity.class, entityRev1.getId(), 1)); - } + @Test + public void testHistoryOfUniquePropsEntity() { + Assert.assertEquals( entityRev1, getAuditReader().find( UniquePropsEntity.class, entityRev1.getId(), 1 ) ); + } - @Test - public void testHistoryOfUniquePropsNotAuditedEntity() { - Assert.assertEquals(entityNotAuditedRev2, getAuditReader().find(UniquePropsNotAuditedEntity.class, entityNotAuditedRev2.getId(), 2)); - } + @Test + public void testHistoryOfUniquePropsNotAuditedEntity() { + Assert.assertEquals( + entityNotAuditedRev2, getAuditReader().find( + UniquePropsNotAuditedEntity.class, + entityNotAuditedRev2.getId(), + 2 + ) + ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/collections/CollectionOfComponents.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/collections/CollectionOfComponents.java index 52e52a6647..9f8317bb4d 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/collections/CollectionOfComponents.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/collections/CollectionOfComponents.java @@ -23,68 +23,69 @@ */ package org.hibernate.envers.test.integration.components.collections; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.Set; -import javax.persistence.EntityManager; - -import org.junit.Ignore; -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.components.Component1; import org.hibernate.envers.test.entities.components.ComponentSetTestEntity; +import org.junit.Ignore; +import org.junit.Test; + /** * TODO: enable and implement + * * @author Adam Warski (adam at warski dot org) */ @Ignore public class CollectionOfComponents extends BaseEnversJPAFunctionalTestCase { - private Integer id1; + private Integer id1; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { ComponentSetTestEntity.class }; - } + return new Class[] {ComponentSetTestEntity.class}; + } - @Test - @Priority(10) - public void initData() { - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); + @Test + @Priority(10) + public void initData() { + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); - ComponentSetTestEntity cte1 = new ComponentSetTestEntity(); + ComponentSetTestEntity cte1 = new ComponentSetTestEntity(); - em.persist(cte1); + em.persist( cte1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em = getEntityManager(); - em.getTransaction().begin(); + // Revision 2 + em = getEntityManager(); + em.getTransaction().begin(); - cte1 = em.find(ComponentSetTestEntity.class, cte1.getId()); + cte1 = em.find( ComponentSetTestEntity.class, cte1.getId() ); - cte1.getComps().add(new Component1("a", "b")); + cte1.getComps().add( new Component1( "a", "b" ) ); - em.getTransaction().commit(); + em.getTransaction().commit(); - id1 = cte1.getId(); - } + id1 = cte1.getId(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(ComponentSetTestEntity.class, id1)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( ComponentSetTestEntity.class, id1 ) ); + } - @Test - public void testHistoryOfId1() { - assert getAuditReader().find(ComponentSetTestEntity.class, id1, 1).getComps().size() == 0; - - Set comps1 = getAuditReader().find(ComponentSetTestEntity.class, id1, 2).getComps(); - assert comps1.size() == 1; - assert comps1.contains(new Component1("a", "b")); - } + @Test + public void testHistoryOfId1() { + assert getAuditReader().find( ComponentSetTestEntity.class, id1, 1 ).getComps().size() == 0; + + Set comps1 = getAuditReader().find( ComponentSetTestEntity.class, id1, 2 ).getComps(); + assert comps1.size() == 1; + assert comps1.contains( new Component1( "a", "b" ) ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/dynamic/AuditedDynamicComponentTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/dynamic/AuditedDynamicComponentTest.java index f0e44ccfc2..418be712ff 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/dynamic/AuditedDynamicComponentTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/dynamic/AuditedDynamicComponentTest.java @@ -7,9 +7,6 @@ import java.net.URL; import java.util.HashMap; import java.util.Map; -import junit.framework.Assert; -import org.junit.Test; - import org.hibernate.MappingException; import org.hibernate.cfg.Configuration; import org.hibernate.envers.Audited; @@ -17,18 +14,24 @@ import org.hibernate.envers.configuration.EnversSettings; import org.hibernate.envers.internal.tools.StringTools; import org.hibernate.envers.test.AbstractEnversTest; import org.hibernate.service.ServiceRegistry; + +import org.junit.Test; +import junit.framework.Assert; + import org.hibernate.testing.ServiceRegistryBuilder; import org.hibernate.testing.TestForIssue; /** * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ -@TestForIssue( jiraKey = "HHH-8049" ) +@TestForIssue(jiraKey = "HHH-8049") public class AuditedDynamicComponentTest extends AbstractEnversTest { @Test public void testAuditedDynamicComponentFailure() throws URISyntaxException { final Configuration config = new Configuration(); - final URL hbm = Thread.currentThread().getContextClassLoader().getResource( "mappings/dynamicComponents/mapAudited.hbm.xml" ); + final URL hbm = Thread.currentThread().getContextClassLoader().getResource( + "mappings/dynamicComponents/mapAudited.hbm.xml" + ); config.addFile( new File( hbm.toURI() ) ); final String auditStrategy = getAuditStrategy(); @@ -41,7 +44,7 @@ public class AuditedDynamicComponentTest extends AbstractEnversTest { config.buildSessionFactory( serviceRegistry ); Assert.fail( "MappingException expected" ); } - catch ( MappingException e ) { + catch (MappingException e) { Assert.assertEquals( "Audited dynamic-component properties are not supported. Consider applying @NotAudited annotation to " + AuditedDynamicMapComponent.class.getName() + "#customFields.", diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/dynamic/NotAuditedDynamicComponentTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/dynamic/NotAuditedDynamicComponentTest.java index f20026f6b4..7a0e3d5e71 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/dynamic/NotAuditedDynamicComponentTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/dynamic/NotAuditedDynamicComponentTest.java @@ -2,22 +2,23 @@ package org.hibernate.envers.test.integration.components.dynamic; import java.util.Arrays; -import junit.framework.Assert; -import org.junit.Test; - import org.hibernate.Session; import org.hibernate.envers.test.BaseEnversFunctionalTestCase; import org.hibernate.envers.test.Priority; + +import org.junit.Test; +import junit.framework.Assert; + import org.hibernate.testing.TestForIssue; /** * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ -@TestForIssue( jiraKey = "HHH-8049" ) +@TestForIssue(jiraKey = "HHH-8049") public class NotAuditedDynamicComponentTest extends BaseEnversFunctionalTestCase { @Override protected String[] getMappings() { - return new String[] { "mappings/dynamicComponents/mapNotAudited.hbm.xml" }; + return new String[] {"mappings/dynamicComponents/mapNotAudited.hbm.xml"}; } @Test @@ -58,21 +59,32 @@ public class NotAuditedDynamicComponentTest extends BaseEnversFunctionalTestCase @Test public void testRevisionsCounts() { - Assert.assertEquals( Arrays.asList( 1, 2, 3 ), getAuditReader().getRevisions( NotAuditedDynamicMapComponent.class, 1L ) ); + Assert.assertEquals( + Arrays.asList( 1, 2, 3 ), + getAuditReader().getRevisions( NotAuditedDynamicMapComponent.class, 1L ) + ); } @Test public void testHistoryOfId1() { // Revision 1 NotAuditedDynamicMapComponent entity = new NotAuditedDynamicMapComponent( 1L, "static field value" ); - NotAuditedDynamicMapComponent ver1 = getAuditReader().find( NotAuditedDynamicMapComponent.class, entity.getId(), 1 ); + NotAuditedDynamicMapComponent ver1 = getAuditReader().find( + NotAuditedDynamicMapComponent.class, + entity.getId(), + 1 + ); Assert.assertEquals( entity, ver1 ); // Assume empty NotAuditedDynamicMapComponent#customFields map, because dynamic-component is not audited. Assert.assertTrue( ver1.getCustomFields().isEmpty() ); // Revision 2 entity.setNote( "updated note" ); - NotAuditedDynamicMapComponent ver2 = getAuditReader().find( NotAuditedDynamicMapComponent.class, entity.getId(), 2 ); + NotAuditedDynamicMapComponent ver2 = getAuditReader().find( + NotAuditedDynamicMapComponent.class, + entity.getId(), + 2 + ); Assert.assertEquals( entity, ver2 ); // Assume empty NotAuditedDynamicMapComponent#customFields map, because dynamic-component is not audited. Assert.assertTrue( ver2.getCustomFields().isEmpty() ); diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/dynamic/NotAuditedDynamicMapComponent.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/dynamic/NotAuditedDynamicMapComponent.java index 28e4b2634b..df747c1d72 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/dynamic/NotAuditedDynamicMapComponent.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/dynamic/NotAuditedDynamicMapComponent.java @@ -26,23 +26,33 @@ public class NotAuditedDynamicMapComponent implements Serializable { @Override public boolean equals(Object o) { - if ( this == o ) return true; - if ( !( o instanceof NotAuditedDynamicMapComponent ) ) return false; + if ( this == o ) { + return true; + } + if ( !(o instanceof NotAuditedDynamicMapComponent) ) { + return false; + } NotAuditedDynamicMapComponent that = (NotAuditedDynamicMapComponent) o; - if ( id != that.id ) return false; - if ( customFields != null ? !customFields.equals( that.customFields ) : that.customFields != null ) return false; - if ( note != null ? !note.equals( that.note ) : that.note != null ) return false; + if ( id != that.id ) { + return false; + } + if ( customFields != null ? !customFields.equals( that.customFields ) : that.customFields != null ) { + return false; + } + if ( note != null ? !note.equals( that.note ) : that.note != null ) { + return false; + } return true; } @Override public int hashCode() { - int result = (int) ( id ^ ( id >>> 32 ) ); - result = 31 * result + ( note != null ? note.hashCode() : 0 ); - result = 31 * result + ( customFields != null ? customFields.hashCode() : 0 ); + int result = (int) (id ^ (id >>> 32)); + result = 31 * result + (note != null ? note.hashCode() : 0); + result = 31 * result + (customFields != null ? customFields.hashCode() : 0); return result; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/relations/ManyToOneInComponent.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/relations/ManyToOneInComponent.java index 4ef4e24211..fd7882acea 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/relations/ManyToOneInComponent.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/relations/ManyToOneInComponent.java @@ -23,10 +23,8 @@ */ package org.hibernate.envers.test.integration.components.relations; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; @@ -34,77 +32,99 @@ import org.hibernate.envers.test.entities.StrTestEntity; import org.hibernate.envers.test.entities.components.relations.ManyToOneComponent; import org.hibernate.envers.test.entities.components.relations.ManyToOneComponentTestEntity; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ -public class ManyToOneInComponent extends BaseEnversJPAFunctionalTestCase { - private Integer mtocte_id1; +public class ManyToOneInComponent extends BaseEnversJPAFunctionalTestCase { + private Integer mtocte_id1; private Integer ste_id1; private Integer ste_id2; - @Override - protected Class[] getAnnotatedClasses() { - return new Class[]{ManyToOneComponentTestEntity.class, StrTestEntity.class}; + @Override + protected Class[] getAnnotatedClasses() { + return new Class[] {ManyToOneComponentTestEntity.class, StrTestEntity.class}; - } + } - @Test - @Priority(10) - public void initData() { - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); + @Test + @Priority(10) + public void initData() { + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); StrTestEntity ste1 = new StrTestEntity(); - ste1.setStr("str1"); + ste1.setStr( "str1" ); StrTestEntity ste2 = new StrTestEntity(); - ste2.setStr("str2"); + ste2.setStr( "str2" ); - em.persist(ste1); - em.persist(ste2); + em.persist( ste1 ); + em.persist( ste2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em = getEntityManager(); - em.getTransaction().begin(); + // Revision 2 + em = getEntityManager(); + em.getTransaction().begin(); - ManyToOneComponentTestEntity mtocte1 = new ManyToOneComponentTestEntity(new ManyToOneComponent(ste1, "data1")); + ManyToOneComponentTestEntity mtocte1 = new ManyToOneComponentTestEntity( + new ManyToOneComponent( + ste1, + "data1" + ) + ); - em.persist(mtocte1); + em.persist( mtocte1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 - em = getEntityManager(); - em.getTransaction().begin(); + // Revision 3 + em = getEntityManager(); + em.getTransaction().begin(); - mtocte1 = em.find(ManyToOneComponentTestEntity.class, mtocte1.getId()); - mtocte1.getComp1().setEntity(ste2); + mtocte1 = em.find( ManyToOneComponentTestEntity.class, mtocte1.getId() ); + mtocte1.getComp1().setEntity( ste2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - mtocte_id1 = mtocte1.getId(); + mtocte_id1 = mtocte1.getId(); ste_id1 = ste1.getId(); ste_id2 = ste2.getId(); - } + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(2, 3).equals(getAuditReader().getRevisions(ManyToOneComponentTestEntity.class, mtocte_id1)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 2, 3 ).equals( + getAuditReader().getRevisions( + ManyToOneComponentTestEntity.class, + mtocte_id1 + ) + ); + } - @Test - public void testHistoryOfId1() { - StrTestEntity ste1 = getEntityManager().find(StrTestEntity.class, ste_id1); - StrTestEntity ste2 = getEntityManager().find(StrTestEntity.class, ste_id2); + @Test + public void testHistoryOfId1() { + StrTestEntity ste1 = getEntityManager().find( StrTestEntity.class, ste_id1 ); + StrTestEntity ste2 = getEntityManager().find( StrTestEntity.class, ste_id2 ); - ManyToOneComponentTestEntity ver2 = new ManyToOneComponentTestEntity(mtocte_id1, new ManyToOneComponent(ste1, "data1")); - ManyToOneComponentTestEntity ver3 = new ManyToOneComponentTestEntity(mtocte_id1, new ManyToOneComponent(ste2, "data1")); + ManyToOneComponentTestEntity ver2 = new ManyToOneComponentTestEntity( + mtocte_id1, new ManyToOneComponent( + ste1, + "data1" + ) + ); + ManyToOneComponentTestEntity ver3 = new ManyToOneComponentTestEntity( + mtocte_id1, new ManyToOneComponent( + ste2, + "data1" + ) + ); - assert getAuditReader().find(ManyToOneComponentTestEntity.class, mtocte_id1, 1) == null; - assert getAuditReader().find(ManyToOneComponentTestEntity.class, mtocte_id1, 2).equals(ver2); - assert getAuditReader().find(ManyToOneComponentTestEntity.class, mtocte_id1, 3).equals(ver3); - } + assert getAuditReader().find( ManyToOneComponentTestEntity.class, mtocte_id1, 1 ) == null; + assert getAuditReader().find( ManyToOneComponentTestEntity.class, mtocte_id1, 2 ).equals( ver2 ); + assert getAuditReader().find( ManyToOneComponentTestEntity.class, mtocte_id1, 3 ).equals( ver3 ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/relations/NotAuditedManyToOneInComponent.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/relations/NotAuditedManyToOneInComponent.java index 5492ca744b..114cdd9c51 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/relations/NotAuditedManyToOneInComponent.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/relations/NotAuditedManyToOneInComponent.java @@ -23,10 +23,8 @@ */ package org.hibernate.envers.test.integration.components.relations; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; @@ -34,80 +32,88 @@ import org.hibernate.envers.test.entities.UnversionedStrTestEntity; import org.hibernate.envers.test.entities.components.relations.NotAuditedManyToOneComponent; import org.hibernate.envers.test.entities.components.relations.NotAuditedManyToOneComponentTestEntity; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class NotAuditedManyToOneInComponent extends BaseEnversJPAFunctionalTestCase { - private Integer mtocte_id1; + private Integer mtocte_id1; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { NotAuditedManyToOneComponentTestEntity.class, UnversionedStrTestEntity.class }; - } + return new Class[] {NotAuditedManyToOneComponentTestEntity.class, UnversionedStrTestEntity.class}; + } - @Test - @Priority(10) - public void initData() { + @Test + @Priority(10) + public void initData() { // No revision - EntityManager em = getEntityManager(); - em.getTransaction().begin(); + EntityManager em = getEntityManager(); + em.getTransaction().begin(); UnversionedStrTestEntity ste1 = new UnversionedStrTestEntity(); - ste1.setStr("str1"); + ste1.setStr( "str1" ); UnversionedStrTestEntity ste2 = new UnversionedStrTestEntity(); - ste2.setStr("str2"); + ste2.setStr( "str2" ); - em.persist(ste1); - em.persist(ste2); + em.persist( ste1 ); + em.persist( ste2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 1 - em = getEntityManager(); - em.getTransaction().begin(); + // Revision 1 + em = getEntityManager(); + em.getTransaction().begin(); NotAuditedManyToOneComponentTestEntity mtocte1 = new NotAuditedManyToOneComponentTestEntity( - new NotAuditedManyToOneComponent(ste1, "data1")); + new NotAuditedManyToOneComponent( ste1, "data1" ) + ); - em.persist(mtocte1); + em.persist( mtocte1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // No revision - em = getEntityManager(); - em.getTransaction().begin(); + // No revision + em = getEntityManager(); + em.getTransaction().begin(); - mtocte1 = em.find(NotAuditedManyToOneComponentTestEntity.class, mtocte1.getId()); - mtocte1.getComp1().setEntity(ste2); + mtocte1 = em.find( NotAuditedManyToOneComponentTestEntity.class, mtocte1.getId() ); + mtocte1.getComp1().setEntity( ste2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em = getEntityManager(); - em.getTransaction().begin(); + // Revision 2 + em = getEntityManager(); + em.getTransaction().begin(); - mtocte1 = em.find(NotAuditedManyToOneComponentTestEntity.class, mtocte1.getId()); - mtocte1.getComp1().setData("data2"); + mtocte1 = em.find( NotAuditedManyToOneComponentTestEntity.class, mtocte1.getId() ); + mtocte1.getComp1().setData( "data2" ); - em.getTransaction().commit(); + em.getTransaction().commit(); - mtocte_id1 = mtocte1.getId(); - } + mtocte_id1 = mtocte1.getId(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(NotAuditedManyToOneComponentTestEntity.class, mtocte_id1)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ) + .equals( getAuditReader().getRevisions( NotAuditedManyToOneComponentTestEntity.class, mtocte_id1 ) ); + } - @Test - public void testHistoryOfId1() { - NotAuditedManyToOneComponentTestEntity ver1 = new NotAuditedManyToOneComponentTestEntity(mtocte_id1, - new NotAuditedManyToOneComponent(null, "data1")); - NotAuditedManyToOneComponentTestEntity ver2 = new NotAuditedManyToOneComponentTestEntity(mtocte_id1, - new NotAuditedManyToOneComponent(null, "data2")); + @Test + public void testHistoryOfId1() { + NotAuditedManyToOneComponentTestEntity ver1 = new NotAuditedManyToOneComponentTestEntity( + mtocte_id1, + new NotAuditedManyToOneComponent( null, "data1" ) + ); + NotAuditedManyToOneComponentTestEntity ver2 = new NotAuditedManyToOneComponentTestEntity( + mtocte_id1, + new NotAuditedManyToOneComponent( null, "data2" ) + ); - assert getAuditReader().find(NotAuditedManyToOneComponentTestEntity.class, mtocte_id1, 1).equals(ver1); - assert getAuditReader().find(NotAuditedManyToOneComponentTestEntity.class, mtocte_id1, 2).equals(ver2); - } + assert getAuditReader().find( NotAuditedManyToOneComponentTestEntity.class, mtocte_id1, 1 ).equals( ver1 ); + assert getAuditReader().find( NotAuditedManyToOneComponentTestEntity.class, mtocte_id1, 2 ).equals( ver2 ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/relations/OneToManyInComponent.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/relations/OneToManyInComponent.java index 480c1a277f..d2076681e6 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/relations/OneToManyInComponent.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/components/relations/OneToManyInComponent.java @@ -23,10 +23,8 @@ */ package org.hibernate.envers.test.integration.components.relations; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; @@ -34,80 +32,95 @@ import org.hibernate.envers.test.entities.StrTestEntity; import org.hibernate.envers.test.entities.components.relations.OneToManyComponent; import org.hibernate.envers.test.entities.components.relations.OneToManyComponentTestEntity; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ -public class OneToManyInComponent extends BaseEnversJPAFunctionalTestCase { - private Integer otmcte_id1; +public class OneToManyInComponent extends BaseEnversJPAFunctionalTestCase { + private Integer otmcte_id1; private Integer ste_id1; private Integer ste_id2; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { OneToManyComponentTestEntity.class, StrTestEntity.class }; - } + return new Class[] {OneToManyComponentTestEntity.class, StrTestEntity.class}; + } - @Test - @Priority(10) - public void initData() { - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); + @Test + @Priority(10) + public void initData() { + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); StrTestEntity ste1 = new StrTestEntity(); - ste1.setStr("str1"); + ste1.setStr( "str1" ); StrTestEntity ste2 = new StrTestEntity(); - ste2.setStr("str2"); + ste2.setStr( "str2" ); - em.persist(ste1); - em.persist(ste2); + em.persist( ste1 ); + em.persist( ste2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em = getEntityManager(); - em.getTransaction().begin(); + // Revision 2 + em = getEntityManager(); + em.getTransaction().begin(); - OneToManyComponentTestEntity otmcte1 = new OneToManyComponentTestEntity(new OneToManyComponent("data1")); - otmcte1.getComp1().getEntities().add(ste1); + OneToManyComponentTestEntity otmcte1 = new OneToManyComponentTestEntity( new OneToManyComponent( "data1" ) ); + otmcte1.getComp1().getEntities().add( ste1 ); - em.persist(otmcte1); + em.persist( otmcte1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 - em = getEntityManager(); - em.getTransaction().begin(); + // Revision 3 + em = getEntityManager(); + em.getTransaction().begin(); - otmcte1 = em.find(OneToManyComponentTestEntity.class, otmcte1.getId()); - otmcte1.getComp1().getEntities().add(ste2); + otmcte1 = em.find( OneToManyComponentTestEntity.class, otmcte1.getId() ); + otmcte1.getComp1().getEntities().add( ste2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - otmcte_id1 = otmcte1.getId(); + otmcte_id1 = otmcte1.getId(); ste_id1 = ste1.getId(); ste_id2 = ste2.getId(); - } + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(2, 3).equals(getAuditReader().getRevisions(OneToManyComponentTestEntity.class, otmcte_id1)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 2, 3 ).equals( + getAuditReader().getRevisions( + OneToManyComponentTestEntity.class, + otmcte_id1 + ) + ); + } - @Test - public void testHistoryOfId1() { - StrTestEntity ste1 = getEntityManager().find(StrTestEntity.class, ste_id1); - StrTestEntity ste2 = getEntityManager().find(StrTestEntity.class, ste_id2); + @Test + public void testHistoryOfId1() { + StrTestEntity ste1 = getEntityManager().find( StrTestEntity.class, ste_id1 ); + StrTestEntity ste2 = getEntityManager().find( StrTestEntity.class, ste_id2 ); - OneToManyComponentTestEntity ver2 = new OneToManyComponentTestEntity(otmcte_id1, new OneToManyComponent("data1")); - ver2.getComp1().getEntities().add(ste1); - OneToManyComponentTestEntity ver3 = new OneToManyComponentTestEntity(otmcte_id1, new OneToManyComponent("data1")); - ver3.getComp1().getEntities().add(ste1); - ver3.getComp1().getEntities().add(ste2); + OneToManyComponentTestEntity ver2 = new OneToManyComponentTestEntity( + otmcte_id1, new OneToManyComponent( + "data1" + ) + ); + ver2.getComp1().getEntities().add( ste1 ); + OneToManyComponentTestEntity ver3 = new OneToManyComponentTestEntity( + otmcte_id1, new OneToManyComponent( + "data1" + ) + ); + ver3.getComp1().getEntities().add( ste1 ); + ver3.getComp1().getEntities().add( ste2 ); - assert getAuditReader().find(OneToManyComponentTestEntity.class, otmcte_id1, 1) == null; - assert getAuditReader().find(OneToManyComponentTestEntity.class, otmcte_id1, 2).equals(ver2); - assert getAuditReader().find(OneToManyComponentTestEntity.class, otmcte_id1, 3).equals(ver3); - } + assert getAuditReader().find( OneToManyComponentTestEntity.class, otmcte_id1, 1 ) == null; + assert getAuditReader().find( OneToManyComponentTestEntity.class, otmcte_id1, 2 ).equals( ver2 ); + assert getAuditReader().find( OneToManyComponentTestEntity.class, otmcte_id1, 3 ).equals( ver3 ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/customtype/CompositeCustom.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/customtype/CompositeCustom.java index bca9b9f543..d0288c22bc 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/customtype/CompositeCustom.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/customtype/CompositeCustom.java @@ -23,79 +23,84 @@ */ package org.hibernate.envers.test.integration.customtype; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.customtype.Component; import org.hibernate.envers.test.entities.customtype.CompositeCustomTypeEntity; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class CompositeCustom extends BaseEnversJPAFunctionalTestCase { - private Integer ccte_id; + private Integer ccte_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { CompositeCustomTypeEntity.class }; - } + return new Class[] {CompositeCustomTypeEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - CompositeCustomTypeEntity ccte = new CompositeCustomTypeEntity(); + CompositeCustomTypeEntity ccte = new CompositeCustomTypeEntity(); - // Revision 1 (persisting 1 entity) - em.getTransaction().begin(); + // Revision 1 (persisting 1 entity) + em.getTransaction().begin(); - ccte.setComponent(new Component("a", 1)); + ccte.setComponent( new Component( "a", 1 ) ); - em.persist(ccte); + em.persist( ccte ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 (changing the component) - em.getTransaction().begin(); + // Revision 2 (changing the component) + em.getTransaction().begin(); - ccte = em.find(CompositeCustomTypeEntity.class, ccte.getId()); + ccte = em.find( CompositeCustomTypeEntity.class, ccte.getId() ); - ccte.getComponent().setProp1("b"); + ccte.getComponent().setProp1( "b" ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 (replacing the component) - em.getTransaction().begin(); + // Revision 3 (replacing the component) + em.getTransaction().begin(); - ccte = em.find(CompositeCustomTypeEntity.class, ccte.getId()); + ccte = em.find( CompositeCustomTypeEntity.class, ccte.getId() ); - ccte.setComponent(new Component("c", 3)); + ccte.setComponent( new Component( "c", 3 ) ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // + // - ccte_id = ccte.getId(); - } + ccte_id = ccte.getId(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2, 3).equals(getAuditReader().getRevisions(CompositeCustomTypeEntity.class, ccte_id)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2, 3 ).equals( + getAuditReader().getRevisions( + CompositeCustomTypeEntity.class, + ccte_id + ) + ); + } - @Test - public void testHistoryOfCcte() { - CompositeCustomTypeEntity rev1 = getAuditReader().find(CompositeCustomTypeEntity.class, ccte_id, 1); - CompositeCustomTypeEntity rev2 = getAuditReader().find(CompositeCustomTypeEntity.class, ccte_id, 2); - CompositeCustomTypeEntity rev3 = getAuditReader().find(CompositeCustomTypeEntity.class, ccte_id, 3); + @Test + public void testHistoryOfCcte() { + CompositeCustomTypeEntity rev1 = getAuditReader().find( CompositeCustomTypeEntity.class, ccte_id, 1 ); + CompositeCustomTypeEntity rev2 = getAuditReader().find( CompositeCustomTypeEntity.class, ccte_id, 2 ); + CompositeCustomTypeEntity rev3 = getAuditReader().find( CompositeCustomTypeEntity.class, ccte_id, 3 ); - assert rev1.getComponent().equals(new Component("a", 1)); - assert rev2.getComponent().equals(new Component("b", 1)); - assert rev3.getComponent().equals(new Component("c", 3)); - } + assert rev1.getComponent().equals( new Component( "a", 1 ) ); + assert rev2.getComponent().equals( new Component( "b", 1 ) ); + assert rev3.getComponent().equals( new Component( "c", 3 ) ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/customtype/EnumTypeTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/customtype/EnumTypeTest.java index df82aec2bf..c4f6bd3e0b 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/customtype/EnumTypeTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/customtype/EnumTypeTest.java @@ -1,24 +1,25 @@ package org.hibernate.envers.test.integration.customtype; -import java.util.List; import javax.persistence.EntityManager; - -import org.junit.Assert; -import org.junit.Test; +import java.util.List; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.customtype.EnumTypeEntity; + +import org.junit.Assert; +import org.junit.Test; + import org.hibernate.testing.TestForIssue; /** * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ -@TestForIssue( jiraKey = "HHH-7780" ) +@TestForIssue(jiraKey = "HHH-7780") public class EnumTypeTest extends BaseEnversJPAFunctionalTestCase { @Override protected Class[] getAnnotatedClasses() { - return new Class[] { EnumTypeEntity.class }; + return new Class[] {EnumTypeEntity.class}; } @Test @@ -37,7 +38,9 @@ public class EnumTypeTest extends BaseEnversJPAFunctionalTestCase { @Test public void testEnumRepresentation() { EntityManager entityManager = getEntityManager(); - List values = entityManager.createNativeQuery( "SELECT enum1, enum2 FROM EnumTypeEntity_AUD ORDER BY rev ASC" ).getResultList(); + List values = entityManager.createNativeQuery( + "SELECT enum1, enum2 FROM EnumTypeEntity_AUD ORDER BY rev ASC" + ).getResultList(); entityManager.close(); Assert.assertNotNull( values ); diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/customtype/ObjectUserType.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/customtype/ObjectUserType.java index b848d8960a..44f9dedf74 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/customtype/ObjectUserType.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/customtype/ObjectUserType.java @@ -21,10 +21,11 @@ import org.hibernate.usertype.UserType; * Custom type used to persist binary representation of Java object in the database. * Spans over two columns - one storing text representation of Java class name and the second one * containing binary data. + * * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public class ObjectUserType implements UserType { - private static final int[] TYPES = new int[] { Types.VARCHAR, Types.BLOB }; + private static final int[] TYPES = new int[] {Types.VARCHAR, Types.BLOB}; @Override public int[] sqlTypes() { @@ -38,8 +39,12 @@ public class ObjectUserType implements UserType { @Override public boolean equals(Object x, Object y) throws HibernateException { - if ( x == y ) return true; - if ( x == null || y == null ) return false; + if ( x == y ) { + return true; + } + if ( x == null || y == null ) { + return false; + } return x.equals( y ); } @@ -77,7 +82,7 @@ public class ObjectUserType implements UserType { objectOutputStream.flush(); return new ByteArrayInputStream( byteArrayOutputStream.toByteArray() ); } - catch ( IOException e ) { + catch (IOException e) { throw new RuntimeException( e ); } finally { @@ -91,7 +96,7 @@ public class ObjectUserType implements UserType { objectInputStream = new ObjectInputStream( inputStream ); return objectInputStream.readObject(); } - catch ( Exception e ) { + catch (Exception e) { throw new RuntimeException( e ); } finally { @@ -104,7 +109,7 @@ public class ObjectUserType implements UserType { try { stream.close(); } - catch ( IOException e ) { + catch (IOException e) { } } } @@ -114,7 +119,7 @@ public class ObjectUserType implements UserType { try { stream.close(); } - catch ( IOException e ) { + catch (IOException e) { } } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/customtype/ObjectUserTypeEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/customtype/ObjectUserTypeEntity.java index f1f39e4eb2..d4aa73a798 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/customtype/ObjectUserTypeEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/customtype/ObjectUserTypeEntity.java @@ -1,10 +1,10 @@ package org.hibernate.envers.test.integration.customtype; -import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; +import java.io.Serializable; import org.hibernate.annotations.Columns; import org.hibernate.annotations.Type; @@ -12,6 +12,7 @@ import org.hibernate.envers.Audited; /** * Entity encapsulating {@link Object} property which concrete type may change during subsequent updates. + * * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ @Entity @@ -24,7 +25,7 @@ public class ObjectUserTypeEntity implements Serializable { private String buildInType; @Type(type = "org.hibernate.envers.test.integration.customtype.ObjectUserType") - @Columns(columns = { @Column(name = "OBJ_TYPE"), @Column(name = "OBJ_VALUE") }) + @Columns(columns = {@Column(name = "OBJ_TYPE"), @Column(name = "OBJ_VALUE")}) private Object userType; public ObjectUserTypeEntity() { @@ -43,14 +44,24 @@ public class ObjectUserTypeEntity implements Serializable { @Override public boolean equals(Object o) { - if ( this == o ) return true; - if ( ! ( o instanceof ObjectUserTypeEntity ) ) return false; + if ( this == o ) { + return true; + } + if ( !(o instanceof ObjectUserTypeEntity) ) { + return false; + } ObjectUserTypeEntity that = (ObjectUserTypeEntity) o; - if ( id != that.id ) return false; - if ( buildInType != null ? !buildInType.equals( that.buildInType ) : that.buildInType != null ) return false; - if ( userType != null ? !userType.equals( that.userType ) : that.userType != null ) return false; + if ( id != that.id ) { + return false; + } + if ( buildInType != null ? !buildInType.equals( that.buildInType ) : that.buildInType != null ) { + return false; + } + if ( userType != null ? !userType.equals( that.userType ) : that.userType != null ) { + return false; + } return true; } @@ -58,8 +69,8 @@ public class ObjectUserTypeEntity implements Serializable { @Override public int hashCode() { int result = id; - result = 31 * result + ( buildInType != null ? buildInType.hashCode() : 0 ); - result = 31 * result + ( userType != null ? userType.hashCode() : 0 ); + result = 31 * result + (buildInType != null ? buildInType.hashCode() : 0); + result = 31 * result + (userType != null ? userType.hashCode() : 0); return result; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/customtype/ObjectUserTypeTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/customtype/ObjectUserTypeTest.java index f6d7a87613..28c5782fb0 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/customtype/ObjectUserTypeTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/customtype/ObjectUserTypeTest.java @@ -1,16 +1,17 @@ package org.hibernate.envers.test.integration.customtype; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.Map; -import javax.persistence.EntityManager; - -import org.junit.Assert; -import org.junit.Test; import org.hibernate.dialect.Oracle8iDialect; import org.hibernate.envers.configuration.EnversSettings; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; + +import org.junit.Assert; +import org.junit.Test; + import org.hibernate.testing.RequiresDialect; import org.hibernate.testing.TestForIssue; @@ -24,7 +25,7 @@ public class ObjectUserTypeTest extends BaseEnversJPAFunctionalTestCase { @Override protected Class[] getAnnotatedClasses() { - return new Class[] { ObjectUserTypeEntity.class }; + return new Class[] {ObjectUserTypeEntity.class}; } @Override @@ -79,7 +80,10 @@ public class ObjectUserTypeTest extends BaseEnversJPAFunctionalTestCase { Assert.assertEquals( ver2, getAuditReader().find( ObjectUserTypeEntity.class, id, 2 ) ); Assert.assertEquals( ver2, - getAuditReader().createQuery().forRevisionsOfEntity( ObjectUserTypeEntity.class, true, true ).getResultList().get( 2 ) + getAuditReader().createQuery() + .forRevisionsOfEntity( ObjectUserTypeEntity.class, true, true ) + .getResultList() + .get( 2 ) ); // Checking delete state. } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/customtype/ParametrizedCustom.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/customtype/ParametrizedCustom.java index 7426d5447e..0074192cfd 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/customtype/ParametrizedCustom.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/customtype/ParametrizedCustom.java @@ -23,67 +23,72 @@ */ package org.hibernate.envers.test.integration.customtype; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.customtype.ParametrizedCustomTypeEntity; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class ParametrizedCustom extends BaseEnversJPAFunctionalTestCase { - private Integer pcte_id; + private Integer pcte_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { ParametrizedCustomTypeEntity.class }; - } + return new Class[] {ParametrizedCustomTypeEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - ParametrizedCustomTypeEntity pcte = new ParametrizedCustomTypeEntity(); + ParametrizedCustomTypeEntity pcte = new ParametrizedCustomTypeEntity(); - // Revision 1 (persisting 1 entity) - em.getTransaction().begin(); + // Revision 1 (persisting 1 entity) + em.getTransaction().begin(); - pcte.setStr("U"); + pcte.setStr( "U" ); - em.persist(pcte); + em.persist( pcte ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 (changing the value) - em.getTransaction().begin(); + // Revision 2 (changing the value) + em.getTransaction().begin(); - pcte = em.find(ParametrizedCustomTypeEntity.class, pcte.getId()); + pcte = em.find( ParametrizedCustomTypeEntity.class, pcte.getId() ); - pcte.setStr("V"); + pcte.setStr( "V" ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // + // - pcte_id = pcte.getId(); - } + pcte_id = pcte.getId(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(ParametrizedCustomTypeEntity.class, pcte_id)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( + getAuditReader().getRevisions( + ParametrizedCustomTypeEntity.class, + pcte_id + ) + ); + } - @Test - public void testHistoryOfCcte() { - ParametrizedCustomTypeEntity rev1 = getAuditReader().find(ParametrizedCustomTypeEntity.class, pcte_id, 1); - ParametrizedCustomTypeEntity rev2 = getAuditReader().find(ParametrizedCustomTypeEntity.class, pcte_id, 2); + @Test + public void testHistoryOfCcte() { + ParametrizedCustomTypeEntity rev1 = getAuditReader().find( ParametrizedCustomTypeEntity.class, pcte_id, 1 ); + ParametrizedCustomTypeEntity rev2 = getAuditReader().find( ParametrizedCustomTypeEntity.class, pcte_id, 2 ); - assert "xUy".equals(rev1.getStr()); - assert "xVy".equals(rev2.getStr()); - } + assert "xUy".equals( rev1.getStr() ); + assert "xVy".equals( rev2.getStr() ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/customtype/UnspecifiedEnumTypeTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/customtype/UnspecifiedEnumTypeTest.java index f370967626..97cc813613 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/customtype/UnspecifiedEnumTypeTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/customtype/UnspecifiedEnumTypeTest.java @@ -3,9 +3,6 @@ package org.hibernate.envers.test.integration.customtype; import java.util.Arrays; import java.util.List; -import org.junit.Assert; -import org.junit.Test; - import org.hibernate.Session; import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Environment; @@ -13,20 +10,24 @@ import org.hibernate.dialect.H2Dialect; import org.hibernate.envers.test.BaseEnversFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.customtype.UnspecifiedEnumTypeEntity; + +import org.junit.Assert; +import org.junit.Test; + import org.hibernate.testing.RequiresDialect; import org.hibernate.testing.TestForIssue; /** * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ -@TestForIssue( jiraKey = "HHH-7780" ) -@RequiresDialect( value = H2Dialect.class ) +@TestForIssue(jiraKey = "HHH-7780") +@RequiresDialect(value = H2Dialect.class) public class UnspecifiedEnumTypeTest extends BaseEnversFunctionalTestCase { private Long id = null; @Override protected String[] getMappings() { - return new String[] { "mappings/customType/mappings.hbm.xml" }; + return new String[] {"mappings/customType/mappings.hbm.xml"}; } @Override @@ -82,7 +83,7 @@ public class UnspecifiedEnumTypeTest extends BaseEnversFunctionalTestCase { try { session.createSQLQuery( query ).executeUpdate(); } - catch ( Exception e ) { + catch (Exception e) { } } @@ -93,7 +94,10 @@ public class UnspecifiedEnumTypeTest extends BaseEnversFunctionalTestCase { // Revision 1 session.getTransaction().begin(); - UnspecifiedEnumTypeEntity entity = new UnspecifiedEnumTypeEntity( UnspecifiedEnumTypeEntity.E1.X, UnspecifiedEnumTypeEntity.E2.A ); + UnspecifiedEnumTypeEntity entity = new UnspecifiedEnumTypeEntity( + UnspecifiedEnumTypeEntity.E1.X, + UnspecifiedEnumTypeEntity.E2.A + ); session.persist( entity ); session.getTransaction().commit(); @@ -113,29 +117,43 @@ public class UnspecifiedEnumTypeTest extends BaseEnversFunctionalTestCase { @Test @Priority(8) public void testRevisionCount() { - Assert.assertEquals( Arrays.asList( 1, 2 ), getAuditReader().getRevisions( UnspecifiedEnumTypeEntity.class, id ) ); + Assert.assertEquals( + Arrays.asList( 1, 2 ), getAuditReader().getRevisions( + UnspecifiedEnumTypeEntity.class, + id + ) + ); } @Test @Priority(7) public void testHistoryOfEnums() { - UnspecifiedEnumTypeEntity ver1 = new UnspecifiedEnumTypeEntity( UnspecifiedEnumTypeEntity.E1.X, UnspecifiedEnumTypeEntity.E2.A, id ); - UnspecifiedEnumTypeEntity ver2 = new UnspecifiedEnumTypeEntity( UnspecifiedEnumTypeEntity.E1.Y, UnspecifiedEnumTypeEntity.E2.B, id ); + UnspecifiedEnumTypeEntity ver1 = new UnspecifiedEnumTypeEntity( + UnspecifiedEnumTypeEntity.E1.X, + UnspecifiedEnumTypeEntity.E2.A, + id + ); + UnspecifiedEnumTypeEntity ver2 = new UnspecifiedEnumTypeEntity( + UnspecifiedEnumTypeEntity.E1.Y, + UnspecifiedEnumTypeEntity.E2.B, + id + ); - Assert.assertEquals( ver1, getAuditReader().find(UnspecifiedEnumTypeEntity.class, id, 1) ); - Assert.assertEquals( ver2, getAuditReader().find(UnspecifiedEnumTypeEntity.class, id, 2) ); + Assert.assertEquals( ver1, getAuditReader().find( UnspecifiedEnumTypeEntity.class, id, 1 ) ); + Assert.assertEquals( ver2, getAuditReader().find( UnspecifiedEnumTypeEntity.class, id, 2 ) ); } @Test @Priority(6) public void testEnumRepresentation() { Session session = getSession(); - List values = session.createSQLQuery( "SELECT enum1, enum2 FROM enum_entity_aud ORDER BY rev ASC" ).list(); + List values = session.createSQLQuery( "SELECT enum1, enum2 FROM enum_entity_aud ORDER BY rev ASC" ) + .list(); session.close(); Assert.assertNotNull( values ); Assert.assertEquals( 2, values.size() ); - Assert.assertArrayEquals( new Object[] { "X", 0 }, values.get( 0 ) ); - Assert.assertArrayEquals( new Object[] { "Y", 1 }, values.get( 1 ) ); + Assert.assertArrayEquals( new Object[] {"X", 0}, values.get( 0 ) ); + Assert.assertArrayEquals( new Object[] {"Y", 1}, values.get( 1 ) ); } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/data/DateTestEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/data/DateTestEntity.java index 0ff1f570c8..325c090a38 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/data/DateTestEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/data/DateTestEntity.java @@ -22,10 +22,11 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.data; -import java.util.Date; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; +import java.util.Date; import org.hibernate.envers.Audited; @@ -34,66 +35,72 @@ import org.hibernate.envers.Audited; */ @Entity public class DateTestEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - @Audited - private Date dateValue; + @Audited + private Date dateValue; - public DateTestEntity() { - } + public DateTestEntity() { + } - public DateTestEntity(Date dateValue) { - this.dateValue = dateValue; - } + public DateTestEntity(Date dateValue) { + this.dateValue = dateValue; + } - public DateTestEntity(Integer id, Date date) { - this.id = id; - this.dateValue = date; - } + public DateTestEntity(Integer id, Date date) { + this.id = id; + this.dateValue = date; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public Date getDateValue() { - return dateValue; - } + public Date getDateValue() { + return dateValue; + } - public void setDateValue(Date dateValue) { - this.dateValue = dateValue; - } + public void setDateValue(Date dateValue) { + this.dateValue = dateValue; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof DateTestEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof DateTestEntity) ) { + return false; + } - DateTestEntity that = (DateTestEntity) o; + DateTestEntity that = (DateTestEntity) o; - if (dateValue != null) { - if (that.dateValue == null) { - return false; - } + if ( dateValue != null ) { + if ( that.dateValue == null ) { + return false; + } - if (dateValue.getTime() != that.dateValue.getTime()) { - return false; - } - } - - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( dateValue.getTime() != that.dateValue.getTime() ) { + return false; + } + } - return true; - } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (dateValue != null ? dateValue.hashCode() : 0); - return result; - } + return true; + } + + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (dateValue != null ? dateValue.hashCode() : 0); + return result; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/data/Dates.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/data/Dates.java index 8820dbfdae..cb1580d6b2 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/data/Dates.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/data/Dates.java @@ -23,54 +23,54 @@ */ package org.hibernate.envers.test.integration.data; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.Date; -import javax.persistence.EntityManager; - -import org.junit.Assert; -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; +import org.junit.Assert; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class Dates extends BaseEnversJPAFunctionalTestCase { - private Integer id1; + private Integer id1; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { DateTestEntity.class }; - } + return new Class[] {DateTestEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); - em.getTransaction().begin(); - DateTestEntity dte = new DateTestEntity(new Date(12345000)); - em.persist(dte); - id1 = dte.getId(); - em.getTransaction().commit(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); + em.getTransaction().begin(); + DateTestEntity dte = new DateTestEntity( new Date( 12345000 ) ); + em.persist( dte ); + id1 = dte.getId(); + em.getTransaction().commit(); - em.getTransaction().begin(); - dte = em.find(DateTestEntity.class, id1); - dte.setDateValue(new Date(45678000)); - em.getTransaction().commit(); - } + em.getTransaction().begin(); + dte = em.find( DateTestEntity.class, id1 ); + dte.setDateValue( new Date( 45678000 ) ); + em.getTransaction().commit(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(DateTestEntity.class, id1)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( DateTestEntity.class, id1 ) ); + } - @Test - public void testHistoryOfId1() { - DateTestEntity ver1 = new DateTestEntity(id1, new Date(12345000)); - DateTestEntity ver2 = new DateTestEntity(id1, new Date(45678000)); + @Test + public void testHistoryOfId1() { + DateTestEntity ver1 = new DateTestEntity( id1, new Date( 12345000 ) ); + DateTestEntity ver2 = new DateTestEntity( id1, new Date( 45678000 ) ); - Assert.assertEquals(ver1, getAuditReader().find(DateTestEntity.class, id1, 1)); - Assert.assertEquals(ver2, getAuditReader().find(DateTestEntity.class, id1, 2)); - } + Assert.assertEquals( ver1, getAuditReader().find( DateTestEntity.class, id1, 1 ) ); + Assert.assertEquals( ver2, getAuditReader().find( DateTestEntity.class, id1, 2 ) ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/data/EnumTestEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/data/EnumTestEntity.java index 19821bd7e9..8ac80cf36a 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/data/EnumTestEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/data/EnumTestEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.data; + import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; @@ -36,75 +37,86 @@ import org.hibernate.envers.Audited; @Entity @Audited public class EnumTestEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - public enum E1 { X, Y } - public enum E2 { A, B } + public enum E1 {X, Y} - @Enumerated(EnumType.STRING) - private E1 enum1; + public enum E2 {A, B} - @Enumerated(EnumType.ORDINAL) - private E2 enum2; + @Enumerated(EnumType.STRING) + private E1 enum1; - public EnumTestEntity() { - } + @Enumerated(EnumType.ORDINAL) + private E2 enum2; - public EnumTestEntity(E1 enum1, E2 enum2) { - this.enum1 = enum1; - this.enum2 = enum2; - } + public EnumTestEntity() { + } - public EnumTestEntity(Integer id, E1 enum1, E2 enum2) { - this.id = id; - this.enum1 = enum1; - this.enum2 = enum2; - } + public EnumTestEntity(E1 enum1, E2 enum2) { + this.enum1 = enum1; + this.enum2 = enum2; + } - public Integer getId() { - return id; - } + public EnumTestEntity(Integer id, E1 enum1, E2 enum2) { + this.id = id; + this.enum1 = enum1; + this.enum2 = enum2; + } - public void setId(Integer id) { - this.id = id; - } + public Integer getId() { + return id; + } - public E1 getEnum1() { - return enum1; - } + public void setId(Integer id) { + this.id = id; + } - public void setEnum1(E1 enum1) { - this.enum1 = enum1; - } + public E1 getEnum1() { + return enum1; + } - public E2 getEnum2() { - return enum2; - } + public void setEnum1(E1 enum1) { + this.enum1 = enum1; + } - public void setEnum2(E2 enum2) { - this.enum2 = enum2; - } + public E2 getEnum2() { + return enum2; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof EnumTestEntity)) return false; + public void setEnum2(E2 enum2) { + this.enum2 = enum2; + } - EnumTestEntity that = (EnumTestEntity) o; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof EnumTestEntity) ) { + return false; + } - if (enum1 != that.enum1) return false; - if (enum2 != that.enum2) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + EnumTestEntity that = (EnumTestEntity) o; - return true; - } + if ( enum1 != that.enum1 ) { + return false; + } + if ( enum2 != that.enum2 ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (enum1 != null ? enum1.hashCode() : 0); - result = 31 * result + (enum2 != null ? enum2.hashCode() : 0); - return result; - } + return true; + } + + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (enum1 != null ? enum1.hashCode() : 0); + result = 31 * result + (enum2 != null ? enum2.hashCode() : 0); + return result; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/data/Enums.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/data/Enums.java index bc4d7b37b2..ba693f818e 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/data/Enums.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/data/Enums.java @@ -23,53 +23,53 @@ */ package org.hibernate.envers.test.integration.data; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class Enums extends BaseEnversJPAFunctionalTestCase { - private Integer id1; + private Integer id1; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { EnumTestEntity.class }; - } + return new Class[] {EnumTestEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); - em.getTransaction().begin(); - EnumTestEntity ete = new EnumTestEntity(EnumTestEntity.E1.X, EnumTestEntity.E2.A); - em.persist(ete); - id1 = ete.getId(); - em.getTransaction().commit(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); + em.getTransaction().begin(); + EnumTestEntity ete = new EnumTestEntity( EnumTestEntity.E1.X, EnumTestEntity.E2.A ); + em.persist( ete ); + id1 = ete.getId(); + em.getTransaction().commit(); - em.getTransaction().begin(); - ete = em.find(EnumTestEntity.class, id1); - ete.setEnum1(EnumTestEntity.E1.Y); - ete.setEnum2(EnumTestEntity.E2.B); - em.getTransaction().commit(); - } + em.getTransaction().begin(); + ete = em.find( EnumTestEntity.class, id1 ); + ete.setEnum1( EnumTestEntity.E1.Y ); + ete.setEnum2( EnumTestEntity.E2.B ); + em.getTransaction().commit(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(EnumTestEntity.class, id1)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( EnumTestEntity.class, id1 ) ); + } - @Test - public void testHistoryOfId1() { - EnumTestEntity ver1 = new EnumTestEntity(id1, EnumTestEntity.E1.X, EnumTestEntity.E2.A); - EnumTestEntity ver2 = new EnumTestEntity(id1, EnumTestEntity.E1.Y, EnumTestEntity.E2.B); + @Test + public void testHistoryOfId1() { + EnumTestEntity ver1 = new EnumTestEntity( id1, EnumTestEntity.E1.X, EnumTestEntity.E2.A ); + EnumTestEntity ver2 = new EnumTestEntity( id1, EnumTestEntity.E1.Y, EnumTestEntity.E2.B ); - assert getAuditReader().find(EnumTestEntity.class, id1, 1).equals(ver1); - assert getAuditReader().find(EnumTestEntity.class, id1, 2).equals(ver2); - } + assert getAuditReader().find( EnumTestEntity.class, id1, 1 ).equals( ver1 ); + assert getAuditReader().find( EnumTestEntity.class, id1, 2 ).equals( ver2 ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/data/LobSerializableTestEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/data/LobSerializableTestEntity.java index 6e16554ecb..09082ae17c 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/data/LobSerializableTestEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/data/LobSerializableTestEntity.java @@ -35,58 +35,66 @@ import org.hibernate.envers.Audited; */ @Entity public class LobSerializableTestEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - @Audited - @Lob - private SerObject obj; + @Audited + @Lob + private SerObject obj; - public LobSerializableTestEntity() { - } + public LobSerializableTestEntity() { + } - public LobSerializableTestEntity(SerObject obj) { - this.obj = obj; - } + public LobSerializableTestEntity(SerObject obj) { + this.obj = obj; + } - public LobSerializableTestEntity(Integer id, SerObject obj) { - this.obj = obj; - this.id = id; - } + public LobSerializableTestEntity(Integer id, SerObject obj) { + this.obj = obj; + this.id = id; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public SerObject getObj() { - return obj; - } + public SerObject getObj() { + return obj; + } - public void setObj(SerObject obj) { - this.obj = obj; - } + public void setObj(SerObject obj) { + this.obj = obj; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof LobSerializableTestEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof LobSerializableTestEntity) ) { + return false; + } - LobSerializableTestEntity that = (LobSerializableTestEntity) o; + LobSerializableTestEntity that = (LobSerializableTestEntity) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; - if (obj != null ? !obj.equals(that.obj) : that.obj != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } + if ( obj != null ? !obj.equals( that.obj ) : that.obj != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (obj != null ? obj.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (obj != null ? obj.hashCode() : 0); + return result; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/data/LobSerializables.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/data/LobSerializables.java index 07402f1fcd..0f9970d70e 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/data/LobSerializables.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/data/LobSerializables.java @@ -23,14 +23,15 @@ */ package org.hibernate.envers.test.integration.data; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.Map; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.dialect.PostgreSQL82Dialect; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; + +import org.junit.Test; + import org.hibernate.testing.DialectChecks; import org.hibernate.testing.RequiresDialectFeature; @@ -39,48 +40,48 @@ import org.hibernate.testing.RequiresDialectFeature; */ @RequiresDialectFeature(DialectChecks.SupportsExpectedLobUsagePattern.class) public class LobSerializables extends BaseEnversJPAFunctionalTestCase { - private Integer id1; + private Integer id1; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { LobSerializableTestEntity.class }; - } + return new Class[] {LobSerializableTestEntity.class}; + } - @Override - protected void addConfigOptions(Map options) { - super.addConfigOptions(options); - if (getDialect() instanceof PostgreSQL82Dialect) { - // In PostgreSQL LOBs cannot be used in auto-commit mode. - options.put("hibernate.connection.autocommit", "false"); - } - } + @Override + protected void addConfigOptions(Map options) { + super.addConfigOptions( options ); + if ( getDialect() instanceof PostgreSQL82Dialect ) { + // In PostgreSQL LOBs cannot be used in auto-commit mode. + options.put( "hibernate.connection.autocommit", "false" ); + } + } - @Test - public void initData() { - EntityManager em = getEntityManager(); - em.getTransaction().begin(); - LobSerializableTestEntity ste = new LobSerializableTestEntity(new SerObject("d1")); - em.persist(ste); - id1 = ste.getId(); - em.getTransaction().commit(); + @Test + public void initData() { + EntityManager em = getEntityManager(); + em.getTransaction().begin(); + LobSerializableTestEntity ste = new LobSerializableTestEntity( new SerObject( "d1" ) ); + em.persist( ste ); + id1 = ste.getId(); + em.getTransaction().commit(); - em.getTransaction().begin(); - ste = em.find(LobSerializableTestEntity.class, id1); - ste.setObj(new SerObject("d2")); - em.getTransaction().commit(); - } + em.getTransaction().begin(); + ste = em.find( LobSerializableTestEntity.class, id1 ); + ste.setObj( new SerObject( "d2" ) ); + em.getTransaction().commit(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(LobSerializableTestEntity.class, id1)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( LobSerializableTestEntity.class, id1 ) ); + } - @Test - public void testHistoryOfId1() { - LobSerializableTestEntity ver1 = new LobSerializableTestEntity(id1, new SerObject("d1")); - LobSerializableTestEntity ver2 = new LobSerializableTestEntity(id1, new SerObject("d2")); + @Test + public void testHistoryOfId1() { + LobSerializableTestEntity ver1 = new LobSerializableTestEntity( id1, new SerObject( "d1" ) ); + LobSerializableTestEntity ver2 = new LobSerializableTestEntity( id1, new SerObject( "d2" ) ); - assert getAuditReader().find(LobSerializableTestEntity.class, id1, 1).equals(ver1); - assert getAuditReader().find(LobSerializableTestEntity.class, id1, 2).equals(ver2); - } + assert getAuditReader().find( LobSerializableTestEntity.class, id1, 1 ).equals( ver1 ); + assert getAuditReader().find( LobSerializableTestEntity.class, id1, 2 ).equals( ver2 ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/data/LobTestEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/data/LobTestEntity.java index 7adbb48ff2..4fd6c7c30f 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/data/LobTestEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/data/LobTestEntity.java @@ -22,11 +22,12 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.data; -import java.util.Arrays; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.Lob; +import java.util.Arrays; import org.hibernate.envers.Audited; @@ -35,90 +36,102 @@ import org.hibernate.envers.Audited; */ @Entity public class LobTestEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - @Lob - @Audited - private String stringLob; + @Lob + @Audited + private String stringLob; - @Lob - @Audited - private byte[] byteLob; + @Lob + @Audited + private byte[] byteLob; - @Lob - @Audited - private char[] charLob; + @Lob + @Audited + private char[] charLob; - public LobTestEntity() { - } + public LobTestEntity() { + } - public LobTestEntity(String stringLob, byte[] byteLob, char[] charLob) { - this.stringLob = stringLob; - this.byteLob = byteLob; - this.charLob = charLob; - } + public LobTestEntity(String stringLob, byte[] byteLob, char[] charLob) { + this.stringLob = stringLob; + this.byteLob = byteLob; + this.charLob = charLob; + } - public LobTestEntity(Integer id, String stringLob, byte[] byteLob, char[] charLob) { - this.id = id; - this.stringLob = stringLob; - this.byteLob = byteLob; - this.charLob = charLob; - } + public LobTestEntity(Integer id, String stringLob, byte[] byteLob, char[] charLob) { + this.id = id; + this.stringLob = stringLob; + this.byteLob = byteLob; + this.charLob = charLob; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getStringLob() { - return stringLob; - } + public String getStringLob() { + return stringLob; + } - public void setStringLob(String stringLob) { - this.stringLob = stringLob; - } + public void setStringLob(String stringLob) { + this.stringLob = stringLob; + } - public byte[] getByteLob() { - return byteLob; - } + public byte[] getByteLob() { + return byteLob; + } - public void setByteLob(byte[] byteLob) { - this.byteLob = byteLob; - } + public void setByteLob(byte[] byteLob) { + this.byteLob = byteLob; + } - public char[] getCharLob() { - return charLob; - } + public char[] getCharLob() { + return charLob; + } - public void setCharLob(char[] charLob) { - this.charLob = charLob; - } + public void setCharLob(char[] charLob) { + this.charLob = charLob; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof LobTestEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof LobTestEntity) ) { + return false; + } - LobTestEntity that = (LobTestEntity) o; + LobTestEntity that = (LobTestEntity) o; - if (!Arrays.equals(byteLob, that.byteLob)) return false; - if (!Arrays.equals(charLob, that.charLob)) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; - if (stringLob != null ? !stringLob.equals(that.stringLob) : that.stringLob != null) return false; + if ( !Arrays.equals( byteLob, that.byteLob ) ) { + return false; + } + if ( !Arrays.equals( charLob, that.charLob ) ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } + if ( stringLob != null ? !stringLob.equals( that.stringLob ) : that.stringLob != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (stringLob != null ? stringLob.hashCode() : 0); - result = 31 * result + (byteLob != null ? Arrays.hashCode(byteLob) : 0); - result = 31 * result + (charLob != null ? Arrays.hashCode(charLob) : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (stringLob != null ? stringLob.hashCode() : 0); + result = 31 * result + (byteLob != null ? Arrays.hashCode( byteLob ) : 0); + result = 31 * result + (charLob != null ? Arrays.hashCode( charLob ) : 0); + return result; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/data/Lobs.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/data/Lobs.java index 03663d91ed..5c69f77cef 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/data/Lobs.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/data/Lobs.java @@ -23,15 +23,16 @@ */ package org.hibernate.envers.test.integration.data; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.Map; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.dialect.PostgreSQL82Dialect; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; + +import org.junit.Test; + import org.hibernate.testing.DialectChecks; import org.hibernate.testing.RequiresDialectFeature; @@ -40,51 +41,51 @@ import org.hibernate.testing.RequiresDialectFeature; */ @RequiresDialectFeature(DialectChecks.SupportsExpectedLobUsagePattern.class) public class Lobs extends BaseEnversJPAFunctionalTestCase { - private Integer id1; + private Integer id1; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { LobTestEntity.class }; - } + return new Class[] {LobTestEntity.class}; + } - @Override - protected void addConfigOptions(Map options) { - super.addConfigOptions(options); - if (getDialect() instanceof PostgreSQL82Dialect) { - // In PostgreSQL LOBs cannot be used in auto-commit mode. - options.put("hibernate.connection.autocommit", "false"); - } - } + @Override + protected void addConfigOptions(Map options) { + super.addConfigOptions( options ); + if ( getDialect() instanceof PostgreSQL82Dialect ) { + // In PostgreSQL LOBs cannot be used in auto-commit mode. + options.put( "hibernate.connection.autocommit", "false" ); + } + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); - em.getTransaction().begin(); - LobTestEntity lte = new LobTestEntity("abc", new byte[] { 0, 1, 2 }, new char[] { 'x', 'y', 'z' }); - em.persist(lte); - id1 = lte.getId(); - em.getTransaction().commit(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); + em.getTransaction().begin(); + LobTestEntity lte = new LobTestEntity( "abc", new byte[] {0, 1, 2}, new char[] {'x', 'y', 'z'} ); + em.persist( lte ); + id1 = lte.getId(); + em.getTransaction().commit(); - em.getTransaction().begin(); - lte = em.find(LobTestEntity.class, id1); - lte.setStringLob("def"); - lte.setByteLob(new byte[] { 3, 4, 5 }); - lte.setCharLob(new char[] { 'h', 'i', 'j' }); - em.getTransaction().commit(); - } + em.getTransaction().begin(); + lte = em.find( LobTestEntity.class, id1 ); + lte.setStringLob( "def" ); + lte.setByteLob( new byte[] {3, 4, 5} ); + lte.setCharLob( new char[] {'h', 'i', 'j'} ); + em.getTransaction().commit(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(LobTestEntity.class, id1)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( LobTestEntity.class, id1 ) ); + } - @Test - public void testHistoryOfId1() { - LobTestEntity ver1 = new LobTestEntity(id1, "abc", new byte[] { 0, 1, 2 }, new char[] { 'x', 'y', 'z' }); - LobTestEntity ver2 = new LobTestEntity(id1, "def", new byte[] { 3, 4, 5 }, new char[] { 'h', 'i', 'j' }); + @Test + public void testHistoryOfId1() { + LobTestEntity ver1 = new LobTestEntity( id1, "abc", new byte[] {0, 1, 2}, new char[] {'x', 'y', 'z'} ); + LobTestEntity ver2 = new LobTestEntity( id1, "def", new byte[] {3, 4, 5}, new char[] {'h', 'i', 'j'} ); - assert getAuditReader().find(LobTestEntity.class, id1, 1).equals(ver1); - assert getAuditReader().find(LobTestEntity.class, id1, 2).equals(ver2); - } + assert getAuditReader().find( LobTestEntity.class, id1, 1 ).equals( ver1 ); + assert getAuditReader().find( LobTestEntity.class, id1, 2 ).equals( ver2 ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/data/SerObject.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/data/SerObject.java index 2738e690cf..7cae26bcaa 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/data/SerObject.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/data/SerObject.java @@ -22,43 +22,50 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.data; + import java.io.Serializable; /** * @author Adam Warski (adam at warski dot org) */ public class SerObject implements Serializable { - static final long serialVersionUID = 982352321924L; + static final long serialVersionUID = 982352321924L; - private String data; + private String data; - public SerObject() { - } + public SerObject() { + } - public SerObject(String data) { - this.data = data; - } + public SerObject(String data) { + this.data = data; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof SerObject)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof SerObject) ) { + return false; + } - SerObject serObject = (SerObject) o; + SerObject serObject = (SerObject) o; - if (data != null ? !data.equals(serObject.data) : serObject.data != null) return false; + if ( data != null ? !data.equals( serObject.data ) : serObject.data != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - return (data != null ? data.hashCode() : 0); - } + public int hashCode() { + return (data != null ? data.hashCode() : 0); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/data/SerializableTestEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/data/SerializableTestEntity.java index e394edf436..7ac19396a9 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/data/SerializableTestEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/data/SerializableTestEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.data; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; @@ -33,57 +34,65 @@ import org.hibernate.envers.Audited; */ @Entity public class SerializableTestEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - @Audited - private SerObject obj; + @Audited + private SerObject obj; - public SerializableTestEntity() { - } + public SerializableTestEntity() { + } - public SerializableTestEntity(SerObject obj) { - this.obj = obj; - } + public SerializableTestEntity(SerObject obj) { + this.obj = obj; + } - public SerializableTestEntity(Integer id, SerObject obj) { - this.obj = obj; - this.id = id; - } + public SerializableTestEntity(Integer id, SerObject obj) { + this.obj = obj; + this.id = id; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public SerObject getObj() { - return obj; - } + public SerObject getObj() { + return obj; + } - public void setObj(SerObject obj) { - this.obj = obj; - } + public void setObj(SerObject obj) { + this.obj = obj; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof SerializableTestEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof SerializableTestEntity) ) { + return false; + } - SerializableTestEntity that = (SerializableTestEntity) o; + SerializableTestEntity that = (SerializableTestEntity) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; - if (obj != null ? !obj.equals(that.obj) : that.obj != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } + if ( obj != null ? !obj.equals( that.obj ) : that.obj != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (obj != null ? obj.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (obj != null ? obj.hashCode() : 0); + return result; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/data/Serializables.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/data/Serializables.java index 4f146c7de4..d022ad3cc7 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/data/Serializables.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/data/Serializables.java @@ -23,52 +23,52 @@ */ package org.hibernate.envers.test.integration.data; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class Serializables extends BaseEnversJPAFunctionalTestCase { - private Integer id1; + private Integer id1; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { SerializableTestEntity.class }; - } + return new Class[] {SerializableTestEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); - em.getTransaction().begin(); - SerializableTestEntity ste = new SerializableTestEntity(new SerObject("d1")); - em.persist(ste); - id1 = ste.getId(); - em.getTransaction().commit(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); + em.getTransaction().begin(); + SerializableTestEntity ste = new SerializableTestEntity( new SerObject( "d1" ) ); + em.persist( ste ); + id1 = ste.getId(); + em.getTransaction().commit(); - em.getTransaction().begin(); - ste = em.find(SerializableTestEntity.class, id1); - ste.setObj(new SerObject("d2")); - em.getTransaction().commit(); - } + em.getTransaction().begin(); + ste = em.find( SerializableTestEntity.class, id1 ); + ste.setObj( new SerObject( "d2" ) ); + em.getTransaction().commit(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(SerializableTestEntity.class, id1)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( SerializableTestEntity.class, id1 ) ); + } - @Test - public void testHistoryOfId1() { - SerializableTestEntity ver1 = new SerializableTestEntity(id1, new SerObject("d1")); - SerializableTestEntity ver2 = new SerializableTestEntity(id1, new SerObject("d2")); + @Test + public void testHistoryOfId1() { + SerializableTestEntity ver1 = new SerializableTestEntity( id1, new SerObject( "d1" ) ); + SerializableTestEntity ver2 = new SerializableTestEntity( id1, new SerObject( "d2" ) ); - assert getAuditReader().find(SerializableTestEntity.class, id1, 1).equals(ver1); - assert getAuditReader().find(SerializableTestEntity.class, id1, 2).equals(ver2); - } + assert getAuditReader().find( SerializableTestEntity.class, id1, 1 ).equals( ver1 ); + assert getAuditReader().find( SerializableTestEntity.class, id1, 2 ).equals( ver2 ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/auditedEntity/Person.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/auditedEntity/Person.java index 2c4991a990..8ae91e2587 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/auditedEntity/Person.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/auditedEntity/Person.java @@ -1,27 +1,28 @@ package org.hibernate.envers.test.integration.entityNames.auditedEntity; + import org.hibernate.envers.Audited; /** * @author Hernán Chanfreau - * */ @Audited public class Person { - + private long id; - + private String name; - + private int age; - - public Person(){ } - - public Person(String name, int age){ + + public Person() { + } + + public Person(String name, int age) { this.name = name; this.age = age; } - + public long getId() { return id; diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/auditedEntity/ReadEntityWhitEntityNameTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/auditedEntity/ReadEntityWhitEntityNameTest.java index 3803f5438d..7dd5e33c4e 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/auditedEntity/ReadEntityWhitEntityNameTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/auditedEntity/ReadEntityWhitEntityNameTest.java @@ -5,134 +5,135 @@ import java.net.URISyntaxException; import java.net.URL; import java.util.List; -import org.junit.Test; - import org.hibernate.MappingException; import org.hibernate.envers.test.AbstractOneSessionTest; import org.hibernate.envers.test.Priority; +import org.junit.Test; + /** * @author Hernán Chanfreau - * */ -public class ReadEntityWhitEntityNameTest extends AbstractOneSessionTest{ +public class ReadEntityWhitEntityNameTest extends AbstractOneSessionTest { private long id_pers1; private long id_pers2; private long id_pers3; - + private Person person1_1; private Person person1_2; private Person person1_3; - + private Person currentPers1; - + protected void initMappings() throws MappingException, URISyntaxException { - URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/entityNames/auditedEntity/mappings.hbm.xml"); - config.addFile(new File(url.toURI())); + URL url = Thread.currentThread().getContextClassLoader().getResource( + "mappings/entityNames/auditedEntity/mappings.hbm.xml" + ); + config.addFile( new File( url.toURI() ) ); } - - - @Test - @Priority(10) - public void initData() { - - initializeSession(); - Person pers1 = new Person("Hernan", 28); - Person pers2 = new Person("Leandro", 29); - Person pers3 = new Person("Barba", 30); - - //REV 1 - getSession().getTransaction().begin(); - getSession().persist("Personaje",pers1); - id_pers1 = pers1.getId(); - getSession().getTransaction().commit(); - //REV 2 - getSession().getTransaction().begin(); - pers1 = (Person)getSession().get("Personaje", id_pers1); - pers1.setAge(29); - getSession().persist("Personaje",pers1); - getSession().persist("Personaje",pers2); - id_pers2 = pers2.getId(); - getSession().getTransaction().commit(); - - //REV - getSession().getTransaction().begin(); - pers1 = (Person)getSession().get("Personaje", id_pers1); - pers1.setName("Hernan David"); - pers2 = (Person)getSession().get("Personaje", id_pers2); - pers2.setAge(30); - getSession().persist("Personaje",pers1); - getSession().persist("Personaje",pers2); - getSession().persist("Personaje",pers3); - id_pers3 = pers3.getId(); - getSession().getTransaction().commit(); - - getSession().getTransaction().begin(); - currentPers1 = (Person)getSession().get("Personaje", id_pers1); - getSession().getTransaction().commit(); - - } - - - @Test - public void testRetrieveRevisionsWithEntityName() { - List pers1Revs = getAuditReader().getRevisions(Person.class,"Personaje", id_pers1); - List pers2Revs = getAuditReader().getRevisions(Person.class,"Personaje", id_pers2); - List pers3Revs = getAuditReader().getRevisions(Person.class,"Personaje", id_pers3); - - assert(pers1Revs.size() == 3); - assert(pers2Revs.size() == 2); - assert(pers3Revs.size() == 1); - } - - @Test - public void testRetrieveAuditedEntityWithEntityName() { - person1_1 = getAuditReader().find(Person.class, "Personaje", id_pers1, 1); - person1_2 = getAuditReader().find(Person.class, "Personaje", id_pers1, 2); - person1_3 = getAuditReader().find(Person.class, "Personaje", id_pers1, 3); - - assert(person1_1 != null); - assert(person1_2 != null); - assert(person1_3 != null); - - } - - @Test - public void testObtainEntityNameAuditedEntityWithEntityName() { - person1_1 = getAuditReader().find(Person.class, "Personaje", id_pers1, 1); - person1_2 = getAuditReader().find(Person.class, "Personaje", id_pers1, 2); - person1_3 = getAuditReader().find(Person.class, "Personaje", id_pers1, 3); - - String currentPers1EN = getSession().getEntityName(currentPers1); - - String person1EN = getAuditReader().getEntityName(person1_1.getId(), 1, person1_1); - assert (currentPers1EN.equals(person1EN)); + @Test + @Priority(10) + public void initData() { - String person2EN = getAuditReader().getEntityName(person1_2.getId(), 2, person1_2); - assert (currentPers1EN.equals(person2EN)); + initializeSession(); - String person3EN = getAuditReader().getEntityName(person1_3.getId(), 3, person1_3); - assert (currentPers1EN.equals(person3EN)); + Person pers1 = new Person( "Hernan", 28 ); + Person pers2 = new Person( "Leandro", 29 ); + Person pers3 = new Person( "Barba", 30 ); + + //REV 1 + getSession().getTransaction().begin(); + getSession().persist( "Personaje", pers1 ); + id_pers1 = pers1.getId(); + getSession().getTransaction().commit(); + + //REV 2 + getSession().getTransaction().begin(); + pers1 = (Person) getSession().get( "Personaje", id_pers1 ); + pers1.setAge( 29 ); + getSession().persist( "Personaje", pers1 ); + getSession().persist( "Personaje", pers2 ); + id_pers2 = pers2.getId(); + getSession().getTransaction().commit(); + + //REV + getSession().getTransaction().begin(); + pers1 = (Person) getSession().get( "Personaje", id_pers1 ); + pers1.setName( "Hernan David" ); + pers2 = (Person) getSession().get( "Personaje", id_pers2 ); + pers2.setAge( 30 ); + getSession().persist( "Personaje", pers1 ); + getSession().persist( "Personaje", pers2 ); + getSession().persist( "Personaje", pers3 ); + id_pers3 = pers3.getId(); + getSession().getTransaction().commit(); + + getSession().getTransaction().begin(); + currentPers1 = (Person) getSession().get( "Personaje", id_pers1 ); + getSession().getTransaction().commit(); + + } + + + @Test + public void testRetrieveRevisionsWithEntityName() { + List pers1Revs = getAuditReader().getRevisions( Person.class, "Personaje", id_pers1 ); + List pers2Revs = getAuditReader().getRevisions( Person.class, "Personaje", id_pers2 ); + List pers3Revs = getAuditReader().getRevisions( Person.class, "Personaje", id_pers3 ); + + assert (pers1Revs.size() == 3); + assert (pers2Revs.size() == 2); + assert (pers3Revs.size() == 1); + } + + @Test + public void testRetrieveAuditedEntityWithEntityName() { + person1_1 = getAuditReader().find( Person.class, "Personaje", id_pers1, 1 ); + person1_2 = getAuditReader().find( Person.class, "Personaje", id_pers1, 2 ); + person1_3 = getAuditReader().find( Person.class, "Personaje", id_pers1, 3 ); + + assert (person1_1 != null); + assert (person1_2 != null); + assert (person1_3 != null); + + } + + @Test + public void testObtainEntityNameAuditedEntityWithEntityName() { + person1_1 = getAuditReader().find( Person.class, "Personaje", id_pers1, 1 ); + person1_2 = getAuditReader().find( Person.class, "Personaje", id_pers1, 2 ); + person1_3 = getAuditReader().find( Person.class, "Personaje", id_pers1, 3 ); + + String currentPers1EN = getSession().getEntityName( currentPers1 ); + + String person1EN = getAuditReader().getEntityName( person1_1.getId(), 1, person1_1 ); + assert (currentPers1EN.equals( person1EN )); + + String person2EN = getAuditReader().getEntityName( person1_2.getId(), 2, person1_2 ); + assert (currentPers1EN.equals( person2EN )); + + String person3EN = getAuditReader().getEntityName( person1_3.getId(), 3, person1_3 ); + assert (currentPers1EN.equals( person3EN )); + + } + + @Test + public void testRetrieveAuditedEntityWithEntityNameWithNewSession() { + + // force a new session and AR + forceNewSession(); + + person1_1 = getAuditReader().find( Person.class, "Personaje", id_pers1, 1 ); + person1_2 = getAuditReader().find( Person.class, "Personaje", id_pers1, 2 ); + person1_3 = getAuditReader().find( Person.class, "Personaje", id_pers1, 3 ); + + assert (person1_1 != null); + assert (person1_2 != null); + assert (person1_3 != null); + } - } - - @Test - public void testRetrieveAuditedEntityWithEntityNameWithNewSession() { - - // force a new session and AR - forceNewSession(); - person1_1 = getAuditReader().find(Person.class, "Personaje", id_pers1, 1); - person1_2 = getAuditReader().find(Person.class, "Personaje", id_pers1, 2); - person1_3 = getAuditReader().find(Person.class, "Personaje", id_pers1, 3); - - assert(person1_1 != null); - assert(person1_2 != null); - assert(person1_3 != null); - } - - } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/manyToManyAudited/Car.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/manyToManyAudited/Car.java index 813cb29786..0767b176c4 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/manyToManyAudited/Car.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/manyToManyAudited/Car.java @@ -1,31 +1,32 @@ package org.hibernate.envers.test.integration.entityNames.manyToManyAudited; + import java.util.List; import org.hibernate.envers.Audited; /** * @author Hernán Chanfreau - * */ @Audited public class Car { - + private long id; - + private int registrationNumber; - + private List owners; - - public Car() { } + + public Car() { + } public Car(int registrationNumber, List owners) { this.registrationNumber = registrationNumber; this.owners = owners; } - + public long getId() { return id; } @@ -40,7 +41,7 @@ public class Car { public void setOwners(List owners) { this.owners = owners; - } + } public int getRegistrationNumber() { return registrationNumber; @@ -51,5 +52,4 @@ public class Car { } - } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/manyToManyAudited/Person.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/manyToManyAudited/Person.java index 59295270f4..6aa6afa3c7 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/manyToManyAudited/Person.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/manyToManyAudited/Person.java @@ -1,31 +1,32 @@ package org.hibernate.envers.test.integration.entityNames.manyToManyAudited; + import java.util.List; import org.hibernate.envers.Audited; /** * @author Hernán Chanfreau - * */ @Audited public class Person { - + private long id; - + private String name; - + private int age; - + private List cars; - - public Person(){ } - - public Person(String name, int age){ + + public Person() { + } + + public Person(String name, int age) { this.name = name; this.age = age; } - + public long getId() { return id; diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/manyToManyAudited/ReadEntityWithAuditedManyToManyTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/manyToManyAudited/ReadEntityWithAuditedManyToManyTest.java index b1f9b50d80..d18900cfb4 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/manyToManyAudited/ReadEntityWithAuditedManyToManyTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/manyToManyAudited/ReadEntityWithAuditedManyToManyTest.java @@ -6,126 +6,126 @@ import java.net.URL; import java.util.ArrayList; import java.util.List; -import org.junit.Test; - import org.hibernate.MappingException; import org.hibernate.envers.test.AbstractOneSessionTest; import org.hibernate.envers.test.Priority; +import org.junit.Test; + /** * @author Hernán Chanfreau - * */ -public class ReadEntityWithAuditedManyToManyTest extends AbstractOneSessionTest{ +public class ReadEntityWithAuditedManyToManyTest extends AbstractOneSessionTest { private long id_car1; private long id_car2; - + private long id_pers1; - + private Person person1; private Car car1; - + private Person person1_1; private Car car1_2; - + protected void initMappings() throws MappingException, URISyntaxException { - URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/entityNames/manyToManyAudited/mappings.hbm.xml"); - config.addFile(new File(url.toURI())); + URL url = Thread.currentThread().getContextClassLoader().getResource( + "mappings/entityNames/manyToManyAudited/mappings.hbm.xml" + ); + config.addFile( new File( url.toURI() ) ); } - - - @Test - @Priority(10) - public void initData() { - - initializeSession(); - Person pers1 = new Person("Hernan", 28); - Person pers2 = new Person("Leandro", 29); - Person pers3 = new Person("Barba", 32); - Person pers4 = new Person("Camomo", 15); - //REV 1 - getSession().getTransaction().begin(); - List owners = new ArrayList(); - owners.add(pers1); - owners.add(pers2); - owners.add(pers3); - Car car1 = new Car(5, owners); + @Test + @Priority(10) + public void initData() { - getSession().persist(car1); - getSession().getTransaction().commit(); - id_pers1 = pers1.getId(); - id_car1 = car1.getId(); + initializeSession(); - owners = new ArrayList(); - owners.add(pers2); - owners.add(pers3); - owners.add(pers4); - Car car2 = new Car(27, owners); - //REV 2 - getSession().getTransaction().begin(); - Person person1 = (Person)getSession().get("Personaje", id_pers1); - person1.setName("Hernan David"); - person1.setAge(40); - getSession().persist(car1); - getSession().persist(car2); - getSession().getTransaction().commit(); - id_car2 = car2.getId(); - } - - private void loadDataOnSessionAndAuditReader() { - - car1_2 = getAuditReader().find(Car.class, id_car1, 2); - Car car2_2 = getAuditReader().find(Car.class, id_car2, 2); + Person pers1 = new Person( "Hernan", 28 ); + Person pers2 = new Person( "Leandro", 29 ); + Person pers3 = new Person( "Barba", 32 ); + Person pers4 = new Person( "Camomo", 15 ); - // navigate through relations to load objects - for (Person owner : car1_2.getOwners()) { - for (Car ownedCar : owner.getCars()) { - ownedCar.getRegistrationNumber(); - } - } - for (Person owner : car2_2.getOwners()) { - for (Car ownedCar : owner.getCars()) { + //REV 1 + getSession().getTransaction().begin(); + List owners = new ArrayList(); + owners.add( pers1 ); + owners.add( pers2 ); + owners.add( pers3 ); + Car car1 = new Car( 5, owners ); + + getSession().persist( car1 ); + getSession().getTransaction().commit(); + id_pers1 = pers1.getId(); + id_car1 = car1.getId(); + + owners = new ArrayList(); + owners.add( pers2 ); + owners.add( pers3 ); + owners.add( pers4 ); + Car car2 = new Car( 27, owners ); + //REV 2 + getSession().getTransaction().begin(); + Person person1 = (Person) getSession().get( "Personaje", id_pers1 ); + person1.setName( "Hernan David" ); + person1.setAge( 40 ); + getSession().persist( car1 ); + getSession().persist( car2 ); + getSession().getTransaction().commit(); + id_car2 = car2.getId(); + } + + private void loadDataOnSessionAndAuditReader() { + + car1_2 = getAuditReader().find( Car.class, id_car1, 2 ); + Car car2_2 = getAuditReader().find( Car.class, id_car2, 2 ); + + // navigate through relations to load objects + for ( Person owner : car1_2.getOwners() ) { + for ( Car ownedCar : owner.getCars() ) { ownedCar.getRegistrationNumber(); } } - - car1 = (Car)getSession().get(Car.class, id_car1); - person1 = (Person)getSession().get("Personaje", id_pers1); - person1_1 = getAuditReader().find(Person.class, "Personaje", id_pers1, 1); - } - + for ( Person owner : car2_2.getOwners() ) { + for ( Car ownedCar : owner.getCars() ) { + ownedCar.getRegistrationNumber(); + } + } + + car1 = (Car) getSession().get( Car.class, id_car1 ); + person1 = (Person) getSession().get( "Personaje", id_pers1 ); + person1_1 = getAuditReader().find( Person.class, "Personaje", id_pers1, 1 ); + } private void checkEntityNames() { - String currPerson1EN = getSession().getEntityName(person1); - String currCar1EN = getSession().getEntityName(car1); - - String person1_1EN = getAuditReader().getEntityName(id_pers1, 1, person1_1); - assert(currPerson1EN.equals(person1_1EN)); - - String car1_2EN = getAuditReader().getEntityName(id_car1, 2, car1_2); - assert(currCar1EN.equals(car1_2EN)); + String currPerson1EN = getSession().getEntityName( person1 ); + String currCar1EN = getSession().getEntityName( car1 ); + + String person1_1EN = getAuditReader().getEntityName( id_pers1, 1, person1_1 ); + assert (currPerson1EN.equals( person1_1EN )); + + String car1_2EN = getAuditReader().getEntityName( id_car1, 2, car1_2 ); + assert (currCar1EN.equals( car1_2EN )); } - - @Test - public void testGetEntityNameManyYoManyWithEntityName() { - - loadDataOnSessionAndAuditReader(); - - checkEntityNames(); - } - - @Test - public void testGetEntityNameManyYoManyWithEntityNameInNewSession() { - //force new session and AR - forceNewSession(); - loadDataOnSessionAndAuditReader(); - - checkEntityNames(); + @Test + public void testGetEntityNameManyYoManyWithEntityName() { - } + loadDataOnSessionAndAuditReader(); + + checkEntityNames(); + } + + + @Test + public void testGetEntityNameManyYoManyWithEntityNameInNewSession() { + //force new session and AR + forceNewSession(); + loadDataOnSessionAndAuditReader(); + + checkEntityNames(); + + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/oneToManyAudited/Car.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/oneToManyAudited/Car.java index 5498c1ddbf..fe7a5766f9 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/oneToManyAudited/Car.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/oneToManyAudited/Car.java @@ -1,31 +1,32 @@ package org.hibernate.envers.test.integration.entityNames.oneToManyAudited; + import java.util.List; import org.hibernate.envers.Audited; /** * @author Hernán Chanfreau - * */ @Audited public class Car { - + private long id; - + private int number; - + private List owners; - - public Car() { } + + public Car() { + } public Car(int number, List owners) { this.number = number; this.owners = owners; } - + public long getId() { return id; } @@ -40,7 +41,7 @@ public class Car { public void setOwners(List owners) { this.owners = owners; - } + } public int getNumber() { return number; @@ -51,5 +52,4 @@ public class Car { } - } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/oneToManyAudited/Person.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/oneToManyAudited/Person.java index b253ebff5a..4e341d2647 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/oneToManyAudited/Person.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/oneToManyAudited/Person.java @@ -1,27 +1,28 @@ package org.hibernate.envers.test.integration.entityNames.oneToManyAudited; + import org.hibernate.envers.Audited; /** * @author Hernán Chanfreau - * */ @Audited public class Person { - + private long id; - + private String name; - + private int age; - - public Person(){ } - - public Person(String name, int age){ + + public Person() { + } + + public Person(String name, int age) { this.name = name; this.age = age; } - + public long getId() { return id; diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/oneToManyAudited/ReadEntityWithAuditedCollectionTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/oneToManyAudited/ReadEntityWithAuditedCollectionTest.java index 0ac4945258..f65fc0b464 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/oneToManyAudited/ReadEntityWithAuditedCollectionTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/oneToManyAudited/ReadEntityWithAuditedCollectionTest.java @@ -6,123 +6,123 @@ import java.net.URL; import java.util.ArrayList; import java.util.List; -import org.junit.Test; - import org.hibernate.MappingException; import org.hibernate.envers.test.AbstractOneSessionTest; import org.hibernate.envers.test.Priority; +import org.junit.Test; + /** * @author Hernán Chanfreau - * */ -public class ReadEntityWithAuditedCollectionTest extends AbstractOneSessionTest{ +public class ReadEntityWithAuditedCollectionTest extends AbstractOneSessionTest { private long id_car1; private long id_car2; - + private Car currentCar1; private Person currentPerson1; - + private long id_pers1; - + private Car car1_1; - private Person person1_1; - + private Person person1_1; + protected void initMappings() throws MappingException, URISyntaxException { - URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/entityNames/oneToManyAudited/mappings.hbm.xml"); - config.addFile(new File(url.toURI())); + URL url = Thread.currentThread().getContextClassLoader().getResource( + "mappings/entityNames/oneToManyAudited/mappings.hbm.xml" + ); + config.addFile( new File( url.toURI() ) ); } - - @Test - @Priority(10) - public void initData() { - - initializeSession(); - Person pers1 = new Person("Hernan", 28); - Person pers2 = new Person("Leandro", 29); - Person pers4 = new Person("Camomo", 15); + @Test + @Priority(10) + public void initData() { - List owners = new ArrayList(); - owners.add(pers1); - owners.add(pers2); - Car car1 = new Car(5, owners); + initializeSession(); - //REV 1 - getSession().getTransaction().begin(); - getSession().persist(car1); - getSession().getTransaction().commit(); - id_pers1 = pers1.getId(); - id_car1 = car1.getId(); + Person pers1 = new Person( "Hernan", 28 ); + Person pers2 = new Person( "Leandro", 29 ); + Person pers4 = new Person( "Camomo", 15 ); - owners = new ArrayList(); - owners.add(pers2); - owners.add(pers4); - Car car2 = new Car(27, owners); - //REV 2 - getSession().getTransaction().begin(); - Person person1 = (Person)getSession().get("Personaje", id_pers1); - person1.setName("Hernan David"); - person1.setAge(40); - getSession().persist(car1); - getSession().persist(car2); - getSession().getTransaction().commit(); - id_car2 = car2.getId(); + List owners = new ArrayList(); + owners.add( pers1 ); + owners.add( pers2 ); + Car car1 = new Car( 5, owners ); - } - - private void loadDataOnSessionAndAuditReader() { - - currentCar1 = (Car)getSession().get(Car.class, id_car1); - currentPerson1 = (Person)getSession().get("Personaje", id_pers1); - - person1_1 = getAuditReader().find(Person.class,"Personaje", id_pers1, 1); - car1_1 = getAuditReader().find(Car.class, id_car1, 2); - Car car2 = getAuditReader().find(Car.class, id_car2, 2); + //REV 1 + getSession().getTransaction().begin(); + getSession().persist( car1 ); + getSession().getTransaction().commit(); + id_pers1 = pers1.getId(); + id_car1 = car1.getId(); - for (Person owner : car1_1.getOwners()) { - owner.getName(); - owner.getAge(); + owners = new ArrayList(); + owners.add( pers2 ); + owners.add( pers4 ); + Car car2 = new Car( 27, owners ); + //REV 2 + getSession().getTransaction().begin(); + Person person1 = (Person) getSession().get( "Personaje", id_pers1 ); + person1.setName( "Hernan David" ); + person1.setAge( 40 ); + getSession().persist( car1 ); + getSession().persist( car2 ); + getSession().getTransaction().commit(); + id_car2 = car2.getId(); + + } + + private void loadDataOnSessionAndAuditReader() { + + currentCar1 = (Car) getSession().get( Car.class, id_car1 ); + currentPerson1 = (Person) getSession().get( "Personaje", id_pers1 ); + + person1_1 = getAuditReader().find( Person.class, "Personaje", id_pers1, 1 ); + car1_1 = getAuditReader().find( Car.class, id_car1, 2 ); + Car car2 = getAuditReader().find( Car.class, id_car2, 2 ); + + for ( Person owner : car1_1.getOwners() ) { + owner.getName(); + owner.getAge(); } - for (Person owner : car2.getOwners()) { - owner.getName(); - owner.getAge(); + for ( Person owner : car2.getOwners() ) { + owner.getName(); + owner.getAge(); } - } + } private void checkEntityNames() { - String currCar1EN = getSession().getEntityName(currentCar1); - String currPerson1EN = getSession().getEntityName(currentPerson1); - - String car1_1EN = getAuditReader().getEntityName(id_car1, 2, car1_1); - assert(currCar1EN.equals(car1_1EN)); - - String person1_1EN = getAuditReader().getEntityName(id_pers1, 1, person1_1); - assert(currPerson1EN.equals(person1_1EN)); - } - - @Test - public void testObtainEntityNameAuditedCollectionWithEntityName() { - - this.loadDataOnSessionAndAuditReader(); - - checkEntityNames(); - - } + String currCar1EN = getSession().getEntityName( currentCar1 ); + String currPerson1EN = getSession().getEntityName( currentPerson1 ); + + String car1_1EN = getAuditReader().getEntityName( id_car1, 2, car1_1 ); + assert (currCar1EN.equals( car1_1EN )); + + String person1_1EN = getAuditReader().getEntityName( id_pers1, 1, person1_1 ); + assert (currPerson1EN.equals( person1_1EN )); + } + + @Test + public void testObtainEntityNameAuditedCollectionWithEntityName() { + + this.loadDataOnSessionAndAuditReader(); + + checkEntityNames(); + + } - - @Test - public void testObtainEntityNameAuditedCollectionWithEntityNameInNewSession() { - // force a new session and AR - forceNewSession(); - - loadDataOnSessionAndAuditReader(); - - checkEntityNames(); - - } + @Test + public void testObtainEntityNameAuditedCollectionWithEntityNameInNewSession() { + // force a new session and AR + forceNewSession(); + + loadDataOnSessionAndAuditReader(); + + checkEntityNames(); + + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/oneToManyNotAudited/Car.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/oneToManyNotAudited/Car.java index ffafbc259c..b8421b7e91 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/oneToManyNotAudited/Car.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/oneToManyNotAudited/Car.java @@ -1,4 +1,5 @@ package org.hibernate.envers.test.integration.entityNames.oneToManyNotAudited; + import java.util.List; import org.hibernate.envers.Audited; @@ -6,26 +7,26 @@ import org.hibernate.envers.RelationTargetAuditMode; /** * @author Hernán Chanfreau - * */ public class Car { - + private long id; - + private int number; - + private List owners; - - public Car() { } + + public Car() { + } public Car(int number, List owners) { this.number = number; this.owners = owners; } - + public long getId() { return id; } @@ -34,14 +35,14 @@ public class Car { this.id = id; } - @Audited(targetAuditMode=RelationTargetAuditMode.NOT_AUDITED) + @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED) public List getOwners() { return owners; } public void setOwners(List owners) { this.owners = owners; - } + } @Audited public int getNumber() { @@ -53,5 +54,4 @@ public class Car { } - } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/oneToManyNotAudited/Person.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/oneToManyNotAudited/Person.java index dbd112abd0..f02d4b32fb 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/oneToManyNotAudited/Person.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/oneToManyNotAudited/Person.java @@ -3,24 +3,24 @@ package org.hibernate.envers.test.integration.entityNames.oneToManyNotAudited; /** * @author Hernán Chanfreau - * */ public class Person { - + private long id; - + private String name; - + private int age; - - public Person(){ } - - public Person(String name, int age){ + + public Person() { + } + + public Person(String name, int age) { this.name = name; this.age = age; } - + public long getId() { return id; diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/oneToManyNotAudited/ReadEntityWithAuditedCollectionTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/oneToManyNotAudited/ReadEntityWithAuditedCollectionTest.java index acdd3b391d..2e59e9218d 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/oneToManyNotAudited/ReadEntityWithAuditedCollectionTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/oneToManyNotAudited/ReadEntityWithAuditedCollectionTest.java @@ -6,126 +6,124 @@ import java.net.URL; import java.util.ArrayList; import java.util.List; -import org.junit.Test; - import org.hibernate.MappingException; import org.hibernate.envers.test.AbstractOneSessionTest; import org.hibernate.envers.test.Priority; +import org.junit.Test; + /** * @author Hernán Chanfreau - * */ -public class ReadEntityWithAuditedCollectionTest extends AbstractOneSessionTest{ +public class ReadEntityWithAuditedCollectionTest extends AbstractOneSessionTest { private long id_car1; private long id_car2; - + private Car currentCar1; private Person currentPerson1; - + private long id_pers1; - + private Car car1_1; - + protected void initMappings() throws MappingException, URISyntaxException { - URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/entityNames/oneToManyNotAudited/mappings.hbm.xml"); - config.addFile(new File(url.toURI())); + URL url = Thread.currentThread().getContextClassLoader().getResource( + "mappings/entityNames/oneToManyNotAudited/mappings.hbm.xml" + ); + config.addFile( new File( url.toURI() ) ); } - - - @Test - @Priority(10) - public void initData() { - - initializeSession(); - Person pers1 = new Person("Hernan", 28); - Person pers2 = new Person("Leandro", 29); - Person pers4 = new Person("Camomo", 15); - List owners = new ArrayList(); - owners.add(pers1); - owners.add(pers2); - Car car1 = new Car(5, owners); + @Test + @Priority(10) + public void initData() { - //REV 1 - getSession().getTransaction().begin(); - getSession().persist(car1); - getSession().getTransaction().commit(); - id_pers1 = pers1.getId(); - id_car1 = car1.getId(); + initializeSession(); - owners = new ArrayList(); - owners.add(pers2); - owners.add(pers4); - Car car2 = new Car(27, owners); - //REV 2 - getSession().getTransaction().begin(); - Person person1 = (Person)getSession().get("Personaje", id_pers1); - person1.setName("Hernan David"); - person1.setAge(40); - getSession().persist(car1); - getSession().persist(car2); - getSession().getTransaction().commit(); - id_car2 = car2.getId(); + Person pers1 = new Person( "Hernan", 28 ); + Person pers2 = new Person( "Leandro", 29 ); + Person pers4 = new Person( "Camomo", 15 ); - } - - private void loadDataOnSessionAndAuditReader() { - - currentCar1 = (Car)getSession().get(Car.class, id_car1); - currentPerson1 = (Person)getSession().get("Personaje", id_pers1); - - car1_1 = getAuditReader().find(Car.class, id_car1, 2); - Car car2 = getAuditReader().find(Car.class, id_car2, 2); + List owners = new ArrayList(); + owners.add( pers1 ); + owners.add( pers2 ); + Car car1 = new Car( 5, owners ); - for (Person owner : car1_1.getOwners()) { - owner.getName(); - owner.getAge(); + //REV 1 + getSession().getTransaction().begin(); + getSession().persist( car1 ); + getSession().getTransaction().commit(); + id_pers1 = pers1.getId(); + id_car1 = car1.getId(); + + owners = new ArrayList(); + owners.add( pers2 ); + owners.add( pers4 ); + Car car2 = new Car( 27, owners ); + //REV 2 + getSession().getTransaction().begin(); + Person person1 = (Person) getSession().get( "Personaje", id_pers1 ); + person1.setName( "Hernan David" ); + person1.setAge( 40 ); + getSession().persist( car1 ); + getSession().persist( car2 ); + getSession().getTransaction().commit(); + id_car2 = car2.getId(); + + } + + private void loadDataOnSessionAndAuditReader() { + + currentCar1 = (Car) getSession().get( Car.class, id_car1 ); + currentPerson1 = (Person) getSession().get( "Personaje", id_pers1 ); + + car1_1 = getAuditReader().find( Car.class, id_car1, 2 ); + Car car2 = getAuditReader().find( Car.class, id_car2, 2 ); + + for ( Person owner : car1_1.getOwners() ) { + owner.getName(); + owner.getAge(); } - for (Person owner : car2.getOwners()) { - owner.getName(); - owner.getAge(); + for ( Person owner : car2.getOwners() ) { + owner.getName(); + owner.getAge(); } - } - - private void checkEntityNames() { - - String currCar1EN = getSession().getEntityName(currentCar1); - String currPerson1EN = getSession().getEntityName(currentPerson1); + } - String car1_1EN = getAuditReader().getEntityName(id_car1, 2, car1_1); - assert(currCar1EN.equals(car1_1EN)); - - String person1_1EN = getSession().getEntityName(currentPerson1); - assert(currPerson1EN.equals(person1_1EN)); - } + private void checkEntityNames() { - @Test - public void testObtainEntityNameCollectionWithEntityNameAndNotAuditedMode() { - loadDataOnSessionAndAuditReader(); - - checkEntityNames(); + String currCar1EN = getSession().getEntityName( currentCar1 ); + String currPerson1EN = getSession().getEntityName( currentPerson1 ); - - } + String car1_1EN = getAuditReader().getEntityName( id_car1, 2, car1_1 ); + assert (currCar1EN.equals( car1_1EN )); - @Test - public void testObtainEntityNameCollectionWithEntityNameAndNotAuditedModeInNewSession() { - // force new session and AR - forceNewSession(); - - loadDataOnSessionAndAuditReader(); - - checkEntityNames(); + String person1_1EN = getSession().getEntityName( currentPerson1 ); + assert (currPerson1EN.equals( person1_1EN )); + } + + @Test + public void testObtainEntityNameCollectionWithEntityNameAndNotAuditedMode() { + loadDataOnSessionAndAuditReader(); + + checkEntityNames(); + + + } + + @Test + public void testObtainEntityNameCollectionWithEntityNameAndNotAuditedModeInNewSession() { + // force new session and AR + forceNewSession(); + + loadDataOnSessionAndAuditReader(); + + checkEntityNames(); + + + } - - } - - - - } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/singleAssociatedAudited/Car.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/singleAssociatedAudited/Car.java index 5bdd0a8758..507bbcbd71 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/singleAssociatedAudited/Car.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/singleAssociatedAudited/Car.java @@ -1,31 +1,32 @@ package org.hibernate.envers.test.integration.entityNames.singleAssociatedAudited; + import org.hibernate.envers.Audited; /** * @author Hernán Chanfreau - * */ @Audited public class Car { - + private long id; - + private int number; - + private Person owner; - private Person driver; - - public Car() { } + private Person driver; + + public Car() { + } public Car(int number, Person owner, Person driver) { this.number = number; this.owner = owner; - this.driver = driver; + this.driver = driver; } - + public long getId() { return id; } @@ -40,7 +41,7 @@ public class Car { public void setOwner(Person owner) { this.owner = owner; - } + } public int getNumber() { return number; @@ -50,11 +51,11 @@ public class Car { this.number = number; } - public Person getDriver() { - return driver; - } + public Person getDriver() { + return driver; + } - public void setDriver(Person driver) { - this.driver = driver; - } + public void setDriver(Person driver) { + this.driver = driver; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/singleAssociatedAudited/Person.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/singleAssociatedAudited/Person.java index 6758e13a2d..5768954935 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/singleAssociatedAudited/Person.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/singleAssociatedAudited/Person.java @@ -1,27 +1,28 @@ package org.hibernate.envers.test.integration.entityNames.singleAssociatedAudited; + import org.hibernate.envers.Audited; /** * @author Hernán Chanfreau - * */ @Audited public class Person { - + private long id; - + private String name; - + private int age; - - public Person(){ } - - public Person(String name, int age){ + + public Person() { + } + + public Person(String name, int age) { this.name = name; this.age = age; } - + public long getId() { return id; diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/singleAssociatedAudited/ReadEntityAssociatedAuditedTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/singleAssociatedAudited/ReadEntityAssociatedAuditedTest.java index 7c9dcedb72..bdc40336ab 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/singleAssociatedAudited/ReadEntityAssociatedAuditedTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/singleAssociatedAudited/ReadEntityAssociatedAuditedTest.java @@ -4,120 +4,119 @@ import java.io.File; import java.net.URISyntaxException; import java.net.URL; -import org.junit.Test; - import org.hibernate.MappingException; import org.hibernate.envers.test.AbstractOneSessionTest; import org.hibernate.envers.test.Priority; +import org.junit.Test; + /** * @author Hernán Chanfreau - * */ -public class ReadEntityAssociatedAuditedTest extends AbstractOneSessionTest{ +public class ReadEntityAssociatedAuditedTest extends AbstractOneSessionTest { private long id_car1; private long id_car2; - + private Car currentCar1; private Car car1; - - private long id_pers1; + + private long id_pers1; private long id_pers2; - + private Person currentPerson1; private Person person1; - - - - + + protected void initMappings() throws MappingException, URISyntaxException { - URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/entityNames/singleAssociatedAudited/mappings.hbm.xml"); - config.addFile(new File(url.toURI())); + URL url = Thread.currentThread().getContextClassLoader().getResource( + "mappings/entityNames/singleAssociatedAudited/mappings.hbm.xml" + ); + config.addFile( new File( url.toURI() ) ); } - - @Test - @Priority(10) - public void initData() { - - initializeSession(); - Person pers1 = new Person("Hernan", 15); - Person pers2 = new Person("Leandro", 19); - - Car car1 = new Car(1, pers1, null); - Car car2 = new Car(2, pers2, null); - - //REV 1 - getSession().getTransaction().begin(); - getSession().persist("Personaje",pers1); - getSession().persist(car1); - getSession().getTransaction().commit(); - id_car1 = car1.getId(); - id_pers1 = pers1.getId(); + @Test + @Priority(10) + public void initData() { + + initializeSession(); + + Person pers1 = new Person( "Hernan", 15 ); + Person pers2 = new Person( "Leandro", 19 ); + + Car car1 = new Car( 1, pers1, null ); + Car car2 = new Car( 2, pers2, null ); + + //REV 1 + getSession().getTransaction().begin(); + getSession().persist( "Personaje", pers1 ); + getSession().persist( car1 ); + getSession().getTransaction().commit(); + id_car1 = car1.getId(); + id_pers1 = pers1.getId(); + + //REV 2 + getSession().getTransaction().begin(); + pers1.setAge( 50 ); + getSession().persist( "Personaje", pers1 ); + getSession().persist( "Personaje", pers2 ); + getSession().persist( car2 ); + getSession().getTransaction().commit(); + id_car2 = car2.getId(); + id_pers2 = pers2.getId(); + + } + + private void loadDataOnSessionAndAuditReader() { + currentCar1 = (Car) getSession().get( Car.class, id_car1 ); + currentPerson1 = (Person) getSession().get( "Personaje", id_pers1 ); + car1 = getAuditReader().find( Car.class, id_car1, 1 ); + person1 = car1.getOwner(); + + } - //REV 2 - getSession().getTransaction().begin(); - pers1.setAge(50); - getSession().persist("Personaje", pers1); - getSession().persist("Personaje", pers2); - getSession().persist(car2); - getSession().getTransaction().commit(); - id_car2 = car2.getId(); - id_pers2 = pers2.getId(); - - } - - private void loadDataOnSessionAndAuditReader() { - currentCar1 = (Car)getSession().get(Car.class, id_car1); - currentPerson1 = (Person)getSession().get("Personaje", id_pers1); - car1 = getAuditReader().find(Car.class, id_car1, 1); - person1 = car1.getOwner(); - - } - private void checkEntities() { - assert(currentPerson1.getAge() != person1.getAge()); - - Person person2 = (Person)getSession().get("Personaje", id_pers2); - Car car2 = getAuditReader().find(Car.class, id_car2, 2); - Person person2_1 = car2.getOwner(); - assert(person2.getAge() == person2_1.getAge()); + assert (currentPerson1.getAge() != person1.getAge()); + + Person person2 = (Person) getSession().get( "Personaje", id_pers2 ); + Car car2 = getAuditReader().find( Car.class, id_car2, 2 ); + Person person2_1 = car2.getOwner(); + assert (person2.getAge() == person2_1.getAge()); } - + private void checkEntityNames() { - String currentCar1EN = getSession().getEntityName(currentCar1); - - String currentPerson1EN = getSession().getEntityName(currentPerson1); - - String car1EN = getAuditReader().getEntityName(id_car1, 1, car1); - assert (currentCar1EN.equals(car1EN)); - - String person1EN = getAuditReader().getEntityName(id_pers1, 1, person1); - assert (currentPerson1EN.equals(person1EN)); - } - - @Test - public void testGetAssociationWithEntityName() { - loadDataOnSessionAndAuditReader(); - checkEntities(); - checkEntityNames(); - } + String currentCar1EN = getSession().getEntityName( currentCar1 ); + + String currentPerson1EN = getSession().getEntityName( currentPerson1 ); + + String car1EN = getAuditReader().getEntityName( id_car1, 1, car1 ); + assert (currentCar1EN.equals( car1EN )); + + String person1EN = getAuditReader().getEntityName( id_pers1, 1, person1 ); + assert (currentPerson1EN.equals( person1EN )); + } + + @Test + public void testGetAssociationWithEntityName() { + loadDataOnSessionAndAuditReader(); + checkEntities(); + checkEntityNames(); + } - @Test - public void testGetAssociationWithEntityNameInNewSession() { - //force a new session and AR - forceNewSession(); + @Test + public void testGetAssociationWithEntityNameInNewSession() { + //force a new session and AR + forceNewSession(); - loadDataOnSessionAndAuditReader(); + loadDataOnSessionAndAuditReader(); - checkEntities(); - - checkEntityNames(); - - } + checkEntities(); + + checkEntityNames(); + + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/singleAssociatedAudited/SingleDomainObjectToMultipleTablesTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/singleAssociatedAudited/SingleDomainObjectToMultipleTablesTest.java index e702cca368..2f7f8731a2 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/singleAssociatedAudited/SingleDomainObjectToMultipleTablesTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/singleAssociatedAudited/SingleDomainObjectToMultipleTablesTest.java @@ -4,62 +4,65 @@ import java.io.File; import java.net.URISyntaxException; import java.net.URL; -import org.junit.Assert; -import org.junit.Test; - import org.hibernate.MappingException; import org.hibernate.envers.test.AbstractOneSessionTest; import org.hibernate.envers.test.Priority; + +import org.junit.Assert; +import org.junit.Test; + import org.hibernate.testing.TestForIssue; /** * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public class SingleDomainObjectToMultipleTablesTest extends AbstractOneSessionTest { - private long carId = 0; - private long ownerId = 0; - private long driverId = 0; + private long carId = 0; + private long ownerId = 0; + private long driverId = 0; - protected void initMappings() throws MappingException, URISyntaxException { - URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/entityNames/singleAssociatedAudited/mappings.hbm.xml"); - config.addFile(new File(url.toURI())); - } + protected void initMappings() throws MappingException, URISyntaxException { + URL url = Thread.currentThread().getContextClassLoader().getResource( + "mappings/entityNames/singleAssociatedAudited/mappings.hbm.xml" + ); + config.addFile( new File( url.toURI() ) ); + } - @Test - @Priority(10) - public void initData() { - initializeSession(); + @Test + @Priority(10) + public void initData() { + initializeSession(); - //REV 1 - getSession().getTransaction().begin(); - Person owner = new Person("Lukasz", 25); - Person driver = new Person("Kinga", 24); - Car car = new Car(1, owner, driver); - getSession().persist("Personaje", owner); - getSession().persist("Driveraje", driver); - getSession().persist(car); - getSession().getTransaction().commit(); - - carId = car.getId(); - ownerId = owner.getId(); - driverId = driver.getId(); - } + //REV 1 + getSession().getTransaction().begin(); + Person owner = new Person( "Lukasz", 25 ); + Person driver = new Person( "Kinga", 24 ); + Car car = new Car( 1, owner, driver ); + getSession().persist( "Personaje", owner ); + getSession().persist( "Driveraje", driver ); + getSession().persist( car ); + getSession().getTransaction().commit(); - @Test - @TestForIssue(jiraKey="HHH-4648") - public void testSingleDomainObjectToMultipleTablesMapping() { - Car carVer1 = getAuditReader().find(Car.class, carId, 1); - Person ownerVer1 = getAuditReader().find(Person.class, "Personaje", ownerId, 1); - Person driverVer1 = getAuditReader().find(Person.class, "Driveraje", driverId, 1); + carId = car.getId(); + ownerId = owner.getId(); + driverId = driver.getId(); + } + + @Test + @TestForIssue(jiraKey = "HHH-4648") + public void testSingleDomainObjectToMultipleTablesMapping() { + Car carVer1 = getAuditReader().find( Car.class, carId, 1 ); + Person ownerVer1 = getAuditReader().find( Person.class, "Personaje", ownerId, 1 ); + Person driverVer1 = getAuditReader().find( Person.class, "Driveraje", driverId, 1 ); /* Check ids. */ - Assert.assertEquals(ownerVer1.getId(), carVer1.getOwner().getId()); - Assert.assertEquals(driverVer1.getId(), carVer1.getDriver().getId()); + Assert.assertEquals( ownerVer1.getId(), carVer1.getOwner().getId() ); + Assert.assertEquals( driverVer1.getId(), carVer1.getDriver().getId() ); /* Check object properties. */ - Assert.assertEquals("Lukasz", ownerVer1.getName()); - Assert.assertEquals("Kinga", driverVer1.getName()); - Assert.assertEquals(1, carVer1.getNumber()); - } + Assert.assertEquals( "Lukasz", ownerVer1.getName() ); + Assert.assertEquals( "Kinga", driverVer1.getName() ); + Assert.assertEquals( 1, carVer1.getNumber() ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/singleAssociatedNotAudited/Car.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/singleAssociatedNotAudited/Car.java index 92d35dc096..da4f1e1953 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/singleAssociatedNotAudited/Car.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/singleAssociatedNotAudited/Car.java @@ -1,29 +1,30 @@ package org.hibernate.envers.test.integration.entityNames.singleAssociatedNotAudited; + import org.hibernate.envers.Audited; import org.hibernate.envers.RelationTargetAuditMode; /** * @author Hernán Chanfreau - * */ public class Car { - + private long id; - + private int number; - + private Person owner; - - public Car() { } + + public Car() { + } public Car(int number, Person owner) { this.number = number; this.owner = owner; } - + public long getId() { return id; } @@ -32,14 +33,14 @@ public class Car { this.id = id; } - @Audited(targetAuditMode=RelationTargetAuditMode.NOT_AUDITED) + @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED) public Person getOwner() { return owner; } public void setOwner(Person owner) { this.owner = owner; - } + } @Audited public int getNumber() { @@ -51,5 +52,4 @@ public class Car { } - } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/singleAssociatedNotAudited/Person.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/singleAssociatedNotAudited/Person.java index 14d79ff0d1..9a9b327053 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/singleAssociatedNotAudited/Person.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/singleAssociatedNotAudited/Person.java @@ -3,24 +3,24 @@ package org.hibernate.envers.test.integration.entityNames.singleAssociatedNotAud /** * @author Hernán Chanfreau - * */ public class Person { - + private long id; - + private String name; - + private int age; - - public Person(){ } - - public Person(String name, int age){ + + public Person() { + } + + public Person(String name, int age) { this.name = name; this.age = age; } - + public long getId() { return id; diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/singleAssociatedNotAudited/ReadEntityAssociatedNotAuditedTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/singleAssociatedNotAudited/ReadEntityAssociatedNotAuditedTest.java index 4b8625f7b4..3fcb36bb83 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/singleAssociatedNotAudited/ReadEntityAssociatedNotAuditedTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/entityNames/singleAssociatedNotAudited/ReadEntityAssociatedNotAuditedTest.java @@ -4,120 +4,121 @@ import java.io.File; import java.net.URISyntaxException; import java.net.URL; -import org.junit.Test; - import org.hibernate.MappingException; import org.hibernate.envers.test.AbstractOneSessionTest; import org.hibernate.envers.test.Priority; +import org.junit.Test; + /** * @author Hernán Chanfreau - * */ public class ReadEntityAssociatedNotAuditedTest extends AbstractOneSessionTest { private long id_car1; private long id_car2; - - private long id_pers1; - private long id_pers2; - + + private long id_pers1; + private long id_pers2; + private Car car1; private Car car2; private Person person1_1; private Person person2; private Person currentPerson1; private Car currentCar1; - - + + protected void initMappings() throws MappingException, URISyntaxException { - URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/entityNames/singleAssociatedNotAudited/mappings.hbm.xml"); - config.addFile(new File(url.toURI())); + URL url = Thread.currentThread().getContextClassLoader().getResource( + "mappings/entityNames/singleAssociatedNotAudited/mappings.hbm.xml" + ); + config.addFile( new File( url.toURI() ) ); } - @Test - @Priority(10) - public void initData() { - - initializeSession(); + @Test + @Priority(10) + public void initData() { - Person pers1 = new Person("Hernan", 15); - Person pers2 = new Person("Leandro", 19); - - Car car1 = new Car(1, pers1); - Car car2 = new Car(2, pers2); - - //REV 1 - getSession().getTransaction().begin(); - getSession().persist("Personaje",pers1); - getSession().persist(car1); - getSession().getTransaction().commit(); - id_car1 = car1.getId(); - id_pers1 = pers1.getId(); + initializeSession(); - //REV 2 - getSession().getTransaction().begin(); - pers1.setAge(50); - getSession().persist("Personaje", pers1); - getSession().persist("Personaje", pers2); - getSession().persist(car2); - getSession().getTransaction().commit(); - id_car2 = car2.getId(); - id_pers2 = pers2.getId(); + Person pers1 = new Person( "Hernan", 15 ); + Person pers2 = new Person( "Leandro", 19 ); - } - - private void loadDataOnSessionAndAuditReader() { - currentPerson1 = (Person)getSession().get("Personaje", id_pers1); - person2 = (Person)getSession().get("Personaje", id_pers2); - - currentCar1 = (Car)getSession().get(Car.class, id_car1); - - car1 = getAuditReader().find(Car.class, id_car1, 1); - car2 = getAuditReader().find(Car.class, id_car2, 2); - - } - - private void checkEntityNames() { - - String currentCar1EN = getSession().getEntityName(currentCar1); - - String car1EN = getAuditReader().getEntityName(id_car1, 1, car1); - - assert (currentCar1EN.equals(car1EN)); - - } - - private void checkEntities() { + Car car1 = new Car( 1, pers1 ); + Car car2 = new Car( 2, pers2 ); - person1_1 = car1.getOwner(); - Person person2_1 = car2.getOwner(); - - assert(currentPerson1.getAge() == person1_1.getAge()); - assert(person2.getAge() == person2_1.getAge()); - } - - @Test - public void testObtainEntityNameAssociationWithEntityNameAndNotAuditedMode() { - loadDataOnSessionAndAuditReader(); - - checkEntities(); - - checkEntityNames(); - } - + //REV 1 + getSession().getTransaction().begin(); + getSession().persist( "Personaje", pers1 ); + getSession().persist( car1 ); + getSession().getTransaction().commit(); + id_car1 = car1.getId(); + id_pers1 = pers1.getId(); - @Test - public void testObtainEntityNameAssociationWithEntityNameAndNotAuditedModeInNewSession() { - //force a new session and AR - forceNewSession(); - - loadDataOnSessionAndAuditReader(); - - checkEntities(); - - checkEntityNames(); + //REV 2 + getSession().getTransaction().begin(); + pers1.setAge( 50 ); + getSession().persist( "Personaje", pers1 ); + getSession().persist( "Personaje", pers2 ); + getSession().persist( car2 ); + getSession().getTransaction().commit(); + id_car2 = car2.getId(); + id_pers2 = pers2.getId(); - } + } + + private void loadDataOnSessionAndAuditReader() { + currentPerson1 = (Person) getSession().get( "Personaje", id_pers1 ); + person2 = (Person) getSession().get( "Personaje", id_pers2 ); + + currentCar1 = (Car) getSession().get( Car.class, id_car1 ); + + car1 = getAuditReader().find( Car.class, id_car1, 1 ); + car2 = getAuditReader().find( Car.class, id_car2, 2 ); + + } + + private void checkEntityNames() { + + String currentCar1EN = getSession().getEntityName( currentCar1 ); + + String car1EN = getAuditReader().getEntityName( id_car1, 1, car1 ); + + assert (currentCar1EN.equals( car1EN )); + + } + + private void checkEntities() { + + person1_1 = car1.getOwner(); + Person person2_1 = car2.getOwner(); + + assert (currentPerson1.getAge() == person1_1.getAge()); + assert (person2.getAge() == person2_1.getAge()); + } + + @Test + public void testObtainEntityNameAssociationWithEntityNameAndNotAuditedMode() { + loadDataOnSessionAndAuditReader(); + + checkEntities(); + + checkEntityNames(); + } + + + @Test + public void testObtainEntityNameAssociationWithEntityNameAndNotAuditedModeInNewSession() { + //force a new session and AR + forceNewSession(); + + loadDataOnSessionAndAuditReader(); + + checkEntities(); + + checkEntityNames(); + + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/flush/AbstractFlushTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/flush/AbstractFlushTest.java index 0defbb2ce2..c5319000dd 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/flush/AbstractFlushTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/flush/AbstractFlushTest.java @@ -23,45 +23,46 @@ */ package org.hibernate.envers.test.integration.flush; -import java.io.IOException; import javax.persistence.EntityManager; - -import org.junit.Before; +import java.io.IOException; import org.hibernate.FlushMode; import org.hibernate.Session; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.entities.StrTestEntity; +import org.junit.Before; + /** * @author Adam Warski (adam at warski dot org) */ public abstract class AbstractFlushTest extends BaseEnversJPAFunctionalTestCase { - public abstract FlushMode getFlushMode(); + public abstract FlushMode getFlushMode(); @Override protected Class[] getAnnotatedClasses() { - return new Class[] { StrTestEntity.class }; + return new Class[] {StrTestEntity.class}; } - private static Session getSession(EntityManager em) { - Object delegate = em.getDelegate(); - if (delegate instanceof Session) { - return (Session) delegate; - } else if (delegate instanceof EntityManager) { - Object delegate2 = ((EntityManager) delegate).getDelegate(); + private static Session getSession(EntityManager em) { + Object delegate = em.getDelegate(); + if ( delegate instanceof Session ) { + return (Session) delegate; + } + else if ( delegate instanceof EntityManager ) { + Object delegate2 = ((EntityManager) delegate).getDelegate(); - if (delegate2 instanceof Session) { - return (Session) delegate2; - } - } + if ( delegate2 instanceof Session ) { + return (Session) delegate2; + } + } - throw new RuntimeException("Invalid entity manager"); - } + throw new RuntimeException( "Invalid entity manager" ); + } - @Before - public void initFlush() throws IOException { - Session session = getSession(getEntityManager()); - session.setFlushMode(getFlushMode()); - } + @Before + public void initFlush() throws IOException { + Session session = getSession( getEntityManager() ); + session.setFlushMode( getFlushMode() ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/flush/DoubleFlushAddDel.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/flush/DoubleFlushAddDel.java index 37d2bdb387..347f096692 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/flush/DoubleFlushAddDel.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/flush/DoubleFlushAddDel.java @@ -23,55 +23,55 @@ */ package org.hibernate.envers.test.integration.flush; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.FlushMode; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrTestEntity; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class DoubleFlushAddDel extends AbstractFlushTest { - private Integer id; + private Integer id; - public FlushMode getFlushMode() { - return FlushMode.MANUAL; - } + public FlushMode getFlushMode() { + return FlushMode.MANUAL; + } - @Test - @Priority(10) - public void initData() { - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); + @Test + @Priority(10) + public void initData() { + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); - StrTestEntity fe = new StrTestEntity("x"); - em.persist(fe); + StrTestEntity fe = new StrTestEntity( "x" ); + em.persist( fe ); - em.flush(); + em.flush(); - em.remove(em.find(StrTestEntity.class, fe.getId())); + em.remove( em.find( StrTestEntity.class, fe.getId() ) ); - em.flush(); + em.flush(); - em.getTransaction().commit(); + em.getTransaction().commit(); - // + // - id = fe.getId(); - } + id = fe.getId(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList().equals(getAuditReader().getRevisions(StrTestEntity.class, id)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList().equals( getAuditReader().getRevisions( StrTestEntity.class, id ) ); + } - @Test - public void testHistoryOfId() { - assert getAuditReader().find(StrTestEntity.class, id, 1) == null; - } + @Test + public void testHistoryOfId() { + assert getAuditReader().find( StrTestEntity.class, id, 1 ) == null; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/flush/DoubleFlushAddMod.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/flush/DoubleFlushAddMod.java index b2c2a13880..cf19d1f6e1 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/flush/DoubleFlushAddMod.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/flush/DoubleFlushAddMod.java @@ -23,11 +23,9 @@ */ package org.hibernate.envers.test.integration.flush; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.List; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.FlushMode; import org.hibernate.envers.RevisionType; @@ -35,74 +33,76 @@ import org.hibernate.envers.query.AuditEntity; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrTestEntity; +import org.junit.Test; + import static org.junit.Assert.assertEquals; /** * @author Adam Warski (adam at warski dot org) */ public class DoubleFlushAddMod extends AbstractFlushTest { - private Integer id; + private Integer id; - public FlushMode getFlushMode() { - return FlushMode.MANUAL; - } + public FlushMode getFlushMode() { + return FlushMode.MANUAL; + } - @Test - @Priority(10) - public void initData() { - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); + @Test + @Priority(10) + public void initData() { + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); - StrTestEntity fe = new StrTestEntity("x"); - em.persist(fe); + StrTestEntity fe = new StrTestEntity( "x" ); + em.persist( fe ); - em.flush(); + em.flush(); - fe.setStr("y"); + fe.setStr( "y" ); - em.flush(); + em.flush(); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); + // Revision 2 + em.getTransaction().begin(); - fe = em.find(StrTestEntity.class, fe.getId()); + fe = em.find( StrTestEntity.class, fe.getId() ); - fe.setStr("z"); - em.flush(); + fe.setStr( "z" ); + em.flush(); - em.getTransaction().commit(); + em.getTransaction().commit(); - // + // - id = fe.getId(); - } + id = fe.getId(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(StrTestEntity.class, id)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( StrTestEntity.class, id ) ); + } - @Test - public void testHistoryOfId() { - StrTestEntity ver1 = new StrTestEntity("y", id); - StrTestEntity ver2 = new StrTestEntity("z", id); + @Test + public void testHistoryOfId() { + StrTestEntity ver1 = new StrTestEntity( "y", id ); + StrTestEntity ver2 = new StrTestEntity( "z", id ); - assert getAuditReader().find(StrTestEntity.class, id, 1).equals(ver1); - assert getAuditReader().find(StrTestEntity.class, id, 2).equals(ver2); - } + assert getAuditReader().find( StrTestEntity.class, id, 1 ).equals( ver1 ); + assert getAuditReader().find( StrTestEntity.class, id, 2 ).equals( ver2 ); + } - @Test - public void testRevisionTypes() { - @SuppressWarnings({"unchecked"}) List results = - getAuditReader().createQuery() - .forRevisionsOfEntity(StrTestEntity.class, false, true) - .add(AuditEntity.id().eq(id)) - .getResultList(); - - assertEquals(results.get(0)[2], RevisionType.ADD); - assertEquals(results.get(1)[2], RevisionType.MOD); - } + @Test + public void testRevisionTypes() { + @SuppressWarnings({"unchecked"}) List results = + getAuditReader().createQuery() + .forRevisionsOfEntity( StrTestEntity.class, false, true ) + .add( AuditEntity.id().eq( id ) ) + .getResultList(); + + assertEquals( results.get( 0 )[2], RevisionType.ADD ); + assertEquals( results.get( 1 )[2], RevisionType.MOD ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/flush/DoubleFlushModDel.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/flush/DoubleFlushModDel.java index 2142c01338..26007d0530 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/flush/DoubleFlushModDel.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/flush/DoubleFlushModDel.java @@ -23,11 +23,9 @@ */ package org.hibernate.envers.test.integration.flush; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.List; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.FlushMode; import org.hibernate.envers.RevisionType; @@ -35,71 +33,73 @@ import org.hibernate.envers.query.AuditEntity; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrTestEntity; +import org.junit.Test; + import static org.junit.Assert.assertEquals; /** * @author Adam Warski (adam at warski dot org) */ public class DoubleFlushModDel extends AbstractFlushTest { - private Integer id; + private Integer id; - public FlushMode getFlushMode() { - return FlushMode.MANUAL; - } + public FlushMode getFlushMode() { + return FlushMode.MANUAL; + } - @Test - @Priority(10) - public void initData() { - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); + @Test + @Priority(10) + public void initData() { + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); - StrTestEntity fe = new StrTestEntity("x"); - em.persist(fe); - em.flush(); + StrTestEntity fe = new StrTestEntity( "x" ); + em.persist( fe ); + em.flush(); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); + // Revision 2 + em.getTransaction().begin(); - fe = em.find(StrTestEntity.class, fe.getId()); + fe = em.find( StrTestEntity.class, fe.getId() ); - fe.setStr("y"); - em.flush(); + fe.setStr( "y" ); + em.flush(); - em.remove(em.find(StrTestEntity.class, fe.getId())); - em.flush(); + em.remove( em.find( StrTestEntity.class, fe.getId() ) ); + em.flush(); - em.getTransaction().commit(); + em.getTransaction().commit(); - // + // - id = fe.getId(); - } + id = fe.getId(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(StrTestEntity.class, id)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( StrTestEntity.class, id ) ); + } - @Test - public void testHistoryOfId() { - StrTestEntity ver1 = new StrTestEntity("x", id); + @Test + public void testHistoryOfId() { + StrTestEntity ver1 = new StrTestEntity( "x", id ); - assert getAuditReader().find(StrTestEntity.class, id, 1).equals(ver1); - assert getAuditReader().find(StrTestEntity.class, id, 2) == null; - } + assert getAuditReader().find( StrTestEntity.class, id, 1 ).equals( ver1 ); + assert getAuditReader().find( StrTestEntity.class, id, 2 ) == null; + } - @Test - public void testRevisionTypes() { - @SuppressWarnings({"unchecked"}) List results = - getAuditReader().createQuery() - .forRevisionsOfEntity(StrTestEntity.class, false, true) - .add(AuditEntity.id().eq(id)) - .getResultList(); + @Test + public void testRevisionTypes() { + @SuppressWarnings({"unchecked"}) List results = + getAuditReader().createQuery() + .forRevisionsOfEntity( StrTestEntity.class, false, true ) + .add( AuditEntity.id().eq( id ) ) + .getResultList(); - assertEquals(results.get(0)[2], RevisionType.ADD); - assertEquals(results.get(1)[2], RevisionType.DEL); - } + assertEquals( results.get( 0 )[2], RevisionType.ADD ); + assertEquals( results.get( 1 )[2], RevisionType.DEL ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/flush/DoubleFlushModMod.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/flush/DoubleFlushModMod.java index 4d4f5f531b..e01f4e0dbd 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/flush/DoubleFlushModMod.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/flush/DoubleFlushModMod.java @@ -23,11 +23,9 @@ */ package org.hibernate.envers.test.integration.flush; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.List; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.FlushMode; import org.hibernate.envers.RevisionType; @@ -35,72 +33,74 @@ import org.hibernate.envers.query.AuditEntity; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrTestEntity; +import org.junit.Test; + import static org.junit.Assert.assertEquals; /** * @author Adam Warski (adam at warski dot org) */ public class DoubleFlushModMod extends AbstractFlushTest { - private Integer id; + private Integer id; - public FlushMode getFlushMode() { - return FlushMode.MANUAL; - } + public FlushMode getFlushMode() { + return FlushMode.MANUAL; + } - @Test - @Priority(10) - public void initData() { - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); + @Test + @Priority(10) + public void initData() { + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); - StrTestEntity fe = new StrTestEntity("x"); - em.persist(fe); - em.flush(); + StrTestEntity fe = new StrTestEntity( "x" ); + em.persist( fe ); + em.flush(); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); + // Revision 2 + em.getTransaction().begin(); - fe = em.find(StrTestEntity.class, fe.getId()); + fe = em.find( StrTestEntity.class, fe.getId() ); - fe.setStr("y"); - em.flush(); + fe.setStr( "y" ); + em.flush(); - fe.setStr("z"); - em.flush(); + fe.setStr( "z" ); + em.flush(); - em.getTransaction().commit(); + em.getTransaction().commit(); - // + // - id = fe.getId(); - } + id = fe.getId(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(StrTestEntity.class, id)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( StrTestEntity.class, id ) ); + } - @Test - public void testHistoryOfId() { - StrTestEntity ver1 = new StrTestEntity("x", id); - StrTestEntity ver2 = new StrTestEntity("z", id); + @Test + public void testHistoryOfId() { + StrTestEntity ver1 = new StrTestEntity( "x", id ); + StrTestEntity ver2 = new StrTestEntity( "z", id ); - assert getAuditReader().find(StrTestEntity.class, id, 1).equals(ver1); - assert getAuditReader().find(StrTestEntity.class, id, 2).equals(ver2); - } + assert getAuditReader().find( StrTestEntity.class, id, 1 ).equals( ver1 ); + assert getAuditReader().find( StrTestEntity.class, id, 2 ).equals( ver2 ); + } - @Test - public void testRevisionTypes() { - @SuppressWarnings({"unchecked"}) List results = - getAuditReader().createQuery() - .forRevisionsOfEntity(StrTestEntity.class, false, true) - .add(AuditEntity.id().eq(id)) - .getResultList(); + @Test + public void testRevisionTypes() { + @SuppressWarnings({"unchecked"}) List results = + getAuditReader().createQuery() + .forRevisionsOfEntity( StrTestEntity.class, false, true ) + .add( AuditEntity.id().eq( id ) ) + .getResultList(); - assertEquals(results.get(0)[2], RevisionType.ADD); - assertEquals(results.get(1)[2], RevisionType.MOD); - } + assertEquals( results.get( 0 )[2], RevisionType.ADD ); + assertEquals( results.get( 1 )[2], RevisionType.MOD ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/flush/ManualFlush.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/flush/ManualFlush.java index 47ed0022d4..15c7d547b6 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/flush/ManualFlush.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/flush/ManualFlush.java @@ -23,11 +23,9 @@ */ package org.hibernate.envers.test.integration.flush; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.List; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.FlushMode; import org.hibernate.envers.RevisionType; @@ -35,84 +33,86 @@ import org.hibernate.envers.query.AuditEntity; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrTestEntity; +import org.junit.Test; + import static org.junit.Assert.assertEquals; /** * @author Adam Warski (adam at warski dot org) */ public class ManualFlush extends AbstractFlushTest { - private Integer id; + private Integer id; - public FlushMode getFlushMode() { - return FlushMode.MANUAL; - } + public FlushMode getFlushMode() { + return FlushMode.MANUAL; + } - @Test - @Priority(10) - public void initData() { - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); + @Test + @Priority(10) + public void initData() { + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); - StrTestEntity fe = new StrTestEntity("x"); - em.persist(fe); - em.flush(); + StrTestEntity fe = new StrTestEntity( "x" ); + em.persist( fe ); + em.flush(); - em.getTransaction().commit(); + em.getTransaction().commit(); - // No revision - we change the data, but do not flush the session - em.getTransaction().begin(); + // No revision - we change the data, but do not flush the session + em.getTransaction().begin(); - fe = em.find(StrTestEntity.class, fe.getId()); - fe.setStr("y"); + fe = em.find( StrTestEntity.class, fe.getId() ); + fe.setStr( "y" ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - only the first change should be saved - em.getTransaction().begin(); + // Revision 2 - only the first change should be saved + em.getTransaction().begin(); - fe = em.find(StrTestEntity.class, fe.getId()); - fe.setStr("z"); - em.flush(); + fe = em.find( StrTestEntity.class, fe.getId() ); + fe.setStr( "z" ); + em.flush(); - fe = em.find(StrTestEntity.class, fe.getId()); - fe.setStr("z2"); + fe = em.find( StrTestEntity.class, fe.getId() ); + fe.setStr( "z2" ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // + // - id = fe.getId(); - } + id = fe.getId(); + } - @Test - public void testRevisionsCounts() { - assertEquals(Arrays.asList(1, 2), getAuditReader().getRevisions(StrTestEntity.class, id)); - } + @Test + public void testRevisionsCounts() { + assertEquals( Arrays.asList( 1, 2 ), getAuditReader().getRevisions( StrTestEntity.class, id ) ); + } - @Test - public void testHistoryOfId() { - StrTestEntity ver1 = new StrTestEntity("x", id); - StrTestEntity ver2 = new StrTestEntity("z", id); + @Test + public void testHistoryOfId() { + StrTestEntity ver1 = new StrTestEntity( "x", id ); + StrTestEntity ver2 = new StrTestEntity( "z", id ); - assertEquals(ver1, getAuditReader().find(StrTestEntity.class, id, 1)); - assertEquals(ver2, getAuditReader().find(StrTestEntity.class, id, 2)); - } + assertEquals( ver1, getAuditReader().find( StrTestEntity.class, id, 1 ) ); + assertEquals( ver2, getAuditReader().find( StrTestEntity.class, id, 2 ) ); + } - @Test - public void testCurrent() { - assertEquals(new StrTestEntity("z", id), getEntityManager().find(StrTestEntity.class, id)); - } + @Test + public void testCurrent() { + assertEquals( new StrTestEntity( "z", id ), getEntityManager().find( StrTestEntity.class, id ) ); + } - @Test - public void testRevisionTypes() { - @SuppressWarnings({"unchecked"}) List results = - getAuditReader().createQuery() - .forRevisionsOfEntity(StrTestEntity.class, false, true) - .add(AuditEntity.id().eq(id)) - .getResultList(); + @Test + public void testRevisionTypes() { + @SuppressWarnings({"unchecked"}) List results = + getAuditReader().createQuery() + .forRevisionsOfEntity( StrTestEntity.class, false, true ) + .add( AuditEntity.id().eq( id ) ) + .getResultList(); - assertEquals(results.get(0)[2], RevisionType.ADD); - assertEquals(results.get(1)[2], RevisionType.MOD); - } + assertEquals( results.get( 0 )[2], RevisionType.ADD ); + assertEquals( results.get( 1 )[2], RevisionType.MOD ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/flush/ManualFlushAutoCommitDisabled.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/flush/ManualFlushAutoCommitDisabled.java index d6f94a5fdf..ee6f2f9030 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/flush/ManualFlushAutoCommitDisabled.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/flush/ManualFlushAutoCommitDisabled.java @@ -9,9 +9,9 @@ import org.hibernate.testing.TestForIssue; */ @TestForIssue(jiraKey = "HHH-7017") public class ManualFlushAutoCommitDisabled extends ManualFlush { - @Override - protected void addConfigOptions(Map options) { - super.addConfigOptions(options); - options.put("hibernate.connection.autocommit", "false"); - } + @Override + protected void addConfigOptions(Map options) { + super.addConfigOptions( options ); + options.put( "hibernate.connection.autocommit", "false" ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/hashcode/ChangingHashcode.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/hashcode/ChangingHashcode.java index 5fad79b7fa..a4b26d6236 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/hashcode/ChangingHashcode.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/hashcode/ChangingHashcode.java @@ -23,15 +23,15 @@ */ package org.hibernate.envers.test.integration.hashcode; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.tools.TestTools; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ @@ -41,63 +41,75 @@ public class ChangingHashcode extends BaseEnversJPAFunctionalTestCase { @Override protected Class[] getAnnotatedClasses() { - return new Class[] { WikiPage.class, WikiImage.class }; - } + return new Class[] {WikiPage.class, WikiImage.class}; + } - @Test - @Priority(10) - public void initData() { - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); + @Test + @Priority(10) + public void initData() { + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); - WikiPage page = new WikiPage("title", "content"); - em.persist(page); + WikiPage page = new WikiPage( "title", "content" ); + em.persist( page ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em = getEntityManager(); - em.getTransaction().begin(); + // Revision 2 + em = getEntityManager(); + em.getTransaction().begin(); - WikiImage image = new WikiImage("name1"); - em.persist(image); + WikiImage image = new WikiImage( "name1" ); + em.persist( image ); - page = em.find(WikiPage.class, page.getId()); - page.getImages().add(image); + page = em.find( WikiPage.class, page.getId() ); + page.getImages().add( image ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 - em = getEntityManager(); - em.getTransaction().begin(); + // Revision 3 + em = getEntityManager(); + em.getTransaction().begin(); - image = em.find(WikiImage.class, image.getId()); - image.setName("name2"); + image = em.find( WikiImage.class, image.getId() ); + image.setName( "name2" ); - em.getTransaction().commit(); + em.getTransaction().commit(); pageId = page.getId(); imageId = image.getId(); - } + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(WikiPage.class, pageId)); - assert Arrays.asList(2, 3).equals(getAuditReader().getRevisions(WikiImage.class, imageId)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( WikiPage.class, pageId ) ); + assert Arrays.asList( 2, 3 ).equals( getAuditReader().getRevisions( WikiImage.class, imageId ) ); + } - @Test - public void testHistoryOfImage() { - assert getAuditReader().find(WikiImage.class, imageId, 1) == null; - assert getAuditReader().find(WikiImage.class, imageId, 2).equals(new WikiImage("name1")); - assert getAuditReader().find(WikiImage.class, imageId, 3).equals(new WikiImage("name2")); - } + @Test + public void testHistoryOfImage() { + assert getAuditReader().find( WikiImage.class, imageId, 1 ) == null; + assert getAuditReader().find( WikiImage.class, imageId, 2 ).equals( new WikiImage( "name1" ) ); + assert getAuditReader().find( WikiImage.class, imageId, 3 ).equals( new WikiImage( "name2" ) ); + } - @Test - public void testHistoryOfPage() { - assert getAuditReader().find(WikiPage.class, pageId, 1).getImages().size() == 0; - assert getAuditReader().find(WikiPage.class, pageId, 2).getImages().equals(TestTools.makeSet(new WikiImage("name1"))); - assert getAuditReader().find(WikiPage.class, pageId, 3).getImages().equals(TestTools.makeSet(new WikiImage("name2"))); - } + @Test + public void testHistoryOfPage() { + assert getAuditReader().find( WikiPage.class, pageId, 1 ).getImages().size() == 0; + assert getAuditReader().find( WikiPage.class, pageId, 2 ).getImages().equals( + TestTools.makeSet( + new WikiImage( + "name1" + ) + ) + ); + assert getAuditReader().find( WikiPage.class, pageId, 3 ).getImages().equals( + TestTools.makeSet( + new WikiImage( + "name2" + ) + ) + ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/hashcode/WikiImage.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/hashcode/WikiImage.java index 02cda00fb7..6a9903bad3 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/hashcode/WikiImage.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/hashcode/WikiImage.java @@ -1,4 +1,5 @@ package org.hibernate.envers.test.integration.hashcode; + import javax.persistence.Basic; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -40,12 +41,18 @@ public class WikiImage { @Override public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof WikiImage)) return false; + if ( this == o ) { + return true; + } + if ( !(o instanceof WikiImage) ) { + return false; + } WikiImage wikiImage = (WikiImage) o; - if (name != null ? !name.equals(wikiImage.name) : wikiImage.name != null) return false; + if ( name != null ? !name.equals( wikiImage.name ) : wikiImage.name != null ) { + return false; + } return true; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/hashcode/WikiPage.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/hashcode/WikiPage.java index 454632e75a..ad152b9f8c 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/hashcode/WikiPage.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/hashcode/WikiPage.java @@ -1,12 +1,13 @@ package org.hibernate.envers.test.integration.hashcode; -import java.util.HashSet; -import java.util.Set; + import javax.persistence.Basic; import javax.persistence.ElementCollection; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.OneToMany; +import java.util.HashSet; +import java.util.Set; import org.hibernate.envers.Audited; @@ -78,13 +79,21 @@ public class WikiPage { @Override public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof WikiPage)) return false; + if ( this == o ) { + return true; + } + if ( !(o instanceof WikiPage) ) { + return false; + } WikiPage wikiPage = (WikiPage) o; - if (content != null ? !content.equals(wikiPage.content) : wikiPage.content != null) return false; - if (title != null ? !title.equals(wikiPage.title) : wikiPage.title != null) return false; + if ( content != null ? !content.equals( wikiPage.content ) : wikiPage.content != null ) { + return false; + } + if ( title != null ? !title.equals( wikiPage.title ) : wikiPage.title != null ) { + return false; + } return true; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/CompositeDateId.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/CompositeDateId.java index 48f6449471..0f3d28d965 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/CompositeDateId.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/CompositeDateId.java @@ -23,64 +23,64 @@ */ package org.hibernate.envers.test.integration.ids; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.Date; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.ids.CompositeDateIdTestEntity; import org.hibernate.envers.test.entities.ids.DateEmbId; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class CompositeDateId extends BaseEnversJPAFunctionalTestCase { - private DateEmbId id1; + private DateEmbId id1; - @Override - protected Class[] getAnnotatedClasses() { - return new Class[]{CompositeDateIdTestEntity.class}; - } + @Override + protected Class[] getAnnotatedClasses() { + return new Class[] {CompositeDateIdTestEntity.class}; + } - @Test - @Priority(10) - public void initData() { + @Test + @Priority(10) + public void initData() { - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); - CompositeDateIdTestEntity dite = new CompositeDateIdTestEntity(new DateEmbId(new Date(), new Date()), "x"); - em.persist(dite); + CompositeDateIdTestEntity dite = new CompositeDateIdTestEntity( new DateEmbId( new Date(), new Date() ), "x" ); + em.persist( dite ); - id1 = dite.getId(); + id1 = dite.getId(); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em = getEntityManager(); - em.getTransaction().begin(); + // Revision 2 + em = getEntityManager(); + em.getTransaction().begin(); - dite = em.find(CompositeDateIdTestEntity.class, id1); - dite.setStr1("y"); + dite = em.find( CompositeDateIdTestEntity.class, id1 ); + dite.setStr1( "y" ); - em.getTransaction().commit(); - } + em.getTransaction().commit(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(CompositeDateIdTestEntity.class, id1)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( CompositeDateIdTestEntity.class, id1 ) ); + } - @Test - public void testHistoryOfId1() { - CompositeDateIdTestEntity ver1 = new CompositeDateIdTestEntity(id1, "x"); - CompositeDateIdTestEntity ver2 = new CompositeDateIdTestEntity(id1, "y"); + @Test + public void testHistoryOfId1() { + CompositeDateIdTestEntity ver1 = new CompositeDateIdTestEntity( id1, "x" ); + CompositeDateIdTestEntity ver2 = new CompositeDateIdTestEntity( id1, "y" ); - assert getAuditReader().find(CompositeDateIdTestEntity.class, id1, 1).getStr1().equals("x"); - assert getAuditReader().find(CompositeDateIdTestEntity.class, id1, 2).getStr1().equals("y"); - } + assert getAuditReader().find( CompositeDateIdTestEntity.class, id1, 1 ).getStr1().equals( "x" ); + assert getAuditReader().find( CompositeDateIdTestEntity.class, id1, 2 ).getStr1().equals( "y" ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/CompositeIds.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/CompositeIds.java index 66d7758906..fdedd4a2c0 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/CompositeIds.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/CompositeIds.java @@ -23,10 +23,8 @@ */ package org.hibernate.envers.test.integration.ids; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; @@ -38,188 +36,200 @@ import org.hibernate.envers.test.entities.ids.EmbIdWithCustomTypeTestEntity; import org.hibernate.envers.test.entities.ids.MulId; import org.hibernate.envers.test.entities.ids.MulIdTestEntity; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class CompositeIds extends BaseEnversJPAFunctionalTestCase { - private EmbId id1; - private EmbId id2; - private MulId id3; - private MulId id4; - private EmbIdWithCustomType id5; - private EmbIdWithCustomType id6; + private EmbId id1; + private EmbId id2; + private MulId id3; + private MulId id4; + private EmbIdWithCustomType id5; + private EmbIdWithCustomType id6; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { EmbIdTestEntity.class, MulIdTestEntity.class, EmbIdWithCustomTypeTestEntity.class }; - } + return new Class[] {EmbIdTestEntity.class, MulIdTestEntity.class, EmbIdWithCustomTypeTestEntity.class}; + } - @Test - @Priority(10) - public void initData() { - id1 = new EmbId(1, 2); - id2 = new EmbId(10, 20); - id3 = new MulId(100, 101); - id4 = new MulId(102, 103); - id5 = new EmbIdWithCustomType(25, CustomEnum.NO); - id6 = new EmbIdWithCustomType(27, CustomEnum.YES); + @Test + @Priority(10) + public void initData() { + id1 = new EmbId( 1, 2 ); + id2 = new EmbId( 10, 20 ); + id3 = new MulId( 100, 101 ); + id4 = new MulId( 102, 103 ); + id5 = new EmbIdWithCustomType( 25, CustomEnum.NO ); + id6 = new EmbIdWithCustomType( 27, CustomEnum.YES ); - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); - em.persist(new EmbIdTestEntity(id1, "x")); - em.persist(new MulIdTestEntity(id3.getId1(), id3.getId2(), "a")); - em.persist(new EmbIdWithCustomTypeTestEntity(id5, "c")); + em.persist( new EmbIdTestEntity( id1, "x" ) ); + em.persist( new MulIdTestEntity( id3.getId1(), id3.getId2(), "a" ) ); + em.persist( new EmbIdWithCustomTypeTestEntity( id5, "c" ) ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em = getEntityManager(); - em.getTransaction().begin(); + // Revision 2 + em = getEntityManager(); + em.getTransaction().begin(); - em.persist(new EmbIdTestEntity(id2, "y")); - em.persist(new MulIdTestEntity(id4.getId1(), id4.getId2(), "b")); - em.persist(new EmbIdWithCustomTypeTestEntity(id6, "d")); + em.persist( new EmbIdTestEntity( id2, "y" ) ); + em.persist( new MulIdTestEntity( id4.getId1(), id4.getId2(), "b" ) ); + em.persist( new EmbIdWithCustomTypeTestEntity( id6, "d" ) ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 - em = getEntityManager(); - em.getTransaction().begin(); + // Revision 3 + em = getEntityManager(); + em.getTransaction().begin(); - EmbIdTestEntity ete1 = em.find(EmbIdTestEntity.class, id1); - EmbIdTestEntity ete2 = em.find(EmbIdTestEntity.class, id2); - MulIdTestEntity mte3 = em.find(MulIdTestEntity.class, id3); - MulIdTestEntity mte4 = em.find(MulIdTestEntity.class, id4); - EmbIdWithCustomTypeTestEntity cte5 = em.find(EmbIdWithCustomTypeTestEntity.class, id5); - EmbIdWithCustomTypeTestEntity cte6 = em.find(EmbIdWithCustomTypeTestEntity.class, id6); + EmbIdTestEntity ete1 = em.find( EmbIdTestEntity.class, id1 ); + EmbIdTestEntity ete2 = em.find( EmbIdTestEntity.class, id2 ); + MulIdTestEntity mte3 = em.find( MulIdTestEntity.class, id3 ); + MulIdTestEntity mte4 = em.find( MulIdTestEntity.class, id4 ); + EmbIdWithCustomTypeTestEntity cte5 = em.find( EmbIdWithCustomTypeTestEntity.class, id5 ); + EmbIdWithCustomTypeTestEntity cte6 = em.find( EmbIdWithCustomTypeTestEntity.class, id6 ); - ete1.setStr1("x2"); - ete2.setStr1("y2"); - mte3.setStr1("a2"); - mte4.setStr1("b2"); - cte5.setStr1("c2"); - cte6.setStr1("d2"); + ete1.setStr1( "x2" ); + ete2.setStr1( "y2" ); + mte3.setStr1( "a2" ); + mte4.setStr1( "b2" ); + cte5.setStr1( "c2" ); + cte6.setStr1( "d2" ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 4 - em = getEntityManager(); - em.getTransaction().begin(); + // Revision 4 + em = getEntityManager(); + em.getTransaction().begin(); - ete1 = em.find(EmbIdTestEntity.class, id1); - ete2 = em.find(EmbIdTestEntity.class, id2); - mte3 = em.find(MulIdTestEntity.class, id3); - cte5 = em.find(EmbIdWithCustomTypeTestEntity.class, id5); - cte6 = em.find(EmbIdWithCustomTypeTestEntity.class, id6); + ete1 = em.find( EmbIdTestEntity.class, id1 ); + ete2 = em.find( EmbIdTestEntity.class, id2 ); + mte3 = em.find( MulIdTestEntity.class, id3 ); + cte5 = em.find( EmbIdWithCustomTypeTestEntity.class, id5 ); + cte6 = em.find( EmbIdWithCustomTypeTestEntity.class, id6 ); - em.remove(ete1); - em.remove(mte3); - em.remove(cte6); + em.remove( ete1 ); + em.remove( mte3 ); + em.remove( cte6 ); - ete2.setStr1("y3"); - cte5.setStr1("c3"); + ete2.setStr1( "y3" ); + cte5.setStr1( "c3" ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 5 - em = getEntityManager(); - em.getTransaction().begin(); + // Revision 5 + em = getEntityManager(); + em.getTransaction().begin(); - ete2 = em.find(EmbIdTestEntity.class, id2); + ete2 = em.find( EmbIdTestEntity.class, id2 ); - em.remove(ete2); + em.remove( ete2 ); - em.getTransaction().commit(); - } + em.getTransaction().commit(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 3, 4).equals(getAuditReader().getRevisions(EmbIdTestEntity.class, id1)); + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 3, 4 ).equals( getAuditReader().getRevisions( EmbIdTestEntity.class, id1 ) ); - assert Arrays.asList(2, 3, 4, 5).equals(getAuditReader().getRevisions(EmbIdTestEntity.class, id2)); + assert Arrays.asList( 2, 3, 4, 5 ).equals( getAuditReader().getRevisions( EmbIdTestEntity.class, id2 ) ); - assert Arrays.asList(1, 3, 4).equals(getAuditReader().getRevisions(MulIdTestEntity.class, id3)); + assert Arrays.asList( 1, 3, 4 ).equals( getAuditReader().getRevisions( MulIdTestEntity.class, id3 ) ); - assert Arrays.asList(2, 3).equals(getAuditReader().getRevisions(MulIdTestEntity.class, id4)); + assert Arrays.asList( 2, 3 ).equals( getAuditReader().getRevisions( MulIdTestEntity.class, id4 ) ); - assert Arrays.asList(1, 3, 4).equals(getAuditReader().getRevisions(EmbIdWithCustomTypeTestEntity.class, id5)); + assert Arrays.asList( 1, 3, 4 ).equals( + getAuditReader().getRevisions( + EmbIdWithCustomTypeTestEntity.class, + id5 + ) + ); - assert Arrays.asList(2, 3, 4).equals(getAuditReader().getRevisions(EmbIdWithCustomTypeTestEntity.class, id6)); - } + assert Arrays.asList( 2, 3, 4 ).equals( + getAuditReader().getRevisions( + EmbIdWithCustomTypeTestEntity.class, + id6 + ) + ); + } - @Test - public void testHistoryOfId1() { - EmbIdTestEntity ver1 = new EmbIdTestEntity(id1, "x"); - EmbIdTestEntity ver2 = new EmbIdTestEntity(id1, "x2"); + @Test + public void testHistoryOfId1() { + EmbIdTestEntity ver1 = new EmbIdTestEntity( id1, "x" ); + EmbIdTestEntity ver2 = new EmbIdTestEntity( id1, "x2" ); - assert getAuditReader().find(EmbIdTestEntity.class, id1, 1).equals(ver1); - assert getAuditReader().find(EmbIdTestEntity.class, id1, 2).equals(ver1); - assert getAuditReader().find(EmbIdTestEntity.class, id1, 3).equals(ver2); - assert getAuditReader().find(EmbIdTestEntity.class, id1, 4) == null; - assert getAuditReader().find(EmbIdTestEntity.class, id1, 5) == null; - } + assert getAuditReader().find( EmbIdTestEntity.class, id1, 1 ).equals( ver1 ); + assert getAuditReader().find( EmbIdTestEntity.class, id1, 2 ).equals( ver1 ); + assert getAuditReader().find( EmbIdTestEntity.class, id1, 3 ).equals( ver2 ); + assert getAuditReader().find( EmbIdTestEntity.class, id1, 4 ) == null; + assert getAuditReader().find( EmbIdTestEntity.class, id1, 5 ) == null; + } - @Test - public void testHistoryOfId2() { - EmbIdTestEntity ver1 = new EmbIdTestEntity(id2, "y"); - EmbIdTestEntity ver2 = new EmbIdTestEntity(id2, "y2"); - EmbIdTestEntity ver3 = new EmbIdTestEntity(id2, "y3"); + @Test + public void testHistoryOfId2() { + EmbIdTestEntity ver1 = new EmbIdTestEntity( id2, "y" ); + EmbIdTestEntity ver2 = new EmbIdTestEntity( id2, "y2" ); + EmbIdTestEntity ver3 = new EmbIdTestEntity( id2, "y3" ); - assert getAuditReader().find(EmbIdTestEntity.class, id2, 1) == null; - assert getAuditReader().find(EmbIdTestEntity.class, id2, 2).equals(ver1); - assert getAuditReader().find(EmbIdTestEntity.class, id2, 3).equals(ver2); - assert getAuditReader().find(EmbIdTestEntity.class, id2, 4).equals(ver3); - assert getAuditReader().find(EmbIdTestEntity.class, id2, 5) == null; - } + assert getAuditReader().find( EmbIdTestEntity.class, id2, 1 ) == null; + assert getAuditReader().find( EmbIdTestEntity.class, id2, 2 ).equals( ver1 ); + assert getAuditReader().find( EmbIdTestEntity.class, id2, 3 ).equals( ver2 ); + assert getAuditReader().find( EmbIdTestEntity.class, id2, 4 ).equals( ver3 ); + assert getAuditReader().find( EmbIdTestEntity.class, id2, 5 ) == null; + } - @Test - public void testHistoryOfId3() { - MulIdTestEntity ver1 = new MulIdTestEntity(id3.getId1(), id3.getId2(), "a"); - MulIdTestEntity ver2 = new MulIdTestEntity(id3.getId1(), id3.getId2(), "a2"); + @Test + public void testHistoryOfId3() { + MulIdTestEntity ver1 = new MulIdTestEntity( id3.getId1(), id3.getId2(), "a" ); + MulIdTestEntity ver2 = new MulIdTestEntity( id3.getId1(), id3.getId2(), "a2" ); - assert getAuditReader().find(MulIdTestEntity.class, id3, 1).equals(ver1); - assert getAuditReader().find(MulIdTestEntity.class, id3, 2).equals(ver1); - assert getAuditReader().find(MulIdTestEntity.class, id3, 3).equals(ver2); - assert getAuditReader().find(MulIdTestEntity.class, id3, 4) == null; - assert getAuditReader().find(MulIdTestEntity.class, id3, 5) == null; - } + assert getAuditReader().find( MulIdTestEntity.class, id3, 1 ).equals( ver1 ); + assert getAuditReader().find( MulIdTestEntity.class, id3, 2 ).equals( ver1 ); + assert getAuditReader().find( MulIdTestEntity.class, id3, 3 ).equals( ver2 ); + assert getAuditReader().find( MulIdTestEntity.class, id3, 4 ) == null; + assert getAuditReader().find( MulIdTestEntity.class, id3, 5 ) == null; + } - @Test - public void testHistoryOfId4() { - MulIdTestEntity ver1 = new MulIdTestEntity(id4.getId1(), id4.getId2(), "b"); - MulIdTestEntity ver2 = new MulIdTestEntity(id4.getId1(), id4.getId2(), "b2"); + @Test + public void testHistoryOfId4() { + MulIdTestEntity ver1 = new MulIdTestEntity( id4.getId1(), id4.getId2(), "b" ); + MulIdTestEntity ver2 = new MulIdTestEntity( id4.getId1(), id4.getId2(), "b2" ); - assert getAuditReader().find(MulIdTestEntity.class, id4, 1) == null; - assert getAuditReader().find(MulIdTestEntity.class, id4, 2).equals(ver1); - assert getAuditReader().find(MulIdTestEntity.class, id4, 3).equals(ver2); - assert getAuditReader().find(MulIdTestEntity.class, id4, 4).equals(ver2); - assert getAuditReader().find(MulIdTestEntity.class, id4, 5).equals(ver2); - } + assert getAuditReader().find( MulIdTestEntity.class, id4, 1 ) == null; + assert getAuditReader().find( MulIdTestEntity.class, id4, 2 ).equals( ver1 ); + assert getAuditReader().find( MulIdTestEntity.class, id4, 3 ).equals( ver2 ); + assert getAuditReader().find( MulIdTestEntity.class, id4, 4 ).equals( ver2 ); + assert getAuditReader().find( MulIdTestEntity.class, id4, 5 ).equals( ver2 ); + } - @Test - public void testHistoryOfId5() { - EmbIdWithCustomTypeTestEntity ver1 = new EmbIdWithCustomTypeTestEntity(id5, "c"); - EmbIdWithCustomTypeTestEntity ver2 = new EmbIdWithCustomTypeTestEntity(id5, "c2"); - EmbIdWithCustomTypeTestEntity ver3 = new EmbIdWithCustomTypeTestEntity(id5, "c3"); + @Test + public void testHistoryOfId5() { + EmbIdWithCustomTypeTestEntity ver1 = new EmbIdWithCustomTypeTestEntity( id5, "c" ); + EmbIdWithCustomTypeTestEntity ver2 = new EmbIdWithCustomTypeTestEntity( id5, "c2" ); + EmbIdWithCustomTypeTestEntity ver3 = new EmbIdWithCustomTypeTestEntity( id5, "c3" ); - assert getAuditReader().find(EmbIdWithCustomTypeTestEntity.class, id5, 1).equals(ver1); - assert getAuditReader().find(EmbIdWithCustomTypeTestEntity.class, id5, 2).equals(ver1); - assert getAuditReader().find(EmbIdWithCustomTypeTestEntity.class, id5, 3).equals(ver2); - assert getAuditReader().find(EmbIdWithCustomTypeTestEntity.class, id5, 4).equals(ver3); - assert getAuditReader().find(EmbIdWithCustomTypeTestEntity.class, id5, 5).equals(ver3); - } + assert getAuditReader().find( EmbIdWithCustomTypeTestEntity.class, id5, 1 ).equals( ver1 ); + assert getAuditReader().find( EmbIdWithCustomTypeTestEntity.class, id5, 2 ).equals( ver1 ); + assert getAuditReader().find( EmbIdWithCustomTypeTestEntity.class, id5, 3 ).equals( ver2 ); + assert getAuditReader().find( EmbIdWithCustomTypeTestEntity.class, id5, 4 ).equals( ver3 ); + assert getAuditReader().find( EmbIdWithCustomTypeTestEntity.class, id5, 5 ).equals( ver3 ); + } - @Test - public void testHistoryOfId6() { - EmbIdWithCustomTypeTestEntity ver1 = new EmbIdWithCustomTypeTestEntity(id6, "d"); - EmbIdWithCustomTypeTestEntity ver2 = new EmbIdWithCustomTypeTestEntity(id6, "d2"); + @Test + public void testHistoryOfId6() { + EmbIdWithCustomTypeTestEntity ver1 = new EmbIdWithCustomTypeTestEntity( id6, "d" ); + EmbIdWithCustomTypeTestEntity ver2 = new EmbIdWithCustomTypeTestEntity( id6, "d2" ); - assert getAuditReader().find(EmbIdWithCustomTypeTestEntity.class, id6, 1) == null; - assert getAuditReader().find(EmbIdWithCustomTypeTestEntity.class, id6, 2).equals(ver1); - assert getAuditReader().find(EmbIdWithCustomTypeTestEntity.class, id6, 3).equals(ver2); - assert getAuditReader().find(EmbIdWithCustomTypeTestEntity.class, id6, 4) == null; - assert getAuditReader().find(EmbIdWithCustomTypeTestEntity.class, id6, 5) == null; - } + assert getAuditReader().find( EmbIdWithCustomTypeTestEntity.class, id6, 1 ) == null; + assert getAuditReader().find( EmbIdWithCustomTypeTestEntity.class, id6, 2 ).equals( ver1 ); + assert getAuditReader().find( EmbIdWithCustomTypeTestEntity.class, id6, 3 ).equals( ver2 ); + assert getAuditReader().find( EmbIdWithCustomTypeTestEntity.class, id6, 4 ) == null; + assert getAuditReader().find( EmbIdWithCustomTypeTestEntity.class, id6, 5 ) == null; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/DateId.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/DateId.java index 229a16f790..3eb24a6e25 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/DateId.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/DateId.java @@ -23,63 +23,63 @@ */ package org.hibernate.envers.test.integration.ids; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.Date; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.ids.DateIdTestEntity; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class DateId extends BaseEnversJPAFunctionalTestCase { - private Date id1; + private Date id1; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { DateIdTestEntity.class }; - } + return new Class[] {DateIdTestEntity.class}; + } - @Test - @Priority(10) - public void initData() { + @Test + @Priority(10) + public void initData() { - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); - DateIdTestEntity dite = new DateIdTestEntity(new Date(), "x"); - em.persist(dite); + DateIdTestEntity dite = new DateIdTestEntity( new Date(), "x" ); + em.persist( dite ); - id1 = dite.getId(); + id1 = dite.getId(); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em = getEntityManager(); - em.getTransaction().begin(); + // Revision 2 + em = getEntityManager(); + em.getTransaction().begin(); - dite = em.find(DateIdTestEntity.class, id1); - dite.setStr1("y"); + dite = em.find( DateIdTestEntity.class, id1 ); + dite.setStr1( "y" ); - em.getTransaction().commit(); - } + em.getTransaction().commit(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(DateIdTestEntity.class, id1)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( DateIdTestEntity.class, id1 ) ); + } - @Test - public void testHistoryOfId1() { - DateIdTestEntity ver1 = new DateIdTestEntity(id1, "x"); - DateIdTestEntity ver2 = new DateIdTestEntity(id1, "y"); + @Test + public void testHistoryOfId1() { + DateIdTestEntity ver1 = new DateIdTestEntity( id1, "x" ); + DateIdTestEntity ver2 = new DateIdTestEntity( id1, "y" ); - assert getAuditReader().find(DateIdTestEntity.class, id1, 1).getStr1().equals("x"); - assert getAuditReader().find(DateIdTestEntity.class, id1, 2).getStr1().equals("y"); - } + assert getAuditReader().find( DateIdTestEntity.class, id1, 1 ).getStr1().equals( "x" ); + assert getAuditReader().find( DateIdTestEntity.class, id1, 2 ).getStr1().equals( "y" ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/ManyToOneIdNotAudited.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/ManyToOneIdNotAudited.java index bbb5d8359a..9fb2e9b125 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/ManyToOneIdNotAudited.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/ManyToOneIdNotAudited.java @@ -2,8 +2,6 @@ package org.hibernate.envers.test.integration.ids; import javax.persistence.EntityManager; -import org.junit.Test; - import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrTestEntity; @@ -11,43 +9,46 @@ import org.hibernate.envers.test.entities.UnversionedStrTestEntity; import org.hibernate.envers.test.entities.ids.ManyToOneIdNotAuditedTestEntity; import org.hibernate.envers.test.entities.ids.ManyToOneNotAuditedEmbId; +import org.junit.Test; + /** * A test checking that when using Envers it is possible to have non-audited entities that use unsupported * components in their ids, e.g. a many-to-one join to another entity. + * * @author Adam Warski (adam at warski dot org) */ public class ManyToOneIdNotAudited extends BaseEnversJPAFunctionalTestCase { - private ManyToOneNotAuditedEmbId id1; + private ManyToOneNotAuditedEmbId id1; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { ManyToOneIdNotAuditedTestEntity.class, UnversionedStrTestEntity.class, StrTestEntity.class }; - } + return new Class[] {ManyToOneIdNotAuditedTestEntity.class, UnversionedStrTestEntity.class, StrTestEntity.class}; + } - @Test - @Priority(10) - public void initData() { - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); + @Test + @Priority(10) + public void initData() { + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); - UnversionedStrTestEntity uste = new UnversionedStrTestEntity(); - uste.setStr("test1"); - em.persist(uste); + UnversionedStrTestEntity uste = new UnversionedStrTestEntity(); + uste.setStr( "test1" ); + em.persist( uste ); - id1 = new ManyToOneNotAuditedEmbId(uste); + id1 = new ManyToOneNotAuditedEmbId( uste ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em = getEntityManager(); - em.getTransaction().begin(); + // Revision 2 + em = getEntityManager(); + em.getTransaction().begin(); - ManyToOneIdNotAuditedTestEntity mtoinate = new ManyToOneIdNotAuditedTestEntity(); - mtoinate.setData("data1"); - mtoinate.setId(id1); - em.persist(mtoinate); + ManyToOneIdNotAuditedTestEntity mtoinate = new ManyToOneIdNotAuditedTestEntity(); + mtoinate.setData( "data1" ); + mtoinate.setId( id1 ); + em.persist( mtoinate ); - em.getTransaction().commit(); - } + em.getTransaction().commit(); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/embeddedid/Item.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/embeddedid/Item.java index b95b70d5ea..5050b1bbab 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/embeddedid/Item.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/embeddedid/Item.java @@ -1,8 +1,8 @@ package org.hibernate.envers.test.integration.ids.embeddedid; -import java.io.Serializable; import javax.persistence.EmbeddedId; import javax.persistence.Entity; +import java.io.Serializable; import org.hibernate.envers.Audited; @@ -12,57 +12,65 @@ import org.hibernate.envers.Audited; @Entity @Audited public class Item implements Serializable { - @EmbeddedId - private ItemId id; + @EmbeddedId + private ItemId id; - private Double price; + private Double price; - public Item() { - } + public Item() { + } - public Item(ItemId id, Double price) { - this.id = id; - this.price = price; - } + public Item(ItemId id, Double price) { + this.id = id; + this.price = price; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof Item)) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof Item) ) { + return false; + } - Item item = (Item) o; + Item item = (Item) o; - if (getId() != null ? !getId().equals(item.getId()) : item.getId() != null) return false; - if (getPrice() != null ? !getPrice().equals(item.getPrice()) : item.getPrice() != null) return false; + if ( getId() != null ? !getId().equals( item.getId() ) : item.getId() != null ) { + return false; + } + if ( getPrice() != null ? !getPrice().equals( item.getPrice() ) : item.getPrice() != null ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - int result = id != null ? id.hashCode() : 0; - result = 31 * result + (price != null ? price.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = id != null ? id.hashCode() : 0; + result = 31 * result + (price != null ? price.hashCode() : 0); + return result; + } - @Override - public String toString() { - return "Item(id = " + id + ", price = + " + price + ")"; - } + @Override + public String toString() { + return "Item(id = " + id + ", price = + " + price + ")"; + } - public ItemId getId() { - return id; - } + public ItemId getId() { + return id; + } - public void setId(ItemId id) { - this.id = id; - } + public void setId(ItemId id) { + this.id = id; + } - public Double getPrice() { - return price; - } + public Double getPrice() { + return price; + } - public void setPrice(Double price) { - this.price = price; - } + public void setPrice(Double price) { + this.price = price; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/embeddedid/ItemId.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/embeddedid/ItemId.java index 1afa11765a..bbd2fc4739 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/embeddedid/ItemId.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/embeddedid/ItemId.java @@ -1,83 +1,93 @@ package org.hibernate.envers.test.integration.ids.embeddedid; -import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Embeddable; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; +import java.io.Serializable; /** * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ @Embeddable public class ItemId implements Serializable { - @Column(name = "model") - private String model; + @Column(name = "model") + private String model; - @Column(name = "version") - private Integer version; + @Column(name = "version") + private Integer version; - @ManyToOne - @JoinColumn(name = "producer", nullable = false) // NOT NULL for Sybase - private Producer producer; + @ManyToOne + @JoinColumn(name = "producer", nullable = false) // NOT NULL for Sybase + private Producer producer; - public ItemId() { - } + public ItemId() { + } - public ItemId(String model, Integer version, Producer producer) { - this.model = model; - this.version = version; - this.producer = producer; - } + public ItemId(String model, Integer version, Producer producer) { + this.model = model; + this.version = version; + this.producer = producer; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ItemId)) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ItemId) ) { + return false; + } - ItemId itemId = (ItemId) o; + ItemId itemId = (ItemId) o; - if (getModel() != null ? !getModel().equals(itemId.getModel()) : itemId.getModel() != null) return false; - if (getProducer() != null ? !getProducer().equals(itemId.getProducer()) : itemId.getProducer() != null) return false; - if (getVersion() != null ? !getVersion().equals(itemId.getVersion()) : itemId.getVersion() != null) return false; + if ( getModel() != null ? !getModel().equals( itemId.getModel() ) : itemId.getModel() != null ) { + return false; + } + if ( getProducer() != null ? !getProducer().equals( itemId.getProducer() ) : itemId.getProducer() != null ) { + return false; + } + if ( getVersion() != null ? !getVersion().equals( itemId.getVersion() ) : itemId.getVersion() != null ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - int result = model != null ? model.hashCode() : 0; - result = 31 * result + (version != null ? version.hashCode() : 0); - result = 31 * result + (producer != null ? producer.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = model != null ? model.hashCode() : 0; + result = 31 * result + (version != null ? version.hashCode() : 0); + result = 31 * result + (producer != null ? producer.hashCode() : 0); + return result; + } - @Override - public String toString() { - return "ItemId(model = " + model + ", version = " + version + ", producer = " + producer + ")"; - } + @Override + public String toString() { + return "ItemId(model = " + model + ", version = " + version + ", producer = " + producer + ")"; + } - public String getModel() { - return model; - } + public String getModel() { + return model; + } - public void setModel(String model) { - this.model = model; - } + public void setModel(String model) { + this.model = model; + } - public Integer getVersion() { - return version; - } + public Integer getVersion() { + return version; + } - public void setVersion(Integer version) { - this.version = version; - } + public void setVersion(Integer version) { + this.version = version; + } - public Producer getProducer() { - return producer; - } + public Producer getProducer() { + return producer; + } - public void setProducer(Producer producer) { - this.producer = producer; - } + public void setProducer(Producer producer) { + this.producer = producer; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/embeddedid/Producer.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/embeddedid/Producer.java index 27538a6d0b..ccf94210b0 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/embeddedid/Producer.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/embeddedid/Producer.java @@ -1,9 +1,9 @@ package org.hibernate.envers.test.integration.ids.embeddedid; -import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; +import java.io.Serializable; import org.hibernate.envers.Audited; @@ -13,59 +13,67 @@ import org.hibernate.envers.Audited; @Entity @Audited public class Producer implements Serializable { - @Id - @Column(name = "id") - private Integer id; + @Id + @Column(name = "id") + private Integer id; - @Column(name = "name") - private String name; + @Column(name = "name") + private String name; - public Producer() { - } + public Producer() { + } - public Producer(Integer id, String name) { - this.id = id; - this.name = name; - } + public Producer(Integer id, String name) { + this.id = id; + this.name = name; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof Producer)) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof Producer) ) { + return false; + } - Producer producer = (Producer) o; + Producer producer = (Producer) o; - if (getId() != null ? !getId().equals(producer.getId()) : producer.getId() != null) return false; - if (getName() != null ? !getName().equals(producer.getName()) : producer.getName() != null) return false; + if ( getId() != null ? !getId().equals( producer.getId() ) : producer.getId() != null ) { + return false; + } + if ( getName() != null ? !getName().equals( producer.getName() ) : producer.getName() != null ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - int result = id != null ? id.hashCode() : 0; - result = 31 * result + (name != null ? name.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = id != null ? id.hashCode() : 0; + result = 31 * result + (name != null ? name.hashCode() : 0); + return result; + } - @Override - public String toString() { - return "Producer(id = " + id + ", name = " + name + ")"; - } + @Override + public String toString() { + return "Producer(id = " + id + ", name = " + name + ")"; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getName() { - return name; - } + public String getName() { + return name; + } - public void setName(String name) { - this.name = name; - } + public void setName(String name) { + this.name = name; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/embeddedid/PurchaseOrder.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/embeddedid/PurchaseOrder.java index 892e32da72..1540fe961a 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/embeddedid/PurchaseOrder.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/embeddedid/PurchaseOrder.java @@ -1,6 +1,5 @@ package org.hibernate.envers.test.integration.ids.embeddedid; -import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -8,6 +7,7 @@ import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.JoinColumns; import javax.persistence.ManyToOne; +import java.io.Serializable; import org.hibernate.envers.Audited; @@ -17,82 +17,93 @@ import org.hibernate.envers.Audited; @Entity @Audited public class PurchaseOrder implements Serializable { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - @ManyToOne - @JoinColumns({ - @JoinColumn(name = "model", referencedColumnName = "model", nullable = true), - @JoinColumn(name = "version", referencedColumnName = "version", nullable = true), - @JoinColumn(name = "producer", referencedColumnName = "producer", nullable = true)}) - private Item item; + @ManyToOne + @JoinColumns({ + @JoinColumn(name = "model", referencedColumnName = "model", nullable = true), + @JoinColumn(name = "version", referencedColumnName = "version", nullable = true), + @JoinColumn(name = "producer", referencedColumnName = "producer", nullable = true) + }) + private Item item; - @Column(name = "NOTE") - private String comment; + @Column(name = "NOTE") + private String comment; - public PurchaseOrder() { - } + public PurchaseOrder() { + } - public PurchaseOrder(Item item, String comment) { - this.item = item; - this.comment = comment; - } + public PurchaseOrder(Item item, String comment) { + this.item = item; + this.comment = comment; + } - public PurchaseOrder(Integer id, Item item, String comment) { - this.id = id; - this.item = item; - this.comment = comment; - } + public PurchaseOrder(Integer id, Item item, String comment) { + this.id = id; + this.item = item; + this.comment = comment; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof PurchaseOrder)) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof PurchaseOrder) ) { + return false; + } - PurchaseOrder that = (PurchaseOrder) o; + PurchaseOrder that = (PurchaseOrder) o; - if (getComment() != null ? !getComment().equals(that.getComment()) : that.getComment() != null) return false; - if (getId() != null ? !getId().equals(that.getId()) : that.getId() != null) return false; - if (getItem() != null ? !getItem().equals(that.getItem()) : that.getItem() != null) return false; + if ( getComment() != null ? !getComment().equals( that.getComment() ) : that.getComment() != null ) { + return false; + } + if ( getId() != null ? !getId().equals( that.getId() ) : that.getId() != null ) { + return false; + } + if ( getItem() != null ? !getItem().equals( that.getItem() ) : that.getItem() != null ) { + return false; + } - return true; - } + return true; + } - @Override - public String toString() { - return "PurchaseOrder(id = " + id + ", item = " + item + ", comment = " + comment + ")"; - } + @Override + public String toString() { + return "PurchaseOrder(id = " + id + ", item = " + item + ", comment = " + comment + ")"; + } - @Override - public int hashCode() { - int result = id != null ? id.hashCode() : 0; - result = 31 * result + (item != null ? item.hashCode() : 0); - result = 31 * result + (comment != null ? comment.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = id != null ? id.hashCode() : 0; + result = 31 * result + (item != null ? item.hashCode() : 0); + result = 31 * result + (comment != null ? comment.hashCode() : 0); + return result; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public Item getItem() { - return item; - } + public Item getItem() { + return item; + } - public void setItem(Item item) { - this.item = item; - } + public void setItem(Item item) { + this.item = item; + } - public String getComment() { - return comment; - } + public String getComment() { + return comment; + } - public void setComment(String comment) { - this.comment = comment; - } + public void setComment(String comment) { + this.comment = comment; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/embeddedid/RelationInsideEmbeddableTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/embeddedid/RelationInsideEmbeddableTest.java index 28ee8adacc..cfc6c47c59 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/embeddedid/RelationInsideEmbeddableTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/embeddedid/RelationInsideEmbeddableTest.java @@ -1,13 +1,14 @@ package org.hibernate.envers.test.integration.ids.embeddedid; -import java.util.Arrays; import javax.persistence.EntityManager; +import java.util.Arrays; + +import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; +import org.hibernate.envers.test.Priority; import org.junit.Assert; import org.junit.Test; -import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; -import org.hibernate.envers.test.Priority; import org.hibernate.testing.TestForIssue; /** @@ -15,70 +16,80 @@ import org.hibernate.testing.TestForIssue; */ @TestForIssue(jiraKey = "HHH-7690") public class RelationInsideEmbeddableTest extends BaseEnversJPAFunctionalTestCase { - private Integer orderId = null; - private ItemId itemId = null; + private Integer orderId = null; + private ItemId itemId = null; - @Override - protected Class[] getAnnotatedClasses() { - return new Class[]{PurchaseOrder.class, Item.class, ItemId.class, Producer.class}; - } + @Override + protected Class[] getAnnotatedClasses() { + return new Class[] {PurchaseOrder.class, Item.class, ItemId.class, Producer.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - // Revision 1 - em.getTransaction().begin(); - Producer producer = new Producer(1, "Sony"); - ItemId sonyId = new ItemId("TV", 1, producer); - Item item = new Item(sonyId, 100.50); - PurchaseOrder order = new PurchaseOrder(item, null); - em.persist(producer); - em.persist(item); - em.persist(order); - em.getTransaction().commit(); + // Revision 1 + em.getTransaction().begin(); + Producer producer = new Producer( 1, "Sony" ); + ItemId sonyId = new ItemId( "TV", 1, producer ); + Item item = new Item( sonyId, 100.50 ); + PurchaseOrder order = new PurchaseOrder( item, null ); + em.persist( producer ); + em.persist( item ); + em.persist( order ); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); - order = em.find(PurchaseOrder.class, order.getId()); - order.setComment("fragile"); - order = em.merge(order); - em.getTransaction().commit(); + // Revision 2 + em.getTransaction().begin(); + order = em.find( PurchaseOrder.class, order.getId() ); + order.setComment( "fragile" ); + order = em.merge( order ); + em.getTransaction().commit(); - // Revision 3 - em.getTransaction().begin(); - item = em.find(Item.class, sonyId); - item.setPrice(110.00); - em.getTransaction().commit(); + // Revision 3 + em.getTransaction().begin(); + item = em.find( Item.class, sonyId ); + item.setPrice( 110.00 ); + em.getTransaction().commit(); - orderId = order.getId(); - itemId = sonyId; + orderId = order.getId(); + itemId = sonyId; - em.close(); - } + em.close(); + } - @Test - public void testRevisionsCounts() throws Exception { - Assert.assertEquals(Arrays.asList(1, 2), getAuditReader().getRevisions(PurchaseOrder.class, orderId)); - Assert.assertEquals(Arrays.asList(1, 3), getAuditReader().getRevisions(Item.class, itemId)); - } + @Test + public void testRevisionsCounts() throws Exception { + Assert.assertEquals( Arrays.asList( 1, 2 ), getAuditReader().getRevisions( PurchaseOrder.class, orderId ) ); + Assert.assertEquals( Arrays.asList( 1, 3 ), getAuditReader().getRevisions( Item.class, itemId ) ); + } - @Test - public void testHistoryOfPurchaseOrder() { - PurchaseOrder ver1 = new PurchaseOrder(orderId, new Item(new ItemId("TV", 1, new Producer(1, "Sony")), 100.50), null); - PurchaseOrder ver2 = new PurchaseOrder(orderId, new Item(new ItemId("TV", 1, new Producer(1, "Sony")), 100.50), "fragile"); + @Test + public void testHistoryOfPurchaseOrder() { + PurchaseOrder ver1 = new PurchaseOrder( + orderId, new Item( + new ItemId( "TV", 1, new Producer( 1, "Sony" ) ), + 100.50 + ), null + ); + PurchaseOrder ver2 = new PurchaseOrder( + orderId, new Item( + new ItemId( "TV", 1, new Producer( 1, "Sony" ) ), + 100.50 + ), "fragile" + ); - Assert.assertEquals(ver1, getAuditReader().find(PurchaseOrder.class, orderId, 1)); - Assert.assertEquals(ver2, getAuditReader().find(PurchaseOrder.class, orderId, 2)); - } + Assert.assertEquals( ver1, getAuditReader().find( PurchaseOrder.class, orderId, 1 ) ); + Assert.assertEquals( ver2, getAuditReader().find( PurchaseOrder.class, orderId, 2 ) ); + } - @Test - public void testHistoryOfItem() { - Item ver1 = new Item(itemId, 100.50); - Item ver2 = new Item(itemId, 110.00); + @Test + public void testHistoryOfItem() { + Item ver1 = new Item( itemId, 100.50 ); + Item ver2 = new Item( itemId, 110.00 ); - Assert.assertEquals(ver1, getAuditReader().find(Item.class, itemId, 1)); - Assert.assertEquals(ver2, getAuditReader().find(Item.class, itemId, 3)); - } + Assert.assertEquals( ver1, getAuditReader().find( Item.class, itemId, 1 ) ); + Assert.assertEquals( ver2, getAuditReader().find( Item.class, itemId, 3 ) ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/idclass/ClassType.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/idclass/ClassType.java index f4a75f2ca4..c1dd7574eb 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/idclass/ClassType.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/idclass/ClassType.java @@ -1,9 +1,9 @@ package org.hibernate.envers.test.integration.ids.idclass; -import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; +import java.io.Serializable; import org.hibernate.envers.Audited; @@ -13,55 +13,61 @@ import org.hibernate.envers.Audited; @Audited @Entity public class ClassType implements Serializable { - @Id - @Column(name = "Name") - private String type; + @Id + @Column(name = "Name") + private String type; - private String description; + private String description; - public ClassType() { - } + public ClassType() { + } - public ClassType(String type, String description) { - this.type = type; - this.description = description; - } + public ClassType(String type, String description) { + this.type = type; + this.description = description; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ClassType)) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ClassType) ) { + return false; + } - ClassType classType = (ClassType) o; + ClassType classType = (ClassType) o; - if (type != null ? !type.equals(classType.type) : classType.type != null) return false; + if ( type != null ? !type.equals( classType.type ) : classType.type != null ) { + return false; + } - return true; - } + return true; + } - @Override - public String toString() { - return "ClassType(type = " + type + ", description = " + description + ")"; - } + @Override + public String toString() { + return "ClassType(type = " + type + ", description = " + description + ")"; + } - @Override - public int hashCode() { - return type != null ? type.hashCode() : 0; - } + @Override + public int hashCode() { + return type != null ? type.hashCode() : 0; + } - public String getType() { - return type; - } + public String getType() { + return type; + } - public void setType(String type) { - this.type = type; - } + public void setType(String type) { + this.type = type; + } - public String getDescription() { - return description; - } + public String getDescription() { + return description; + } - public void setDescription(String description) { - this.description = description; - } + public void setDescription(String description) { + this.description = description; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/idclass/IdClassWithRelationTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/idclass/IdClassWithRelationTest.java index e76ab25a00..7395f699a0 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/idclass/IdClassWithRelationTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/idclass/IdClassWithRelationTest.java @@ -1,13 +1,14 @@ package org.hibernate.envers.test.integration.ids.idclass; -import java.util.Arrays; import javax.persistence.EntityManager; - -import junit.framework.Assert; -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; + +import org.junit.Test; +import junit.framework.Assert; + import org.hibernate.testing.TestForIssue; /** @@ -15,103 +16,103 @@ import org.hibernate.testing.TestForIssue; */ @TestForIssue(jiraKey = "HHH-4751") public class IdClassWithRelationTest extends BaseEnversJPAFunctionalTestCase { - private RelationalClassId entityId = null; - private String typeId = null; + private RelationalClassId entityId = null; + private String typeId = null; - @Override - protected Class[] getAnnotatedClasses() { - return new Class[]{SampleClass.class, RelationalClassId.class, ClassType.class}; - } + @Override + protected Class[] getAnnotatedClasses() { + return new Class[] {SampleClass.class, RelationalClassId.class, ClassType.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - // Revision 1 - em.getTransaction().begin(); - ClassType type = new ClassType("type", "initial description"); - SampleClass entity = new SampleClass(); - entity.setType(type); - entity.setSampleValue("initial data"); - em.persist(type); - em.persist(entity); - em.getTransaction().commit(); + // Revision 1 + em.getTransaction().begin(); + ClassType type = new ClassType( "type", "initial description" ); + SampleClass entity = new SampleClass(); + entity.setType( type ); + entity.setSampleValue( "initial data" ); + em.persist( type ); + em.persist( entity ); + em.getTransaction().commit(); - typeId = type.getType(); - entityId = new RelationalClassId(entity.getId(), new ClassType("type", "initial description")); + typeId = type.getType(); + entityId = new RelationalClassId( entity.getId(), new ClassType( "type", "initial description" ) ); - // Revision 2 - em.getTransaction().begin(); - type = em.find(ClassType.class, type.getType()); - type.setDescription("modified description"); - em.merge(type); - em.getTransaction().commit(); + // Revision 2 + em.getTransaction().begin(); + type = em.find( ClassType.class, type.getType() ); + type.setDescription( "modified description" ); + em.merge( type ); + em.getTransaction().commit(); - // Revision 3 - em.getTransaction().begin(); - entity = em.find(SampleClass.class, entityId); - entity.setSampleValue("modified data"); - em.merge(entity); - em.getTransaction().commit(); + // Revision 3 + em.getTransaction().begin(); + entity = em.find( SampleClass.class, entityId ); + entity.setSampleValue( "modified data" ); + em.merge( entity ); + em.getTransaction().commit(); - em.close(); - } + em.close(); + } - @Test - public void testRevisionsCounts() { - Assert.assertEquals(Arrays.asList(1, 2), getAuditReader().getRevisions(ClassType.class, typeId)); - Assert.assertEquals(Arrays.asList(1, 3), getAuditReader().getRevisions(SampleClass.class, entityId)); - } + @Test + public void testRevisionsCounts() { + Assert.assertEquals( Arrays.asList( 1, 2 ), getAuditReader().getRevisions( ClassType.class, typeId ) ); + Assert.assertEquals( Arrays.asList( 1, 3 ), getAuditReader().getRevisions( SampleClass.class, entityId ) ); + } - @Test - public void testHistoryOfEntity() { - // given - SampleClass entity = new SampleClass(entityId.getId(), entityId.getType(), "initial data"); + @Test + public void testHistoryOfEntity() { + // given + SampleClass entity = new SampleClass( entityId.getId(), entityId.getType(), "initial data" ); - // when - SampleClass ver1 = getAuditReader().find(SampleClass.class, entityId, 1); + // when + SampleClass ver1 = getAuditReader().find( SampleClass.class, entityId, 1 ); - // then - Assert.assertEquals(entity.getId(), ver1.getId()); - Assert.assertEquals(entity.getSampleValue(), ver1.getSampleValue()); - Assert.assertEquals(entity.getType().getType(), ver1.getType().getType()); - Assert.assertEquals(entity.getType().getDescription(), ver1.getType().getDescription()); + // then + Assert.assertEquals( entity.getId(), ver1.getId() ); + Assert.assertEquals( entity.getSampleValue(), ver1.getSampleValue() ); + Assert.assertEquals( entity.getType().getType(), ver1.getType().getType() ); + Assert.assertEquals( entity.getType().getDescription(), ver1.getType().getDescription() ); - // given - entity.setSampleValue("modified data"); - entity.getType().setDescription("modified description"); + // given + entity.setSampleValue( "modified data" ); + entity.getType().setDescription( "modified description" ); - // when - SampleClass ver2 = getAuditReader().find(SampleClass.class, entityId, 3); + // when + SampleClass ver2 = getAuditReader().find( SampleClass.class, entityId, 3 ); - // then - Assert.assertEquals(entity.getId(), ver2.getId()); - Assert.assertEquals(entity.getSampleValue(), ver2.getSampleValue()); - Assert.assertEquals(entity.getType().getType(), ver2.getType().getType()); - Assert.assertEquals(entity.getType().getDescription(), ver2.getType().getDescription()); - } + // then + Assert.assertEquals( entity.getId(), ver2.getId() ); + Assert.assertEquals( entity.getSampleValue(), ver2.getSampleValue() ); + Assert.assertEquals( entity.getType().getType(), ver2.getType().getType() ); + Assert.assertEquals( entity.getType().getDescription(), ver2.getType().getDescription() ); + } - @Test - public void testHistoryOfType() { - // given - ClassType type = new ClassType(typeId, "initial description"); + @Test + public void testHistoryOfType() { + // given + ClassType type = new ClassType( typeId, "initial description" ); - // when - ClassType ver1 = getAuditReader().find(ClassType.class, typeId, 1); + // when + ClassType ver1 = getAuditReader().find( ClassType.class, typeId, 1 ); - // then - Assert.assertEquals(type, ver1); - Assert.assertEquals(type.getDescription(), ver1.getDescription()); + // then + Assert.assertEquals( type, ver1 ); + Assert.assertEquals( type.getDescription(), ver1.getDescription() ); - // given - type.setDescription("modified description"); + // given + type.setDescription( "modified description" ); - // when - ClassType ver2 = getAuditReader().find(ClassType.class, typeId, 2); + // when + ClassType ver2 = getAuditReader().find( ClassType.class, typeId, 2 ); - // then - Assert.assertEquals(type, ver2); - Assert.assertEquals(type.getDescription(), ver2.getDescription()); - } + // then + Assert.assertEquals( type, ver2 ); + Assert.assertEquals( type.getDescription(), ver2.getDescription() ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/idclass/RelationalClassId.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/idclass/RelationalClassId.java index a158b9b177..8cf8de32ea 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/idclass/RelationalClassId.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/idclass/RelationalClassId.java @@ -6,55 +6,63 @@ import java.io.Serializable; * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public class RelationalClassId implements Serializable { - private Long id; - private ClassType type; + private Long id; + private ClassType type; - public RelationalClassId() { - } + public RelationalClassId() { + } - public RelationalClassId(Long id, ClassType type) { - this.id = id; - this.type = type; - } + public RelationalClassId(Long id, ClassType type) { + this.id = id; + this.type = type; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof RelationalClassId)) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof RelationalClassId) ) { + return false; + } - RelationalClassId that = (RelationalClassId) o; + RelationalClassId that = (RelationalClassId) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; - if (type != null ? !type.equals(that.type) : that.type != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } + if ( type != null ? !type.equals( that.type ) : that.type != null ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - int result = id != null ? id.hashCode() : 0; - result = 31 * result + (type != null ? type.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = id != null ? id.hashCode() : 0; + result = 31 * result + (type != null ? type.hashCode() : 0); + return result; + } - @Override - public String toString() { - return "RelationalClassId(id = " + id + ", type = " + type + ")"; - } + @Override + public String toString() { + return "RelationalClassId(id = " + id + ", type = " + type + ")"; + } - public Long getId() { - return id; - } + public Long getId() { + return id; + } - public void setId(Long id) { - this.id = id; - } + public void setId(Long id) { + this.id = id; + } - public ClassType getType() { - return type; - } + public ClassType getType() { + return type; + } - public void setType(ClassType type) { - this.type = type; - } + public void setType(ClassType type) { + this.type = type; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/idclass/SampleClass.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/idclass/SampleClass.java index a5dd4df63a..4658e6de02 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/idclass/SampleClass.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/idclass/SampleClass.java @@ -1,6 +1,5 @@ package org.hibernate.envers.test.integration.ids.idclass; -import java.io.Serializable; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; @@ -8,6 +7,7 @@ import javax.persistence.Id; import javax.persistence.IdClass; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; +import java.io.Serializable; import org.hibernate.envers.Audited; @@ -18,79 +18,89 @@ import org.hibernate.envers.Audited; @Entity @IdClass(RelationalClassId.class) public class SampleClass implements Serializable { - @Id - @GeneratedValue - private Long id; + @Id + @GeneratedValue + private Long id; - @Id - @ManyToOne(fetch = FetchType.LAZY, optional = false) - @JoinColumn(name = "ClassTypeName", referencedColumnName = "Name", - insertable = true, updatable = true, nullable = false) - private ClassType type; + @Id + @ManyToOne(fetch = FetchType.LAZY, optional = false) + @JoinColumn(name = "ClassTypeName", referencedColumnName = "Name", + insertable = true, updatable = true, nullable = false) + private ClassType type; - private String sampleValue; + private String sampleValue; - public SampleClass() { - } + public SampleClass() { + } - public SampleClass(ClassType type) { - this.type = type; - } + public SampleClass(ClassType type) { + this.type = type; + } - public SampleClass(Long id, ClassType type) { - this.id = id; - this.type = type; - } + public SampleClass(Long id, ClassType type) { + this.id = id; + this.type = type; + } - public SampleClass(Long id, ClassType type, String sampleValue) { - this.id = id; - this.type = type; - this.sampleValue = sampleValue; - } + public SampleClass(Long id, ClassType type, String sampleValue) { + this.id = id; + this.type = type; + this.sampleValue = sampleValue; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof SampleClass)) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof SampleClass) ) { + return false; + } - SampleClass sampleClass = (SampleClass) o; + SampleClass sampleClass = (SampleClass) o; - if (id != null ? !id.equals(sampleClass.id) : sampleClass.id != null) return false; - if (type != null ? !type.equals(sampleClass.type) : sampleClass.type != null) return false; - if (sampleValue != null ? !sampleValue.equals(sampleClass.sampleValue) : sampleClass.sampleValue != null) return false; + if ( id != null ? !id.equals( sampleClass.id ) : sampleClass.id != null ) { + return false; + } + if ( type != null ? !type.equals( sampleClass.type ) : sampleClass.type != null ) { + return false; + } + if ( sampleValue != null ? !sampleValue.equals( sampleClass.sampleValue ) : sampleClass.sampleValue != null ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - int result = id != null ? id.hashCode() : 0; - result = 31 * result + (type != null ? type.hashCode() : 0); - result = 31 * result + (sampleValue != null ? sampleValue.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = id != null ? id.hashCode() : 0; + result = 31 * result + (type != null ? type.hashCode() : 0); + result = 31 * result + (sampleValue != null ? sampleValue.hashCode() : 0); + return result; + } - public Long getId() { - return id; - } + public Long getId() { + return id; + } - public void setId(Long id) { - this.id = id; - } + public void setId(Long id) { + this.id = id; + } - public ClassType getType() { - return type; - } + public ClassType getType() { + return type; + } - public void setType(ClassType type) { - this.type = type; - } + public void setType(ClassType type) { + this.type = type; + } - public String getSampleValue() { - return sampleValue; - } + public String getSampleValue() { + return sampleValue; + } - public void setSampleValue(String sampleValue) { - this.sampleValue = sampleValue; - } + public void setSampleValue(String sampleValue) { + this.sampleValue = sampleValue; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/protectedmodifier/ProtectedConstructorEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/protectedmodifier/ProtectedConstructorEntity.java index bc05df0635..d1d17f41f4 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/protectedmodifier/ProtectedConstructorEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/protectedmodifier/ProtectedConstructorEntity.java @@ -1,8 +1,8 @@ package org.hibernate.envers.test.integration.ids.protectedmodifier; -import java.io.Serializable; import javax.persistence.EmbeddedId; import javax.persistence.Entity; +import java.io.Serializable; import org.hibernate.envers.Audited; @@ -25,20 +25,30 @@ public class ProtectedConstructorEntity implements Serializable { } public boolean equals(Object o) { - if ( this == o ) return true; - if ( !( o instanceof ProtectedConstructorEntity ) ) return false; + if ( this == o ) { + return true; + } + if ( !(o instanceof ProtectedConstructorEntity) ) { + return false; + } ProtectedConstructorEntity that = (ProtectedConstructorEntity) o; - if ( wrappedStringId != null ? !wrappedStringId.equals( that.wrappedStringId ) : that.wrappedStringId != null ) return false; - if ( str1 != null ? !str1.equals( that.str1 ) : that.str1 != null ) return false; + if ( wrappedStringId != null ? + !wrappedStringId.equals( that.wrappedStringId ) : + that.wrappedStringId != null ) { + return false; + } + if ( str1 != null ? !str1.equals( that.str1 ) : that.str1 != null ) { + return false; + } return true; } public int hashCode() { - int result = ( wrappedStringId != null ? wrappedStringId.hashCode() : 0 ); - result = 31 * result + ( str1 != null ? str1.hashCode() : 0 ); + int result = (wrappedStringId != null ? wrappedStringId.hashCode() : 0); + result = 31 * result + (str1 != null ? str1.hashCode() : 0); return result; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/protectedmodifier/ProtectedConstructorTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/protectedmodifier/ProtectedConstructorTest.java index 7a8f69fe6d..72a5b5baa8 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/protectedmodifier/ProtectedConstructorTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/protectedmodifier/ProtectedConstructorTest.java @@ -1,14 +1,15 @@ package org.hibernate.envers.test.integration.ids.protectedmodifier; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.List; -import javax.persistence.EntityManager; + +import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; +import org.hibernate.envers.test.Priority; import org.junit.Assert; import org.junit.Test; -import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; -import org.hibernate.envers.test.Priority; import org.hibernate.testing.TestForIssue; /** @@ -16,11 +17,15 @@ import org.hibernate.testing.TestForIssue; */ @TestForIssue(jiraKey = "HHH-7934") public class ProtectedConstructorTest extends BaseEnversJPAFunctionalTestCase { - private final ProtectedConstructorEntity testEntity = new ProtectedConstructorEntity( new WrappedStringId( "embeddedStringId" ), "string" ); + private final ProtectedConstructorEntity testEntity = new ProtectedConstructorEntity( + new WrappedStringId( + "embeddedStringId" + ), "string" + ); @Override protected Class[] getAnnotatedClasses() { - return new Class[] { WrappedStringId.class, ProtectedConstructorEntity.class }; + return new Class[] {WrappedStringId.class, ProtectedConstructorEntity.class}; } @Test @@ -36,7 +41,9 @@ public class ProtectedConstructorTest extends BaseEnversJPAFunctionalTestCase { @Test public void testAuditEntityInstantiation() { - List result = getAuditReader().createQuery().forEntitiesAtRevision( ProtectedConstructorEntity.class, 1 ).getResultList(); + List result = getAuditReader().createQuery() + .forEntitiesAtRevision( ProtectedConstructorEntity.class, 1 ) + .getResultList(); Assert.assertEquals( Arrays.asList( testEntity ), result ); } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/protectedmodifier/WrappedStringId.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/protectedmodifier/WrappedStringId.java index 0c06d8b42f..4e2a528ec1 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/protectedmodifier/WrappedStringId.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/ids/protectedmodifier/WrappedStringId.java @@ -1,7 +1,7 @@ package org.hibernate.envers.test.integration.ids.protectedmodifier; -import java.io.Serializable; import javax.persistence.Embeddable; +import java.io.Serializable; @Embeddable public class WrappedStringId implements Serializable { @@ -21,10 +21,14 @@ public class WrappedStringId implements Serializable { } public boolean equals(Object o) { - if ( this == o ) return true; - if ( o == null || getClass() != o.getClass() ) return false; + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } WrappedStringId that = (WrappedStringId) o; - return !( id != null ? !id.equals( that.id ) : that.id != null ); + return !(id != null ? !id.equals( that.id ) : that.id != null); } public int hashCode() { diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/ChildAuditing.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/ChildAuditing.java index 599d9e96b1..839f83d7be 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/ChildAuditing.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/ChildAuditing.java @@ -24,71 +24,71 @@ package org.hibernate.envers.test.integration.inheritance.joined; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class ChildAuditing extends BaseEnversJPAFunctionalTestCase { - private Integer id1; + private Integer id1; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { ChildEntity.class, ParentEntity.class }; - } + return new Class[] {ChildEntity.class, ParentEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - id1 = 1; + id1 = 1; - // Rev 1 - em.getTransaction().begin(); - ChildEntity ce = new ChildEntity(id1, "x", 1l); - em.persist(ce); - em.getTransaction().commit(); + // Rev 1 + em.getTransaction().begin(); + ChildEntity ce = new ChildEntity( id1, "x", 1l ); + em.persist( ce ); + em.getTransaction().commit(); - // Rev 2 - em.getTransaction().begin(); - ce = em.find(ChildEntity.class, id1); - ce.setData("y"); - ce.setNumVal(2l); - em.getTransaction().commit(); - } + // Rev 2 + em.getTransaction().begin(); + ce = em.find( ChildEntity.class, id1 ); + ce.setData( "y" ); + ce.setNumVal( 2l ); + em.getTransaction().commit(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(ChildEntity.class, id1)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( ChildEntity.class, id1 ) ); + } - @Test - public void testHistoryOfChildId1() { - ChildEntity ver1 = new ChildEntity(id1, "x", 1l); - ChildEntity ver2 = new ChildEntity(id1, "y", 2l); + @Test + public void testHistoryOfChildId1() { + ChildEntity ver1 = new ChildEntity( id1, "x", 1l ); + ChildEntity ver2 = new ChildEntity( id1, "y", 2l ); - assert getAuditReader().find(ChildEntity.class, id1, 1).equals(ver1); - assert getAuditReader().find(ChildEntity.class, id1, 2).equals(ver2); + assert getAuditReader().find( ChildEntity.class, id1, 1 ).equals( ver1 ); + assert getAuditReader().find( ChildEntity.class, id1, 2 ).equals( ver2 ); - assert getAuditReader().find(ParentEntity.class, id1, 1).equals(ver1); - assert getAuditReader().find(ParentEntity.class, id1, 2).equals(ver2); - } + assert getAuditReader().find( ParentEntity.class, id1, 1 ).equals( ver1 ); + assert getAuditReader().find( ParentEntity.class, id1, 2 ).equals( ver2 ); + } - @Test - public void testPolymorphicQuery() { - ChildEntity childVer1 = new ChildEntity(id1, "x", 1l); + @Test + public void testPolymorphicQuery() { + ChildEntity childVer1 = new ChildEntity( id1, "x", 1l ); - assert getAuditReader().createQuery().forEntitiesAtRevision(ChildEntity.class, 1).getSingleResult() - .equals(childVer1); + assert getAuditReader().createQuery().forEntitiesAtRevision( ChildEntity.class, 1 ).getSingleResult() + .equals( childVer1 ); - assert getAuditReader().createQuery().forEntitiesAtRevision(ParentEntity.class, 1).getSingleResult() - .equals(childVer1); - } + assert getAuditReader().createQuery().forEntitiesAtRevision( ParentEntity.class, 1 ).getSingleResult() + .equals( childVer1 ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/ChildEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/ChildEntity.java index fc68fa982a..37fe522296 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/ChildEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/ChildEntity.java @@ -23,6 +23,7 @@ */ package org.hibernate.envers.test.integration.inheritance.joined; + import javax.persistence.Basic; import javax.persistence.Entity; @@ -34,44 +35,52 @@ import org.hibernate.envers.Audited; @Entity @Audited public class ChildEntity extends ParentEntity { - @Basic - private Long numVal; + @Basic + private Long numVal; - public ChildEntity() { - } + public ChildEntity() { + } - public ChildEntity(Integer id, String data, Long numVal) { - super(id, data); - this.numVal = numVal; - } + public ChildEntity(Integer id, String data, Long numVal) { + super( id, data ); + this.numVal = numVal; + } - public Long getNumVal() { - return numVal; - } + public Long getNumVal() { + return numVal; + } - public void setNumVal(Long numVal) { - this.numVal = numVal; - } + public void setNumVal(Long numVal) { + this.numVal = numVal; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ChildEntity)) return false; - if (!super.equals(o)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ChildEntity) ) { + return false; + } + if ( !super.equals( o ) ) { + return false; + } - ChildEntity childEntity = (ChildEntity) o; + ChildEntity childEntity = (ChildEntity) o; - if (numVal != null ? !numVal.equals(childEntity.numVal) : childEntity.numVal != null) return false; + if ( numVal != null ? !numVal.equals( childEntity.numVal ) : childEntity.numVal != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result = super.hashCode(); - result = 31 * result + (numVal != null ? numVal.hashCode() : 0); - return result; - } + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (numVal != null ? numVal.hashCode() : 0); + return result; + } - public String toString() { - return "ChildEntity(id = " + getId() + ", data = " + getData() + ", numVal = " + numVal + ")"; - } + public String toString() { + return "ChildEntity(id = " + getId() + ", data = " + getData() + ", numVal = " + numVal + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/ChildNullAuditing.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/ChildNullAuditing.java index 91dd71299e..e1058fdd2d 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/ChildNullAuditing.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/ChildNullAuditing.java @@ -24,71 +24,71 @@ package org.hibernate.envers.test.integration.inheritance.joined; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class ChildNullAuditing extends BaseEnversJPAFunctionalTestCase { - private Integer id1; + private Integer id1; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { ChildEntity.class, ParentEntity.class }; - } + return new Class[] {ChildEntity.class, ParentEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - id1 = 1; + id1 = 1; - // Rev 1 - em.getTransaction().begin(); - ChildEntity ce = new ChildEntity(id1, "x", null); - em.persist(ce); - em.getTransaction().commit(); + // Rev 1 + em.getTransaction().begin(); + ChildEntity ce = new ChildEntity( id1, "x", null ); + em.persist( ce ); + em.getTransaction().commit(); - // Rev 2 - em.getTransaction().begin(); - ce = em.find(ChildEntity.class, id1); - ce.setData(null); - ce.setNumVal(2l); - em.getTransaction().commit(); - } + // Rev 2 + em.getTransaction().begin(); + ce = em.find( ChildEntity.class, id1 ); + ce.setData( null ); + ce.setNumVal( 2l ); + em.getTransaction().commit(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(ChildEntity.class, id1)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( ChildEntity.class, id1 ) ); + } - @Test - public void testHistoryOfChildId1() { - ChildEntity ver1 = new ChildEntity(id1, "x", null); - ChildEntity ver2 = new ChildEntity(id1, null, 2l); + @Test + public void testHistoryOfChildId1() { + ChildEntity ver1 = new ChildEntity( id1, "x", null ); + ChildEntity ver2 = new ChildEntity( id1, null, 2l ); - assert getAuditReader().find(ChildEntity.class, id1, 1).equals(ver1); - assert getAuditReader().find(ChildEntity.class, id1, 2).equals(ver2); + assert getAuditReader().find( ChildEntity.class, id1, 1 ).equals( ver1 ); + assert getAuditReader().find( ChildEntity.class, id1, 2 ).equals( ver2 ); - assert getAuditReader().find(ParentEntity.class, id1, 1).equals(ver1); - assert getAuditReader().find(ParentEntity.class, id1, 2).equals(ver2); - } + assert getAuditReader().find( ParentEntity.class, id1, 1 ).equals( ver1 ); + assert getAuditReader().find( ParentEntity.class, id1, 2 ).equals( ver2 ); + } - @Test - public void testPolymorphicQuery() { - ChildEntity childVer1 = new ChildEntity(id1, "x", null); + @Test + public void testPolymorphicQuery() { + ChildEntity childVer1 = new ChildEntity( id1, "x", null ); - assert getAuditReader().createQuery().forEntitiesAtRevision(ChildEntity.class, 1).getSingleResult() - .equals(childVer1); + assert getAuditReader().createQuery().forEntitiesAtRevision( ChildEntity.class, 1 ).getSingleResult() + .equals( childVer1 ); - assert getAuditReader().createQuery().forEntitiesAtRevision(ParentEntity.class, 1).getSingleResult() - .equals(childVer1); - } + assert getAuditReader().createQuery().forEntitiesAtRevision( ParentEntity.class, 1 ).getSingleResult() + .equals( childVer1 ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/ParentAuditing.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/ParentAuditing.java index 91c91bf0e8..e38d0889e5 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/ParentAuditing.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/ParentAuditing.java @@ -24,72 +24,72 @@ package org.hibernate.envers.test.integration.inheritance.joined; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class ParentAuditing extends BaseEnversJPAFunctionalTestCase { - private Integer id1; + private Integer id1; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { ChildEntity.class, ParentEntity.class }; - } + return new Class[] {ChildEntity.class, ParentEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - id1 = 1; + id1 = 1; - // Rev 1 - em.getTransaction().begin(); - ParentEntity pe = new ParentEntity(id1, "x"); - em.persist(pe); - em.getTransaction().commit(); + // Rev 1 + em.getTransaction().begin(); + ParentEntity pe = new ParentEntity( id1, "x" ); + em.persist( pe ); + em.getTransaction().commit(); - // Rev 2 - em.getTransaction().begin(); - pe = em.find(ParentEntity.class, id1); - pe.setData("y"); - em.getTransaction().commit(); - } + // Rev 2 + em.getTransaction().begin(); + pe = em.find( ParentEntity.class, id1 ); + pe.setData( "y" ); + em.getTransaction().commit(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(ParentEntity.class, id1)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( ParentEntity.class, id1 ) ); + } - @Test - public void testHistoryOfChildId1() { - assert getAuditReader().find(ChildEntity.class, id1, 1) == null; - assert getAuditReader().find(ChildEntity.class, id1, 2) == null; - } + @Test + public void testHistoryOfChildId1() { + assert getAuditReader().find( ChildEntity.class, id1, 1 ) == null; + assert getAuditReader().find( ChildEntity.class, id1, 2 ) == null; + } - @Test - public void testHistoryOfParentId1() { - ParentEntity ver1 = new ParentEntity(id1, "x"); - ParentEntity ver2 = new ParentEntity(id1, "y"); + @Test + public void testHistoryOfParentId1() { + ParentEntity ver1 = new ParentEntity( id1, "x" ); + ParentEntity ver2 = new ParentEntity( id1, "y" ); - assert getAuditReader().find(ParentEntity.class, id1, 1).equals(ver1); - assert getAuditReader().find(ParentEntity.class, id1, 2).equals(ver2); - } + assert getAuditReader().find( ParentEntity.class, id1, 1 ).equals( ver1 ); + assert getAuditReader().find( ParentEntity.class, id1, 2 ).equals( ver2 ); + } - @Test - public void testPolymorphicQuery() { - ParentEntity parentVer1 = new ParentEntity(id1, "x"); + @Test + public void testPolymorphicQuery() { + ParentEntity parentVer1 = new ParentEntity( id1, "x" ); - assert getAuditReader().createQuery().forEntitiesAtRevision(ParentEntity.class, 1).getSingleResult() - .equals(parentVer1); - assert getAuditReader().createQuery().forEntitiesAtRevision(ChildEntity.class, 1) - .getResultList().size() == 0; - } + assert getAuditReader().createQuery().forEntitiesAtRevision( ParentEntity.class, 1 ).getSingleResult() + .equals( parentVer1 ); + assert getAuditReader().createQuery().forEntitiesAtRevision( ChildEntity.class, 1 ) + .getResultList().size() == 0; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/ParentEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/ParentEntity.java index eaa731b5d6..5e95eac3b2 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/ParentEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/ParentEntity.java @@ -23,6 +23,7 @@ */ package org.hibernate.envers.test.integration.inheritance.joined; + import javax.persistence.Basic; import javax.persistence.Entity; import javax.persistence.Id; @@ -38,56 +39,64 @@ import org.hibernate.envers.Audited; @Inheritance(strategy = InheritanceType.JOINED) @Audited public class ParentEntity { - @Id - private Integer id; + @Id + private Integer id; - @Basic - private String data; + @Basic + private String data; - public ParentEntity() { - } + public ParentEntity() { + } - public ParentEntity(Integer id, String data) { - this.id = id; - this.data = data; - } + public ParentEntity(Integer id, String data) { + this.id = id; + this.data = data; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ParentEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ParentEntity) ) { + return false; + } - ParentEntity that = (ParentEntity) o; + ParentEntity that = (ParentEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "ParentEntity(id = " + getId() + ", data = " + getData() + ")"; - } + public String toString() { + return "ParentEntity(id = " + getId() + ", data = " + getData() + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/childrelation/ChildIngEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/childrelation/ChildIngEntity.java index c4b019ecca..0c3a429abb 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/childrelation/ChildIngEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/childrelation/ChildIngEntity.java @@ -23,6 +23,7 @@ */ package org.hibernate.envers.test.integration.inheritance.joined.childrelation; + import javax.persistence.Basic; import javax.persistence.Entity; import javax.persistence.ManyToOne; @@ -35,55 +36,63 @@ import org.hibernate.envers.Audited; @Entity @Audited public class ChildIngEntity extends ParentNotIngEntity { - @Basic - private Long numVal; + @Basic + private Long numVal; - @ManyToOne - private ReferencedEntity referenced; + @ManyToOne + private ReferencedEntity referenced; - public ChildIngEntity() { - } + public ChildIngEntity() { + } - public ChildIngEntity(Integer id, String data, Long numVal) { - super(id, data); - this.numVal = numVal; - } + public ChildIngEntity(Integer id, String data, Long numVal) { + super( id, data ); + this.numVal = numVal; + } - public Long getNumVal() { - return numVal; - } + public Long getNumVal() { + return numVal; + } - public void setNumVal(Long numVal) { - this.numVal = numVal; - } + public void setNumVal(Long numVal) { + this.numVal = numVal; + } - public ReferencedEntity getReferenced() { - return referenced; - } + public ReferencedEntity getReferenced() { + return referenced; + } - public void setReferenced(ReferencedEntity referenced) { - this.referenced = referenced; - } + public void setReferenced(ReferencedEntity referenced) { + this.referenced = referenced; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ChildIngEntity)) return false; - if (!super.equals(o)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ChildIngEntity) ) { + return false; + } + if ( !super.equals( o ) ) { + return false; + } - ChildIngEntity childEntity = (ChildIngEntity) o; + ChildIngEntity childEntity = (ChildIngEntity) o; - if (numVal != null ? !numVal.equals(childEntity.numVal) : childEntity.numVal != null) return false; + if ( numVal != null ? !numVal.equals( childEntity.numVal ) : childEntity.numVal != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result = super.hashCode(); - result = 31 * result + (numVal != null ? numVal.hashCode() : 0); - return result; - } + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (numVal != null ? numVal.hashCode() : 0); + return result; + } - public String toString() { - return "ChildIngEntity(id = " + getId() + ", data = " + getData() + ", numVal = " + numVal + ")"; - } + public String toString() { + return "ChildIngEntity(id = " + getId() + ", data = " + getData() + ", numVal = " + numVal + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/childrelation/ChildReferencing.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/childrelation/ChildReferencing.java index 553370f11f..bf83568fed 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/childrelation/ChildReferencing.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/childrelation/ChildReferencing.java @@ -24,100 +24,104 @@ package org.hibernate.envers.test.integration.inheritance.joined.childrelation; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.tools.TestTools; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class ChildReferencing extends BaseEnversJPAFunctionalTestCase { - private Integer re_id1; - private Integer re_id2; - private Integer c_id; + private Integer re_id1; + private Integer re_id2; + private Integer c_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { ChildIngEntity.class, ParentNotIngEntity.class, ReferencedEntity.class }; - } + return new Class[] {ChildIngEntity.class, ParentNotIngEntity.class, ReferencedEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - re_id1 = 1; - re_id2 = 10; - c_id = 100; + re_id1 = 1; + re_id2 = 10; + c_id = 100; - // Rev 1 - em.getTransaction().begin(); + // Rev 1 + em.getTransaction().begin(); - ReferencedEntity re1 = new ReferencedEntity(re_id1); - em.persist(re1); + ReferencedEntity re1 = new ReferencedEntity( re_id1 ); + em.persist( re1 ); - ReferencedEntity re2 = new ReferencedEntity(re_id2); - em.persist(re2); + ReferencedEntity re2 = new ReferencedEntity( re_id2 ); + em.persist( re2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Rev 2 - em.getTransaction().begin(); + // Rev 2 + em.getTransaction().begin(); - re1 = em.find(ReferencedEntity.class, re_id1); + re1 = em.find( ReferencedEntity.class, re_id1 ); - ChildIngEntity cie = new ChildIngEntity(c_id, "y", 1l); - cie.setReferenced(re1); - em.persist(cie); - c_id = cie.getId(); + ChildIngEntity cie = new ChildIngEntity( c_id, "y", 1l ); + cie.setReferenced( re1 ); + em.persist( cie ); + c_id = cie.getId(); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Rev 3 - em.getTransaction().begin(); + // Rev 3 + em.getTransaction().begin(); - re2 = em.find(ReferencedEntity.class, re_id2); - cie = em.find(ChildIngEntity.class, c_id); + re2 = em.find( ReferencedEntity.class, re_id2 ); + cie = em.find( ChildIngEntity.class, c_id ); - cie.setReferenced(re2); + cie.setReferenced( re2 ); - em.getTransaction().commit(); - } + em.getTransaction().commit(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2, 3).equals(getAuditReader().getRevisions(ReferencedEntity.class, re_id1)); - assert Arrays.asList(1, 3).equals(getAuditReader().getRevisions(ReferencedEntity.class, re_id2)); - assert Arrays.asList(2, 3).equals(getAuditReader().getRevisions(ChildIngEntity.class, c_id)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2, 3 ).equals( getAuditReader().getRevisions( ReferencedEntity.class, re_id1 ) ); + assert Arrays.asList( 1, 3 ).equals( getAuditReader().getRevisions( ReferencedEntity.class, re_id2 ) ); + assert Arrays.asList( 2, 3 ).equals( getAuditReader().getRevisions( ChildIngEntity.class, c_id ) ); + } - @Test - public void testHistoryOfReferencedCollection1() { - assert getAuditReader().find(ReferencedEntity.class, re_id1, 1).getReferencing().size() == 0; - assert getAuditReader().find(ReferencedEntity.class, re_id1, 2).getReferencing().equals( - TestTools.makeSet(new ChildIngEntity(c_id, "y", 1l))); - assert getAuditReader().find(ReferencedEntity.class, re_id1, 3).getReferencing().size() == 0; - } + @Test + public void testHistoryOfReferencedCollection1() { + assert getAuditReader().find( ReferencedEntity.class, re_id1, 1 ).getReferencing().size() == 0; + assert getAuditReader().find( ReferencedEntity.class, re_id1, 2 ).getReferencing().equals( + TestTools.makeSet( new ChildIngEntity( c_id, "y", 1l ) ) + ); + assert getAuditReader().find( ReferencedEntity.class, re_id1, 3 ).getReferencing().size() == 0; + } - @Test - public void testHistoryOfReferencedCollection2() { - assert getAuditReader().find(ReferencedEntity.class, re_id2, 1).getReferencing().size() == 0; - assert getAuditReader().find(ReferencedEntity.class, re_id2, 2).getReferencing().size() == 0; - assert getAuditReader().find(ReferencedEntity.class, re_id2, 3).getReferencing().equals( - TestTools.makeSet(new ChildIngEntity(c_id, "y", 1l))); - } + @Test + public void testHistoryOfReferencedCollection2() { + assert getAuditReader().find( ReferencedEntity.class, re_id2, 1 ).getReferencing().size() == 0; + assert getAuditReader().find( ReferencedEntity.class, re_id2, 2 ).getReferencing().size() == 0; + assert getAuditReader().find( ReferencedEntity.class, re_id2, 3 ).getReferencing().equals( + TestTools.makeSet( new ChildIngEntity( c_id, "y", 1l ) ) + ); + } - @Test - public void testChildHistory() { - assert getAuditReader().find(ChildIngEntity.class, c_id, 1) == null; - assert getAuditReader().find(ChildIngEntity.class, c_id, 2).getReferenced().equals( - new ReferencedEntity(re_id1)); - assert getAuditReader().find(ChildIngEntity.class, c_id, 3).getReferenced().equals( - new ReferencedEntity(re_id2)); - } + @Test + public void testChildHistory() { + assert getAuditReader().find( ChildIngEntity.class, c_id, 1 ) == null; + assert getAuditReader().find( ChildIngEntity.class, c_id, 2 ).getReferenced().equals( + new ReferencedEntity( re_id1 ) + ); + assert getAuditReader().find( ChildIngEntity.class, c_id, 3 ).getReferenced().equals( + new ReferencedEntity( re_id2 ) + ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/childrelation/ParentNotIngEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/childrelation/ParentNotIngEntity.java index 3e60f965d1..a496ef6582 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/childrelation/ParentNotIngEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/childrelation/ParentNotIngEntity.java @@ -23,6 +23,7 @@ */ package org.hibernate.envers.test.integration.inheritance.joined.childrelation; + import javax.persistence.Basic; import javax.persistence.Entity; import javax.persistence.Id; @@ -38,56 +39,64 @@ import org.hibernate.envers.Audited; @Inheritance(strategy = InheritanceType.JOINED) @Audited public class ParentNotIngEntity { - @Id - private Integer id; + @Id + private Integer id; - @Basic - private String data; + @Basic + private String data; - public ParentNotIngEntity() { - } + public ParentNotIngEntity() { + } - public ParentNotIngEntity(Integer id, String data) { - this.id = id; - this.data = data; - } + public ParentNotIngEntity(Integer id, String data) { + this.id = id; + this.data = data; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ParentNotIngEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ParentNotIngEntity) ) { + return false; + } - ParentNotIngEntity that = (ParentNotIngEntity) o; + ParentNotIngEntity that = (ParentNotIngEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "ParentNotIngEntity(id = " + getId() + ", data = " + getData() + ")"; - } + public String toString() { + return "ParentNotIngEntity(id = " + getId() + ", data = " + getData() + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/childrelation/ReferencedEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/childrelation/ReferencedEntity.java index 46f84e9c05..81778b25ba 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/childrelation/ReferencedEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/childrelation/ReferencedEntity.java @@ -23,10 +23,11 @@ */ package org.hibernate.envers.test.integration.inheritance.joined.childrelation; -import java.util.Set; + import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.OneToMany; +import java.util.Set; import org.hibernate.envers.Audited; @@ -36,51 +37,57 @@ import org.hibernate.envers.Audited; @Entity @Audited public class ReferencedEntity { - @Id - private Integer id; + @Id + private Integer id; - @OneToMany(mappedBy = "referenced") - private Set referencing; + @OneToMany(mappedBy = "referenced") + private Set referencing; - public ReferencedEntity(Integer id) { - this.id = id; - } + public ReferencedEntity(Integer id) { + this.id = id; + } - public ReferencedEntity() { - } + public ReferencedEntity() { + } - public Set getReferencing() { - return referencing; - } + public Set getReferencing() { + return referencing; + } - public void setReferencing(Set referencing) { - this.referencing = referencing; - } + public void setReferencing(Set referencing) { + this.referencing = referencing; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ReferencedEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ReferencedEntity) ) { + return false; + } - ReferencedEntity that = (ReferencedEntity) o; + ReferencedEntity that = (ReferencedEntity) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - return id; - } + public int hashCode() { + return id; + } - public String toString() { - return "ReferencedEntity(id = " + getId() + ")"; - } + public String toString() { + return "ReferencedEntity(id = " + getId() + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/emptychild/EmptyChildAuditing.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/emptychild/EmptyChildAuditing.java index 6b445ec732..31953adb33 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/emptychild/EmptyChildAuditing.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/emptychild/EmptyChildAuditing.java @@ -24,70 +24,70 @@ package org.hibernate.envers.test.integration.inheritance.joined.emptychild; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class EmptyChildAuditing extends BaseEnversJPAFunctionalTestCase { - private Integer id1; + private Integer id1; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { EmptyChildEntity.class, ParentEntity.class }; - } + return new Class[] {EmptyChildEntity.class, ParentEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - id1 = 1; + id1 = 1; - // Rev 1 - em.getTransaction().begin(); - EmptyChildEntity pe = new EmptyChildEntity(id1, "x"); - em.persist(pe); - em.getTransaction().commit(); + // Rev 1 + em.getTransaction().begin(); + EmptyChildEntity pe = new EmptyChildEntity( id1, "x" ); + em.persist( pe ); + em.getTransaction().commit(); - // Rev 2 - em.getTransaction().begin(); - pe = em.find(EmptyChildEntity.class, id1); - pe.setData("y"); - em.getTransaction().commit(); - } + // Rev 2 + em.getTransaction().begin(); + pe = em.find( EmptyChildEntity.class, id1 ); + pe.setData( "y" ); + em.getTransaction().commit(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(EmptyChildEntity.class, id1)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( EmptyChildEntity.class, id1 ) ); + } - @Test - public void testHistoryOfChildId1() { - EmptyChildEntity ver1 = new EmptyChildEntity(id1, "x"); - EmptyChildEntity ver2 = new EmptyChildEntity(id1, "y"); + @Test + public void testHistoryOfChildId1() { + EmptyChildEntity ver1 = new EmptyChildEntity( id1, "x" ); + EmptyChildEntity ver2 = new EmptyChildEntity( id1, "y" ); - assert getAuditReader().find(EmptyChildEntity.class, id1, 1).equals(ver1); - assert getAuditReader().find(EmptyChildEntity.class, id1, 2).equals(ver2); + assert getAuditReader().find( EmptyChildEntity.class, id1, 1 ).equals( ver1 ); + assert getAuditReader().find( EmptyChildEntity.class, id1, 2 ).equals( ver2 ); - assert getAuditReader().find(ParentEntity.class, id1, 1).equals(ver1); - assert getAuditReader().find(ParentEntity.class, id1, 2).equals(ver2); - } + assert getAuditReader().find( ParentEntity.class, id1, 1 ).equals( ver1 ); + assert getAuditReader().find( ParentEntity.class, id1, 2 ).equals( ver2 ); + } - @Test - public void testPolymorphicQuery() { - EmptyChildEntity childVer1 = new EmptyChildEntity(id1, "x"); + @Test + public void testPolymorphicQuery() { + EmptyChildEntity childVer1 = new EmptyChildEntity( id1, "x" ); - assert getAuditReader().createQuery().forEntitiesAtRevision(EmptyChildEntity.class, 1).getSingleResult() - .equals(childVer1); + assert getAuditReader().createQuery().forEntitiesAtRevision( EmptyChildEntity.class, 1 ).getSingleResult() + .equals( childVer1 ); - assert getAuditReader().createQuery().forEntitiesAtRevision(ParentEntity.class, 1).getSingleResult() - .equals(childVer1); - } + assert getAuditReader().createQuery().forEntitiesAtRevision( ParentEntity.class, 1 ).getSingleResult() + .equals( childVer1 ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/emptychild/EmptyChildEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/emptychild/EmptyChildEntity.java index 60c1323b40..3644001ead 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/emptychild/EmptyChildEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/emptychild/EmptyChildEntity.java @@ -23,6 +23,7 @@ */ package org.hibernate.envers.test.integration.inheritance.joined.emptychild; + import javax.persistence.Entity; import org.hibernate.envers.Audited; @@ -37,6 +38,6 @@ public class EmptyChildEntity extends ParentEntity { } public EmptyChildEntity(Integer id, String data) { - super(id, data); + super( id, data ); } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/emptychild/ParentEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/emptychild/ParentEntity.java index e4ac929d4d..bea7991354 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/emptychild/ParentEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/emptychild/ParentEntity.java @@ -23,6 +23,7 @@ */ package org.hibernate.envers.test.integration.inheritance.joined.emptychild; + import javax.persistence.Basic; import javax.persistence.Entity; import javax.persistence.Id; @@ -38,56 +39,64 @@ import org.hibernate.envers.Audited; @Inheritance(strategy = InheritanceType.JOINED) @Audited public abstract class ParentEntity { - @Id - private Integer id; + @Id + private Integer id; - @Basic - private String data; + @Basic + private String data; - public ParentEntity() { - } + public ParentEntity() { + } - public ParentEntity(Integer id, String data) { - this.id = id; - this.data = data; - } + public ParentEntity(Integer id, String data) { + this.id = id; + this.data = data; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ParentEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ParentEntity) ) { + return false; + } - ParentEntity that = (ParentEntity) o; + ParentEntity that = (ParentEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "ParentEntity(id = " + getId() + ", data = " + getData() + ")"; - } + public String toString() { + return "ParentEntity(id = " + getId() + ", data = " + getData() + ")"; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/notownedrelation/Address.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/notownedrelation/Address.java index 900af7ad69..1979f6dfc1 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/notownedrelation/Address.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/notownedrelation/Address.java @@ -23,10 +23,11 @@ */ package org.hibernate.envers.test.integration.inheritance.joined.notownedrelation; -import java.io.Serializable; + import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.ManyToOne; +import java.io.Serializable; import org.hibernate.envers.Audited; @@ -41,15 +42,15 @@ public class Address implements Serializable { @ManyToOne private Contact contact; - public Address() { - } + public Address() { + } - public Address(Long id, String address1) { - this.id = id; - this.address1 = address1; - } + public Address(Long id, String address1) { + this.id = id; + this.address1 = address1; + } - public Long getId() { + public Long getId() { return id; } @@ -73,26 +74,34 @@ public class Address implements Serializable { this.contact = contact; } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof Address)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof Address) ) { + return false; + } - Address address = (Address) o; + Address address = (Address) o; - if (address1 != null ? !address1.equals(address.address1) : address.address1 != null) return false; - if (id != null ? !id.equals(address.id) : address.id != null) return false; + if ( address1 != null ? !address1.equals( address.address1 ) : address.address1 != null ) { + return false; + } + if ( id != null ? !id.equals( address.id ) : address.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (address1 != null ? address1.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (address1 != null ? address1.hashCode() : 0); + return result; + } - public String toString() { - return "Address(id = " + getId() + ", address1 = " + getAddress1() + ")"; - } + public String toString() { + return "Address(id = " + getId() + ", address1 = " + getAddress1() + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/notownedrelation/Contact.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/notownedrelation/Contact.java index 7eb136ada5..fb47233e4d 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/notownedrelation/Contact.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/notownedrelation/Contact.java @@ -23,53 +23,58 @@ */ package org.hibernate.envers.test.integration.inheritance.joined.notownedrelation; -import java.io.Serializable; -import java.util.Set; + import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; import javax.persistence.OneToMany; +import java.io.Serializable; +import java.util.Set; import org.hibernate.envers.Audited; @Entity -@Inheritance(strategy=InheritanceType.JOINED) +@Inheritance(strategy = InheritanceType.JOINED) @Audited public class Contact implements Serializable { - @Id - private Long id; + @Id + private Long id; - private String email; + private String email; - @OneToMany(mappedBy="contact") - private Set
addresses; + @OneToMany(mappedBy = "contact") + private Set
addresses; - public Contact() { - } + public Contact() { + } - public Contact(Long id, String email) { - this.id = id; - this.email = email; - } + public Contact(Long id, String email) { + this.id = id; + this.email = email; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } - public Long getId() { - return id; - } - public void setId(Long id) { - this.id = id; - } public String getEmail() { - return email; - } - public void setEmail(String email) { - this.email = email; - } + return email; + } - public Set
getAddresses() { - return addresses; - } - public void setAddresses(Set
addresses) { - this.addresses = addresses; - } + public void setEmail(String email) { + this.email = email; + } + + public Set
getAddresses() { + return addresses; + } + + public void setAddresses(Set
addresses) { + this.addresses = addresses; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/notownedrelation/NotOwnedBidirectional.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/notownedrelation/NotOwnedBidirectional.java index 0a088aab98..3d0ef4f614 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/notownedrelation/NotOwnedBidirectional.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/notownedrelation/NotOwnedBidirectional.java @@ -24,91 +24,95 @@ package org.hibernate.envers.test.integration.inheritance.joined.notownedrelation; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.tools.TestTools; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class NotOwnedBidirectional extends BaseEnversJPAFunctionalTestCase { - private Long pc_id; - private Long a1_id; - private Long a2_id; + private Long pc_id; + private Long a1_id; + private Long a2_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { Address.class, Contact.class, PersonalContact.class }; - } + return new Class[] {Address.class, Contact.class, PersonalContact.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - pc_id = 1l; - a1_id = 10l; - a2_id = 100l; + pc_id = 1l; + a1_id = 10l; + a2_id = 100l; - // Rev 1 - em.getTransaction().begin(); + // Rev 1 + em.getTransaction().begin(); - PersonalContact pc = new PersonalContact(pc_id, "e", "f"); + PersonalContact pc = new PersonalContact( pc_id, "e", "f" ); - Address a1 = new Address(a1_id, "a1"); - a1.setContact(pc); + Address a1 = new Address( a1_id, "a1" ); + a1.setContact( pc ); - em.persist(pc); - em.persist(a1); + em.persist( pc ); + em.persist( a1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Rev 2 - em.getTransaction().begin(); + // Rev 2 + em.getTransaction().begin(); - pc = em.find(PersonalContact.class, pc_id); + pc = em.find( PersonalContact.class, pc_id ); - Address a2 = new Address(a2_id, "a2"); - a2.setContact(pc); + Address a2 = new Address( a2_id, "a2" ); + a2.setContact( pc ); - em.persist(a2); + em.persist( a2 ); - em.getTransaction().commit(); - } + em.getTransaction().commit(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(Contact.class, pc_id)); - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(PersonalContact.class, pc_id)); + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( Contact.class, pc_id ) ); + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( PersonalContact.class, pc_id ) ); - assert Arrays.asList(1).equals(getAuditReader().getRevisions(Address.class, a1_id)); - assert Arrays.asList(1).equals(getAuditReader().getRevisions(Address.class, a1_id)); + assert Arrays.asList( 1 ).equals( getAuditReader().getRevisions( Address.class, a1_id ) ); + assert Arrays.asList( 1 ).equals( getAuditReader().getRevisions( Address.class, a1_id ) ); - assert Arrays.asList(2).equals(getAuditReader().getRevisions(Address.class, a2_id)); - assert Arrays.asList(2).equals(getAuditReader().getRevisions(Address.class, a2_id)); - } + assert Arrays.asList( 2 ).equals( getAuditReader().getRevisions( Address.class, a2_id ) ); + assert Arrays.asList( 2 ).equals( getAuditReader().getRevisions( Address.class, a2_id ) ); + } - @Test - public void testHistoryOfContact() { - assert getAuditReader().find(Contact.class, pc_id, 1).getAddresses().equals( - TestTools.makeSet(new Address(a1_id, "a1"))); + @Test + public void testHistoryOfContact() { + assert getAuditReader().find( Contact.class, pc_id, 1 ).getAddresses().equals( + TestTools.makeSet( new Address( a1_id, "a1" ) ) + ); - assert getAuditReader().find(Contact.class, pc_id, 2).getAddresses().equals( - TestTools.makeSet(new Address(a1_id, "a1"), new Address(a2_id, "a2"))); - } + assert getAuditReader().find( Contact.class, pc_id, 2 ).getAddresses().equals( + TestTools.makeSet( new Address( a1_id, "a1" ), new Address( a2_id, "a2" ) ) + ); + } - @Test - public void testHistoryOfPersonalContact() { - System.out.println(getAuditReader().find(PersonalContact.class, pc_id, 1).getAddresses()); - assert getAuditReader().find(PersonalContact.class, pc_id, 1).getAddresses().equals( - TestTools.makeSet(new Address(a1_id, "a1"))); + @Test + public void testHistoryOfPersonalContact() { + System.out.println( getAuditReader().find( PersonalContact.class, pc_id, 1 ).getAddresses() ); + assert getAuditReader().find( PersonalContact.class, pc_id, 1 ).getAddresses().equals( + TestTools.makeSet( new Address( a1_id, "a1" ) ) + ); - assert getAuditReader().find(PersonalContact.class, pc_id, 2).getAddresses().equals( - TestTools.makeSet(new Address(a1_id, "a1"), new Address(a2_id, "a2"))); - } + assert getAuditReader().find( PersonalContact.class, pc_id, 2 ).getAddresses().equals( + TestTools.makeSet( new Address( a1_id, "a1" ), new Address( a2_id, "a2" ) ) + ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/notownedrelation/PersonalContact.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/notownedrelation/PersonalContact.java index 49c795aa68..e79b952e1c 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/notownedrelation/PersonalContact.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/notownedrelation/PersonalContact.java @@ -23,6 +23,7 @@ */ package org.hibernate.envers.test.integration.inheritance.joined.notownedrelation; + import javax.persistence.Entity; import org.hibernate.envers.Audited; @@ -30,21 +31,21 @@ import org.hibernate.envers.Audited; @Entity @Audited public class PersonalContact extends Contact { - private String firstname; + private String firstname; - public PersonalContact() { - } + public PersonalContact() { + } - public PersonalContact(Long id, String email, String firstname) { - super(id, email); - this.firstname = firstname; - } + public PersonalContact(Long id, String email, String firstname) { + super( id, email ); + this.firstname = firstname; + } - public String getFirstname() { + public String getFirstname() { return firstname; } - public void setFirstname(String firstname) { + public void setFirstname(String firstname) { this.firstname = firstname; } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/primarykeyjoin/ChildPrimaryKeyJoinAuditing.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/primarykeyjoin/ChildPrimaryKeyJoinAuditing.java index 09733bc72d..2d96f5b568 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/primarykeyjoin/ChildPrimaryKeyJoinAuditing.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/primarykeyjoin/ChildPrimaryKeyJoinAuditing.java @@ -24,82 +24,88 @@ package org.hibernate.envers.test.integration.inheritance.joined.primarykeyjoin; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Assert; -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.integration.inheritance.joined.ParentEntity; import org.hibernate.mapping.Column; +import org.junit.Assert; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class ChildPrimaryKeyJoinAuditing extends BaseEnversJPAFunctionalTestCase { - private Integer id1; + private Integer id1; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { ChildPrimaryKeyJoinEntity.class, ParentEntity.class }; - } + return new Class[] {ChildPrimaryKeyJoinEntity.class, ParentEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - id1 = 1; + id1 = 1; - // Rev 1 - em.getTransaction().begin(); - ChildPrimaryKeyJoinEntity ce = new ChildPrimaryKeyJoinEntity(id1, "x", 1l); - em.persist(ce); - em.getTransaction().commit(); + // Rev 1 + em.getTransaction().begin(); + ChildPrimaryKeyJoinEntity ce = new ChildPrimaryKeyJoinEntity( id1, "x", 1l ); + em.persist( ce ); + em.getTransaction().commit(); - // Rev 2 - em.getTransaction().begin(); - ce = em.find(ChildPrimaryKeyJoinEntity.class, id1); - ce.setData("y"); - ce.setNumVal(2l); - em.getTransaction().commit(); - } + // Rev 2 + em.getTransaction().begin(); + ce = em.find( ChildPrimaryKeyJoinEntity.class, id1 ); + ce.setData( "y" ); + ce.setNumVal( 2l ); + em.getTransaction().commit(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(ChildPrimaryKeyJoinEntity.class, id1)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( ChildPrimaryKeyJoinEntity.class, id1 ) ); + } - @Test - public void testHistoryOfChildId1() { - ChildPrimaryKeyJoinEntity ver1 = new ChildPrimaryKeyJoinEntity(id1, "x", 1l); - ChildPrimaryKeyJoinEntity ver2 = new ChildPrimaryKeyJoinEntity(id1, "y", 2l); + @Test + public void testHistoryOfChildId1() { + ChildPrimaryKeyJoinEntity ver1 = new ChildPrimaryKeyJoinEntity( id1, "x", 1l ); + ChildPrimaryKeyJoinEntity ver2 = new ChildPrimaryKeyJoinEntity( id1, "y", 2l ); - assert getAuditReader().find(ChildPrimaryKeyJoinEntity.class, id1, 1).equals(ver1); - assert getAuditReader().find(ChildPrimaryKeyJoinEntity.class, id1, 2).equals(ver2); + assert getAuditReader().find( ChildPrimaryKeyJoinEntity.class, id1, 1 ).equals( ver1 ); + assert getAuditReader().find( ChildPrimaryKeyJoinEntity.class, id1, 2 ).equals( ver2 ); - assert getAuditReader().find(ParentEntity.class, id1, 1).equals(ver1); - assert getAuditReader().find(ParentEntity.class, id1, 2).equals(ver2); - } + assert getAuditReader().find( ParentEntity.class, id1, 1 ).equals( ver1 ); + assert getAuditReader().find( ParentEntity.class, id1, 2 ).equals( ver2 ); + } - @Test - public void testPolymorphicQuery() { - ChildPrimaryKeyJoinEntity childVer1 = new ChildPrimaryKeyJoinEntity(id1, "x", 1l); + @Test + public void testPolymorphicQuery() { + ChildPrimaryKeyJoinEntity childVer1 = new ChildPrimaryKeyJoinEntity( id1, "x", 1l ); - assert getAuditReader().createQuery().forEntitiesAtRevision(ChildPrimaryKeyJoinEntity.class, 1).getSingleResult() - .equals(childVer1); + assert getAuditReader().createQuery() + .forEntitiesAtRevision( ChildPrimaryKeyJoinEntity.class, 1 ) + .getSingleResult() + .equals( childVer1 ); - assert getAuditReader().createQuery().forEntitiesAtRevision(ParentEntity.class, 1).getSingleResult() - .equals(childVer1); - } + assert getAuditReader().createQuery().forEntitiesAtRevision( ParentEntity.class, 1 ).getSingleResult() + .equals( childVer1 ); + } - @Test - public void testChildIdColumnName() { - Assert.assertEquals("other_id", - ((Column) getCfg() - .getClassMapping("org.hibernate.envers.test.integration.inheritance.joined.primarykeyjoin.ChildPrimaryKeyJoinEntity_AUD") - .getKey().getColumnIterator().next()).getName()); - } + @Test + public void testChildIdColumnName() { + Assert.assertEquals( + "other_id", + ((Column) getCfg() + .getClassMapping( + "org.hibernate.envers.test.integration.inheritance.joined.primarykeyjoin.ChildPrimaryKeyJoinEntity_AUD" + ) + .getKey().getColumnIterator().next()).getName() + ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/primarykeyjoin/ChildPrimaryKeyJoinEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/primarykeyjoin/ChildPrimaryKeyJoinEntity.java index af82e9fd83..80f5dbaa1d 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/primarykeyjoin/ChildPrimaryKeyJoinEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/primarykeyjoin/ChildPrimaryKeyJoinEntity.java @@ -23,6 +23,7 @@ */ package org.hibernate.envers.test.integration.inheritance.joined.primarykeyjoin; + import javax.persistence.Basic; import javax.persistence.Entity; import javax.persistence.PrimaryKeyJoinColumn; @@ -37,45 +38,55 @@ import org.hibernate.envers.test.integration.inheritance.joined.ParentEntity; @Audited @PrimaryKeyJoinColumn(name = "other_id") public class ChildPrimaryKeyJoinEntity extends ParentEntity { - @Basic - private Long namVal; + @Basic + private Long namVal; - public ChildPrimaryKeyJoinEntity() { - } + public ChildPrimaryKeyJoinEntity() { + } - public ChildPrimaryKeyJoinEntity(Integer id, String data, Long namVal) { - super(id, data); - this.namVal = namVal; - } + public ChildPrimaryKeyJoinEntity(Integer id, String data, Long namVal) { + super( id, data ); + this.namVal = namVal; + } - public Long getNumVal() { - return namVal; - } + public Long getNumVal() { + return namVal; + } - public void setNumVal(Long namVal) { - this.namVal = namVal; - } + public void setNumVal(Long namVal) { + this.namVal = namVal; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ChildPrimaryKeyJoinEntity)) return false; - if (!super.equals(o)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ChildPrimaryKeyJoinEntity) ) { + return false; + } + if ( !super.equals( o ) ) { + return false; + } - ChildPrimaryKeyJoinEntity childPrimaryKeyJoinEntity = (ChildPrimaryKeyJoinEntity) o; + ChildPrimaryKeyJoinEntity childPrimaryKeyJoinEntity = (ChildPrimaryKeyJoinEntity) o; - //noinspection RedundantIfStatement - if (namVal != null ? !namVal.equals(childPrimaryKeyJoinEntity.namVal) : childPrimaryKeyJoinEntity.namVal != null) return false; + //noinspection RedundantIfStatement + if ( namVal != null ? + !namVal.equals( childPrimaryKeyJoinEntity.namVal ) : + childPrimaryKeyJoinEntity.namVal != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result = super.hashCode(); - result = 31 * result + (namVal != null ? namVal.hashCode() : 0); - return result; - } + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (namVal != null ? namVal.hashCode() : 0); + return result; + } - public String toString() { - return "CPKJE(id = " + getId() + ", data = " + getData() + ", namVal = " + namVal + ")"; - } + public String toString() { + return "CPKJE(id = " + getId() + ", data = " + getData() + ", namVal = " + namVal + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/ChildIngEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/ChildIngEntity.java index 8fb953c167..afa542f99a 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/ChildIngEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/ChildIngEntity.java @@ -23,6 +23,7 @@ */ package org.hibernate.envers.test.integration.inheritance.joined.relation; + import javax.persistence.Basic; import javax.persistence.Entity; @@ -34,44 +35,52 @@ import org.hibernate.envers.Audited; @Entity @Audited public class ChildIngEntity extends ParentIngEntity { - @Basic - private Long numVal; + @Basic + private Long numVal; - public ChildIngEntity() { - } + public ChildIngEntity() { + } - public ChildIngEntity(Integer id, String data, Long numVal) { - super(id, data); - this.numVal = numVal; - } + public ChildIngEntity(Integer id, String data, Long numVal) { + super( id, data ); + this.numVal = numVal; + } - public Long getNumVal() { - return numVal; - } + public Long getNumVal() { + return numVal; + } - public void setNumVal(Long numVal) { - this.numVal = numVal; - } + public void setNumVal(Long numVal) { + this.numVal = numVal; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ChildIngEntity)) return false; - if (!super.equals(o)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ChildIngEntity) ) { + return false; + } + if ( !super.equals( o ) ) { + return false; + } - ChildIngEntity childEntity = (ChildIngEntity) o; + ChildIngEntity childEntity = (ChildIngEntity) o; - if (numVal != null ? !numVal.equals(childEntity.numVal) : childEntity.numVal != null) return false; + if ( numVal != null ? !numVal.equals( childEntity.numVal ) : childEntity.numVal != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result = super.hashCode(); - result = 31 * result + (numVal != null ? numVal.hashCode() : 0); - return result; - } + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (numVal != null ? numVal.hashCode() : 0); + return result; + } - public String toString() { - return "ChildIngEntity(id = " + getId() + ", data = " + getData() + ", numVal = " + numVal + ")"; - } + public String toString() { + return "ChildIngEntity(id = " + getId() + ", data = " + getData() + ", numVal = " + numVal + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/ParentIngEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/ParentIngEntity.java index 9e7f4edd4b..7ac7a5ee9e 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/ParentIngEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/ParentIngEntity.java @@ -23,6 +23,7 @@ */ package org.hibernate.envers.test.integration.inheritance.joined.relation; + import javax.persistence.Basic; import javax.persistence.Entity; import javax.persistence.Id; @@ -39,67 +40,75 @@ import org.hibernate.envers.Audited; @Inheritance(strategy = InheritanceType.JOINED) @Audited public class ParentIngEntity { - @Id - private Integer id; + @Id + private Integer id; - @Basic - private String data; + @Basic + private String data; - @ManyToOne - private ReferencedEntity referenced; + @ManyToOne + private ReferencedEntity referenced; - public ParentIngEntity() { - } + public ParentIngEntity() { + } - public ParentIngEntity(Integer id, String data) { - this.id = id; - this.data = data; - } + public ParentIngEntity(Integer id, String data) { + this.id = id; + this.data = data; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public ReferencedEntity getReferenced() { - return referenced; - } + public ReferencedEntity getReferenced() { + return referenced; + } - public void setReferenced(ReferencedEntity referenced) { - this.referenced = referenced; - } + public void setReferenced(ReferencedEntity referenced) { + this.referenced = referenced; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ParentIngEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ParentIngEntity) ) { + return false; + } - ParentIngEntity that = (ParentIngEntity) o; + ParentIngEntity that = (ParentIngEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "ParentIngEntity(id = " + getId() + ", data = " + getData() + ")"; - } + public String toString() { + return "ParentIngEntity(id = " + getId() + ", data = " + getData() + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/ParentReferencingChildTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/ParentReferencingChildTest.java index 3c401f25ea..10824484fa 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/ParentReferencingChildTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/ParentReferencingChildTest.java @@ -1,14 +1,15 @@ package org.hibernate.envers.test.integration.inheritance.joined.relation; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Assert; -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.tools.TestTools; + +import org.junit.Assert; +import org.junit.Test; + import org.hibernate.testing.TestForIssue; /** @@ -16,61 +17,71 @@ import org.hibernate.testing.TestForIssue; */ @TestForIssue(jiraKey = "HHH-3843") public class ParentReferencingChildTest extends BaseEnversJPAFunctionalTestCase { - Person expLukaszRev1 = null; - Role expAdminRev1 = null; + Person expLukaszRev1 = null; + Role expAdminRev1 = null; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { Person.class, Role.class, RightsSubject.class }; - } + return new Class[] {Person.class, Role.class, RightsSubject.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - // Revision 1 - em.getTransaction().begin(); - Person lukasz = new Person(); - lukasz.setName("Lukasz"); - lukasz.setGroup("IT"); - em.persist(lukasz); - Role admin = new Role(); - admin.setName("Admin"); - admin.setGroup("Confidential"); - lukasz.getRoles().add(admin); - admin.getMembers().add(lukasz); - em.persist(admin); - em.getTransaction().commit(); + // Revision 1 + em.getTransaction().begin(); + Person lukasz = new Person(); + lukasz.setName( "Lukasz" ); + lukasz.setGroup( "IT" ); + em.persist( lukasz ); + Role admin = new Role(); + admin.setName( "Admin" ); + admin.setGroup( "Confidential" ); + lukasz.getRoles().add( admin ); + admin.getMembers().add( lukasz ); + em.persist( admin ); + em.getTransaction().commit(); - expLukaszRev1 = new Person(lukasz.getId(), "IT", "Lukasz"); - expAdminRev1 = new Role(admin.getId(), "Confidential", "Admin"); - } + expLukaszRev1 = new Person( lukasz.getId(), "IT", "Lukasz" ); + expAdminRev1 = new Role( admin.getId(), "Confidential", "Admin" ); + } - @Test - public void testRevisionsCounts() { - Assert.assertEquals(Arrays.asList(1), getAuditReader().getRevisions(Person.class, expLukaszRev1.getId())); - Assert.assertEquals(Arrays.asList(1), getAuditReader().getRevisions(RightsSubject.class, expLukaszRev1.getId())); + @Test + public void testRevisionsCounts() { + Assert.assertEquals( Arrays.asList( 1 ), getAuditReader().getRevisions( Person.class, expLukaszRev1.getId() ) ); + Assert.assertEquals( + Arrays.asList( 1 ), getAuditReader().getRevisions( + RightsSubject.class, + expLukaszRev1.getId() + ) + ); - Assert.assertEquals(Arrays.asList(1), getAuditReader().getRevisions(Role.class, expAdminRev1.getId())); - Assert.assertEquals(Arrays.asList(1), getAuditReader().getRevisions(RightsSubject.class, expAdminRev1.getId())); - } + Assert.assertEquals( Arrays.asList( 1 ), getAuditReader().getRevisions( Role.class, expAdminRev1.getId() ) ); + Assert.assertEquals( + Arrays.asList( 1 ), getAuditReader().getRevisions( + RightsSubject.class, + expAdminRev1.getId() + ) + ); + } - @Test - public void testHistoryOfLukasz() { - Person lukaszRev1 = getAuditReader().find(Person.class, expLukaszRev1.getId(), 1); - RightsSubject rightsSubjectLukaszRev1 = getAuditReader().find(RightsSubject.class, expLukaszRev1.getId(), 1); + @Test + public void testHistoryOfLukasz() { + Person lukaszRev1 = getAuditReader().find( Person.class, expLukaszRev1.getId(), 1 ); + RightsSubject rightsSubjectLukaszRev1 = getAuditReader().find( RightsSubject.class, expLukaszRev1.getId(), 1 ); - Assert.assertEquals(expLukaszRev1, lukaszRev1); - Assert.assertEquals(TestTools.makeSet(expAdminRev1), lukaszRev1.getRoles()); - Assert.assertEquals(TestTools.makeSet(expAdminRev1), rightsSubjectLukaszRev1.getRoles()); - } + Assert.assertEquals( expLukaszRev1, lukaszRev1 ); + Assert.assertEquals( TestTools.makeSet( expAdminRev1 ), lukaszRev1.getRoles() ); + Assert.assertEquals( TestTools.makeSet( expAdminRev1 ), rightsSubjectLukaszRev1.getRoles() ); + } - @Test - public void testHistoryOfAdmin() { - Role adminRev1 = getAuditReader().find(Role.class, expAdminRev1.getId(), 1); + @Test + public void testHistoryOfAdmin() { + Role adminRev1 = getAuditReader().find( Role.class, expAdminRev1.getId(), 1 ); - Assert.assertEquals(expAdminRev1, adminRev1); - Assert.assertEquals(TestTools.makeSet(expLukaszRev1), adminRev1.getMembers()); - } + Assert.assertEquals( expAdminRev1, adminRev1 ); + Assert.assertEquals( TestTools.makeSet( expLukaszRev1 ), adminRev1.getMembers() ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/Person.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/Person.java index eac7475862..299f33d628 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/Person.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/Person.java @@ -10,45 +10,53 @@ import org.hibernate.envers.Audited; @Entity @Audited public class Person extends RightsSubject { - private String name; + private String name; - public Person() { - } + public Person() { + } - public Person(Long id, String group, String name) { - super(id, group); - this.name = name; - } + public Person(Long id, String group, String name) { + super( id, group ); + this.name = name; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof Person)) return false; - if (!super.equals(o)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof Person) ) { + return false; + } + if ( !super.equals( o ) ) { + return false; + } - Person person = (Person) o; + Person person = (Person) o; - if (name != null ? !name.equals(person.name) : person.name != null) return false; + if ( name != null ? !name.equals( person.name ) : person.name != null ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - int result = super.hashCode(); - result = 31 * result + (name != null ? name.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (name != null ? name.hashCode() : 0); + return result; + } - @Override - public String toString() { - return "Person(" + super.toString() + ", name = " + name + ")"; - } + @Override + public String toString() { + return "Person(" + super.toString() + ", name = " + name + ")"; + } - public String getName() { - return name; - } + public String getName() { + return name; + } - public void setName(String name) { - this.name = name; - } + public void setName(String name) { + this.name = name; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/PolymorphicCollection.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/PolymorphicCollection.java index cb5e0e561d..fc5f70c716 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/PolymorphicCollection.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/PolymorphicCollection.java @@ -24,83 +24,85 @@ package org.hibernate.envers.test.integration.inheritance.joined.relation; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.tools.TestTools; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class PolymorphicCollection extends BaseEnversJPAFunctionalTestCase { - private Integer ed_id1; - private Integer c_id; - private Integer p_id; + private Integer ed_id1; + private Integer c_id; + private Integer p_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { ChildIngEntity.class, ParentIngEntity.class, ReferencedEntity.class }; - } + return new Class[] {ChildIngEntity.class, ParentIngEntity.class, ReferencedEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - ed_id1 = 1; - p_id = 10; - c_id = 100; + ed_id1 = 1; + p_id = 10; + c_id = 100; - // Rev 1 - em.getTransaction().begin(); + // Rev 1 + em.getTransaction().begin(); - ReferencedEntity re = new ReferencedEntity(ed_id1); - em.persist(re); + ReferencedEntity re = new ReferencedEntity( ed_id1 ); + em.persist( re ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Rev 2 - em.getTransaction().begin(); + // Rev 2 + em.getTransaction().begin(); - re = em.find(ReferencedEntity.class, ed_id1); + re = em.find( ReferencedEntity.class, ed_id1 ); - ParentIngEntity pie = new ParentIngEntity(p_id,"x"); - pie.setReferenced(re); - em.persist(pie); - p_id = pie.getId(); + ParentIngEntity pie = new ParentIngEntity( p_id, "x" ); + pie.setReferenced( re ); + em.persist( pie ); + p_id = pie.getId(); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Rev 3 - em.getTransaction().begin(); + // Rev 3 + em.getTransaction().begin(); - re = em.find(ReferencedEntity.class, ed_id1); + re = em.find( ReferencedEntity.class, ed_id1 ); - ChildIngEntity cie = new ChildIngEntity(c_id, "y", 1l); - cie.setReferenced(re); - em.persist(cie); - c_id = cie.getId(); + ChildIngEntity cie = new ChildIngEntity( c_id, "y", 1l ); + cie.setReferenced( re ); + em.persist( cie ); + c_id = cie.getId(); - em.getTransaction().commit(); - } + em.getTransaction().commit(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2, 3).equals(getAuditReader().getRevisions(ReferencedEntity.class, ed_id1)); - assert Arrays.asList(2).equals(getAuditReader().getRevisions(ParentIngEntity.class, p_id)); - assert Arrays.asList(3).equals(getAuditReader().getRevisions(ChildIngEntity.class, c_id)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2, 3 ).equals( getAuditReader().getRevisions( ReferencedEntity.class, ed_id1 ) ); + assert Arrays.asList( 2 ).equals( getAuditReader().getRevisions( ParentIngEntity.class, p_id ) ); + assert Arrays.asList( 3 ).equals( getAuditReader().getRevisions( ChildIngEntity.class, c_id ) ); + } - @Test - public void testHistoryOfReferencedCollection() { - assert getAuditReader().find(ReferencedEntity.class, ed_id1, 1).getReferencing().size() == 0; - assert getAuditReader().find(ReferencedEntity.class, ed_id1, 2).getReferencing().equals( - TestTools.makeSet(new ParentIngEntity(p_id, "x"))); - assert getAuditReader().find(ReferencedEntity.class, ed_id1, 3).getReferencing().equals( - TestTools.makeSet(new ParentIngEntity(p_id, "x"), new ChildIngEntity(c_id, "y", 1l))); - } + @Test + public void testHistoryOfReferencedCollection() { + assert getAuditReader().find( ReferencedEntity.class, ed_id1, 1 ).getReferencing().size() == 0; + assert getAuditReader().find( ReferencedEntity.class, ed_id1, 2 ).getReferencing().equals( + TestTools.makeSet( new ParentIngEntity( p_id, "x" ) ) + ); + assert getAuditReader().find( ReferencedEntity.class, ed_id1, 3 ).getReferencing().equals( + TestTools.makeSet( new ParentIngEntity( p_id, "x" ), new ChildIngEntity( c_id, "y", 1l ) ) + ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/ReferencedEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/ReferencedEntity.java index ac393f7da6..6e8e772e0f 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/ReferencedEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/ReferencedEntity.java @@ -23,10 +23,11 @@ */ package org.hibernate.envers.test.integration.inheritance.joined.relation; -import java.util.Set; + import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.OneToMany; +import java.util.Set; import org.hibernate.envers.Audited; @@ -36,51 +37,57 @@ import org.hibernate.envers.Audited; @Entity @Audited public class ReferencedEntity { - @Id - private Integer id; + @Id + private Integer id; - @OneToMany(mappedBy = "referenced") - private Set referencing; + @OneToMany(mappedBy = "referenced") + private Set referencing; - public ReferencedEntity() { - } + public ReferencedEntity() { + } - public ReferencedEntity(Integer id) { - this.id = id; - } + public ReferencedEntity(Integer id) { + this.id = id; + } - public Set getReferencing() { - return referencing; - } + public Set getReferencing() { + return referencing; + } - public void setReferencing(Set referencing) { - this.referencing = referencing; - } + public void setReferencing(Set referencing) { + this.referencing = referencing; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ReferencedEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ReferencedEntity) ) { + return false; + } - ReferencedEntity that = (ReferencedEntity) o; + ReferencedEntity that = (ReferencedEntity) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - return id; - } + public int hashCode() { + return id; + } - public String toString() { - return "ReferencedEntity(id = " + getId() + ")"; - } + public String toString() { + return "ReferencedEntity(id = " + getId() + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/RightsSubject.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/RightsSubject.java index 2ca029daa4..3da654283d 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/RightsSubject.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/RightsSubject.java @@ -1,7 +1,5 @@ package org.hibernate.envers.test.integration.inheritance.joined.relation; -import java.util.HashSet; -import java.util.Set; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -9,6 +7,8 @@ import javax.persistence.Id; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; import javax.persistence.ManyToMany; +import java.util.HashSet; +import java.util.Set; import org.hibernate.envers.Audited; @@ -19,70 +19,78 @@ import org.hibernate.envers.Audited; @Inheritance(strategy = InheritanceType.JOINED) @Audited public class RightsSubject { - @Id - @GeneratedValue - private Long id; + @Id + @GeneratedValue + private Long id; - @Column(name = "APP_GROUP") - private String group; + @Column(name = "APP_GROUP") + private String group; - @ManyToMany(mappedBy="members") - private Set roles = new HashSet(); + @ManyToMany(mappedBy = "members") + private Set roles = new HashSet(); - public RightsSubject() { - } + public RightsSubject() { + } - public RightsSubject(Long id, String group) { - this.id = id; - this.group = group; - } + public RightsSubject(Long id, String group) { + this.id = id; + this.group = group; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof RightsSubject)) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof RightsSubject) ) { + return false; + } - RightsSubject that = (RightsSubject) o; + RightsSubject that = (RightsSubject) o; - if (group != null ? !group.equals(that.group) : that.group != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( group != null ? !group.equals( that.group ) : that.group != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - int result = id != null ? id.hashCode() : 0; - result = 31 * result + (group != null ? group.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = id != null ? id.hashCode() : 0; + result = 31 * result + (group != null ? group.hashCode() : 0); + return result; + } - @Override - public String toString() { - return "RightsSubject(id = " + id + ", group = " + group + ")"; - } + @Override + public String toString() { + return "RightsSubject(id = " + id + ", group = " + group + ")"; + } - public Long getId() { - return id; - } + public Long getId() { + return id; + } - public void setId(Long id) { - this.id = id; - } + public void setId(Long id) { + this.id = id; + } - public Set getRoles() { - return roles; - } + public Set getRoles() { + return roles; + } - public void setRoles(Set roles) { - this.roles = roles; - } + public void setRoles(Set roles) { + this.roles = roles; + } - public String getGroup() { - return group; - } + public String getGroup() { + return group; + } - public void setGroup(String group) { - this.group = group; - } + public void setGroup(String group) { + this.group = group; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/Role.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/Role.java index ee29971c50..5beba72a86 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/Role.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/Role.java @@ -1,10 +1,10 @@ package org.hibernate.envers.test.integration.inheritance.joined.relation; -import java.util.HashSet; -import java.util.Set; import javax.persistence.Entity; import javax.persistence.ManyToMany; import javax.persistence.Table; +import java.util.HashSet; +import java.util.Set; import org.hibernate.envers.Audited; @@ -15,56 +15,64 @@ import org.hibernate.envers.Audited; @Table(name = "APP_ROLE") @Audited public class Role extends RightsSubject { - private String name; - - @ManyToMany + private String name; + + @ManyToMany private Set members = new HashSet(); - public Role() { - } + public Role() { + } - public Role(Long id, String group, String name) { - super(id, group); - this.name = name; - } + public Role(Long id, String group, String name) { + super( id, group ); + this.name = name; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof Role)) return false; - if (!super.equals(o)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof Role) ) { + return false; + } + if ( !super.equals( o ) ) { + return false; + } - Role role = (Role) o; + Role role = (Role) o; - if (name != null ? !name.equals(role.name) : role.name != null) return false; + if ( name != null ? !name.equals( role.name ) : role.name != null ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - int result = super.hashCode(); - result = 31 * result + (name != null ? name.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (name != null ? name.hashCode() : 0); + return result; + } - @Override - public String toString() { - return "Role(" + super.toString() + ", name = " + name + ")"; - } + @Override + public String toString() { + return "Role(" + super.toString() + ", name = " + name + ")"; + } - public String getName() { - return name; - } + public String getName() { + return name; + } - public void setName(String name) { - this.name = name; - } + public void setName(String name) { + this.name = name; + } - public Set getMembers() { - return members; - } + public Set getMembers() { + return members; + } - public void setMembers(Set members) { - this.members = members; - } + public void setMembers(Set members) { + this.members = members; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/unidirectional/AbstractContainedEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/unidirectional/AbstractContainedEntity.java index 2cdc0c1d02..1e9a813199 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/unidirectional/AbstractContainedEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/unidirectional/AbstractContainedEntity.java @@ -23,6 +23,7 @@ */ package org.hibernate.envers.test.integration.inheritance.joined.relation.unidirectional; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; @@ -43,9 +44,9 @@ public abstract class AbstractContainedEntity { @Id @GeneratedValue private Long id; - - public AbstractContainedEntity() { - } + + public AbstractContainedEntity() { + } public Long getId() { return id; @@ -57,12 +58,18 @@ public abstract class AbstractContainedEntity { @Override public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof AbstractContainedEntity)) return false; + if ( this == o ) { + return true; + } + if ( !(o instanceof AbstractContainedEntity) ) { + return false; + } AbstractContainedEntity that = (AbstractContainedEntity) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } return true; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/unidirectional/AbstractSetEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/unidirectional/AbstractSetEntity.java index 33f911dddf..9eceab993d 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/unidirectional/AbstractSetEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/unidirectional/AbstractSetEntity.java @@ -23,8 +23,7 @@ */ package org.hibernate.envers.test.integration.inheritance.joined.relation.unidirectional; -import java.util.HashSet; -import java.util.Set; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; @@ -32,6 +31,8 @@ import javax.persistence.Inheritance; import javax.persistence.InheritanceType; import javax.persistence.OneToMany; import javax.persistence.Table; +import java.util.HashSet; +import java.util.Set; import org.hibernate.envers.Audited; @@ -43,23 +44,23 @@ import org.hibernate.envers.Audited; @Inheritance(strategy = InheritanceType.JOINED) @Audited public abstract class AbstractSetEntity { - @Id + @Id @GeneratedValue - private Integer id; + private Integer id; - @OneToMany - private Set entities = new HashSet(); + @OneToMany + private Set entities = new HashSet(); - public AbstractSetEntity() { - } + public AbstractSetEntity() { + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } public Set getEntities() { return entities; diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/unidirectional/ContainedEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/unidirectional/ContainedEntity.java index 81b99d953b..06130466f6 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/unidirectional/ContainedEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/unidirectional/ContainedEntity.java @@ -23,6 +23,7 @@ */ package org.hibernate.envers.test.integration.inheritance.joined.relation.unidirectional; + import javax.persistence.Entity; import javax.persistence.Table; @@ -34,5 +35,5 @@ import org.hibernate.envers.Audited; @Entity @Table(name = "Contained") @Audited -public class ContainedEntity extends AbstractContainedEntity { +public class ContainedEntity extends AbstractContainedEntity { } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/unidirectional/SetEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/unidirectional/SetEntity.java index 559a6d3640..9215585244 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/unidirectional/SetEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/unidirectional/SetEntity.java @@ -23,6 +23,7 @@ */ package org.hibernate.envers.test.integration.inheritance.joined.relation.unidirectional; + import javax.persistence.Entity; import org.hibernate.envers.Audited; diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/unidirectional/UnidirectionalDoubleAbstract.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/unidirectional/UnidirectionalDoubleAbstract.java index cbab8cb8ed..b959f0fb4b 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/unidirectional/UnidirectionalDoubleAbstract.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/unidirectional/UnidirectionalDoubleAbstract.java @@ -24,15 +24,15 @@ package org.hibernate.envers.test.integration.inheritance.joined.relation.unidirectional; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.Set; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ @@ -48,42 +48,42 @@ public class UnidirectionalDoubleAbstract extends BaseEnversJPAFunctionalTestCas ContainedEntity.class, SetEntity.class }; - } + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - // Rev 1 - em.getTransaction().begin(); + // Rev 1 + em.getTransaction().begin(); - ContainedEntity cce1 = new ContainedEntity(); - em.persist(cce1); + ContainedEntity cce1 = new ContainedEntity(); + em.persist( cce1 ); SetEntity cse1 = new SetEntity(); - cse1.getEntities().add(cce1); - em.persist(cse1); + cse1.getEntities().add( cce1 ); + em.persist( cse1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); cce1_id = cce1.getId(); cse1_id = cse1.getId(); - } + } @Test - public void testRevisionsCounts() { - assert Arrays.asList(1).equals(getAuditReader().getRevisions(ContainedEntity.class, cce1_id)); - assert Arrays.asList(1).equals(getAuditReader().getRevisions(SetEntity.class, cse1_id)); - } + public void testRevisionsCounts() { + assert Arrays.asList( 1 ).equals( getAuditReader().getRevisions( ContainedEntity.class, cce1_id ) ); + assert Arrays.asList( 1 ).equals( getAuditReader().getRevisions( SetEntity.class, cse1_id ) ); + } - @Test - public void testHistoryOfReferencedCollection() { - ContainedEntity cce1 = getEntityManager().find(ContainedEntity.class, cce1_id); + @Test + public void testHistoryOfReferencedCollection() { + ContainedEntity cce1 = getEntityManager().find( ContainedEntity.class, cce1_id ); - Set entities = getAuditReader().find(SetEntity.class, cse1_id, 1).getEntities(); - assert entities.size() == 1; + Set entities = getAuditReader().find( SetEntity.class, cse1_id, 1 ).getEntities(); + assert entities.size() == 1; assert entities.iterator().next() instanceof ContainedEntity; - assert entities.contains(cce1); - } + assert entities.contains( cce1 ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/MixedInheritanceStrategiesEntityTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/MixedInheritanceStrategiesEntityTest.java index e676e3659d..5b9354e76d 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/MixedInheritanceStrategiesEntityTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/MixedInheritanceStrategiesEntityTest.java @@ -2,8 +2,6 @@ package org.hibernate.envers.test.integration.inheritance.mixed; import java.util.Arrays; -import org.junit.Test; - import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.integration.inheritance.mixed.entities.AbstractActivity; @@ -13,12 +11,14 @@ import org.hibernate.envers.test.integration.inheritance.mixed.entities.Activity import org.hibernate.envers.test.integration.inheritance.mixed.entities.CheckInActivity; import org.hibernate.envers.test.integration.inheritance.mixed.entities.NormalActivity; +import org.junit.Test; + import static org.junit.Assert.assertEquals; /** * @author Michal Skowronek (mskowr at o2 pl) */ -public class MixedInheritanceStrategiesEntityTest extends BaseEnversJPAFunctionalTestCase { +public class MixedInheritanceStrategiesEntityTest extends BaseEnversJPAFunctionalTestCase { private ActivityId id2; private ActivityId id1; @@ -32,117 +32,117 @@ public class MixedInheritanceStrategiesEntityTest extends BaseEnversJPAFunctiona CheckInActivity.class, NormalActivity.class }; - } + } - @Test - @Priority(10) - public void initData() { - NormalActivity normalActivity = new NormalActivity(); - id1 = new ActivityId(1, 2); - normalActivity.setId(id1); - normalActivity.setSequenceNumber(1); + @Test + @Priority(10) + public void initData() { + NormalActivity normalActivity = new NormalActivity(); + id1 = new ActivityId( 1, 2 ); + normalActivity.setId( id1 ); + normalActivity.setSequenceNumber( 1 ); - // Revision 1 - getEntityManager().getTransaction().begin(); + // Revision 1 + getEntityManager().getTransaction().begin(); - getEntityManager().persist(normalActivity); + getEntityManager().persist( normalActivity ); - getEntityManager().getTransaction().commit(); - // Revision 2 - getEntityManager().getTransaction().begin(); + getEntityManager().getTransaction().commit(); + // Revision 2 + getEntityManager().getTransaction().begin(); - normalActivity = getEntityManager().find(NormalActivity.class, id1); - CheckInActivity checkInActivity = new CheckInActivity(); - id2 = new ActivityId(2, 3); - checkInActivity.setId(id2); - checkInActivity.setSequenceNumber(0); - checkInActivity.setDurationInMinutes(30); - checkInActivity.setRelatedActivity(normalActivity); + normalActivity = getEntityManager().find( NormalActivity.class, id1 ); + CheckInActivity checkInActivity = new CheckInActivity(); + id2 = new ActivityId( 2, 3 ); + checkInActivity.setId( id2 ); + checkInActivity.setSequenceNumber( 0 ); + checkInActivity.setDurationInMinutes( 30 ); + checkInActivity.setRelatedActivity( normalActivity ); - getEntityManager().persist(checkInActivity); + getEntityManager().persist( checkInActivity ); - getEntityManager().getTransaction().commit(); + getEntityManager().getTransaction().commit(); - // Revision 3 - normalActivity = new NormalActivity(); - id3 = new ActivityId(3, 4); - normalActivity.setId(id3); - normalActivity.setSequenceNumber(2); + // Revision 3 + normalActivity = new NormalActivity(); + id3 = new ActivityId( 3, 4 ); + normalActivity.setId( id3 ); + normalActivity.setSequenceNumber( 2 ); - getEntityManager().getTransaction().begin(); + getEntityManager().getTransaction().begin(); - getEntityManager().persist(normalActivity); + getEntityManager().persist( normalActivity ); - getEntityManager().getTransaction().commit(); + getEntityManager().getTransaction().commit(); - // Revision 4 - getEntityManager().getTransaction().begin(); + // Revision 4 + getEntityManager().getTransaction().begin(); - normalActivity = getEntityManager().find(NormalActivity.class, id3); - checkInActivity = getEntityManager().find(CheckInActivity.class, id2); - checkInActivity.setRelatedActivity(normalActivity); + normalActivity = getEntityManager().find( NormalActivity.class, id3 ); + checkInActivity = getEntityManager().find( CheckInActivity.class, id2 ); + checkInActivity.setRelatedActivity( normalActivity ); - getEntityManager().merge(checkInActivity); + getEntityManager().merge( checkInActivity ); - getEntityManager().getTransaction().commit(); - } + getEntityManager().getTransaction().commit(); + } - @Test - public void testRevisionsCounts() { - assertEquals(Arrays.asList(1), getAuditReader().getRevisions(NormalActivity.class, id1)); - assertEquals(Arrays.asList(3), getAuditReader().getRevisions(NormalActivity.class, id3)); - assertEquals(Arrays.asList(2, 4), getAuditReader().getRevisions(CheckInActivity.class, id2)); - } + @Test + public void testRevisionsCounts() { + assertEquals( Arrays.asList( 1 ), getAuditReader().getRevisions( NormalActivity.class, id1 ) ); + assertEquals( Arrays.asList( 3 ), getAuditReader().getRevisions( NormalActivity.class, id3 ) ); + assertEquals( Arrays.asList( 2, 4 ), getAuditReader().getRevisions( CheckInActivity.class, id2 ) ); + } - @Test - public void testCurrentStateOfCheckInActivity() { + @Test + public void testCurrentStateOfCheckInActivity() { - final CheckInActivity checkInActivity = getEntityManager().find(CheckInActivity.class, id2); - final NormalActivity normalActivity = getEntityManager().find(NormalActivity.class, id3); + final CheckInActivity checkInActivity = getEntityManager().find( CheckInActivity.class, id2 ); + final NormalActivity normalActivity = getEntityManager().find( NormalActivity.class, id3 ); - assertEquals(id2, checkInActivity.getId()); - assertEquals(0, checkInActivity.getSequenceNumber().intValue()); - assertEquals(30, checkInActivity.getDurationInMinutes().intValue()); - final Activity relatedActivity = checkInActivity.getRelatedActivity(); - assertEquals(normalActivity.getId(), relatedActivity.getId()); - assertEquals(normalActivity.getSequenceNumber(), relatedActivity.getSequenceNumber()); - } + assertEquals( id2, checkInActivity.getId() ); + assertEquals( 0, checkInActivity.getSequenceNumber().intValue() ); + assertEquals( 30, checkInActivity.getDurationInMinutes().intValue() ); + final Activity relatedActivity = checkInActivity.getRelatedActivity(); + assertEquals( normalActivity.getId(), relatedActivity.getId() ); + assertEquals( normalActivity.getSequenceNumber(), relatedActivity.getSequenceNumber() ); + } - @Test - public void testCheckCurrentStateOfNormalActivities() throws Exception { - final NormalActivity normalActivity1 = getEntityManager().find(NormalActivity.class, id1); - final NormalActivity normalActivity2 = getEntityManager().find(NormalActivity.class, id3); + @Test + public void testCheckCurrentStateOfNormalActivities() throws Exception { + final NormalActivity normalActivity1 = getEntityManager().find( NormalActivity.class, id1 ); + final NormalActivity normalActivity2 = getEntityManager().find( NormalActivity.class, id3 ); - assertEquals(id1, normalActivity1.getId()); - assertEquals(1, normalActivity1.getSequenceNumber().intValue()); - assertEquals(id3, normalActivity2.getId()); - assertEquals(2, normalActivity2.getSequenceNumber().intValue()); - } + assertEquals( id1, normalActivity1.getId() ); + assertEquals( 1, normalActivity1.getSequenceNumber().intValue() ); + assertEquals( id3, normalActivity2.getId() ); + assertEquals( 2, normalActivity2.getSequenceNumber().intValue() ); + } - @Test - public void doTestFirstRevisionOfCheckInActivity() throws Exception { - CheckInActivity checkInActivity = getAuditReader().find(CheckInActivity.class, id2, 2); - NormalActivity normalActivity = getAuditReader().find(NormalActivity.class, id1, 2); + @Test + public void doTestFirstRevisionOfCheckInActivity() throws Exception { + CheckInActivity checkInActivity = getAuditReader().find( CheckInActivity.class, id2, 2 ); + NormalActivity normalActivity = getAuditReader().find( NormalActivity.class, id1, 2 ); - assertEquals(id2, checkInActivity.getId()); - assertEquals(0, checkInActivity.getSequenceNumber().intValue()); - assertEquals(30, checkInActivity.getDurationInMinutes().intValue()); - Activity relatedActivity = checkInActivity.getRelatedActivity(); - assertEquals(normalActivity.getId(), relatedActivity.getId()); - assertEquals(normalActivity.getSequenceNumber(), relatedActivity.getSequenceNumber()); - } + assertEquals( id2, checkInActivity.getId() ); + assertEquals( 0, checkInActivity.getSequenceNumber().intValue() ); + assertEquals( 30, checkInActivity.getDurationInMinutes().intValue() ); + Activity relatedActivity = checkInActivity.getRelatedActivity(); + assertEquals( normalActivity.getId(), relatedActivity.getId() ); + assertEquals( normalActivity.getSequenceNumber(), relatedActivity.getSequenceNumber() ); + } - @Test - public void doTestSecondRevisionOfCheckInActivity() throws Exception { - CheckInActivity checkInActivity = getAuditReader().find(CheckInActivity.class, id2, 4); - NormalActivity normalActivity = getAuditReader().find(NormalActivity.class, id3, 4); + @Test + public void doTestSecondRevisionOfCheckInActivity() throws Exception { + CheckInActivity checkInActivity = getAuditReader().find( CheckInActivity.class, id2, 4 ); + NormalActivity normalActivity = getAuditReader().find( NormalActivity.class, id3, 4 ); - assertEquals(id2, checkInActivity.getId()); - assertEquals(0, checkInActivity.getSequenceNumber().intValue()); - assertEquals(30, checkInActivity.getDurationInMinutes().intValue()); - Activity relatedActivity = checkInActivity.getRelatedActivity(); - assertEquals(normalActivity.getId(), relatedActivity.getId()); - assertEquals(normalActivity.getSequenceNumber(), relatedActivity.getSequenceNumber()); - } + assertEquals( id2, checkInActivity.getId() ); + assertEquals( 0, checkInActivity.getSequenceNumber().intValue() ); + assertEquals( 30, checkInActivity.getDurationInMinutes().intValue() ); + Activity relatedActivity = checkInActivity.getRelatedActivity(); + assertEquals( normalActivity.getId(), relatedActivity.getId() ); + assertEquals( normalActivity.getSequenceNumber(), relatedActivity.getSequenceNumber() ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/entities/AbstractActivity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/entities/AbstractActivity.java index 23d6e5c077..85ec767bfe 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/entities/AbstractActivity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/entities/AbstractActivity.java @@ -12,23 +12,23 @@ import org.hibernate.envers.Audited; @Inheritance(strategy = InheritanceType.SINGLE_TABLE) public abstract class AbstractActivity implements Activity { @EmbeddedId - private ActivityId id; + private ActivityId id; - private Integer sequenceNumber; + private Integer sequenceNumber; - public ActivityId getId() { - return id; - } + public ActivityId getId() { + return id; + } - public void setId(ActivityId id) { - this.id = id; - } + public void setId(ActivityId id) { + this.id = id; + } public Integer getSequenceNumber() { - return sequenceNumber; - } + return sequenceNumber; + } - public void setSequenceNumber(Integer sequenceNumber) { - this.sequenceNumber = sequenceNumber; - } + public void setSequenceNumber(Integer sequenceNumber) { + this.sequenceNumber = sequenceNumber; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/entities/AbstractCheckActivity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/entities/AbstractCheckActivity.java index afc36effa7..4b8c37779b 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/entities/AbstractCheckActivity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/entities/AbstractCheckActivity.java @@ -17,29 +17,33 @@ import org.hibernate.envers.Audited; @Entity @DiscriminatorValue(value = "CHECK") @SecondaryTable(name = "ACTIVITY_CHECK", - pkJoinColumns = {@PrimaryKeyJoinColumn(name = "ACTIVITY_ID"), - @PrimaryKeyJoinColumn(name = "ACTIVITY_ID2")}) + pkJoinColumns = { + @PrimaryKeyJoinColumn(name = "ACTIVITY_ID"), + @PrimaryKeyJoinColumn(name = "ACTIVITY_ID2") + }) public abstract class AbstractCheckActivity extends AbstractActivity { - @Column(table = "ACTIVITY_CHECK") - private Integer durationInMinutes; - @ManyToOne(targetEntity = AbstractActivity.class, cascade = CascadeType.MERGE, fetch = FetchType.LAZY) - @JoinColumns({@JoinColumn(table = "ACTIVITY_CHECK", referencedColumnName = "id"), - @JoinColumn(table = "ACTIVITY_CHECK", referencedColumnName = "id2")}) - private Activity relatedActivity; + @Column(table = "ACTIVITY_CHECK") + private Integer durationInMinutes; + @ManyToOne(targetEntity = AbstractActivity.class, cascade = CascadeType.MERGE, fetch = FetchType.LAZY) + @JoinColumns({ + @JoinColumn(table = "ACTIVITY_CHECK", referencedColumnName = "id"), + @JoinColumn(table = "ACTIVITY_CHECK", referencedColumnName = "id2") + }) + private Activity relatedActivity; - public Integer getDurationInMinutes() { - return durationInMinutes; - } + public Integer getDurationInMinutes() { + return durationInMinutes; + } - public void setDurationInMinutes(Integer durationInMinutes) { - this.durationInMinutes = durationInMinutes; - } + public void setDurationInMinutes(Integer durationInMinutes) { + this.durationInMinutes = durationInMinutes; + } - public Activity getRelatedActivity() { - return relatedActivity; - } + public Activity getRelatedActivity() { + return relatedActivity; + } - public void setRelatedActivity(Activity relatedActivity) { - this.relatedActivity = relatedActivity; - } + public void setRelatedActivity(Activity relatedActivity) { + this.relatedActivity = relatedActivity; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/entities/Activity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/entities/Activity.java index ee35f3926f..7db86b0c89 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/entities/Activity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/entities/Activity.java @@ -5,5 +5,5 @@ import java.io.Serializable; public interface Activity extends Serializable { ActivityId getId(); - Integer getSequenceNumber(); + Integer getSequenceNumber(); } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/entities/ActivityId.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/entities/ActivityId.java index c776f165d4..b6333b42e5 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/entities/ActivityId.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/entities/ActivityId.java @@ -1,7 +1,7 @@ package org.hibernate.envers.test.integration.inheritance.mixed.entities; -import java.io.Serializable; import javax.persistence.Embeddable; +import java.io.Serializable; @Embeddable public class ActivityId implements Serializable { @@ -34,14 +34,14 @@ public class ActivityId implements Serializable { @Override public boolean equals(Object obj) { - if (obj == null) { + if ( obj == null ) { return true; } - if (!(obj instanceof ActivityId)) { + if ( !(obj instanceof ActivityId) ) { return false; } ActivityId id = (ActivityId) obj; - return getId().equals(id.getId()) && getId2().equals(id.getId2()); + return getId().equals( id.getId() ) && getId2().equals( id.getId2() ); } @Override diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/entities/CheckInActivity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/entities/CheckInActivity.java index f5943cb2da..c8adb252b6 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/entities/CheckInActivity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/entities/CheckInActivity.java @@ -10,21 +10,21 @@ import org.hibernate.envers.Audited; @DiscriminatorValue(value = "CHECK_IN") public class CheckInActivity extends AbstractCheckActivity { - @Override - public boolean equals(Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof CheckInActivity)) { - return false; - } - CheckInActivity checkInActivity = (CheckInActivity) obj; - return getId().equals(checkInActivity.getId()); - } + @Override + public boolean equals(Object obj) { + if ( obj == this ) { + return true; + } + if ( !(obj instanceof CheckInActivity) ) { + return false; + } + CheckInActivity checkInActivity = (CheckInActivity) obj; + return getId().equals( checkInActivity.getId() ); + } - @Override - public int hashCode() { - return getId().hashCode(); - } + @Override + public int hashCode() { + return getId().hashCode(); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/entities/NormalActivity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/entities/NormalActivity.java index d389aea408..edfac4f95a 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/entities/NormalActivity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/entities/NormalActivity.java @@ -10,20 +10,20 @@ import org.hibernate.envers.Audited; @DiscriminatorValue(value = "NORMAL") public class NormalActivity extends AbstractActivity { - @Override - public boolean equals(Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof NormalActivity)) { - return false; - } - NormalActivity normalActivity = (NormalActivity) obj; - return getId().equals(normalActivity.getId()); - } + @Override + public boolean equals(Object obj) { + if ( obj == this ) { + return true; + } + if ( !(obj instanceof NormalActivity) ) { + return false; + } + NormalActivity normalActivity = (NormalActivity) obj; + return getId().equals( normalActivity.getId() ); + } - @Override - public int hashCode() { - return getId().hashCode(); - } + @Override + public int hashCode() { + return getId().hashCode(); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/ChildAuditing.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/ChildAuditing.java index ad117adbf5..fdd37c1cdd 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/ChildAuditing.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/ChildAuditing.java @@ -23,70 +23,70 @@ */ package org.hibernate.envers.test.integration.inheritance.single; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class ChildAuditing extends BaseEnversJPAFunctionalTestCase { - private Integer id1; + private Integer id1; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { ChildEntity.class, ParentEntity.class }; + return new Class[] {ChildEntity.class, ParentEntity.class}; } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - // Rev 1 - em.getTransaction().begin(); - ChildEntity ce = new ChildEntity("x", 1l); - em.persist(ce); - id1 = ce.getId(); - em.getTransaction().commit(); + // Rev 1 + em.getTransaction().begin(); + ChildEntity ce = new ChildEntity( "x", 1l ); + em.persist( ce ); + id1 = ce.getId(); + em.getTransaction().commit(); - // Rev 2 - em.getTransaction().begin(); - ce = em.find(ChildEntity.class, id1); - ce.setData("y"); - ce.setNumVal(2l); - em.getTransaction().commit(); - } + // Rev 2 + em.getTransaction().begin(); + ce = em.find( ChildEntity.class, id1 ); + ce.setData( "y" ); + ce.setNumVal( 2l ); + em.getTransaction().commit(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(ChildEntity.class, id1)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( ChildEntity.class, id1 ) ); + } - @Test - public void testHistoryOfChildId1() { - ChildEntity ver1 = new ChildEntity(id1, "x", 1l); - ChildEntity ver2 = new ChildEntity(id1, "y", 2l); + @Test + public void testHistoryOfChildId1() { + ChildEntity ver1 = new ChildEntity( id1, "x", 1l ); + ChildEntity ver2 = new ChildEntity( id1, "y", 2l ); - assert getAuditReader().find(ChildEntity.class, id1, 1).equals(ver1); - assert getAuditReader().find(ChildEntity.class, id1, 2).equals(ver2); + assert getAuditReader().find( ChildEntity.class, id1, 1 ).equals( ver1 ); + assert getAuditReader().find( ChildEntity.class, id1, 2 ).equals( ver2 ); - assert getAuditReader().find(ParentEntity.class, id1, 1).equals(ver1); - assert getAuditReader().find(ParentEntity.class, id1, 2).equals(ver2); - } + assert getAuditReader().find( ParentEntity.class, id1, 1 ).equals( ver1 ); + assert getAuditReader().find( ParentEntity.class, id1, 2 ).equals( ver2 ); + } - @Test - public void testPolymorphicQuery() { - ChildEntity childVer1 = new ChildEntity(id1, "x", 1l); + @Test + public void testPolymorphicQuery() { + ChildEntity childVer1 = new ChildEntity( id1, "x", 1l ); - assert getAuditReader().createQuery().forEntitiesAtRevision(ChildEntity.class, 1).getSingleResult() - .equals(childVer1); + assert getAuditReader().createQuery().forEntitiesAtRevision( ChildEntity.class, 1 ).getSingleResult() + .equals( childVer1 ); - assert getAuditReader().createQuery().forEntitiesAtRevision(ParentEntity.class, 1).getSingleResult() - .equals(childVer1); - } + assert getAuditReader().createQuery().forEntitiesAtRevision( ParentEntity.class, 1 ).getSingleResult() + .equals( childVer1 ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/ChildEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/ChildEntity.java index e12dd722e4..292f6f9043 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/ChildEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/ChildEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.inheritance.single; + import javax.persistence.Basic; import javax.persistence.DiscriminatorValue; import javax.persistence.Entity; @@ -35,49 +36,57 @@ import org.hibernate.envers.Audited; @DiscriminatorValue("2") @Audited public class ChildEntity extends ParentEntity { - @Basic - private Long numVal; + @Basic + private Long numVal; - public ChildEntity() { - } + public ChildEntity() { + } - public ChildEntity(String data, Long numVal) { - super(data); - this.numVal = numVal; - } + public ChildEntity(String data, Long numVal) { + super( data ); + this.numVal = numVal; + } - public ChildEntity(Integer id, String data, Long numVal) { - super(id, data); - this.numVal = numVal; - } + public ChildEntity(Integer id, String data, Long numVal) { + super( id, data ); + this.numVal = numVal; + } - public Long getNumVal() { - return numVal; - } + public Long getNumVal() { + return numVal; + } - public void setNumVal(Long numVal) { - this.numVal = numVal; - } + public void setNumVal(Long numVal) { + this.numVal = numVal; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ChildEntity)) return false; - if (!super.equals(o)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ChildEntity) ) { + return false; + } + if ( !super.equals( o ) ) { + return false; + } - ChildEntity childEntity = (ChildEntity) o; + ChildEntity childEntity = (ChildEntity) o; - if (numVal != null ? !numVal.equals(childEntity.numVal) : childEntity.numVal != null) return false; + if ( numVal != null ? !numVal.equals( childEntity.numVal ) : childEntity.numVal != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result = super.hashCode(); - result = 31 * result + (numVal != null ? numVal.hashCode() : 0); - return result; - } + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (numVal != null ? numVal.hashCode() : 0); + return result; + } - public String toString() { - return "ChildPrimaryKeyJoinEntity(id = " + getId() + ", data = " + getData() + ", numVal = " + numVal + ")"; - } + public String toString() { + return "ChildPrimaryKeyJoinEntity(id = " + getId() + ", data = " + getData() + ", numVal = " + numVal + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/ParentAuditing.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/ParentAuditing.java index e1869bb8af..d2e1e731a5 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/ParentAuditing.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/ParentAuditing.java @@ -23,71 +23,71 @@ */ package org.hibernate.envers.test.integration.inheritance.single; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class ParentAuditing extends BaseEnversJPAFunctionalTestCase { - private Integer id1; + private Integer id1; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { ChildEntity.class, ParentEntity.class }; - } + return new Class[] {ChildEntity.class, ParentEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - // Rev 1 - em.getTransaction().begin(); - ParentEntity pe = new ParentEntity("x"); - em.persist(pe); - id1 = pe.getId(); - em.getTransaction().commit(); + // Rev 1 + em.getTransaction().begin(); + ParentEntity pe = new ParentEntity( "x" ); + em.persist( pe ); + id1 = pe.getId(); + em.getTransaction().commit(); - // Rev 2 - em.getTransaction().begin(); - pe = em.find(ParentEntity.class, id1); - pe.setData("y"); - em.getTransaction().commit(); - } + // Rev 2 + em.getTransaction().begin(); + pe = em.find( ParentEntity.class, id1 ); + pe.setData( "y" ); + em.getTransaction().commit(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(ParentEntity.class, id1)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( ParentEntity.class, id1 ) ); + } - @Test - public void testHistoryOfChildId1() { - assert getAuditReader().find(ChildEntity.class, id1, 1) == null; - assert getAuditReader().find(ChildEntity.class, id1, 2) == null; - } + @Test + public void testHistoryOfChildId1() { + assert getAuditReader().find( ChildEntity.class, id1, 1 ) == null; + assert getAuditReader().find( ChildEntity.class, id1, 2 ) == null; + } - @Test - public void testHistoryOfParentId1() { - ParentEntity ver1 = new ParentEntity(id1, "x"); - ParentEntity ver2 = new ParentEntity(id1, "y"); + @Test + public void testHistoryOfParentId1() { + ParentEntity ver1 = new ParentEntity( id1, "x" ); + ParentEntity ver2 = new ParentEntity( id1, "y" ); - assert getAuditReader().find(ParentEntity.class, id1, 1).equals(ver1); - assert getAuditReader().find(ParentEntity.class, id1, 2).equals(ver2); - } + assert getAuditReader().find( ParentEntity.class, id1, 1 ).equals( ver1 ); + assert getAuditReader().find( ParentEntity.class, id1, 2 ).equals( ver2 ); + } - @Test - public void testPolymorphicQuery() { - ParentEntity parentVer1 = new ParentEntity(id1, "x"); + @Test + public void testPolymorphicQuery() { + ParentEntity parentVer1 = new ParentEntity( id1, "x" ); - assert getAuditReader().createQuery().forEntitiesAtRevision(ParentEntity.class, 1).getSingleResult() - .equals(parentVer1); - assert getAuditReader().createQuery().forEntitiesAtRevision(ChildEntity.class, 1) - .getResultList().size() == 0; - } + assert getAuditReader().createQuery().forEntitiesAtRevision( ParentEntity.class, 1 ).getSingleResult() + .equals( parentVer1 ); + assert getAuditReader().createQuery().forEntitiesAtRevision( ChildEntity.class, 1 ) + .getResultList().size() == 0; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/ParentEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/ParentEntity.java index e3104ddd15..7a5085b729 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/ParentEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/ParentEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.inheritance.single; + import javax.persistence.Basic; import javax.persistence.DiscriminatorColumn; import javax.persistence.DiscriminatorType; @@ -43,61 +44,69 @@ import org.hibernate.envers.Audited; @DiscriminatorValue("1") @Audited public class ParentEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - @Basic - private String data; + @Basic + private String data; - public ParentEntity() { - } + public ParentEntity() { + } - public ParentEntity(String data) { - this.data = data; - } + public ParentEntity(String data) { + this.data = data; + } - public ParentEntity(Integer id, String data) { - this.id = id; - this.data = data; - } + public ParentEntity(Integer id, String data) { + this.id = id; + this.data = data; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ParentEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ParentEntity) ) { + return false; + } - ParentEntity that = (ParentEntity) o; + ParentEntity that = (ParentEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "ParentEntity(id = " + getId() + ", data = " + getData() + ")"; - } + public String toString() { + return "ParentEntity(id = " + getId() + ", data = " + getData() + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/childrelation/ChildIngEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/childrelation/ChildIngEntity.java index 2e8c0075b0..2539270640 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/childrelation/ChildIngEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/childrelation/ChildIngEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.inheritance.single.childrelation; + import javax.persistence.Basic; import javax.persistence.DiscriminatorValue; import javax.persistence.Entity; @@ -36,60 +37,68 @@ import org.hibernate.envers.Audited; @DiscriminatorValue("2") @Audited public class ChildIngEntity extends ParentNotIngEntity { - @Basic - private Long numVal; + @Basic + private Long numVal; - @ManyToOne - private ReferencedEntity referenced; + @ManyToOne + private ReferencedEntity referenced; - public ChildIngEntity() { - } + public ChildIngEntity() { + } - public ChildIngEntity(String data, Long numVal) { - super(data); - this.numVal = numVal; - } + public ChildIngEntity(String data, Long numVal) { + super( data ); + this.numVal = numVal; + } - public ChildIngEntity(Integer id, String data, Long numVal) { - super(id, data); - this.numVal = numVal; - } + public ChildIngEntity(Integer id, String data, Long numVal) { + super( id, data ); + this.numVal = numVal; + } - public Long getNumVal() { - return numVal; - } + public Long getNumVal() { + return numVal; + } - public void setNumVal(Long numVal) { - this.numVal = numVal; - } + public void setNumVal(Long numVal) { + this.numVal = numVal; + } - public ReferencedEntity getReferenced() { - return referenced; - } + public ReferencedEntity getReferenced() { + return referenced; + } - public void setReferenced(ReferencedEntity referenced) { - this.referenced = referenced; - } + public void setReferenced(ReferencedEntity referenced) { + this.referenced = referenced; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ChildIngEntity)) return false; - if (!super.equals(o)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ChildIngEntity) ) { + return false; + } + if ( !super.equals( o ) ) { + return false; + } - ChildIngEntity childEntity = (ChildIngEntity) o; + ChildIngEntity childEntity = (ChildIngEntity) o; - if (numVal != null ? !numVal.equals(childEntity.numVal) : childEntity.numVal != null) return false; + if ( numVal != null ? !numVal.equals( childEntity.numVal ) : childEntity.numVal != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result = super.hashCode(); - result = 31 * result + (numVal != null ? numVal.hashCode() : 0); - return result; - } + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (numVal != null ? numVal.hashCode() : 0); + return result; + } - public String toString() { - return "ChildIngEntity(id = " + getId() + ", data = " + getData() + ", numVal = " + numVal + ")"; - } + public String toString() { + return "ChildIngEntity(id = " + getId() + ", data = " + getData() + ", numVal = " + numVal + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/childrelation/ChildReferencing.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/childrelation/ChildReferencing.java index c1d901a5e6..980bf517ad 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/childrelation/ChildReferencing.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/childrelation/ChildReferencing.java @@ -23,98 +23,102 @@ */ package org.hibernate.envers.test.integration.inheritance.single.childrelation; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.tools.TestTools; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class ChildReferencing extends BaseEnversJPAFunctionalTestCase { - private Integer re_id1; - private Integer re_id2; - private Integer c_id; + private Integer re_id1; + private Integer re_id2; + private Integer c_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { ChildIngEntity.class, ParentNotIngEntity.class, ReferencedEntity.class }; - } + return new Class[] {ChildIngEntity.class, ParentNotIngEntity.class, ReferencedEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - // Rev 1 - em.getTransaction().begin(); + // Rev 1 + em.getTransaction().begin(); - ReferencedEntity re1 = new ReferencedEntity(); - em.persist(re1); - re_id1 = re1.getId(); + ReferencedEntity re1 = new ReferencedEntity(); + em.persist( re1 ); + re_id1 = re1.getId(); - ReferencedEntity re2 = new ReferencedEntity(); - em.persist(re2); - re_id2 = re2.getId(); + ReferencedEntity re2 = new ReferencedEntity(); + em.persist( re2 ); + re_id2 = re2.getId(); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Rev 2 - em.getTransaction().begin(); + // Rev 2 + em.getTransaction().begin(); - re1 = em.find(ReferencedEntity.class, re_id1); + re1 = em.find( ReferencedEntity.class, re_id1 ); - ChildIngEntity cie = new ChildIngEntity("y", 1l); - cie.setReferenced(re1); - em.persist(cie); - c_id = cie.getId(); + ChildIngEntity cie = new ChildIngEntity( "y", 1l ); + cie.setReferenced( re1 ); + em.persist( cie ); + c_id = cie.getId(); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Rev 3 - em.getTransaction().begin(); + // Rev 3 + em.getTransaction().begin(); - re2 = em.find(ReferencedEntity.class, re_id2); - cie = em.find(ChildIngEntity.class, c_id); + re2 = em.find( ReferencedEntity.class, re_id2 ); + cie = em.find( ChildIngEntity.class, c_id ); - cie.setReferenced(re2); + cie.setReferenced( re2 ); - em.getTransaction().commit(); - } + em.getTransaction().commit(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2, 3).equals(getAuditReader().getRevisions(ReferencedEntity.class, re_id1)); - assert Arrays.asList(1, 3).equals(getAuditReader().getRevisions(ReferencedEntity.class, re_id2)); - assert Arrays.asList(2, 3).equals(getAuditReader().getRevisions(ChildIngEntity.class, c_id)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2, 3 ).equals( getAuditReader().getRevisions( ReferencedEntity.class, re_id1 ) ); + assert Arrays.asList( 1, 3 ).equals( getAuditReader().getRevisions( ReferencedEntity.class, re_id2 ) ); + assert Arrays.asList( 2, 3 ).equals( getAuditReader().getRevisions( ChildIngEntity.class, c_id ) ); + } - @Test - public void testHistoryOfReferencedCollection1() { - assert getAuditReader().find(ReferencedEntity.class, re_id1, 1).getReferencing().size() == 0; - assert getAuditReader().find(ReferencedEntity.class, re_id1, 2).getReferencing().equals( - TestTools.makeSet(new ChildIngEntity(c_id, "y", 1l))); - assert getAuditReader().find(ReferencedEntity.class, re_id1, 3).getReferencing().size() == 0; - } + @Test + public void testHistoryOfReferencedCollection1() { + assert getAuditReader().find( ReferencedEntity.class, re_id1, 1 ).getReferencing().size() == 0; + assert getAuditReader().find( ReferencedEntity.class, re_id1, 2 ).getReferencing().equals( + TestTools.makeSet( new ChildIngEntity( c_id, "y", 1l ) ) + ); + assert getAuditReader().find( ReferencedEntity.class, re_id1, 3 ).getReferencing().size() == 0; + } - @Test - public void testHistoryOfReferencedCollection2() { - assert getAuditReader().find(ReferencedEntity.class, re_id2, 1).getReferencing().size() == 0; - assert getAuditReader().find(ReferencedEntity.class, re_id2, 2).getReferencing().size() == 0; - assert getAuditReader().find(ReferencedEntity.class, re_id2, 3).getReferencing().equals( - TestTools.makeSet(new ChildIngEntity(c_id, "y", 1l))); - } + @Test + public void testHistoryOfReferencedCollection2() { + assert getAuditReader().find( ReferencedEntity.class, re_id2, 1 ).getReferencing().size() == 0; + assert getAuditReader().find( ReferencedEntity.class, re_id2, 2 ).getReferencing().size() == 0; + assert getAuditReader().find( ReferencedEntity.class, re_id2, 3 ).getReferencing().equals( + TestTools.makeSet( new ChildIngEntity( c_id, "y", 1l ) ) + ); + } - @Test - public void testChildHistory() { - assert getAuditReader().find(ChildIngEntity.class, c_id, 1) == null; - assert getAuditReader().find(ChildIngEntity.class, c_id, 2).getReferenced().equals( - new ReferencedEntity(re_id1)); - assert getAuditReader().find(ChildIngEntity.class, c_id, 3).getReferenced().equals( - new ReferencedEntity(re_id2)); - } + @Test + public void testChildHistory() { + assert getAuditReader().find( ChildIngEntity.class, c_id, 1 ) == null; + assert getAuditReader().find( ChildIngEntity.class, c_id, 2 ).getReferenced().equals( + new ReferencedEntity( re_id1 ) + ); + assert getAuditReader().find( ChildIngEntity.class, c_id, 3 ).getReferenced().equals( + new ReferencedEntity( re_id2 ) + ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/childrelation/ParentNotIngEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/childrelation/ParentNotIngEntity.java index f307bc1ae6..7f36d0829c 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/childrelation/ParentNotIngEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/childrelation/ParentNotIngEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.inheritance.single.childrelation; + import javax.persistence.Basic; import javax.persistence.DiscriminatorColumn; import javax.persistence.DiscriminatorType; @@ -43,61 +44,69 @@ import org.hibernate.envers.Audited; @DiscriminatorValue("1") @Audited public class ParentNotIngEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - @Basic - private String data; + @Basic + private String data; - public ParentNotIngEntity() { - } + public ParentNotIngEntity() { + } - public ParentNotIngEntity(String data) { - this.data = data; - } + public ParentNotIngEntity(String data) { + this.data = data; + } - public ParentNotIngEntity(Integer id, String data) { - this.id = id; - this.data = data; - } + public ParentNotIngEntity(Integer id, String data) { + this.id = id; + this.data = data; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ParentNotIngEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ParentNotIngEntity) ) { + return false; + } - ParentNotIngEntity that = (ParentNotIngEntity) o; + ParentNotIngEntity that = (ParentNotIngEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "ParentNotIngEntity(id = " + getId() + ", data = " + getData() + ")"; - } + public String toString() { + return "ParentNotIngEntity(id = " + getId() + ", data = " + getData() + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/childrelation/ReferencedEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/childrelation/ReferencedEntity.java index 4782c9f022..2da54c49fe 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/childrelation/ReferencedEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/childrelation/ReferencedEntity.java @@ -22,11 +22,12 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.inheritance.single.childrelation; -import java.util.Set; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.OneToMany; +import java.util.Set; import org.hibernate.envers.Audited; @@ -36,48 +37,54 @@ import org.hibernate.envers.Audited; @Entity @Audited public class ReferencedEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - @OneToMany(mappedBy = "referenced") - private Set referencing; + @OneToMany(mappedBy = "referenced") + private Set referencing; - public ReferencedEntity(Integer id) { - this.id = id; - } + public ReferencedEntity(Integer id) { + this.id = id; + } - public ReferencedEntity() { - } + public ReferencedEntity() { + } - public Set getReferencing() { - return referencing; - } + public Set getReferencing() { + return referencing; + } - public void setReferencing(Set referencing) { - this.referencing = referencing; - } + public void setReferencing(Set referencing) { + this.referencing = referencing; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ReferencedEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ReferencedEntity) ) { + return false; + } - ReferencedEntity that = (ReferencedEntity) o; + ReferencedEntity that = (ReferencedEntity) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - return id; - } + public int hashCode() { + return id; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/discriminatorformula/ChildEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/discriminatorformula/ChildEntity.java index ed10a22ecd..a4458d3d64 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/discriminatorformula/ChildEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/discriminatorformula/ChildEntity.java @@ -12,48 +12,56 @@ import org.hibernate.envers.Audited; @DiscriminatorValue(ClassTypeEntity.CHILD_TYPE) @Audited public class ChildEntity extends ParentEntity { - private String specificData; + private String specificData; - public ChildEntity() { - } + public ChildEntity() { + } - public ChildEntity(Long typeId, String data, String specificData) { - super(typeId, data); - this.specificData = specificData; - } + public ChildEntity(Long typeId, String data, String specificData) { + super( typeId, data ); + this.specificData = specificData; + } - public ChildEntity(Long id, Long typeId, String data, String specificData) { - super(id, typeId, data); - this.specificData = specificData; - } + public ChildEntity(Long id, Long typeId, String data, String specificData) { + super( id, typeId, data ); + this.specificData = specificData; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ChildEntity)) return false; - if (!super.equals(o)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ChildEntity) ) { + return false; + } + if ( !super.equals( o ) ) { + return false; + } - ChildEntity that = (ChildEntity) o; + ChildEntity that = (ChildEntity) o; - if (specificData != null ? !specificData.equals(that.specificData) : that.specificData != null) return false; + if ( specificData != null ? !specificData.equals( that.specificData ) : that.specificData != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result = super.hashCode(); - result = 31 * result + (specificData != null ? specificData.hashCode() : 0); - return result; - } + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (specificData != null ? specificData.hashCode() : 0); + return result; + } - public String toString() { - return "ChildEntity(id = " + id + ", typeId = " + typeId + ", data = " + data + ", specificData = " + specificData + ")"; - } + public String toString() { + return "ChildEntity(id = " + id + ", typeId = " + typeId + ", data = " + data + ", specificData = " + specificData + ")"; + } - public String getSpecificData() { - return specificData; - } + public String getSpecificData() { + return specificData; + } - public void setSpecificData(String specificData) { - this.specificData = specificData; - } + public void setSpecificData(String specificData) { + this.specificData = specificData; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/discriminatorformula/ClassTypeEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/discriminatorformula/ClassTypeEntity.java index e3ba0f5f9e..b9f2152a65 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/discriminatorformula/ClassTypeEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/discriminatorformula/ClassTypeEntity.java @@ -9,51 +9,59 @@ import javax.persistence.Id; */ @Entity public class ClassTypeEntity { - public static final String PARENT_TYPE = "Parent"; - public static final String CHILD_TYPE = "Child"; + public static final String PARENT_TYPE = "Parent"; + public static final String CHILD_TYPE = "Child"; - @Id - @GeneratedValue - private Long id; + @Id + @GeneratedValue + private Long id; - private String type; + private String type; - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ClassTypeEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ClassTypeEntity) ) { + return false; + } - ClassTypeEntity that = (ClassTypeEntity) o; + ClassTypeEntity that = (ClassTypeEntity) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; - if (type != null ? !type.equals(that.type) : that.type != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } + if ( type != null ? !type.equals( that.type ) : that.type != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result = super.hashCode(); - result = 31 * result + (id != null ? id.hashCode() : 0); - result = 31 * result + (type != null ? type.hashCode() : 0); - return result; - } + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (id != null ? id.hashCode() : 0); + result = 31 * result + (type != null ? type.hashCode() : 0); + return result; + } - public String toString() { - return "ClassTypeEntity(id = " + id + ", type = " + type + ")"; - } + public String toString() { + return "ClassTypeEntity(id = " + id + ", type = " + type + ")"; + } - public Long getId() { - return id; - } + public Long getId() { + return id; + } - public void setId(Long id) { - this.id = id; - } + public void setId(Long id) { + this.id = id; + } - public String getType() { - return type; - } + public String getType() { + return type; + } - public void setType(String type) { - this.type = type; - } + public void setType(String type) { + this.type = type; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/discriminatorformula/DiscriminatorFormulaTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/discriminatorformula/DiscriminatorFormulaTest.java index 7229926fe2..d471294988 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/discriminatorformula/DiscriminatorFormulaTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/discriminatorformula/DiscriminatorFormulaTest.java @@ -1,130 +1,158 @@ package org.hibernate.envers.test.integration.inheritance.single.discriminatorformula; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.Iterator; import java.util.List; -import javax.persistence.EntityManager; - -import org.junit.Assert; -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.mapping.Formula; import org.hibernate.mapping.PersistentClass; +import org.junit.Assert; +import org.junit.Test; + /** * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public class DiscriminatorFormulaTest extends BaseEnversJPAFunctionalTestCase { - private PersistentClass parentAudit = null; - private ChildEntity childVer1 = null; - private ChildEntity childVer2 = null; - private ParentEntity parentVer1 = null; - private ParentEntity parentVer2 = null; + private PersistentClass parentAudit = null; + private ChildEntity childVer1 = null; + private ChildEntity childVer2 = null; + private ParentEntity parentVer1 = null; + private ParentEntity parentVer2 = null; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { ClassTypeEntity.class, ParentEntity.class, ChildEntity.class }; - } + return new Class[] {ClassTypeEntity.class, ParentEntity.class, ChildEntity.class}; + } - @Test - @Priority(10) - public void initData() { - parentAudit = getCfg().getClassMapping("org.hibernate.envers.test.integration.inheritance.single.discriminatorformula.ParentEntity_AUD"); + @Test + @Priority(10) + public void initData() { + parentAudit = getCfg().getClassMapping( + "org.hibernate.envers.test.integration.inheritance.single.discriminatorformula.ParentEntity_AUD" + ); - EntityManager em = getEntityManager(); + EntityManager em = getEntityManager(); - // Child entity type - em.getTransaction().begin(); - ClassTypeEntity childType = new ClassTypeEntity(); - childType.setType(ClassTypeEntity.CHILD_TYPE); - em.persist(childType); - Long childTypeId = childType.getId(); - em.getTransaction().commit(); + // Child entity type + em.getTransaction().begin(); + ClassTypeEntity childType = new ClassTypeEntity(); + childType.setType( ClassTypeEntity.CHILD_TYPE ); + em.persist( childType ); + Long childTypeId = childType.getId(); + em.getTransaction().commit(); - // Parent entity type - em.getTransaction().begin(); - ClassTypeEntity parentType = new ClassTypeEntity(); - parentType.setType(ClassTypeEntity.PARENT_TYPE); - em.persist(parentType); - Long parentTypeId = parentType.getId(); - em.getTransaction().commit(); + // Parent entity type + em.getTransaction().begin(); + ClassTypeEntity parentType = new ClassTypeEntity(); + parentType.setType( ClassTypeEntity.PARENT_TYPE ); + em.persist( parentType ); + Long parentTypeId = parentType.getId(); + em.getTransaction().commit(); - // Child Rev 1 - em.getTransaction().begin(); - ChildEntity child = new ChildEntity(childTypeId, "Child data", "Child specific data"); - em.persist(child); - Long childId = child.getId(); - em.getTransaction().commit(); + // Child Rev 1 + em.getTransaction().begin(); + ChildEntity child = new ChildEntity( childTypeId, "Child data", "Child specific data" ); + em.persist( child ); + Long childId = child.getId(); + em.getTransaction().commit(); - // Parent Rev 2 - em.getTransaction().begin(); - ParentEntity parent = new ParentEntity(parentTypeId, "Parent data"); - em.persist(parent); - Long parentId = parent.getId(); - em.getTransaction().commit(); + // Parent Rev 2 + em.getTransaction().begin(); + ParentEntity parent = new ParentEntity( parentTypeId, "Parent data" ); + em.persist( parent ); + Long parentId = parent.getId(); + em.getTransaction().commit(); - // Child Rev 3 - em.getTransaction().begin(); - child = em.find(ChildEntity.class, childId); - child.setData("Child data modified"); - em.getTransaction().commit(); + // Child Rev 3 + em.getTransaction().begin(); + child = em.find( ChildEntity.class, childId ); + child.setData( "Child data modified" ); + em.getTransaction().commit(); - // Parent Rev 4 - em.getTransaction().begin(); - parent = em.find(ParentEntity.class, parentId); - parent.setData("Parent data modified"); - em.getTransaction().commit(); + // Parent Rev 4 + em.getTransaction().begin(); + parent = em.find( ParentEntity.class, parentId ); + parent.setData( "Parent data modified" ); + em.getTransaction().commit(); - childVer1 = new ChildEntity(childId, childTypeId, "Child data", "Child specific data"); - childVer2 = new ChildEntity(childId, childTypeId, "Child data modified", "Child specific data"); - parentVer1 = new ParentEntity(parentId, parentTypeId, "Parent data"); - parentVer2 = new ParentEntity(parentId, parentTypeId, "Parent data modified"); - } + childVer1 = new ChildEntity( childId, childTypeId, "Child data", "Child specific data" ); + childVer2 = new ChildEntity( childId, childTypeId, "Child data modified", "Child specific data" ); + parentVer1 = new ParentEntity( parentId, parentTypeId, "Parent data" ); + parentVer2 = new ParentEntity( parentId, parentTypeId, "Parent data modified" ); + } - @Test - public void testDiscriminatorFormulaInAuditTable() { - assert parentAudit.getDiscriminator().hasFormula(); - Iterator iterator = parentAudit.getDiscriminator().getColumnIterator(); - while (iterator.hasNext()) { - Object o = iterator.next(); - if (o instanceof Formula) { - Formula formula = (Formula) o; - Assert.assertEquals(ParentEntity.DISCRIMINATOR_QUERY, formula.getText()); - return; - } - } - assert false; - } + @Test + public void testDiscriminatorFormulaInAuditTable() { + assert parentAudit.getDiscriminator().hasFormula(); + Iterator iterator = parentAudit.getDiscriminator().getColumnIterator(); + while ( iterator.hasNext() ) { + Object o = iterator.next(); + if ( o instanceof Formula ) { + Formula formula = (Formula) o; + Assert.assertEquals( ParentEntity.DISCRIMINATOR_QUERY, formula.getText() ); + return; + } + } + assert false; + } - @Test - public void testRevisionsCounts() { - Assert.assertEquals(Arrays.asList(1, 3), getAuditReader().getRevisions(ChildEntity.class, childVer1.getId())); - Assert.assertEquals(Arrays.asList(2, 4), getAuditReader().getRevisions(ParentEntity.class, parentVer1.getId())); - } + @Test + public void testRevisionsCounts() { + Assert.assertEquals( + Arrays.asList( 1, 3 ), getAuditReader().getRevisions( + ChildEntity.class, + childVer1.getId() + ) + ); + Assert.assertEquals( + Arrays.asList( 2, 4 ), getAuditReader().getRevisions( + ParentEntity.class, + parentVer1.getId() + ) + ); + } - @Test - public void testHistoryOfParent() { - Assert.assertEquals(parentVer1, getAuditReader().find(ParentEntity.class, parentVer1.getId(), 2)); - Assert.assertEquals(parentVer2, getAuditReader().find(ParentEntity.class, parentVer2.getId(), 4)); - } + @Test + public void testHistoryOfParent() { + Assert.assertEquals( parentVer1, getAuditReader().find( ParentEntity.class, parentVer1.getId(), 2 ) ); + Assert.assertEquals( parentVer2, getAuditReader().find( ParentEntity.class, parentVer2.getId(), 4 ) ); + } - @Test - public void testHistoryOfChild() { - Assert.assertEquals(childVer1, getAuditReader().find(ChildEntity.class, childVer1.getId(), 1)); - Assert.assertEquals(childVer2, getAuditReader().find(ChildEntity.class, childVer2.getId(), 3)); - } + @Test + public void testHistoryOfChild() { + Assert.assertEquals( childVer1, getAuditReader().find( ChildEntity.class, childVer1.getId(), 1 ) ); + Assert.assertEquals( childVer2, getAuditReader().find( ChildEntity.class, childVer2.getId(), 3 ) ); + } - @Test - public void testPolymorphicQuery() { - Assert.assertEquals(childVer1, getAuditReader().createQuery().forEntitiesAtRevision(ChildEntity.class, 1).getSingleResult()); - Assert.assertEquals(childVer1, getAuditReader().createQuery().forEntitiesAtRevision(ParentEntity.class, 1).getSingleResult()); + @Test + public void testPolymorphicQuery() { + Assert.assertEquals( + childVer1, getAuditReader().createQuery() + .forEntitiesAtRevision( ChildEntity.class, 1 ) + .getSingleResult() + ); + Assert.assertEquals( + childVer1, getAuditReader().createQuery() + .forEntitiesAtRevision( ParentEntity.class, 1 ) + .getSingleResult() + ); - List childEntityRevisions = getAuditReader().createQuery().forRevisionsOfEntity(ChildEntity.class, true, false).getResultList(); - Assert.assertEquals(Arrays.asList(childVer1, childVer2), childEntityRevisions); + List childEntityRevisions = getAuditReader().createQuery().forRevisionsOfEntity( + ChildEntity.class, + true, + false + ).getResultList(); + Assert.assertEquals( Arrays.asList( childVer1, childVer2 ), childEntityRevisions ); - List parentEntityRevisions = getAuditReader().createQuery().forRevisionsOfEntity(ParentEntity.class, true, false).getResultList(); - Assert.assertEquals(Arrays.asList(childVer1, parentVer1, childVer2, parentVer2), parentEntityRevisions); - } + List parentEntityRevisions = getAuditReader().createQuery().forRevisionsOfEntity( + ParentEntity.class, + true, + false + ).getResultList(); + Assert.assertEquals( Arrays.asList( childVer1, parentVer1, childVer2, parentVer2 ), parentEntityRevisions ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/discriminatorformula/ParentEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/discriminatorformula/ParentEntity.java index ba37c8f802..5f1aa9f636 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/discriminatorformula/ParentEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/discriminatorformula/ParentEntity.java @@ -16,76 +16,86 @@ import org.hibernate.envers.Audited; @DiscriminatorValue(ClassTypeEntity.PARENT_TYPE) @Audited public class ParentEntity { - public static final String DISCRIMINATOR_QUERY = "(SELECT c.type FROM ClassTypeEntity c WHERE c.id = typeId)"; + public static final String DISCRIMINATOR_QUERY = "(SELECT c.type FROM ClassTypeEntity c WHERE c.id = typeId)"; - @Id - @GeneratedValue - protected Long id; + @Id + @GeneratedValue + protected Long id; - protected Long typeId; + protected Long typeId; - protected String data; + protected String data; - public ParentEntity() { - } + public ParentEntity() { + } - public ParentEntity(Long typeId, String data) { - this.typeId = typeId; - this.data = data; - } + public ParentEntity(Long typeId, String data) { + this.typeId = typeId; + this.data = data; + } - public ParentEntity(Long id, Long typeId, String data) { - this.id = id; - this.typeId = typeId; - this.data = data; - } + public ParentEntity(Long id, Long typeId, String data) { + this.id = id; + this.typeId = typeId; + this.data = data; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ParentEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ParentEntity) ) { + return false; + } - ParentEntity that = (ParentEntity) o; + ParentEntity that = (ParentEntity) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; - if (typeId != null ? !typeId.equals(that.typeId) : that.typeId != null) return false; - if (data != null ? !data.equals(that.data) : that.data != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } + if ( typeId != null ? !typeId.equals( that.typeId ) : that.typeId != null ) { + return false; + } + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (typeId != null ? typeId.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (typeId != null ? typeId.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "ParentEntity(id = " + id + ", typeId = " + typeId + ", data = " + data + ")"; - } + public String toString() { + return "ParentEntity(id = " + id + ", typeId = " + typeId + ", data = " + data + ")"; + } - public Long getId() { - return id; - } + public Long getId() { + return id; + } - public void setId(Long id) { - this.id = id; - } + public void setId(Long id) { + this.id = id; + } - public Long getTypeId() { - return typeId; - } + public Long getTypeId() { + return typeId; + } - public void setTypeId(Long typeId) { - this.typeId = typeId; - } + public void setTypeId(Long typeId) { + this.typeId = typeId; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/notownedrelation/Address.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/notownedrelation/Address.java index 5d0b5fc298..d458c92fae 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/notownedrelation/Address.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/notownedrelation/Address.java @@ -1,16 +1,18 @@ package org.hibernate.envers.test.integration.inheritance.single.notownedrelation; -import java.io.Serializable; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.ManyToOne; +import java.io.Serializable; import org.hibernate.envers.Audited; @Entity @Audited public class Address implements Serializable { - @Id @GeneratedValue + @Id + @GeneratedValue private Long id; private String address1; @@ -18,15 +20,15 @@ public class Address implements Serializable { @ManyToOne private Contact contact; - public Address() { - } + public Address() { + } - public Address(Long id, String address1) { - this.id = id; - this.address1 = address1; - } + public Address(Long id, String address1) { + this.id = id; + this.address1 = address1; + } - public Long getId() { + public Long getId() { return id; } @@ -50,22 +52,30 @@ public class Address implements Serializable { this.contact = contact; } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof Address)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof Address) ) { + return false; + } - Address address = (Address) o; + Address address = (Address) o; - if (address1 != null ? !address1.equals(address.address1) : address.address1 != null) return false; - if (id != null ? !id.equals(address.id) : address.id != null) return false; + if ( address1 != null ? !address1.equals( address.address1 ) : address.address1 != null ) { + return false; + } + if ( id != null ? !id.equals( address.id ) : address.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (address1 != null ? address1.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (address1 != null ? address1.hashCode() : 0); + return result; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/notownedrelation/Contact.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/notownedrelation/Contact.java index f99abf8818..6872760f67 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/notownedrelation/Contact.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/notownedrelation/Contact.java @@ -1,6 +1,5 @@ package org.hibernate.envers.test.integration.inheritance.single.notownedrelation; -import java.io.Serializable; -import java.util.Set; + import javax.persistence.DiscriminatorColumn; import javax.persistence.DiscriminatorValue; import javax.persistence.Entity; @@ -9,43 +8,50 @@ import javax.persistence.Id; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; import javax.persistence.OneToMany; +import java.io.Serializable; +import java.util.Set; import org.hibernate.envers.Audited; @Entity -@Inheritance(strategy=InheritanceType.SINGLE_TABLE) +@Inheritance(strategy = InheritanceType.SINGLE_TABLE) @DiscriminatorValue("Contact") -@DiscriminatorColumn(name="contactType",discriminatorType=javax.persistence.DiscriminatorType.STRING) +@DiscriminatorColumn(name = "contactType", discriminatorType = javax.persistence.DiscriminatorType.STRING) @Audited public class Contact implements Serializable { - @Id @GeneratedValue - private Long id; + @Id + @GeneratedValue + private Long id; - private String email; + private String email; - @OneToMany(mappedBy="contact") - private Set
addresses; + @OneToMany(mappedBy = "contact") + private Set
addresses; - public Contact() { - } + public Contact() { + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } - public Long getId() { - return id; - } - public void setId(Long id) { - this.id = id; - } public String getEmail() { - return email; - } - public void setEmail(String email) { - this.email = email; - } + return email; + } - public Set
getAddresses() { - return addresses; - } - public void setAddresses(Set
addresses) { - this.addresses = addresses; - } + public void setEmail(String email) { + this.email = email; + } + + public Set
getAddresses() { + return addresses; + } + + public void setAddresses(Set
addresses) { + this.addresses = addresses; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/notownedrelation/NotOwnedBidirectional.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/notownedrelation/NotOwnedBidirectional.java index 46fffcea2e..15de57985e 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/notownedrelation/NotOwnedBidirectional.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/notownedrelation/NotOwnedBidirectional.java @@ -24,96 +24,100 @@ package org.hibernate.envers.test.integration.inheritance.single.notownedrelation; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.tools.TestTools; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class NotOwnedBidirectional extends BaseEnversJPAFunctionalTestCase { - private Long pc_id; - private Long a1_id; - private Long a2_id; + private Long pc_id; + private Long a1_id; + private Long a2_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { Address.class, Contact.class, PersonalContact.class }; - } + return new Class[] {Address.class, Contact.class, PersonalContact.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - // Rev 1 - em.getTransaction().begin(); + // Rev 1 + em.getTransaction().begin(); - PersonalContact pc = new PersonalContact(); - pc.setEmail("e"); - pc.setFirstname("f"); + PersonalContact pc = new PersonalContact(); + pc.setEmail( "e" ); + pc.setFirstname( "f" ); - Address a1 = new Address(); - a1.setAddress1("a1"); - a1.setContact(pc); + Address a1 = new Address(); + a1.setAddress1( "a1" ); + a1.setContact( pc ); - em.persist(pc); - em.persist(a1); + em.persist( pc ); + em.persist( a1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Rev 2 - em.getTransaction().begin(); + // Rev 2 + em.getTransaction().begin(); - pc = em.find(PersonalContact.class, pc.getId()); + pc = em.find( PersonalContact.class, pc.getId() ); - Address a2 = new Address(); - a2.setAddress1("a2"); - a2.setContact(pc); + Address a2 = new Address(); + a2.setAddress1( "a2" ); + a2.setContact( pc ); - em.persist(a2); + em.persist( a2 ); - em.getTransaction().commit(); - - // + em.getTransaction().commit(); - pc_id = pc.getId(); - a1_id = a1.getId(); - a2_id = a2.getId(); - } + // - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(Contact.class, pc_id)); - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(PersonalContact.class, pc_id)); + pc_id = pc.getId(); + a1_id = a1.getId(); + a2_id = a2.getId(); + } - assert Arrays.asList(1).equals(getAuditReader().getRevisions(Address.class, a1_id)); - assert Arrays.asList(1).equals(getAuditReader().getRevisions(Address.class, a1_id)); + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( Contact.class, pc_id ) ); + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( PersonalContact.class, pc_id ) ); - assert Arrays.asList(2).equals(getAuditReader().getRevisions(Address.class, a2_id)); - assert Arrays.asList(2).equals(getAuditReader().getRevisions(Address.class, a2_id)); - } + assert Arrays.asList( 1 ).equals( getAuditReader().getRevisions( Address.class, a1_id ) ); + assert Arrays.asList( 1 ).equals( getAuditReader().getRevisions( Address.class, a1_id ) ); - @Test - public void testHistoryOfContact() { - assert getAuditReader().find(Contact.class, pc_id, 1).getAddresses().equals( - TestTools.makeSet(new Address(a1_id, "a1"))); + assert Arrays.asList( 2 ).equals( getAuditReader().getRevisions( Address.class, a2_id ) ); + assert Arrays.asList( 2 ).equals( getAuditReader().getRevisions( Address.class, a2_id ) ); + } - assert getAuditReader().find(Contact.class, pc_id, 2).getAddresses().equals( - TestTools.makeSet(new Address(a1_id, "a1"), new Address(a2_id, "a2"))); - } + @Test + public void testHistoryOfContact() { + assert getAuditReader().find( Contact.class, pc_id, 1 ).getAddresses().equals( + TestTools.makeSet( new Address( a1_id, "a1" ) ) + ); - @Test - public void testHistoryOfPersonalContact() { - assert getAuditReader().find(PersonalContact.class, pc_id, 1).getAddresses().equals( - TestTools.makeSet(new Address(a1_id, "a1"))); + assert getAuditReader().find( Contact.class, pc_id, 2 ).getAddresses().equals( + TestTools.makeSet( new Address( a1_id, "a1" ), new Address( a2_id, "a2" ) ) + ); + } - assert getAuditReader().find(PersonalContact.class, pc_id, 2).getAddresses().equals( - TestTools.makeSet(new Address(a1_id, "a1"), new Address(a2_id, "a2"))); - } + @Test + public void testHistoryOfPersonalContact() { + assert getAuditReader().find( PersonalContact.class, pc_id, 1 ).getAddresses().equals( + TestTools.makeSet( new Address( a1_id, "a1" ) ) + ); + + assert getAuditReader().find( PersonalContact.class, pc_id, 2 ).getAddresses().equals( + TestTools.makeSet( new Address( a1_id, "a1" ), new Address( a2_id, "a2" ) ) + ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/notownedrelation/PersonalContact.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/notownedrelation/PersonalContact.java index ddae0cf878..64e400a52a 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/notownedrelation/PersonalContact.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/notownedrelation/PersonalContact.java @@ -1,4 +1,5 @@ package org.hibernate.envers.test.integration.inheritance.single.notownedrelation; + import javax.persistence.DiscriminatorValue; import javax.persistence.Entity; @@ -13,8 +14,8 @@ public class PersonalContact extends Contact { public String getFirstname() { return firstname; } - - public void setFirstname(String firstname) { + + public void setFirstname(String firstname) { this.firstname = firstname; } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/relation/ChildIngEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/relation/ChildIngEntity.java index bd57edd27e..eb00fb1986 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/relation/ChildIngEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/relation/ChildIngEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.inheritance.single.relation; + import javax.persistence.Basic; import javax.persistence.DiscriminatorValue; import javax.persistence.Entity; @@ -35,49 +36,57 @@ import org.hibernate.envers.Audited; @DiscriminatorValue("2") @Audited public class ChildIngEntity extends ParentIngEntity { - @Basic - private Long numVal; + @Basic + private Long numVal; - public ChildIngEntity() { - } + public ChildIngEntity() { + } - public ChildIngEntity(String data, Long numVal) { - super(data); - this.numVal = numVal; - } + public ChildIngEntity(String data, Long numVal) { + super( data ); + this.numVal = numVal; + } - public ChildIngEntity(Integer id, String data, Long numVal) { - super(id, data); - this.numVal = numVal; - } + public ChildIngEntity(Integer id, String data, Long numVal) { + super( id, data ); + this.numVal = numVal; + } - public Long getNumVal() { - return numVal; - } + public Long getNumVal() { + return numVal; + } - public void setNumVal(Long numVal) { - this.numVal = numVal; - } + public void setNumVal(Long numVal) { + this.numVal = numVal; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ChildIngEntity)) return false; - if (!super.equals(o)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ChildIngEntity) ) { + return false; + } + if ( !super.equals( o ) ) { + return false; + } - ChildIngEntity childEntity = (ChildIngEntity) o; + ChildIngEntity childEntity = (ChildIngEntity) o; - if (numVal != null ? !numVal.equals(childEntity.numVal) : childEntity.numVal != null) return false; + if ( numVal != null ? !numVal.equals( childEntity.numVal ) : childEntity.numVal != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result = super.hashCode(); - result = 31 * result + (numVal != null ? numVal.hashCode() : 0); - return result; - } + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (numVal != null ? numVal.hashCode() : 0); + return result; + } - public String toString() { - return "ChildIngEntity(id = " + getId() + ", data = " + getData() + ", numVal = " + numVal + ")"; - } + public String toString() { + return "ChildIngEntity(id = " + getId() + ", data = " + getData() + ", numVal = " + numVal + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/relation/ParentIngEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/relation/ParentIngEntity.java index 0f47ac41e5..29ee0006d0 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/relation/ParentIngEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/relation/ParentIngEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.inheritance.single.relation; + import javax.persistence.Basic; import javax.persistence.DiscriminatorColumn; import javax.persistence.DiscriminatorType; @@ -44,72 +45,80 @@ import org.hibernate.envers.Audited; @DiscriminatorValue("1") @Audited public class ParentIngEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - @Basic - private String data; + @Basic + private String data; - @ManyToOne - private ReferencedEntity referenced; + @ManyToOne + private ReferencedEntity referenced; - public ParentIngEntity() { - } + public ParentIngEntity() { + } - public ParentIngEntity(String data) { - this.data = data; - } + public ParentIngEntity(String data) { + this.data = data; + } - public ParentIngEntity(Integer id, String data) { - this.id = id; - this.data = data; - } + public ParentIngEntity(Integer id, String data) { + this.id = id; + this.data = data; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public ReferencedEntity getReferenced() { - return referenced; - } + public ReferencedEntity getReferenced() { + return referenced; + } - public void setReferenced(ReferencedEntity referenced) { - this.referenced = referenced; - } + public void setReferenced(ReferencedEntity referenced) { + this.referenced = referenced; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ParentIngEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ParentIngEntity) ) { + return false; + } - ParentIngEntity that = (ParentIngEntity) o; + ParentIngEntity that = (ParentIngEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "ParentIngEntity(id = " + getId() + ", data = " + getData() + ")"; - } + public String toString() { + return "ParentIngEntity(id = " + getId() + ", data = " + getData() + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/relation/PolymorphicCollection.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/relation/PolymorphicCollection.java index 7d92c65dae..a1049f16b6 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/relation/PolymorphicCollection.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/relation/PolymorphicCollection.java @@ -23,80 +23,82 @@ */ package org.hibernate.envers.test.integration.inheritance.single.relation; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.tools.TestTools; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class PolymorphicCollection extends BaseEnversJPAFunctionalTestCase { - private Integer ed_id1; - private Integer c_id; - private Integer p_id; + private Integer ed_id1; + private Integer c_id; + private Integer p_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { ChildIngEntity.class, ParentIngEntity.class, ReferencedEntity.class }; - } + return new Class[] {ChildIngEntity.class, ParentIngEntity.class, ReferencedEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - // Rev 1 - em.getTransaction().begin(); + // Rev 1 + em.getTransaction().begin(); - ReferencedEntity re = new ReferencedEntity(); - em.persist(re); - ed_id1 = re.getId(); + ReferencedEntity re = new ReferencedEntity(); + em.persist( re ); + ed_id1 = re.getId(); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Rev 2 - em.getTransaction().begin(); + // Rev 2 + em.getTransaction().begin(); - re = em.find(ReferencedEntity.class, ed_id1); + re = em.find( ReferencedEntity.class, ed_id1 ); - ParentIngEntity pie = new ParentIngEntity("x"); - pie.setReferenced(re); - em.persist(pie); - p_id = pie.getId(); + ParentIngEntity pie = new ParentIngEntity( "x" ); + pie.setReferenced( re ); + em.persist( pie ); + p_id = pie.getId(); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Rev 3 - em.getTransaction().begin(); - - re = em.find(ReferencedEntity.class, ed_id1); + // Rev 3 + em.getTransaction().begin(); - ChildIngEntity cie = new ChildIngEntity("y", 1l); - cie.setReferenced(re); - em.persist(cie); - c_id = cie.getId(); + re = em.find( ReferencedEntity.class, ed_id1 ); - em.getTransaction().commit(); - } + ChildIngEntity cie = new ChildIngEntity( "y", 1l ); + cie.setReferenced( re ); + em.persist( cie ); + c_id = cie.getId(); - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2, 3).equals(getAuditReader().getRevisions(ReferencedEntity.class, ed_id1)); - assert Arrays.asList(2).equals(getAuditReader().getRevisions(ParentIngEntity.class, p_id)); - assert Arrays.asList(3).equals(getAuditReader().getRevisions(ChildIngEntity.class, c_id)); - } + em.getTransaction().commit(); + } - @Test - public void testHistoryOfReferencedCollection() { - assert getAuditReader().find(ReferencedEntity.class, ed_id1, 1).getReferencing().size() == 0; - assert getAuditReader().find(ReferencedEntity.class, ed_id1, 2).getReferencing().equals( - TestTools.makeSet(new ParentIngEntity(p_id, "x"))); - assert getAuditReader().find(ReferencedEntity.class, ed_id1, 3).getReferencing().equals( - TestTools.makeSet(new ParentIngEntity(p_id, "x"), new ChildIngEntity(c_id, "y", 1l))); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2, 3 ).equals( getAuditReader().getRevisions( ReferencedEntity.class, ed_id1 ) ); + assert Arrays.asList( 2 ).equals( getAuditReader().getRevisions( ParentIngEntity.class, p_id ) ); + assert Arrays.asList( 3 ).equals( getAuditReader().getRevisions( ChildIngEntity.class, c_id ) ); + } + + @Test + public void testHistoryOfReferencedCollection() { + assert getAuditReader().find( ReferencedEntity.class, ed_id1, 1 ).getReferencing().size() == 0; + assert getAuditReader().find( ReferencedEntity.class, ed_id1, 2 ).getReferencing().equals( + TestTools.makeSet( new ParentIngEntity( p_id, "x" ) ) + ); + assert getAuditReader().find( ReferencedEntity.class, ed_id1, 3 ).getReferencing().equals( + TestTools.makeSet( new ParentIngEntity( p_id, "x" ), new ChildIngEntity( c_id, "y", 1l ) ) + ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/relation/ReferencedEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/relation/ReferencedEntity.java index 5caaf46488..a77cf9b68f 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/relation/ReferencedEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/relation/ReferencedEntity.java @@ -22,11 +22,12 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.inheritance.single.relation; -import java.util.Set; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.OneToMany; +import java.util.Set; import org.hibernate.envers.Audited; @@ -36,41 +37,47 @@ import org.hibernate.envers.Audited; @Entity @Audited public class ReferencedEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - @OneToMany(mappedBy = "referenced") - private Set referencing; + @OneToMany(mappedBy = "referenced") + private Set referencing; - public Set getReferencing() { - return referencing; - } + public Set getReferencing() { + return referencing; + } - public void setReferencing(Set referencing) { - this.referencing = referencing; - } + public void setReferencing(Set referencing) { + this.referencing = referencing; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ReferencedEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ReferencedEntity) ) { + return false; + } - ReferencedEntity that = (ReferencedEntity) o; + ReferencedEntity that = (ReferencedEntity) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - return id; - } + public int hashCode() { + return id; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/ChildAuditing.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/ChildAuditing.java index d13ed2fef8..75423c4617 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/ChildAuditing.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/ChildAuditing.java @@ -24,71 +24,71 @@ package org.hibernate.envers.test.integration.inheritance.tableperclass; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class ChildAuditing extends BaseEnversJPAFunctionalTestCase { - private Integer id1; + private Integer id1; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { ChildEntity.class, ParentEntity.class }; - } + return new Class[] {ChildEntity.class, ParentEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - id1 = 1; + id1 = 1; - // Rev 1 - em.getTransaction().begin(); - ChildEntity ce = new ChildEntity(id1, "x", 1l); - em.persist(ce); - em.getTransaction().commit(); + // Rev 1 + em.getTransaction().begin(); + ChildEntity ce = new ChildEntity( id1, "x", 1l ); + em.persist( ce ); + em.getTransaction().commit(); - // Rev 2 - em.getTransaction().begin(); - ce = em.find(ChildEntity.class, id1); - ce.setData("y"); - ce.setNumVal(2l); - em.getTransaction().commit(); - } + // Rev 2 + em.getTransaction().begin(); + ce = em.find( ChildEntity.class, id1 ); + ce.setData( "y" ); + ce.setNumVal( 2l ); + em.getTransaction().commit(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(ChildEntity.class, id1)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( ChildEntity.class, id1 ) ); + } - @Test - public void testHistoryOfChildId1() { - ChildEntity ver1 = new ChildEntity(id1, "x", 1l); - ChildEntity ver2 = new ChildEntity(id1, "y", 2l); + @Test + public void testHistoryOfChildId1() { + ChildEntity ver1 = new ChildEntity( id1, "x", 1l ); + ChildEntity ver2 = new ChildEntity( id1, "y", 2l ); - assert getAuditReader().find(ChildEntity.class, id1, 1).equals(ver1); - assert getAuditReader().find(ChildEntity.class, id1, 2).equals(ver2); + assert getAuditReader().find( ChildEntity.class, id1, 1 ).equals( ver1 ); + assert getAuditReader().find( ChildEntity.class, id1, 2 ).equals( ver2 ); - assert getAuditReader().find(ParentEntity.class, id1, 1).equals(ver1); - assert getAuditReader().find(ParentEntity.class, id1, 2).equals(ver2); - } + assert getAuditReader().find( ParentEntity.class, id1, 1 ).equals( ver1 ); + assert getAuditReader().find( ParentEntity.class, id1, 2 ).equals( ver2 ); + } - @Test - public void testPolymorphicQuery() { - ChildEntity childVer1 = new ChildEntity(id1, "x", 1l); + @Test + public void testPolymorphicQuery() { + ChildEntity childVer1 = new ChildEntity( id1, "x", 1l ); - assert getAuditReader().createQuery().forEntitiesAtRevision(ChildEntity.class, 1).getSingleResult() - .equals(childVer1); + assert getAuditReader().createQuery().forEntitiesAtRevision( ChildEntity.class, 1 ).getSingleResult() + .equals( childVer1 ); - assert getAuditReader().createQuery().forEntitiesAtRevision(ParentEntity.class, 1).getSingleResult() - .equals(childVer1); - } + assert getAuditReader().createQuery().forEntitiesAtRevision( ParentEntity.class, 1 ).getSingleResult() + .equals( childVer1 ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/ChildEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/ChildEntity.java index 345306189f..d7fca93a99 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/ChildEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/ChildEntity.java @@ -23,6 +23,7 @@ */ package org.hibernate.envers.test.integration.inheritance.tableperclass; + import javax.persistence.Basic; import javax.persistence.Entity; @@ -34,44 +35,52 @@ import org.hibernate.envers.Audited; @Entity @Audited public class ChildEntity extends ParentEntity { - @Basic - private Long numVal; + @Basic + private Long numVal; - public ChildEntity() { - } + public ChildEntity() { + } - public ChildEntity(Integer id, String data, Long numVal) { - super(id, data); - this.numVal = numVal; - } + public ChildEntity(Integer id, String data, Long numVal) { + super( id, data ); + this.numVal = numVal; + } - public Long getNumVal() { - return numVal; - } + public Long getNumVal() { + return numVal; + } - public void setNumVal(Long numVal) { - this.numVal = numVal; - } + public void setNumVal(Long numVal) { + this.numVal = numVal; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ChildEntity)) return false; - if (!super.equals(o)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ChildEntity) ) { + return false; + } + if ( !super.equals( o ) ) { + return false; + } - ChildEntity childEntity = (ChildEntity) o; + ChildEntity childEntity = (ChildEntity) o; - if (numVal != null ? !numVal.equals(childEntity.numVal) : childEntity.numVal != null) return false; + if ( numVal != null ? !numVal.equals( childEntity.numVal ) : childEntity.numVal != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result = super.hashCode(); - result = 31 * result + (numVal != null ? numVal.hashCode() : 0); - return result; - } + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (numVal != null ? numVal.hashCode() : 0); + return result; + } - public String toString() { - return "ChildPrimaryKeyJoinEntity(id = " + getId() + ", data = " + getData() + ", numVal = " + numVal + ")"; - } + public String toString() { + return "ChildPrimaryKeyJoinEntity(id = " + getId() + ", data = " + getData() + ", numVal = " + numVal + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/ParentAuditing.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/ParentAuditing.java index 97500a5015..69b8549b2e 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/ParentAuditing.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/ParentAuditing.java @@ -24,72 +24,72 @@ package org.hibernate.envers.test.integration.inheritance.tableperclass; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class ParentAuditing extends BaseEnversJPAFunctionalTestCase { - private Integer id1; + private Integer id1; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { ChildEntity.class, ParentEntity.class }; - } + return new Class[] {ChildEntity.class, ParentEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - id1 = 1; + id1 = 1; - // Rev 1 - em.getTransaction().begin(); - ParentEntity pe = new ParentEntity(id1, "x"); - em.persist(pe); - em.getTransaction().commit(); + // Rev 1 + em.getTransaction().begin(); + ParentEntity pe = new ParentEntity( id1, "x" ); + em.persist( pe ); + em.getTransaction().commit(); - // Rev 2 - em.getTransaction().begin(); - pe = em.find(ParentEntity.class, id1); - pe.setData("y"); - em.getTransaction().commit(); - } + // Rev 2 + em.getTransaction().begin(); + pe = em.find( ParentEntity.class, id1 ); + pe.setData( "y" ); + em.getTransaction().commit(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(ParentEntity.class, id1)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( ParentEntity.class, id1 ) ); + } - @Test - public void testHistoryOfChildId1() { - assert getAuditReader().find(ChildEntity.class, id1, 1) == null; - assert getAuditReader().find(ChildEntity.class, id1, 2) == null; - } + @Test + public void testHistoryOfChildId1() { + assert getAuditReader().find( ChildEntity.class, id1, 1 ) == null; + assert getAuditReader().find( ChildEntity.class, id1, 2 ) == null; + } - @Test - public void testHistoryOfParentId1() { - ParentEntity ver1 = new ParentEntity(id1, "x"); - ParentEntity ver2 = new ParentEntity(id1, "y"); + @Test + public void testHistoryOfParentId1() { + ParentEntity ver1 = new ParentEntity( id1, "x" ); + ParentEntity ver2 = new ParentEntity( id1, "y" ); - assert getAuditReader().find(ParentEntity.class, id1, 1).equals(ver1); - assert getAuditReader().find(ParentEntity.class, id1, 2).equals(ver2); - } + assert getAuditReader().find( ParentEntity.class, id1, 1 ).equals( ver1 ); + assert getAuditReader().find( ParentEntity.class, id1, 2 ).equals( ver2 ); + } - @Test - public void testPolymorphicQuery() { - ParentEntity parentVer1 = new ParentEntity(id1, "x"); + @Test + public void testPolymorphicQuery() { + ParentEntity parentVer1 = new ParentEntity( id1, "x" ); - assert getAuditReader().createQuery().forEntitiesAtRevision(ParentEntity.class, 1).getSingleResult() - .equals(parentVer1); - assert getAuditReader().createQuery().forEntitiesAtRevision(ChildEntity.class, 1) - .getResultList().size() == 0; - } + assert getAuditReader().createQuery().forEntitiesAtRevision( ParentEntity.class, 1 ).getSingleResult() + .equals( parentVer1 ); + assert getAuditReader().createQuery().forEntitiesAtRevision( ChildEntity.class, 1 ) + .getResultList().size() == 0; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/ParentEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/ParentEntity.java index 268607d052..7b7b5c7cda 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/ParentEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/ParentEntity.java @@ -23,6 +23,7 @@ */ package org.hibernate.envers.test.integration.inheritance.tableperclass; + import javax.persistence.Basic; import javax.persistence.Entity; import javax.persistence.Id; @@ -38,56 +39,64 @@ import org.hibernate.envers.Audited; @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) @Audited public class ParentEntity { - @Id - private Integer id; + @Id + private Integer id; - @Basic - private String data; + @Basic + private String data; - public ParentEntity() { - } + public ParentEntity() { + } - public ParentEntity(Integer id, String data) { - this.id = id; - this.data = data; - } + public ParentEntity(Integer id, String data) { + this.id = id; + this.data = data; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ParentEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ParentEntity) ) { + return false; + } - ParentEntity that = (ParentEntity) o; + ParentEntity that = (ParentEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "ParentEntity(id = " + getId() + ", data = " + getData() + ")"; - } + public String toString() { + return "ParentEntity(id = " + getId() + ", data = " + getData() + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/abstractparent/AuditedAbstractParentTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/abstractparent/AuditedAbstractParentTest.java index 73553b5472..f6b95aedad 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/abstractparent/AuditedAbstractParentTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/abstractparent/AuditedAbstractParentTest.java @@ -1,14 +1,15 @@ package org.hibernate.envers.test.integration.inheritance.tableperclass.abstractparent; -import java.util.Iterator; import javax.persistence.EntityManager; - -import org.junit.Assert; -import org.junit.Test; +import java.util.Iterator; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.mapping.Table; + +import org.junit.Assert; +import org.junit.Test; + import org.hibernate.testing.TestForIssue; /** @@ -18,7 +19,7 @@ import org.hibernate.testing.TestForIssue; public class AuditedAbstractParentTest extends BaseEnversJPAFunctionalTestCase { @Override protected Class[] getAnnotatedClasses() { - return new Class[] { AbstractEntity.class, EffectiveEntity1.class }; + return new Class[] {AbstractEntity.class, EffectiveEntity1.class}; } @Test diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/childrelation/ChildIngEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/childrelation/ChildIngEntity.java index af1b87a605..c391953c0d 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/childrelation/ChildIngEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/childrelation/ChildIngEntity.java @@ -23,6 +23,7 @@ */ package org.hibernate.envers.test.integration.inheritance.tableperclass.childrelation; + import javax.persistence.Basic; import javax.persistence.Entity; import javax.persistence.ManyToOne; @@ -35,55 +36,63 @@ import org.hibernate.envers.Audited; @Entity @Audited public class ChildIngEntity extends ParentNotIngEntity { - @Basic - private Long numVal; + @Basic + private Long numVal; - @ManyToOne - private ReferencedEntity referenced; + @ManyToOne + private ReferencedEntity referenced; - public ChildIngEntity() { - } + public ChildIngEntity() { + } - public ChildIngEntity(Integer id, String data, Long numVal) { - super(id, data); - this.numVal = numVal; - } + public ChildIngEntity(Integer id, String data, Long numVal) { + super( id, data ); + this.numVal = numVal; + } - public Long getNumVal() { - return numVal; - } + public Long getNumVal() { + return numVal; + } - public void setNumVal(Long numVal) { - this.numVal = numVal; - } + public void setNumVal(Long numVal) { + this.numVal = numVal; + } - public ReferencedEntity getReferenced() { - return referenced; - } + public ReferencedEntity getReferenced() { + return referenced; + } - public void setReferenced(ReferencedEntity referenced) { - this.referenced = referenced; - } + public void setReferenced(ReferencedEntity referenced) { + this.referenced = referenced; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ChildIngEntity)) return false; - if (!super.equals(o)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ChildIngEntity) ) { + return false; + } + if ( !super.equals( o ) ) { + return false; + } - ChildIngEntity childEntity = (ChildIngEntity) o; + ChildIngEntity childEntity = (ChildIngEntity) o; - if (numVal != null ? !numVal.equals(childEntity.numVal) : childEntity.numVal != null) return false; + if ( numVal != null ? !numVal.equals( childEntity.numVal ) : childEntity.numVal != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result = super.hashCode(); - result = 31 * result + (numVal != null ? numVal.hashCode() : 0); - return result; - } + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (numVal != null ? numVal.hashCode() : 0); + return result; + } - public String toString() { - return "ChildIngEntity(id = " + getId() + ", data = " + getData() + ", numVal = " + numVal + ")"; - } + public String toString() { + return "ChildIngEntity(id = " + getId() + ", data = " + getData() + ", numVal = " + numVal + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/childrelation/ChildReferencing.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/childrelation/ChildReferencing.java index 2d34eac5fb..27075b4617 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/childrelation/ChildReferencing.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/childrelation/ChildReferencing.java @@ -24,100 +24,104 @@ package org.hibernate.envers.test.integration.inheritance.tableperclass.childrelation; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.tools.TestTools; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class ChildReferencing extends BaseEnversJPAFunctionalTestCase { - private Integer re_id1; - private Integer re_id2; - private Integer c_id; + private Integer re_id1; + private Integer re_id2; + private Integer c_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { ChildIngEntity.class, ParentNotIngEntity.class, ReferencedEntity.class }; - } + return new Class[] {ChildIngEntity.class, ParentNotIngEntity.class, ReferencedEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - re_id1 = 1; - re_id2 = 10; - c_id = 100; + re_id1 = 1; + re_id2 = 10; + c_id = 100; - // Rev 1 - em.getTransaction().begin(); + // Rev 1 + em.getTransaction().begin(); - ReferencedEntity re1 = new ReferencedEntity(re_id1); - em.persist(re1); + ReferencedEntity re1 = new ReferencedEntity( re_id1 ); + em.persist( re1 ); - ReferencedEntity re2 = new ReferencedEntity(re_id2); - em.persist(re2); + ReferencedEntity re2 = new ReferencedEntity( re_id2 ); + em.persist( re2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Rev 2 - em.getTransaction().begin(); + // Rev 2 + em.getTransaction().begin(); - re1 = em.find(ReferencedEntity.class, re_id1); + re1 = em.find( ReferencedEntity.class, re_id1 ); - ChildIngEntity cie = new ChildIngEntity(c_id, "y", 1l); - cie.setReferenced(re1); - em.persist(cie); - c_id = cie.getId(); + ChildIngEntity cie = new ChildIngEntity( c_id, "y", 1l ); + cie.setReferenced( re1 ); + em.persist( cie ); + c_id = cie.getId(); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Rev 3 - em.getTransaction().begin(); + // Rev 3 + em.getTransaction().begin(); - re2 = em.find(ReferencedEntity.class, re_id2); - cie = em.find(ChildIngEntity.class, c_id); + re2 = em.find( ReferencedEntity.class, re_id2 ); + cie = em.find( ChildIngEntity.class, c_id ); - cie.setReferenced(re2); + cie.setReferenced( re2 ); - em.getTransaction().commit(); - } + em.getTransaction().commit(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2, 3).equals(getAuditReader().getRevisions(ReferencedEntity.class, re_id1)); - assert Arrays.asList(1, 3).equals(getAuditReader().getRevisions(ReferencedEntity.class, re_id2)); - assert Arrays.asList(2, 3).equals(getAuditReader().getRevisions(ChildIngEntity.class, c_id)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2, 3 ).equals( getAuditReader().getRevisions( ReferencedEntity.class, re_id1 ) ); + assert Arrays.asList( 1, 3 ).equals( getAuditReader().getRevisions( ReferencedEntity.class, re_id2 ) ); + assert Arrays.asList( 2, 3 ).equals( getAuditReader().getRevisions( ChildIngEntity.class, c_id ) ); + } - @Test - public void testHistoryOfReferencedCollection1() { - assert getAuditReader().find(ReferencedEntity.class, re_id1, 1).getReferencing().size() == 0; - assert getAuditReader().find(ReferencedEntity.class, re_id1, 2).getReferencing().equals( - TestTools.makeSet(new ChildIngEntity(c_id, "y", 1l))); - assert getAuditReader().find(ReferencedEntity.class, re_id1, 3).getReferencing().size() == 0; - } + @Test + public void testHistoryOfReferencedCollection1() { + assert getAuditReader().find( ReferencedEntity.class, re_id1, 1 ).getReferencing().size() == 0; + assert getAuditReader().find( ReferencedEntity.class, re_id1, 2 ).getReferencing().equals( + TestTools.makeSet( new ChildIngEntity( c_id, "y", 1l ) ) + ); + assert getAuditReader().find( ReferencedEntity.class, re_id1, 3 ).getReferencing().size() == 0; + } - @Test - public void testHistoryOfReferencedCollection2() { - assert getAuditReader().find(ReferencedEntity.class, re_id2, 1).getReferencing().size() == 0; - assert getAuditReader().find(ReferencedEntity.class, re_id2, 2).getReferencing().size() == 0; - assert getAuditReader().find(ReferencedEntity.class, re_id2, 3).getReferencing().equals( - TestTools.makeSet(new ChildIngEntity(c_id, "y", 1l))); - } + @Test + public void testHistoryOfReferencedCollection2() { + assert getAuditReader().find( ReferencedEntity.class, re_id2, 1 ).getReferencing().size() == 0; + assert getAuditReader().find( ReferencedEntity.class, re_id2, 2 ).getReferencing().size() == 0; + assert getAuditReader().find( ReferencedEntity.class, re_id2, 3 ).getReferencing().equals( + TestTools.makeSet( new ChildIngEntity( c_id, "y", 1l ) ) + ); + } - @Test - public void testChildHistory() { - assert getAuditReader().find(ChildIngEntity.class, c_id, 1) == null; - assert getAuditReader().find(ChildIngEntity.class, c_id, 2).getReferenced().equals( - new ReferencedEntity(re_id1)); - assert getAuditReader().find(ChildIngEntity.class, c_id, 3).getReferenced().equals( - new ReferencedEntity(re_id2)); - } + @Test + public void testChildHistory() { + assert getAuditReader().find( ChildIngEntity.class, c_id, 1 ) == null; + assert getAuditReader().find( ChildIngEntity.class, c_id, 2 ).getReferenced().equals( + new ReferencedEntity( re_id1 ) + ); + assert getAuditReader().find( ChildIngEntity.class, c_id, 3 ).getReferenced().equals( + new ReferencedEntity( re_id2 ) + ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/childrelation/ParentNotIngEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/childrelation/ParentNotIngEntity.java index fc06884da3..c7fda2de74 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/childrelation/ParentNotIngEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/childrelation/ParentNotIngEntity.java @@ -23,6 +23,7 @@ */ package org.hibernate.envers.test.integration.inheritance.tableperclass.childrelation; + import javax.persistence.Basic; import javax.persistence.Entity; import javax.persistence.Id; @@ -38,56 +39,64 @@ import org.hibernate.envers.Audited; @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) @Audited public class ParentNotIngEntity { - @Id - private Integer id; + @Id + private Integer id; - @Basic - private String data; + @Basic + private String data; - public ParentNotIngEntity() { - } + public ParentNotIngEntity() { + } - public ParentNotIngEntity(Integer id, String data) { - this.id = id; - this.data = data; - } + public ParentNotIngEntity(Integer id, String data) { + this.id = id; + this.data = data; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ParentNotIngEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ParentNotIngEntity) ) { + return false; + } - ParentNotIngEntity that = (ParentNotIngEntity) o; + ParentNotIngEntity that = (ParentNotIngEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "ParentNotIngEntity(id = " + getId() + ", data = " + getData() + ")"; - } + public String toString() { + return "ParentNotIngEntity(id = " + getId() + ", data = " + getData() + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/childrelation/ReferencedEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/childrelation/ReferencedEntity.java index 91f12f0141..f3beec7884 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/childrelation/ReferencedEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/childrelation/ReferencedEntity.java @@ -23,10 +23,11 @@ */ package org.hibernate.envers.test.integration.inheritance.tableperclass.childrelation; -import java.util.Set; + import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.OneToMany; +import java.util.Set; import org.hibernate.envers.Audited; @@ -36,51 +37,57 @@ import org.hibernate.envers.Audited; @Entity @Audited public class ReferencedEntity { - @Id - private Integer id; + @Id + private Integer id; - @OneToMany(mappedBy = "referenced") - private Set referencing; + @OneToMany(mappedBy = "referenced") + private Set referencing; - public ReferencedEntity(Integer id) { - this.id = id; - } + public ReferencedEntity(Integer id) { + this.id = id; + } - public ReferencedEntity() { - } + public ReferencedEntity() { + } - public Set getReferencing() { - return referencing; - } + public Set getReferencing() { + return referencing; + } - public void setReferencing(Set referencing) { - this.referencing = referencing; - } + public void setReferencing(Set referencing) { + this.referencing = referencing; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ReferencedEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ReferencedEntity) ) { + return false; + } - ReferencedEntity that = (ReferencedEntity) o; + ReferencedEntity that = (ReferencedEntity) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - return id; - } + public int hashCode() { + return id; + } - public String toString() { - return "ReferencedEntity(id = " + getId() + ")"; - } + public String toString() { + return "ReferencedEntity(id = " + getId() + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/notownedrelation/Address.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/notownedrelation/Address.java index 9894d343e7..0768d117fe 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/notownedrelation/Address.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/notownedrelation/Address.java @@ -23,10 +23,11 @@ */ package org.hibernate.envers.test.integration.inheritance.tableperclass.notownedrelation; -import java.io.Serializable; + import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.ManyToOne; +import java.io.Serializable; import org.hibernate.envers.Audited; @@ -41,15 +42,15 @@ public class Address implements Serializable { @ManyToOne private Contact contact; - public Address() { - } + public Address() { + } - public Address(Long id, String address1) { - this.id = id; - this.address1 = address1; - } + public Address(Long id, String address1) { + this.id = id; + this.address1 = address1; + } - public Long getId() { + public Long getId() { return id; } @@ -73,26 +74,34 @@ public class Address implements Serializable { this.contact = contact; } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof Address)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof Address) ) { + return false; + } - Address address = (Address) o; + Address address = (Address) o; - if (address1 != null ? !address1.equals(address.address1) : address.address1 != null) return false; - if (id != null ? !id.equals(address.id) : address.id != null) return false; + if ( address1 != null ? !address1.equals( address.address1 ) : address.address1 != null ) { + return false; + } + if ( id != null ? !id.equals( address.id ) : address.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (address1 != null ? address1.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (address1 != null ? address1.hashCode() : 0); + return result; + } - public String toString() { - return "Address(id = " + getId() + ", address1 = " + getAddress1() + ")"; - } + public String toString() { + return "Address(id = " + getId() + ", address1 = " + getAddress1() + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/notownedrelation/Contact.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/notownedrelation/Contact.java index a8129d4379..367cbecb59 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/notownedrelation/Contact.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/notownedrelation/Contact.java @@ -23,53 +23,58 @@ */ package org.hibernate.envers.test.integration.inheritance.tableperclass.notownedrelation; -import java.io.Serializable; -import java.util.Set; + import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; import javax.persistence.OneToMany; +import java.io.Serializable; +import java.util.Set; import org.hibernate.envers.Audited; @Entity -@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS) +@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) @Audited public class Contact implements Serializable { - @Id - private Long id; + @Id + private Long id; - private String email; + private String email; - @OneToMany(mappedBy="contact") - private Set
addresses; + @OneToMany(mappedBy = "contact") + private Set
addresses; - public Contact() { - } + public Contact() { + } - public Contact(Long id, String email) { - this.id = id; - this.email = email; - } + public Contact(Long id, String email) { + this.id = id; + this.email = email; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } - public Long getId() { - return id; - } - public void setId(Long id) { - this.id = id; - } public String getEmail() { - return email; - } - public void setEmail(String email) { - this.email = email; - } + return email; + } - public Set
getAddresses() { - return addresses; - } - public void setAddresses(Set
addresses) { - this.addresses = addresses; - } + public void setEmail(String email) { + this.email = email; + } + + public Set
getAddresses() { + return addresses; + } + + public void setAddresses(Set
addresses) { + this.addresses = addresses; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/notownedrelation/NotOwnedBidirectional.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/notownedrelation/NotOwnedBidirectional.java index 612fab0999..5596d82019 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/notownedrelation/NotOwnedBidirectional.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/notownedrelation/NotOwnedBidirectional.java @@ -24,91 +24,95 @@ package org.hibernate.envers.test.integration.inheritance.tableperclass.notownedrelation; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.tools.TestTools; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class NotOwnedBidirectional extends BaseEnversJPAFunctionalTestCase { - private Long pc_id; - private Long a1_id; - private Long a2_id; + private Long pc_id; + private Long a1_id; + private Long a2_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { Address.class, Contact.class, PersonalContact.class }; - } + return new Class[] {Address.class, Contact.class, PersonalContact.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - pc_id = 1l; - a1_id = 10l; - a2_id = 100l; + pc_id = 1l; + a1_id = 10l; + a2_id = 100l; - // Rev 1 - em.getTransaction().begin(); + // Rev 1 + em.getTransaction().begin(); - PersonalContact pc = new PersonalContact(pc_id, "e", "f"); + PersonalContact pc = new PersonalContact( pc_id, "e", "f" ); - Address a1 = new Address(a1_id, "a1"); - a1.setContact(pc); + Address a1 = new Address( a1_id, "a1" ); + a1.setContact( pc ); - em.persist(pc); - em.persist(a1); + em.persist( pc ); + em.persist( a1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Rev 2 - em.getTransaction().begin(); + // Rev 2 + em.getTransaction().begin(); - pc = em.find(PersonalContact.class, pc_id); + pc = em.find( PersonalContact.class, pc_id ); - Address a2 = new Address(a2_id, "a2"); - a2.setContact(pc); + Address a2 = new Address( a2_id, "a2" ); + a2.setContact( pc ); - em.persist(a2); + em.persist( a2 ); - em.getTransaction().commit(); - } + em.getTransaction().commit(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(Contact.class, pc_id)); - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(PersonalContact.class, pc_id)); + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( Contact.class, pc_id ) ); + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( PersonalContact.class, pc_id ) ); - assert Arrays.asList(1).equals(getAuditReader().getRevisions(Address.class, a1_id)); - assert Arrays.asList(1).equals(getAuditReader().getRevisions(Address.class, a1_id)); + assert Arrays.asList( 1 ).equals( getAuditReader().getRevisions( Address.class, a1_id ) ); + assert Arrays.asList( 1 ).equals( getAuditReader().getRevisions( Address.class, a1_id ) ); - assert Arrays.asList(2).equals(getAuditReader().getRevisions(Address.class, a2_id)); - assert Arrays.asList(2).equals(getAuditReader().getRevisions(Address.class, a2_id)); - } + assert Arrays.asList( 2 ).equals( getAuditReader().getRevisions( Address.class, a2_id ) ); + assert Arrays.asList( 2 ).equals( getAuditReader().getRevisions( Address.class, a2_id ) ); + } - @Test - public void testHistoryOfContact() { - assert getAuditReader().find(Contact.class, pc_id, 1).getAddresses().equals( - TestTools.makeSet(new Address(a1_id, "a1"))); + @Test + public void testHistoryOfContact() { + assert getAuditReader().find( Contact.class, pc_id, 1 ).getAddresses().equals( + TestTools.makeSet( new Address( a1_id, "a1" ) ) + ); - assert getAuditReader().find(Contact.class, pc_id, 2).getAddresses().equals( - TestTools.makeSet(new Address(a1_id, "a1"), new Address(a2_id, "a2"))); - } + assert getAuditReader().find( Contact.class, pc_id, 2 ).getAddresses().equals( + TestTools.makeSet( new Address( a1_id, "a1" ), new Address( a2_id, "a2" ) ) + ); + } - @Test - public void testHistoryOfPersonalContact() { - System.out.println(getAuditReader().find(PersonalContact.class, pc_id, 1).getAddresses()); - assert getAuditReader().find(PersonalContact.class, pc_id, 1).getAddresses().equals( - TestTools.makeSet(new Address(a1_id, "a1"))); + @Test + public void testHistoryOfPersonalContact() { + System.out.println( getAuditReader().find( PersonalContact.class, pc_id, 1 ).getAddresses() ); + assert getAuditReader().find( PersonalContact.class, pc_id, 1 ).getAddresses().equals( + TestTools.makeSet( new Address( a1_id, "a1" ) ) + ); - assert getAuditReader().find(PersonalContact.class, pc_id, 2).getAddresses().equals( - TestTools.makeSet(new Address(a1_id, "a1"), new Address(a2_id, "a2"))); - } + assert getAuditReader().find( PersonalContact.class, pc_id, 2 ).getAddresses().equals( + TestTools.makeSet( new Address( a1_id, "a1" ), new Address( a2_id, "a2" ) ) + ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/notownedrelation/PersonalContact.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/notownedrelation/PersonalContact.java index 647374ccfa..5aefdf77c2 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/notownedrelation/PersonalContact.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/notownedrelation/PersonalContact.java @@ -23,6 +23,7 @@ */ package org.hibernate.envers.test.integration.inheritance.tableperclass.notownedrelation; + import javax.persistence.Entity; import org.hibernate.envers.Audited; @@ -30,21 +31,21 @@ import org.hibernate.envers.Audited; @Entity @Audited public class PersonalContact extends Contact { - private String firstname; + private String firstname; - public PersonalContact() { - } + public PersonalContact() { + } - public PersonalContact(Long id, String email, String firstname) { - super(id, email); - this.firstname = firstname; - } + public PersonalContact(Long id, String email, String firstname) { + super( id, email ); + this.firstname = firstname; + } - public String getFirstname() { + public String getFirstname() { return firstname; } - public void setFirstname(String firstname) { + public void setFirstname(String firstname) { this.firstname = firstname; } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/relation/ChildIngEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/relation/ChildIngEntity.java index 2fd18872a0..6c2fc1aa75 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/relation/ChildIngEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/relation/ChildIngEntity.java @@ -23,6 +23,7 @@ */ package org.hibernate.envers.test.integration.inheritance.tableperclass.relation; + import javax.persistence.Basic; import javax.persistence.Entity; @@ -34,44 +35,52 @@ import org.hibernate.envers.Audited; @Entity @Audited public class ChildIngEntity extends ParentIngEntity { - @Basic - private Long numVal; + @Basic + private Long numVal; - public ChildIngEntity() { - } + public ChildIngEntity() { + } - public ChildIngEntity(Integer id, String data, Long numVal) { - super(id, data); - this.numVal = numVal; - } + public ChildIngEntity(Integer id, String data, Long numVal) { + super( id, data ); + this.numVal = numVal; + } - public Long getNumVal() { - return numVal; - } + public Long getNumVal() { + return numVal; + } - public void setNumVal(Long numVal) { - this.numVal = numVal; - } + public void setNumVal(Long numVal) { + this.numVal = numVal; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ChildIngEntity)) return false; - if (!super.equals(o)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ChildIngEntity) ) { + return false; + } + if ( !super.equals( o ) ) { + return false; + } - ChildIngEntity childEntity = (ChildIngEntity) o; + ChildIngEntity childEntity = (ChildIngEntity) o; - if (numVal != null ? !numVal.equals(childEntity.numVal) : childEntity.numVal != null) return false; + if ( numVal != null ? !numVal.equals( childEntity.numVal ) : childEntity.numVal != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result = super.hashCode(); - result = 31 * result + (numVal != null ? numVal.hashCode() : 0); - return result; - } + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (numVal != null ? numVal.hashCode() : 0); + return result; + } - public String toString() { - return "ChildIngEntity(id = " + getId() + ", data = " + getData() + ", numVal = " + numVal + ")"; - } + public String toString() { + return "ChildIngEntity(id = " + getId() + ", data = " + getData() + ", numVal = " + numVal + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/relation/ParentIngEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/relation/ParentIngEntity.java index 32f8c12cb3..e342368712 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/relation/ParentIngEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/relation/ParentIngEntity.java @@ -23,6 +23,7 @@ */ package org.hibernate.envers.test.integration.inheritance.tableperclass.relation; + import javax.persistence.Basic; import javax.persistence.Entity; import javax.persistence.Id; @@ -39,67 +40,75 @@ import org.hibernate.envers.Audited; @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) @Audited public class ParentIngEntity { - @Id - private Integer id; + @Id + private Integer id; - @Basic - private String data; + @Basic + private String data; - @ManyToOne - private ReferencedEntity referenced; + @ManyToOne + private ReferencedEntity referenced; - public ParentIngEntity() { - } + public ParentIngEntity() { + } - public ParentIngEntity(Integer id, String data) { - this.id = id; - this.data = data; - } + public ParentIngEntity(Integer id, String data) { + this.id = id; + this.data = data; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public ReferencedEntity getReferenced() { - return referenced; - } + public ReferencedEntity getReferenced() { + return referenced; + } - public void setReferenced(ReferencedEntity referenced) { - this.referenced = referenced; - } + public void setReferenced(ReferencedEntity referenced) { + this.referenced = referenced; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ParentIngEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ParentIngEntity) ) { + return false; + } - ParentIngEntity that = (ParentIngEntity) o; + ParentIngEntity that = (ParentIngEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "ParentIngEntity(id = " + getId() + ", data = " + getData() + ")"; - } + public String toString() { + return "ParentIngEntity(id = " + getId() + ", data = " + getData() + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/relation/PolymorphicCollection.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/relation/PolymorphicCollection.java index 4622934bf5..360bb82a5a 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/relation/PolymorphicCollection.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/relation/PolymorphicCollection.java @@ -24,83 +24,85 @@ package org.hibernate.envers.test.integration.inheritance.tableperclass.relation; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.tools.TestTools; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class PolymorphicCollection extends BaseEnversJPAFunctionalTestCase { - private Integer ed_id1; - private Integer c_id; - private Integer p_id; + private Integer ed_id1; + private Integer c_id; + private Integer p_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { ChildIngEntity.class, ParentIngEntity.class, ReferencedEntity.class }; - } + return new Class[] {ChildIngEntity.class, ParentIngEntity.class, ReferencedEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - ed_id1 = 1; - p_id = 10; - c_id = 100; + ed_id1 = 1; + p_id = 10; + c_id = 100; - // Rev 1 - em.getTransaction().begin(); + // Rev 1 + em.getTransaction().begin(); - ReferencedEntity re = new ReferencedEntity(ed_id1); - em.persist(re); + ReferencedEntity re = new ReferencedEntity( ed_id1 ); + em.persist( re ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Rev 2 - em.getTransaction().begin(); + // Rev 2 + em.getTransaction().begin(); - re = em.find(ReferencedEntity.class, ed_id1); + re = em.find( ReferencedEntity.class, ed_id1 ); - ParentIngEntity pie = new ParentIngEntity(p_id,"x"); - pie.setReferenced(re); - em.persist(pie); - p_id = pie.getId(); + ParentIngEntity pie = new ParentIngEntity( p_id, "x" ); + pie.setReferenced( re ); + em.persist( pie ); + p_id = pie.getId(); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Rev 3 - em.getTransaction().begin(); + // Rev 3 + em.getTransaction().begin(); - re = em.find(ReferencedEntity.class, ed_id1); + re = em.find( ReferencedEntity.class, ed_id1 ); - ChildIngEntity cie = new ChildIngEntity(c_id, "y", 1l); - cie.setReferenced(re); - em.persist(cie); - c_id = cie.getId(); + ChildIngEntity cie = new ChildIngEntity( c_id, "y", 1l ); + cie.setReferenced( re ); + em.persist( cie ); + c_id = cie.getId(); - em.getTransaction().commit(); - } + em.getTransaction().commit(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2, 3).equals(getAuditReader().getRevisions(ReferencedEntity.class, ed_id1)); - assert Arrays.asList(2).equals(getAuditReader().getRevisions(ParentIngEntity.class, p_id)); - assert Arrays.asList(3).equals(getAuditReader().getRevisions(ChildIngEntity.class, c_id)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2, 3 ).equals( getAuditReader().getRevisions( ReferencedEntity.class, ed_id1 ) ); + assert Arrays.asList( 2 ).equals( getAuditReader().getRevisions( ParentIngEntity.class, p_id ) ); + assert Arrays.asList( 3 ).equals( getAuditReader().getRevisions( ChildIngEntity.class, c_id ) ); + } - @Test - public void testHistoryOfReferencedCollection() { - assert getAuditReader().find(ReferencedEntity.class, ed_id1, 1).getReferencing().size() == 0; - assert getAuditReader().find(ReferencedEntity.class, ed_id1, 2).getReferencing().equals( - TestTools.makeSet(new ParentIngEntity(p_id, "x"))); - assert getAuditReader().find(ReferencedEntity.class, ed_id1, 3).getReferencing().equals( - TestTools.makeSet(new ParentIngEntity(p_id, "x"), new ChildIngEntity(c_id, "y", 1l))); - } + @Test + public void testHistoryOfReferencedCollection() { + assert getAuditReader().find( ReferencedEntity.class, ed_id1, 1 ).getReferencing().size() == 0; + assert getAuditReader().find( ReferencedEntity.class, ed_id1, 2 ).getReferencing().equals( + TestTools.makeSet( new ParentIngEntity( p_id, "x" ) ) + ); + assert getAuditReader().find( ReferencedEntity.class, ed_id1, 3 ).getReferencing().equals( + TestTools.makeSet( new ParentIngEntity( p_id, "x" ), new ChildIngEntity( c_id, "y", 1l ) ) + ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/relation/ReferencedEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/relation/ReferencedEntity.java index 79297a6c32..b7e12e8a71 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/relation/ReferencedEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/relation/ReferencedEntity.java @@ -23,10 +23,11 @@ */ package org.hibernate.envers.test.integration.inheritance.tableperclass.relation; -import java.util.Set; + import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.OneToMany; +import java.util.Set; import org.hibernate.envers.Audited; @@ -36,51 +37,57 @@ import org.hibernate.envers.Audited; @Entity @Audited public class ReferencedEntity { - @Id - private Integer id; + @Id + private Integer id; - @OneToMany(mappedBy = "referenced") - private Set referencing; + @OneToMany(mappedBy = "referenced") + private Set referencing; - public ReferencedEntity() { - } + public ReferencedEntity() { + } - public ReferencedEntity(Integer id) { - this.id = id; - } + public ReferencedEntity(Integer id) { + this.id = id; + } - public Set getReferencing() { - return referencing; - } + public Set getReferencing() { + return referencing; + } - public void setReferencing(Set referencing) { - this.referencing = referencing; - } + public void setReferencing(Set referencing) { + this.referencing = referencing; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ReferencedEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ReferencedEntity) ) { + return false; + } - ReferencedEntity that = (ReferencedEntity) o; + ReferencedEntity that = (ReferencedEntity) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - return id; - } + public int hashCode() { + return id; + } - public String toString() { - return "ReferencedEntity(id = " + getId() + ")"; - } + public String toString() { + return "ReferencedEntity(id = " + getId() + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/components/Component1.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/components/Component1.java index 29c3fae061..af89307640 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/components/Component1.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/components/Component1.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.interfaces.components; + import javax.persistence.Embeddable; /** @@ -29,7 +30,7 @@ import javax.persistence.Embeddable; */ @Embeddable public class Component1 implements IComponent { - private String data; + private String data; public Component1(String data) { this.data = data; @@ -48,12 +49,18 @@ public class Component1 implements IComponent { @Override public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof Component1)) return false; + if ( this == o ) { + return true; + } + if ( !(o instanceof Component1) ) { + return false; + } Component1 that = (Component1) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } return true; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/components/ComponentTestEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/components/ComponentTestEntity.java index 47fc53d81d..4901af1b80 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/components/ComponentTestEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/components/ComponentTestEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.interfaces.components; + import javax.persistence.Embedded; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -34,18 +35,18 @@ import org.hibernate.envers.Audited; * @author Adam Warski (adam at warski dot org) */ @Entity - @Audited +@Audited public class ComponentTestEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - @Embedded + @Embedded @Target(Component1.class) - private IComponent comp1; + private IComponent comp1; - public ComponentTestEntity() { - } + public ComponentTestEntity() { + } public ComponentTestEntity(IComponent comp1) { this.comp1 = comp1; @@ -57,12 +58,12 @@ public class ComponentTestEntity { } public Integer getId() { - return id; - } + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } public IComponent getComp1() { return comp1; @@ -74,12 +75,18 @@ public class ComponentTestEntity { @Override public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ComponentTestEntity)) return false; + if ( this == o ) { + return true; + } + if ( !(o instanceof ComponentTestEntity) ) { + return false; + } ComponentTestEntity that = (ComponentTestEntity) o; - if (comp1 != null ? !comp1.equals(that.comp1) : that.comp1 != null) return false; + if ( comp1 != null ? !comp1.equals( that.comp1 ) : that.comp1 != null ) { + return false; + } return true; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/components/IComponent.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/components/IComponent.java index e0eebf6485..d3d7d7c159 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/components/IComponent.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/components/IComponent.java @@ -6,5 +6,6 @@ package org.hibernate.envers.test.integration.interfaces.components; */ public interface IComponent { String getData(); + void setData(String data); } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/components/InterfacesComponents.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/components/InterfacesComponents.java index ee3dbf8c36..f28e6032ad 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/components/InterfacesComponents.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/components/InterfacesComponents.java @@ -23,74 +23,74 @@ */ package org.hibernate.envers.test.integration.interfaces.components; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class InterfacesComponents extends BaseEnversJPAFunctionalTestCase { - private Integer id1; + private Integer id1; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { ComponentTestEntity.class }; - } + return new Class[] {ComponentTestEntity.class}; + } - @Test - @Priority(10) - public void initData() { - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); + @Test + @Priority(10) + public void initData() { + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); - ComponentTestEntity cte1 = new ComponentTestEntity(new Component1("a")); + ComponentTestEntity cte1 = new ComponentTestEntity( new Component1( "a" ) ); - em.persist(cte1); + em.persist( cte1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em = getEntityManager(); - em.getTransaction().begin(); + // Revision 2 + em = getEntityManager(); + em.getTransaction().begin(); - cte1 = em.find(ComponentTestEntity.class, cte1.getId()); + cte1 = em.find( ComponentTestEntity.class, cte1.getId() ); - cte1.setComp1(new Component1("b")); + cte1.setComp1( new Component1( "b" ) ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 - em = getEntityManager(); - em.getTransaction().begin(); + // Revision 3 + em = getEntityManager(); + em.getTransaction().begin(); - cte1 = em.find(ComponentTestEntity.class, cte1.getId()); + cte1 = em.find( ComponentTestEntity.class, cte1.getId() ); - cte1.getComp1().setData("c"); + cte1.getComp1().setData( "c" ); - em.getTransaction().commit(); + em.getTransaction().commit(); - id1 = cte1.getId(); - } + id1 = cte1.getId(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2, 3).equals(getAuditReader().getRevisions(ComponentTestEntity.class, id1)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2, 3 ).equals( getAuditReader().getRevisions( ComponentTestEntity.class, id1 ) ); + } - @Test - public void testHistoryOfId1() { - ComponentTestEntity ver1 = new ComponentTestEntity(id1, new Component1("a")); - ComponentTestEntity ver2 = new ComponentTestEntity(id1, new Component1("b")); - ComponentTestEntity ver3 = new ComponentTestEntity(id1, new Component1("c")); + @Test + public void testHistoryOfId1() { + ComponentTestEntity ver1 = new ComponentTestEntity( id1, new Component1( "a" ) ); + ComponentTestEntity ver2 = new ComponentTestEntity( id1, new Component1( "b" ) ); + ComponentTestEntity ver3 = new ComponentTestEntity( id1, new Component1( "c" ) ); - assert getAuditReader().find(ComponentTestEntity.class, id1, 1).equals(ver1); - assert getAuditReader().find(ComponentTestEntity.class, id1, 2).equals(ver2); - assert getAuditReader().find(ComponentTestEntity.class, id1, 3).equals(ver3); - } + assert getAuditReader().find( ComponentTestEntity.class, id1, 1 ).equals( ver1 ); + assert getAuditReader().find( ComponentTestEntity.class, id1, 2 ).equals( ver2 ); + assert getAuditReader().find( ComponentTestEntity.class, id1, 3 ).equals( ver3 ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/allAudited/AbstractAllAuditedTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/allAudited/AbstractAllAuditedTest.java index a4f858f1b8..9938e67fd3 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/allAudited/AbstractAllAuditedTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/allAudited/AbstractAllAuditedTest.java @@ -1,15 +1,15 @@ package org.hibernate.envers.test.integration.interfaces.hbm.allAudited; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Assert; -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.exception.NotAuditedException; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; +import org.junit.Assert; +import org.junit.Test; + /** * @author Hern�n Chanfreau * @author Adam Warski (adam at warski dot org) @@ -17,106 +17,107 @@ import org.hibernate.envers.test.Priority; public abstract class AbstractAllAuditedTest extends BaseEnversJPAFunctionalTestCase { private long ai_id; private long nai_id; - - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); - AuditedImplementor ai = new AuditedImplementor(); - ai.setData("La data"); - ai.setAuditedImplementorData("audited implementor data"); - - NonAuditedImplementor nai = new NonAuditedImplementor(); - nai.setData("info"); - nai.setNonAuditedImplementorData("sttring"); - - // Revision 1 - em.getTransaction().begin(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - em.persist(ai); - - em.persist(nai); + AuditedImplementor ai = new AuditedImplementor(); + ai.setData( "La data" ); + ai.setAuditedImplementorData( "audited implementor data" ); - em.getTransaction().commit(); + NonAuditedImplementor nai = new NonAuditedImplementor(); + nai.setData( "info" ); + nai.setNonAuditedImplementorData( "sttring" ); - // Revision 2 - em.getTransaction().begin(); + // Revision 1 + em.getTransaction().begin(); - ai = em.find(AuditedImplementor.class, ai.getId()); - nai = em.find(NonAuditedImplementor.class, nai.getId()); + em.persist( ai ); - ai.setData("La data 2"); - ai.setAuditedImplementorData("audited implementor data 2"); + em.persist( nai ); - nai.setData("info 2"); - nai.setNonAuditedImplementorData("sttring 2"); + em.getTransaction().commit(); - em.getTransaction().commit(); + // Revision 2 + em.getTransaction().begin(); - // + ai = em.find( AuditedImplementor.class, ai.getId() ); + nai = em.find( NonAuditedImplementor.class, nai.getId() ); - ai_id = ai.getId(); - nai_id = nai.getId(); - } + ai.setData( "La data 2" ); + ai.setAuditedImplementorData( "audited implementor data 2" ); - @Test - public void testRevisions() { - Assert.assertEquals(getAuditReader().getRevisions(AuditedImplementor.class, ai_id), Arrays.asList(1, 2)); - } + nai.setData( "info 2" ); + nai.setNonAuditedImplementorData( "sttring 2" ); - @Test - public void testRetrieveAudited() { - // levanto las versiones actuales - AuditedImplementor ai = getEntityManager().find(AuditedImplementor.class, ai_id); - assert ai != null; - SimpleInterface si = getEntityManager().find(SimpleInterface.class, ai_id); - assert si != null; + em.getTransaction().commit(); - // levanto las de la revisi�n 1, ninguna debe ser null - AuditedImplementor ai_rev1 = getAuditReader().find(AuditedImplementor.class, ai_id, 1); - assert ai_rev1 != null; - SimpleInterface si_rev1 = getAuditReader().find(SimpleInterface.class, ai_id, 1); - assert si_rev1 != null; + // - AuditedImplementor ai_rev2 = getAuditReader().find(AuditedImplementor.class, ai_id, 2); - assert ai_rev2 != null; - SimpleInterface si_rev2 = getAuditReader().find(SimpleInterface.class, ai_id, 2); - assert si_rev2 != null; - - // data de las actuales no debe ser null - Assert.assertEquals(ai.getData(), "La data 2"); - Assert.assertEquals(si.getData(), "La data 2"); - // la data de las revisiones no debe ser null - Assert.assertEquals(ai_rev1.getData(), "La data"); - Assert.assertEquals(si_rev1.getData(), "La data"); + ai_id = ai.getId(); + nai_id = nai.getId(); + } - Assert.assertEquals(ai_rev2.getData(), "La data 2"); - Assert.assertEquals(si_rev2.getData(), "La data 2"); - } - - @Test - public void testRetrieveNonAudited() { - // levanto las versiones actuales - NonAuditedImplementor nai = getEntityManager().find(NonAuditedImplementor.class, nai_id); - assert nai != null; - SimpleInterface si = getEntityManager().find(SimpleInterface.class, nai_id); - assert si != null; - - assert si.getData().equals(nai.getData()); + @Test + public void testRevisions() { + Assert.assertEquals( getAuditReader().getRevisions( AuditedImplementor.class, ai_id ), Arrays.asList( 1, 2 ) ); + } - try { - // levanto la revision - getAuditReader().find(NonAuditedImplementor.class, nai_id, 1); - assert false; - } catch (Exception e) { - // no es auditable!!! - assert (e instanceof NotAuditedException); + @Test + public void testRetrieveAudited() { + // levanto las versiones actuales + AuditedImplementor ai = getEntityManager().find( AuditedImplementor.class, ai_id ); + assert ai != null; + SimpleInterface si = getEntityManager().find( SimpleInterface.class, ai_id ); + assert si != null; + + // levanto las de la revisi�n 1, ninguna debe ser null + AuditedImplementor ai_rev1 = getAuditReader().find( AuditedImplementor.class, ai_id, 1 ); + assert ai_rev1 != null; + SimpleInterface si_rev1 = getAuditReader().find( SimpleInterface.class, ai_id, 1 ); + assert si_rev1 != null; + + AuditedImplementor ai_rev2 = getAuditReader().find( AuditedImplementor.class, ai_id, 2 ); + assert ai_rev2 != null; + SimpleInterface si_rev2 = getAuditReader().find( SimpleInterface.class, ai_id, 2 ); + assert si_rev2 != null; + + // data de las actuales no debe ser null + Assert.assertEquals( ai.getData(), "La data 2" ); + Assert.assertEquals( si.getData(), "La data 2" ); + // la data de las revisiones no debe ser null + Assert.assertEquals( ai_rev1.getData(), "La data" ); + Assert.assertEquals( si_rev1.getData(), "La data" ); + + Assert.assertEquals( ai_rev2.getData(), "La data 2" ); + Assert.assertEquals( si_rev2.getData(), "La data 2" ); + } + + @Test + public void testRetrieveNonAudited() { + // levanto las versiones actuales + NonAuditedImplementor nai = getEntityManager().find( NonAuditedImplementor.class, nai_id ); + assert nai != null; + SimpleInterface si = getEntityManager().find( SimpleInterface.class, nai_id ); + assert si != null; + + assert si.getData().equals( nai.getData() ); + + try { + // levanto la revision + getAuditReader().find( NonAuditedImplementor.class, nai_id, 1 ); + assert false; } - - // levanto la revision que no es auditable pero con la interfaz, el resultado debe ser null - SimpleInterface si_rev1 = getAuditReader().find(SimpleInterface.class, nai_id, 1); - assert si_rev1 == null; - - } + catch (Exception e) { + // no es auditable!!! + assert (e instanceof NotAuditedException); + } + + // levanto la revision que no es auditable pero con la interfaz, el resultado debe ser null + SimpleInterface si_rev1 = getAuditReader().find( SimpleInterface.class, nai_id, 1 ); + assert si_rev1 == null; + + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/allAudited/AuditedImplementor.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/allAudited/AuditedImplementor.java index fd10b8ae78..f134b0e38d 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/allAudited/AuditedImplementor.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/allAudited/AuditedImplementor.java @@ -1,9 +1,9 @@ package org.hibernate.envers.test.integration.interfaces.hbm.allAudited; + import org.hibernate.envers.Audited; /** * @author Hern�n Chanfreau - * */ @Audited public class AuditedImplementor implements SimpleInterface { diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/allAudited/NonAuditedImplementor.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/allAudited/NonAuditedImplementor.java index c85ab20d75..83dce67de6 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/allAudited/NonAuditedImplementor.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/allAudited/NonAuditedImplementor.java @@ -1,10 +1,8 @@ package org.hibernate.envers.test.integration.interfaces.hbm.allAudited; - /** * @author Hern�n Chanfreau - * */ public class NonAuditedImplementor implements SimpleInterface { private long id; diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/allAudited/SimpleInterface.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/allAudited/SimpleInterface.java index 8995125430..97d6fa3e44 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/allAudited/SimpleInterface.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/allAudited/SimpleInterface.java @@ -1,19 +1,19 @@ package org.hibernate.envers.test.integration.interfaces.hbm.allAudited; + import org.hibernate.envers.Audited; /** * @author Hern�n Chanfreau - * */ @Audited public interface SimpleInterface { - + long getId(); - + void setId(long id); - + String getData(); - + void setData(String data); } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/allAudited/joined/JoinedAllAuditedTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/allAudited/joined/JoinedAllAuditedTest.java index 0589bd6c83..0242ecf0dd 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/allAudited/joined/JoinedAllAuditedTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/allAudited/joined/JoinedAllAuditedTest.java @@ -6,8 +6,8 @@ import org.hibernate.envers.test.integration.interfaces.hbm.allAudited.AbstractA * @author Hern�n Chanfreau */ public class JoinedAllAuditedTest extends AbstractAllAuditedTest { - @Override - protected String[] getMappings() { - return new String[]{"mappings/interfaces/joinedAllAuditedMappings.hbm.xml"}; - } + @Override + protected String[] getMappings() { + return new String[] {"mappings/interfaces/joinedAllAuditedMappings.hbm.xml"}; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/allAudited/subclass/SubclassAllAuditedTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/allAudited/subclass/SubclassAllAuditedTest.java index 3cf243f48c..6cbb92252d 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/allAudited/subclass/SubclassAllAuditedTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/allAudited/subclass/SubclassAllAuditedTest.java @@ -6,8 +6,8 @@ import org.hibernate.envers.test.integration.interfaces.hbm.allAudited.AbstractA * @author Hern�n Chanfreau */ public class SubclassAllAuditedTest extends AbstractAllAuditedTest { - @Override - protected String[] getMappings() { - return new String[]{"mappings/interfaces/subclassAllAuditedMappings.hbm.xml"}; - } + @Override + protected String[] getMappings() { + return new String[] {"mappings/interfaces/subclassAllAuditedMappings.hbm.xml"}; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/allAudited/union/UnionAllAuditedTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/allAudited/union/UnionAllAuditedTest.java index b84209dea1..033741a0d7 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/allAudited/union/UnionAllAuditedTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/allAudited/union/UnionAllAuditedTest.java @@ -6,8 +6,8 @@ import org.hibernate.envers.test.integration.interfaces.hbm.allAudited.AbstractA * @author Hern�n Chanfreau */ public class UnionAllAuditedTest extends AbstractAllAuditedTest { - @Override - protected String[] getMappings() { - return new String[]{"mappings/interfaces/unionAllAuditedMappings.hbm.xml"}; - } + @Override + protected String[] getMappings() { + return new String[] {"mappings/interfaces/unionAllAuditedMappings.hbm.xml"}; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited/AbstractPropertiesAuditedTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited/AbstractPropertiesAuditedTest.java index f85c393403..5bf313b22b 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited/AbstractPropertiesAuditedTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited/AbstractPropertiesAuditedTest.java @@ -2,43 +2,42 @@ package org.hibernate.envers.test.integration.interfaces.hbm.propertiesAudited; import javax.persistence.EntityManager; -import org.junit.Test; - import org.hibernate.envers.exception.NotAuditedException; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; +import org.junit.Test; + /** * @author Hern�n Chanfreau - * */ -public abstract class AbstractPropertiesAuditedTest extends BaseEnversJPAFunctionalTestCase { +public abstract class AbstractPropertiesAuditedTest extends BaseEnversJPAFunctionalTestCase { private long ai_id; private long nai_id; private static int NUMERITO = 555; @Test - @Priority(10) + @Priority(10) public void initData() { EntityManager em = getEntityManager(); AuditedImplementor ai = new AuditedImplementor(); - ai.setData("La data"); - ai.setAuditedImplementorData("audited implementor data"); - ai.setNumerito(NUMERITO); + ai.setData( "La data" ); + ai.setAuditedImplementorData( "audited implementor data" ); + ai.setNumerito( NUMERITO ); NonAuditedImplementor nai = new NonAuditedImplementor(); - nai.setData("info"); - nai.setNonAuditedImplementorData("sttring"); - nai.setNumerito(NUMERITO); + nai.setData( "info" ); + nai.setNonAuditedImplementorData( "sttring" ); + nai.setNumerito( NUMERITO ); // Revision 1 em.getTransaction().begin(); - em.persist(ai); + em.persist( ai ); - em.persist(nai); + em.persist( nai ); em.getTransaction().commit(); @@ -54,18 +53,24 @@ public abstract class AbstractPropertiesAuditedTest extends BaseEnversJPAFunctio public void testRetrieveAudited() { // levanto las versiones actuales AuditedImplementor ai = getEntityManager().find( - AuditedImplementor.class, ai_id); + AuditedImplementor.class, ai_id + ); assert ai != null; - SimpleInterface si = getEntityManager().find(SimpleInterface.class, - ai_id); + SimpleInterface si = getEntityManager().find( + SimpleInterface.class, + ai_id + ); assert si != null; // levanto las de la revisi�n 1, ninguna debe ser null AuditedImplementor ai_rev1 = getAuditReader().find( - AuditedImplementor.class, ai_id, 1); + AuditedImplementor.class, ai_id, 1 + ); assert ai_rev1 != null; - SimpleInterface si_rev1 = getAuditReader().find(SimpleInterface.class, - ai_id, 1); + SimpleInterface si_rev1 = getAuditReader().find( + SimpleInterface.class, + ai_id, 1 + ); assert si_rev1 != null; // data de las actuales no debe ser null @@ -83,27 +88,33 @@ public abstract class AbstractPropertiesAuditedTest extends BaseEnversJPAFunctio public void testRetrieveNonAudited() { // levanto las versiones actuales NonAuditedImplementor nai = getEntityManager().find( - NonAuditedImplementor.class, nai_id); + NonAuditedImplementor.class, nai_id + ); assert nai != null; - SimpleInterface si = getEntityManager().find(SimpleInterface.class, - nai_id); + SimpleInterface si = getEntityManager().find( + SimpleInterface.class, + nai_id + ); assert si != null; - assert si.getData().equals(nai.getData()); + assert si.getData().equals( nai.getData() ); try { // levanto la revision - getAuditReader().find(NonAuditedImplementor.class, nai_id, 1); + getAuditReader().find( NonAuditedImplementor.class, nai_id, 1 ); assert false; - } catch (Exception e) { + } + catch (Exception e) { // no es auditable!!! assert (e instanceof NotAuditedException); } // levanto la revision que no es auditable pero con la interfaz, el // resultado debe ser null - SimpleInterface si_rev1 = getAuditReader().find(SimpleInterface.class, - nai_id, 1); + SimpleInterface si_rev1 = getAuditReader().find( + SimpleInterface.class, + nai_id, 1 + ); assert si_rev1 == null; } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited/AuditedImplementor.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited/AuditedImplementor.java index 0289ffbe38..608b58849e 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited/AuditedImplementor.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited/AuditedImplementor.java @@ -1,9 +1,9 @@ package org.hibernate.envers.test.integration.interfaces.hbm.propertiesAudited; + import org.hibernate.envers.Audited; /** * @author Hern�n Chanfreau - * */ @Audited public class AuditedImplementor implements SimpleInterface { @@ -38,7 +38,7 @@ public class AuditedImplementor implements SimpleInterface { public void setAuditedImplementorData(String implementorData) { this.auditedImplementorData = implementorData; } - + public int getNumerito() { return numerito; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited/SimpleInterface.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited/SimpleInterface.java index a125fca35f..08b5d55b64 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited/SimpleInterface.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited/SimpleInterface.java @@ -1,23 +1,23 @@ package org.hibernate.envers.test.integration.interfaces.hbm.propertiesAudited; + import org.hibernate.envers.Audited; /** * @author Hern�n Chanfreau - * */ public interface SimpleInterface { - + long getId(); - + void setId(long id); - + String getData(); - + void setData(String data); - + @Audited int getNumerito(); - + void setNumerito(int num); } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited/joined/JoinedPropertiesAuditedTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited/joined/JoinedPropertiesAuditedTest.java index a75f556ae3..ee043e4e48 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited/joined/JoinedPropertiesAuditedTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited/joined/JoinedPropertiesAuditedTest.java @@ -4,12 +4,11 @@ import org.hibernate.envers.test.integration.interfaces.hbm.propertiesAudited.Ab /** * @author Hern�n Chanfreau - * */ public class JoinedPropertiesAuditedTest extends AbstractPropertiesAuditedTest { @Override protected String[] getMappings() { - return new String[] { "mappings/interfaces/joinedPropertiesAuditedMappings.hbm.xml" }; - } + return new String[] {"mappings/interfaces/joinedPropertiesAuditedMappings.hbm.xml"}; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited/subclass/SubclassPropertiesAuditedTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited/subclass/SubclassPropertiesAuditedTest.java index fb50cf33b0..7caf878627 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited/subclass/SubclassPropertiesAuditedTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited/subclass/SubclassPropertiesAuditedTest.java @@ -4,11 +4,10 @@ import org.hibernate.envers.test.integration.interfaces.hbm.propertiesAudited.Ab /** * @author Hern�n Chanfreau - * */ public class SubclassPropertiesAuditedTest extends AbstractPropertiesAuditedTest { @Override protected String[] getMappings() { - return new String[] { "mappings/interfaces/subclassPropertiesAuditedMappings.hbm.xml" }; + return new String[] {"mappings/interfaces/subclassPropertiesAuditedMappings.hbm.xml"}; } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited/union/UnionPropertiesAuditedTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited/union/UnionPropertiesAuditedTest.java index 39a5da77bd..1ec2f8b854 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited/union/UnionPropertiesAuditedTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited/union/UnionPropertiesAuditedTest.java @@ -4,12 +4,11 @@ import org.hibernate.envers.test.integration.interfaces.hbm.propertiesAudited.Ab /** * @author Hern�n Chanfreau - * */ public class UnionPropertiesAuditedTest extends AbstractPropertiesAuditedTest { @Override protected String[] getMappings() { - return new String[] { "mappings/interfaces/unionPropertiesAuditedMappings.hbm.xml" }; - } + return new String[] {"mappings/interfaces/unionPropertiesAuditedMappings.hbm.xml"}; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited2/AbstractPropertiesAudited2Test.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited2/AbstractPropertiesAudited2Test.java index 2d287a8810..e87a27ca39 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited2/AbstractPropertiesAudited2Test.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited2/AbstractPropertiesAudited2Test.java @@ -2,15 +2,14 @@ package org.hibernate.envers.test.integration.interfaces.hbm.propertiesAudited2; import javax.persistence.EntityManager; -import org.junit.Test; - import org.hibernate.envers.exception.NotAuditedException; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; +import org.junit.Test; + /** * @author Hern�n Chanfreau - * */ public abstract class AbstractPropertiesAudited2Test extends BaseEnversJPAFunctionalTestCase { private long ai_id; @@ -19,26 +18,26 @@ public abstract class AbstractPropertiesAudited2Test extends BaseEnversJPAFuncti private static int NUMERITO = 555; @Test - @Priority(10) + @Priority(10) public void initData() { EntityManager em = getEntityManager(); AuditedImplementor ai = new AuditedImplementor(); - ai.setData("La data"); - ai.setAuditedImplementorData("audited implementor data"); - ai.setNumerito(NUMERITO); + ai.setData( "La data" ); + ai.setAuditedImplementorData( "audited implementor data" ); + ai.setNumerito( NUMERITO ); NonAuditedImplementor nai = new NonAuditedImplementor(); - nai.setData("info"); - nai.setNonAuditedImplementorData("sttring"); - nai.setNumerito(NUMERITO); + nai.setData( "info" ); + nai.setNonAuditedImplementorData( "sttring" ); + nai.setNumerito( NUMERITO ); // Revision 1 em.getTransaction().begin(); - em.persist(ai); + em.persist( ai ); - em.persist(nai); + em.persist( nai ); em.getTransaction().commit(); @@ -54,18 +53,24 @@ public abstract class AbstractPropertiesAudited2Test extends BaseEnversJPAFuncti public void testRetrieveAudited() { // levanto las versiones actuales AuditedImplementor ai = getEntityManager().find( - AuditedImplementor.class, ai_id); + AuditedImplementor.class, ai_id + ); assert ai != null; - SimpleInterface si = getEntityManager().find(SimpleInterface.class, - ai_id); + SimpleInterface si = getEntityManager().find( + SimpleInterface.class, + ai_id + ); assert si != null; // levanto las de la revisi�n 1, ninguna debe ser null AuditedImplementor ai_rev1 = getAuditReader().find( - AuditedImplementor.class, ai_id, 1); + AuditedImplementor.class, ai_id, 1 + ); assert ai_rev1 != null; - SimpleInterface si_rev1 = getAuditReader().find(SimpleInterface.class, - ai_id, 1); + SimpleInterface si_rev1 = getAuditReader().find( + SimpleInterface.class, + ai_id, 1 + ); assert si_rev1 != null; // data de las actuales no debe ser null @@ -83,27 +88,33 @@ public abstract class AbstractPropertiesAudited2Test extends BaseEnversJPAFuncti public void testRetrieveNonAudited() { // levanto las versiones actuales NonAuditedImplementor nai = getEntityManager().find( - NonAuditedImplementor.class, nai_id); + NonAuditedImplementor.class, nai_id + ); assert nai != null; - SimpleInterface si = getEntityManager().find(SimpleInterface.class, - nai_id); + SimpleInterface si = getEntityManager().find( + SimpleInterface.class, + nai_id + ); assert si != null; - assert si.getData().equals(nai.getData()); + assert si.getData().equals( nai.getData() ); try { // levanto la revision - getAuditReader().find(NonAuditedImplementor.class, nai_id, 1); + getAuditReader().find( NonAuditedImplementor.class, nai_id, 1 ); assert false; - } catch (Exception e) { + } + catch (Exception e) { // no es auditable!!! assert (e instanceof NotAuditedException); } // levanto la revision que no es auditable pero con la interfaz, el // resultado debe ser null - SimpleInterface si_rev1 = getAuditReader().find(SimpleInterface.class, - nai_id, 1); + SimpleInterface si_rev1 = getAuditReader().find( + SimpleInterface.class, + nai_id, 1 + ); assert si_rev1 == null; } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited2/AuditedImplementor.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited2/AuditedImplementor.java index 6e9c88b82d..8c736a9278 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited2/AuditedImplementor.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited2/AuditedImplementor.java @@ -1,9 +1,9 @@ package org.hibernate.envers.test.integration.interfaces.hbm.propertiesAudited2; + import org.hibernate.envers.Audited; /** * @author Hern�n Chanfreau - * */ @Audited public class AuditedImplementor implements SimpleInterface { @@ -38,7 +38,7 @@ public class AuditedImplementor implements SimpleInterface { public void setAuditedImplementorData(String implementorData) { this.auditedImplementorData = implementorData; } - + public int getNumerito() { return numerito; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited2/NonAuditedImplementor.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited2/NonAuditedImplementor.java index 356a686bd9..c252c6a7cb 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited2/NonAuditedImplementor.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited2/NonAuditedImplementor.java @@ -3,7 +3,6 @@ package org.hibernate.envers.test.integration.interfaces.hbm.propertiesAudited2; /** * @author Hern�n Chanfreau - * */ public class NonAuditedImplementor implements SimpleInterface { private long id; @@ -37,7 +36,7 @@ public class NonAuditedImplementor implements SimpleInterface { public void setNonAuditedImplementorData(String implementorData) { this.nonAuditedImplementorData = implementorData; } - + public int getNumerito() { return numerito; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited2/SimpleInterface.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited2/SimpleInterface.java index 4b7d4e1c2d..ba7153ab49 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited2/SimpleInterface.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited2/SimpleInterface.java @@ -1,24 +1,24 @@ package org.hibernate.envers.test.integration.interfaces.hbm.propertiesAudited2; + import org.hibernate.envers.Audited; /** * @author Hern�n Chanfreau - * */ public interface SimpleInterface { - + long getId(); - + void setId(long id); - + @Audited String getData(); - + void setData(String data); - + @Audited int getNumerito(); - + void setNumerito(int num); } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited2/joined/JoinedPropertiesAudited2Test.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited2/joined/JoinedPropertiesAudited2Test.java index ab69c7c6ce..7f4acf5475 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited2/joined/JoinedPropertiesAudited2Test.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited2/joined/JoinedPropertiesAudited2Test.java @@ -8,6 +8,6 @@ import org.hibernate.envers.test.integration.interfaces.hbm.propertiesAudited2.A public class JoinedPropertiesAudited2Test extends AbstractPropertiesAudited2Test { @Override protected String[] getMappings() { - return new String[] { "mappings/interfaces/joinedPropertiesAudited2Mappings.hbm.xml" }; + return new String[] {"mappings/interfaces/joinedPropertiesAudited2Mappings.hbm.xml"}; } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited2/subclass/SubclassPropertiesAudited2Test.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited2/subclass/SubclassPropertiesAudited2Test.java index 9bc97c4979..1adce3c08e 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited2/subclass/SubclassPropertiesAudited2Test.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited2/subclass/SubclassPropertiesAudited2Test.java @@ -4,12 +4,11 @@ import org.hibernate.envers.test.integration.interfaces.hbm.propertiesAudited2.A /** * @author Hern�n Chanfreau - * */ public class SubclassPropertiesAudited2Test extends AbstractPropertiesAudited2Test { @Override protected String[] getMappings() { - return new String[] { "mappings/interfaces/subclassPropertiesAudited2Mappings.hbm.xml" }; - } - + return new String[] {"mappings/interfaces/subclassPropertiesAudited2Mappings.hbm.xml"}; + } + } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited2/union/UnionPropertiesAudited2Test.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited2/union/UnionPropertiesAudited2Test.java index 5c1791599e..01088eafb8 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited2/union/UnionPropertiesAudited2Test.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/hbm/propertiesAudited2/union/UnionPropertiesAudited2Test.java @@ -4,11 +4,10 @@ import org.hibernate.envers.test.integration.interfaces.hbm.propertiesAudited2.A /** * @author Hern�n Chanfreau - * */ public class UnionPropertiesAudited2Test extends AbstractPropertiesAudited2Test { @Override protected String[] getMappings() { - return new String[] { "mappings/interfaces/unionPropertiesAudited2Mappings.hbm.xml" }; - } + return new String[] {"mappings/interfaces/unionPropertiesAudited2Mappings.hbm.xml"}; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/relation/InterfacesRelation.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/relation/InterfacesRelation.java index c4c3850c6c..2938caa36c 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/relation/InterfacesRelation.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/relation/InterfacesRelation.java @@ -23,94 +23,94 @@ */ package org.hibernate.envers.test.integration.interfaces.relation; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class InterfacesRelation extends BaseEnversJPAFunctionalTestCase { - private Integer ed1_id; - private Integer ed2_id; + private Integer ed1_id; + private Integer ed2_id; - private Integer ing1_id; + private Integer ing1_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { SetRefEdEntity.class, SetRefIngEntity.class }; - } + return new Class[] {SetRefEdEntity.class, SetRefIngEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - SetRefEdEntity ed1 = new SetRefEdEntity(1, "data_ed_1"); - SetRefEdEntity ed2 = new SetRefEdEntity(2, "data_ed_2"); + SetRefEdEntity ed1 = new SetRefEdEntity( 1, "data_ed_1" ); + SetRefEdEntity ed2 = new SetRefEdEntity( 2, "data_ed_2" ); - SetRefIngEntity ing1 = new SetRefIngEntity(3, "data_ing_1"); + SetRefIngEntity ing1 = new SetRefIngEntity( 3, "data_ing_1" ); - // Revision 1 - em.getTransaction().begin(); + // Revision 1 + em.getTransaction().begin(); - em.persist(ed1); - em.persist(ed2); + em.persist( ed1 ); + em.persist( ed2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 + // Revision 2 - em.getTransaction().begin(); + em.getTransaction().begin(); - ed1 = em.find(SetRefEdEntity.class, ed1.getId()); + ed1 = em.find( SetRefEdEntity.class, ed1.getId() ); - ing1.setReference(ed1); - em.persist(ing1); + ing1.setReference( ed1 ); + em.persist( ing1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 - em.getTransaction().begin(); + // Revision 3 + em.getTransaction().begin(); - ing1 = em.find(SetRefIngEntity.class, ing1.getId()); - ed2 = em.find(SetRefEdEntity.class, ed2.getId()); + ing1 = em.find( SetRefIngEntity.class, ing1.getId() ); + ed2 = em.find( SetRefEdEntity.class, ed2.getId() ); - ing1.setReference(ed2); + ing1.setReference( ed2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // + // - ed1_id = ed1.getId(); - ed2_id = ed2.getId(); + ed1_id = ed1.getId(); + ed2_id = ed2.getId(); - ing1_id = ing1.getId(); - } + ing1_id = ing1.getId(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1).equals(getAuditReader().getRevisions(SetRefEdEntity.class, ed1_id)); - assert Arrays.asList(1).equals(getAuditReader().getRevisions(SetRefEdEntity.class, ed2_id)); + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1 ).equals( getAuditReader().getRevisions( SetRefEdEntity.class, ed1_id ) ); + assert Arrays.asList( 1 ).equals( getAuditReader().getRevisions( SetRefEdEntity.class, ed2_id ) ); - assert Arrays.asList(2, 3).equals(getAuditReader().getRevisions(SetRefIngEntity.class, ing1_id)); - } + assert Arrays.asList( 2, 3 ).equals( getAuditReader().getRevisions( SetRefIngEntity.class, ing1_id ) ); + } - @Test - public void testHistoryOfEdIng1() { - SetRefEdEntity ed1 = getEntityManager().find(SetRefEdEntity.class, ed1_id); - SetRefEdEntity ed2 = getEntityManager().find(SetRefEdEntity.class, ed2_id); + @Test + public void testHistoryOfEdIng1() { + SetRefEdEntity ed1 = getEntityManager().find( SetRefEdEntity.class, ed1_id ); + SetRefEdEntity ed2 = getEntityManager().find( SetRefEdEntity.class, ed2_id ); - SetRefIngEntity rev1 = getAuditReader().find(SetRefIngEntity.class, ing1_id, 1); - SetRefIngEntity rev2 = getAuditReader().find(SetRefIngEntity.class, ing1_id, 2); - SetRefIngEntity rev3 = getAuditReader().find(SetRefIngEntity.class, ing1_id, 3); + SetRefIngEntity rev1 = getAuditReader().find( SetRefIngEntity.class, ing1_id, 1 ); + SetRefIngEntity rev2 = getAuditReader().find( SetRefIngEntity.class, ing1_id, 2 ); + SetRefIngEntity rev3 = getAuditReader().find( SetRefIngEntity.class, ing1_id, 3 ); - assert rev1 == null; - assert rev2.getReference().equals(ed1); - assert rev3.getReference().equals(ed2); - } + assert rev1 == null; + assert rev2.getReference().equals( ed1 ); + assert rev3.getReference().equals( ed2 ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/relation/SetRefEdEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/relation/SetRefEdEntity.java index fa984be5eb..bb17a45716 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/relation/SetRefEdEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/relation/SetRefEdEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.interfaces.relation; + import javax.persistence.Entity; import javax.persistence.Id; @@ -29,64 +30,73 @@ import org.hibernate.envers.Audited; /** * ReferencEd entity + * * @author Adam Warski (adam at warski dot org) */ @Entity @Audited public class SetRefEdEntity implements ISetRefEdEntity { - @Id - private Integer id; + @Id + private Integer id; - private String data; + private String data; - public SetRefEdEntity() { - } + public SetRefEdEntity() { + } - public SetRefEdEntity(Integer id, String data) { - this.id = id; - this.data = data; - } + public SetRefEdEntity(Integer id, String data) { + this.id = id; + this.data = data; + } - public SetRefEdEntity(String data) { - this.data = data; - } + public SetRefEdEntity(String data) { + this.data = data; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof SetRefEdEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof SetRefEdEntity) ) { + return false; + } - SetRefEdEntity that = (SetRefEdEntity) o; + SetRefEdEntity that = (SetRefEdEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "SetRefEdEntity(id = " + id + ", data = " + data + ")"; - } + public String toString() { + return "SetRefEdEntity(id = " + id + ", data = " + data + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/relation/SetRefIngEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/relation/SetRefIngEntity.java index 207305c41a..d45eb04901 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/relation/SetRefIngEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/interfaces/relation/SetRefIngEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.interfaces.relation; + import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.ManyToOne; @@ -30,82 +31,92 @@ import org.hibernate.envers.Audited; /** * ReferencIng entity + * * @author Adam Warski (adam at warski dot org) */ @Entity public class SetRefIngEntity { - @Id - private Integer id; + @Id + private Integer id; - @Audited - private String data; + @Audited + private String data; - @Audited - @ManyToOne(targetEntity = SetRefEdEntity.class) - private ISetRefEdEntity reference; + @Audited + @ManyToOne(targetEntity = SetRefEdEntity.class) + private ISetRefEdEntity reference; - public SetRefIngEntity() { } + public SetRefIngEntity() { + } - public SetRefIngEntity(Integer id, String data, ISetRefEdEntity reference) { - this.id = id; - this.data = data; - this.reference = reference; - } + public SetRefIngEntity(Integer id, String data, ISetRefEdEntity reference) { + this.id = id; + this.data = data; + this.reference = reference; + } - public SetRefIngEntity(String data, ISetRefEdEntity reference) { - this.data = data; - this.reference = reference; - } + public SetRefIngEntity(String data, ISetRefEdEntity reference) { + this.data = data; + this.reference = reference; + } - public SetRefIngEntity(Integer id, String data) { - this.id = id; - this.data = data; - } + public SetRefIngEntity(Integer id, String data) { + this.id = id; + this.data = data; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public ISetRefEdEntity getReference() { - return reference; - } + public ISetRefEdEntity getReference() { + return reference; + } - public void setReference(ISetRefEdEntity reference) { - this.reference = reference; - } + public void setReference(ISetRefEdEntity reference) { + this.reference = reference; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof SetRefIngEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof SetRefIngEntity) ) { + return false; + } - SetRefIngEntity that = (SetRefIngEntity) o; + SetRefIngEntity that = (SetRefIngEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "SetRefIngEntity(id = " + id + ", data = " + data + ")"; - } + public String toString() { + return "SetRefIngEntity(id = " + id + ", data = " + data + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/jta/JtaExceptionListener.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/jta/JtaExceptionListener.java index 643f41bf35..476ad0c1b3 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/jta/JtaExceptionListener.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/jta/JtaExceptionListener.java @@ -23,63 +23,67 @@ */ package org.hibernate.envers.test.integration.jta; -import java.util.Map; import javax.persistence.EntityManager; import javax.transaction.RollbackException; - -import org.junit.Assert; -import org.junit.Test; +import java.util.Map; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrTestEntity; import org.hibernate.envers.test.integration.reventity.ExceptionListenerRevEntity; + +import org.junit.Assert; +import org.junit.Test; + import org.hibernate.testing.jta.TestingJtaBootstrap; import org.hibernate.testing.jta.TestingJtaPlatformImpl; /** * Same as {@link org.hibernate.envers.test.integration.reventity.ExceptionListener}, but in a JTA environment. + * * @author Adam Warski (adam at warski dot org) */ public class JtaExceptionListener extends BaseEnversJPAFunctionalTestCase { @Override protected Class[] getAnnotatedClasses() { - return new Class[] { StrTestEntity.class, ExceptionListenerRevEntity.class }; - } + return new Class[] {StrTestEntity.class, ExceptionListenerRevEntity.class}; + } - @Override - protected void addConfigOptions(Map options) { - TestingJtaBootstrap.prepare(options); - } + @Override + protected void addConfigOptions(Map options) { + TestingJtaBootstrap.prepare( options ); + } - @Test(expected = RollbackException.class) - @Priority(5) // must run before testDataNotPersisted() - public void testTransactionRollback() throws Exception { + @Test(expected = RollbackException.class) + @Priority(5) // must run before testDataNotPersisted() + public void testTransactionRollback() throws Exception { TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin(); - try { + try { EntityManager em = getEntityManager(); - // Trying to persist an entity - however the listener should throw an exception, so the entity - // shouldn't be persisted - StrTestEntity te = new StrTestEntity("x"); - em.persist(te); - } finally { + // Trying to persist an entity - however the listener should throw an exception, so the entity + // shouldn't be persisted + StrTestEntity te = new StrTestEntity( "x" ); + em.persist( te ); + } + finally { TestingJtaPlatformImpl.tryCommit(); - } - } + } + } - @Test - public void testDataNotPersisted() throws Exception { + @Test + public void testDataNotPersisted() throws Exception { TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin(); - try { - // Checking if the entity became persisted - EntityManager em = getEntityManager(); - long count = em.createQuery("from StrTestEntity s where s.str = 'x'").getResultList().size(); - Assert.assertEquals( 0, count ); - } finally { + try { + // Checking if the entity became persisted + EntityManager em = getEntityManager(); + long count = em.createQuery( "from StrTestEntity s where s.str = 'x'" ).getResultList().size(); + Assert.assertEquals( 0, count ); + } + finally { TestingJtaPlatformImpl.tryCommit(); - } - } + } + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/jta/JtaTransaction.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/jta/JtaTransaction.java index 529749f7b7..1e2d62bf87 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/jta/JtaTransaction.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/jta/JtaTransaction.java @@ -1,68 +1,75 @@ package org.hibernate.envers.test.integration.jta; +import javax.persistence.EntityManager; import java.util.List; import java.util.Map; -import javax.persistence.EntityManager; - -import org.junit.Assert; -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.IntTestEntity; + +import org.junit.Assert; +import org.junit.Test; + import org.hibernate.testing.jta.TestingJtaBootstrap; import org.hibernate.testing.jta.TestingJtaPlatformImpl; /** * Same as {@link org.hibernate.envers.test.integration.basic.Simple}, but in a JTA environment. + * * @author Adam Warski (adam at warski dot org) */ -public class JtaTransaction extends BaseEnversJPAFunctionalTestCase { - private Integer id1; +public class JtaTransaction extends BaseEnversJPAFunctionalTestCase { + private Integer id1; - @Override - protected Class[] getAnnotatedClasses() { - return new Class[]{IntTestEntity.class}; - } + @Override + protected Class[] getAnnotatedClasses() { + return new Class[] {IntTestEntity.class}; + } - @Override - protected void addConfigOptions(Map options) { - TestingJtaBootstrap.prepare(options); - } + @Override + protected void addConfigOptions(Map options) { + TestingJtaBootstrap.prepare( options ); + } - @Test - @Priority(10) - public void initData() throws Exception { + @Test + @Priority(10) + public void initData() throws Exception { TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin(); - EntityManager em; - IntTestEntity ite; - try { - em = getEntityManager(); - ite = new IntTestEntity(10); - em.persist(ite); - id1 = ite.getId(); - } finally { + EntityManager em; + IntTestEntity ite; + try { + em = getEntityManager(); + ite = new IntTestEntity( 10 ); + em.persist( ite ); + id1 = ite.getId(); + } + finally { TestingJtaPlatformImpl.tryCommit(); - } - em.close(); + } + em.close(); TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin(); - try { - em = getEntityManager(); - ite = em.find(IntTestEntity.class, id1); - ite.setNumber(20); - } finally { + try { + em = getEntityManager(); + ite = em.find( IntTestEntity.class, id1 ); + ite.setNumber( 20 ); + } + finally { TestingJtaPlatformImpl.tryCommit(); - } - em.close(); - } + } + em.close(); + } @Test public void testRevisionsCounts() throws Exception { - Assert.assertEquals( 2, getAuditReader().getRevisions( - IntTestEntity.class, id1 ).size() ); + Assert.assertEquals( + 2, getAuditReader().getRevisions( + IntTestEntity.class, id1 + ).size() + ); } @Test @@ -70,12 +77,19 @@ public class JtaTransaction extends BaseEnversJPAFunctionalTestCase { IntTestEntity ver1 = new IntTestEntity( 10, id1 ); IntTestEntity ver2 = new IntTestEntity( 20, id1 ); - List revisions = getAuditReader().getRevisions( - IntTestEntity.class, id1 ); + List revisions = getAuditReader().getRevisions( + IntTestEntity.class, id1 + ); - Assert.assertEquals( ver1, getAuditReader().find( - IntTestEntity.class, id1, revisions.get( 0 ) ) ); - Assert.assertEquals( ver2, getAuditReader().find( - IntTestEntity.class, id1, revisions.get( 1 ) ) ); + Assert.assertEquals( + ver1, getAuditReader().find( + IntTestEntity.class, id1, revisions.get( 0 ) + ) + ); + Assert.assertEquals( + ver2, getAuditReader().find( + IntTestEntity.class, id1, revisions.get( 1 ) + ) + ); } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/BasicList.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/BasicList.java index 1a9fb5ee27..31818bebac 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/BasicList.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/BasicList.java @@ -23,12 +23,10 @@ */ package org.hibernate.envers.test.integration.manytomany; +import javax.persistence.EntityManager; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; @@ -36,178 +34,185 @@ import org.hibernate.envers.test.entities.manytomany.ListOwnedEntity; import org.hibernate.envers.test.entities.manytomany.ListOwningEntity; import org.hibernate.envers.test.tools.TestTools; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class BasicList extends BaseEnversJPAFunctionalTestCase { - private Integer ed1_id; - private Integer ed2_id; + private Integer ed1_id; + private Integer ed2_id; - private Integer ing1_id; - private Integer ing2_id; + private Integer ing1_id; + private Integer ing2_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { ListOwningEntity.class, ListOwnedEntity.class }; - } + return new Class[] {ListOwningEntity.class, ListOwnedEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - ListOwnedEntity ed1 = new ListOwnedEntity(1, "data_ed_1"); - ListOwnedEntity ed2 = new ListOwnedEntity(2, "data_ed_2"); + ListOwnedEntity ed1 = new ListOwnedEntity( 1, "data_ed_1" ); + ListOwnedEntity ed2 = new ListOwnedEntity( 2, "data_ed_2" ); - ListOwningEntity ing1 = new ListOwningEntity(3, "data_ing_1"); - ListOwningEntity ing2 = new ListOwningEntity(4, "data_ing_2"); + ListOwningEntity ing1 = new ListOwningEntity( 3, "data_ing_1" ); + ListOwningEntity ing2 = new ListOwningEntity( 4, "data_ing_2" ); - // Revision 1 - em.getTransaction().begin(); + // Revision 1 + em.getTransaction().begin(); - em.persist(ed1); - em.persist(ed2); - em.persist(ing1); - em.persist(ing2); + em.persist( ed1 ); + em.persist( ed2 ); + em.persist( ing1 ); + em.persist( ing2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 + // Revision 2 - em.getTransaction().begin(); + em.getTransaction().begin(); - ing1 = em.find(ListOwningEntity.class, ing1.getId()); - ing2 = em.find(ListOwningEntity.class, ing2.getId()); - ed1 = em.find(ListOwnedEntity.class, ed1.getId()); - ed2 = em.find(ListOwnedEntity.class, ed2.getId()); + ing1 = em.find( ListOwningEntity.class, ing1.getId() ); + ing2 = em.find( ListOwningEntity.class, ing2.getId() ); + ed1 = em.find( ListOwnedEntity.class, ed1.getId() ); + ed2 = em.find( ListOwnedEntity.class, ed2.getId() ); - ing1.setReferences(new ArrayList()); - ing1.getReferences().add(ed1); + ing1.setReferences( new ArrayList() ); + ing1.getReferences().add( ed1 ); - ing2.setReferences(new ArrayList()); - ing2.getReferences().add(ed1); - ing2.getReferences().add(ed2); + ing2.setReferences( new ArrayList() ); + ing2.getReferences().add( ed1 ); + ing2.getReferences().add( ed2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 - em.getTransaction().begin(); + // Revision 3 + em.getTransaction().begin(); - ing1 = em.find(ListOwningEntity.class, ing1.getId()); - ed2 = em.find(ListOwnedEntity.class, ed2.getId()); - ed1 = em.find(ListOwnedEntity.class, ed1.getId()); + ing1 = em.find( ListOwningEntity.class, ing1.getId() ); + ed2 = em.find( ListOwnedEntity.class, ed2.getId() ); + ed1 = em.find( ListOwnedEntity.class, ed1.getId() ); - ing1.getReferences().add(ed2); + ing1.getReferences().add( ed2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 4 - em.getTransaction().begin(); + // Revision 4 + em.getTransaction().begin(); - ing1 = em.find(ListOwningEntity.class, ing1.getId()); - ed2 = em.find(ListOwnedEntity.class, ed2.getId()); - ed1 = em.find(ListOwnedEntity.class, ed1.getId()); + ing1 = em.find( ListOwningEntity.class, ing1.getId() ); + ed2 = em.find( ListOwnedEntity.class, ed2.getId() ); + ed1 = em.find( ListOwnedEntity.class, ed1.getId() ); - ing1.getReferences().remove(ed1); + ing1.getReferences().remove( ed1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 5 - em.getTransaction().begin(); + // Revision 5 + em.getTransaction().begin(); - ing1 = em.find(ListOwningEntity.class, ing1.getId()); + ing1 = em.find( ListOwningEntity.class, ing1.getId() ); - ing1.setReferences(null); + ing1.setReferences( null ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // + // - ed1_id = ed1.getId(); - ed2_id = ed2.getId(); + ed1_id = ed1.getId(); + ed2_id = ed2.getId(); - ing1_id = ing1.getId(); - ing2_id = ing2.getId(); - } + ing1_id = ing1.getId(); + ing2_id = ing2.getId(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2, 4).equals(getAuditReader().getRevisions(ListOwnedEntity.class, ed1_id)); - assert Arrays.asList(1, 2, 3, 5).equals(getAuditReader().getRevisions(ListOwnedEntity.class, ed2_id)); + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2, 4 ).equals( getAuditReader().getRevisions( ListOwnedEntity.class, ed1_id ) ); + assert Arrays.asList( 1, 2, 3, 5 ).equals( getAuditReader().getRevisions( ListOwnedEntity.class, ed2_id ) ); - assert Arrays.asList(1, 2, 3, 4, 5).equals(getAuditReader().getRevisions(ListOwningEntity.class, ing1_id)); - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(ListOwningEntity.class, ing2_id)); - } + assert Arrays.asList( 1, 2, 3, 4, 5 ).equals( + getAuditReader().getRevisions( + ListOwningEntity.class, + ing1_id + ) + ); + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( ListOwningEntity.class, ing2_id ) ); + } - @Test - public void testHistoryOfEdId1() { - ListOwningEntity ing1 = getEntityManager().find(ListOwningEntity.class, ing1_id); - ListOwningEntity ing2 = getEntityManager().find(ListOwningEntity.class, ing2_id); + @Test + public void testHistoryOfEdId1() { + ListOwningEntity ing1 = getEntityManager().find( ListOwningEntity.class, ing1_id ); + ListOwningEntity ing2 = getEntityManager().find( ListOwningEntity.class, ing2_id ); - ListOwnedEntity rev1 = getAuditReader().find(ListOwnedEntity.class, ed1_id, 1); - ListOwnedEntity rev2 = getAuditReader().find(ListOwnedEntity.class, ed1_id, 2); - ListOwnedEntity rev3 = getAuditReader().find(ListOwnedEntity.class, ed1_id, 3); - ListOwnedEntity rev4 = getAuditReader().find(ListOwnedEntity.class, ed1_id, 4); - ListOwnedEntity rev5 = getAuditReader().find(ListOwnedEntity.class, ed1_id, 5); + ListOwnedEntity rev1 = getAuditReader().find( ListOwnedEntity.class, ed1_id, 1 ); + ListOwnedEntity rev2 = getAuditReader().find( ListOwnedEntity.class, ed1_id, 2 ); + ListOwnedEntity rev3 = getAuditReader().find( ListOwnedEntity.class, ed1_id, 3 ); + ListOwnedEntity rev4 = getAuditReader().find( ListOwnedEntity.class, ed1_id, 4 ); + ListOwnedEntity rev5 = getAuditReader().find( ListOwnedEntity.class, ed1_id, 5 ); - assert rev1.getReferencing().equals(Collections.EMPTY_LIST); - assert TestTools.checkList(rev2.getReferencing(), ing1, ing2); - assert TestTools.checkList(rev3.getReferencing(), ing1, ing2); - assert TestTools.checkList(rev4.getReferencing(), ing2); - assert TestTools.checkList(rev5.getReferencing(), ing2); - } + assert rev1.getReferencing().equals( Collections.EMPTY_LIST ); + assert TestTools.checkList( rev2.getReferencing(), ing1, ing2 ); + assert TestTools.checkList( rev3.getReferencing(), ing1, ing2 ); + assert TestTools.checkList( rev4.getReferencing(), ing2 ); + assert TestTools.checkList( rev5.getReferencing(), ing2 ); + } - @Test - public void testHistoryOfEdId2() { - ListOwningEntity ing1 = getEntityManager().find(ListOwningEntity.class, ing1_id); - ListOwningEntity ing2 = getEntityManager().find(ListOwningEntity.class, ing2_id); + @Test + public void testHistoryOfEdId2() { + ListOwningEntity ing1 = getEntityManager().find( ListOwningEntity.class, ing1_id ); + ListOwningEntity ing2 = getEntityManager().find( ListOwningEntity.class, ing2_id ); - ListOwnedEntity rev1 = getAuditReader().find(ListOwnedEntity.class, ed2_id, 1); - ListOwnedEntity rev2 = getAuditReader().find(ListOwnedEntity.class, ed2_id, 2); - ListOwnedEntity rev3 = getAuditReader().find(ListOwnedEntity.class, ed2_id, 3); - ListOwnedEntity rev4 = getAuditReader().find(ListOwnedEntity.class, ed2_id, 4); - ListOwnedEntity rev5 = getAuditReader().find(ListOwnedEntity.class, ed2_id, 5); + ListOwnedEntity rev1 = getAuditReader().find( ListOwnedEntity.class, ed2_id, 1 ); + ListOwnedEntity rev2 = getAuditReader().find( ListOwnedEntity.class, ed2_id, 2 ); + ListOwnedEntity rev3 = getAuditReader().find( ListOwnedEntity.class, ed2_id, 3 ); + ListOwnedEntity rev4 = getAuditReader().find( ListOwnedEntity.class, ed2_id, 4 ); + ListOwnedEntity rev5 = getAuditReader().find( ListOwnedEntity.class, ed2_id, 5 ); - assert rev1.getReferencing().equals(Collections.EMPTY_LIST); - assert TestTools.checkList(rev2.getReferencing(), ing2); - assert TestTools.checkList(rev3.getReferencing(), ing1, ing2); - assert TestTools.checkList(rev4.getReferencing(), ing1, ing2); - assert TestTools.checkList(rev5.getReferencing(), ing2); - } + assert rev1.getReferencing().equals( Collections.EMPTY_LIST ); + assert TestTools.checkList( rev2.getReferencing(), ing2 ); + assert TestTools.checkList( rev3.getReferencing(), ing1, ing2 ); + assert TestTools.checkList( rev4.getReferencing(), ing1, ing2 ); + assert TestTools.checkList( rev5.getReferencing(), ing2 ); + } - @Test - public void testHistoryOfEdIng1() { - ListOwnedEntity ed1 = getEntityManager().find(ListOwnedEntity.class, ed1_id); - ListOwnedEntity ed2 = getEntityManager().find(ListOwnedEntity.class, ed2_id); + @Test + public void testHistoryOfEdIng1() { + ListOwnedEntity ed1 = getEntityManager().find( ListOwnedEntity.class, ed1_id ); + ListOwnedEntity ed2 = getEntityManager().find( ListOwnedEntity.class, ed2_id ); - ListOwningEntity rev1 = getAuditReader().find(ListOwningEntity.class, ing1_id, 1); - ListOwningEntity rev2 = getAuditReader().find(ListOwningEntity.class, ing1_id, 2); - ListOwningEntity rev3 = getAuditReader().find(ListOwningEntity.class, ing1_id, 3); - ListOwningEntity rev4 = getAuditReader().find(ListOwningEntity.class, ing1_id, 4); - ListOwningEntity rev5 = getAuditReader().find(ListOwningEntity.class, ing1_id, 5); + ListOwningEntity rev1 = getAuditReader().find( ListOwningEntity.class, ing1_id, 1 ); + ListOwningEntity rev2 = getAuditReader().find( ListOwningEntity.class, ing1_id, 2 ); + ListOwningEntity rev3 = getAuditReader().find( ListOwningEntity.class, ing1_id, 3 ); + ListOwningEntity rev4 = getAuditReader().find( ListOwningEntity.class, ing1_id, 4 ); + ListOwningEntity rev5 = getAuditReader().find( ListOwningEntity.class, ing1_id, 5 ); - assert rev1.getReferences().equals(Collections.EMPTY_LIST); - assert TestTools.checkList(rev2.getReferences(), ed1); - assert TestTools.checkList(rev3.getReferences(), ed1, ed2); - assert TestTools.checkList(rev4.getReferences(), ed2); - assert rev5.getReferences().equals(Collections.EMPTY_LIST); - } + assert rev1.getReferences().equals( Collections.EMPTY_LIST ); + assert TestTools.checkList( rev2.getReferences(), ed1 ); + assert TestTools.checkList( rev3.getReferences(), ed1, ed2 ); + assert TestTools.checkList( rev4.getReferences(), ed2 ); + assert rev5.getReferences().equals( Collections.EMPTY_LIST ); + } - @Test - public void testHistoryOfEdIng2() { - ListOwnedEntity ed1 = getEntityManager().find(ListOwnedEntity.class, ed1_id); - ListOwnedEntity ed2 = getEntityManager().find(ListOwnedEntity.class, ed2_id); + @Test + public void testHistoryOfEdIng2() { + ListOwnedEntity ed1 = getEntityManager().find( ListOwnedEntity.class, ed1_id ); + ListOwnedEntity ed2 = getEntityManager().find( ListOwnedEntity.class, ed2_id ); - ListOwningEntity rev1 = getAuditReader().find(ListOwningEntity.class, ing2_id, 1); - ListOwningEntity rev2 = getAuditReader().find(ListOwningEntity.class, ing2_id, 2); - ListOwningEntity rev3 = getAuditReader().find(ListOwningEntity.class, ing2_id, 3); - ListOwningEntity rev4 = getAuditReader().find(ListOwningEntity.class, ing2_id, 4); - ListOwningEntity rev5 = getAuditReader().find(ListOwningEntity.class, ing2_id, 5); + ListOwningEntity rev1 = getAuditReader().find( ListOwningEntity.class, ing2_id, 1 ); + ListOwningEntity rev2 = getAuditReader().find( ListOwningEntity.class, ing2_id, 2 ); + ListOwningEntity rev3 = getAuditReader().find( ListOwningEntity.class, ing2_id, 3 ); + ListOwningEntity rev4 = getAuditReader().find( ListOwningEntity.class, ing2_id, 4 ); + ListOwningEntity rev5 = getAuditReader().find( ListOwningEntity.class, ing2_id, 5 ); - assert rev1.getReferences().equals(Collections.EMPTY_LIST); - assert TestTools.checkList(rev2.getReferences(), ed1, ed2); - assert TestTools.checkList(rev3.getReferences(), ed1, ed2); - assert TestTools.checkList(rev4.getReferences(), ed1, ed2); - assert TestTools.checkList(rev5.getReferences(), ed1, ed2); - } + assert rev1.getReferences().equals( Collections.EMPTY_LIST ); + assert TestTools.checkList( rev2.getReferences(), ed1, ed2 ); + assert TestTools.checkList( rev3.getReferences(), ed1, ed2 ); + assert TestTools.checkList( rev4.getReferences(), ed1, ed2 ); + assert TestTools.checkList( rev5.getReferences(), ed1, ed2 ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/BasicMap.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/BasicMap.java index 5114856e4b..2c6340c376 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/BasicMap.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/BasicMap.java @@ -23,12 +23,10 @@ */ package org.hibernate.envers.test.integration.manytomany; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; @@ -36,152 +34,154 @@ import org.hibernate.envers.test.entities.manytomany.MapOwnedEntity; import org.hibernate.envers.test.entities.manytomany.MapOwningEntity; import org.hibernate.envers.test.tools.TestTools; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class BasicMap extends BaseEnversJPAFunctionalTestCase { - private Integer ed1_id; - private Integer ed2_id; + private Integer ed1_id; + private Integer ed2_id; - private Integer ing1_id; - private Integer ing2_id; + private Integer ing1_id; + private Integer ing2_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { MapOwningEntity.class, MapOwnedEntity.class }; + return new Class[] {MapOwningEntity.class, MapOwnedEntity.class}; } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - MapOwnedEntity ed1 = new MapOwnedEntity(1, "data_ed_1"); - MapOwnedEntity ed2 = new MapOwnedEntity(2, "data_ed_2"); + MapOwnedEntity ed1 = new MapOwnedEntity( 1, "data_ed_1" ); + MapOwnedEntity ed2 = new MapOwnedEntity( 2, "data_ed_2" ); - MapOwningEntity ing1 = new MapOwningEntity(3, "data_ing_1"); - MapOwningEntity ing2 = new MapOwningEntity(4, "data_ing_2"); + MapOwningEntity ing1 = new MapOwningEntity( 3, "data_ing_1" ); + MapOwningEntity ing2 = new MapOwningEntity( 4, "data_ing_2" ); - // Revision 1 (ing1: initialy empty, ing2: one mapping) - em.getTransaction().begin(); + // Revision 1 (ing1: initialy empty, ing2: one mapping) + em.getTransaction().begin(); - ing2.getReferences().put("2", ed2); + ing2.getReferences().put( "2", ed2 ); - em.persist(ed1); - em.persist(ed2); - em.persist(ing1); - em.persist(ing2); + em.persist( ed1 ); + em.persist( ed2 ); + em.persist( ing1 ); + em.persist( ing2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 (ing1: adding two mappings, ing2: replacing an existing mapping) + // Revision 2 (ing1: adding two mappings, ing2: replacing an existing mapping) - em.getTransaction().begin(); + em.getTransaction().begin(); - ing1 = em.find(MapOwningEntity.class, ing1.getId()); - ing2 = em.find(MapOwningEntity.class, ing2.getId()); - ed1 = em.find(MapOwnedEntity.class, ed1.getId()); - ed2 = em.find(MapOwnedEntity.class, ed2.getId()); + ing1 = em.find( MapOwningEntity.class, ing1.getId() ); + ing2 = em.find( MapOwningEntity.class, ing2.getId() ); + ed1 = em.find( MapOwnedEntity.class, ed1.getId() ); + ed2 = em.find( MapOwnedEntity.class, ed2.getId() ); - ing1.getReferences().put("1", ed1); - ing1.getReferences().put("2", ed1); + ing1.getReferences().put( "1", ed1 ); + ing1.getReferences().put( "2", ed1 ); - ing2.getReferences().put("2", ed1); + ing2.getReferences().put( "2", ed1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // No revision (ing1: adding an existing mapping, ing2: removing a non existing mapping) - em.getTransaction().begin(); + // No revision (ing1: adding an existing mapping, ing2: removing a non existing mapping) + em.getTransaction().begin(); - ing1 = em.find(MapOwningEntity.class, ing1.getId()); - ing2 = em.find(MapOwningEntity.class, ing2.getId()); + ing1 = em.find( MapOwningEntity.class, ing1.getId() ); + ing2 = em.find( MapOwningEntity.class, ing2.getId() ); - ing1.getReferences().put("1", ed1); + ing1.getReferences().put( "1", ed1 ); - ing2.getReferences().remove("3"); + ing2.getReferences().remove( "3" ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 (ing1: clearing, ing2: replacing with a new map) - em.getTransaction().begin(); + // Revision 3 (ing1: clearing, ing2: replacing with a new map) + em.getTransaction().begin(); - ing1 = em.find(MapOwningEntity.class, ing1.getId()); - ed1 = em.find(MapOwnedEntity.class, ed1.getId()); + ing1 = em.find( MapOwningEntity.class, ing1.getId() ); + ed1 = em.find( MapOwnedEntity.class, ed1.getId() ); - ing1.getReferences().clear(); - ing2.setReferences(new HashMap()); - ing2.getReferences().put("1", ed2); + ing1.getReferences().clear(); + ing2.setReferences( new HashMap() ); + ing2.getReferences().put( "1", ed2 ); - em.getTransaction().commit(); - // + em.getTransaction().commit(); + // - ed1_id = ed1.getId(); - ed2_id = ed2.getId(); + ed1_id = ed1.getId(); + ed2_id = ed2.getId(); - ing1_id = ing1.getId(); - ing2_id = ing2.getId(); - } + ing1_id = ing1.getId(); + ing2_id = ing2.getId(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2, 3).equals(getAuditReader().getRevisions(MapOwnedEntity.class, ed1_id)); - assert Arrays.asList(1, 2, 3).equals(getAuditReader().getRevisions(MapOwnedEntity.class, ed2_id)); + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2, 3 ).equals( getAuditReader().getRevisions( MapOwnedEntity.class, ed1_id ) ); + assert Arrays.asList( 1, 2, 3 ).equals( getAuditReader().getRevisions( MapOwnedEntity.class, ed2_id ) ); - assert Arrays.asList(1, 2, 3).equals(getAuditReader().getRevisions(MapOwningEntity.class, ing1_id)); - assert Arrays.asList(1, 2, 3).equals(getAuditReader().getRevisions(MapOwningEntity.class, ing2_id)); - } + assert Arrays.asList( 1, 2, 3 ).equals( getAuditReader().getRevisions( MapOwningEntity.class, ing1_id ) ); + assert Arrays.asList( 1, 2, 3 ).equals( getAuditReader().getRevisions( MapOwningEntity.class, ing2_id ) ); + } - @Test - public void testHistoryOfEdId1() { - MapOwningEntity ing1 = getEntityManager().find(MapOwningEntity.class, ing1_id); - MapOwningEntity ing2 = getEntityManager().find(MapOwningEntity.class, ing2_id); + @Test + public void testHistoryOfEdId1() { + MapOwningEntity ing1 = getEntityManager().find( MapOwningEntity.class, ing1_id ); + MapOwningEntity ing2 = getEntityManager().find( MapOwningEntity.class, ing2_id ); - MapOwnedEntity rev1 = getAuditReader().find(MapOwnedEntity.class, ed1_id, 1); - MapOwnedEntity rev2 = getAuditReader().find(MapOwnedEntity.class, ed1_id, 2); - MapOwnedEntity rev3 = getAuditReader().find(MapOwnedEntity.class, ed1_id, 3); + MapOwnedEntity rev1 = getAuditReader().find( MapOwnedEntity.class, ed1_id, 1 ); + MapOwnedEntity rev2 = getAuditReader().find( MapOwnedEntity.class, ed1_id, 2 ); + MapOwnedEntity rev3 = getAuditReader().find( MapOwnedEntity.class, ed1_id, 3 ); - assert rev1.getReferencing().equals(Collections.EMPTY_SET); - assert rev2.getReferencing().equals(TestTools.makeSet(ing1, ing2)); - assert rev3.getReferencing().equals(Collections.EMPTY_SET); - } + assert rev1.getReferencing().equals( Collections.EMPTY_SET ); + assert rev2.getReferencing().equals( TestTools.makeSet( ing1, ing2 ) ); + assert rev3.getReferencing().equals( Collections.EMPTY_SET ); + } - @Test - public void testHistoryOfEdId2() { - MapOwningEntity ing2 = getEntityManager().find(MapOwningEntity.class, ing2_id); + @Test + public void testHistoryOfEdId2() { + MapOwningEntity ing2 = getEntityManager().find( MapOwningEntity.class, ing2_id ); - MapOwnedEntity rev1 = getAuditReader().find(MapOwnedEntity.class, ed2_id, 1); - MapOwnedEntity rev2 = getAuditReader().find(MapOwnedEntity.class, ed2_id, 2); - MapOwnedEntity rev3 = getAuditReader().find(MapOwnedEntity.class, ed2_id, 3); + MapOwnedEntity rev1 = getAuditReader().find( MapOwnedEntity.class, ed2_id, 1 ); + MapOwnedEntity rev2 = getAuditReader().find( MapOwnedEntity.class, ed2_id, 2 ); + MapOwnedEntity rev3 = getAuditReader().find( MapOwnedEntity.class, ed2_id, 3 ); - assert rev1.getReferencing().equals(TestTools.makeSet(ing2)); - assert rev2.getReferencing().equals(Collections.EMPTY_SET); - assert rev3.getReferencing().equals(TestTools.makeSet(ing2)); - } + assert rev1.getReferencing().equals( TestTools.makeSet( ing2 ) ); + assert rev2.getReferencing().equals( Collections.EMPTY_SET ); + assert rev3.getReferencing().equals( TestTools.makeSet( ing2 ) ); + } - @Test - public void testHistoryOfEdIng1() { - MapOwnedEntity ed1 = getEntityManager().find(MapOwnedEntity.class, ed1_id); + @Test + public void testHistoryOfEdIng1() { + MapOwnedEntity ed1 = getEntityManager().find( MapOwnedEntity.class, ed1_id ); - MapOwningEntity rev1 = getAuditReader().find(MapOwningEntity.class, ing1_id, 1); - MapOwningEntity rev2 = getAuditReader().find(MapOwningEntity.class, ing1_id, 2); - MapOwningEntity rev3 = getAuditReader().find(MapOwningEntity.class, ing1_id, 3); + MapOwningEntity rev1 = getAuditReader().find( MapOwningEntity.class, ing1_id, 1 ); + MapOwningEntity rev2 = getAuditReader().find( MapOwningEntity.class, ing1_id, 2 ); + MapOwningEntity rev3 = getAuditReader().find( MapOwningEntity.class, ing1_id, 3 ); - assert rev1.getReferences().equals(Collections.EMPTY_MAP); - assert rev2.getReferences().equals(TestTools.makeMap("1", ed1, "2", ed1)); - assert rev3.getReferences().equals(Collections.EMPTY_MAP); - } + assert rev1.getReferences().equals( Collections.EMPTY_MAP ); + assert rev2.getReferences().equals( TestTools.makeMap( "1", ed1, "2", ed1 ) ); + assert rev3.getReferences().equals( Collections.EMPTY_MAP ); + } - @Test - public void testHistoryOfEdIng2() { - MapOwnedEntity ed1 = getEntityManager().find(MapOwnedEntity.class, ed1_id); - MapOwnedEntity ed2 = getEntityManager().find(MapOwnedEntity.class, ed2_id); + @Test + public void testHistoryOfEdIng2() { + MapOwnedEntity ed1 = getEntityManager().find( MapOwnedEntity.class, ed1_id ); + MapOwnedEntity ed2 = getEntityManager().find( MapOwnedEntity.class, ed2_id ); - MapOwningEntity rev1 = getAuditReader().find(MapOwningEntity.class, ing2_id, 1); - MapOwningEntity rev2 = getAuditReader().find(MapOwningEntity.class, ing2_id, 2); - MapOwningEntity rev3 = getAuditReader().find(MapOwningEntity.class, ing2_id, 3); + MapOwningEntity rev1 = getAuditReader().find( MapOwningEntity.class, ing2_id, 1 ); + MapOwningEntity rev2 = getAuditReader().find( MapOwningEntity.class, ing2_id, 2 ); + MapOwningEntity rev3 = getAuditReader().find( MapOwningEntity.class, ing2_id, 3 ); - assert rev1.getReferences().equals(TestTools.makeMap("2", ed2)); - assert rev2.getReferences().equals(TestTools.makeMap("2", ed1)); - assert rev3.getReferences().equals(TestTools.makeMap("1", ed2)); - } + assert rev1.getReferences().equals( TestTools.makeMap( "2", ed2 ) ); + assert rev2.getReferences().equals( TestTools.makeMap( "2", ed1 ) ); + assert rev3.getReferences().equals( TestTools.makeMap( "1", ed2 ) ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/BasicSet.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/BasicSet.java index 0355e817e4..eb5c5419d7 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/BasicSet.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/BasicSet.java @@ -23,12 +23,10 @@ */ package org.hibernate.envers.test.integration.manytomany; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; @@ -36,178 +34,180 @@ import org.hibernate.envers.test.entities.manytomany.SetOwnedEntity; import org.hibernate.envers.test.entities.manytomany.SetOwningEntity; import org.hibernate.envers.test.tools.TestTools; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ -public class BasicSet extends BaseEnversJPAFunctionalTestCase { - private Integer ed1_id; - private Integer ed2_id; +public class BasicSet extends BaseEnversJPAFunctionalTestCase { + private Integer ed1_id; + private Integer ed2_id; - private Integer ing1_id; - private Integer ing2_id; + private Integer ing1_id; + private Integer ing2_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { SetOwningEntity.class, SetOwnedEntity.class }; - } + return new Class[] {SetOwningEntity.class, SetOwnedEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - SetOwnedEntity ed1 = new SetOwnedEntity(1, "data_ed_1"); - SetOwnedEntity ed2 = new SetOwnedEntity(2, "data_ed_2"); + SetOwnedEntity ed1 = new SetOwnedEntity( 1, "data_ed_1" ); + SetOwnedEntity ed2 = new SetOwnedEntity( 2, "data_ed_2" ); - SetOwningEntity ing1 = new SetOwningEntity(3, "data_ing_1"); - SetOwningEntity ing2 = new SetOwningEntity(4, "data_ing_2"); + SetOwningEntity ing1 = new SetOwningEntity( 3, "data_ing_1" ); + SetOwningEntity ing2 = new SetOwningEntity( 4, "data_ing_2" ); - // Revision 1 - em.getTransaction().begin(); + // Revision 1 + em.getTransaction().begin(); - em.persist(ed1); - em.persist(ed2); - em.persist(ing1); - em.persist(ing2); + em.persist( ed1 ); + em.persist( ed2 ); + em.persist( ing1 ); + em.persist( ing2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 + // Revision 2 - em.getTransaction().begin(); + em.getTransaction().begin(); - ing1 = em.find(SetOwningEntity.class, ing1.getId()); - ing2 = em.find(SetOwningEntity.class, ing2.getId()); - ed1 = em.find(SetOwnedEntity.class, ed1.getId()); - ed2 = em.find(SetOwnedEntity.class, ed2.getId()); + ing1 = em.find( SetOwningEntity.class, ing1.getId() ); + ing2 = em.find( SetOwningEntity.class, ing2.getId() ); + ed1 = em.find( SetOwnedEntity.class, ed1.getId() ); + ed2 = em.find( SetOwnedEntity.class, ed2.getId() ); - ing1.setReferences(new HashSet()); - ing1.getReferences().add(ed1); + ing1.setReferences( new HashSet() ); + ing1.getReferences().add( ed1 ); - ing2.setReferences(new HashSet()); - ing2.getReferences().add(ed1); - ing2.getReferences().add(ed2); + ing2.setReferences( new HashSet() ); + ing2.getReferences().add( ed1 ); + ing2.getReferences().add( ed2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 - em.getTransaction().begin(); + // Revision 3 + em.getTransaction().begin(); - ing1 = em.find(SetOwningEntity.class, ing1.getId()); - ed2 = em.find(SetOwnedEntity.class, ed2.getId()); - ed1 = em.find(SetOwnedEntity.class, ed1.getId()); + ing1 = em.find( SetOwningEntity.class, ing1.getId() ); + ed2 = em.find( SetOwnedEntity.class, ed2.getId() ); + ed1 = em.find( SetOwnedEntity.class, ed1.getId() ); - ing1.getReferences().add(ed2); + ing1.getReferences().add( ed2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 4 - em.getTransaction().begin(); + // Revision 4 + em.getTransaction().begin(); - ing1 = em.find(SetOwningEntity.class, ing1.getId()); - ed2 = em.find(SetOwnedEntity.class, ed2.getId()); - ed1 = em.find(SetOwnedEntity.class, ed1.getId()); + ing1 = em.find( SetOwningEntity.class, ing1.getId() ); + ed2 = em.find( SetOwnedEntity.class, ed2.getId() ); + ed1 = em.find( SetOwnedEntity.class, ed1.getId() ); - ing1.getReferences().remove(ed1); + ing1.getReferences().remove( ed1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 5 - em.getTransaction().begin(); + // Revision 5 + em.getTransaction().begin(); - ing1 = em.find(SetOwningEntity.class, ing1.getId()); + ing1 = em.find( SetOwningEntity.class, ing1.getId() ); - ing1.setReferences(null); + ing1.setReferences( null ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // + // - ed1_id = ed1.getId(); - ed2_id = ed2.getId(); + ed1_id = ed1.getId(); + ed2_id = ed2.getId(); - ing1_id = ing1.getId(); - ing2_id = ing2.getId(); - } + ing1_id = ing1.getId(); + ing2_id = ing2.getId(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2, 4).equals(getAuditReader().getRevisions(SetOwnedEntity.class, ed1_id)); - assert Arrays.asList(1, 2, 3, 5).equals(getAuditReader().getRevisions(SetOwnedEntity.class, ed2_id)); + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2, 4 ).equals( getAuditReader().getRevisions( SetOwnedEntity.class, ed1_id ) ); + assert Arrays.asList( 1, 2, 3, 5 ).equals( getAuditReader().getRevisions( SetOwnedEntity.class, ed2_id ) ); - assert Arrays.asList(1, 2, 3, 4, 5).equals(getAuditReader().getRevisions(SetOwningEntity.class, ing1_id)); - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(SetOwningEntity.class, ing2_id)); - } + assert Arrays.asList( 1, 2, 3, 4, 5 ).equals( getAuditReader().getRevisions( SetOwningEntity.class, ing1_id ) ); + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( SetOwningEntity.class, ing2_id ) ); + } - @Test - public void testHistoryOfEdId1() { - SetOwningEntity ing1 = getEntityManager().find(SetOwningEntity.class, ing1_id); - SetOwningEntity ing2 = getEntityManager().find(SetOwningEntity.class, ing2_id); + @Test + public void testHistoryOfEdId1() { + SetOwningEntity ing1 = getEntityManager().find( SetOwningEntity.class, ing1_id ); + SetOwningEntity ing2 = getEntityManager().find( SetOwningEntity.class, ing2_id ); - SetOwnedEntity rev1 = getAuditReader().find(SetOwnedEntity.class, ed1_id, 1); - SetOwnedEntity rev2 = getAuditReader().find(SetOwnedEntity.class, ed1_id, 2); - SetOwnedEntity rev3 = getAuditReader().find(SetOwnedEntity.class, ed1_id, 3); - SetOwnedEntity rev4 = getAuditReader().find(SetOwnedEntity.class, ed1_id, 4); - SetOwnedEntity rev5 = getAuditReader().find(SetOwnedEntity.class, ed1_id, 5); + SetOwnedEntity rev1 = getAuditReader().find( SetOwnedEntity.class, ed1_id, 1 ); + SetOwnedEntity rev2 = getAuditReader().find( SetOwnedEntity.class, ed1_id, 2 ); + SetOwnedEntity rev3 = getAuditReader().find( SetOwnedEntity.class, ed1_id, 3 ); + SetOwnedEntity rev4 = getAuditReader().find( SetOwnedEntity.class, ed1_id, 4 ); + SetOwnedEntity rev5 = getAuditReader().find( SetOwnedEntity.class, ed1_id, 5 ); - assert rev1.getReferencing().equals(Collections.EMPTY_SET); - assert rev2.getReferencing().equals(TestTools.makeSet(ing1, ing2)); - assert rev3.getReferencing().equals(TestTools.makeSet(ing1, ing2)); - assert rev4.getReferencing().equals(TestTools.makeSet(ing2)); - assert rev5.getReferencing().equals(TestTools.makeSet(ing2)); - } + assert rev1.getReferencing().equals( Collections.EMPTY_SET ); + assert rev2.getReferencing().equals( TestTools.makeSet( ing1, ing2 ) ); + assert rev3.getReferencing().equals( TestTools.makeSet( ing1, ing2 ) ); + assert rev4.getReferencing().equals( TestTools.makeSet( ing2 ) ); + assert rev5.getReferencing().equals( TestTools.makeSet( ing2 ) ); + } - @Test - public void testHistoryOfEdId2() { - SetOwningEntity ing1 = getEntityManager().find(SetOwningEntity.class, ing1_id); - SetOwningEntity ing2 = getEntityManager().find(SetOwningEntity.class, ing2_id); + @Test + public void testHistoryOfEdId2() { + SetOwningEntity ing1 = getEntityManager().find( SetOwningEntity.class, ing1_id ); + SetOwningEntity ing2 = getEntityManager().find( SetOwningEntity.class, ing2_id ); - SetOwnedEntity rev1 = getAuditReader().find(SetOwnedEntity.class, ed2_id, 1); - SetOwnedEntity rev2 = getAuditReader().find(SetOwnedEntity.class, ed2_id, 2); - SetOwnedEntity rev3 = getAuditReader().find(SetOwnedEntity.class, ed2_id, 3); - SetOwnedEntity rev4 = getAuditReader().find(SetOwnedEntity.class, ed2_id, 4); - SetOwnedEntity rev5 = getAuditReader().find(SetOwnedEntity.class, ed2_id, 5); + SetOwnedEntity rev1 = getAuditReader().find( SetOwnedEntity.class, ed2_id, 1 ); + SetOwnedEntity rev2 = getAuditReader().find( SetOwnedEntity.class, ed2_id, 2 ); + SetOwnedEntity rev3 = getAuditReader().find( SetOwnedEntity.class, ed2_id, 3 ); + SetOwnedEntity rev4 = getAuditReader().find( SetOwnedEntity.class, ed2_id, 4 ); + SetOwnedEntity rev5 = getAuditReader().find( SetOwnedEntity.class, ed2_id, 5 ); - assert rev1.getReferencing().equals(Collections.EMPTY_SET); - assert rev2.getReferencing().equals(TestTools.makeSet(ing2)); - assert rev3.getReferencing().equals(TestTools.makeSet(ing1, ing2)); - assert rev4.getReferencing().equals(TestTools.makeSet(ing1, ing2)); - assert rev5.getReferencing().equals(TestTools.makeSet(ing2)); - } + assert rev1.getReferencing().equals( Collections.EMPTY_SET ); + assert rev2.getReferencing().equals( TestTools.makeSet( ing2 ) ); + assert rev3.getReferencing().equals( TestTools.makeSet( ing1, ing2 ) ); + assert rev4.getReferencing().equals( TestTools.makeSet( ing1, ing2 ) ); + assert rev5.getReferencing().equals( TestTools.makeSet( ing2 ) ); + } - @Test - public void testHistoryOfEdIng1() { - SetOwnedEntity ed1 = getEntityManager().find(SetOwnedEntity.class, ed1_id); - SetOwnedEntity ed2 = getEntityManager().find(SetOwnedEntity.class, ed2_id); + @Test + public void testHistoryOfEdIng1() { + SetOwnedEntity ed1 = getEntityManager().find( SetOwnedEntity.class, ed1_id ); + SetOwnedEntity ed2 = getEntityManager().find( SetOwnedEntity.class, ed2_id ); - SetOwningEntity rev1 = getAuditReader().find(SetOwningEntity.class, ing1_id, 1); - SetOwningEntity rev2 = getAuditReader().find(SetOwningEntity.class, ing1_id, 2); - SetOwningEntity rev3 = getAuditReader().find(SetOwningEntity.class, ing1_id, 3); - SetOwningEntity rev4 = getAuditReader().find(SetOwningEntity.class, ing1_id, 4); - SetOwningEntity rev5 = getAuditReader().find(SetOwningEntity.class, ing1_id, 5); + SetOwningEntity rev1 = getAuditReader().find( SetOwningEntity.class, ing1_id, 1 ); + SetOwningEntity rev2 = getAuditReader().find( SetOwningEntity.class, ing1_id, 2 ); + SetOwningEntity rev3 = getAuditReader().find( SetOwningEntity.class, ing1_id, 3 ); + SetOwningEntity rev4 = getAuditReader().find( SetOwningEntity.class, ing1_id, 4 ); + SetOwningEntity rev5 = getAuditReader().find( SetOwningEntity.class, ing1_id, 5 ); - assert rev1.getReferences().equals(Collections.EMPTY_SET); - assert rev2.getReferences().equals(TestTools.makeSet(ed1)); - assert rev3.getReferences().equals(TestTools.makeSet(ed1, ed2)); - assert rev4.getReferences().equals(TestTools.makeSet(ed2)); - assert rev5.getReferences().equals(Collections.EMPTY_SET); - } + assert rev1.getReferences().equals( Collections.EMPTY_SET ); + assert rev2.getReferences().equals( TestTools.makeSet( ed1 ) ); + assert rev3.getReferences().equals( TestTools.makeSet( ed1, ed2 ) ); + assert rev4.getReferences().equals( TestTools.makeSet( ed2 ) ); + assert rev5.getReferences().equals( Collections.EMPTY_SET ); + } - @Test - public void testHistoryOfEdIng2() { - SetOwnedEntity ed1 = getEntityManager().find(SetOwnedEntity.class, ed1_id); - SetOwnedEntity ed2 = getEntityManager().find(SetOwnedEntity.class, ed2_id); + @Test + public void testHistoryOfEdIng2() { + SetOwnedEntity ed1 = getEntityManager().find( SetOwnedEntity.class, ed1_id ); + SetOwnedEntity ed2 = getEntityManager().find( SetOwnedEntity.class, ed2_id ); - SetOwningEntity rev1 = getAuditReader().find(SetOwningEntity.class, ing2_id, 1); - SetOwningEntity rev2 = getAuditReader().find(SetOwningEntity.class, ing2_id, 2); - SetOwningEntity rev3 = getAuditReader().find(SetOwningEntity.class, ing2_id, 3); - SetOwningEntity rev4 = getAuditReader().find(SetOwningEntity.class, ing2_id, 4); - SetOwningEntity rev5 = getAuditReader().find(SetOwningEntity.class, ing2_id, 5); + SetOwningEntity rev1 = getAuditReader().find( SetOwningEntity.class, ing2_id, 1 ); + SetOwningEntity rev2 = getAuditReader().find( SetOwningEntity.class, ing2_id, 2 ); + SetOwningEntity rev3 = getAuditReader().find( SetOwningEntity.class, ing2_id, 3 ); + SetOwningEntity rev4 = getAuditReader().find( SetOwningEntity.class, ing2_id, 4 ); + SetOwningEntity rev5 = getAuditReader().find( SetOwningEntity.class, ing2_id, 5 ); - assert rev1.getReferences().equals(Collections.EMPTY_SET); - assert rev2.getReferences().equals(TestTools.makeSet(ed1, ed2)); - assert rev3.getReferences().equals(TestTools.makeSet(ed1, ed2)); - assert rev4.getReferences().equals(TestTools.makeSet(ed1, ed2)); - assert rev5.getReferences().equals(TestTools.makeSet(ed1, ed2)); - } + assert rev1.getReferences().equals( Collections.EMPTY_SET ); + assert rev2.getReferences().equals( TestTools.makeSet( ed1, ed2 ) ); + assert rev3.getReferences().equals( TestTools.makeSet( ed1, ed2 ) ); + assert rev4.getReferences().equals( TestTools.makeSet( ed1, ed2 ) ); + assert rev5.getReferences().equals( TestTools.makeSet( ed1, ed2 ) ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/BasicWhereJoinTable.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/BasicWhereJoinTable.java index 2935dffeb9..ca67bbb217 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/BasicWhereJoinTable.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/BasicWhereJoinTable.java @@ -23,10 +23,8 @@ */ package org.hibernate.envers.test.integration.manytomany; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; @@ -34,155 +32,157 @@ import org.hibernate.envers.test.entities.IntNoAutoIdTestEntity; import org.hibernate.envers.test.entities.manytomany.WhereJoinTableEntity; import org.hibernate.envers.test.tools.TestTools; +import org.junit.Test; + import static org.junit.Assert.assertEquals; /** * @author Adam Warski (adam at warski dot org) */ public class BasicWhereJoinTable extends BaseEnversJPAFunctionalTestCase { - private Integer ite1_1_id; - private Integer ite1_2_id; - private Integer ite2_1_id; - private Integer ite2_2_id; + private Integer ite1_1_id; + private Integer ite1_2_id; + private Integer ite2_1_id; + private Integer ite2_2_id; - private Integer wjte1_id; - private Integer wjte2_id; + private Integer wjte1_id; + private Integer wjte2_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { WhereJoinTableEntity.class, IntNoAutoIdTestEntity.class }; - } + return new Class[] {WhereJoinTableEntity.class, IntNoAutoIdTestEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - IntNoAutoIdTestEntity ite1_1 = new IntNoAutoIdTestEntity(1, 10); - IntNoAutoIdTestEntity ite1_2 = new IntNoAutoIdTestEntity(1, 11); - IntNoAutoIdTestEntity ite2_1 = new IntNoAutoIdTestEntity(2, 20); - IntNoAutoIdTestEntity ite2_2 = new IntNoAutoIdTestEntity(2, 21); + IntNoAutoIdTestEntity ite1_1 = new IntNoAutoIdTestEntity( 1, 10 ); + IntNoAutoIdTestEntity ite1_2 = new IntNoAutoIdTestEntity( 1, 11 ); + IntNoAutoIdTestEntity ite2_1 = new IntNoAutoIdTestEntity( 2, 20 ); + IntNoAutoIdTestEntity ite2_2 = new IntNoAutoIdTestEntity( 2, 21 ); - WhereJoinTableEntity wjte1 = new WhereJoinTableEntity(); - wjte1.setData("wjte1"); + WhereJoinTableEntity wjte1 = new WhereJoinTableEntity(); + wjte1.setData( "wjte1" ); - WhereJoinTableEntity wjte2 = new WhereJoinTableEntity(); - wjte1.setData("wjte2"); + WhereJoinTableEntity wjte2 = new WhereJoinTableEntity(); + wjte1.setData( "wjte2" ); - // Revision 1 - em.getTransaction().begin(); + // Revision 1 + em.getTransaction().begin(); - em.persist(ite1_1); - em.persist(ite1_2); - em.persist(ite2_1); - em.persist(ite2_2); - em.persist(wjte1); - em.persist(wjte2); + em.persist( ite1_1 ); + em.persist( ite1_2 ); + em.persist( ite2_1 ); + em.persist( ite2_2 ); + em.persist( wjte1 ); + em.persist( wjte2 ); - em.getTransaction().commit(); - em.clear(); + em.getTransaction().commit(); + em.clear(); - // Revision 2 (wjte1: 1_1, 2_1) + // Revision 2 (wjte1: 1_1, 2_1) - em.getTransaction().begin(); + em.getTransaction().begin(); - wjte1 = em.find(WhereJoinTableEntity.class, wjte1.getId()); + wjte1 = em.find( WhereJoinTableEntity.class, wjte1.getId() ); - wjte1.getReferences1().add(ite1_1); - wjte1.getReferences2().add(ite2_1); + wjte1.getReferences1().add( ite1_1 ); + wjte1.getReferences2().add( ite2_1 ); - em.getTransaction().commit(); - em.clear(); + em.getTransaction().commit(); + em.clear(); - // Revision 3 (wjte1: 1_1, 2_1; wjte2: 1_1, 1_2) - em.getTransaction().begin(); + // Revision 3 (wjte1: 1_1, 2_1; wjte2: 1_1, 1_2) + em.getTransaction().begin(); - wjte2 = em.find(WhereJoinTableEntity.class, wjte2.getId()); + wjte2 = em.find( WhereJoinTableEntity.class, wjte2.getId() ); - wjte2.getReferences1().add(ite1_1); - wjte2.getReferences1().add(ite1_2); + wjte2.getReferences1().add( ite1_1 ); + wjte2.getReferences1().add( ite1_2 ); - em.getTransaction().commit(); - em.clear(); + em.getTransaction().commit(); + em.clear(); - // Revision 4 (wjte1: 2_1; wjte2: 1_1, 1_2, 2_2) - em.getTransaction().begin(); + // Revision 4 (wjte1: 2_1; wjte2: 1_1, 1_2, 2_2) + em.getTransaction().begin(); - wjte1 = em.find(WhereJoinTableEntity.class, wjte1.getId()); - wjte2 = em.find(WhereJoinTableEntity.class, wjte2.getId()); + wjte1 = em.find( WhereJoinTableEntity.class, wjte1.getId() ); + wjte2 = em.find( WhereJoinTableEntity.class, wjte2.getId() ); - wjte1.getReferences1().remove(ite1_1); - wjte2.getReferences2().add(ite2_2); + wjte1.getReferences1().remove( ite1_1 ); + wjte2.getReferences2().add( ite2_2 ); - em.getTransaction().commit(); - em.clear(); + em.getTransaction().commit(); + em.clear(); - // + // - ite1_1_id = ite1_1.getId(); - ite1_2_id = ite1_2.getId(); - ite2_1_id = ite2_1.getId(); - ite2_2_id = ite2_2.getId(); + ite1_1_id = ite1_1.getId(); + ite1_2_id = ite1_2.getId(); + ite2_1_id = ite2_1.getId(); + ite2_2_id = ite2_2.getId(); - wjte1_id = wjte1.getId(); - wjte2_id = wjte2.getId(); - } + wjte1_id = wjte1.getId(); + wjte2_id = wjte2.getId(); + } - @Test - public void testRevisionsCounts() { - assertEquals(Arrays.asList(1, 2, 4), getAuditReader().getRevisions(WhereJoinTableEntity.class, wjte1_id)); - assertEquals(Arrays.asList(1, 3, 4), getAuditReader().getRevisions(WhereJoinTableEntity.class, wjte2_id)); + @Test + public void testRevisionsCounts() { + assertEquals( Arrays.asList( 1, 2, 4 ), getAuditReader().getRevisions( WhereJoinTableEntity.class, wjte1_id ) ); + assertEquals( Arrays.asList( 1, 3, 4 ), getAuditReader().getRevisions( WhereJoinTableEntity.class, wjte2_id ) ); - assertEquals(Arrays.asList(1), getAuditReader().getRevisions(IntNoAutoIdTestEntity.class, ite1_1_id)); - assertEquals(Arrays.asList(1), getAuditReader().getRevisions(IntNoAutoIdTestEntity.class, ite1_2_id)); - assertEquals(Arrays.asList(1), getAuditReader().getRevisions(IntNoAutoIdTestEntity.class, ite2_1_id)); - assertEquals(Arrays.asList(1), getAuditReader().getRevisions(IntNoAutoIdTestEntity.class, ite2_2_id)); - } + assertEquals( Arrays.asList( 1 ), getAuditReader().getRevisions( IntNoAutoIdTestEntity.class, ite1_1_id ) ); + assertEquals( Arrays.asList( 1 ), getAuditReader().getRevisions( IntNoAutoIdTestEntity.class, ite1_2_id ) ); + assertEquals( Arrays.asList( 1 ), getAuditReader().getRevisions( IntNoAutoIdTestEntity.class, ite2_1_id ) ); + assertEquals( Arrays.asList( 1 ), getAuditReader().getRevisions( IntNoAutoIdTestEntity.class, ite2_2_id ) ); + } - @Test - public void testHistoryOfWjte1() { - IntNoAutoIdTestEntity ite1_1 = getEntityManager().find(IntNoAutoIdTestEntity.class, ite1_1_id); - IntNoAutoIdTestEntity ite2_1 = getEntityManager().find(IntNoAutoIdTestEntity.class, ite2_1_id); + @Test + public void testHistoryOfWjte1() { + IntNoAutoIdTestEntity ite1_1 = getEntityManager().find( IntNoAutoIdTestEntity.class, ite1_1_id ); + IntNoAutoIdTestEntity ite2_1 = getEntityManager().find( IntNoAutoIdTestEntity.class, ite2_1_id ); - WhereJoinTableEntity rev1 = getAuditReader().find(WhereJoinTableEntity.class, wjte1_id, 1); - WhereJoinTableEntity rev2 = getAuditReader().find(WhereJoinTableEntity.class, wjte1_id, 2); - WhereJoinTableEntity rev3 = getAuditReader().find(WhereJoinTableEntity.class, wjte1_id, 3); - WhereJoinTableEntity rev4 = getAuditReader().find(WhereJoinTableEntity.class, wjte1_id, 4); + WhereJoinTableEntity rev1 = getAuditReader().find( WhereJoinTableEntity.class, wjte1_id, 1 ); + WhereJoinTableEntity rev2 = getAuditReader().find( WhereJoinTableEntity.class, wjte1_id, 2 ); + WhereJoinTableEntity rev3 = getAuditReader().find( WhereJoinTableEntity.class, wjte1_id, 3 ); + WhereJoinTableEntity rev4 = getAuditReader().find( WhereJoinTableEntity.class, wjte1_id, 4 ); - // Checking 1st list - assert TestTools.checkList(rev1.getReferences1()); - assert TestTools.checkList(rev2.getReferences1(), ite1_1); - assert TestTools.checkList(rev3.getReferences1(), ite1_1); - assert TestTools.checkList(rev4.getReferences1()); + // Checking 1st list + assert TestTools.checkList( rev1.getReferences1() ); + assert TestTools.checkList( rev2.getReferences1(), ite1_1 ); + assert TestTools.checkList( rev3.getReferences1(), ite1_1 ); + assert TestTools.checkList( rev4.getReferences1() ); - // Checking 2nd list - assert TestTools.checkList(rev1.getReferences2()); - assert TestTools.checkList(rev2.getReferences2(), ite2_1); - assert TestTools.checkList(rev3.getReferences2(), ite2_1); - assert TestTools.checkList(rev4.getReferences2(), ite2_1); - } + // Checking 2nd list + assert TestTools.checkList( rev1.getReferences2() ); + assert TestTools.checkList( rev2.getReferences2(), ite2_1 ); + assert TestTools.checkList( rev3.getReferences2(), ite2_1 ); + assert TestTools.checkList( rev4.getReferences2(), ite2_1 ); + } - @Test - public void testHistoryOfWjte2() { - IntNoAutoIdTestEntity ite1_1 = getEntityManager().find(IntNoAutoIdTestEntity.class, ite1_1_id); - IntNoAutoIdTestEntity ite1_2 = getEntityManager().find(IntNoAutoIdTestEntity.class, ite1_2_id); - IntNoAutoIdTestEntity ite2_2 = getEntityManager().find(IntNoAutoIdTestEntity.class, ite2_2_id); + @Test + public void testHistoryOfWjte2() { + IntNoAutoIdTestEntity ite1_1 = getEntityManager().find( IntNoAutoIdTestEntity.class, ite1_1_id ); + IntNoAutoIdTestEntity ite1_2 = getEntityManager().find( IntNoAutoIdTestEntity.class, ite1_2_id ); + IntNoAutoIdTestEntity ite2_2 = getEntityManager().find( IntNoAutoIdTestEntity.class, ite2_2_id ); - WhereJoinTableEntity rev1 = getAuditReader().find(WhereJoinTableEntity.class, wjte2_id, 1); - WhereJoinTableEntity rev2 = getAuditReader().find(WhereJoinTableEntity.class, wjte2_id, 2); - WhereJoinTableEntity rev3 = getAuditReader().find(WhereJoinTableEntity.class, wjte2_id, 3); - WhereJoinTableEntity rev4 = getAuditReader().find(WhereJoinTableEntity.class, wjte2_id, 4); + WhereJoinTableEntity rev1 = getAuditReader().find( WhereJoinTableEntity.class, wjte2_id, 1 ); + WhereJoinTableEntity rev2 = getAuditReader().find( WhereJoinTableEntity.class, wjte2_id, 2 ); + WhereJoinTableEntity rev3 = getAuditReader().find( WhereJoinTableEntity.class, wjte2_id, 3 ); + WhereJoinTableEntity rev4 = getAuditReader().find( WhereJoinTableEntity.class, wjte2_id, 4 ); - // Checking 1st list - assert TestTools.checkList(rev1.getReferences1()); - assert TestTools.checkList(rev2.getReferences1()); - assert TestTools.checkList(rev3.getReferences1(), ite1_1, ite1_2); - assert TestTools.checkList(rev4.getReferences1(), ite1_1, ite1_2); + // Checking 1st list + assert TestTools.checkList( rev1.getReferences1() ); + assert TestTools.checkList( rev2.getReferences1() ); + assert TestTools.checkList( rev3.getReferences1(), ite1_1, ite1_2 ); + assert TestTools.checkList( rev4.getReferences1(), ite1_1, ite1_2 ); - // Checking 2nd list - assert TestTools.checkList(rev1.getReferences2()); - assert TestTools.checkList(rev2.getReferences2()); - assert TestTools.checkList(rev3.getReferences2()); - assert TestTools.checkList(rev4.getReferences2(), ite2_2); - } + // Checking 2nd list + assert TestTools.checkList( rev1.getReferences2() ); + assert TestTools.checkList( rev2.getReferences2() ); + assert TestTools.checkList( rev3.getReferences2() ); + assert TestTools.checkList( rev4.getReferences2(), ite2_2 ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/CustomComparatorEntityTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/CustomComparatorEntityTest.java index 6282b4078f..cc5bb26d36 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/CustomComparatorEntityTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/CustomComparatorEntityTest.java @@ -23,14 +23,12 @@ */ package org.hibernate.envers.test.integration.manytomany; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.Iterator; import java.util.Map; import java.util.SortedMap; import java.util.SortedSet; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; @@ -38,6 +36,8 @@ import org.hibernate.envers.test.entities.StrTestEntity; import org.hibernate.envers.test.entities.StrTestEntityComparator; import org.hibernate.envers.test.entities.manytomany.SortedSetEntity; +import org.junit.Test; + import static org.junit.Assert.assertEquals; /** @@ -45,238 +45,238 @@ import static org.junit.Assert.assertEquals; */ public class CustomComparatorEntityTest extends BaseEnversJPAFunctionalTestCase { - private Integer id1; - private Integer id2; - private Integer id3; - private Integer id4; + private Integer id1; + private Integer id2; + private Integer id3; + private Integer id4; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { StrTestEntity.class, SortedSetEntity.class }; - } + return new Class[] {StrTestEntity.class, SortedSetEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - SortedSetEntity entity1 = new SortedSetEntity(1, "sortedEntity1"); + SortedSetEntity entity1 = new SortedSetEntity( 1, "sortedEntity1" ); - // Revision 1 - em.getTransaction().begin(); + // Revision 1 + em.getTransaction().begin(); - em.persist(entity1); + em.persist( entity1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 + // Revision 2 - em.getTransaction().begin(); + em.getTransaction().begin(); - entity1 = em.find(SortedSetEntity.class, 1); - final StrTestEntity strTestEntity1 = new StrTestEntity("abc"); - em.persist(strTestEntity1); - id1 = strTestEntity1.getId(); - entity1.getSortedSet().add(strTestEntity1); - entity1.getSortedMap().put(strTestEntity1, "abc"); + entity1 = em.find( SortedSetEntity.class, 1 ); + final StrTestEntity strTestEntity1 = new StrTestEntity( "abc" ); + em.persist( strTestEntity1 ); + id1 = strTestEntity1.getId(); + entity1.getSortedSet().add( strTestEntity1 ); + entity1.getSortedMap().put( strTestEntity1, "abc" ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 - em.getTransaction().begin(); + // Revision 3 + em.getTransaction().begin(); - entity1 = em.find(SortedSetEntity.class, 1); - final StrTestEntity strTestEntity2 = new StrTestEntity("aaa"); - em.persist(strTestEntity2); - id2 = strTestEntity2.getId(); - entity1.getSortedSet().add(strTestEntity2); - entity1.getSortedMap().put(strTestEntity2, "aaa"); + entity1 = em.find( SortedSetEntity.class, 1 ); + final StrTestEntity strTestEntity2 = new StrTestEntity( "aaa" ); + em.persist( strTestEntity2 ); + id2 = strTestEntity2.getId(); + entity1.getSortedSet().add( strTestEntity2 ); + entity1.getSortedMap().put( strTestEntity2, "aaa" ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 4 - em.getTransaction().begin(); + // Revision 4 + em.getTransaction().begin(); - entity1 = em.find(SortedSetEntity.class, 1); - final StrTestEntity strTestEntity3 = new StrTestEntity("aba"); - em.persist(strTestEntity3); - id3 = strTestEntity3.getId(); - entity1.getSortedSet().add(strTestEntity3); - entity1.getSortedMap().put(strTestEntity3, "aba"); + entity1 = em.find( SortedSetEntity.class, 1 ); + final StrTestEntity strTestEntity3 = new StrTestEntity( "aba" ); + em.persist( strTestEntity3 ); + id3 = strTestEntity3.getId(); + entity1.getSortedSet().add( strTestEntity3 ); + entity1.getSortedMap().put( strTestEntity3, "aba" ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 5 - em.getTransaction().begin(); + // Revision 5 + em.getTransaction().begin(); - entity1 = em.find(SortedSetEntity.class, 1); - final StrTestEntity strTestEntity4 = new StrTestEntity("aac"); - em.persist(strTestEntity4); - id4 = strTestEntity4.getId(); - entity1.getSortedSet().add(strTestEntity4); - entity1.getSortedMap().put(strTestEntity4, "aac"); + entity1 = em.find( SortedSetEntity.class, 1 ); + final StrTestEntity strTestEntity4 = new StrTestEntity( "aac" ); + em.persist( strTestEntity4 ); + id4 = strTestEntity4.getId(); + entity1.getSortedSet().add( strTestEntity4 ); + entity1.getSortedMap().put( strTestEntity4, "aac" ); - em.getTransaction().commit(); - } + em.getTransaction().commit(); + } - @Test - public void testRevisionsCounts() { - assertEquals(Arrays.asList(1, 2, 3, 4, 5), getAuditReader().getRevisions(SortedSetEntity.class, 1)); - assertEquals(Arrays.asList(2), getAuditReader().getRevisions(StrTestEntity.class, id1)); - assertEquals(Arrays.asList(3), getAuditReader().getRevisions(StrTestEntity.class, id2)); - assertEquals(Arrays.asList(4), getAuditReader().getRevisions(StrTestEntity.class, id3)); - assertEquals(Arrays.asList(5), getAuditReader().getRevisions(StrTestEntity.class, id4)); - } + @Test + public void testRevisionsCounts() { + assertEquals( Arrays.asList( 1, 2, 3, 4, 5 ), getAuditReader().getRevisions( SortedSetEntity.class, 1 ) ); + assertEquals( Arrays.asList( 2 ), getAuditReader().getRevisions( StrTestEntity.class, id1 ) ); + assertEquals( Arrays.asList( 3 ), getAuditReader().getRevisions( StrTestEntity.class, id2 ) ); + assertEquals( Arrays.asList( 4 ), getAuditReader().getRevisions( StrTestEntity.class, id3 ) ); + assertEquals( Arrays.asList( 5 ), getAuditReader().getRevisions( StrTestEntity.class, id4 ) ); + } - @Test - public void testCurrentStateOfEntity1() { - final SortedSetEntity entity1 = getEntityManager().find(SortedSetEntity.class, 1); + @Test + public void testCurrentStateOfEntity1() { + final SortedSetEntity entity1 = getEntityManager().find( SortedSetEntity.class, 1 ); - assertEquals("sortedEntity1", entity1.getData()); - assertEquals(Integer.valueOf(1), entity1.getId()); + assertEquals( "sortedEntity1", entity1.getData() ); + assertEquals( Integer.valueOf( 1 ), entity1.getId() ); - final SortedSet sortedSet = entity1.getSortedSet(); - assertEquals(StrTestEntityComparator.class, sortedSet.comparator().getClass()); - assertEquals(4, sortedSet.size()); - final Iterator iterator = sortedSet.iterator(); - checkStrTestEntity(iterator.next(), id2, "aaa"); - checkStrTestEntity(iterator.next(), id4, "aac"); - checkStrTestEntity(iterator.next(), id3, "aba"); - checkStrTestEntity(iterator.next(), id1, "abc"); + final SortedSet sortedSet = entity1.getSortedSet(); + assertEquals( StrTestEntityComparator.class, sortedSet.comparator().getClass() ); + assertEquals( 4, sortedSet.size() ); + final Iterator iterator = sortedSet.iterator(); + checkStrTestEntity( iterator.next(), id2, "aaa" ); + checkStrTestEntity( iterator.next(), id4, "aac" ); + checkStrTestEntity( iterator.next(), id3, "aba" ); + checkStrTestEntity( iterator.next(), id1, "abc" ); final SortedMap sortedMap = entity1.getSortedMap(); - assertEquals(StrTestEntityComparator.class, sortedMap.comparator().getClass()); - assertEquals(4, sortedMap.size()); + assertEquals( StrTestEntityComparator.class, sortedMap.comparator().getClass() ); + assertEquals( 4, sortedMap.size() ); Iterator> mapIterator = sortedMap.entrySet().iterator(); - checkStrTestEntity(mapIterator.next().getKey(), id2, "aaa"); - checkStrTestEntity(mapIterator.next().getKey(), id4, "aac"); - checkStrTestEntity(mapIterator.next().getKey(), id3, "aba"); - checkStrTestEntity(mapIterator.next().getKey(), id1, "abc"); + checkStrTestEntity( mapIterator.next().getKey(), id2, "aaa" ); + checkStrTestEntity( mapIterator.next().getKey(), id4, "aac" ); + checkStrTestEntity( mapIterator.next().getKey(), id3, "aba" ); + checkStrTestEntity( mapIterator.next().getKey(), id1, "abc" ); - mapIterator = sortedMap.entrySet().iterator(); - assertEquals(mapIterator.next().getValue(), "aaa"); - assertEquals(mapIterator.next().getValue(), "aac"); - assertEquals(mapIterator.next().getValue(), "aba"); - assertEquals(mapIterator.next().getValue(), "abc"); - } + mapIterator = sortedMap.entrySet().iterator(); + assertEquals( mapIterator.next().getValue(), "aaa" ); + assertEquals( mapIterator.next().getValue(), "aac" ); + assertEquals( mapIterator.next().getValue(), "aba" ); + assertEquals( mapIterator.next().getValue(), "abc" ); + } - private void checkStrTestEntity(StrTestEntity entity, Integer id, String sortKey) { - assertEquals(id, entity.getId()); - assertEquals(sortKey, entity.getStr()); - } + private void checkStrTestEntity(StrTestEntity entity, Integer id, String sortKey) { + assertEquals( id, entity.getId() ); + assertEquals( sortKey, entity.getStr() ); + } - @Test - public void testHistoryOfEntity1() throws Exception { - SortedSetEntity entity1 = getAuditReader().find(SortedSetEntity.class, 1, 1); + @Test + public void testHistoryOfEntity1() throws Exception { + SortedSetEntity entity1 = getAuditReader().find( SortedSetEntity.class, 1, 1 ); - assertEquals("sortedEntity1", entity1.getData()); - assertEquals(Integer.valueOf(1), entity1.getId()); + assertEquals( "sortedEntity1", entity1.getData() ); + assertEquals( Integer.valueOf( 1 ), entity1.getId() ); - SortedSet sortedSet = entity1.getSortedSet(); - assertEquals(StrTestEntityComparator.class, sortedSet.comparator().getClass()); - assertEquals(0, sortedSet.size()); + SortedSet sortedSet = entity1.getSortedSet(); + assertEquals( StrTestEntityComparator.class, sortedSet.comparator().getClass() ); + assertEquals( 0, sortedSet.size() ); SortedMap sortedMap = entity1.getSortedMap(); - assertEquals(StrTestEntityComparator.class, sortedMap.comparator().getClass()); - assertEquals(0, sortedMap.size()); + assertEquals( StrTestEntityComparator.class, sortedMap.comparator().getClass() ); + assertEquals( 0, sortedMap.size() ); - entity1 = getAuditReader().find(SortedSetEntity.class, 1, 2); + entity1 = getAuditReader().find( SortedSetEntity.class, 1, 2 ); - assertEquals("sortedEntity1", entity1.getData()); - assertEquals(Integer.valueOf(1), entity1.getId()); + assertEquals( "sortedEntity1", entity1.getData() ); + assertEquals( Integer.valueOf( 1 ), entity1.getId() ); - sortedSet = entity1.getSortedSet(); - assertEquals(StrTestEntityComparator.class, sortedSet.comparator().getClass()); - assertEquals(1, sortedSet.size()); - Iterator iterator = sortedSet.iterator(); - checkStrTestEntity(iterator.next(), id1, "abc"); + sortedSet = entity1.getSortedSet(); + assertEquals( StrTestEntityComparator.class, sortedSet.comparator().getClass() ); + assertEquals( 1, sortedSet.size() ); + Iterator iterator = sortedSet.iterator(); + checkStrTestEntity( iterator.next(), id1, "abc" ); sortedMap = entity1.getSortedMap(); - assertEquals(StrTestEntityComparator.class, sortedMap.comparator().getClass()); - assertEquals(1, sortedMap.size()); + assertEquals( StrTestEntityComparator.class, sortedMap.comparator().getClass() ); + assertEquals( 1, sortedMap.size() ); Iterator> mapIterator = sortedMap.entrySet().iterator(); - checkStrTestEntity(mapIterator.next().getKey(), id1, "abc"); + checkStrTestEntity( mapIterator.next().getKey(), id1, "abc" ); - mapIterator = sortedMap.entrySet().iterator(); - assertEquals(mapIterator.next().getValue(), "abc"); + mapIterator = sortedMap.entrySet().iterator(); + assertEquals( mapIterator.next().getValue(), "abc" ); - entity1 = getAuditReader().find(SortedSetEntity.class, 1, 3); + entity1 = getAuditReader().find( SortedSetEntity.class, 1, 3 ); - assertEquals("sortedEntity1", entity1.getData()); - assertEquals(Integer.valueOf(1), entity1.getId()); + assertEquals( "sortedEntity1", entity1.getData() ); + assertEquals( Integer.valueOf( 1 ), entity1.getId() ); - sortedSet = entity1.getSortedSet(); - assertEquals(StrTestEntityComparator.class, sortedSet.comparator().getClass()); - assertEquals(2, sortedSet.size()); - iterator = sortedSet.iterator(); - checkStrTestEntity(iterator.next(), id2, "aaa"); - checkStrTestEntity(iterator.next(), id1, "abc"); + sortedSet = entity1.getSortedSet(); + assertEquals( StrTestEntityComparator.class, sortedSet.comparator().getClass() ); + assertEquals( 2, sortedSet.size() ); + iterator = sortedSet.iterator(); + checkStrTestEntity( iterator.next(), id2, "aaa" ); + checkStrTestEntity( iterator.next(), id1, "abc" ); sortedMap = entity1.getSortedMap(); - assertEquals(StrTestEntityComparator.class, sortedMap.comparator().getClass()); - assertEquals(2, sortedMap.size()); + assertEquals( StrTestEntityComparator.class, sortedMap.comparator().getClass() ); + assertEquals( 2, sortedMap.size() ); mapIterator = sortedMap.entrySet().iterator(); - checkStrTestEntity(mapIterator.next().getKey(), id2, "aaa"); - checkStrTestEntity(mapIterator.next().getKey(), id1, "abc"); + checkStrTestEntity( mapIterator.next().getKey(), id2, "aaa" ); + checkStrTestEntity( mapIterator.next().getKey(), id1, "abc" ); - mapIterator = sortedMap.entrySet().iterator(); - assertEquals(mapIterator.next().getValue(), "aaa"); - assertEquals(mapIterator.next().getValue(), "abc"); + mapIterator = sortedMap.entrySet().iterator(); + assertEquals( mapIterator.next().getValue(), "aaa" ); + assertEquals( mapIterator.next().getValue(), "abc" ); - entity1 = getAuditReader().find(SortedSetEntity.class, 1, 4); + entity1 = getAuditReader().find( SortedSetEntity.class, 1, 4 ); - assertEquals("sortedEntity1", entity1.getData()); - assertEquals(Integer.valueOf(1), entity1.getId()); + assertEquals( "sortedEntity1", entity1.getData() ); + assertEquals( Integer.valueOf( 1 ), entity1.getId() ); - sortedSet = entity1.getSortedSet(); - assertEquals(StrTestEntityComparator.class, sortedSet.comparator().getClass()); - assertEquals(3, sortedSet.size()); - iterator = sortedSet.iterator(); - checkStrTestEntity(iterator.next(), id2, "aaa"); - checkStrTestEntity(iterator.next(), id3, "aba"); - checkStrTestEntity(iterator.next(), id1, "abc"); + sortedSet = entity1.getSortedSet(); + assertEquals( StrTestEntityComparator.class, sortedSet.comparator().getClass() ); + assertEquals( 3, sortedSet.size() ); + iterator = sortedSet.iterator(); + checkStrTestEntity( iterator.next(), id2, "aaa" ); + checkStrTestEntity( iterator.next(), id3, "aba" ); + checkStrTestEntity( iterator.next(), id1, "abc" ); sortedMap = entity1.getSortedMap(); - assertEquals(StrTestEntityComparator.class, sortedMap.comparator().getClass()); - assertEquals(3, sortedMap.size()); + assertEquals( StrTestEntityComparator.class, sortedMap.comparator().getClass() ); + assertEquals( 3, sortedMap.size() ); mapIterator = sortedMap.entrySet().iterator(); - checkStrTestEntity(mapIterator.next().getKey(), id2, "aaa"); - checkStrTestEntity(mapIterator.next().getKey(), id3, "aba"); - checkStrTestEntity(mapIterator.next().getKey(), id1, "abc"); + checkStrTestEntity( mapIterator.next().getKey(), id2, "aaa" ); + checkStrTestEntity( mapIterator.next().getKey(), id3, "aba" ); + checkStrTestEntity( mapIterator.next().getKey(), id1, "abc" ); - mapIterator = sortedMap.entrySet().iterator(); - assertEquals(mapIterator.next().getValue(), "aaa"); - assertEquals(mapIterator.next().getValue(), "aba"); - assertEquals(mapIterator.next().getValue(), "abc"); + mapIterator = sortedMap.entrySet().iterator(); + assertEquals( mapIterator.next().getValue(), "aaa" ); + assertEquals( mapIterator.next().getValue(), "aba" ); + assertEquals( mapIterator.next().getValue(), "abc" ); - entity1 = getAuditReader().find(SortedSetEntity.class, 1, 5); + entity1 = getAuditReader().find( SortedSetEntity.class, 1, 5 ); - assertEquals("sortedEntity1", entity1.getData()); - assertEquals(Integer.valueOf(1), entity1.getId()); + assertEquals( "sortedEntity1", entity1.getData() ); + assertEquals( Integer.valueOf( 1 ), entity1.getId() ); - sortedSet = entity1.getSortedSet(); - assertEquals(StrTestEntityComparator.class, sortedSet.comparator().getClass()); - assertEquals(4, sortedSet.size()); - iterator = sortedSet.iterator(); - checkStrTestEntity(iterator.next(), id2, "aaa"); - checkStrTestEntity(iterator.next(), id4, "aac"); - checkStrTestEntity(iterator.next(), id3, "aba"); - checkStrTestEntity(iterator.next(), id1, "abc"); + sortedSet = entity1.getSortedSet(); + assertEquals( StrTestEntityComparator.class, sortedSet.comparator().getClass() ); + assertEquals( 4, sortedSet.size() ); + iterator = sortedSet.iterator(); + checkStrTestEntity( iterator.next(), id2, "aaa" ); + checkStrTestEntity( iterator.next(), id4, "aac" ); + checkStrTestEntity( iterator.next(), id3, "aba" ); + checkStrTestEntity( iterator.next(), id1, "abc" ); sortedMap = entity1.getSortedMap(); - assertEquals(StrTestEntityComparator.class, sortedMap.comparator().getClass()); - assertEquals(4, sortedMap.size()); + assertEquals( StrTestEntityComparator.class, sortedMap.comparator().getClass() ); + assertEquals( 4, sortedMap.size() ); mapIterator = sortedMap.entrySet().iterator(); - checkStrTestEntity(mapIterator.next().getKey(), id2, "aaa"); - checkStrTestEntity(mapIterator.next().getKey(), id4, "aac"); - checkStrTestEntity(mapIterator.next().getKey(), id3, "aba"); - checkStrTestEntity(mapIterator.next().getKey(), id1, "abc"); + checkStrTestEntity( mapIterator.next().getKey(), id2, "aaa" ); + checkStrTestEntity( mapIterator.next().getKey(), id4, "aac" ); + checkStrTestEntity( mapIterator.next().getKey(), id3, "aba" ); + checkStrTestEntity( mapIterator.next().getKey(), id1, "abc" ); - mapIterator = sortedMap.entrySet().iterator(); - assertEquals(mapIterator.next().getValue(), "aaa"); - assertEquals(mapIterator.next().getValue(), "aac"); - assertEquals(mapIterator.next().getValue(), "aba"); - assertEquals(mapIterator.next().getValue(), "abc"); - } + mapIterator = sortedMap.entrySet().iterator(); + assertEquals( mapIterator.next().getValue(), "aaa" ); + assertEquals( mapIterator.next().getValue(), "aac" ); + assertEquals( mapIterator.next().getValue(), "aba" ); + assertEquals( mapIterator.next().getValue(), "abc" ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/biowned/BasicBiowned.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/biowned/BasicBiowned.java index 20927626ee..b9af0e5b08 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/biowned/BasicBiowned.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/biowned/BasicBiowned.java @@ -23,10 +23,8 @@ */ package org.hibernate.envers.test.integration.manytomany.biowned; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; @@ -34,189 +32,196 @@ import org.hibernate.envers.test.entities.manytomany.biowned.ListBiowning1Entity import org.hibernate.envers.test.entities.manytomany.biowned.ListBiowning2Entity; import org.hibernate.envers.test.tools.TestTools; +import org.junit.Test; + import static org.junit.Assert.assertEquals; /** * @author Adam Warski (adam at warski dot org) */ public class BasicBiowned extends BaseEnversJPAFunctionalTestCase { - private Integer o1_1_id; - private Integer o1_2_id; - private Integer o2_1_id; - private Integer o2_2_id; + private Integer o1_1_id; + private Integer o1_2_id; + private Integer o2_1_id; + private Integer o2_2_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { ListBiowning1Entity.class, ListBiowning2Entity.class }; - } + return new Class[] {ListBiowning1Entity.class, ListBiowning2Entity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - ListBiowning1Entity o1_1 = new ListBiowning1Entity("o1_1"); - ListBiowning1Entity o1_2 = new ListBiowning1Entity("o1_2"); - ListBiowning2Entity o2_1 = new ListBiowning2Entity("o2_1"); - ListBiowning2Entity o2_2 = new ListBiowning2Entity("o2_2"); + ListBiowning1Entity o1_1 = new ListBiowning1Entity( "o1_1" ); + ListBiowning1Entity o1_2 = new ListBiowning1Entity( "o1_2" ); + ListBiowning2Entity o2_1 = new ListBiowning2Entity( "o2_1" ); + ListBiowning2Entity o2_2 = new ListBiowning2Entity( "o2_2" ); - // Revision 1 - em.getTransaction().begin(); + // Revision 1 + em.getTransaction().begin(); - em.persist(o1_1); - em.persist(o1_2); - em.persist(o2_1); - em.persist(o2_2); + em.persist( o1_1 ); + em.persist( o1_2 ); + em.persist( o2_1 ); + em.persist( o2_2 ); - em.getTransaction().commit(); - em.clear(); + em.getTransaction().commit(); + em.clear(); - // Revision 2 (1_1 <-> 2_1; 1_2 <-> 2_2) + // Revision 2 (1_1 <-> 2_1; 1_2 <-> 2_2) - em.getTransaction().begin(); + em.getTransaction().begin(); - o1_1 = em.find(ListBiowning1Entity.class, o1_1.getId()); - o1_2 = em.find(ListBiowning1Entity.class, o1_2.getId()); - o2_1 = em.find(ListBiowning2Entity.class, o2_1.getId()); - o2_2 = em.find(ListBiowning2Entity.class, o2_2.getId()); + o1_1 = em.find( ListBiowning1Entity.class, o1_1.getId() ); + o1_2 = em.find( ListBiowning1Entity.class, o1_2.getId() ); + o2_1 = em.find( ListBiowning2Entity.class, o2_1.getId() ); + o2_2 = em.find( ListBiowning2Entity.class, o2_2.getId() ); - o1_1.getReferences().add(o2_1); - o1_2.getReferences().add(o2_2); + o1_1.getReferences().add( o2_1 ); + o1_2.getReferences().add( o2_2 ); - em.getTransaction().commit(); - em.clear(); + em.getTransaction().commit(); + em.clear(); - // Revision 3 (1_1 <-> 2_1, 2_2; 1_2 <-> 2_2) - em.getTransaction().begin(); + // Revision 3 (1_1 <-> 2_1, 2_2; 1_2 <-> 2_2) + em.getTransaction().begin(); - o1_1 = em.find(ListBiowning1Entity.class, o1_1.getId()); - o2_2 = em.find(ListBiowning2Entity.class, o2_2.getId()); + o1_1 = em.find( ListBiowning1Entity.class, o1_1.getId() ); + o2_2 = em.find( ListBiowning2Entity.class, o2_2.getId() ); - o1_1.getReferences().add(o2_2); + o1_1.getReferences().add( o2_2 ); - em.getTransaction().commit(); - em.clear(); + em.getTransaction().commit(); + em.clear(); - // Revision 4 (1_2 <-> 2_1, 2_2) - em.getTransaction().begin(); + // Revision 4 (1_2 <-> 2_1, 2_2) + em.getTransaction().begin(); - o1_1 = em.find(ListBiowning1Entity.class, o1_1.getId()); - o1_2 = em.find(ListBiowning1Entity.class, o1_2.getId()); - o2_1 = em.find(ListBiowning2Entity.class, o2_1.getId()); - o2_2 = em.find(ListBiowning2Entity.class, o2_2.getId()); + o1_1 = em.find( ListBiowning1Entity.class, o1_1.getId() ); + o1_2 = em.find( ListBiowning1Entity.class, o1_2.getId() ); + o2_1 = em.find( ListBiowning2Entity.class, o2_1.getId() ); + o2_2 = em.find( ListBiowning2Entity.class, o2_2.getId() ); - o2_2.getReferences().remove(o1_1); - o2_1.getReferences().remove(o1_1); - o2_1.getReferences().add(o1_2); + o2_2.getReferences().remove( o1_1 ); + o2_1.getReferences().remove( o1_1 ); + o2_1.getReferences().add( o1_2 ); - em.getTransaction().commit(); - em.clear(); + em.getTransaction().commit(); + em.clear(); - // Revision 5 (1_1 <-> 2_2, 1_2 <-> 2_2) - em.getTransaction().begin(); + // Revision 5 (1_1 <-> 2_2, 1_2 <-> 2_2) + em.getTransaction().begin(); - o1_1 = em.find(ListBiowning1Entity.class, o1_1.getId()); - o1_2 = em.find(ListBiowning1Entity.class, o1_2.getId()); - o2_1 = em.find(ListBiowning2Entity.class, o2_1.getId()); - o2_2 = em.find(ListBiowning2Entity.class, o2_2.getId()); + o1_1 = em.find( ListBiowning1Entity.class, o1_1.getId() ); + o1_2 = em.find( ListBiowning1Entity.class, o1_2.getId() ); + o2_1 = em.find( ListBiowning2Entity.class, o2_1.getId() ); + o2_2 = em.find( ListBiowning2Entity.class, o2_2.getId() ); - o1_2.getReferences().remove(o2_1); - o1_1.getReferences().add(o2_2); + o1_2.getReferences().remove( o2_1 ); + o1_1.getReferences().add( o2_2 ); - em.getTransaction().commit(); - em.clear(); + em.getTransaction().commit(); + em.clear(); - // + // - o1_1_id = o1_1.getId(); - o1_2_id = o1_2.getId(); - o2_1_id = o2_1.getId(); - o2_2_id = o2_2.getId(); - } + o1_1_id = o1_1.getId(); + o1_2_id = o1_2.getId(); + o2_1_id = o2_1.getId(); + o2_2_id = o2_2.getId(); + } - @Test - public void testRevisionsCounts() { - // Although it would seem that when modifying references both entities should be marked as modified, because - // ownly the owning side is notified (because of the bi-owning mapping), a revision is created only for - // the entity where the collection was directly modified. + @Test + public void testRevisionsCounts() { + // Although it would seem that when modifying references both entities should be marked as modified, because + // ownly the owning side is notified (because of the bi-owning mapping), a revision is created only for + // the entity where the collection was directly modified. - assertEquals(Arrays.asList(1, 2, 3, 5), getAuditReader().getRevisions(ListBiowning1Entity.class, o1_1_id)); - assertEquals(Arrays.asList(1, 2, 5), getAuditReader().getRevisions(ListBiowning1Entity.class, o1_2_id)); + assertEquals( + Arrays.asList( 1, 2, 3, 5 ), getAuditReader().getRevisions( + ListBiowning1Entity.class, + o1_1_id + ) + ); + assertEquals( Arrays.asList( 1, 2, 5 ), getAuditReader().getRevisions( ListBiowning1Entity.class, o1_2_id ) ); - assertEquals(Arrays.asList(1, 4), getAuditReader().getRevisions(ListBiowning2Entity.class, o2_1_id)); - assertEquals(Arrays.asList(1, 4), getAuditReader().getRevisions(ListBiowning2Entity.class, o2_2_id)); - } + assertEquals( Arrays.asList( 1, 4 ), getAuditReader().getRevisions( ListBiowning2Entity.class, o2_1_id ) ); + assertEquals( Arrays.asList( 1, 4 ), getAuditReader().getRevisions( ListBiowning2Entity.class, o2_2_id ) ); + } - @Test - public void testHistoryOfO1_1() { - ListBiowning2Entity o2_1 = getEntityManager().find(ListBiowning2Entity.class, o2_1_id); - ListBiowning2Entity o2_2 = getEntityManager().find(ListBiowning2Entity.class, o2_2_id); + @Test + public void testHistoryOfO1_1() { + ListBiowning2Entity o2_1 = getEntityManager().find( ListBiowning2Entity.class, o2_1_id ); + ListBiowning2Entity o2_2 = getEntityManager().find( ListBiowning2Entity.class, o2_2_id ); - ListBiowning1Entity rev1 = getAuditReader().find(ListBiowning1Entity.class, o1_1_id, 1); - ListBiowning1Entity rev2 = getAuditReader().find(ListBiowning1Entity.class, o1_1_id, 2); - ListBiowning1Entity rev3 = getAuditReader().find(ListBiowning1Entity.class, o1_1_id, 3); - ListBiowning1Entity rev4 = getAuditReader().find(ListBiowning1Entity.class, o1_1_id, 4); - ListBiowning1Entity rev5 = getAuditReader().find(ListBiowning1Entity.class, o1_1_id, 5); + ListBiowning1Entity rev1 = getAuditReader().find( ListBiowning1Entity.class, o1_1_id, 1 ); + ListBiowning1Entity rev2 = getAuditReader().find( ListBiowning1Entity.class, o1_1_id, 2 ); + ListBiowning1Entity rev3 = getAuditReader().find( ListBiowning1Entity.class, o1_1_id, 3 ); + ListBiowning1Entity rev4 = getAuditReader().find( ListBiowning1Entity.class, o1_1_id, 4 ); + ListBiowning1Entity rev5 = getAuditReader().find( ListBiowning1Entity.class, o1_1_id, 5 ); - assert TestTools.checkList(rev1.getReferences()); - assert TestTools.checkList(rev2.getReferences(), o2_1); - assert TestTools.checkList(rev3.getReferences(), o2_1, o2_2); - assert TestTools.checkList(rev4.getReferences()); - assert TestTools.checkList(rev5.getReferences(), o2_2); - } + assert TestTools.checkList( rev1.getReferences() ); + assert TestTools.checkList( rev2.getReferences(), o2_1 ); + assert TestTools.checkList( rev3.getReferences(), o2_1, o2_2 ); + assert TestTools.checkList( rev4.getReferences() ); + assert TestTools.checkList( rev5.getReferences(), o2_2 ); + } - @Test - public void testHistoryOfO1_2() { - ListBiowning2Entity o2_1 = getEntityManager().find(ListBiowning2Entity.class, o2_1_id); - ListBiowning2Entity o2_2 = getEntityManager().find(ListBiowning2Entity.class, o2_2_id); + @Test + public void testHistoryOfO1_2() { + ListBiowning2Entity o2_1 = getEntityManager().find( ListBiowning2Entity.class, o2_1_id ); + ListBiowning2Entity o2_2 = getEntityManager().find( ListBiowning2Entity.class, o2_2_id ); - ListBiowning1Entity rev1 = getAuditReader().find(ListBiowning1Entity.class, o1_2_id, 1); - ListBiowning1Entity rev2 = getAuditReader().find(ListBiowning1Entity.class, o1_2_id, 2); - ListBiowning1Entity rev3 = getAuditReader().find(ListBiowning1Entity.class, o1_2_id, 3); - ListBiowning1Entity rev4 = getAuditReader().find(ListBiowning1Entity.class, o1_2_id, 4); - ListBiowning1Entity rev5 = getAuditReader().find(ListBiowning1Entity.class, o1_2_id, 5); + ListBiowning1Entity rev1 = getAuditReader().find( ListBiowning1Entity.class, o1_2_id, 1 ); + ListBiowning1Entity rev2 = getAuditReader().find( ListBiowning1Entity.class, o1_2_id, 2 ); + ListBiowning1Entity rev3 = getAuditReader().find( ListBiowning1Entity.class, o1_2_id, 3 ); + ListBiowning1Entity rev4 = getAuditReader().find( ListBiowning1Entity.class, o1_2_id, 4 ); + ListBiowning1Entity rev5 = getAuditReader().find( ListBiowning1Entity.class, o1_2_id, 5 ); - assert TestTools.checkList(rev1.getReferences()); - assert TestTools.checkList(rev2.getReferences(), o2_2); - assert TestTools.checkList(rev3.getReferences(), o2_2); - assert TestTools.checkList(rev4.getReferences(), o2_1, o2_2); - System.out.println("rev5.getReferences() = " + rev5.getReferences()); - assert TestTools.checkList(rev5.getReferences(), o2_2); - } + assert TestTools.checkList( rev1.getReferences() ); + assert TestTools.checkList( rev2.getReferences(), o2_2 ); + assert TestTools.checkList( rev3.getReferences(), o2_2 ); + assert TestTools.checkList( rev4.getReferences(), o2_1, o2_2 ); + System.out.println( "rev5.getReferences() = " + rev5.getReferences() ); + assert TestTools.checkList( rev5.getReferences(), o2_2 ); + } - @Test - public void testHistoryOfO2_1() { - ListBiowning1Entity o1_1 = getEntityManager().find(ListBiowning1Entity.class, o1_1_id); - ListBiowning1Entity o1_2 = getEntityManager().find(ListBiowning1Entity.class, o1_2_id); + @Test + public void testHistoryOfO2_1() { + ListBiowning1Entity o1_1 = getEntityManager().find( ListBiowning1Entity.class, o1_1_id ); + ListBiowning1Entity o1_2 = getEntityManager().find( ListBiowning1Entity.class, o1_2_id ); - ListBiowning2Entity rev1 = getAuditReader().find(ListBiowning2Entity.class, o2_1_id, 1); - ListBiowning2Entity rev2 = getAuditReader().find(ListBiowning2Entity.class, o2_1_id, 2); - ListBiowning2Entity rev3 = getAuditReader().find(ListBiowning2Entity.class, o2_1_id, 3); - ListBiowning2Entity rev4 = getAuditReader().find(ListBiowning2Entity.class, o2_1_id, 4); - ListBiowning2Entity rev5 = getAuditReader().find(ListBiowning2Entity.class, o2_1_id, 5); + ListBiowning2Entity rev1 = getAuditReader().find( ListBiowning2Entity.class, o2_1_id, 1 ); + ListBiowning2Entity rev2 = getAuditReader().find( ListBiowning2Entity.class, o2_1_id, 2 ); + ListBiowning2Entity rev3 = getAuditReader().find( ListBiowning2Entity.class, o2_1_id, 3 ); + ListBiowning2Entity rev4 = getAuditReader().find( ListBiowning2Entity.class, o2_1_id, 4 ); + ListBiowning2Entity rev5 = getAuditReader().find( ListBiowning2Entity.class, o2_1_id, 5 ); - assert TestTools.checkList(rev1.getReferences()); - assert TestTools.checkList(rev2.getReferences(), o1_1); - assert TestTools.checkList(rev3.getReferences(), o1_1); - assert TestTools.checkList(rev4.getReferences(), o1_2); - assert TestTools.checkList(rev5.getReferences()); - } + assert TestTools.checkList( rev1.getReferences() ); + assert TestTools.checkList( rev2.getReferences(), o1_1 ); + assert TestTools.checkList( rev3.getReferences(), o1_1 ); + assert TestTools.checkList( rev4.getReferences(), o1_2 ); + assert TestTools.checkList( rev5.getReferences() ); + } - @Test - public void testHistoryOfO2_2() { - ListBiowning1Entity o1_1 = getEntityManager().find(ListBiowning1Entity.class, o1_1_id); - ListBiowning1Entity o1_2 = getEntityManager().find(ListBiowning1Entity.class, o1_2_id); + @Test + public void testHistoryOfO2_2() { + ListBiowning1Entity o1_1 = getEntityManager().find( ListBiowning1Entity.class, o1_1_id ); + ListBiowning1Entity o1_2 = getEntityManager().find( ListBiowning1Entity.class, o1_2_id ); - ListBiowning2Entity rev1 = getAuditReader().find(ListBiowning2Entity.class, o2_2_id, 1); - ListBiowning2Entity rev2 = getAuditReader().find(ListBiowning2Entity.class, o2_2_id, 2); - ListBiowning2Entity rev3 = getAuditReader().find(ListBiowning2Entity.class, o2_2_id, 3); - ListBiowning2Entity rev4 = getAuditReader().find(ListBiowning2Entity.class, o2_2_id, 4); - ListBiowning2Entity rev5 = getAuditReader().find(ListBiowning2Entity.class, o2_2_id, 5); + ListBiowning2Entity rev1 = getAuditReader().find( ListBiowning2Entity.class, o2_2_id, 1 ); + ListBiowning2Entity rev2 = getAuditReader().find( ListBiowning2Entity.class, o2_2_id, 2 ); + ListBiowning2Entity rev3 = getAuditReader().find( ListBiowning2Entity.class, o2_2_id, 3 ); + ListBiowning2Entity rev4 = getAuditReader().find( ListBiowning2Entity.class, o2_2_id, 4 ); + ListBiowning2Entity rev5 = getAuditReader().find( ListBiowning2Entity.class, o2_2_id, 5 ); - assert TestTools.checkList(rev1.getReferences()); - assert TestTools.checkList(rev2.getReferences(), o1_2); - assert TestTools.checkList(rev3.getReferences(), o1_1, o1_2); - assert TestTools.checkList(rev4.getReferences(), o1_2); - assert TestTools.checkList(rev5.getReferences(), o1_1, o1_2); - } + assert TestTools.checkList( rev1.getReferences() ); + assert TestTools.checkList( rev2.getReferences(), o1_2 ); + assert TestTools.checkList( rev3.getReferences(), o1_1, o1_2 ); + assert TestTools.checkList( rev4.getReferences(), o1_2 ); + assert TestTools.checkList( rev5.getReferences(), o1_1, o1_2 ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/inverseToSuperclass/DetailSubclass.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/inverseToSuperclass/DetailSubclass.java index e211f4cd96..e9641d36a6 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/inverseToSuperclass/DetailSubclass.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/inverseToSuperclass/DetailSubclass.java @@ -1,4 +1,5 @@ package org.hibernate.envers.test.integration.manytomany.inverseToSuperclass; + import org.hibernate.envers.Audited; @Audited diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/inverseToSuperclass/DetailSubclass2.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/inverseToSuperclass/DetailSubclass2.java index e99efaf833..ffcef01c60 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/inverseToSuperclass/DetailSubclass2.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/inverseToSuperclass/DetailSubclass2.java @@ -1,4 +1,5 @@ package org.hibernate.envers.test.integration.manytomany.inverseToSuperclass; + import org.hibernate.envers.Audited; @Audited @@ -7,7 +8,7 @@ public class DetailSubclass2 extends DetailSubclass { private String str3; public DetailSubclass2() { - + } public String getStr3() { diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/inverseToSuperclass/DetailSuperclass.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/inverseToSuperclass/DetailSuperclass.java index f5697a74d4..2234676b44 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/inverseToSuperclass/DetailSuperclass.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/inverseToSuperclass/DetailSuperclass.java @@ -1,4 +1,5 @@ package org.hibernate.envers.test.integration.manytomany.inverseToSuperclass; + import java.util.List; import org.hibernate.envers.Audited; diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/inverseToSuperclass/ManyToManyInverseToSuperclassTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/inverseToSuperclass/ManyToManyInverseToSuperclassTest.java index 16deaf5b4f..4a0f2a4f71 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/inverseToSuperclass/ManyToManyInverseToSuperclassTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/inverseToSuperclass/ManyToManyInverseToSuperclassTest.java @@ -1,27 +1,26 @@ package org.hibernate.envers.test.integration.manytomany.inverseToSuperclass; -import java.util.ArrayList; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.ArrayList; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; +import org.junit.Test; + /** * @author Hern�n Chanfreau - * */ -public class ManyToManyInverseToSuperclassTest extends BaseEnversJPAFunctionalTestCase { +public class ManyToManyInverseToSuperclassTest extends BaseEnversJPAFunctionalTestCase { private long m1_id; @Override protected String[] getMappings() { - return new String[] { "mappings/manyToMany/inverseToSuperclass/mappings.hbm.xml" }; + return new String[] {"mappings/manyToMany/inverseToSuperclass/mappings.hbm.xml"}; } @Test - @Priority(10) + @Priority(10) public void initData() { EntityManager em = getEntityManager(); @@ -31,16 +30,16 @@ public class ManyToManyInverseToSuperclassTest extends BaseEnversJPAFunctionalTe // Revision 1 em.getTransaction().begin(); - det1.setStr2("detail 1"); + det1.setStr2( "detail 1" ); - m1.setStr("master"); - m1.setItems(new ArrayList()); - m1.getItems().add(det1); + m1.setStr( "master" ); + m1.setItems( new ArrayList() ); + m1.getItems().add( det1 ); - det1.setMasters(new ArrayList()); - det1.getMasters().add(m1); + det1.setMasters( new ArrayList() ); + det1.getMasters().add( m1 ); - em.persist(m1); + em.persist( m1 ); em.getTransaction().commit(); m1_id = m1.getId(); @@ -89,10 +88,10 @@ public class ManyToManyInverseToSuperclassTest extends BaseEnversJPAFunctionalTe @Test public void testHistoryExists() { - Master rev1_1 = getAuditReader().find(Master.class, m1_id, 1); - Master rev1_2 = getAuditReader().find(Master.class, m1_id, 2); - Master rev1_3 = getAuditReader().find(Master.class, m1_id, 3); - Master rev1_4 = getAuditReader().find(Master.class, m1_id, 4); + Master rev1_1 = getAuditReader().find( Master.class, m1_id, 1 ); + Master rev1_2 = getAuditReader().find( Master.class, m1_id, 2 ); + Master rev1_3 = getAuditReader().find( Master.class, m1_id, 3 ); + Master rev1_4 = getAuditReader().find( Master.class, m1_id, 4 ); assert (rev1_1 != null); assert (rev1_2 != null); diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/inverseToSuperclass/Master.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/inverseToSuperclass/Master.java index 6a66ee44d2..b87834634c 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/inverseToSuperclass/Master.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/inverseToSuperclass/Master.java @@ -1,4 +1,5 @@ package org.hibernate.envers.test.integration.manytomany.inverseToSuperclass; + import java.util.List; import org.hibernate.envers.Audited; diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/sametable/BasicSametable.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/sametable/BasicSametable.java index df91a972f9..d33b29fc0b 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/sametable/BasicSametable.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/sametable/BasicSametable.java @@ -23,12 +23,9 @@ */ package org.hibernate.envers.test.integration.manytomany.sametable; +import javax.persistence.EntityManager; import java.sql.Types; import java.util.Arrays; -import javax.persistence.EntityManager; - -import org.junit.Assert; -import org.junit.Test; import org.hibernate.Session; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; @@ -38,268 +35,276 @@ import org.hibernate.envers.test.entities.manytomany.sametable.Child2Entity; import org.hibernate.envers.test.entities.manytomany.sametable.ParentEntity; import org.hibernate.envers.test.tools.TestTools; +import org.junit.Assert; +import org.junit.Test; + /** * Test which checks that auditing entities which contain multiple mappings to same tables work. + * * @author Adam Warski (adam at warski dot org) */ -public class BasicSametable extends BaseEnversJPAFunctionalTestCase { - private Integer p1_id; - private Integer p2_id; - private Integer c1_1_id; - private Integer c1_2_id; - private Integer c2_1_id; - private Integer c2_2_id; +public class BasicSametable extends BaseEnversJPAFunctionalTestCase { + private Integer p1_id; + private Integer p2_id; + private Integer c1_1_id; + private Integer c1_2_id; + private Integer c2_1_id; + private Integer c2_2_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { ParentEntity.class, Child1Entity.class, Child2Entity.class }; - } + return new Class[] {ParentEntity.class, Child1Entity.class, Child2Entity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - // We need first to modify the columns in the middle (join table) to allow null values. Hbm2ddl doesn't seem - // to allow this. - em.getTransaction().begin(); - Session session = (Session) em.getDelegate(); - session.createSQLQuery("DROP TABLE children").executeUpdate(); - session.createSQLQuery("CREATE TABLE children ( parent_id " + getDialect().getTypeName(Types.INTEGER) + - ", child1_id " + getDialect().getTypeName(Types.INTEGER) + " NULL" + - ", child2_id " + getDialect().getTypeName(Types.INTEGER) + " NULL )").executeUpdate(); - session.createSQLQuery("DROP TABLE children_AUD").executeUpdate(); - session.createSQLQuery("CREATE TABLE children_AUD ( REV " + getDialect().getTypeName(Types.INTEGER) + " NOT NULL" + - ", REVEND " + getDialect().getTypeName(Types.INTEGER) + - ", REVTYPE " + getDialect().getTypeName(Types.TINYINT) + - ", parent_id " + getDialect().getTypeName(Types.INTEGER) + - ", child1_id " + getDialect().getTypeName(Types.INTEGER) + " NULL" + - ", child2_id " + getDialect().getTypeName(Types.INTEGER) + " NULL )").executeUpdate(); - em.getTransaction().commit(); - em.clear(); + // We need first to modify the columns in the middle (join table) to allow null values. Hbm2ddl doesn't seem + // to allow this. + em.getTransaction().begin(); + Session session = (Session) em.getDelegate(); + session.createSQLQuery( "DROP TABLE children" ).executeUpdate(); + session.createSQLQuery( + "CREATE TABLE children ( parent_id " + getDialect().getTypeName( Types.INTEGER ) + + ", child1_id " + getDialect().getTypeName( Types.INTEGER ) + " NULL" + + ", child2_id " + getDialect().getTypeName( Types.INTEGER ) + " NULL )" + ).executeUpdate(); + session.createSQLQuery( "DROP TABLE children_AUD" ).executeUpdate(); + session.createSQLQuery( + "CREATE TABLE children_AUD ( REV " + getDialect().getTypeName( Types.INTEGER ) + " NOT NULL" + + ", REVEND " + getDialect().getTypeName( Types.INTEGER ) + + ", REVTYPE " + getDialect().getTypeName( Types.TINYINT ) + + ", parent_id " + getDialect().getTypeName( Types.INTEGER ) + + ", child1_id " + getDialect().getTypeName( Types.INTEGER ) + " NULL" + + ", child2_id " + getDialect().getTypeName( Types.INTEGER ) + " NULL )" + ).executeUpdate(); + em.getTransaction().commit(); + em.clear(); - ParentEntity p1 = new ParentEntity("parent_1"); - ParentEntity p2 = new ParentEntity("parent_2"); + ParentEntity p1 = new ParentEntity( "parent_1" ); + ParentEntity p2 = new ParentEntity( "parent_2" ); - Child1Entity c1_1 = new Child1Entity("child1_1"); - Child1Entity c1_2 = new Child1Entity("child1_2"); + Child1Entity c1_1 = new Child1Entity( "child1_1" ); + Child1Entity c1_2 = new Child1Entity( "child1_2" ); - Child2Entity c2_1 = new Child2Entity("child2_1"); - Child2Entity c2_2 = new Child2Entity("child2_2"); + Child2Entity c2_1 = new Child2Entity( "child2_1" ); + Child2Entity c2_2 = new Child2Entity( "child2_2" ); - // Revision 1 - em.getTransaction().begin(); + // Revision 1 + em.getTransaction().begin(); - em.persist(p1); - em.persist(p2); - em.persist(c1_1); - em.persist(c1_2); - em.persist(c2_1); - em.persist(c2_2); + em.persist( p1 ); + em.persist( p2 ); + em.persist( c1_1 ); + em.persist( c1_2 ); + em.persist( c2_1 ); + em.persist( c2_2 ); - em.getTransaction().commit(); - em.clear(); + em.getTransaction().commit(); + em.clear(); - // Revision 2 - (p1: c1_1, p2: c2_1) + // Revision 2 - (p1: c1_1, p2: c2_1) - em.getTransaction().begin(); + em.getTransaction().begin(); - p1 = em.find(ParentEntity.class, p1.getId()); - p2 = em.find(ParentEntity.class, p2.getId()); - c1_1 = em.find(Child1Entity.class, c1_1.getId()); - c2_1 = em.find(Child2Entity.class, c2_1.getId()); + p1 = em.find( ParentEntity.class, p1.getId() ); + p2 = em.find( ParentEntity.class, p2.getId() ); + c1_1 = em.find( Child1Entity.class, c1_1.getId() ); + c2_1 = em.find( Child2Entity.class, c2_1.getId() ); - p1.getChildren1().add(c1_1); - p2.getChildren2().add(c2_1); + p1.getChildren1().add( c1_1 ); + p2.getChildren2().add( c2_1 ); - em.getTransaction().commit(); - em.clear(); + em.getTransaction().commit(); + em.clear(); - // Revision 3 - (p1: c1_1, c1_2, c2_2, p2: c1_1, c2_1) - em.getTransaction().begin(); + // Revision 3 - (p1: c1_1, c1_2, c2_2, p2: c1_1, c2_1) + em.getTransaction().begin(); - p1 = em.find(ParentEntity.class, p1.getId()); - p2 = em.find(ParentEntity.class, p2.getId()); - c1_1 = em.find(Child1Entity.class, c1_1.getId()); - c1_2 = em.find(Child1Entity.class, c1_2.getId()); - c2_2 = em.find(Child2Entity.class, c2_2.getId()); + p1 = em.find( ParentEntity.class, p1.getId() ); + p2 = em.find( ParentEntity.class, p2.getId() ); + c1_1 = em.find( Child1Entity.class, c1_1.getId() ); + c1_2 = em.find( Child1Entity.class, c1_2.getId() ); + c2_2 = em.find( Child2Entity.class, c2_2.getId() ); - p1.getChildren1().add(c1_2); - p1.getChildren2().add(c2_2); + p1.getChildren1().add( c1_2 ); + p1.getChildren2().add( c2_2 ); - p2.getChildren1().add(c1_1); + p2.getChildren1().add( c1_1 ); - em.getTransaction().commit(); - em.clear(); + em.getTransaction().commit(); + em.clear(); - // Revision 4 - (p1: c1_2, c2_2, p2: c1_1, c2_1, c2_2) - em.getTransaction().begin(); + // Revision 4 - (p1: c1_2, c2_2, p2: c1_1, c2_1, c2_2) + em.getTransaction().begin(); - p1 = em.find(ParentEntity.class, p1.getId()); - p2 = em.find(ParentEntity.class, p2.getId()); - c1_1 = em.find(Child1Entity.class, c1_1.getId()); - c2_2 = em.find(Child2Entity.class, c2_2.getId()); + p1 = em.find( ParentEntity.class, p1.getId() ); + p2 = em.find( ParentEntity.class, p2.getId() ); + c1_1 = em.find( Child1Entity.class, c1_1.getId() ); + c2_2 = em.find( Child2Entity.class, c2_2.getId() ); - p1.getChildren1().remove(c1_1); - p2.getChildren2().add(c2_2); + p1.getChildren1().remove( c1_1 ); + p2.getChildren2().add( c2_2 ); - em.getTransaction().commit(); - em.clear(); + em.getTransaction().commit(); + em.clear(); - // Revision 5 - (p1: c2_2, p2: c1_1, c2_1) - em.getTransaction().begin(); + // Revision 5 - (p1: c2_2, p2: c1_1, c2_1) + em.getTransaction().begin(); - p1 = em.find(ParentEntity.class, p1.getId()); - p2 = em.find(ParentEntity.class, p2.getId()); - c1_2 = em.find(Child1Entity.class, c1_2.getId()); - c2_2 = em.find(Child2Entity.class, c2_2.getId()); + p1 = em.find( ParentEntity.class, p1.getId() ); + p2 = em.find( ParentEntity.class, p2.getId() ); + c1_2 = em.find( Child1Entity.class, c1_2.getId() ); + c2_2 = em.find( Child2Entity.class, c2_2.getId() ); - c2_2.getParents().remove(p2); - c1_2.getParents().remove(p1); + c2_2.getParents().remove( p2 ); + c1_2.getParents().remove( p1 ); - em.getTransaction().commit(); - em.clear(); + em.getTransaction().commit(); + em.clear(); - // + // - p1_id = p1.getId(); - p2_id = p2.getId(); - c1_1_id = c1_1.getId(); - c1_2_id = c1_2.getId(); - c2_1_id = c2_1.getId(); - c2_2_id = c2_2.getId(); - } + p1_id = p1.getId(); + p2_id = p2.getId(); + c1_1_id = c1_1.getId(); + c1_2_id = c1_2.getId(); + c2_1_id = c2_1.getId(); + c2_2_id = c2_2.getId(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2, 3, 4).equals(getAuditReader().getRevisions(ParentEntity.class, p1_id)); - assert Arrays.asList(1, 2, 3, 4).equals(getAuditReader().getRevisions(ParentEntity.class, p2_id)); + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2, 3, 4 ).equals( getAuditReader().getRevisions( ParentEntity.class, p1_id ) ); + assert Arrays.asList( 1, 2, 3, 4 ).equals( getAuditReader().getRevisions( ParentEntity.class, p2_id ) ); - assert Arrays.asList(1).equals(getAuditReader().getRevisions(Child1Entity.class, c1_1_id)); - assert Arrays.asList(1, 5).equals(getAuditReader().getRevisions(Child1Entity.class, c1_2_id)); + assert Arrays.asList( 1 ).equals( getAuditReader().getRevisions( Child1Entity.class, c1_1_id ) ); + assert Arrays.asList( 1, 5 ).equals( getAuditReader().getRevisions( Child1Entity.class, c1_2_id ) ); - Assert.assertEquals(Arrays.asList(1), getAuditReader().getRevisions(Child2Entity.class, c2_1_id)); - Assert.assertEquals(Arrays.asList(1, 5), getAuditReader().getRevisions(Child2Entity.class, c2_2_id)); - } + Assert.assertEquals( Arrays.asList( 1 ), getAuditReader().getRevisions( Child2Entity.class, c2_1_id ) ); + Assert.assertEquals( Arrays.asList( 1, 5 ), getAuditReader().getRevisions( Child2Entity.class, c2_2_id ) ); + } - @Test - public void testHistoryOfParent1() { - Child1Entity c1_1 = getEntityManager().find(Child1Entity.class, c1_1_id); - Child1Entity c1_2 = getEntityManager().find(Child1Entity.class, c1_2_id); - Child2Entity c2_2 = getEntityManager().find(Child2Entity.class, c2_2_id); + @Test + public void testHistoryOfParent1() { + Child1Entity c1_1 = getEntityManager().find( Child1Entity.class, c1_1_id ); + Child1Entity c1_2 = getEntityManager().find( Child1Entity.class, c1_2_id ); + Child2Entity c2_2 = getEntityManager().find( Child2Entity.class, c2_2_id ); - ParentEntity rev1 = getAuditReader().find(ParentEntity.class, p1_id, 1); - ParentEntity rev2 = getAuditReader().find(ParentEntity.class, p1_id, 2); - ParentEntity rev3 = getAuditReader().find(ParentEntity.class, p1_id, 3); - ParentEntity rev4 = getAuditReader().find(ParentEntity.class, p1_id, 4); - ParentEntity rev5 = getAuditReader().find(ParentEntity.class, p1_id, 5); + ParentEntity rev1 = getAuditReader().find( ParentEntity.class, p1_id, 1 ); + ParentEntity rev2 = getAuditReader().find( ParentEntity.class, p1_id, 2 ); + ParentEntity rev3 = getAuditReader().find( ParentEntity.class, p1_id, 3 ); + ParentEntity rev4 = getAuditReader().find( ParentEntity.class, p1_id, 4 ); + ParentEntity rev5 = getAuditReader().find( ParentEntity.class, p1_id, 5 ); - assert TestTools.checkList(rev1.getChildren1()); - assert TestTools.checkList(rev2.getChildren1(), c1_1); - assert TestTools.checkList(rev3.getChildren1(), c1_1, c1_2); - assert TestTools.checkList(rev4.getChildren1(), c1_2); - assert TestTools.checkList(rev5.getChildren1()); + assert TestTools.checkList( rev1.getChildren1() ); + assert TestTools.checkList( rev2.getChildren1(), c1_1 ); + assert TestTools.checkList( rev3.getChildren1(), c1_1, c1_2 ); + assert TestTools.checkList( rev4.getChildren1(), c1_2 ); + assert TestTools.checkList( rev5.getChildren1() ); - assert TestTools.checkList(rev1.getChildren2()); - assert TestTools.checkList(rev2.getChildren2()); - assert TestTools.checkList(rev3.getChildren2(), c2_2); - assert TestTools.checkList(rev4.getChildren2(), c2_2); - assert TestTools.checkList(rev5.getChildren2(), c2_2); - } + assert TestTools.checkList( rev1.getChildren2() ); + assert TestTools.checkList( rev2.getChildren2() ); + assert TestTools.checkList( rev3.getChildren2(), c2_2 ); + assert TestTools.checkList( rev4.getChildren2(), c2_2 ); + assert TestTools.checkList( rev5.getChildren2(), c2_2 ); + } - @Test - public void testHistoryOfParent2() { - Child1Entity c1_1 = getEntityManager().find(Child1Entity.class, c1_1_id); - Child2Entity c2_1 = getEntityManager().find(Child2Entity.class, c2_1_id); - Child2Entity c2_2 = getEntityManager().find(Child2Entity.class, c2_2_id); + @Test + public void testHistoryOfParent2() { + Child1Entity c1_1 = getEntityManager().find( Child1Entity.class, c1_1_id ); + Child2Entity c2_1 = getEntityManager().find( Child2Entity.class, c2_1_id ); + Child2Entity c2_2 = getEntityManager().find( Child2Entity.class, c2_2_id ); - ParentEntity rev1 = getAuditReader().find(ParentEntity.class, p2_id, 1); - ParentEntity rev2 = getAuditReader().find(ParentEntity.class, p2_id, 2); - ParentEntity rev3 = getAuditReader().find(ParentEntity.class, p2_id, 3); - ParentEntity rev4 = getAuditReader().find(ParentEntity.class, p2_id, 4); - ParentEntity rev5 = getAuditReader().find(ParentEntity.class, p2_id, 5); + ParentEntity rev1 = getAuditReader().find( ParentEntity.class, p2_id, 1 ); + ParentEntity rev2 = getAuditReader().find( ParentEntity.class, p2_id, 2 ); + ParentEntity rev3 = getAuditReader().find( ParentEntity.class, p2_id, 3 ); + ParentEntity rev4 = getAuditReader().find( ParentEntity.class, p2_id, 4 ); + ParentEntity rev5 = getAuditReader().find( ParentEntity.class, p2_id, 5 ); - assert TestTools.checkList(rev1.getChildren1()); - assert TestTools.checkList(rev2.getChildren1()); - assert TestTools.checkList(rev3.getChildren1(), c1_1); - assert TestTools.checkList(rev4.getChildren1(), c1_1); - assert TestTools.checkList(rev5.getChildren1(), c1_1); + assert TestTools.checkList( rev1.getChildren1() ); + assert TestTools.checkList( rev2.getChildren1() ); + assert TestTools.checkList( rev3.getChildren1(), c1_1 ); + assert TestTools.checkList( rev4.getChildren1(), c1_1 ); + assert TestTools.checkList( rev5.getChildren1(), c1_1 ); - assert TestTools.checkList(rev1.getChildren2()); - assert TestTools.checkList(rev2.getChildren2(), c2_1); - assert TestTools.checkList(rev3.getChildren2(), c2_1); - assert TestTools.checkList(rev4.getChildren2(), c2_1, c2_2); - assert TestTools.checkList(rev5.getChildren2(), c2_1); - } + assert TestTools.checkList( rev1.getChildren2() ); + assert TestTools.checkList( rev2.getChildren2(), c2_1 ); + assert TestTools.checkList( rev3.getChildren2(), c2_1 ); + assert TestTools.checkList( rev4.getChildren2(), c2_1, c2_2 ); + assert TestTools.checkList( rev5.getChildren2(), c2_1 ); + } - @Test - public void testHistoryOfChild1_1() { - ParentEntity p1 = getEntityManager().find(ParentEntity.class, p1_id); - ParentEntity p2 = getEntityManager().find(ParentEntity.class, p2_id); + @Test + public void testHistoryOfChild1_1() { + ParentEntity p1 = getEntityManager().find( ParentEntity.class, p1_id ); + ParentEntity p2 = getEntityManager().find( ParentEntity.class, p2_id ); - Child1Entity rev1 = getAuditReader().find(Child1Entity.class, c1_1_id, 1); - Child1Entity rev2 = getAuditReader().find(Child1Entity.class, c1_1_id, 2); - Child1Entity rev3 = getAuditReader().find(Child1Entity.class, c1_1_id, 3); - Child1Entity rev4 = getAuditReader().find(Child1Entity.class, c1_1_id, 4); - Child1Entity rev5 = getAuditReader().find(Child1Entity.class, c1_1_id, 5); + Child1Entity rev1 = getAuditReader().find( Child1Entity.class, c1_1_id, 1 ); + Child1Entity rev2 = getAuditReader().find( Child1Entity.class, c1_1_id, 2 ); + Child1Entity rev3 = getAuditReader().find( Child1Entity.class, c1_1_id, 3 ); + Child1Entity rev4 = getAuditReader().find( Child1Entity.class, c1_1_id, 4 ); + Child1Entity rev5 = getAuditReader().find( Child1Entity.class, c1_1_id, 5 ); - assert TestTools.checkList(rev1.getParents()); - assert TestTools.checkList(rev2.getParents(), p1); - assert TestTools.checkList(rev3.getParents(), p1, p2); - assert TestTools.checkList(rev4.getParents(), p2); - assert TestTools.checkList(rev5.getParents(), p2); - } + assert TestTools.checkList( rev1.getParents() ); + assert TestTools.checkList( rev2.getParents(), p1 ); + assert TestTools.checkList( rev3.getParents(), p1, p2 ); + assert TestTools.checkList( rev4.getParents(), p2 ); + assert TestTools.checkList( rev5.getParents(), p2 ); + } - // TODO: was disabled? - @Test - public void testHistoryOfChild1_2() { - ParentEntity p1 = getEntityManager().find(ParentEntity.class, p1_id); + // TODO: was disabled? + @Test + public void testHistoryOfChild1_2() { + ParentEntity p1 = getEntityManager().find( ParentEntity.class, p1_id ); - Child1Entity rev1 = getAuditReader().find(Child1Entity.class, c1_2_id, 1); - Child1Entity rev2 = getAuditReader().find(Child1Entity.class, c1_2_id, 2); - Child1Entity rev3 = getAuditReader().find(Child1Entity.class, c1_2_id, 3); - Child1Entity rev4 = getAuditReader().find(Child1Entity.class, c1_2_id, 4); - Child1Entity rev5 = getAuditReader().find(Child1Entity.class, c1_2_id, 5); + Child1Entity rev1 = getAuditReader().find( Child1Entity.class, c1_2_id, 1 ); + Child1Entity rev2 = getAuditReader().find( Child1Entity.class, c1_2_id, 2 ); + Child1Entity rev3 = getAuditReader().find( Child1Entity.class, c1_2_id, 3 ); + Child1Entity rev4 = getAuditReader().find( Child1Entity.class, c1_2_id, 4 ); + Child1Entity rev5 = getAuditReader().find( Child1Entity.class, c1_2_id, 5 ); - assert TestTools.checkList(rev1.getParents()); - assert TestTools.checkList(rev2.getParents()); - assert TestTools.checkList(rev3.getParents(), p1); - assert TestTools.checkList(rev4.getParents(), p1); - assert TestTools.checkList(rev5.getParents()); - } + assert TestTools.checkList( rev1.getParents() ); + assert TestTools.checkList( rev2.getParents() ); + assert TestTools.checkList( rev3.getParents(), p1 ); + assert TestTools.checkList( rev4.getParents(), p1 ); + assert TestTools.checkList( rev5.getParents() ); + } - @Test - public void testHistoryOfChild2_1() { - ParentEntity p2 = getEntityManager().find(ParentEntity.class, p2_id); + @Test + public void testHistoryOfChild2_1() { + ParentEntity p2 = getEntityManager().find( ParentEntity.class, p2_id ); - Child2Entity rev1 = getAuditReader().find(Child2Entity.class, c2_1_id, 1); - Child2Entity rev2 = getAuditReader().find(Child2Entity.class, c2_1_id, 2); - Child2Entity rev3 = getAuditReader().find(Child2Entity.class, c2_1_id, 3); - Child2Entity rev4 = getAuditReader().find(Child2Entity.class, c2_1_id, 4); - Child2Entity rev5 = getAuditReader().find(Child2Entity.class, c2_1_id, 5); + Child2Entity rev1 = getAuditReader().find( Child2Entity.class, c2_1_id, 1 ); + Child2Entity rev2 = getAuditReader().find( Child2Entity.class, c2_1_id, 2 ); + Child2Entity rev3 = getAuditReader().find( Child2Entity.class, c2_1_id, 3 ); + Child2Entity rev4 = getAuditReader().find( Child2Entity.class, c2_1_id, 4 ); + Child2Entity rev5 = getAuditReader().find( Child2Entity.class, c2_1_id, 5 ); - assert TestTools.checkList(rev1.getParents()); - assert TestTools.checkList(rev2.getParents(), p2); - assert TestTools.checkList(rev3.getParents(), p2); - assert TestTools.checkList(rev4.getParents(), p2); - assert TestTools.checkList(rev5.getParents(), p2); - } + assert TestTools.checkList( rev1.getParents() ); + assert TestTools.checkList( rev2.getParents(), p2 ); + assert TestTools.checkList( rev3.getParents(), p2 ); + assert TestTools.checkList( rev4.getParents(), p2 ); + assert TestTools.checkList( rev5.getParents(), p2 ); + } - @Test - public void testHistoryOfChild2_2() { - ParentEntity p1 = getEntityManager().find(ParentEntity.class, p1_id); - ParentEntity p2 = getEntityManager().find(ParentEntity.class, p2_id); + @Test + public void testHistoryOfChild2_2() { + ParentEntity p1 = getEntityManager().find( ParentEntity.class, p1_id ); + ParentEntity p2 = getEntityManager().find( ParentEntity.class, p2_id ); - Child2Entity rev1 = getAuditReader().find(Child2Entity.class, c2_2_id, 1); - Child2Entity rev2 = getAuditReader().find(Child2Entity.class, c2_2_id, 2); - Child2Entity rev3 = getAuditReader().find(Child2Entity.class, c2_2_id, 3); - Child2Entity rev4 = getAuditReader().find(Child2Entity.class, c2_2_id, 4); - Child2Entity rev5 = getAuditReader().find(Child2Entity.class, c2_2_id, 5); + Child2Entity rev1 = getAuditReader().find( Child2Entity.class, c2_2_id, 1 ); + Child2Entity rev2 = getAuditReader().find( Child2Entity.class, c2_2_id, 2 ); + Child2Entity rev3 = getAuditReader().find( Child2Entity.class, c2_2_id, 3 ); + Child2Entity rev4 = getAuditReader().find( Child2Entity.class, c2_2_id, 4 ); + Child2Entity rev5 = getAuditReader().find( Child2Entity.class, c2_2_id, 5 ); - assert TestTools.checkList(rev1.getParents()); - assert TestTools.checkList(rev2.getParents()); - assert TestTools.checkList(rev3.getParents(), p1); - assert TestTools.checkList(rev4.getParents(), p1, p2); - assert TestTools.checkList(rev5.getParents(), p1); - } + assert TestTools.checkList( rev1.getParents() ); + assert TestTools.checkList( rev2.getParents() ); + assert TestTools.checkList( rev3.getParents(), p1 ); + assert TestTools.checkList( rev4.getParents(), p1, p2 ); + assert TestTools.checkList( rev5.getParents(), p1 ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/ternary/TernaryMap.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/ternary/TernaryMap.java index 4fcb435dfb..f527070643 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/ternary/TernaryMap.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/ternary/TernaryMap.java @@ -23,11 +23,8 @@ */ package org.hibernate.envers.test.integration.manytomany.ternary; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Assert; -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; @@ -35,166 +32,169 @@ import org.hibernate.envers.test.entities.IntTestPrivSeqEntity; import org.hibernate.envers.test.entities.StrTestPrivSeqEntity; import org.hibernate.envers.test.tools.TestTools; +import org.junit.Assert; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class TernaryMap extends BaseEnversJPAFunctionalTestCase { - private Integer str1_id; - private Integer str2_id; + private Integer str1_id; + private Integer str2_id; - private Integer int1_id; - private Integer int2_id; + private Integer int1_id; + private Integer int2_id; - private Integer map1_id; - private Integer map2_id; + private Integer map1_id; + private Integer map2_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { TernaryMapEntity.class, StrTestPrivSeqEntity.class, IntTestPrivSeqEntity.class }; - } + return new Class[] {TernaryMapEntity.class, StrTestPrivSeqEntity.class, IntTestPrivSeqEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - StrTestPrivSeqEntity str1 = new StrTestPrivSeqEntity("a"); - StrTestPrivSeqEntity str2 = new StrTestPrivSeqEntity("b"); + StrTestPrivSeqEntity str1 = new StrTestPrivSeqEntity( "a" ); + StrTestPrivSeqEntity str2 = new StrTestPrivSeqEntity( "b" ); - IntTestPrivSeqEntity int1 = new IntTestPrivSeqEntity(1); - IntTestPrivSeqEntity int2 = new IntTestPrivSeqEntity(2); + IntTestPrivSeqEntity int1 = new IntTestPrivSeqEntity( 1 ); + IntTestPrivSeqEntity int2 = new IntTestPrivSeqEntity( 2 ); - TernaryMapEntity map1 = new TernaryMapEntity(); - TernaryMapEntity map2 = new TernaryMapEntity(); + TernaryMapEntity map1 = new TernaryMapEntity(); + TernaryMapEntity map2 = new TernaryMapEntity(); - // Revision 1 (map1: initialy one mapping int1 -> str1, map2: empty) - em.getTransaction().begin(); + // Revision 1 (map1: initialy one mapping int1 -> str1, map2: empty) + em.getTransaction().begin(); - em.persist(str1); - em.persist(str2); - em.persist(int1); - em.persist(int2); + em.persist( str1 ); + em.persist( str2 ); + em.persist( int1 ); + em.persist( int2 ); - map1.getMap().put(int1, str1); + map1.getMap().put( int1, str1 ); - em.persist(map1); - em.persist(map2); + em.persist( map1 ); + em.persist( map2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 (map1: replacing the mapping, map2: adding two mappings) + // Revision 2 (map1: replacing the mapping, map2: adding two mappings) - em.getTransaction().begin(); + em.getTransaction().begin(); - map1 = em.find(TernaryMapEntity.class, map1.getId()); - map2 = em.find(TernaryMapEntity.class, map2.getId()); + map1 = em.find( TernaryMapEntity.class, map1.getId() ); + map2 = em.find( TernaryMapEntity.class, map2.getId() ); - str1 = em.find(StrTestPrivSeqEntity.class, str1.getId()); - str2 = em.find(StrTestPrivSeqEntity.class, str2.getId()); + str1 = em.find( StrTestPrivSeqEntity.class, str1.getId() ); + str2 = em.find( StrTestPrivSeqEntity.class, str2.getId() ); - int1 = em.find(IntTestPrivSeqEntity.class, int1.getId()); - int2 = em.find(IntTestPrivSeqEntity.class, int2.getId()); + int1 = em.find( IntTestPrivSeqEntity.class, int1.getId() ); + int2 = em.find( IntTestPrivSeqEntity.class, int2.getId() ); - map1.getMap().put(int1, str2); + map1.getMap().put( int1, str2 ); - map2.getMap().put(int1, str1); - map2.getMap().put(int2, str1); + map2.getMap().put( int1, str1 ); + map2.getMap().put( int2, str1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 (map1: removing a non-existing mapping, adding an existing mapping - no changes, map2: removing a mapping) - em.getTransaction().begin(); + // Revision 3 (map1: removing a non-existing mapping, adding an existing mapping - no changes, map2: removing a mapping) + em.getTransaction().begin(); - map1 = em.find(TernaryMapEntity.class, map1.getId()); - map2 = em.find(TernaryMapEntity.class, map2.getId()); + map1 = em.find( TernaryMapEntity.class, map1.getId() ); + map2 = em.find( TernaryMapEntity.class, map2.getId() ); - str2 = em.find(StrTestPrivSeqEntity.class, str2.getId()); + str2 = em.find( StrTestPrivSeqEntity.class, str2.getId() ); - int1 = em.find(IntTestPrivSeqEntity.class, int1.getId()); - int2 = em.find(IntTestPrivSeqEntity.class, int2.getId()); + int1 = em.find( IntTestPrivSeqEntity.class, int1.getId() ); + int2 = em.find( IntTestPrivSeqEntity.class, int2.getId() ); - map1.getMap().remove(int2); - map1.getMap().put(int1, str2); + map1.getMap().remove( int2 ); + map1.getMap().put( int1, str2 ); - map2.getMap().remove(int1); + map2.getMap().remove( int1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 4 (map1: adding a mapping, map2: adding a mapping) - em.getTransaction().begin(); + // Revision 4 (map1: adding a mapping, map2: adding a mapping) + em.getTransaction().begin(); - map1 = em.find(TernaryMapEntity.class, map1.getId()); - map2 = em.find(TernaryMapEntity.class, map2.getId()); + map1 = em.find( TernaryMapEntity.class, map1.getId() ); + map2 = em.find( TernaryMapEntity.class, map2.getId() ); - str2 = em.find(StrTestPrivSeqEntity.class, str2.getId()); + str2 = em.find( StrTestPrivSeqEntity.class, str2.getId() ); - int1 = em.find(IntTestPrivSeqEntity.class, int1.getId()); - int2 = em.find(IntTestPrivSeqEntity.class, int2.getId()); + int1 = em.find( IntTestPrivSeqEntity.class, int1.getId() ); + int2 = em.find( IntTestPrivSeqEntity.class, int2.getId() ); - map1.getMap().put(int2, str2); + map1.getMap().put( int2, str2 ); - map2.getMap().put(int1, str2); + map2.getMap().put( int1, str2 ); - em.getTransaction().commit(); - // + em.getTransaction().commit(); + // - map1_id = map1.getId(); - map2_id = map2.getId(); + map1_id = map1.getId(); + map2_id = map2.getId(); - str1_id = str1.getId(); - str2_id = str2.getId(); + str1_id = str1.getId(); + str2_id = str2.getId(); - int1_id = int1.getId(); - int2_id = int2.getId(); - } + int1_id = int1.getId(); + int2_id = int2.getId(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2, 4).equals(getAuditReader().getRevisions(TernaryMapEntity.class, map1_id)); - assert Arrays.asList(1, 2, 3, 4).equals(getAuditReader().getRevisions(TernaryMapEntity.class, map2_id)); + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2, 4 ).equals( getAuditReader().getRevisions( TernaryMapEntity.class, map1_id ) ); + assert Arrays.asList( 1, 2, 3, 4 ).equals( getAuditReader().getRevisions( TernaryMapEntity.class, map2_id ) ); - assert Arrays.asList(1).equals(getAuditReader().getRevisions(StrTestPrivSeqEntity.class, str1_id)); - assert Arrays.asList(1).equals(getAuditReader().getRevisions(StrTestPrivSeqEntity.class, str2_id)); + assert Arrays.asList( 1 ).equals( getAuditReader().getRevisions( StrTestPrivSeqEntity.class, str1_id ) ); + assert Arrays.asList( 1 ).equals( getAuditReader().getRevisions( StrTestPrivSeqEntity.class, str2_id ) ); - assert Arrays.asList(1).equals(getAuditReader().getRevisions(IntTestPrivSeqEntity.class, int1_id)); - assert Arrays.asList(1).equals(getAuditReader().getRevisions(IntTestPrivSeqEntity.class, int2_id)); - } + assert Arrays.asList( 1 ).equals( getAuditReader().getRevisions( IntTestPrivSeqEntity.class, int1_id ) ); + assert Arrays.asList( 1 ).equals( getAuditReader().getRevisions( IntTestPrivSeqEntity.class, int2_id ) ); + } - @Test - public void testHistoryOfMap1() { - StrTestPrivSeqEntity str1 = getEntityManager().find(StrTestPrivSeqEntity.class, str1_id); - StrTestPrivSeqEntity str2 = getEntityManager().find(StrTestPrivSeqEntity.class, str2_id); + @Test + public void testHistoryOfMap1() { + StrTestPrivSeqEntity str1 = getEntityManager().find( StrTestPrivSeqEntity.class, str1_id ); + StrTestPrivSeqEntity str2 = getEntityManager().find( StrTestPrivSeqEntity.class, str2_id ); - IntTestPrivSeqEntity int1 = getEntityManager().find(IntTestPrivSeqEntity.class, int1_id); - IntTestPrivSeqEntity int2 = getEntityManager().find(IntTestPrivSeqEntity.class, int2_id); + IntTestPrivSeqEntity int1 = getEntityManager().find( IntTestPrivSeqEntity.class, int1_id ); + IntTestPrivSeqEntity int2 = getEntityManager().find( IntTestPrivSeqEntity.class, int2_id ); - TernaryMapEntity rev1 = getAuditReader().find(TernaryMapEntity.class, map1_id, 1); - TernaryMapEntity rev2 = getAuditReader().find(TernaryMapEntity.class, map1_id, 2); - TernaryMapEntity rev3 = getAuditReader().find(TernaryMapEntity.class, map1_id, 3); - TernaryMapEntity rev4 = getAuditReader().find(TernaryMapEntity.class, map1_id, 4); + TernaryMapEntity rev1 = getAuditReader().find( TernaryMapEntity.class, map1_id, 1 ); + TernaryMapEntity rev2 = getAuditReader().find( TernaryMapEntity.class, map1_id, 2 ); + TernaryMapEntity rev3 = getAuditReader().find( TernaryMapEntity.class, map1_id, 3 ); + TernaryMapEntity rev4 = getAuditReader().find( TernaryMapEntity.class, map1_id, 4 ); - Assert.assertEquals(TestTools.makeMap(int1, str1), rev1.getMap()); - Assert.assertEquals(TestTools.makeMap(int1, str2), rev2.getMap()); - Assert.assertEquals(TestTools.makeMap(int1, str2), rev3.getMap()); - Assert.assertEquals(TestTools.makeMap(int1, str2, int2, str2), rev4.getMap()); - } + Assert.assertEquals( TestTools.makeMap( int1, str1 ), rev1.getMap() ); + Assert.assertEquals( TestTools.makeMap( int1, str2 ), rev2.getMap() ); + Assert.assertEquals( TestTools.makeMap( int1, str2 ), rev3.getMap() ); + Assert.assertEquals( TestTools.makeMap( int1, str2, int2, str2 ), rev4.getMap() ); + } - @Test - public void testHistoryOfMap2() { - StrTestPrivSeqEntity str1 = getEntityManager().find(StrTestPrivSeqEntity.class, str1_id); - StrTestPrivSeqEntity str2 = getEntityManager().find(StrTestPrivSeqEntity.class, str2_id); + @Test + public void testHistoryOfMap2() { + StrTestPrivSeqEntity str1 = getEntityManager().find( StrTestPrivSeqEntity.class, str1_id ); + StrTestPrivSeqEntity str2 = getEntityManager().find( StrTestPrivSeqEntity.class, str2_id ); - IntTestPrivSeqEntity int1 = getEntityManager().find(IntTestPrivSeqEntity.class, int1_id); - IntTestPrivSeqEntity int2 = getEntityManager().find(IntTestPrivSeqEntity.class, int2_id); + IntTestPrivSeqEntity int1 = getEntityManager().find( IntTestPrivSeqEntity.class, int1_id ); + IntTestPrivSeqEntity int2 = getEntityManager().find( IntTestPrivSeqEntity.class, int2_id ); - TernaryMapEntity rev1 = getAuditReader().find(TernaryMapEntity.class, map2_id, 1); - TernaryMapEntity rev2 = getAuditReader().find(TernaryMapEntity.class, map2_id, 2); - TernaryMapEntity rev3 = getAuditReader().find(TernaryMapEntity.class, map2_id, 3); - TernaryMapEntity rev4 = getAuditReader().find(TernaryMapEntity.class, map2_id, 4); + TernaryMapEntity rev1 = getAuditReader().find( TernaryMapEntity.class, map2_id, 1 ); + TernaryMapEntity rev2 = getAuditReader().find( TernaryMapEntity.class, map2_id, 2 ); + TernaryMapEntity rev3 = getAuditReader().find( TernaryMapEntity.class, map2_id, 3 ); + TernaryMapEntity rev4 = getAuditReader().find( TernaryMapEntity.class, map2_id, 4 ); - assert rev1.getMap().equals(TestTools.makeMap()); - assert rev2.getMap().equals(TestTools.makeMap(int1, str1, int2, str1)); - assert rev3.getMap().equals(TestTools.makeMap(int2, str1)); - assert rev4.getMap().equals(TestTools.makeMap(int1, str2, int2, str1)); - } + assert rev1.getMap().equals( TestTools.makeMap() ); + assert rev2.getMap().equals( TestTools.makeMap( int1, str1, int2, str1 ) ); + assert rev3.getMap().equals( TestTools.makeMap( int2, str1 ) ); + assert rev4.getMap().equals( TestTools.makeMap( int1, str2, int2, str1 ) ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/ternary/TernaryMapEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/ternary/TernaryMapEntity.java index 24a7789b5d..3313be249a 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/ternary/TernaryMapEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/ternary/TernaryMapEntity.java @@ -22,12 +22,13 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.manytomany.ternary; -import java.util.HashMap; -import java.util.Map; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.ManyToMany; +import java.util.HashMap; +import java.util.Map; import org.hibernate.envers.Audited; import org.hibernate.envers.test.entities.IntTestPrivSeqEntity; @@ -38,51 +39,57 @@ import org.hibernate.envers.test.entities.StrTestPrivSeqEntity; */ @Entity public class TernaryMapEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - @Audited - @ManyToMany - @javax.persistence.MapKeyJoinColumn - private Map map; + @Audited + @ManyToMany + @javax.persistence.MapKeyJoinColumn + private Map map; - public TernaryMapEntity() { - map = new HashMap(); - } + public TernaryMapEntity() { + map = new HashMap(); + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public Map getMap() { - return map; - } + public Map getMap() { + return map; + } - public void setMap(Map map) { - this.map = map; - } + public void setMap(Map map) { + this.map = map; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof TernaryMapEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof TernaryMapEntity) ) { + return false; + } - TernaryMapEntity that = (TernaryMapEntity) o; + TernaryMapEntity that = (TernaryMapEntity) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - return (id != null ? id.hashCode() : 0); - } + public int hashCode() { + return (id != null ? id.hashCode() : 0); + } - public String toString() { - return "TME(id = " + id + ", map = " + map + ")"; - } + public String toString() { + return "TME(id = " + id + ", map = " + map + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/ternary/TernaryMapFlush.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/ternary/TernaryMapFlush.java index 0a7fb128c2..e072ec36b7 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/ternary/TernaryMapFlush.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/ternary/TernaryMapFlush.java @@ -23,11 +23,9 @@ */ package org.hibernate.envers.test.integration.manytomany.ternary; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.HashMap; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; @@ -35,112 +33,114 @@ import org.hibernate.envers.test.entities.IntTestPrivSeqEntity; import org.hibernate.envers.test.entities.StrTestPrivSeqEntity; import org.hibernate.envers.test.tools.TestTools; +import org.junit.Test; + import static org.junit.Assert.assertEquals; /** * @author Adam Warski (adam at warski dot org) */ public class TernaryMapFlush extends BaseEnversJPAFunctionalTestCase { - private Integer str1_id; - private Integer str2_id; - private Integer int1_id; - private Integer int2_id; - private Integer map1_id; + private Integer str1_id; + private Integer str2_id; + private Integer int1_id; + private Integer int2_id; + private Integer map1_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { TernaryMapEntity.class, StrTestPrivSeqEntity.class, IntTestPrivSeqEntity.class }; - } + return new Class[] {TernaryMapEntity.class, StrTestPrivSeqEntity.class, IntTestPrivSeqEntity.class}; + } - @Test - @Priority(10) - public void createData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void createData() { + EntityManager em = getEntityManager(); - StrTestPrivSeqEntity str1 = new StrTestPrivSeqEntity("a"); - StrTestPrivSeqEntity str2 = new StrTestPrivSeqEntity("b"); - IntTestPrivSeqEntity int1 = new IntTestPrivSeqEntity(1); - IntTestPrivSeqEntity int2 = new IntTestPrivSeqEntity(2); - TernaryMapEntity map1 = new TernaryMapEntity(); + StrTestPrivSeqEntity str1 = new StrTestPrivSeqEntity( "a" ); + StrTestPrivSeqEntity str2 = new StrTestPrivSeqEntity( "b" ); + IntTestPrivSeqEntity int1 = new IntTestPrivSeqEntity( 1 ); + IntTestPrivSeqEntity int2 = new IntTestPrivSeqEntity( 2 ); + TernaryMapEntity map1 = new TernaryMapEntity(); - // Revision 1 (int1 -> str1) - em.getTransaction().begin(); + // Revision 1 (int1 -> str1) + em.getTransaction().begin(); - em.persist(str1); - em.persist(str2); - em.persist(int1); - em.persist(int2); + em.persist( str1 ); + em.persist( str2 ); + em.persist( int1 ); + em.persist( int2 ); - map1.getMap().put(int1, str1); + map1.getMap().put( int1, str1 ); - em.persist(map1); + em.persist( map1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 (removing int1->str1, flushing, adding int1->str1 again and a new int2->str2 mapping to force a change) + // Revision 2 (removing int1->str1, flushing, adding int1->str1 again and a new int2->str2 mapping to force a change) - em.getTransaction().begin(); + em.getTransaction().begin(); - map1 = em.find(TernaryMapEntity.class, map1.getId()); - str1 = em.find(StrTestPrivSeqEntity.class, str1.getId()); - int1 = em.find(IntTestPrivSeqEntity.class, int1.getId()); + map1 = em.find( TernaryMapEntity.class, map1.getId() ); + str1 = em.find( StrTestPrivSeqEntity.class, str1.getId() ); + int1 = em.find( IntTestPrivSeqEntity.class, int1.getId() ); - map1.setMap(new HashMap()); - - em.flush(); + map1.setMap( new HashMap() ); - map1.getMap().put(int1, str1); - map1.getMap().put(int2, str2); + em.flush(); - em.getTransaction().commit(); + map1.getMap().put( int1, str1 ); + map1.getMap().put( int2, str2 ); - // Revision 3 (removing int1->str1, flushing, overwriting int2->str1) + em.getTransaction().commit(); - em.getTransaction().begin(); + // Revision 3 (removing int1->str1, flushing, overwriting int2->str1) - map1 = em.find(TernaryMapEntity.class, map1.getId()); - str1 = em.find(StrTestPrivSeqEntity.class, str1.getId()); - int1 = em.find(IntTestPrivSeqEntity.class, int1.getId()); + em.getTransaction().begin(); - map1.getMap().remove(int1); + map1 = em.find( TernaryMapEntity.class, map1.getId() ); + str1 = em.find( StrTestPrivSeqEntity.class, str1.getId() ); + int1 = em.find( IntTestPrivSeqEntity.class, int1.getId() ); - em.flush(); + map1.getMap().remove( int1 ); - map1.getMap().put(int2, str1); + em.flush(); - em.getTransaction().commit(); + map1.getMap().put( int2, str1 ); - // + em.getTransaction().commit(); - map1_id = map1.getId(); - str1_id = str1.getId(); - str2_id = str2.getId(); - int1_id = int1.getId(); - int2_id = int2.getId(); - } + // - @Test - public void testRevisionsCounts() { - assertEquals(Arrays.asList(1, 2, 3), getAuditReader().getRevisions(TernaryMapEntity.class, map1_id)); - assertEquals(Arrays.asList(1), getAuditReader().getRevisions(StrTestPrivSeqEntity.class, str1_id)); - assertEquals(Arrays.asList(1), getAuditReader().getRevisions(StrTestPrivSeqEntity.class, str2_id)); - assertEquals(Arrays.asList(1) ,getAuditReader().getRevisions(IntTestPrivSeqEntity.class, int1_id)); - assertEquals(Arrays.asList(1) ,getAuditReader().getRevisions(IntTestPrivSeqEntity.class, int2_id)); - } + map1_id = map1.getId(); + str1_id = str1.getId(); + str2_id = str2.getId(); + int1_id = int1.getId(); + int2_id = int2.getId(); + } - @Test - public void testHistoryOfMap1() { - StrTestPrivSeqEntity str1 = getEntityManager().find(StrTestPrivSeqEntity.class, str1_id); - StrTestPrivSeqEntity str2 = getEntityManager().find(StrTestPrivSeqEntity.class, str2_id); - IntTestPrivSeqEntity int1 = getEntityManager().find(IntTestPrivSeqEntity.class, int1_id); - IntTestPrivSeqEntity int2 = getEntityManager().find(IntTestPrivSeqEntity.class, int2_id); + @Test + public void testRevisionsCounts() { + assertEquals( Arrays.asList( 1, 2, 3 ), getAuditReader().getRevisions( TernaryMapEntity.class, map1_id ) ); + assertEquals( Arrays.asList( 1 ), getAuditReader().getRevisions( StrTestPrivSeqEntity.class, str1_id ) ); + assertEquals( Arrays.asList( 1 ), getAuditReader().getRevisions( StrTestPrivSeqEntity.class, str2_id ) ); + assertEquals( Arrays.asList( 1 ), getAuditReader().getRevisions( IntTestPrivSeqEntity.class, int1_id ) ); + assertEquals( Arrays.asList( 1 ), getAuditReader().getRevisions( IntTestPrivSeqEntity.class, int2_id ) ); + } - TernaryMapEntity rev1 = getAuditReader().find(TernaryMapEntity.class, map1_id, 1); - TernaryMapEntity rev2 = getAuditReader().find(TernaryMapEntity.class, map1_id, 2); - TernaryMapEntity rev3 = getAuditReader().find(TernaryMapEntity.class, map1_id, 3); + @Test + public void testHistoryOfMap1() { + StrTestPrivSeqEntity str1 = getEntityManager().find( StrTestPrivSeqEntity.class, str1_id ); + StrTestPrivSeqEntity str2 = getEntityManager().find( StrTestPrivSeqEntity.class, str2_id ); + IntTestPrivSeqEntity int1 = getEntityManager().find( IntTestPrivSeqEntity.class, int1_id ); + IntTestPrivSeqEntity int2 = getEntityManager().find( IntTestPrivSeqEntity.class, int2_id ); - assertEquals(rev1.getMap(), TestTools.makeMap(int1, str1)); - assertEquals(rev2.getMap(), TestTools.makeMap(int1, str1, int2, str2)); - assertEquals(rev3.getMap(), TestTools.makeMap(int2, str1)); - } + TernaryMapEntity rev1 = getAuditReader().find( TernaryMapEntity.class, map1_id, 1 ); + TernaryMapEntity rev2 = getAuditReader().find( TernaryMapEntity.class, map1_id, 2 ); + TernaryMapEntity rev3 = getAuditReader().find( TernaryMapEntity.class, map1_id, 3 ); + + assertEquals( rev1.getMap(), TestTools.makeMap( int1, str1 ) ); + assertEquals( rev2.getMap(), TestTools.makeMap( int1, str1, int2, str2 ) ); + assertEquals( rev3.getMap(), TestTools.makeMap( int2, str1 ) ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/unidirectional/BasicUniList.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/unidirectional/BasicUniList.java index 31971c684f..04654084bc 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/unidirectional/BasicUniList.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/unidirectional/BasicUniList.java @@ -23,12 +23,10 @@ */ package org.hibernate.envers.test.integration.manytomany.unidirectional; +import javax.persistence.EntityManager; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; @@ -36,142 +34,144 @@ import org.hibernate.envers.test.entities.StrTestEntity; import org.hibernate.envers.test.entities.manytomany.unidirectional.ListUniEntity; import org.hibernate.envers.test.tools.TestTools; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class BasicUniList extends BaseEnversJPAFunctionalTestCase { - private Integer ed1_id; - private Integer ed2_id; + private Integer ed1_id; + private Integer ed2_id; - private Integer ing1_id; - private Integer ing2_id; + private Integer ing1_id; + private Integer ing2_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { ListUniEntity.class, StrTestEntity.class }; - } + return new Class[] {ListUniEntity.class, StrTestEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - StrTestEntity ed1 = new StrTestEntity("data_ed_1"); - StrTestEntity ed2 = new StrTestEntity("data_ed_2"); + StrTestEntity ed1 = new StrTestEntity( "data_ed_1" ); + StrTestEntity ed2 = new StrTestEntity( "data_ed_2" ); - ListUniEntity ing1 = new ListUniEntity(3, "data_ing_1"); - ListUniEntity ing2 = new ListUniEntity(4, "data_ing_2"); + ListUniEntity ing1 = new ListUniEntity( 3, "data_ing_1" ); + ListUniEntity ing2 = new ListUniEntity( 4, "data_ing_2" ); - // Revision 1 - em.getTransaction().begin(); + // Revision 1 + em.getTransaction().begin(); - em.persist(ed1); - em.persist(ed2); - em.persist(ing1); - em.persist(ing2); + em.persist( ed1 ); + em.persist( ed2 ); + em.persist( ing1 ); + em.persist( ing2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 + // Revision 2 - em.getTransaction().begin(); + em.getTransaction().begin(); - ing1 = em.find(ListUniEntity.class, ing1.getId()); - ing2 = em.find(ListUniEntity.class, ing2.getId()); - ed1 = em.find(StrTestEntity.class, ed1.getId()); - ed2 = em.find(StrTestEntity.class, ed2.getId()); + ing1 = em.find( ListUniEntity.class, ing1.getId() ); + ing2 = em.find( ListUniEntity.class, ing2.getId() ); + ed1 = em.find( StrTestEntity.class, ed1.getId() ); + ed2 = em.find( StrTestEntity.class, ed2.getId() ); - ing1.setReferences(new ArrayList()); - ing1.getReferences().add(ed1); + ing1.setReferences( new ArrayList() ); + ing1.getReferences().add( ed1 ); - ing2.setReferences(new ArrayList()); - ing2.getReferences().add(ed1); - ing2.getReferences().add(ed2); + ing2.setReferences( new ArrayList() ); + ing2.getReferences().add( ed1 ); + ing2.getReferences().add( ed2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 - em.getTransaction().begin(); + // Revision 3 + em.getTransaction().begin(); - ing1 = em.find(ListUniEntity.class, ing1.getId()); - ed2 = em.find(StrTestEntity.class, ed2.getId()); - ed1 = em.find(StrTestEntity.class, ed1.getId()); + ing1 = em.find( ListUniEntity.class, ing1.getId() ); + ed2 = em.find( StrTestEntity.class, ed2.getId() ); + ed1 = em.find( StrTestEntity.class, ed1.getId() ); - ing1.getReferences().add(ed2); + ing1.getReferences().add( ed2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 4 - em.getTransaction().begin(); + // Revision 4 + em.getTransaction().begin(); - ing1 = em.find(ListUniEntity.class, ing1.getId()); - ed2 = em.find(StrTestEntity.class, ed2.getId()); - ed1 = em.find(StrTestEntity.class, ed1.getId()); + ing1 = em.find( ListUniEntity.class, ing1.getId() ); + ed2 = em.find( StrTestEntity.class, ed2.getId() ); + ed1 = em.find( StrTestEntity.class, ed1.getId() ); - ing1.getReferences().remove(ed1); + ing1.getReferences().remove( ed1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 5 - em.getTransaction().begin(); + // Revision 5 + em.getTransaction().begin(); - ing1 = em.find(ListUniEntity.class, ing1.getId()); + ing1 = em.find( ListUniEntity.class, ing1.getId() ); - ing1.setReferences(null); + ing1.setReferences( null ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // + // - ed1_id = ed1.getId(); - ed2_id = ed2.getId(); + ed1_id = ed1.getId(); + ed2_id = ed2.getId(); - ing1_id = ing1.getId(); - ing2_id = ing2.getId(); - } + ing1_id = ing1.getId(); + ing2_id = ing2.getId(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1).equals(getAuditReader().getRevisions(StrTestEntity.class, ed1_id)); - assert Arrays.asList(1).equals(getAuditReader().getRevisions(StrTestEntity.class, ed2_id)); + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1 ).equals( getAuditReader().getRevisions( StrTestEntity.class, ed1_id ) ); + assert Arrays.asList( 1 ).equals( getAuditReader().getRevisions( StrTestEntity.class, ed2_id ) ); - assert Arrays.asList(1, 2, 3, 4, 5).equals(getAuditReader().getRevisions(ListUniEntity.class, ing1_id)); - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(ListUniEntity.class, ing2_id)); - } + assert Arrays.asList( 1, 2, 3, 4, 5 ).equals( getAuditReader().getRevisions( ListUniEntity.class, ing1_id ) ); + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( ListUniEntity.class, ing2_id ) ); + } - @Test - public void testHistoryOfEdIng1() { - StrTestEntity ed1 = getEntityManager().find(StrTestEntity.class, ed1_id); - StrTestEntity ed2 = getEntityManager().find(StrTestEntity.class, ed2_id); + @Test + public void testHistoryOfEdIng1() { + StrTestEntity ed1 = getEntityManager().find( StrTestEntity.class, ed1_id ); + StrTestEntity ed2 = getEntityManager().find( StrTestEntity.class, ed2_id ); - ListUniEntity rev1 = getAuditReader().find(ListUniEntity.class, ing1_id, 1); - ListUniEntity rev2 = getAuditReader().find(ListUniEntity.class, ing1_id, 2); - ListUniEntity rev3 = getAuditReader().find(ListUniEntity.class, ing1_id, 3); - ListUniEntity rev4 = getAuditReader().find(ListUniEntity.class, ing1_id, 4); - ListUniEntity rev5 = getAuditReader().find(ListUniEntity.class, ing1_id, 5); + ListUniEntity rev1 = getAuditReader().find( ListUniEntity.class, ing1_id, 1 ); + ListUniEntity rev2 = getAuditReader().find( ListUniEntity.class, ing1_id, 2 ); + ListUniEntity rev3 = getAuditReader().find( ListUniEntity.class, ing1_id, 3 ); + ListUniEntity rev4 = getAuditReader().find( ListUniEntity.class, ing1_id, 4 ); + ListUniEntity rev5 = getAuditReader().find( ListUniEntity.class, ing1_id, 5 ); - assert rev1.getReferences().equals(Collections.EMPTY_LIST); - assert TestTools.checkList(rev2.getReferences(), ed1); - assert TestTools.checkList(rev3.getReferences(), ed1, ed2); - assert TestTools.checkList(rev4.getReferences(), ed2); - assert rev5.getReferences().equals(Collections.EMPTY_LIST); - } + assert rev1.getReferences().equals( Collections.EMPTY_LIST ); + assert TestTools.checkList( rev2.getReferences(), ed1 ); + assert TestTools.checkList( rev3.getReferences(), ed1, ed2 ); + assert TestTools.checkList( rev4.getReferences(), ed2 ); + assert rev5.getReferences().equals( Collections.EMPTY_LIST ); + } - @Test - public void testHistoryOfEdIng2() { - StrTestEntity ed1 = getEntityManager().find(StrTestEntity.class, ed1_id); - StrTestEntity ed2 = getEntityManager().find(StrTestEntity.class, ed2_id); + @Test + public void testHistoryOfEdIng2() { + StrTestEntity ed1 = getEntityManager().find( StrTestEntity.class, ed1_id ); + StrTestEntity ed2 = getEntityManager().find( StrTestEntity.class, ed2_id ); - ListUniEntity rev1 = getAuditReader().find(ListUniEntity.class, ing2_id, 1); - ListUniEntity rev2 = getAuditReader().find(ListUniEntity.class, ing2_id, 2); - ListUniEntity rev3 = getAuditReader().find(ListUniEntity.class, ing2_id, 3); - ListUniEntity rev4 = getAuditReader().find(ListUniEntity.class, ing2_id, 4); - ListUniEntity rev5 = getAuditReader().find(ListUniEntity.class, ing2_id, 5); + ListUniEntity rev1 = getAuditReader().find( ListUniEntity.class, ing2_id, 1 ); + ListUniEntity rev2 = getAuditReader().find( ListUniEntity.class, ing2_id, 2 ); + ListUniEntity rev3 = getAuditReader().find( ListUniEntity.class, ing2_id, 3 ); + ListUniEntity rev4 = getAuditReader().find( ListUniEntity.class, ing2_id, 4 ); + ListUniEntity rev5 = getAuditReader().find( ListUniEntity.class, ing2_id, 5 ); - assert rev1.getReferences().equals(Collections.EMPTY_LIST); - assert TestTools.checkList(rev2.getReferences(), ed1, ed2); - assert TestTools.checkList(rev3.getReferences(), ed1, ed2); - assert TestTools.checkList(rev4.getReferences(), ed1, ed2); - assert TestTools.checkList(rev5.getReferences(), ed1, ed2); - } + assert rev1.getReferences().equals( Collections.EMPTY_LIST ); + assert TestTools.checkList( rev2.getReferences(), ed1, ed2 ); + assert TestTools.checkList( rev3.getReferences(), ed1, ed2 ); + assert TestTools.checkList( rev4.getReferences(), ed1, ed2 ); + assert TestTools.checkList( rev5.getReferences(), ed1, ed2 ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/unidirectional/BasicUniMap.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/unidirectional/BasicUniMap.java index 61ac0a98f5..b92ff275df 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/unidirectional/BasicUniMap.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/unidirectional/BasicUniMap.java @@ -23,11 +23,9 @@ */ package org.hibernate.envers.test.integration.manytomany.unidirectional; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.HashMap; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; @@ -35,105 +33,107 @@ import org.hibernate.envers.test.entities.StrTestEntity; import org.hibernate.envers.test.entities.manytomany.unidirectional.MapUniEntity; import org.hibernate.envers.test.tools.TestTools; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class BasicUniMap extends BaseEnversJPAFunctionalTestCase { - private Integer str1_id; - private Integer str2_id; + private Integer str1_id; + private Integer str2_id; - private Integer coll1_id; + private Integer coll1_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { StrTestEntity.class, MapUniEntity.class }; - } + return new Class[] {StrTestEntity.class, MapUniEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - StrTestEntity str1 = new StrTestEntity("str1"); - StrTestEntity str2 = new StrTestEntity("str2"); + StrTestEntity str1 = new StrTestEntity( "str1" ); + StrTestEntity str2 = new StrTestEntity( "str2" ); - MapUniEntity coll1 = new MapUniEntity(3, "coll1"); + MapUniEntity coll1 = new MapUniEntity( 3, "coll1" ); - // Revision 1 (coll1: initialy one mapping) - em.getTransaction().begin(); + // Revision 1 (coll1: initialy one mapping) + em.getTransaction().begin(); - em.persist(str1); - em.persist(str2); + em.persist( str1 ); + em.persist( str2 ); - coll1.setMap(new HashMap()); - coll1.getMap().put("1", str1); - em.persist(coll1); + coll1.setMap( new HashMap() ); + coll1.getMap().put( "1", str1 ); + em.persist( coll1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 (coll1: adding one mapping) - em.getTransaction().begin(); + // Revision 2 (coll1: adding one mapping) + em.getTransaction().begin(); - str2 = em.find(StrTestEntity.class, str2.getId()); - coll1 = em.find(MapUniEntity.class, coll1.getId()); + str2 = em.find( StrTestEntity.class, str2.getId() ); + coll1 = em.find( MapUniEntity.class, coll1.getId() ); - coll1.getMap().put("2", str2); + coll1.getMap().put( "2", str2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 (coll1: replacing one mapping) - em.getTransaction().begin(); + // Revision 3 (coll1: replacing one mapping) + em.getTransaction().begin(); - str1 = em.find(StrTestEntity.class, str1.getId()); - coll1 = em.find(MapUniEntity.class, coll1.getId()); + str1 = em.find( StrTestEntity.class, str1.getId() ); + coll1 = em.find( MapUniEntity.class, coll1.getId() ); - coll1.getMap().put("2", str1); + coll1.getMap().put( "2", str1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 4 (coll1: removing one mapping) - em.getTransaction().begin(); + // Revision 4 (coll1: removing one mapping) + em.getTransaction().begin(); - coll1 = em.find(MapUniEntity.class, coll1.getId()); + coll1 = em.find( MapUniEntity.class, coll1.getId() ); - coll1.getMap().remove("1"); + coll1.getMap().remove( "1" ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // + // - str1_id = str1.getId(); - str2_id = str2.getId(); + str1_id = str1.getId(); + str2_id = str2.getId(); - coll1_id = coll1.getId(); - } + coll1_id = coll1.getId(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2, 3, 4).equals(getAuditReader().getRevisions(MapUniEntity.class, coll1_id)); + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2, 3, 4 ).equals( getAuditReader().getRevisions( MapUniEntity.class, coll1_id ) ); - assert Arrays.asList(1).equals(getAuditReader().getRevisions(StrTestEntity.class, str1_id)); - assert Arrays.asList(1).equals(getAuditReader().getRevisions(StrTestEntity.class, str2_id)); - } + assert Arrays.asList( 1 ).equals( getAuditReader().getRevisions( StrTestEntity.class, str1_id ) ); + assert Arrays.asList( 1 ).equals( getAuditReader().getRevisions( StrTestEntity.class, str2_id ) ); + } - @Test - public void testHistoryOfColl1() { - StrTestEntity str1 = getEntityManager().find(StrTestEntity.class, str1_id); - StrTestEntity str2 = getEntityManager().find(StrTestEntity.class, str2_id); + @Test + public void testHistoryOfColl1() { + StrTestEntity str1 = getEntityManager().find( StrTestEntity.class, str1_id ); + StrTestEntity str2 = getEntityManager().find( StrTestEntity.class, str2_id ); - MapUniEntity rev1 = getAuditReader().find(MapUniEntity.class, coll1_id, 1); - MapUniEntity rev2 = getAuditReader().find(MapUniEntity.class, coll1_id, 2); - MapUniEntity rev3 = getAuditReader().find(MapUniEntity.class, coll1_id, 3); - MapUniEntity rev4 = getAuditReader().find(MapUniEntity.class, coll1_id, 4); + MapUniEntity rev1 = getAuditReader().find( MapUniEntity.class, coll1_id, 1 ); + MapUniEntity rev2 = getAuditReader().find( MapUniEntity.class, coll1_id, 2 ); + MapUniEntity rev3 = getAuditReader().find( MapUniEntity.class, coll1_id, 3 ); + MapUniEntity rev4 = getAuditReader().find( MapUniEntity.class, coll1_id, 4 ); - assert rev1.getMap().equals(TestTools.makeMap("1", str1)); - assert rev2.getMap().equals(TestTools.makeMap("1", str1, "2", str2)); - assert rev3.getMap().equals(TestTools.makeMap("1", str1, "2", str1)); - assert rev4.getMap().equals(TestTools.makeMap("2", str1)); + assert rev1.getMap().equals( TestTools.makeMap( "1", str1 ) ); + assert rev2.getMap().equals( TestTools.makeMap( "1", str1, "2", str2 ) ); + assert rev3.getMap().equals( TestTools.makeMap( "1", str1, "2", str1 ) ); + assert rev4.getMap().equals( TestTools.makeMap( "2", str1 ) ); - assert "coll1".equals(rev1.getData()); - assert "coll1".equals(rev2.getData()); - assert "coll1".equals(rev3.getData()); - assert "coll1".equals(rev4.getData()); - } + assert "coll1".equals( rev1.getData() ); + assert "coll1".equals( rev2.getData() ); + assert "coll1".equals( rev3.getData() ); + assert "coll1".equals( rev4.getData() ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/unidirectional/BasicUniSet.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/unidirectional/BasicUniSet.java index f2e734f06c..77d00ec9e0 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/unidirectional/BasicUniSet.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/unidirectional/BasicUniSet.java @@ -23,12 +23,10 @@ */ package org.hibernate.envers.test.integration.manytomany.unidirectional; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; @@ -36,142 +34,144 @@ import org.hibernate.envers.test.entities.StrTestEntity; import org.hibernate.envers.test.entities.manytomany.unidirectional.SetUniEntity; import org.hibernate.envers.test.tools.TestTools; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class BasicUniSet extends BaseEnversJPAFunctionalTestCase { - private Integer ed1_id; - private Integer ed2_id; + private Integer ed1_id; + private Integer ed2_id; - private Integer ing1_id; - private Integer ing2_id; + private Integer ing1_id; + private Integer ing2_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { SetUniEntity.class, StrTestEntity.class }; - } + return new Class[] {SetUniEntity.class, StrTestEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - StrTestEntity ed1 = new StrTestEntity("data_ed_1"); - StrTestEntity ed2 = new StrTestEntity("data_ed_2"); + StrTestEntity ed1 = new StrTestEntity( "data_ed_1" ); + StrTestEntity ed2 = new StrTestEntity( "data_ed_2" ); - SetUniEntity ing1 = new SetUniEntity(3, "data_ing_1"); - SetUniEntity ing2 = new SetUniEntity(4, "data_ing_2"); + SetUniEntity ing1 = new SetUniEntity( 3, "data_ing_1" ); + SetUniEntity ing2 = new SetUniEntity( 4, "data_ing_2" ); - // Revision 1 - em.getTransaction().begin(); + // Revision 1 + em.getTransaction().begin(); - em.persist(ed1); - em.persist(ed2); - em.persist(ing1); - em.persist(ing2); + em.persist( ed1 ); + em.persist( ed2 ); + em.persist( ing1 ); + em.persist( ing2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 + // Revision 2 - em.getTransaction().begin(); + em.getTransaction().begin(); - ing1 = em.find(SetUniEntity.class, ing1.getId()); - ing2 = em.find(SetUniEntity.class, ing2.getId()); - ed1 = em.find(StrTestEntity.class, ed1.getId()); - ed2 = em.find(StrTestEntity.class, ed2.getId()); + ing1 = em.find( SetUniEntity.class, ing1.getId() ); + ing2 = em.find( SetUniEntity.class, ing2.getId() ); + ed1 = em.find( StrTestEntity.class, ed1.getId() ); + ed2 = em.find( StrTestEntity.class, ed2.getId() ); - ing1.setReferences(new HashSet()); - ing1.getReferences().add(ed1); + ing1.setReferences( new HashSet() ); + ing1.getReferences().add( ed1 ); - ing2.setReferences(new HashSet()); - ing2.getReferences().add(ed1); - ing2.getReferences().add(ed2); + ing2.setReferences( new HashSet() ); + ing2.getReferences().add( ed1 ); + ing2.getReferences().add( ed2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 - em.getTransaction().begin(); + // Revision 3 + em.getTransaction().begin(); - ing1 = em.find(SetUniEntity.class, ing1.getId()); - ed2 = em.find(StrTestEntity.class, ed2.getId()); - ed1 = em.find(StrTestEntity.class, ed1.getId()); + ing1 = em.find( SetUniEntity.class, ing1.getId() ); + ed2 = em.find( StrTestEntity.class, ed2.getId() ); + ed1 = em.find( StrTestEntity.class, ed1.getId() ); - ing1.getReferences().add(ed2); + ing1.getReferences().add( ed2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 4 - em.getTransaction().begin(); + // Revision 4 + em.getTransaction().begin(); - ing1 = em.find(SetUniEntity.class, ing1.getId()); - ed2 = em.find(StrTestEntity.class, ed2.getId()); - ed1 = em.find(StrTestEntity.class, ed1.getId()); + ing1 = em.find( SetUniEntity.class, ing1.getId() ); + ed2 = em.find( StrTestEntity.class, ed2.getId() ); + ed1 = em.find( StrTestEntity.class, ed1.getId() ); - ing1.getReferences().remove(ed1); + ing1.getReferences().remove( ed1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 5 - em.getTransaction().begin(); + // Revision 5 + em.getTransaction().begin(); - ing1 = em.find(SetUniEntity.class, ing1.getId()); + ing1 = em.find( SetUniEntity.class, ing1.getId() ); - ing1.setReferences(null); + ing1.setReferences( null ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // + // - ed1_id = ed1.getId(); - ed2_id = ed2.getId(); + ed1_id = ed1.getId(); + ed2_id = ed2.getId(); - ing1_id = ing1.getId(); - ing2_id = ing2.getId(); - } + ing1_id = ing1.getId(); + ing2_id = ing2.getId(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1).equals(getAuditReader().getRevisions(StrTestEntity.class, ed1_id)); - assert Arrays.asList(1).equals(getAuditReader().getRevisions(StrTestEntity.class, ed2_id)); + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1 ).equals( getAuditReader().getRevisions( StrTestEntity.class, ed1_id ) ); + assert Arrays.asList( 1 ).equals( getAuditReader().getRevisions( StrTestEntity.class, ed2_id ) ); - assert Arrays.asList(1, 2, 3, 4, 5).equals(getAuditReader().getRevisions(SetUniEntity.class, ing1_id)); - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(SetUniEntity.class, ing2_id)); - } + assert Arrays.asList( 1, 2, 3, 4, 5 ).equals( getAuditReader().getRevisions( SetUniEntity.class, ing1_id ) ); + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( SetUniEntity.class, ing2_id ) ); + } - @Test - public void testHistoryOfEdIng1() { - StrTestEntity ed1 = getEntityManager().find(StrTestEntity.class, ed1_id); - StrTestEntity ed2 = getEntityManager().find(StrTestEntity.class, ed2_id); + @Test + public void testHistoryOfEdIng1() { + StrTestEntity ed1 = getEntityManager().find( StrTestEntity.class, ed1_id ); + StrTestEntity ed2 = getEntityManager().find( StrTestEntity.class, ed2_id ); - SetUniEntity rev1 = getAuditReader().find(SetUniEntity.class, ing1_id, 1); - SetUniEntity rev2 = getAuditReader().find(SetUniEntity.class, ing1_id, 2); - SetUniEntity rev3 = getAuditReader().find(SetUniEntity.class, ing1_id, 3); - SetUniEntity rev4 = getAuditReader().find(SetUniEntity.class, ing1_id, 4); - SetUniEntity rev5 = getAuditReader().find(SetUniEntity.class, ing1_id, 5); + SetUniEntity rev1 = getAuditReader().find( SetUniEntity.class, ing1_id, 1 ); + SetUniEntity rev2 = getAuditReader().find( SetUniEntity.class, ing1_id, 2 ); + SetUniEntity rev3 = getAuditReader().find( SetUniEntity.class, ing1_id, 3 ); + SetUniEntity rev4 = getAuditReader().find( SetUniEntity.class, ing1_id, 4 ); + SetUniEntity rev5 = getAuditReader().find( SetUniEntity.class, ing1_id, 5 ); - assert rev1.getReferences().equals(Collections.EMPTY_SET); - assert rev2.getReferences().equals(TestTools.makeSet(ed1)); - assert rev3.getReferences().equals(TestTools.makeSet(ed1, ed2)); - assert rev4.getReferences().equals(TestTools.makeSet(ed2)); - assert rev5.getReferences().equals(Collections.EMPTY_SET); - } + assert rev1.getReferences().equals( Collections.EMPTY_SET ); + assert rev2.getReferences().equals( TestTools.makeSet( ed1 ) ); + assert rev3.getReferences().equals( TestTools.makeSet( ed1, ed2 ) ); + assert rev4.getReferences().equals( TestTools.makeSet( ed2 ) ); + assert rev5.getReferences().equals( Collections.EMPTY_SET ); + } - @Test - public void testHistoryOfEdIng2() { - StrTestEntity ed1 = getEntityManager().find(StrTestEntity.class, ed1_id); - StrTestEntity ed2 = getEntityManager().find(StrTestEntity.class, ed2_id); + @Test + public void testHistoryOfEdIng2() { + StrTestEntity ed1 = getEntityManager().find( StrTestEntity.class, ed1_id ); + StrTestEntity ed2 = getEntityManager().find( StrTestEntity.class, ed2_id ); - SetUniEntity rev1 = getAuditReader().find(SetUniEntity.class, ing2_id, 1); - SetUniEntity rev2 = getAuditReader().find(SetUniEntity.class, ing2_id, 2); - SetUniEntity rev3 = getAuditReader().find(SetUniEntity.class, ing2_id, 3); - SetUniEntity rev4 = getAuditReader().find(SetUniEntity.class, ing2_id, 4); - SetUniEntity rev5 = getAuditReader().find(SetUniEntity.class, ing2_id, 5); + SetUniEntity rev1 = getAuditReader().find( SetUniEntity.class, ing2_id, 1 ); + SetUniEntity rev2 = getAuditReader().find( SetUniEntity.class, ing2_id, 2 ); + SetUniEntity rev3 = getAuditReader().find( SetUniEntity.class, ing2_id, 3 ); + SetUniEntity rev4 = getAuditReader().find( SetUniEntity.class, ing2_id, 4 ); + SetUniEntity rev5 = getAuditReader().find( SetUniEntity.class, ing2_id, 5 ); - assert rev1.getReferences().equals(Collections.EMPTY_SET); - assert rev2.getReferences().equals(TestTools.makeSet(ed1, ed2)); - assert rev3.getReferences().equals(TestTools.makeSet(ed1, ed2)); - assert rev4.getReferences().equals(TestTools.makeSet(ed1, ed2)); - assert rev5.getReferences().equals(TestTools.makeSet(ed1, ed2)); - } + assert rev1.getReferences().equals( Collections.EMPTY_SET ); + assert rev2.getReferences().equals( TestTools.makeSet( ed1, ed2 ) ); + assert rev3.getReferences().equals( TestTools.makeSet( ed1, ed2 ) ); + assert rev4.getReferences().equals( TestTools.makeSet( ed1, ed2 ) ); + assert rev5.getReferences().equals( TestTools.makeSet( ed1, ed2 ) ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/unidirectional/JoinTableDetachedTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/unidirectional/JoinTableDetachedTest.java index 78b6a86d72..2eeb3dcaba 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/unidirectional/JoinTableDetachedTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/unidirectional/JoinTableDetachedTest.java @@ -1,22 +1,23 @@ package org.hibernate.envers.test.integration.manytomany.unidirectional; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.HashSet; -import javax.persistence.EntityManager; - -import org.junit.Assert; -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrTestEntity; import org.hibernate.envers.test.entities.manytomany.unidirectional.JoinTableEntity; + +import org.junit.Assert; +import org.junit.Test; + import org.hibernate.testing.TestForIssue; /** * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ -@TestForIssue( jiraKey = "HHH-8087" ) +@TestForIssue(jiraKey = "HHH-8087") public class JoinTableDetachedTest extends BaseEnversJPAFunctionalTestCase { private Long collectionEntityId = null; private Integer element1Id = null; @@ -24,7 +25,7 @@ public class JoinTableDetachedTest extends BaseEnversJPAFunctionalTestCase { @Override protected Class[] getAnnotatedClasses() { - return new Class[] { JoinTableEntity.class, StrTestEntity.class }; + return new Class[] {JoinTableEntity.class, StrTestEntity.class}; } @Test @@ -93,9 +94,14 @@ public class JoinTableDetachedTest extends BaseEnversJPAFunctionalTestCase { @Test public void testRevisionsCounts() { - Assert.assertEquals( Arrays.asList( 1, 2, 3, 4, 5 ), getAuditReader().getRevisions(JoinTableEntity.class, collectionEntityId ) ); - Assert.assertEquals( Arrays.asList( 1 ), getAuditReader().getRevisions(StrTestEntity.class, element1Id ) ); - Assert.assertEquals( Arrays.asList( 1 ), getAuditReader().getRevisions(StrTestEntity.class, element2Id ) ); + Assert.assertEquals( + Arrays.asList( 1, 2, 3, 4, 5 ), getAuditReader().getRevisions( + JoinTableEntity.class, + collectionEntityId + ) + ); + Assert.assertEquals( Arrays.asList( 1 ), getAuditReader().getRevisions( StrTestEntity.class, element1Id ) ); + Assert.assertEquals( Arrays.asList( 1 ), getAuditReader().getRevisions( StrTestEntity.class, element2Id ) ); } @Test diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/unidirectional/M2MIndexedListNotAuditedTarget.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/unidirectional/M2MIndexedListNotAuditedTarget.java index 0a0fdef23c..63c8c56c3d 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/unidirectional/M2MIndexedListNotAuditedTarget.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/unidirectional/M2MIndexedListNotAuditedTarget.java @@ -1,16 +1,16 @@ package org.hibernate.envers.test.integration.manytomany.unidirectional; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.List; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.UnversionedStrTestEntity; import org.hibernate.envers.test.entities.manytomany.unidirectional.M2MIndexedListTargetNotAuditedEntity; +import org.junit.Test; + import static org.hibernate.envers.test.tools.TestTools.checkList; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; @@ -23,98 +23,122 @@ import static org.junit.Assert.assertTrue; * @author Adam Warski */ public class M2MIndexedListNotAuditedTarget extends BaseEnversJPAFunctionalTestCase { - private Integer itnae1_id; - private Integer itnae2_id; + private Integer itnae1_id; + private Integer itnae2_id; - private UnversionedStrTestEntity uste1; - private UnversionedStrTestEntity uste2; + private UnversionedStrTestEntity uste1; + private UnversionedStrTestEntity uste2; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { UnversionedStrTestEntity.class, M2MIndexedListTargetNotAuditedEntity.class }; - } + return new Class[] {UnversionedStrTestEntity.class, M2MIndexedListTargetNotAuditedEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - uste1 = new UnversionedStrTestEntity("str1"); - uste2 = new UnversionedStrTestEntity("str2"); + uste1 = new UnversionedStrTestEntity( "str1" ); + uste2 = new UnversionedStrTestEntity( "str2" ); - // No revision - em.getTransaction().begin(); + // No revision + em.getTransaction().begin(); - em.persist(uste1); - em.persist(uste2); + em.persist( uste1 ); + em.persist( uste2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 1 - em.getTransaction().begin(); + // Revision 1 + em.getTransaction().begin(); - uste1 = em.find(UnversionedStrTestEntity.class, uste1.getId()); - uste2 = em.find(UnversionedStrTestEntity.class, uste2.getId()); + uste1 = em.find( UnversionedStrTestEntity.class, uste1.getId() ); + uste2 = em.find( UnversionedStrTestEntity.class, uste2.getId() ); - M2MIndexedListTargetNotAuditedEntity itnae1 = new M2MIndexedListTargetNotAuditedEntity(1, "tnae1"); + M2MIndexedListTargetNotAuditedEntity itnae1 = new M2MIndexedListTargetNotAuditedEntity( 1, "tnae1" ); - itnae1.getReferences().add(uste1); - itnae1.getReferences().add(uste2); + itnae1.getReferences().add( uste1 ); + itnae1.getReferences().add( uste2 ); - em.persist(itnae1); + em.persist( itnae1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); + // Revision 2 + em.getTransaction().begin(); - M2MIndexedListTargetNotAuditedEntity itnae2 = new M2MIndexedListTargetNotAuditedEntity(2, "tnae2"); + M2MIndexedListTargetNotAuditedEntity itnae2 = new M2MIndexedListTargetNotAuditedEntity( 2, "tnae2" ); - itnae2.getReferences().add(uste2); + itnae2.getReferences().add( uste2 ); - em.persist(itnae2); + em.persist( itnae2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 - em.getTransaction().begin(); + // Revision 3 + em.getTransaction().begin(); - itnae1.getReferences().set(0, uste2); - itnae1.getReferences().set(1, uste1); - em.getTransaction().commit(); + itnae1.getReferences().set( 0, uste2 ); + itnae1.getReferences().set( 1, uste1 ); + em.getTransaction().commit(); - itnae1_id = itnae1.getId(); - itnae2_id = itnae2.getId(); - } + itnae1_id = itnae1.getId(); + itnae2_id = itnae2.getId(); + } @Test public void testRevisionsCounts() { - List revisions = getAuditReader().getRevisions(M2MIndexedListTargetNotAuditedEntity.class, itnae1_id); - assertEquals(revisions, Arrays.asList(1, 3)); + List revisions = getAuditReader().getRevisions( M2MIndexedListTargetNotAuditedEntity.class, itnae1_id ); + assertEquals( revisions, Arrays.asList( 1, 3 ) ); - revisions = getAuditReader().getRevisions(M2MIndexedListTargetNotAuditedEntity.class, itnae2_id); - assertEquals(revisions, Arrays.asList(2)); + revisions = getAuditReader().getRevisions( M2MIndexedListTargetNotAuditedEntity.class, itnae2_id ); + assertEquals( revisions, Arrays.asList( 2 ) ); } - @Test - public void testHistory1() throws Exception { - M2MIndexedListTargetNotAuditedEntity rev1 = getAuditReader().find(M2MIndexedListTargetNotAuditedEntity.class, itnae1_id, 1); - M2MIndexedListTargetNotAuditedEntity rev2 = getAuditReader().find(M2MIndexedListTargetNotAuditedEntity.class, itnae1_id, 2); - M2MIndexedListTargetNotAuditedEntity rev3 = getAuditReader().find(M2MIndexedListTargetNotAuditedEntity.class, itnae1_id, 3); + @Test + public void testHistory1() throws Exception { + M2MIndexedListTargetNotAuditedEntity rev1 = getAuditReader().find( + M2MIndexedListTargetNotAuditedEntity.class, + itnae1_id, + 1 + ); + M2MIndexedListTargetNotAuditedEntity rev2 = getAuditReader().find( + M2MIndexedListTargetNotAuditedEntity.class, + itnae1_id, + 2 + ); + M2MIndexedListTargetNotAuditedEntity rev3 = getAuditReader().find( + M2MIndexedListTargetNotAuditedEntity.class, + itnae1_id, + 3 + ); - assertTrue(checkList(rev1.getReferences(), uste1, uste2)); - assertTrue(checkList(rev2.getReferences(), uste1, uste2)); - assertTrue(checkList(rev3.getReferences(), uste2, uste1)); - } + assertTrue( checkList( rev1.getReferences(), uste1, uste2 ) ); + assertTrue( checkList( rev2.getReferences(), uste1, uste2 ) ); + assertTrue( checkList( rev3.getReferences(), uste2, uste1 ) ); + } - @Test - public void testHistory2() throws Exception { - M2MIndexedListTargetNotAuditedEntity rev1 = getAuditReader().find(M2MIndexedListTargetNotAuditedEntity.class, itnae2_id, 1); - M2MIndexedListTargetNotAuditedEntity rev2 = getAuditReader().find(M2MIndexedListTargetNotAuditedEntity.class, itnae2_id, 2); - M2MIndexedListTargetNotAuditedEntity rev3 = getAuditReader().find(M2MIndexedListTargetNotAuditedEntity.class, itnae2_id, 3); + @Test + public void testHistory2() throws Exception { + M2MIndexedListTargetNotAuditedEntity rev1 = getAuditReader().find( + M2MIndexedListTargetNotAuditedEntity.class, + itnae2_id, + 1 + ); + M2MIndexedListTargetNotAuditedEntity rev2 = getAuditReader().find( + M2MIndexedListTargetNotAuditedEntity.class, + itnae2_id, + 2 + ); + M2MIndexedListTargetNotAuditedEntity rev3 = getAuditReader().find( + M2MIndexedListTargetNotAuditedEntity.class, + itnae2_id, + 3 + ); - assertNull(rev1); - assertTrue(checkList(rev2.getReferences(), uste2)); - assertTrue(checkList(rev3.getReferences(), uste2)); - } + assertNull( rev1 ); + assertTrue( checkList( rev2.getReferences(), uste2 ) ); + assertTrue( checkList( rev3.getReferences(), uste2 ) ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/unidirectional/M2MRelationNotAuditedTarget.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/unidirectional/M2MRelationNotAuditedTarget.java index 50594e2672..2e7d567128 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/unidirectional/M2MRelationNotAuditedTarget.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/unidirectional/M2MRelationNotAuditedTarget.java @@ -23,23 +23,24 @@ */ package org.hibernate.envers.test.integration.manytomany.unidirectional; +import javax.persistence.EntityManager; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.UnversionedStrTestEntity; import org.hibernate.envers.test.entities.manytomany.unidirectional.M2MTargetNotAuditedEntity; +import org.junit.Test; + import static org.hibernate.envers.test.tools.TestTools.checkList; import static org.junit.Assert.assertTrue; /** * A test for auditing a many-to-many relation where the target entity is not audited. + * * @author Adam Warski */ public class M2MRelationNotAuditedTarget extends BaseEnversJPAFunctionalTestCase { @@ -51,71 +52,79 @@ public class M2MRelationNotAuditedTarget extends BaseEnversJPAFunctionalTestCase @Override protected Class[] getAnnotatedClasses() { - return new Class[] { M2MTargetNotAuditedEntity.class, UnversionedStrTestEntity.class }; + return new Class[] {M2MTargetNotAuditedEntity.class, UnversionedStrTestEntity.class}; } @Test - @Priority(10) + @Priority(10) public void initData() { EntityManager em = getEntityManager(); - UnversionedStrTestEntity uste1 = new UnversionedStrTestEntity("str1"); - UnversionedStrTestEntity uste2 = new UnversionedStrTestEntity("str2"); + UnversionedStrTestEntity uste1 = new UnversionedStrTestEntity( "str1" ); + UnversionedStrTestEntity uste2 = new UnversionedStrTestEntity( "str2" ); // No revision em.getTransaction().begin(); - em.persist(uste1); - em.persist(uste2); + em.persist( uste1 ); + em.persist( uste2 ); em.getTransaction().commit(); // Revision 1 em.getTransaction().begin(); - uste1 = em.find(UnversionedStrTestEntity.class, uste1.getId()); - uste2 = em.find(UnversionedStrTestEntity.class, uste2.getId()); + uste1 = em.find( UnversionedStrTestEntity.class, uste1.getId() ); + uste2 = em.find( UnversionedStrTestEntity.class, uste2.getId() ); - M2MTargetNotAuditedEntity tnae1 = new M2MTargetNotAuditedEntity(1, "tnae1", new ArrayList()); - M2MTargetNotAuditedEntity tnae2 = new M2MTargetNotAuditedEntity(2, "tnae2", new ArrayList()); - tnae2.getReferences().add(uste1); - tnae2.getReferences().add(uste2); - em.persist(tnae1); - em.persist(tnae2); + M2MTargetNotAuditedEntity tnae1 = new M2MTargetNotAuditedEntity( + 1, + "tnae1", + new ArrayList() + ); + M2MTargetNotAuditedEntity tnae2 = new M2MTargetNotAuditedEntity( + 2, + "tnae2", + new ArrayList() + ); + tnae2.getReferences().add( uste1 ); + tnae2.getReferences().add( uste2 ); + em.persist( tnae1 ); + em.persist( tnae2 ); em.getTransaction().commit(); // Revision 2 em.getTransaction().begin(); - tnae1 = em.find(M2MTargetNotAuditedEntity.class, tnae1.getId()); - tnae2 = em.find(M2MTargetNotAuditedEntity.class, tnae2.getId()); + tnae1 = em.find( M2MTargetNotAuditedEntity.class, tnae1.getId() ); + tnae2 = em.find( M2MTargetNotAuditedEntity.class, tnae2.getId() ); - tnae1.getReferences().add(uste1); - tnae2.getReferences().remove(uste1); + tnae1.getReferences().add( uste1 ); + tnae2.getReferences().remove( uste1 ); em.getTransaction().commit(); // Revision 3 em.getTransaction().begin(); - tnae1 = em.find(M2MTargetNotAuditedEntity.class, tnae1.getId()); - tnae2 = em.find(M2MTargetNotAuditedEntity.class, tnae2.getId()); + tnae1 = em.find( M2MTargetNotAuditedEntity.class, tnae1.getId() ); + tnae2 = em.find( M2MTargetNotAuditedEntity.class, tnae2.getId() ); //field not changed!!! - tnae1.getReferences().add(uste1); - tnae2.getReferences().remove(uste2); + tnae1.getReferences().add( uste1 ); + tnae2.getReferences().remove( uste2 ); em.getTransaction().commit(); // Revision 4 em.getTransaction().begin(); - tnae1 = em.find(M2MTargetNotAuditedEntity.class, tnae1.getId()); - tnae2 = em.find(M2MTargetNotAuditedEntity.class, tnae2.getId()); + tnae1 = em.find( M2MTargetNotAuditedEntity.class, tnae1.getId() ); + tnae2 = em.find( M2MTargetNotAuditedEntity.class, tnae2.getId() ); - tnae1.getReferences().add(uste2); - tnae2.getReferences().add(uste1); + tnae1.getReferences().add( uste2 ); + tnae2.getReferences().add( uste1 ); em.getTransaction().commit(); @@ -128,41 +137,41 @@ public class M2MRelationNotAuditedTarget extends BaseEnversJPAFunctionalTestCase @Test public void testRevisionsCounts() { - List revisions = getAuditReader().getRevisions(M2MTargetNotAuditedEntity.class, tnae1_id); - assert Arrays.asList(1, 2, 4).equals(revisions); - revisions = getAuditReader().getRevisions(M2MTargetNotAuditedEntity.class, tnae2_id); - assert Arrays.asList(1, 2, 3, 4).equals(revisions); + List revisions = getAuditReader().getRevisions( M2MTargetNotAuditedEntity.class, tnae1_id ); + assert Arrays.asList( 1, 2, 4 ).equals( revisions ); + revisions = getAuditReader().getRevisions( M2MTargetNotAuditedEntity.class, tnae2_id ); + assert Arrays.asList( 1, 2, 3, 4 ).equals( revisions ); } @Test public void testHistoryOfTnae1_id() { - UnversionedStrTestEntity uste1 = getEntityManager().find(UnversionedStrTestEntity.class, uste1_id); - UnversionedStrTestEntity uste2 = getEntityManager().find(UnversionedStrTestEntity.class, uste2_id); + UnversionedStrTestEntity uste1 = getEntityManager().find( UnversionedStrTestEntity.class, uste1_id ); + UnversionedStrTestEntity uste2 = getEntityManager().find( UnversionedStrTestEntity.class, uste2_id ); - M2MTargetNotAuditedEntity rev1 = getAuditReader().find(M2MTargetNotAuditedEntity.class, tnae1_id, 1); - M2MTargetNotAuditedEntity rev2 = getAuditReader().find(M2MTargetNotAuditedEntity.class, tnae1_id, 2); - M2MTargetNotAuditedEntity rev3 = getAuditReader().find(M2MTargetNotAuditedEntity.class, tnae1_id, 3); - M2MTargetNotAuditedEntity rev4 = getAuditReader().find(M2MTargetNotAuditedEntity.class, tnae1_id, 4); + M2MTargetNotAuditedEntity rev1 = getAuditReader().find( M2MTargetNotAuditedEntity.class, tnae1_id, 1 ); + M2MTargetNotAuditedEntity rev2 = getAuditReader().find( M2MTargetNotAuditedEntity.class, tnae1_id, 2 ); + M2MTargetNotAuditedEntity rev3 = getAuditReader().find( M2MTargetNotAuditedEntity.class, tnae1_id, 3 ); + M2MTargetNotAuditedEntity rev4 = getAuditReader().find( M2MTargetNotAuditedEntity.class, tnae1_id, 4 ); - assertTrue(checkList(rev1.getReferences())); - assertTrue(checkList(rev2.getReferences(), uste1)); - assertTrue(checkList(rev3.getReferences(), uste1)); - assertTrue(checkList(rev4.getReferences(), uste1, uste2)); + assertTrue( checkList( rev1.getReferences() ) ); + assertTrue( checkList( rev2.getReferences(), uste1 ) ); + assertTrue( checkList( rev3.getReferences(), uste1 ) ); + assertTrue( checkList( rev4.getReferences(), uste1, uste2 ) ); } @Test public void testHistoryOfTnae2_id() { - UnversionedStrTestEntity uste1 = getEntityManager().find(UnversionedStrTestEntity.class, uste1_id); - UnversionedStrTestEntity uste2 = getEntityManager().find(UnversionedStrTestEntity.class, uste2_id); + UnversionedStrTestEntity uste1 = getEntityManager().find( UnversionedStrTestEntity.class, uste1_id ); + UnversionedStrTestEntity uste2 = getEntityManager().find( UnversionedStrTestEntity.class, uste2_id ); - M2MTargetNotAuditedEntity rev1 = getAuditReader().find(M2MTargetNotAuditedEntity.class, tnae2_id, 1); - M2MTargetNotAuditedEntity rev2 = getAuditReader().find(M2MTargetNotAuditedEntity.class, tnae2_id, 2); - M2MTargetNotAuditedEntity rev3 = getAuditReader().find(M2MTargetNotAuditedEntity.class, tnae2_id, 3); - M2MTargetNotAuditedEntity rev4 = getAuditReader().find(M2MTargetNotAuditedEntity.class, tnae2_id, 4); + M2MTargetNotAuditedEntity rev1 = getAuditReader().find( M2MTargetNotAuditedEntity.class, tnae2_id, 1 ); + M2MTargetNotAuditedEntity rev2 = getAuditReader().find( M2MTargetNotAuditedEntity.class, tnae2_id, 2 ); + M2MTargetNotAuditedEntity rev3 = getAuditReader().find( M2MTargetNotAuditedEntity.class, tnae2_id, 3 ); + M2MTargetNotAuditedEntity rev4 = getAuditReader().find( M2MTargetNotAuditedEntity.class, tnae2_id, 4 ); - assertTrue(checkList(rev1.getReferences(), uste1, uste2)); - assertTrue(checkList(rev2.getReferences(), uste2)); - assertTrue(checkList(rev3.getReferences())); - assertTrue(checkList(rev4.getReferences(), uste1)); + assertTrue( checkList( rev1.getReferences(), uste1, uste2 ) ); + assertTrue( checkList( rev2.getReferences(), uste2 ) ); + assertTrue( checkList( rev3.getReferences() ) ); + assertTrue( checkList( rev4.getReferences(), uste1 ) ); } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytoone/bidirectional/ImplicitMappedByTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytoone/bidirectional/ImplicitMappedByTest.java index e1f5c2c8ab..d4b3bfc187 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytoone/bidirectional/ImplicitMappedByTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytoone/bidirectional/ImplicitMappedByTest.java @@ -1,16 +1,17 @@ package org.hibernate.envers.test.integration.manytoone.bidirectional; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.HashSet; import java.util.Set; -import javax.persistence.EntityManager; - -import org.junit.Assert; -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.tools.TestTools; + +import org.junit.Assert; +import org.junit.Test; + import org.hibernate.testing.TestForIssue; /** @@ -18,93 +19,93 @@ import org.hibernate.testing.TestForIssue; */ @TestForIssue(jiraKey = "HHH-4962") public class ImplicitMappedByTest extends BaseEnversJPAFunctionalTestCase { - private Long ownedId = null; - private Long owning1Id = null; - private Long owning2Id = null; + private Long ownedId = null; + private Long owning1Id = null; + private Long owning2Id = null; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { OneToManyOwned.class, ManyToOneOwning.class }; - } + return new Class[] {OneToManyOwned.class, ManyToOneOwning.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - OneToManyOwned owned = new OneToManyOwned("data", null); - Set referencing = new HashSet(); - ManyToOneOwning owning1 = new ManyToOneOwning("data1", owned); - referencing.add(owning1); - ManyToOneOwning owning2 = new ManyToOneOwning("data2", owned); - referencing.add(owning2); - owned.setReferencing(referencing); + OneToManyOwned owned = new OneToManyOwned( "data", null ); + Set referencing = new HashSet(); + ManyToOneOwning owning1 = new ManyToOneOwning( "data1", owned ); + referencing.add( owning1 ); + ManyToOneOwning owning2 = new ManyToOneOwning( "data2", owned ); + referencing.add( owning2 ); + owned.setReferencing( referencing ); - // Revision 1 - em.getTransaction().begin(); - em.persist(owned); - em.persist(owning1); - em.persist(owning2); - em.getTransaction().commit(); + // Revision 1 + em.getTransaction().begin(); + em.persist( owned ); + em.persist( owning1 ); + em.persist( owning2 ); + em.getTransaction().commit(); - ownedId = owned.getId(); - owning1Id = owning1.getId(); - owning2Id = owning2.getId(); + ownedId = owned.getId(); + owning1Id = owning1.getId(); + owning2Id = owning2.getId(); - // Revision 2 - em.getTransaction().begin(); - owning1 = em.find(ManyToOneOwning.class, owning1.getId()); - em.remove(owning1); - em.getTransaction().commit(); + // Revision 2 + em.getTransaction().begin(); + owning1 = em.find( ManyToOneOwning.class, owning1.getId() ); + em.remove( owning1 ); + em.getTransaction().commit(); - // Revision 3 - em.getTransaction().begin(); - owning2 = em.find(ManyToOneOwning.class, owning2.getId()); - owning2.setData("data2modified"); - em.merge(owning2); - em.getTransaction().commit(); - } + // Revision 3 + em.getTransaction().begin(); + owning2 = em.find( ManyToOneOwning.class, owning2.getId() ); + owning2.setData( "data2modified" ); + em.merge( owning2 ); + em.getTransaction().commit(); + } - @Test + @Test public void testRevisionsCounts() { - Assert.assertEquals(Arrays.asList(1, 2), getAuditReader().getRevisions(OneToManyOwned.class, ownedId)); - Assert.assertEquals(Arrays.asList(1, 2), getAuditReader().getRevisions(ManyToOneOwning.class, owning1Id)); - Assert.assertEquals(Arrays.asList(1, 3), getAuditReader().getRevisions(ManyToOneOwning.class, owning2Id)); - } + Assert.assertEquals( Arrays.asList( 1, 2 ), getAuditReader().getRevisions( OneToManyOwned.class, ownedId ) ); + Assert.assertEquals( Arrays.asList( 1, 2 ), getAuditReader().getRevisions( ManyToOneOwning.class, owning1Id ) ); + Assert.assertEquals( Arrays.asList( 1, 3 ), getAuditReader().getRevisions( ManyToOneOwning.class, owning2Id ) ); + } - @Test - public void testHistoryOfOwned() { - OneToManyOwned owned = new OneToManyOwned("data", null, ownedId); - ManyToOneOwning owning1 = new ManyToOneOwning("data1", owned, owning1Id); - ManyToOneOwning owning2 = new ManyToOneOwning("data2", owned, owning2Id); + @Test + public void testHistoryOfOwned() { + OneToManyOwned owned = new OneToManyOwned( "data", null, ownedId ); + ManyToOneOwning owning1 = new ManyToOneOwning( "data1", owned, owning1Id ); + ManyToOneOwning owning2 = new ManyToOneOwning( "data2", owned, owning2Id ); - OneToManyOwned ver1 = getAuditReader().find(OneToManyOwned.class, ownedId, 1); - Assert.assertEquals(owned, ver1); - Assert.assertEquals(TestTools.makeSet(owning1, owning2), ver1.getReferencing()); + OneToManyOwned ver1 = getAuditReader().find( OneToManyOwned.class, ownedId, 1 ); + Assert.assertEquals( owned, ver1 ); + Assert.assertEquals( TestTools.makeSet( owning1, owning2 ), ver1.getReferencing() ); - OneToManyOwned ver2 = getAuditReader().find(OneToManyOwned.class, ownedId, 2); - Assert.assertEquals(owned, ver2); - Assert.assertEquals(TestTools.makeSet(owning2), ver2.getReferencing()); - } + OneToManyOwned ver2 = getAuditReader().find( OneToManyOwned.class, ownedId, 2 ); + Assert.assertEquals( owned, ver2 ); + Assert.assertEquals( TestTools.makeSet( owning2 ), ver2.getReferencing() ); + } - @Test - public void testHistoryOfOwning1() { - ManyToOneOwning ver1 = new ManyToOneOwning("data1", null, owning1Id); - Assert.assertEquals(ver1, getAuditReader().find(ManyToOneOwning.class, owning1Id, 1)); - } + @Test + public void testHistoryOfOwning1() { + ManyToOneOwning ver1 = new ManyToOneOwning( "data1", null, owning1Id ); + Assert.assertEquals( ver1, getAuditReader().find( ManyToOneOwning.class, owning1Id, 1 ) ); + } - @Test - public void testHistoryOfOwning2() { - OneToManyOwned owned = new OneToManyOwned("data", null, ownedId); - ManyToOneOwning owning1 = new ManyToOneOwning("data2", owned, owning2Id); - ManyToOneOwning owning3 = new ManyToOneOwning("data2modified", owned, owning2Id); + @Test + public void testHistoryOfOwning2() { + OneToManyOwned owned = new OneToManyOwned( "data", null, ownedId ); + ManyToOneOwning owning1 = new ManyToOneOwning( "data2", owned, owning2Id ); + ManyToOneOwning owning3 = new ManyToOneOwning( "data2modified", owned, owning2Id ); - ManyToOneOwning ver1 = getAuditReader().find(ManyToOneOwning.class, owning2Id, 1); - ManyToOneOwning ver3 = getAuditReader().find(ManyToOneOwning.class, owning2Id, 3); + ManyToOneOwning ver1 = getAuditReader().find( ManyToOneOwning.class, owning2Id, 1 ); + ManyToOneOwning ver3 = getAuditReader().find( ManyToOneOwning.class, owning2Id, 3 ); - Assert.assertEquals(owning1, ver1); - Assert.assertEquals(owned.getId(), ver1.getReferences().getId()); - Assert.assertEquals(owning3, ver3); - Assert.assertEquals(owned.getId(), ver3.getReferences().getId()); - } + Assert.assertEquals( owning1, ver1 ); + Assert.assertEquals( owned.getId(), ver1.getReferences().getId() ); + Assert.assertEquals( owning3, ver3 ); + Assert.assertEquals( owned.getId(), ver3.getReferences().getId() ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytoone/bidirectional/ManyToOneOwning.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytoone/bidirectional/ManyToOneOwning.java index 36cc49aeb9..38536a9745 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytoone/bidirectional/ManyToOneOwning.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytoone/bidirectional/ManyToOneOwning.java @@ -1,12 +1,12 @@ package org.hibernate.envers.test.integration.manytoone.bidirectional; -import java.io.Serializable; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; import javax.persistence.ManyToOne; +import java.io.Serializable; import org.hibernate.envers.Audited; @@ -16,77 +16,85 @@ import org.hibernate.envers.Audited; @Entity @Audited public class ManyToOneOwning implements Serializable { - @Id - @GeneratedValue - private Long id; + @Id + @GeneratedValue + private Long id; - private String data; + private String data; - @ManyToOne - @JoinTable(name = "many_to_one_join_table", joinColumns = @JoinColumn(name = "owning_id"), - inverseJoinColumns = @JoinColumn(name = "owned_id")) - private OneToManyOwned references; + @ManyToOne + @JoinTable(name = "many_to_one_join_table", joinColumns = @JoinColumn(name = "owning_id"), + inverseJoinColumns = @JoinColumn(name = "owned_id")) + private OneToManyOwned references; - public ManyToOneOwning() { - } + public ManyToOneOwning() { + } - public ManyToOneOwning(String data, OneToManyOwned references) { - this.data = data; - this.references = references; - } + public ManyToOneOwning(String data, OneToManyOwned references) { + this.data = data; + this.references = references; + } - public ManyToOneOwning(String data, OneToManyOwned references, Long id) { - this.id = id; - this.data = data; - this.references = references; - } + public ManyToOneOwning(String data, OneToManyOwned references, Long id) { + this.id = id; + this.data = data; + this.references = references; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ManyToOneOwning)) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ManyToOneOwning) ) { + return false; + } - ManyToOneOwning that = (ManyToOneOwning) o; + ManyToOneOwning that = (ManyToOneOwning) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - int result = id != null ? id.hashCode() : 0; - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = id != null ? id.hashCode() : 0; + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - @Override - public String toString() { - return "ManyToOneOwning(id = " + id + ", data = " + data + ")"; - } + @Override + public String toString() { + return "ManyToOneOwning(id = " + id + ", data = " + data + ")"; + } - public Long getId() { - return id; - } + public Long getId() { + return id; + } - public void setId(Long id) { - this.id = id; - } + public void setId(Long id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public OneToManyOwned getReferences() { - return references; - } + public OneToManyOwned getReferences() { + return references; + } - public void setReferences(OneToManyOwned references) { - this.references = references; - } + public void setReferences(OneToManyOwned references) { + this.references = references; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytoone/bidirectional/OneToManyOwned.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytoone/bidirectional/OneToManyOwned.java index b91a373ec4..7f5d7b9147 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytoone/bidirectional/OneToManyOwned.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytoone/bidirectional/OneToManyOwned.java @@ -1,12 +1,12 @@ package org.hibernate.envers.test.integration.manytoone.bidirectional; -import java.io.Serializable; -import java.util.HashSet; -import java.util.Set; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.OneToMany; +import java.io.Serializable; +import java.util.HashSet; +import java.util.Set; import org.hibernate.envers.Audited; @@ -16,75 +16,83 @@ import org.hibernate.envers.Audited; @Entity @Audited public class OneToManyOwned implements Serializable { - @Id - @GeneratedValue - private Long id; + @Id + @GeneratedValue + private Long id; - private String data; + private String data; - @OneToMany(mappedBy="references") - private Set referencing = new HashSet(); + @OneToMany(mappedBy = "references") + private Set referencing = new HashSet(); - public OneToManyOwned() { - } + public OneToManyOwned() { + } - public OneToManyOwned(String data, Set referencing) { - this.data = data; - this.referencing = referencing; - } + public OneToManyOwned(String data, Set referencing) { + this.data = data; + this.referencing = referencing; + } - public OneToManyOwned(String data, Set referencing, Long id) { - this.id = id; - this.data = data; - this.referencing = referencing; - } + public OneToManyOwned(String data, Set referencing, Long id) { + this.id = id; + this.data = data; + this.referencing = referencing; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof OneToManyOwned)) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof OneToManyOwned) ) { + return false; + } - OneToManyOwned that = (OneToManyOwned) o; + OneToManyOwned that = (OneToManyOwned) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - int result = id != null ? id.hashCode() : 0; - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = id != null ? id.hashCode() : 0; + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - @Override - public String toString() { - return "OneToManyOwned(id = " + id + ", data = " + data + ")"; - } + @Override + public String toString() { + return "OneToManyOwned(id = " + id + ", data = " + data + ")"; + } - public Long getId() { - return id; - } + public Long getId() { + return id; + } - public void setId(Long id) { - this.id = id; - } + public void setId(Long id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public Set getReferencing() { - return referencing; - } + public Set getReferencing() { + return referencing; + } - public void setReferencing(Set referencing) { - this.referencing = referencing; - } + public void setReferencing(Set referencing) { + this.referencing = referencing; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytoone/unidirectional/RelationNotAuditedTarget.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytoone/unidirectional/RelationNotAuditedTarget.java index a2f5592cc7..9b701d4da7 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytoone/unidirectional/RelationNotAuditedTarget.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytoone/unidirectional/RelationNotAuditedTarget.java @@ -23,11 +23,9 @@ */ package org.hibernate.envers.test.integration.manytoone.unidirectional; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.List; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.Hibernate; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; @@ -37,6 +35,8 @@ import org.hibernate.envers.test.entities.manytoone.unidirectional.TargetNotAudi import org.hibernate.proxy.HibernateProxy; import org.hibernate.proxy.HibernateProxyHelper; +import org.junit.Test; + /** * @author Tomasz Bech */ @@ -49,69 +49,69 @@ public class RelationNotAuditedTarget extends BaseEnversJPAFunctionalTestCase { @Override protected Class[] getAnnotatedClasses() { - return new Class[] { TargetNotAuditedEntity.class, UnversionedStrTestEntity.class }; + return new Class[] {TargetNotAuditedEntity.class, UnversionedStrTestEntity.class}; } @Test - @Priority(10) + @Priority(10) public void initData() { EntityManager em = getEntityManager(); - UnversionedStrTestEntity uste1 = new UnversionedStrTestEntity("str1"); - UnversionedStrTestEntity uste2 = new UnversionedStrTestEntity("str2"); + UnversionedStrTestEntity uste1 = new UnversionedStrTestEntity( "str1" ); + UnversionedStrTestEntity uste2 = new UnversionedStrTestEntity( "str2" ); // No revision em.getTransaction().begin(); - em.persist(uste1); - em.persist(uste2); + em.persist( uste1 ); + em.persist( uste2 ); em.getTransaction().commit(); // Revision 1 em.getTransaction().begin(); - uste1 = em.find(UnversionedStrTestEntity.class, uste1.getId()); - uste2 = em.find(UnversionedStrTestEntity.class, uste2.getId()); + uste1 = em.find( UnversionedStrTestEntity.class, uste1.getId() ); + uste2 = em.find( UnversionedStrTestEntity.class, uste2.getId() ); - TargetNotAuditedEntity tnae1 = new TargetNotAuditedEntity(1, "tnae1", uste1); - TargetNotAuditedEntity tnae2 = new TargetNotAuditedEntity(2, "tnae2", uste2); - em.persist(tnae1); - em.persist(tnae2); + TargetNotAuditedEntity tnae1 = new TargetNotAuditedEntity( 1, "tnae1", uste1 ); + TargetNotAuditedEntity tnae2 = new TargetNotAuditedEntity( 2, "tnae2", uste2 ); + em.persist( tnae1 ); + em.persist( tnae2 ); em.getTransaction().commit(); // Revision 2 em.getTransaction().begin(); - tnae1 = em.find(TargetNotAuditedEntity.class, tnae1.getId()); - tnae2 = em.find(TargetNotAuditedEntity.class, tnae2.getId()); + tnae1 = em.find( TargetNotAuditedEntity.class, tnae1.getId() ); + tnae2 = em.find( TargetNotAuditedEntity.class, tnae2.getId() ); - tnae1.setReference(uste2); - tnae2.setReference(uste1); + tnae1.setReference( uste2 ); + tnae2.setReference( uste1 ); em.getTransaction().commit(); // Revision 3 em.getTransaction().begin(); - tnae1 = em.find(TargetNotAuditedEntity.class, tnae1.getId()); - tnae2 = em.find(TargetNotAuditedEntity.class, tnae2.getId()); + tnae1 = em.find( TargetNotAuditedEntity.class, tnae1.getId() ); + tnae2 = em.find( TargetNotAuditedEntity.class, tnae2.getId() ); //field not changed!!! - tnae1.setReference(uste2); - tnae2.setReference(uste2); + tnae1.setReference( uste2 ); + tnae2.setReference( uste2 ); em.getTransaction().commit(); // Revision 4 em.getTransaction().begin(); - tnae1 = em.find(TargetNotAuditedEntity.class, tnae1.getId()); - tnae2 = em.find(TargetNotAuditedEntity.class, tnae2.getId()); + tnae1 = em.find( TargetNotAuditedEntity.class, tnae1.getId() ); + tnae2 = em.find( TargetNotAuditedEntity.class, tnae2.getId() ); - tnae1.setReference(uste1); - tnae2.setReference(uste1); + tnae1.setReference( uste1 ); + tnae2.setReference( uste1 ); em.getTransaction().commit(); @@ -124,49 +124,49 @@ public class RelationNotAuditedTarget extends BaseEnversJPAFunctionalTestCase { @Test public void testRevisionsCounts() { - List revisions = getAuditReader().getRevisions(TargetNotAuditedEntity.class, tnae1_id); - assert Arrays.asList(1, 2, 4).equals(revisions); - revisions = getAuditReader().getRevisions(TargetNotAuditedEntity.class, tnae2_id); - assert Arrays.asList(1, 2, 3, 4).equals(revisions); + List revisions = getAuditReader().getRevisions( TargetNotAuditedEntity.class, tnae1_id ); + assert Arrays.asList( 1, 2, 4 ).equals( revisions ); + revisions = getAuditReader().getRevisions( TargetNotAuditedEntity.class, tnae2_id ); + assert Arrays.asList( 1, 2, 3, 4 ).equals( revisions ); } @Test public void testHistoryOfTnae1_id() { // load original "tnae1" TargetNotAuditedEntity to force load "str1" UnversionedStrTestEntity as Proxy - TargetNotAuditedEntity original = getEntityManager().find(TargetNotAuditedEntity.class, tnae1_id); + TargetNotAuditedEntity original = getEntityManager().find( TargetNotAuditedEntity.class, tnae1_id ); - UnversionedStrTestEntity uste1 = getEntityManager().find(UnversionedStrTestEntity.class, uste1_id); - UnversionedStrTestEntity uste2 = getEntityManager().find(UnversionedStrTestEntity.class, uste2_id); + UnversionedStrTestEntity uste1 = getEntityManager().find( UnversionedStrTestEntity.class, uste1_id ); + UnversionedStrTestEntity uste2 = getEntityManager().find( UnversionedStrTestEntity.class, uste2_id ); - TargetNotAuditedEntity rev1 = getAuditReader().find(TargetNotAuditedEntity.class, tnae1_id, 1); - TargetNotAuditedEntity rev2 = getAuditReader().find(TargetNotAuditedEntity.class, tnae1_id, 2); - TargetNotAuditedEntity rev3 = getAuditReader().find(TargetNotAuditedEntity.class, tnae1_id, 3); - TargetNotAuditedEntity rev4 = getAuditReader().find(TargetNotAuditedEntity.class, tnae1_id, 4); + TargetNotAuditedEntity rev1 = getAuditReader().find( TargetNotAuditedEntity.class, tnae1_id, 1 ); + TargetNotAuditedEntity rev2 = getAuditReader().find( TargetNotAuditedEntity.class, tnae1_id, 2 ); + TargetNotAuditedEntity rev3 = getAuditReader().find( TargetNotAuditedEntity.class, tnae1_id, 3 ); + TargetNotAuditedEntity rev4 = getAuditReader().find( TargetNotAuditedEntity.class, tnae1_id, 4 ); - assert rev1.getReference().equals(uste1); - assert rev2.getReference().equals(uste2); - assert rev3.getReference().equals(uste2); - assert rev4.getReference().equals(uste1); + assert rev1.getReference().equals( uste1 ); + assert rev2.getReference().equals( uste2 ); + assert rev3.getReference().equals( uste2 ); + assert rev4.getReference().equals( uste1 ); assert original.getReference() instanceof HibernateProxy; - assert UnversionedStrTestEntity.class.equals(Hibernate.getClass(original.getReference())); - assert UnversionedStrTestEntity.class.equals(HibernateProxyHelper.getClassWithoutInitializingProxy(rev1.getReference())); - assert UnversionedStrTestEntity.class.equals(Hibernate.getClass(rev1.getReference())); + assert UnversionedStrTestEntity.class.equals( Hibernate.getClass( original.getReference() ) ); + assert UnversionedStrTestEntity.class.equals( HibernateProxyHelper.getClassWithoutInitializingProxy( rev1.getReference() ) ); + assert UnversionedStrTestEntity.class.equals( Hibernate.getClass( rev1.getReference() ) ); } @Test public void testHistoryOfTnae2_id() { - UnversionedStrTestEntity uste1 = getEntityManager().find(UnversionedStrTestEntity.class, uste1_id); - UnversionedStrTestEntity uste2 = getEntityManager().find(UnversionedStrTestEntity.class, uste2_id); + UnversionedStrTestEntity uste1 = getEntityManager().find( UnversionedStrTestEntity.class, uste1_id ); + UnversionedStrTestEntity uste2 = getEntityManager().find( UnversionedStrTestEntity.class, uste2_id ); - TargetNotAuditedEntity rev1 = getAuditReader().find(TargetNotAuditedEntity.class, tnae2_id, 1); - TargetNotAuditedEntity rev2 = getAuditReader().find(TargetNotAuditedEntity.class, tnae2_id, 2); - TargetNotAuditedEntity rev3 = getAuditReader().find(TargetNotAuditedEntity.class, tnae2_id, 3); - TargetNotAuditedEntity rev4 = getAuditReader().find(TargetNotAuditedEntity.class, tnae2_id, 4); + TargetNotAuditedEntity rev1 = getAuditReader().find( TargetNotAuditedEntity.class, tnae2_id, 1 ); + TargetNotAuditedEntity rev2 = getAuditReader().find( TargetNotAuditedEntity.class, tnae2_id, 2 ); + TargetNotAuditedEntity rev3 = getAuditReader().find( TargetNotAuditedEntity.class, tnae2_id, 3 ); + TargetNotAuditedEntity rev4 = getAuditReader().find( TargetNotAuditedEntity.class, tnae2_id, 4 ); - assert rev1.getReference().equals(uste2); - assert rev2.getReference().equals(uste1); - assert rev3.getReference().equals(uste2); - assert rev4.getReference().equals(uste1); + assert rev1.getReference().equals( uste2 ); + assert rev2.getReference().equals( uste1 ); + assert rev3.getReference().equals( uste2 ); + assert rev4.getReference().equals( uste1 ); } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/merge/AddDelTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/merge/AddDelTest.java index fc0530472e..b7afd264cb 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/merge/AddDelTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/merge/AddDelTest.java @@ -2,13 +2,14 @@ package org.hibernate.envers.test.integration.merge; import java.util.Arrays; -import org.junit.Assert; -import org.junit.Test; - import org.hibernate.Session; import org.hibernate.envers.test.BaseEnversFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrTestEntity; + +import org.junit.Assert; +import org.junit.Test; + import org.hibernate.testing.TestForIssue; /** @@ -16,53 +17,59 @@ import org.hibernate.testing.TestForIssue; */ @TestForIssue(jiraKey = "HHH-6753") public class AddDelTest extends BaseEnversFunctionalTestCase { - @Override - protected Class[] getAnnotatedClasses() { - return new Class[]{StrTestEntity.class, GivenIdStrEntity.class}; - } + @Override + protected Class[] getAnnotatedClasses() { + return new Class[] {StrTestEntity.class, GivenIdStrEntity.class}; + } - @Test - @Priority(10) - public void initData() { - // Revision 1 - Session session = openSession(); - session.getTransaction().begin(); - GivenIdStrEntity entity = new GivenIdStrEntity(1, "data"); - session.persist(entity); - session.getTransaction().commit(); + @Test + @Priority(10) + public void initData() { + // Revision 1 + Session session = openSession(); + session.getTransaction().begin(); + GivenIdStrEntity entity = new GivenIdStrEntity( 1, "data" ); + session.persist( entity ); + session.getTransaction().commit(); - // Revision 2 - session.getTransaction().begin(); - session.persist(new StrTestEntity("another data")); // Just to create second revision. - entity = (GivenIdStrEntity) session.get(GivenIdStrEntity.class, 1); - session.delete(entity); // First try to remove the entity. - session.save(entity); // Then save it. - session.getTransaction().commit(); + // Revision 2 + session.getTransaction().begin(); + session.persist( new StrTestEntity( "another data" ) ); // Just to create second revision. + entity = (GivenIdStrEntity) session.get( GivenIdStrEntity.class, 1 ); + session.delete( entity ); // First try to remove the entity. + session.save( entity ); // Then save it. + session.getTransaction().commit(); - // Revision 3 - session.getTransaction().begin(); - entity = (GivenIdStrEntity) session.get(GivenIdStrEntity.class, 1); - session.delete(entity); // First try to remove the entity. - entity.setData("modified data"); // Then change it's state. - session.save(entity); // Finally save it. - session.getTransaction().commit(); + // Revision 3 + session.getTransaction().begin(); + entity = (GivenIdStrEntity) session.get( GivenIdStrEntity.class, 1 ); + session.delete( entity ); // First try to remove the entity. + entity.setData( "modified data" ); // Then change it's state. + session.save( entity ); // Finally save it. + session.getTransaction().commit(); - session.close(); - } + session.close(); + } - @Test - public void testRevisionsCountOfGivenIdStrEntity() { - // Revision 2 has not changed entity's state. - Assert.assertEquals(Arrays.asList(1, 3), getAuditReader().getRevisions(GivenIdStrEntity.class, 1)); + @Test + public void testRevisionsCountOfGivenIdStrEntity() { + // Revision 2 has not changed entity's state. + Assert.assertEquals( Arrays.asList( 1, 3 ), getAuditReader().getRevisions( GivenIdStrEntity.class, 1 ) ); - getSession().close(); - } + getSession().close(); + } - @Test - public void testHistoryOfGivenIdStrEntity() { - Assert.assertEquals(new GivenIdStrEntity(1, "data"), getAuditReader().find(GivenIdStrEntity.class, 1, 1)); - Assert.assertEquals(new GivenIdStrEntity(1, "modified data"), getAuditReader().find(GivenIdStrEntity.class, 1, 3)); + @Test + public void testHistoryOfGivenIdStrEntity() { + Assert.assertEquals( new GivenIdStrEntity( 1, "data" ), getAuditReader().find( GivenIdStrEntity.class, 1, 1 ) ); + Assert.assertEquals( + new GivenIdStrEntity( 1, "modified data" ), getAuditReader().find( + GivenIdStrEntity.class, + 1, + 3 + ) + ); - getSession().close(); - } + getSession().close(); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/merge/GivenIdStrEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/merge/GivenIdStrEntity.java index 9981928b2d..4ce7415928 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/merge/GivenIdStrEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/merge/GivenIdStrEntity.java @@ -13,57 +13,65 @@ import org.hibernate.envers.Audited; @Audited @AuditTable("GIVENIDSTRENTITY_AUD") public class GivenIdStrEntity { - @Id - private Integer id; + @Id + private Integer id; - private String data; + private String data; - public GivenIdStrEntity() { - } + public GivenIdStrEntity() { + } - public GivenIdStrEntity(Integer id, String data) { - this.id = id; - this.data = data; - } + public GivenIdStrEntity(Integer id, String data) { + this.id = id; + this.data = data; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof GivenIdStrEntity)) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof GivenIdStrEntity) ) { + return false; + } - GivenIdStrEntity that = (GivenIdStrEntity) o; + GivenIdStrEntity that = (GivenIdStrEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - int result = id != null ? id.hashCode() : 0; - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = id != null ? id.hashCode() : 0; + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - @Override - public String toString() { - return "GivenIdStrEntity(id = " + id + ", data = " + data + ")"; - } + @Override + public String toString() { + return "GivenIdStrEntity(id = " + id + ", data = " + data + ")"; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/AbstractModifiedFlagsEntityTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/AbstractModifiedFlagsEntityTest.java index 59998f8ad5..ad6ffe2c36 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/AbstractModifiedFlagsEntityTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/AbstractModifiedFlagsEntityTest.java @@ -33,15 +33,15 @@ import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; /** * Base test for modified flags feature - * + * * @author Michal Skowronek (mskowr at o2 dot pl) */ public abstract class AbstractModifiedFlagsEntityTest extends BaseEnversJPAFunctionalTestCase { @Override protected void addConfigOptions(Map options) { - super.addConfigOptions(options); - if (forceModifiedFlags()) { - options.put(EnversSettings.GLOBAL_WITH_MODIFIED_FLAG, "true"); + super.addConfigOptions( options ); + if ( forceModifiedFlags() ) { + options.put( EnversSettings.GLOBAL_WITH_MODIFIED_FLAG, "true" ); } } @@ -49,52 +49,58 @@ public abstract class AbstractModifiedFlagsEntityTest extends BaseEnversJPAFunct return true; } - protected List queryForPropertyHasChanged(Class clazz, Object id, - String... propertyNames) { - AuditQuery query = createForRevisionsQuery(clazz, id, false); - addHasChangedProperties(query, propertyNames); + protected List queryForPropertyHasChanged( + Class clazz, Object id, + String... propertyNames) { + AuditQuery query = createForRevisionsQuery( clazz, id, false ); + addHasChangedProperties( query, propertyNames ); return query.getResultList(); } - protected List queryForPropertyHasChangedWithDeleted(Class clazz, Object id, - String... propertyNames) { - AuditQuery query = createForRevisionsQuery(clazz, id, true); - addHasChangedProperties(query, propertyNames); + protected List queryForPropertyHasChangedWithDeleted( + Class clazz, Object id, + String... propertyNames) { + AuditQuery query = createForRevisionsQuery( clazz, id, true ); + addHasChangedProperties( query, propertyNames ); return query.getResultList(); } - protected List queryForPropertyHasNotChanged(Class clazz, Object id, - String... propertyNames) { - AuditQuery query = createForRevisionsQuery(clazz, id, false); - addHasNotChangedProperties(query, propertyNames); + protected List queryForPropertyHasNotChanged( + Class clazz, Object id, + String... propertyNames) { + AuditQuery query = createForRevisionsQuery( clazz, id, false ); + addHasNotChangedProperties( query, propertyNames ); return query.getResultList(); } - protected List queryForPropertyHasNotChangedWithDeleted(Class clazz, Object id, - String... propertyNames) { - AuditQuery query = createForRevisionsQuery(clazz, id, true); - addHasNotChangedProperties(query, propertyNames); + protected List queryForPropertyHasNotChangedWithDeleted( + Class clazz, Object id, + String... propertyNames) { + AuditQuery query = createForRevisionsQuery( clazz, id, true ); + addHasNotChangedProperties( query, propertyNames ); return query.getResultList(); } - private void addHasChangedProperties(AuditQuery query, - String[] propertyNames) { - for (String propertyName : propertyNames) { - query.add(AuditEntity.property(propertyName).hasChanged()); + private void addHasChangedProperties( + AuditQuery query, + String[] propertyNames) { + for ( String propertyName : propertyNames ) { + query.add( AuditEntity.property( propertyName ).hasChanged() ); } } - private void addHasNotChangedProperties(AuditQuery query, - String[] propertyNames) { - for (String propertyName : propertyNames) { - query.add(AuditEntity.property(propertyName).hasNotChanged()); + private void addHasNotChangedProperties( + AuditQuery query, + String[] propertyNames) { + for ( String propertyName : propertyNames ) { + query.add( AuditEntity.property( propertyName ).hasNotChanged() ); } } private AuditQuery createForRevisionsQuery(Class clazz, Object id, boolean withDeleted) { return getAuditReader().createQuery() - .forRevisionsOfEntity(clazz, false, withDeleted) - .add(AuditEntity.id().eq(id)); + .forRevisionsOfEntity( clazz, false, withDeleted ) + .add( AuditEntity.id().eq( id ) ); } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/AbstractModifiedFlagsOneSessionTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/AbstractModifiedFlagsOneSessionTest.java index 48372fbead..dd605196f6 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/AbstractModifiedFlagsOneSessionTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/AbstractModifiedFlagsOneSessionTest.java @@ -29,17 +29,17 @@ import org.hibernate.envers.test.AbstractOneSessionTest; /** * Base test for modified flags feature - * + * * @author Michal Skowronek (mskowr at o2 dot pl) */ public abstract class AbstractModifiedFlagsOneSessionTest extends - AbstractOneSessionTest { + AbstractOneSessionTest { @Override protected void addProperties(Configuration configuration) { - super.addProperties(configuration); - if (forceModifiedFlags()) { - configuration.setProperty(EnversSettings.GLOBAL_WITH_MODIFIED_FLAG, "true"); + super.addProperties( configuration ); + if ( forceModifiedFlags() ) { + configuration.setProperty( EnversSettings.GLOBAL_WITH_MODIFIED_FLAG, "true" ); } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedAPITest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedAPITest.java index c8653307c3..88dcc2bbae 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedAPITest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedAPITest.java @@ -23,63 +23,63 @@ */ package org.hibernate.envers.test.integration.modifiedflags; -import java.util.List; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.List; import org.hibernate.envers.query.AuditEntity; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.integration.auditReader.AuditedTestEntity; import org.hibernate.envers.test.integration.auditReader.NotAuditedTestEntity; +import org.junit.Test; + import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertTrue; /** * A test which checks the correct behavior of AuditReader.isEntityClassAudited(Class entityClass). - * + * * @author Hernan Chanfreau * @author Michal Skowronek (mskowr at o2 dot pl) */ public class HasChangedAPITest extends AbstractModifiedFlagsEntityTest { @Override protected Class[] getAnnotatedClasses() { - return new Class[] { AuditedTestEntity.class, NotAuditedTestEntity.class }; - } + return new Class[] {AuditedTestEntity.class, NotAuditedTestEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); - em.getTransaction().begin(); - AuditedTestEntity ent1 = new AuditedTestEntity(1, "str1"); - NotAuditedTestEntity ent2 = new NotAuditedTestEntity(1, "str1"); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); + em.getTransaction().begin(); + AuditedTestEntity ent1 = new AuditedTestEntity( 1, "str1" ); + NotAuditedTestEntity ent2 = new NotAuditedTestEntity( 1, "str1" ); - em.persist(ent1); - em.persist(ent2); - em.getTransaction().commit(); + em.persist( ent1 ); + em.persist( ent2 ); + em.getTransaction().commit(); - em.getTransaction().begin(); + em.getTransaction().begin(); - ent1 = em.find(AuditedTestEntity.class, 1); - ent2 = em.find(NotAuditedTestEntity.class, 1); - ent1.setStr1("str2"); - ent2.setStr1("str2"); - em.getTransaction().commit(); - } + ent1 = em.find( AuditedTestEntity.class, 1 ); + ent2 = em.find( NotAuditedTestEntity.class, 1 ); + ent1.setStr1( "str2" ); + ent2.setStr1( "str2" ); + em.getTransaction().commit(); + } - @Test + @Test public void testHasChangedHasNotChangedCriteria() throws Exception { - List list = getAuditReader().createQuery().forRevisionsOfEntity(AuditedTestEntity.class, true, true) - .add(AuditEntity.property("str1").hasChanged()).getResultList(); - assertEquals(2, list.size()); - assertEquals("str1", ((AuditedTestEntity) list.get(0)).getStr1()); - assertEquals("str2", ((AuditedTestEntity) list.get(1)).getStr1()); + List list = getAuditReader().createQuery().forRevisionsOfEntity( AuditedTestEntity.class, true, true ) + .add( AuditEntity.property( "str1" ).hasChanged() ).getResultList(); + assertEquals( 2, list.size() ); + assertEquals( "str1", ((AuditedTestEntity) list.get( 0 )).getStr1() ); + assertEquals( "str2", ((AuditedTestEntity) list.get( 1 )).getStr1() ); - list = getAuditReader().createQuery().forRevisionsOfEntity(AuditedTestEntity.class, true, true) - .add(AuditEntity.property("str1").hasNotChanged()).getResultList(); - assertTrue(list.isEmpty()); + list = getAuditReader().createQuery().forRevisionsOfEntity( AuditedTestEntity.class, true, true ) + .add( AuditEntity.property( "str1" ).hasNotChanged() ).getResultList(); + assertTrue( list.isEmpty() ); } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedAuditedManyToManyTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedAuditedManyToManyTest.java index 6cbda2db5a..3df9dd68db 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedAuditedManyToManyTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedAuditedManyToManyTest.java @@ -6,14 +6,14 @@ import java.net.URL; import java.util.ArrayList; import java.util.List; -import org.junit.Test; - import org.hibernate.MappingException; import org.hibernate.envers.query.AuditEntity; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.integration.entityNames.manyToManyAudited.Car; import org.hibernate.envers.test.integration.entityNames.manyToManyAudited.Person; +import org.junit.Test; + import static junit.framework.Assert.assertEquals; import static org.hibernate.envers.test.tools.TestTools.extractRevisionNumbers; import static org.hibernate.envers.test.tools.TestTools.makeList; @@ -21,9 +21,8 @@ import static org.hibernate.envers.test.tools.TestTools.makeList; /** * @author Hernán Chanfreau * @author Michal Skowronek (mskowr at o2 dot pl) - * */ -public class HasChangedAuditedManyToManyTest extends AbstractModifiedFlagsOneSessionTest{ +public class HasChangedAuditedManyToManyTest extends AbstractModifiedFlagsOneSessionTest { private long id_car1; @@ -31,96 +30,98 @@ public class HasChangedAuditedManyToManyTest extends AbstractModifiedFlagsOneSes private long id_pers2; protected void initMappings() throws MappingException, URISyntaxException { - URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/entityNames/manyToManyAudited/mappings.hbm.xml"); - config.addFile(new File(url.toURI())); + URL url = Thread.currentThread().getContextClassLoader().getResource( + "mappings/entityNames/manyToManyAudited/mappings.hbm.xml" + ); + config.addFile( new File( url.toURI() ) ); } - @Test - @Priority(10) - public void initData() { - - initializeSession(); + @Test + @Priority(10) + public void initData() { - Person pers1 = new Person("Hernan", 28); - Person pers2 = new Person("Leandro", 29); - Person pers3 = new Person("Barba", 32); - Person pers4 = new Person("Camomo", 15); + initializeSession(); - //REV 1 - getSession().getTransaction().begin(); - List owners = new ArrayList(); - owners.add(pers1); - owners.add(pers2); - owners.add(pers3); - Car car1 = new Car(5, owners); + Person pers1 = new Person( "Hernan", 28 ); + Person pers2 = new Person( "Leandro", 29 ); + Person pers3 = new Person( "Barba", 32 ); + Person pers4 = new Person( "Camomo", 15 ); - getSession().persist(car1); - getSession().getTransaction().commit(); - id_pers1 = pers1.getId(); - id_car1 = car1.getId(); + //REV 1 + getSession().getTransaction().begin(); + List owners = new ArrayList(); + owners.add( pers1 ); + owners.add( pers2 ); + owners.add( pers3 ); + Car car1 = new Car( 5, owners ); + + getSession().persist( car1 ); + getSession().getTransaction().commit(); + id_pers1 = pers1.getId(); + id_car1 = car1.getId(); id_pers2 = pers2.getId(); - owners = new ArrayList(); - owners.add(pers2); - owners.add(pers3); - owners.add(pers4); - Car car2 = new Car(27, owners); - //REV 2 - getSession().getTransaction().begin(); - Person person1 = (Person)getSession().get("Personaje", id_pers1); - person1.setName("Hernan David"); - person1.setAge(40); - getSession().persist(car1); - getSession().persist(car2); - getSession().getTransaction().commit(); + owners = new ArrayList(); + owners.add( pers2 ); + owners.add( pers3 ); + owners.add( pers4 ); + Car car2 = new Car( 27, owners ); + //REV 2 + getSession().getTransaction().begin(); + Person person1 = (Person) getSession().get( "Personaje", id_pers1 ); + person1.setName( "Hernan David" ); + person1.setAge( 40 ); + getSession().persist( car1 ); + getSession().persist( car2 ); + getSession().getTransaction().commit(); } @Test public void testHasChangedPerson1() throws Exception { - List list = getAuditReader().createQuery().forRevisionsOfEntity(Person.class, "Personaje", false, false) - .add(AuditEntity.id().eq(id_pers1)) - .add(AuditEntity.property("cars").hasChanged()) + List list = getAuditReader().createQuery().forRevisionsOfEntity( Person.class, "Personaje", false, false ) + .add( AuditEntity.id().eq( id_pers1 ) ) + .add( AuditEntity.property( "cars" ).hasChanged() ) .getResultList(); - assertEquals(1, list.size()); - assertEquals(makeList(1), extractRevisionNumbers(list)); + assertEquals( 1, list.size() ); + assertEquals( makeList( 1 ), extractRevisionNumbers( list ) ); - list = getAuditReader().createQuery().forRevisionsOfEntity(Person.class, "Personaje", false, false) - .add(AuditEntity.id().eq(id_pers1)) - .add(AuditEntity.property("cars").hasNotChanged()) + list = getAuditReader().createQuery().forRevisionsOfEntity( Person.class, "Personaje", false, false ) + .add( AuditEntity.id().eq( id_pers1 ) ) + .add( AuditEntity.property( "cars" ).hasNotChanged() ) .getResultList(); - assertEquals(1, list.size()); - assertEquals(makeList(2), extractRevisionNumbers(list)); + assertEquals( 1, list.size() ); + assertEquals( makeList( 2 ), extractRevisionNumbers( list ) ); } @Test public void testHasChangedPerson2() throws Exception { - List list = getAuditReader().createQuery().forRevisionsOfEntity(Person.class, "Personaje", false, false) - .add(AuditEntity.id().eq(id_pers2)) - .add(AuditEntity.property("cars").hasChanged()) + List list = getAuditReader().createQuery().forRevisionsOfEntity( Person.class, "Personaje", false, false ) + .add( AuditEntity.id().eq( id_pers2 ) ) + .add( AuditEntity.property( "cars" ).hasChanged() ) .getResultList(); - assertEquals(2, list.size()); - assertEquals(makeList(1, 2), extractRevisionNumbers(list)); + assertEquals( 2, list.size() ); + assertEquals( makeList( 1, 2 ), extractRevisionNumbers( list ) ); - list = getAuditReader().createQuery().forRevisionsOfEntity(Person.class, "Personaje", false, false) - .add(AuditEntity.id().eq(id_pers2)) - .add(AuditEntity.property("cars").hasNotChanged()) + list = getAuditReader().createQuery().forRevisionsOfEntity( Person.class, "Personaje", false, false ) + .add( AuditEntity.id().eq( id_pers2 ) ) + .add( AuditEntity.property( "cars" ).hasNotChanged() ) .getResultList(); - assertEquals(0, list.size()); + assertEquals( 0, list.size() ); } @Test public void testHasChangedCar1() throws Exception { - List list = getAuditReader().createQuery().forRevisionsOfEntity(Car.class, false, false) - .add(AuditEntity.id().eq(id_car1)) - .add(AuditEntity.property("owners").hasChanged()) + List list = getAuditReader().createQuery().forRevisionsOfEntity( Car.class, false, false ) + .add( AuditEntity.id().eq( id_car1 ) ) + .add( AuditEntity.property( "owners" ).hasChanged() ) .getResultList(); - assertEquals(1, list.size()); - assertEquals(makeList(1), extractRevisionNumbers(list)); + assertEquals( 1, list.size() ); + assertEquals( makeList( 1 ), extractRevisionNumbers( list ) ); - list = getAuditReader().createQuery().forRevisionsOfEntity(Car.class, false, false) - .add(AuditEntity.id().eq(id_car1)) - .add(AuditEntity.property("owners").hasNotChanged()) + list = getAuditReader().createQuery().forRevisionsOfEntity( Car.class, false, false ) + .add( AuditEntity.id().eq( id_car1 ) ) + .add( AuditEntity.property( "owners" ).hasNotChanged() ) .getResultList(); - assertEquals(0, list.size()); + assertEquals( 0, list.size() ); } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedBidirectional2.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedBidirectional2.java index 5b9c8d9873..77e0ceab75 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedBidirectional2.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedBidirectional2.java @@ -23,15 +23,15 @@ */ package org.hibernate.envers.test.integration.modifiedflags; -import java.util.List; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.List; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.integration.onetoone.bidirectional.BiRefEdEntity; import org.hibernate.envers.test.integration.onetoone.bidirectional.BiRefIngEntity; +import org.junit.Test; + import static junit.framework.Assert.assertEquals; import static org.hibernate.envers.test.tools.TestTools.extractRevisionNumbers; import static org.hibernate.envers.test.tools.TestTools.makeList; @@ -41,85 +41,89 @@ import static org.hibernate.envers.test.tools.TestTools.makeList; * @author Michal Skowronek (mskowr at o2 dot pl) */ public class HasChangedBidirectional2 extends AbstractModifiedFlagsEntityTest { - private Integer ed1_id; - private Integer ed2_id; + private Integer ed1_id; + private Integer ed2_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { BiRefEdEntity.class, BiRefIngEntity.class }; - } + return new Class[] {BiRefEdEntity.class, BiRefIngEntity.class}; + } - @Test - @Priority(10) - public void initData() { - BiRefEdEntity ed1 = new BiRefEdEntity(1, "data_ed_1"); - BiRefEdEntity ed2 = new BiRefEdEntity(2, "data_ed_2"); + @Test + @Priority(10) + public void initData() { + BiRefEdEntity ed1 = new BiRefEdEntity( 1, "data_ed_1" ); + BiRefEdEntity ed2 = new BiRefEdEntity( 2, "data_ed_2" ); - BiRefIngEntity ing1 = new BiRefIngEntity(3, "data_ing_1"); - BiRefIngEntity ing2 = new BiRefIngEntity(4, "data_ing_2"); + BiRefIngEntity ing1 = new BiRefIngEntity( 3, "data_ing_1" ); + BiRefIngEntity ing2 = new BiRefIngEntity( 4, "data_ing_2" ); - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); - em.persist(ed1); - em.persist(ed2); + em.persist( ed1 ); + em.persist( ed2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); + // Revision 2 + em.getTransaction().begin(); - ed1 = em.find(BiRefEdEntity.class, ed1.getId()); + ed1 = em.find( BiRefEdEntity.class, ed1.getId() ); - ing1.setReference(ed1); + ing1.setReference( ed1 ); - em.persist(ing1); - em.persist(ing2); + em.persist( ing1 ); + em.persist( ing2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 - em.getTransaction().begin(); + // Revision 3 + em.getTransaction().begin(); - ed1 = em.find(BiRefEdEntity.class, ed1.getId()); - ing1 = em.find(BiRefIngEntity.class, ing1.getId()); - ing2 = em.find(BiRefIngEntity.class, ing2.getId()); + ed1 = em.find( BiRefEdEntity.class, ed1.getId() ); + ing1 = em.find( BiRefIngEntity.class, ing1.getId() ); + ing2 = em.find( BiRefIngEntity.class, ing2.getId() ); - ing1.setReference(null); - ing2.setReference(ed1); + ing1.setReference( null ); + ing2.setReference( ed1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 4 - em.getTransaction().begin(); + // Revision 4 + em.getTransaction().begin(); - ed2 = em.find(BiRefEdEntity.class, ed2.getId()); - ing1 = em.find(BiRefIngEntity.class, ing1.getId()); - ing2 = em.find(BiRefIngEntity.class, ing2.getId()); + ed2 = em.find( BiRefEdEntity.class, ed2.getId() ); + ing1 = em.find( BiRefIngEntity.class, ing1.getId() ); + ing2 = em.find( BiRefIngEntity.class, ing2.getId() ); - ing1.setReference(ed2); - ing2.setReference(null); + ing1.setReference( ed2 ); + ing2.setReference( null ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // + // - ed1_id = ed1.getId(); - ed2_id = ed2.getId(); + ed1_id = ed1.getId(); + ed2_id = ed2.getId(); } @Test public void testHasChanged() throws Exception { - List list = queryForPropertyHasChanged(BiRefEdEntity.class, ed1_id, - "referencing"); - assertEquals(3, list.size()); - assertEquals(makeList(2, 3, 4), extractRevisionNumbers(list)); + List list = queryForPropertyHasChanged( + BiRefEdEntity.class, ed1_id, + "referencing" + ); + assertEquals( 3, list.size() ); + assertEquals( makeList( 2, 3, 4 ), extractRevisionNumbers( list ) ); - list = queryForPropertyHasChanged(BiRefEdEntity.class, ed2_id, - "referencing"); - assertEquals(1, list.size()); - assertEquals(makeList(4), extractRevisionNumbers(list)); + list = queryForPropertyHasChanged( + BiRefEdEntity.class, ed2_id, + "referencing" + ); + assertEquals( 1, list.size() ); + assertEquals( makeList( 4 ), extractRevisionNumbers( list ) ); } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedChildAuditing.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedChildAuditing.java index f32e8d5068..63aba97d17 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedChildAuditing.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedChildAuditing.java @@ -24,15 +24,15 @@ package org.hibernate.envers.test.integration.modifiedflags; -import java.util.List; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.List; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.integration.inheritance.joined.ChildEntity; import org.hibernate.envers.test.integration.inheritance.joined.ParentEntity; +import org.junit.Test; + import static junit.framework.Assert.assertEquals; import static org.hibernate.envers.test.tools.TestTools.extractRevisionNumbers; import static org.hibernate.envers.test.tools.TestTools.makeList; @@ -42,58 +42,58 @@ import static org.hibernate.envers.test.tools.TestTools.makeList; * @author Michal Skowronek (mskowr at o2 dot pl) */ public class HasChangedChildAuditing extends AbstractModifiedFlagsEntityTest { - private Integer id1; + private Integer id1; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { ChildEntity.class, ParentEntity.class }; - } + return new Class[] {ChildEntity.class, ParentEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - id1 = 1; + id1 = 1; - // Rev 1 - em.getTransaction().begin(); - ChildEntity ce = new ChildEntity(id1, "x", 1l); - em.persist(ce); - em.getTransaction().commit(); + // Rev 1 + em.getTransaction().begin(); + ChildEntity ce = new ChildEntity( id1, "x", 1l ); + em.persist( ce ); + em.getTransaction().commit(); - // Rev 2 - em.getTransaction().begin(); - ce = em.find(ChildEntity.class, id1); - ce.setData("y"); - ce.setNumVal(2l); - em.getTransaction().commit(); - } + // Rev 2 + em.getTransaction().begin(); + ce = em.find( ChildEntity.class, id1 ); + ce.setData( "y" ); + ce.setNumVal( 2l ); + em.getTransaction().commit(); + } @Test public void testChildHasChanged() throws Exception { - List list = queryForPropertyHasChanged(ChildEntity.class, id1, "data"); - assertEquals(2, list.size()); - assertEquals(makeList(1, 2), extractRevisionNumbers(list)); + List list = queryForPropertyHasChanged( ChildEntity.class, id1, "data" ); + assertEquals( 2, list.size() ); + assertEquals( makeList( 1, 2 ), extractRevisionNumbers( list ) ); - list = queryForPropertyHasChanged(ChildEntity.class, id1, "numVal"); - assertEquals(2, list.size()); - assertEquals(makeList(1, 2), extractRevisionNumbers(list)); + list = queryForPropertyHasChanged( ChildEntity.class, id1, "numVal" ); + assertEquals( 2, list.size() ); + assertEquals( makeList( 1, 2 ), extractRevisionNumbers( list ) ); - list = queryForPropertyHasNotChanged(ChildEntity.class, id1, "data"); - assertEquals(0, list.size()); + list = queryForPropertyHasNotChanged( ChildEntity.class, id1, "data" ); + assertEquals( 0, list.size() ); - list = queryForPropertyHasNotChanged(ChildEntity.class, id1, "numVal"); - assertEquals(0, list.size()); + list = queryForPropertyHasNotChanged( ChildEntity.class, id1, "numVal" ); + assertEquals( 0, list.size() ); } @Test public void testParentHasChanged() throws Exception { - List list = queryForPropertyHasChanged(ParentEntity.class, id1, "data"); - assertEquals(2, list.size()); - assertEquals(makeList(1, 2), extractRevisionNumbers(list)); + List list = queryForPropertyHasChanged( ParentEntity.class, id1, "data" ); + assertEquals( 2, list.size() ); + assertEquals( makeList( 1, 2 ), extractRevisionNumbers( list ) ); - list = queryForPropertyHasNotChanged(ParentEntity.class, id1, "data"); - assertEquals(0, list.size()); + list = queryForPropertyHasNotChanged( ParentEntity.class, id1, "data" ); + assertEquals( 0, list.size() ); } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedChildReferencing.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedChildReferencing.java index 97c11022ba..7f631613c2 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedChildReferencing.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedChildReferencing.java @@ -24,16 +24,16 @@ package org.hibernate.envers.test.integration.modifiedflags; -import java.util.List; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.List; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.integration.inheritance.joined.childrelation.ChildIngEntity; import org.hibernate.envers.test.integration.inheritance.joined.childrelation.ParentNotIngEntity; import org.hibernate.envers.test.integration.inheritance.joined.childrelation.ReferencedEntity; +import org.junit.Test; + import static junit.framework.Assert.assertEquals; import static org.hibernate.envers.test.tools.TestTools.extractRevisionNumbers; import static org.hibernate.envers.test.tools.TestTools.makeList; @@ -43,70 +43,70 @@ import static org.hibernate.envers.test.tools.TestTools.makeList; * @author Michal Skowronek (mskowr at o2 dot pl) */ public class HasChangedChildReferencing extends AbstractModifiedFlagsEntityTest { - private Integer re_id1; - private Integer re_id2; + private Integer re_id1; + private Integer re_id2; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { ChildIngEntity.class, ParentNotIngEntity.class, ReferencedEntity.class }; - } + return new Class[] {ChildIngEntity.class, ParentNotIngEntity.class, ReferencedEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - re_id1 = 1; - re_id2 = 10; + re_id1 = 1; + re_id2 = 10; Integer c_id = 100; - // Rev 1 - em.getTransaction().begin(); + // Rev 1 + em.getTransaction().begin(); - ReferencedEntity re1 = new ReferencedEntity(re_id1); - em.persist(re1); + ReferencedEntity re1 = new ReferencedEntity( re_id1 ); + em.persist( re1 ); - ReferencedEntity re2 = new ReferencedEntity(re_id2); - em.persist(re2); + ReferencedEntity re2 = new ReferencedEntity( re_id2 ); + em.persist( re2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Rev 2 - em.getTransaction().begin(); + // Rev 2 + em.getTransaction().begin(); - re1 = em.find(ReferencedEntity.class, re_id1); + re1 = em.find( ReferencedEntity.class, re_id1 ); - ChildIngEntity cie = new ChildIngEntity(c_id, "y", 1l); - cie.setReferenced(re1); - em.persist(cie); - c_id = cie.getId(); + ChildIngEntity cie = new ChildIngEntity( c_id, "y", 1l ); + cie.setReferenced( re1 ); + em.persist( cie ); + c_id = cie.getId(); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Rev 3 - em.getTransaction().begin(); + // Rev 3 + em.getTransaction().begin(); - re2 = em.find(ReferencedEntity.class, re_id2); - cie = em.find(ChildIngEntity.class, c_id); + re2 = em.find( ReferencedEntity.class, re_id2 ); + cie = em.find( ChildIngEntity.class, c_id ); - cie.setReferenced(re2); + cie.setReferenced( re2 ); - em.getTransaction().commit(); - } + em.getTransaction().commit(); + } @Test public void testReferencedEntityHasChanged() throws Exception { - List list = queryForPropertyHasChanged(ReferencedEntity.class, re_id1, "referencing"); - assertEquals(2, list.size()); - assertEquals(makeList(2, 3), extractRevisionNumbers(list)); + List list = queryForPropertyHasChanged( ReferencedEntity.class, re_id1, "referencing" ); + assertEquals( 2, list.size() ); + assertEquals( makeList( 2, 3 ), extractRevisionNumbers( list ) ); - list = queryForPropertyHasNotChanged(ReferencedEntity.class, re_id1, "referencing"); - assertEquals(1, list.size()); // initially referencing collection is null - assertEquals(makeList(1), extractRevisionNumbers(list)); + list = queryForPropertyHasNotChanged( ReferencedEntity.class, re_id1, "referencing" ); + assertEquals( 1, list.size() ); // initially referencing collection is null + assertEquals( makeList( 1 ), extractRevisionNumbers( list ) ); - list = queryForPropertyHasChanged(ReferencedEntity.class, re_id2, "referencing"); - assertEquals(1, list.size()); - assertEquals(makeList(3), extractRevisionNumbers(list)); + list = queryForPropertyHasChanged( ReferencedEntity.class, re_id2, "referencing" ); + assertEquals( 1, list.size() ); + assertEquals( makeList( 3 ), extractRevisionNumbers( list ) ); } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedComponentCollection.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedComponentCollection.java index 29de8400cd..49db29119a 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedComponentCollection.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedComponentCollection.java @@ -1,14 +1,15 @@ package org.hibernate.envers.test.integration.modifiedflags; -import java.util.List; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.List; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.collection.EmbeddableListEntity1; import org.hibernate.envers.test.entities.components.Component3; import org.hibernate.envers.test.entities.components.Component4; + +import org.junit.Test; + import org.hibernate.testing.TestForIssue; import static org.hibernate.envers.test.tools.TestTools.extractRevisionNumbers; @@ -18,7 +19,7 @@ import static org.junit.Assert.assertEquals; /** * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ -@TestForIssue( jiraKey = "HHH-6613" ) +@TestForIssue(jiraKey = "HHH-6613") public class HasChangedComponentCollection extends AbstractModifiedFlagsEntityTest { private Integer ele1_id = null; @@ -29,7 +30,7 @@ public class HasChangedComponentCollection extends AbstractModifiedFlagsEntityTe @Override protected Class[] getAnnotatedClasses() { - return new Class[] { EmbeddableListEntity1.class }; + return new Class[] {EmbeddableListEntity1.class}; } @Test diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedComponentMapKey.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedComponentMapKey.java index d66f46b00e..54909f5ea0 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedComponentMapKey.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedComponentMapKey.java @@ -23,10 +23,8 @@ */ package org.hibernate.envers.test.integration.modifiedflags; -import java.util.List; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.List; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.components.Component1; @@ -34,6 +32,8 @@ import org.hibernate.envers.test.entities.components.Component2; import org.hibernate.envers.test.entities.components.ComponentTestEntity; import org.hibernate.envers.test.integration.collection.mapkey.ComponentMapKeyEntity; +import org.junit.Test; + import static junit.framework.Assert.assertEquals; import static org.hibernate.envers.test.tools.TestTools.extractRevisionNumbers; import static org.hibernate.envers.test.tools.TestTools.makeList; @@ -43,83 +43,99 @@ import static org.hibernate.envers.test.tools.TestTools.makeList; * @author Michal Skowronek (mskowr at o2 dot pl) */ public class HasChangedComponentMapKey extends AbstractModifiedFlagsEntityTest { - private Integer cmke_id; + private Integer cmke_id; - private Integer cte1_id; - private Integer cte2_id; + private Integer cte1_id; + private Integer cte2_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { ComponentMapKeyEntity.class, ComponentTestEntity.class }; - } + return new Class[] {ComponentMapKeyEntity.class, ComponentTestEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - ComponentMapKeyEntity imke = new ComponentMapKeyEntity(); + ComponentMapKeyEntity imke = new ComponentMapKeyEntity(); - // Revision 1 (intialy 1 mapping) - em.getTransaction().begin(); + // Revision 1 (intialy 1 mapping) + em.getTransaction().begin(); - ComponentTestEntity cte1 = new ComponentTestEntity(new Component1("x1", "y2"), new Component2("a1", "b2")); - ComponentTestEntity cte2 = new ComponentTestEntity(new Component1("x1", "y2"), new Component2("a1", "b2")); + ComponentTestEntity cte1 = new ComponentTestEntity( + new Component1( "x1", "y2" ), new Component2( + "a1", + "b2" + ) + ); + ComponentTestEntity cte2 = new ComponentTestEntity( + new Component1( "x1", "y2" ), new Component2( + "a1", + "b2" + ) + ); - em.persist(cte1); - em.persist(cte2); + em.persist( cte1 ); + em.persist( cte2 ); - imke.getIdmap().put(cte1.getComp1(), cte1); + imke.getIdmap().put( cte1.getComp1(), cte1 ); - em.persist(imke); + em.persist( imke ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 (sse1: adding 1 mapping) - em.getTransaction().begin(); + // Revision 2 (sse1: adding 1 mapping) + em.getTransaction().begin(); - cte2 = em.find(ComponentTestEntity.class, cte2.getId()); - imke = em.find(ComponentMapKeyEntity.class, imke.getId()); + cte2 = em.find( ComponentTestEntity.class, cte2.getId() ); + imke = em.find( ComponentMapKeyEntity.class, imke.getId() ); - imke.getIdmap().put(cte2.getComp1(), cte2); + imke.getIdmap().put( cte2.getComp1(), cte2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // + // - cmke_id = imke.getId(); + cmke_id = imke.getId(); - cte1_id = cte1.getId(); - cte2_id = cte2.getId(); - } + cte1_id = cte1.getId(); + cte2_id = cte2.getId(); + } @Test public void testHasChangedMapEntity() throws Exception { - List list = queryForPropertyHasChanged(ComponentMapKeyEntity.class, cmke_id, "idmap"); - assertEquals(2, list.size()); - assertEquals(makeList(1, 2), extractRevisionNumbers(list)); + List list = queryForPropertyHasChanged( ComponentMapKeyEntity.class, cmke_id, "idmap" ); + assertEquals( 2, list.size() ); + assertEquals( makeList( 1, 2 ), extractRevisionNumbers( list ) ); - list = queryForPropertyHasNotChanged(ComponentMapKeyEntity.class, - cmke_id, "idmap"); - assertEquals(0, list.size()); + list = queryForPropertyHasNotChanged( + ComponentMapKeyEntity.class, + cmke_id, "idmap" + ); + assertEquals( 0, list.size() ); } @Test public void testHasChangedComponentEntity() throws Exception { - List list = queryForPropertyHasChanged(ComponentTestEntity.class, - cte1_id, "comp1"); - assertEquals(1, list.size()); - assertEquals(makeList(1), extractRevisionNumbers(list)); + List list = queryForPropertyHasChanged( + ComponentTestEntity.class, + cte1_id, "comp1" + ); + assertEquals( 1, list.size() ); + assertEquals( makeList( 1 ), extractRevisionNumbers( list ) ); - list = queryForPropertyHasNotChanged(ComponentTestEntity.class, cte1_id, - "comp1"); - assertEquals(0, list.size()); + list = queryForPropertyHasNotChanged( + ComponentTestEntity.class, cte1_id, + "comp1" + ); + assertEquals( 0, list.size() ); - list = queryForPropertyHasChanged(ComponentTestEntity.class, cte2_id, "comp1"); - assertEquals(1, list.size()); - assertEquals(makeList(1), extractRevisionNumbers(list)); + list = queryForPropertyHasChanged( ComponentTestEntity.class, cte2_id, "comp1" ); + assertEquals( 1, list.size() ); + assertEquals( makeList( 1 ), extractRevisionNumbers( list ) ); - list = queryForPropertyHasNotChanged(ComponentTestEntity.class, cte2_id, "comp1"); - assertEquals(0, list.size()); + list = queryForPropertyHasNotChanged( ComponentTestEntity.class, cte2_id, "comp1" ); + assertEquals( 0, list.size() ); } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedComponents.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedComponents.java index b1d5ecbd0d..f39023c8cb 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedComponents.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedComponents.java @@ -23,10 +23,8 @@ */ package org.hibernate.envers.test.integration.modifiedflags; -import java.util.List; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.List; import org.hibernate.QueryException; import org.hibernate.envers.test.Priority; @@ -35,6 +33,8 @@ import org.hibernate.envers.test.entities.components.Component2; import org.hibernate.envers.test.entities.components.ComponentTestEntity; import org.hibernate.envers.test.tools.TestTools; +import org.junit.Test; + import static junit.framework.Assert.assertEquals; import static org.hibernate.envers.test.tools.TestTools.extractRevisionNumbers; import static org.hibernate.envers.test.tools.TestTools.makeList; @@ -44,136 +44,151 @@ import static org.hibernate.envers.test.tools.TestTools.makeList; * @author Michal Skowronek (mskowr at o2 dot pl) */ public class HasChangedComponents extends AbstractModifiedFlagsEntityTest { - private Integer id1; - private Integer id2; - private Integer id3; - private Integer id4; + private Integer id1; + private Integer id2; + private Integer id3; + private Integer id4; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { ComponentTestEntity.class }; - } - - @Test - @Priority(10) - public void initData() { - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); - - ComponentTestEntity cte1 = new ComponentTestEntity(new Component1("a", "b"), new Component2("x", "y")); - ComponentTestEntity cte2 = new ComponentTestEntity(new Component1("a2", "b2"), new Component2("x2", "y2")); - ComponentTestEntity cte3 = new ComponentTestEntity(new Component1("a3", "b3"), new Component2("x3", "y3")); - ComponentTestEntity cte4 = new ComponentTestEntity(null, null); - - em.persist(cte1); - em.persist(cte2); - em.persist(cte3); - em.persist(cte4); - - em.getTransaction().commit(); - - // Revision 2 - em = getEntityManager(); - em.getTransaction().begin(); - - cte1 = em.find(ComponentTestEntity.class, cte1.getId()); - cte2 = em.find(ComponentTestEntity.class, cte2.getId()); - cte3 = em.find(ComponentTestEntity.class, cte3.getId()); - cte4 = em.find(ComponentTestEntity.class, cte4.getId()); - - cte1.setComp1(new Component1("a'", "b'")); - cte2.getComp1().setStr1("a2'"); - cte3.getComp2().setStr6("y3'"); - cte4.setComp1(new Component1()); - cte4.getComp1().setStr1("n"); - cte4.setComp2(new Component2()); - cte4.getComp2().setStr5("m"); - - em.getTransaction().commit(); - - // Revision 3 - em = getEntityManager(); - em.getTransaction().begin(); - - cte1 = em.find(ComponentTestEntity.class, cte1.getId()); - cte2 = em.find(ComponentTestEntity.class, cte2.getId()); - cte3 = em.find(ComponentTestEntity.class, cte3.getId()); - cte4 = em.find(ComponentTestEntity.class, cte4.getId()); - - cte1.setComp2(new Component2("x'", "y'")); - cte3.getComp1().setStr2("b3'"); - cte4.setComp1(null); - cte4.setComp2(null); - - em.getTransaction().commit(); - - // Revision 4 - em = getEntityManager(); - em.getTransaction().begin(); - - cte2 = em.find(ComponentTestEntity.class, cte2.getId()); - - em.remove(cte2); - - em.getTransaction().commit(); - - id1 = cte1.getId(); - id2 = cte2.getId(); - id3 = cte3.getId(); - id4 = cte4.getId(); - } + return new Class[] {ComponentTestEntity.class}; + } @Test - public void testModFlagProperties() { - assertEquals(TestTools.makeSet("comp1_MOD"), - TestTools.extractModProperties(getCfg().getClassMapping( - "org.hibernate.envers.test.entities.components.ComponentTestEntity_AUD"))); + @Priority(10) + public void initData() { + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); + + ComponentTestEntity cte1 = new ComponentTestEntity( new Component1( "a", "b" ), new Component2( "x", "y" ) ); + ComponentTestEntity cte2 = new ComponentTestEntity( + new Component1( "a2", "b2" ), new Component2( + "x2", + "y2" + ) + ); + ComponentTestEntity cte3 = new ComponentTestEntity( + new Component1( "a3", "b3" ), new Component2( + "x3", + "y3" + ) + ); + ComponentTestEntity cte4 = new ComponentTestEntity( null, null ); + + em.persist( cte1 ); + em.persist( cte2 ); + em.persist( cte3 ); + em.persist( cte4 ); + + em.getTransaction().commit(); + + // Revision 2 + em = getEntityManager(); + em.getTransaction().begin(); + + cte1 = em.find( ComponentTestEntity.class, cte1.getId() ); + cte2 = em.find( ComponentTestEntity.class, cte2.getId() ); + cte3 = em.find( ComponentTestEntity.class, cte3.getId() ); + cte4 = em.find( ComponentTestEntity.class, cte4.getId() ); + + cte1.setComp1( new Component1( "a'", "b'" ) ); + cte2.getComp1().setStr1( "a2'" ); + cte3.getComp2().setStr6( "y3'" ); + cte4.setComp1( new Component1() ); + cte4.getComp1().setStr1( "n" ); + cte4.setComp2( new Component2() ); + cte4.getComp2().setStr5( "m" ); + + em.getTransaction().commit(); + + // Revision 3 + em = getEntityManager(); + em.getTransaction().begin(); + + cte1 = em.find( ComponentTestEntity.class, cte1.getId() ); + cte2 = em.find( ComponentTestEntity.class, cte2.getId() ); + cte3 = em.find( ComponentTestEntity.class, cte3.getId() ); + cte4 = em.find( ComponentTestEntity.class, cte4.getId() ); + + cte1.setComp2( new Component2( "x'", "y'" ) ); + cte3.getComp1().setStr2( "b3'" ); + cte4.setComp1( null ); + cte4.setComp2( null ); + + em.getTransaction().commit(); + + // Revision 4 + em = getEntityManager(); + em.getTransaction().begin(); + + cte2 = em.find( ComponentTestEntity.class, cte2.getId() ); + + em.remove( cte2 ); + + em.getTransaction().commit(); + + id1 = cte1.getId(); + id2 = cte2.getId(); + id3 = cte3.getId(); + id4 = cte4.getId(); + } + + @Test + public void testModFlagProperties() { + assertEquals( + TestTools.makeSet( "comp1_MOD" ), + TestTools.extractModProperties( + getCfg().getClassMapping( + "org.hibernate.envers.test.entities.components.ComponentTestEntity_AUD" + ) + ) + ); } @Test(expected = QueryException.class) public void testHasChangedNotAudited() throws Exception { - queryForPropertyHasChanged(ComponentTestEntity.class, id1, "comp2"); + queryForPropertyHasChanged( ComponentTestEntity.class, id1, "comp2" ); } @Test public void testHasChangedId1() throws Exception { - List list = queryForPropertyHasChanged(ComponentTestEntity.class, id1, "comp1"); - assertEquals(2, list.size()); - assertEquals(makeList(1, 2), extractRevisionNumbers(list)); + List list = queryForPropertyHasChanged( ComponentTestEntity.class, id1, "comp1" ); + assertEquals( 2, list.size() ); + assertEquals( makeList( 1, 2 ), extractRevisionNumbers( list ) ); - list = queryForPropertyHasNotChanged(ComponentTestEntity.class, id1, "comp1"); - assertEquals(0, list.size()); + list = queryForPropertyHasNotChanged( ComponentTestEntity.class, id1, "comp1" ); + assertEquals( 0, list.size() ); } @Test public void testHasChangedId2() throws Exception { - List list = queryForPropertyHasChangedWithDeleted(ComponentTestEntity.class, id2, "comp1"); - assertEquals(3, list.size()); - assertEquals(makeList(1, 2, 4), extractRevisionNumbers(list)); + List list = queryForPropertyHasChangedWithDeleted( ComponentTestEntity.class, id2, "comp1" ); + assertEquals( 3, list.size() ); + assertEquals( makeList( 1, 2, 4 ), extractRevisionNumbers( list ) ); - list = queryForPropertyHasNotChangedWithDeleted(ComponentTestEntity.class, id2, "comp1"); - assertEquals(0, list.size()); + list = queryForPropertyHasNotChangedWithDeleted( ComponentTestEntity.class, id2, "comp1" ); + assertEquals( 0, list.size() ); } @Test public void testHasChangedId3() throws Exception { - List list = queryForPropertyHasChangedWithDeleted(ComponentTestEntity.class, id3, "comp1"); - assertEquals(2, list.size()); - assertEquals(makeList(1, 3), extractRevisionNumbers(list)); + List list = queryForPropertyHasChangedWithDeleted( ComponentTestEntity.class, id3, "comp1" ); + assertEquals( 2, list.size() ); + assertEquals( makeList( 1, 3 ), extractRevisionNumbers( list ) ); - list = queryForPropertyHasNotChangedWithDeleted(ComponentTestEntity.class, id3, "comp1"); - assertEquals(0, list.size()); + list = queryForPropertyHasNotChangedWithDeleted( ComponentTestEntity.class, id3, "comp1" ); + assertEquals( 0, list.size() ); } @Test public void testHasChangedId4() throws Exception { - List list = queryForPropertyHasChangedWithDeleted(ComponentTestEntity.class, id4, "comp1"); - assertEquals(2, list.size()); - assertEquals(makeList(2, 3), extractRevisionNumbers(list)); + List list = queryForPropertyHasChangedWithDeleted( ComponentTestEntity.class, id4, "comp1" ); + assertEquals( 2, list.size() ); + assertEquals( makeList( 2, 3 ), extractRevisionNumbers( list ) ); - list = queryForPropertyHasNotChangedWithDeleted(ComponentTestEntity.class, id4, "comp1"); - assertEquals(1, list.size()); - assertEquals(makeList(1), extractRevisionNumbers(list)); + list = queryForPropertyHasNotChangedWithDeleted( ComponentTestEntity.class, id4, "comp1" ); + assertEquals( 1, list.size() ); + assertEquals( makeList( 1 ), extractRevisionNumbers( list ) ); } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedCompositeCustom.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedCompositeCustom.java index 5c58a93b54..902dfa1c5c 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedCompositeCustom.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedCompositeCustom.java @@ -23,15 +23,15 @@ */ package org.hibernate.envers.test.integration.modifiedflags; -import java.util.List; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.List; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.customtype.Component; import org.hibernate.envers.test.entities.customtype.CompositeCustomTypeEntity; +import org.junit.Test; + import static junit.framework.Assert.assertEquals; import static org.hibernate.envers.test.tools.TestTools.extractRevisionNumbers; import static org.hibernate.envers.test.tools.TestTools.makeList; @@ -41,59 +41,59 @@ import static org.hibernate.envers.test.tools.TestTools.makeList; * @author Michal Skowronek (mskowr at o2 dot pl) */ public class HasChangedCompositeCustom extends AbstractModifiedFlagsEntityTest { - private Integer ccte_id; + private Integer ccte_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { CompositeCustomTypeEntity.class }; - } + return new Class[] {CompositeCustomTypeEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - CompositeCustomTypeEntity ccte = new CompositeCustomTypeEntity(); + CompositeCustomTypeEntity ccte = new CompositeCustomTypeEntity(); - // Revision 1 (persisting 1 entity) - em.getTransaction().begin(); + // Revision 1 (persisting 1 entity) + em.getTransaction().begin(); - ccte.setComponent(new Component("a", 1)); + ccte.setComponent( new Component( "a", 1 ) ); - em.persist(ccte); + em.persist( ccte ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 (changing the component) - em.getTransaction().begin(); + // Revision 2 (changing the component) + em.getTransaction().begin(); - ccte = em.find(CompositeCustomTypeEntity.class, ccte.getId()); + ccte = em.find( CompositeCustomTypeEntity.class, ccte.getId() ); - ccte.getComponent().setProp1("b"); + ccte.getComponent().setProp1( "b" ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 (replacing the component) - em.getTransaction().begin(); + // Revision 3 (replacing the component) + em.getTransaction().begin(); - ccte = em.find(CompositeCustomTypeEntity.class, ccte.getId()); + ccte = em.find( CompositeCustomTypeEntity.class, ccte.getId() ); - ccte.setComponent(new Component("c", 3)); + ccte.setComponent( new Component( "c", 3 ) ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // + // - ccte_id = ccte.getId(); - } + ccte_id = ccte.getId(); + } @Test public void testHasChanged() throws Exception { - List list = queryForPropertyHasChanged(CompositeCustomTypeEntity.class,ccte_id, "component"); - assertEquals(3, list.size()); - assertEquals(makeList(1, 2, 3), extractRevisionNumbers(list)); + List list = queryForPropertyHasChanged( CompositeCustomTypeEntity.class, ccte_id, "component" ); + assertEquals( 3, list.size() ); + assertEquals( makeList( 1, 2, 3 ), extractRevisionNumbers( list ) ); - list = queryForPropertyHasNotChanged(CompositeCustomTypeEntity.class,ccte_id, "component"); - assertEquals(0, list.size()); + list = queryForPropertyHasNotChanged( CompositeCustomTypeEntity.class, ccte_id, "component" ); + assertEquals( 0, list.size() ); } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedDetachedMultipleCollection.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedDetachedMultipleCollection.java index 7c6036b562..f0e3e3518b 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedDetachedMultipleCollection.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedDetachedMultipleCollection.java @@ -1,16 +1,17 @@ package org.hibernate.envers.test.integration.modifiedflags; +import javax.persistence.EntityManager; import java.util.ArrayList; import java.util.List; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.dialect.Oracle8iDialect; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.collection.MultipleCollectionEntity; import org.hibernate.envers.test.entities.collection.MultipleCollectionRefEntity1; import org.hibernate.envers.test.entities.collection.MultipleCollectionRefEntity2; + +import org.junit.Test; + import org.hibernate.testing.SkipForDialect; import org.hibernate.testing.TestForIssue; @@ -23,7 +24,7 @@ import static org.junit.Assert.assertEquals; */ @TestForIssue(jiraKey = "HHH-7437") @SkipForDialect(value = Oracle8iDialect.class, - comment = "Oracle does not support identity key generation") + comment = "Oracle does not support identity key generation") public class HasChangedDetachedMultipleCollection extends AbstractModifiedFlagsEntityTest { private Long mce1Id = null; private Long mce2Id = null; diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedDoubleJoinColumnBidirectionalList.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedDoubleJoinColumnBidirectionalList.java index 4bd2dca4d5..a37f6b98d2 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedDoubleJoinColumnBidirectionalList.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedDoubleJoinColumnBidirectionalList.java @@ -23,16 +23,16 @@ */ package org.hibernate.envers.test.integration.modifiedflags; -import java.util.List; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.List; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.onetomany.detached.DoubleListJoinColumnBidirectionalRefEdEntity1; import org.hibernate.envers.test.entities.onetomany.detached.DoubleListJoinColumnBidirectionalRefEdEntity2; import org.hibernate.envers.test.entities.onetomany.detached.DoubleListJoinColumnBidirectionalRefIngEntity; +import org.junit.Test; + import static junit.framework.Assert.assertEquals; import static org.hibernate.envers.test.tools.TestTools.extractRevisionNumbers; import static org.hibernate.envers.test.tools.TestTools.makeList; @@ -40,17 +40,18 @@ import static org.hibernate.envers.test.tools.TestTools.makeList; /** * Test for a double "fake" bidirectional mapping where one side uses @OneToMany+@JoinColumn * (and thus owns the relation), and the other uses a @ManyToOne(insertable=false, updatable=false). + * * @author Adam Warski (adam at warski dot org) * @author Michal Skowronek (mskowr at o2 dot pl) */ public class HasChangedDoubleJoinColumnBidirectionalList extends AbstractModifiedFlagsEntityTest { - private Integer ed1_1_id; - private Integer ed2_1_id; - private Integer ed1_2_id; - private Integer ed2_2_id; + private Integer ed1_1_id; + private Integer ed2_1_id; + private Integer ed1_2_id; + private Integer ed2_2_id; - private Integer ing1_id; - private Integer ing2_id; + private Integer ing1_id; + private Integer ing2_id; @Override protected Class[] getAnnotatedClasses() { @@ -59,205 +60,233 @@ public class HasChangedDoubleJoinColumnBidirectionalList extends AbstractModifie DoubleListJoinColumnBidirectionalRefEdEntity1.class, DoubleListJoinColumnBidirectionalRefEdEntity2.class }; - } + } - @Test - @Priority(10) - public void createData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void createData() { + EntityManager em = getEntityManager(); - DoubleListJoinColumnBidirectionalRefEdEntity1 ed1_1 = new DoubleListJoinColumnBidirectionalRefEdEntity1("ed1_1", null); - DoubleListJoinColumnBidirectionalRefEdEntity1 ed1_2 = new DoubleListJoinColumnBidirectionalRefEdEntity1("ed1_2", null); + DoubleListJoinColumnBidirectionalRefEdEntity1 ed1_1 = new DoubleListJoinColumnBidirectionalRefEdEntity1( + "ed1_1", + null + ); + DoubleListJoinColumnBidirectionalRefEdEntity1 ed1_2 = new DoubleListJoinColumnBidirectionalRefEdEntity1( + "ed1_2", + null + ); - DoubleListJoinColumnBidirectionalRefEdEntity2 ed2_1 = new DoubleListJoinColumnBidirectionalRefEdEntity2("ed2_1", null); - DoubleListJoinColumnBidirectionalRefEdEntity2 ed2_2 = new DoubleListJoinColumnBidirectionalRefEdEntity2("ed2_2", null); + DoubleListJoinColumnBidirectionalRefEdEntity2 ed2_1 = new DoubleListJoinColumnBidirectionalRefEdEntity2( + "ed2_1", + null + ); + DoubleListJoinColumnBidirectionalRefEdEntity2 ed2_2 = new DoubleListJoinColumnBidirectionalRefEdEntity2( + "ed2_2", + null + ); - DoubleListJoinColumnBidirectionalRefIngEntity ing1 = new DoubleListJoinColumnBidirectionalRefIngEntity("coll1"); - DoubleListJoinColumnBidirectionalRefIngEntity ing2 = new DoubleListJoinColumnBidirectionalRefIngEntity("coll2"); + DoubleListJoinColumnBidirectionalRefIngEntity ing1 = new DoubleListJoinColumnBidirectionalRefIngEntity( "coll1" ); + DoubleListJoinColumnBidirectionalRefIngEntity ing2 = new DoubleListJoinColumnBidirectionalRefIngEntity( "coll2" ); - // Revision 1 (ing1: ed1_1, ed2_1, ing2: ed1_2, ed2_2) - em.getTransaction().begin(); + // Revision 1 (ing1: ed1_1, ed2_1, ing2: ed1_2, ed2_2) + em.getTransaction().begin(); - ing1.getReferences1().add(ed1_1); - ing1.getReferences2().add(ed2_1); + ing1.getReferences1().add( ed1_1 ); + ing1.getReferences2().add( ed2_1 ); - ing2.getReferences1().add(ed1_2); - ing2.getReferences2().add(ed2_2); + ing2.getReferences1().add( ed1_2 ); + ing2.getReferences2().add( ed2_2 ); - em.persist(ed1_1); - em.persist(ed1_2); - em.persist(ed2_1); - em.persist(ed2_2); - em.persist(ing1); - em.persist(ing2); + em.persist( ed1_1 ); + em.persist( ed1_2 ); + em.persist( ed2_1 ); + em.persist( ed2_2 ); + em.persist( ing1 ); + em.persist( ing2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 (ing1: ed1_1, ed1_2, ed2_1, ed2_2) - em.getTransaction().begin(); + // Revision 2 (ing1: ed1_1, ed1_2, ed2_1, ed2_2) + em.getTransaction().begin(); - ing1 = em.find(DoubleListJoinColumnBidirectionalRefIngEntity.class, ing1.getId()); - ing2 = em.find(DoubleListJoinColumnBidirectionalRefIngEntity.class, ing2.getId()); - ed1_1 = em.find(DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_1.getId()); - ed1_2 = em.find(DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_2.getId()); - ed2_1 = em.find(DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_1.getId()); - ed2_2 = em.find(DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_2.getId()); + ing1 = em.find( DoubleListJoinColumnBidirectionalRefIngEntity.class, ing1.getId() ); + ing2 = em.find( DoubleListJoinColumnBidirectionalRefIngEntity.class, ing2.getId() ); + ed1_1 = em.find( DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_1.getId() ); + ed1_2 = em.find( DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_2.getId() ); + ed2_1 = em.find( DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_1.getId() ); + ed2_2 = em.find( DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_2.getId() ); - ing2.getReferences1().clear(); - ing2.getReferences2().clear(); + ing2.getReferences1().clear(); + ing2.getReferences2().clear(); - ing1.getReferences1().add(ed1_2); - ing1.getReferences2().add(ed2_2); + ing1.getReferences1().add( ed1_2 ); + ing1.getReferences2().add( ed2_2 ); - em.getTransaction().commit(); - em.clear(); + em.getTransaction().commit(); + em.clear(); - // Revision 3 (ing1: ed1_1, ed1_2, ed2_1, ed2_2) - em.getTransaction().begin(); + // Revision 3 (ing1: ed1_1, ed1_2, ed2_1, ed2_2) + em.getTransaction().begin(); - ing1 = em.find(DoubleListJoinColumnBidirectionalRefIngEntity.class, ing1.getId()); - ing2 = em.find(DoubleListJoinColumnBidirectionalRefIngEntity.class, ing2.getId()); - ed1_1 = em.find(DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_1.getId()); - ed1_2 = em.find(DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_2.getId()); - ed2_1 = em.find(DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_1.getId()); - ed2_2 = em.find(DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_2.getId()); + ing1 = em.find( DoubleListJoinColumnBidirectionalRefIngEntity.class, ing1.getId() ); + ing2 = em.find( DoubleListJoinColumnBidirectionalRefIngEntity.class, ing2.getId() ); + ed1_1 = em.find( DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_1.getId() ); + ed1_2 = em.find( DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_2.getId() ); + ed2_1 = em.find( DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_1.getId() ); + ed2_2 = em.find( DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_2.getId() ); - ed1_1.setData("ed1_1 bis"); - ed2_2.setData("ed2_2 bis"); + ed1_1.setData( "ed1_1 bis" ); + ed2_2.setData( "ed2_2 bis" ); - em.getTransaction().commit(); - em.clear(); + em.getTransaction().commit(); + em.clear(); - // Revision 4 (ing1: ed2_2, ing2: ed2_1, ed1_1, ed1_2) - em.getTransaction().begin(); + // Revision 4 (ing1: ed2_2, ing2: ed2_1, ed1_1, ed1_2) + em.getTransaction().begin(); - ing1 = em.find(DoubleListJoinColumnBidirectionalRefIngEntity.class, ing1.getId()); - ing2 = em.find(DoubleListJoinColumnBidirectionalRefIngEntity.class, ing2.getId()); - ed1_1 = em.find(DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_1.getId()); - ed1_2 = em.find(DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_2.getId()); - ed2_1 = em.find(DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_1.getId()); - ed2_2 = em.find(DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_2.getId()); + ing1 = em.find( DoubleListJoinColumnBidirectionalRefIngEntity.class, ing1.getId() ); + ing2 = em.find( DoubleListJoinColumnBidirectionalRefIngEntity.class, ing2.getId() ); + ed1_1 = em.find( DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_1.getId() ); + ed1_2 = em.find( DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_2.getId() ); + ed2_1 = em.find( DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_1.getId() ); + ed2_2 = em.find( DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_2.getId() ); - ing1.getReferences1().clear(); - ing2.getReferences1().add(ed1_1); - ing2.getReferences1().add(ed1_2); + ing1.getReferences1().clear(); + ing2.getReferences1().add( ed1_1 ); + ing2.getReferences1().add( ed1_2 ); - ing1.getReferences2().remove(ed2_1); - ing2.getReferences2().add(ed2_1); + ing1.getReferences2().remove( ed2_1 ); + ing2.getReferences2().add( ed2_1 ); - em.getTransaction().commit(); - em.clear(); + em.getTransaction().commit(); + em.clear(); - // + // - ing1_id = ing1.getId(); - ing2_id = ing2.getId(); + ing1_id = ing1.getId(); + ing2_id = ing2.getId(); - ed1_1_id = ed1_1.getId(); - ed1_2_id = ed1_2.getId(); - ed2_1_id = ed2_1.getId(); - ed2_2_id = ed2_2.getId(); - } + ed1_1_id = ed1_1.getId(); + ed1_2_id = ed1_2.getId(); + ed2_1_id = ed2_1.getId(); + ed2_2_id = ed2_2.getId(); + } @Test public void testOwnerHasChanged() throws Exception { List list = queryForPropertyHasChanged( DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_1_id, - "owner"); - assertEquals(2, list.size()); - assertEquals(makeList(1, 4), extractRevisionNumbers(list)); + "owner" + ); + assertEquals( 2, list.size() ); + assertEquals( makeList( 1, 4 ), extractRevisionNumbers( list ) ); list = queryForPropertyHasNotChanged( DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_1_id, - "owner"); - assertEquals(1, list.size()); - assertEquals(makeList(3), extractRevisionNumbers(list)); + "owner" + ); + assertEquals( 1, list.size() ); + assertEquals( makeList( 3 ), extractRevisionNumbers( list ) ); list = queryForPropertyHasChanged( DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_2_id, - "owner"); - assertEquals(3, list.size()); - assertEquals(makeList(1, 2, 4), extractRevisionNumbers(list)); + "owner" + ); + assertEquals( 3, list.size() ); + assertEquals( makeList( 1, 2, 4 ), extractRevisionNumbers( list ) ); list = queryForPropertyHasNotChanged( DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_2_id, - "owner"); - assertEquals(0, list.size()); + "owner" + ); + assertEquals( 0, list.size() ); } @Test public void testOwnerSecEntityHasChanged() throws Exception { List list = queryForPropertyHasChanged( DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_1_id, - "owner"); - assertEquals(2, list.size()); - assertEquals(makeList(1, 4), extractRevisionNumbers(list)); + "owner" + ); + assertEquals( 2, list.size() ); + assertEquals( makeList( 1, 4 ), extractRevisionNumbers( list ) ); list = queryForPropertyHasNotChanged( DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_1_id, - "owner"); - assertEquals(0, list.size()); + "owner" + ); + assertEquals( 0, list.size() ); list = queryForPropertyHasChanged( DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_2_id, - "owner"); - assertEquals(2, list.size()); - assertEquals(makeList(1, 2), extractRevisionNumbers(list)); + "owner" + ); + assertEquals( 2, list.size() ); + assertEquals( makeList( 1, 2 ), extractRevisionNumbers( list ) ); list = queryForPropertyHasNotChanged( DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_2_id, - "owner"); - assertEquals(1, list.size()); - assertEquals(makeList(3), extractRevisionNumbers(list)); + "owner" + ); + assertEquals( 1, list.size() ); + assertEquals( makeList( 3 ), extractRevisionNumbers( list ) ); } @Test public void testReferences1HasChanged() throws Exception { List list = queryForPropertyHasChanged( DoubleListJoinColumnBidirectionalRefIngEntity.class, ing1_id, - "references1"); - assertEquals(3, list.size()); - assertEquals(makeList(1, 2, 4), extractRevisionNumbers(list)); + "references1" + ); + assertEquals( 3, list.size() ); + assertEquals( makeList( 1, 2, 4 ), extractRevisionNumbers( list ) ); list = queryForPropertyHasChanged( DoubleListJoinColumnBidirectionalRefIngEntity.class, ing2_id, - "references1"); - assertEquals(3, list.size()); - assertEquals(makeList(1, 2, 4), extractRevisionNumbers(list)); + "references1" + ); + assertEquals( 3, list.size() ); + assertEquals( makeList( 1, 2, 4 ), extractRevisionNumbers( list ) ); list = queryForPropertyHasNotChanged( DoubleListJoinColumnBidirectionalRefIngEntity.class, ing1_id, - "references1"); - assertEquals(0, list.size()); + "references1" + ); + assertEquals( 0, list.size() ); list = queryForPropertyHasNotChanged( DoubleListJoinColumnBidirectionalRefIngEntity.class, ing2_id, - "references1"); - assertEquals(0, list.size()); + "references1" + ); + assertEquals( 0, list.size() ); } @Test public void testReferences2HasChanged() throws Exception { List list = queryForPropertyHasChanged( DoubleListJoinColumnBidirectionalRefIngEntity.class, ing1_id, - "references2"); - assertEquals(3, list.size()); - assertEquals(makeList(1, 2, 4), extractRevisionNumbers(list)); + "references2" + ); + assertEquals( 3, list.size() ); + assertEquals( makeList( 1, 2, 4 ), extractRevisionNumbers( list ) ); list = queryForPropertyHasChanged( DoubleListJoinColumnBidirectionalRefIngEntity.class, ing2_id, - "references2"); - assertEquals(3, list.size()); - assertEquals(makeList(1, 2, 4), extractRevisionNumbers(list)); + "references2" + ); + assertEquals( 3, list.size() ); + assertEquals( makeList( 1, 2, 4 ), extractRevisionNumbers( list ) ); list = queryForPropertyHasNotChanged( DoubleListJoinColumnBidirectionalRefIngEntity.class, ing1_id, - "references2"); - assertEquals(0, list.size()); + "references2" + ); + assertEquals( 0, list.size() ); list = queryForPropertyHasNotChanged( DoubleListJoinColumnBidirectionalRefIngEntity.class, ing2_id, - "references2"); - assertEquals(0, list.size()); + "references2" + ); + assertEquals( 0, list.size() ); } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedEnumSet.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedEnumSet.java index 56d73e839e..1a71085b58 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedEnumSet.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedEnumSet.java @@ -23,16 +23,16 @@ */ package org.hibernate.envers.test.integration.modifiedflags; -import java.util.List; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.List; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.collection.EnumSetEntity; import org.hibernate.envers.test.entities.collection.EnumSetEntity.E1; import org.hibernate.envers.test.entities.collection.EnumSetEntity.E2; +import org.junit.Test; + import static junit.framework.Assert.assertEquals; import static org.hibernate.envers.test.tools.TestTools.extractRevisionNumbers; import static org.hibernate.envers.test.tools.TestTools.makeList; @@ -42,74 +42,82 @@ import static org.hibernate.envers.test.tools.TestTools.makeList; * @author Michal Skowronek (mskowr at o2 dot pl) */ public class HasChangedEnumSet extends AbstractModifiedFlagsEntityTest { - private Integer sse1_id; + private Integer sse1_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { EnumSetEntity.class }; - } + return new Class[] {EnumSetEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - EnumSetEntity sse1 = new EnumSetEntity(); + EnumSetEntity sse1 = new EnumSetEntity(); - // Revision 1 (sse1: initialy 1 element) - em.getTransaction().begin(); + // Revision 1 (sse1: initialy 1 element) + em.getTransaction().begin(); - sse1.getEnums1().add(E1.X); - sse1.getEnums2().add(E2.A); + sse1.getEnums1().add( E1.X ); + sse1.getEnums2().add( E2.A ); - em.persist(sse1); + em.persist( sse1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 (sse1: adding 1 element/removing a non-existing element) - em.getTransaction().begin(); + // Revision 2 (sse1: adding 1 element/removing a non-existing element) + em.getTransaction().begin(); - sse1 = em.find(EnumSetEntity.class, sse1.getId()); + sse1 = em.find( EnumSetEntity.class, sse1.getId() ); - sse1.getEnums1().add(E1.Y); - sse1.getEnums2().remove(E2.B); + sse1.getEnums1().add( E1.Y ); + sse1.getEnums2().remove( E2.B ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 (sse1: removing 1 element/adding an exisiting element) - em.getTransaction().begin(); + // Revision 3 (sse1: removing 1 element/adding an exisiting element) + em.getTransaction().begin(); - sse1 = em.find(EnumSetEntity.class, sse1.getId()); + sse1 = em.find( EnumSetEntity.class, sse1.getId() ); - sse1.getEnums1().remove(E1.X); - sse1.getEnums2().add(E2.A); + sse1.getEnums1().remove( E1.X ); + sse1.getEnums2().add( E2.A ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // + // - sse1_id = sse1.getId(); - } + sse1_id = sse1.getId(); + } @Test public void testHasChanged() throws Exception { - List list = queryForPropertyHasChanged(EnumSetEntity.class, sse1_id, - "enums1"); - assertEquals(3, list.size()); - assertEquals(makeList(1, 2, 3), extractRevisionNumbers(list)); + List list = queryForPropertyHasChanged( + EnumSetEntity.class, sse1_id, + "enums1" + ); + assertEquals( 3, list.size() ); + assertEquals( makeList( 1, 2, 3 ), extractRevisionNumbers( list ) ); - list = queryForPropertyHasChanged(EnumSetEntity.class, sse1_id, - "enums2"); - assertEquals(1, list.size()); - assertEquals(makeList(1), extractRevisionNumbers(list)); + list = queryForPropertyHasChanged( + EnumSetEntity.class, sse1_id, + "enums2" + ); + assertEquals( 1, list.size() ); + assertEquals( makeList( 1 ), extractRevisionNumbers( list ) ); - list = queryForPropertyHasNotChanged(EnumSetEntity.class, sse1_id, - "enums1"); - assertEquals(0, list.size()); + list = queryForPropertyHasNotChanged( + EnumSetEntity.class, sse1_id, + "enums1" + ); + assertEquals( 0, list.size() ); - list = queryForPropertyHasNotChanged(EnumSetEntity.class, sse1_id, - "enums2"); - assertEquals(2, list.size()); - assertEquals(makeList(2, 3), extractRevisionNumbers(list)); + list = queryForPropertyHasNotChanged( + EnumSetEntity.class, sse1_id, + "enums2" + ); + assertEquals( 2, list.size() ); + assertEquals( makeList( 2, 3 ), extractRevisionNumbers( list ) ); } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedForDefaultNotUsing.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedForDefaultNotUsing.java index 0edee4e6ba..ce28305313 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedForDefaultNotUsing.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedForDefaultNotUsing.java @@ -23,11 +23,9 @@ */ package org.hibernate.envers.test.integration.modifiedflags; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.List; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.QueryException; import org.hibernate.envers.test.Priority; @@ -37,6 +35,8 @@ import org.hibernate.envers.test.entities.components.Component2; import org.hibernate.envers.test.integration.modifiedflags.entities.PartialModifiedFlagsEntity; import org.hibernate.envers.test.integration.modifiedflags.entities.WithModifiedFlagReferencingEntity; +import org.junit.Test; + import static junit.framework.Assert.assertEquals; import static org.hibernate.envers.test.tools.TestTools.extractRevisionNumbers; import static org.hibernate.envers.test.tools.TestTools.makeList; @@ -55,219 +55,243 @@ public class HasChangedForDefaultNotUsing extends AbstractModifiedFlagsEntityTes @Override protected Class[] getAnnotatedClasses() { - return new Class[] { PartialModifiedFlagsEntity.class, WithModifiedFlagReferencingEntity.class, StrTestEntity.class }; - } + return new Class[] { + PartialModifiedFlagsEntity.class, + WithModifiedFlagReferencingEntity.class, + StrTestEntity.class + }; + } - @Test - @Priority(10) - public void initData() { + @Test + @Priority(10) + public void initData() { PartialModifiedFlagsEntity entity = - new PartialModifiedFlagsEntity(entityId); + new PartialModifiedFlagsEntity( entityId ); // Revision 1 EntityManager em = getEntityManager(); em.getTransaction().begin(); - em.persist(entity); + em.persist( entity ); em.getTransaction().commit(); // Revision 2 em.getTransaction().begin(); - entity.setData("data1"); - entity = em.merge(entity); + entity.setData( "data1" ); + entity = em.merge( entity ); em.getTransaction().commit(); // Revision 3 em.getTransaction().begin(); - entity.setComp1(new Component1("str1", "str2")); - entity = em.merge(entity); + entity.setComp1( new Component1( "str1", "str2" ) ); + entity = em.merge( entity ); em.getTransaction().commit(); // Revision 4 em.getTransaction().begin(); - entity.setComp2(new Component2("str1", "str2")); - entity = em.merge(entity); + entity.setComp2( new Component2( "str1", "str2" ) ); + entity = em.merge( entity ); em.getTransaction().commit(); // Revision 5 em.getTransaction().begin(); - WithModifiedFlagReferencingEntity withModifiedFlagReferencingEntity = new WithModifiedFlagReferencingEntity(refEntityId, "first"); - withModifiedFlagReferencingEntity.setReference(entity); - em.persist(withModifiedFlagReferencingEntity); + WithModifiedFlagReferencingEntity withModifiedFlagReferencingEntity = new WithModifiedFlagReferencingEntity( + refEntityId, + "first" + ); + withModifiedFlagReferencingEntity.setReference( entity ); + em.persist( withModifiedFlagReferencingEntity ); em.getTransaction().commit(); // Revision 6 em.getTransaction().begin(); - withModifiedFlagReferencingEntity = em.find(WithModifiedFlagReferencingEntity.class, refEntityId); - withModifiedFlagReferencingEntity.setReference(null); - withModifiedFlagReferencingEntity.setSecondReference(entity); - em.merge(withModifiedFlagReferencingEntity); + withModifiedFlagReferencingEntity = em.find( WithModifiedFlagReferencingEntity.class, refEntityId ); + withModifiedFlagReferencingEntity.setReference( null ); + withModifiedFlagReferencingEntity.setSecondReference( entity ); + em.merge( withModifiedFlagReferencingEntity ); em.getTransaction().commit(); // Revision 7 em.getTransaction().begin(); - entity.getStringSet().add("firstElement"); - entity.getStringSet().add("secondElement"); - entity = em.merge(entity); + entity.getStringSet().add( "firstElement" ); + entity.getStringSet().add( "secondElement" ); + entity = em.merge( entity ); em.getTransaction().commit(); // Revision 8 em.getTransaction().begin(); - entity.getStringSet().remove("secondElement"); - entity.getStringMap().put("someKey", "someValue"); - entity = em.merge(entity); + entity.getStringSet().remove( "secondElement" ); + entity.getStringMap().put( "someKey", "someValue" ); + entity = em.merge( entity ); em.getTransaction().commit(); // Revision 9 - main entity doesn't change em.getTransaction().begin(); - StrTestEntity strTestEntity = new StrTestEntity("first"); - em.persist(strTestEntity); + StrTestEntity strTestEntity = new StrTestEntity( "first" ); + em.persist( strTestEntity ); em.getTransaction().commit(); // Revision 10 em.getTransaction().begin(); - entity.getEntitiesSet().add(strTestEntity); - entity = em.merge(entity); + entity.getEntitiesSet().add( strTestEntity ); + entity = em.merge( entity ); em.getTransaction().commit(); // Revision 11 em.getTransaction().begin(); - entity.getEntitiesSet().remove(strTestEntity); - entity.getEntitiesMap().put("someKey", strTestEntity); - em.merge(entity); + entity.getEntitiesSet().remove( strTestEntity ); + entity.getEntitiesMap().put( "someKey", strTestEntity ); + em.merge( entity ); em.getTransaction().commit(); // Revision 12 - main entity doesn't change em.getTransaction().begin(); - strTestEntity.setStr("second"); - em.merge(strTestEntity); + strTestEntity.setStr( "second" ); + em.merge( strTestEntity ); em.getTransaction().commit(); } @Test - public void testRevisionsCounts() { - assertEquals(Arrays.asList((Number) 1, 2, 3, 4, 5, 6, 7, 8, 10, 11), + public void testRevisionsCounts() { + assertEquals( + Arrays.asList( (Number) 1, 2, 3, 4, 5, 6, 7, 8, 10, 11 ), getAuditReader() - .getRevisions(PartialModifiedFlagsEntity.class, - entityId)); - } + .getRevisions( + PartialModifiedFlagsEntity.class, + entityId + ) + ); + } @Test public void testHasChangedData() throws Exception { List list = queryForPropertyHasChanged( PartialModifiedFlagsEntity.class, - entityId, "data"); - assertEquals(1, list.size()); - assertEquals(makeList(2), extractRevisionNumbers(list)); + entityId, "data" + ); + assertEquals( 1, list.size() ); + assertEquals( makeList( 2 ), extractRevisionNumbers( list ) ); } @Test public void testHasChangedComp1() throws Exception { List list = queryForPropertyHasChanged( PartialModifiedFlagsEntity.class, - entityId, "comp1"); - assertEquals(1, list.size()); - assertEquals(makeList(3), extractRevisionNumbers(list)); + entityId, "comp1" + ); + assertEquals( 1, list.size() ); + assertEquals( makeList( 3 ), extractRevisionNumbers( list ) ); } @Test(expected = QueryException.class) public void testHasChangedComp2() throws Exception { - queryForPropertyHasChanged(PartialModifiedFlagsEntity.class, - entityId, "comp2"); + queryForPropertyHasChanged( + PartialModifiedFlagsEntity.class, + entityId, "comp2" + ); } @Test public void testHasChangedReferencing() throws Exception { List list = queryForPropertyHasChanged( PartialModifiedFlagsEntity.class, - entityId, "referencing"); - assertEquals(2, list.size()); - assertEquals(makeList(5, 6), extractRevisionNumbers(list)); + entityId, "referencing" + ); + assertEquals( 2, list.size() ); + assertEquals( makeList( 5, 6 ), extractRevisionNumbers( list ) ); } @Test(expected = QueryException.class) public void testHasChangedReferencing2() throws Exception { - queryForPropertyHasChanged(PartialModifiedFlagsEntity.class, - entityId, "referencing2"); + queryForPropertyHasChanged( + PartialModifiedFlagsEntity.class, + entityId, "referencing2" + ); } @Test public void testHasChangedStringSet() throws Exception { List list = queryForPropertyHasChanged( PartialModifiedFlagsEntity.class, - entityId, "stringSet"); - assertEquals(3, list.size()); - assertEquals(makeList(1, 7, 8), extractRevisionNumbers(list)); + entityId, "stringSet" + ); + assertEquals( 3, list.size() ); + assertEquals( makeList( 1, 7, 8 ), extractRevisionNumbers( list ) ); } @Test public void testHasChangedStringMap() throws Exception { List list = queryForPropertyHasChanged( PartialModifiedFlagsEntity.class, - entityId, "stringMap"); - assertEquals(2, list.size()); - assertEquals(makeList(1, 8), extractRevisionNumbers(list)); + entityId, "stringMap" + ); + assertEquals( 2, list.size() ); + assertEquals( makeList( 1, 8 ), extractRevisionNumbers( list ) ); } @Test public void testHasChangedStringSetAndMap() throws Exception { List list = queryForPropertyHasChanged( PartialModifiedFlagsEntity.class, - entityId, "stringSet", "stringMap"); - assertEquals(2, list.size()); - assertEquals(makeList(1, 8), extractRevisionNumbers(list)); + entityId, "stringSet", "stringMap" + ); + assertEquals( 2, list.size() ); + assertEquals( makeList( 1, 8 ), extractRevisionNumbers( list ) ); } @Test public void testHasChangedEntitiesSet() throws Exception { List list = queryForPropertyHasChanged( PartialModifiedFlagsEntity.class, - entityId, "entitiesSet"); - assertEquals(3, list.size()); - assertEquals(makeList(1, 10, 11), extractRevisionNumbers(list)); + entityId, "entitiesSet" + ); + assertEquals( 3, list.size() ); + assertEquals( makeList( 1, 10, 11 ), extractRevisionNumbers( list ) ); } @Test public void testHasChangedEntitiesMap() throws Exception { List list = queryForPropertyHasChanged( PartialModifiedFlagsEntity.class, - entityId, "entitiesMap"); - assertEquals(2, list.size()); - assertEquals(makeList(1, 11), extractRevisionNumbers(list)); + entityId, "entitiesMap" + ); + assertEquals( 2, list.size() ); + assertEquals( makeList( 1, 11 ), extractRevisionNumbers( list ) ); } @Test public void testHasChangedEntitiesSetAndMap() throws Exception { List list = queryForPropertyHasChanged( PartialModifiedFlagsEntity.class, - entityId, "entitiesSet", "entitiesMap"); - assertEquals(2, list.size()); - assertEquals(makeList(1, 11), extractRevisionNumbers(list)); + entityId, "entitiesSet", "entitiesMap" + ); + assertEquals( 2, list.size() ); + assertEquals( makeList( 1, 11 ), extractRevisionNumbers( list ) ); } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedIdMapKey.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedIdMapKey.java index ba0dd857ba..1b8837dc7c 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedIdMapKey.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedIdMapKey.java @@ -23,15 +23,15 @@ */ package org.hibernate.envers.test.integration.modifiedflags; -import java.util.List; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.List; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrTestEntity; import org.hibernate.envers.test.integration.collection.mapkey.IdMapKeyEntity; +import org.junit.Test; + import static junit.framework.Assert.assertEquals; import static org.hibernate.envers.test.tools.TestTools.extractRevisionNumbers; import static org.hibernate.envers.test.tools.TestTools.makeList; @@ -41,60 +41,64 @@ import static org.hibernate.envers.test.tools.TestTools.makeList; * @author Michal Skowronek (mskowr at o2 dot pl) */ public class HasChangedIdMapKey extends AbstractModifiedFlagsEntityTest { - private Integer imke_id; + private Integer imke_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { IdMapKeyEntity.class, StrTestEntity.class }; - } + return new Class[] {IdMapKeyEntity.class, StrTestEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - IdMapKeyEntity imke = new IdMapKeyEntity(); + IdMapKeyEntity imke = new IdMapKeyEntity(); - // Revision 1 (intialy 1 mapping) - em.getTransaction().begin(); + // Revision 1 (intialy 1 mapping) + em.getTransaction().begin(); - StrTestEntity ste1 = new StrTestEntity("x"); - StrTestEntity ste2 = new StrTestEntity("y"); + StrTestEntity ste1 = new StrTestEntity( "x" ); + StrTestEntity ste2 = new StrTestEntity( "y" ); - em.persist(ste1); - em.persist(ste2); + em.persist( ste1 ); + em.persist( ste2 ); - imke.getIdmap().put(ste1.getId(), ste1); + imke.getIdmap().put( ste1.getId(), ste1 ); - em.persist(imke); + em.persist( imke ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 (sse1: adding 1 mapping) - em.getTransaction().begin(); + // Revision 2 (sse1: adding 1 mapping) + em.getTransaction().begin(); - ste2 = em.find(StrTestEntity.class, ste2.getId()); - imke = em.find(IdMapKeyEntity.class, imke.getId()); + ste2 = em.find( StrTestEntity.class, ste2.getId() ); + imke = em.find( IdMapKeyEntity.class, imke.getId() ); - imke.getIdmap().put(ste2.getId(), ste2); + imke.getIdmap().put( ste2.getId(), ste2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // + // - imke_id = imke.getId(); + imke_id = imke.getId(); } @Test public void testHasChanged() throws Exception { - List list = queryForPropertyHasChanged(IdMapKeyEntity.class, imke_id, - "idmap"); - assertEquals(2, list.size()); - assertEquals(makeList(1, 2), extractRevisionNumbers(list)); + List list = queryForPropertyHasChanged( + IdMapKeyEntity.class, imke_id, + "idmap" + ); + assertEquals( 2, list.size() ); + assertEquals( makeList( 1, 2 ), extractRevisionNumbers( list ) ); - list = queryForPropertyHasNotChanged(IdMapKeyEntity.class, imke_id, - "idmap"); - assertEquals(0, list.size()); + list = queryForPropertyHasNotChanged( + IdMapKeyEntity.class, imke_id, + "idmap" + ); + assertEquals( 0, list.size() ); } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedManualFlush.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedManualFlush.java index b6d2630cad..153a7cef02 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedManualFlush.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedManualFlush.java @@ -1,12 +1,13 @@ package org.hibernate.envers.test.integration.modifiedflags; -import java.util.List; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.List; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.integration.basic.BasicTestEntity1; + +import org.junit.Test; + import org.hibernate.testing.TestForIssue; import static org.hibernate.envers.test.tools.TestTools.extractRevisionNumbers; @@ -22,7 +23,7 @@ public class HasChangedManualFlush extends AbstractModifiedFlagsEntityTest { @Override protected Class[] getAnnotatedClasses() { - return new Class[] { BasicTestEntity1.class }; + return new Class[] {BasicTestEntity1.class}; } @Test diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedManyToOneInComponent.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedManyToOneInComponent.java index b0eeee997c..1a771185f9 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedManyToOneInComponent.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedManyToOneInComponent.java @@ -23,16 +23,16 @@ */ package org.hibernate.envers.test.integration.modifiedflags; -import java.util.List; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.List; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrTestEntity; import org.hibernate.envers.test.entities.components.relations.ManyToOneComponent; import org.hibernate.envers.test.entities.components.relations.ManyToOneComponentTestEntity; +import org.junit.Test; + import static junit.framework.Assert.assertEquals; import static org.hibernate.envers.test.tools.TestTools.extractRevisionNumbers; import static org.hibernate.envers.test.tools.TestTools.makeList; @@ -42,63 +42,72 @@ import static org.hibernate.envers.test.tools.TestTools.makeList; * @author Michal Skowronek (mskowr at o2 dot pl) */ public class HasChangedManyToOneInComponent extends AbstractModifiedFlagsEntityTest { - private Integer mtocte_id1; + private Integer mtocte_id1; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { ManyToOneComponentTestEntity.class, StrTestEntity.class }; - } + return new Class[] {ManyToOneComponentTestEntity.class, StrTestEntity.class}; + } - @Test - @Priority(10) - public void initData() { - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); + @Test + @Priority(10) + public void initData() { + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); StrTestEntity ste1 = new StrTestEntity(); - ste1.setStr("str1"); + ste1.setStr( "str1" ); StrTestEntity ste2 = new StrTestEntity(); - ste2.setStr("str2"); + ste2.setStr( "str2" ); - em.persist(ste1); - em.persist(ste2); + em.persist( ste1 ); + em.persist( ste2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em = getEntityManager(); - em.getTransaction().begin(); + // Revision 2 + em = getEntityManager(); + em.getTransaction().begin(); - ManyToOneComponentTestEntity mtocte1 = new ManyToOneComponentTestEntity(new ManyToOneComponent(ste1, "data1")); + ManyToOneComponentTestEntity mtocte1 = new ManyToOneComponentTestEntity( + new ManyToOneComponent( + ste1, + "data1" + ) + ); - em.persist(mtocte1); + em.persist( mtocte1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 - em = getEntityManager(); - em.getTransaction().begin(); + // Revision 3 + em = getEntityManager(); + em.getTransaction().begin(); - mtocte1 = em.find(ManyToOneComponentTestEntity.class, mtocte1.getId()); - mtocte1.getComp1().setEntity(ste2); + mtocte1 = em.find( ManyToOneComponentTestEntity.class, mtocte1.getId() ); + mtocte1.getComp1().setEntity( ste2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - mtocte_id1 = mtocte1.getId(); + mtocte_id1 = mtocte1.getId(); } @Test public void testHasChangedId1() throws Exception { - List list = queryForPropertyHasChanged(ManyToOneComponentTestEntity.class, - mtocte_id1, "comp1"); - assertEquals(2, list.size()); - assertEquals(makeList(2, 3), extractRevisionNumbers(list)); + List list = queryForPropertyHasChanged( + ManyToOneComponentTestEntity.class, + mtocte_id1, "comp1" + ); + assertEquals( 2, list.size() ); + assertEquals( makeList( 2, 3 ), extractRevisionNumbers( list ) ); - list = queryForPropertyHasNotChanged(ManyToOneComponentTestEntity.class, - mtocte_id1, "comp1"); - assertEquals(0, list.size()); + list = queryForPropertyHasNotChanged( + ManyToOneComponentTestEntity.class, + mtocte_id1, "comp1" + ); + assertEquals( 0, list.size() ); } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedMergeTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedMergeTest.java index 6971ce9da4..5155eb5f5e 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedMergeTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedMergeTest.java @@ -1,14 +1,15 @@ package org.hibernate.envers.test.integration.modifiedflags; +import javax.persistence.EntityManager; import java.util.ArrayList; import java.util.List; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.onetomany.ListRefEdEntity; import org.hibernate.envers.test.entities.onetomany.ListRefIngEntity; + +import org.junit.Test; + import org.hibernate.testing.TestForIssue; import static org.hibernate.envers.test.tools.TestTools.extractRevisionNumbers; @@ -27,7 +28,7 @@ public class HasChangedMergeTest extends AbstractModifiedFlagsEntityTest { @Override protected Class[] getAnnotatedClasses() { - return new Class[] { ListRefEdEntity.class, ListRefIngEntity.class }; + return new Class[] {ListRefEdEntity.class, ListRefIngEntity.class}; } @Test diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedNotOwnedBidirectional.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedNotOwnedBidirectional.java index 93d3c43962..1bb69c38a3 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedNotOwnedBidirectional.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedNotOwnedBidirectional.java @@ -24,16 +24,16 @@ package org.hibernate.envers.test.integration.modifiedflags; -import java.util.List; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.List; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.integration.inheritance.joined.notownedrelation.Address; import org.hibernate.envers.test.integration.inheritance.joined.notownedrelation.Contact; import org.hibernate.envers.test.integration.inheritance.joined.notownedrelation.PersonalContact; +import org.junit.Test; + import static junit.framework.Assert.assertEquals; import static org.hibernate.envers.test.tools.TestTools.extractRevisionNumbers; import static org.hibernate.envers.test.tools.TestTools.makeList; @@ -43,63 +43,65 @@ import static org.hibernate.envers.test.tools.TestTools.makeList; * @author Michal Skowronek (mskowr at o2 dot pl) */ public class HasChangedNotOwnedBidirectional extends AbstractModifiedFlagsEntityTest { - private Long pc_id; - private Long a1_id; - private Long a2_id; + private Long pc_id; + private Long a1_id; + private Long a2_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { Address.class, Contact.class, PersonalContact.class }; - } + return new Class[] {Address.class, Contact.class, PersonalContact.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - pc_id = 1l; - a1_id = 10l; - a2_id = 100l; + pc_id = 1l; + a1_id = 10l; + a2_id = 100l; - // Rev 1 - em.getTransaction().begin(); + // Rev 1 + em.getTransaction().begin(); - PersonalContact pc = new PersonalContact(pc_id, "e", "f"); + PersonalContact pc = new PersonalContact( pc_id, "e", "f" ); - Address a1 = new Address(a1_id, "a1"); - a1.setContact(pc); + Address a1 = new Address( a1_id, "a1" ); + a1.setContact( pc ); - em.persist(pc); - em.persist(a1); + em.persist( pc ); + em.persist( a1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Rev 2 - em.getTransaction().begin(); + // Rev 2 + em.getTransaction().begin(); - pc = em.find(PersonalContact.class, pc_id); + pc = em.find( PersonalContact.class, pc_id ); - Address a2 = new Address(a2_id, "a2"); - a2.setContact(pc); + Address a2 = new Address( a2_id, "a2" ); + a2.setContact( pc ); - em.persist(a2); + em.persist( a2 ); - em.getTransaction().commit(); - } + em.getTransaction().commit(); + } @Test public void testReferencedEntityHasChanged() throws Exception { - List list = queryForPropertyHasChanged(PersonalContact.class, pc_id, - "addresses"); - assertEquals(2, list.size()); - assertEquals(makeList(1, 2), extractRevisionNumbers(list)); + List list = queryForPropertyHasChanged( + PersonalContact.class, pc_id, + "addresses" + ); + assertEquals( 2, list.size() ); + assertEquals( makeList( 1, 2 ), extractRevisionNumbers( list ) ); - list = queryForPropertyHasChanged(Address.class, a1_id, "contact"); - assertEquals(1, list.size()); - assertEquals(makeList(1), extractRevisionNumbers(list)); + list = queryForPropertyHasChanged( Address.class, a1_id, "contact" ); + assertEquals( 1, list.size() ); + assertEquals( makeList( 1 ), extractRevisionNumbers( list ) ); - list = queryForPropertyHasChanged(Address.class, a2_id, "contact"); - assertEquals(1, list.size()); - assertEquals(makeList(2), extractRevisionNumbers(list)); + list = queryForPropertyHasChanged( Address.class, a2_id, "contact" ); + assertEquals( 1, list.size() ); + assertEquals( makeList( 2 ), extractRevisionNumbers( list ) ); } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedNullProperties.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedNullProperties.java index a5b78bf811..341f48eed2 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedNullProperties.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedNullProperties.java @@ -23,15 +23,15 @@ */ package org.hibernate.envers.test.integration.modifiedflags; -import java.util.List; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.List; import org.hibernate.envers.query.AuditEntity; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.integration.basic.BasicTestEntity1; +import org.junit.Test; + import static junit.framework.Assert.assertEquals; import static org.hibernate.envers.test.tools.TestTools.extractRevisionNumbers; import static org.hibernate.envers.test.tools.TestTools.makeList; @@ -41,71 +41,79 @@ import static org.hibernate.envers.test.tools.TestTools.makeList; * @author Michal Skowronek (mskowr at o2 dot pl) */ public class HasChangedNullProperties extends AbstractModifiedFlagsEntityTest { - private Integer id1; - private Integer id2; + private Integer id1; + private Integer id2; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { BasicTestEntity1.class }; - } + return new Class[] {BasicTestEntity1.class}; + } - private Integer addNewEntity(String str, long lng) { - EntityManager em = getEntityManager(); - em.getTransaction().begin(); - BasicTestEntity1 bte1 = new BasicTestEntity1(str, lng); - em.persist(bte1); - em.getTransaction().commit(); + private Integer addNewEntity(String str, long lng) { + EntityManager em = getEntityManager(); + em.getTransaction().begin(); + BasicTestEntity1 bte1 = new BasicTestEntity1( str, lng ); + em.persist( bte1 ); + em.getTransaction().commit(); - return bte1.getId(); - } + return bte1.getId(); + } - private void modifyEntity(Integer id, String str, long lng) { - EntityManager em = getEntityManager(); - em.getTransaction().begin(); - BasicTestEntity1 bte1 = em.find(BasicTestEntity1.class, id); - bte1.setLong1(lng); - bte1.setStr1(str); - em.getTransaction().commit(); - } + private void modifyEntity(Integer id, String str, long lng) { + EntityManager em = getEntityManager(); + em.getTransaction().begin(); + BasicTestEntity1 bte1 = em.find( BasicTestEntity1.class, id ); + bte1.setLong1( lng ); + bte1.setStr1( str ); + em.getTransaction().commit(); + } - @Test - @Priority(10) - public void initData() { - id1 = addNewEntity("x", 1); // rev 1 - id2 = addNewEntity(null, 20); // rev 2 + @Test + @Priority(10) + public void initData() { + id1 = addNewEntity( "x", 1 ); // rev 1 + id2 = addNewEntity( null, 20 ); // rev 2 - modifyEntity(id1, null, 1); // rev 3 - modifyEntity(id2, "y2", 20); // rev 4 - } + modifyEntity( id1, null, 1 ); // rev 3 + modifyEntity( id2, "y2", 20 ); // rev 4 + } @Test public void testHasChanged() throws Exception { - List list = queryForPropertyHasChangedWithDeleted(BasicTestEntity1.class, - id1, "str1"); - assertEquals(2, list.size()); - assertEquals(makeList(1, 3), extractRevisionNumbers(list)); + List list = queryForPropertyHasChangedWithDeleted( + BasicTestEntity1.class, + id1, "str1" + ); + assertEquals( 2, list.size() ); + assertEquals( makeList( 1, 3 ), extractRevisionNumbers( list ) ); - list = queryForPropertyHasChangedWithDeleted(BasicTestEntity1.class, - id1, "long1"); - assertEquals(1, list.size()); - assertEquals(makeList(1), extractRevisionNumbers(list)); + list = queryForPropertyHasChangedWithDeleted( + BasicTestEntity1.class, + id1, "long1" + ); + assertEquals( 1, list.size() ); + assertEquals( makeList( 1 ), extractRevisionNumbers( list ) ); - list = queryForPropertyHasChangedWithDeleted(BasicTestEntity1.class, - id2, "str1"); + list = queryForPropertyHasChangedWithDeleted( + BasicTestEntity1.class, + id2, "str1" + ); // str1 property was null before insert and after insert so in a way it didn't change - is it a good way to go? - assertEquals(1, list.size()); - assertEquals(makeList(4), extractRevisionNumbers(list)); + assertEquals( 1, list.size() ); + assertEquals( makeList( 4 ), extractRevisionNumbers( list ) ); - list = queryForPropertyHasChangedWithDeleted(BasicTestEntity1.class, - id2, "long1"); - assertEquals(1, list.size()); - assertEquals(makeList(2), extractRevisionNumbers(list)); + list = queryForPropertyHasChangedWithDeleted( + BasicTestEntity1.class, + id2, "long1" + ); + assertEquals( 1, list.size() ); + assertEquals( makeList( 2 ), extractRevisionNumbers( list ) ); - list = getAuditReader().createQuery().forRevisionsOfEntity(BasicTestEntity1.class, false, true) - .add(AuditEntity.property("str1").hasChanged()) - .add(AuditEntity.property("long1").hasChanged()) + list = getAuditReader().createQuery().forRevisionsOfEntity( BasicTestEntity1.class, false, true ) + .add( AuditEntity.property( "str1" ).hasChanged() ) + .add( AuditEntity.property( "long1" ).hasChanged() ) .getResultList(); - assertEquals(1, list.size()); - assertEquals(makeList(1), extractRevisionNumbers(list)); + assertEquals( 1, list.size() ); + assertEquals( makeList( 1 ), extractRevisionNumbers( list ) ); } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedOneToManyInComponent.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedOneToManyInComponent.java index 9af0928020..e6453884f2 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedOneToManyInComponent.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedOneToManyInComponent.java @@ -23,16 +23,16 @@ */ package org.hibernate.envers.test.integration.modifiedflags; -import java.util.List; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.List; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrTestEntity; import org.hibernate.envers.test.entities.components.relations.OneToManyComponent; import org.hibernate.envers.test.entities.components.relations.OneToManyComponentTestEntity; +import org.junit.Test; + import static junit.framework.Assert.assertEquals; import static org.hibernate.envers.test.tools.TestTools.extractRevisionNumbers; import static org.hibernate.envers.test.tools.TestTools.makeList; @@ -42,64 +42,68 @@ import static org.hibernate.envers.test.tools.TestTools.makeList; * @author Michal Skowronek (mskowr at o2 dot pl) */ public class HasChangedOneToManyInComponent extends AbstractModifiedFlagsEntityTest { - private Integer otmcte_id1; + private Integer otmcte_id1; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { OneToManyComponentTestEntity.class, StrTestEntity.class }; - } + return new Class[] {OneToManyComponentTestEntity.class, StrTestEntity.class}; + } - @Test - @Priority(10) - public void initData() { - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); + @Test + @Priority(10) + public void initData() { + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); StrTestEntity ste1 = new StrTestEntity(); - ste1.setStr("str1"); + ste1.setStr( "str1" ); StrTestEntity ste2 = new StrTestEntity(); - ste2.setStr("str2"); + ste2.setStr( "str2" ); - em.persist(ste1); - em.persist(ste2); + em.persist( ste1 ); + em.persist( ste2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em = getEntityManager(); - em.getTransaction().begin(); + // Revision 2 + em = getEntityManager(); + em.getTransaction().begin(); - OneToManyComponentTestEntity otmcte1 = new OneToManyComponentTestEntity(new OneToManyComponent("data1")); - otmcte1.getComp1().getEntities().add(ste1); + OneToManyComponentTestEntity otmcte1 = new OneToManyComponentTestEntity( new OneToManyComponent( "data1" ) ); + otmcte1.getComp1().getEntities().add( ste1 ); - em.persist(otmcte1); + em.persist( otmcte1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 - em = getEntityManager(); - em.getTransaction().begin(); + // Revision 3 + em = getEntityManager(); + em.getTransaction().begin(); - otmcte1 = em.find(OneToManyComponentTestEntity.class, otmcte1.getId()); - otmcte1.getComp1().getEntities().add(ste2); + otmcte1 = em.find( OneToManyComponentTestEntity.class, otmcte1.getId() ); + otmcte1.getComp1().getEntities().add( ste2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - otmcte_id1 = otmcte1.getId(); + otmcte_id1 = otmcte1.getId(); } @Test public void testHasChangedId1() throws Exception { List list = - queryForPropertyHasChanged(OneToManyComponentTestEntity.class, - otmcte_id1, "comp1"); - assertEquals(2, list.size()); - assertEquals(makeList(2, 3), extractRevisionNumbers(list)); + queryForPropertyHasChanged( + OneToManyComponentTestEntity.class, + otmcte_id1, "comp1" + ); + assertEquals( 2, list.size() ); + assertEquals( makeList( 2, 3 ), extractRevisionNumbers( list ) ); - list = queryForPropertyHasNotChanged(OneToManyComponentTestEntity.class, - otmcte_id1, "comp1"); - assertEquals(0, list.size()); + list = queryForPropertyHasNotChanged( + OneToManyComponentTestEntity.class, + otmcte_id1, "comp1" + ); + assertEquals( 0, list.size() ); } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedStringMap.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedStringMap.java index b5ef7f5a71..9eddbe9f84 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedStringMap.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedStringMap.java @@ -23,14 +23,14 @@ */ package org.hibernate.envers.test.integration.modifiedflags; -import java.util.List; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.List; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.collection.StringMapEntity; +import org.junit.Test; + import static junit.framework.Assert.assertEquals; import static org.hibernate.envers.test.tools.TestTools.extractRevisionNumbers; import static org.hibernate.envers.test.tools.TestTools.makeList; @@ -40,89 +40,97 @@ import static org.hibernate.envers.test.tools.TestTools.makeList; * @author Michal Skowronek (mskowr at o2 dot pl) */ public class HasChangedStringMap extends AbstractModifiedFlagsEntityTest { - private Integer sme1_id; - private Integer sme2_id; + private Integer sme1_id; + private Integer sme2_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { StringMapEntity.class }; - } + return new Class[] {StringMapEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - StringMapEntity sme1 = new StringMapEntity(); - StringMapEntity sme2 = new StringMapEntity(); + StringMapEntity sme1 = new StringMapEntity(); + StringMapEntity sme2 = new StringMapEntity(); - // Revision 1 (sme1: initialy empty, sme2: initialy 1 mapping) - em.getTransaction().begin(); + // Revision 1 (sme1: initialy empty, sme2: initialy 1 mapping) + em.getTransaction().begin(); - sme2.getStrings().put("1", "a"); + sme2.getStrings().put( "1", "a" ); - em.persist(sme1); - em.persist(sme2); + em.persist( sme1 ); + em.persist( sme2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 (sme1: adding 2 mappings, sme2: no changes) - em.getTransaction().begin(); + // Revision 2 (sme1: adding 2 mappings, sme2: no changes) + em.getTransaction().begin(); - sme1 = em.find(StringMapEntity.class, sme1.getId()); - sme2 = em.find(StringMapEntity.class, sme2.getId()); + sme1 = em.find( StringMapEntity.class, sme1.getId() ); + sme2 = em.find( StringMapEntity.class, sme2.getId() ); - sme1.getStrings().put("1", "a"); - sme1.getStrings().put("2", "b"); + sme1.getStrings().put( "1", "a" ); + sme1.getStrings().put( "2", "b" ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 (sme1: removing an existing mapping, sme2: replacing a value) - em.getTransaction().begin(); + // Revision 3 (sme1: removing an existing mapping, sme2: replacing a value) + em.getTransaction().begin(); - sme1 = em.find(StringMapEntity.class, sme1.getId()); - sme2 = em.find(StringMapEntity.class, sme2.getId()); + sme1 = em.find( StringMapEntity.class, sme1.getId() ); + sme2 = em.find( StringMapEntity.class, sme2.getId() ); - sme1.getStrings().remove("1"); - sme2.getStrings().put("1", "b"); - - em.getTransaction().commit(); + sme1.getStrings().remove( "1" ); + sme2.getStrings().put( "1", "b" ); - // No revision (sme1: removing a non-existing mapping, sme2: replacing with the same value) - em.getTransaction().begin(); + em.getTransaction().commit(); - sme1 = em.find(StringMapEntity.class, sme1.getId()); - sme2 = em.find(StringMapEntity.class, sme2.getId()); + // No revision (sme1: removing a non-existing mapping, sme2: replacing with the same value) + em.getTransaction().begin(); - sme1.getStrings().remove("3"); - sme2.getStrings().put("1", "b"); + sme1 = em.find( StringMapEntity.class, sme1.getId() ); + sme2 = em.find( StringMapEntity.class, sme2.getId() ); - em.getTransaction().commit(); + sme1.getStrings().remove( "3" ); + sme2.getStrings().put( "1", "b" ); - // + em.getTransaction().commit(); - sme1_id = sme1.getId(); - sme2_id = sme2.getId(); - } + // + + sme1_id = sme1.getId(); + sme2_id = sme2.getId(); + } @Test public void testHasChanged() throws Exception { - List list = queryForPropertyHasChanged(StringMapEntity.class, sme1_id, - "strings"); - assertEquals(3, list.size()); - assertEquals(makeList(1, 2, 3), extractRevisionNumbers(list)); + List list = queryForPropertyHasChanged( + StringMapEntity.class, sme1_id, + "strings" + ); + assertEquals( 3, list.size() ); + assertEquals( makeList( 1, 2, 3 ), extractRevisionNumbers( list ) ); - list = queryForPropertyHasChanged(StringMapEntity.class, sme2_id, - "strings"); - assertEquals(2, list.size()); - assertEquals(makeList(1, 3), extractRevisionNumbers(list)); + list = queryForPropertyHasChanged( + StringMapEntity.class, sme2_id, + "strings" + ); + assertEquals( 2, list.size() ); + assertEquals( makeList( 1, 3 ), extractRevisionNumbers( list ) ); - list = queryForPropertyHasNotChanged(StringMapEntity.class, sme1_id, - "strings"); - assertEquals(0, list.size()); + list = queryForPropertyHasNotChanged( + StringMapEntity.class, sme1_id, + "strings" + ); + assertEquals( 0, list.size() ); - list = queryForPropertyHasNotChanged(StringMapEntity.class, sme2_id, - "strings"); - assertEquals(0, list.size()); // in rev 2 there was no version generated for sme2_id + list = queryForPropertyHasNotChanged( + StringMapEntity.class, sme2_id, + "strings" + ); + assertEquals( 0, list.size() ); // in rev 2 there was no version generated for sme2_id } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedStringSet.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedStringSet.java index 3ed5328f6d..af83adbf2c 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedStringSet.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedStringSet.java @@ -23,14 +23,14 @@ */ package org.hibernate.envers.test.integration.modifiedflags; -import java.util.List; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.List; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.collection.StringSetEntity; +import org.junit.Test; + import static junit.framework.Assert.assertEquals; import static org.hibernate.envers.test.tools.TestTools.extractRevisionNumbers; import static org.hibernate.envers.test.tools.TestTools.makeList; @@ -40,81 +40,89 @@ import static org.hibernate.envers.test.tools.TestTools.makeList; * @author Michal Skowronek (mskowr at o2 dot pl) */ public class HasChangedStringSet extends AbstractModifiedFlagsEntityTest { - private Integer sse1_id; - private Integer sse2_id; + private Integer sse1_id; + private Integer sse2_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { StringSetEntity.class }; - } + return new Class[] {StringSetEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - StringSetEntity sse1 = new StringSetEntity(); - StringSetEntity sse2 = new StringSetEntity(); + StringSetEntity sse1 = new StringSetEntity(); + StringSetEntity sse2 = new StringSetEntity(); - // Revision 1 (sse1: initialy empty, sse2: initialy 2 elements) - em.getTransaction().begin(); + // Revision 1 (sse1: initialy empty, sse2: initialy 2 elements) + em.getTransaction().begin(); - sse2.getStrings().add("sse2_string1"); - sse2.getStrings().add("sse2_string2"); + sse2.getStrings().add( "sse2_string1" ); + sse2.getStrings().add( "sse2_string2" ); - em.persist(sse1); - em.persist(sse2); + em.persist( sse1 ); + em.persist( sse2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 (sse1: adding 2 elements, sse2: adding an existing element) - em.getTransaction().begin(); + // Revision 2 (sse1: adding 2 elements, sse2: adding an existing element) + em.getTransaction().begin(); - sse1 = em.find(StringSetEntity.class, sse1.getId()); - sse2 = em.find(StringSetEntity.class, sse2.getId()); + sse1 = em.find( StringSetEntity.class, sse1.getId() ); + sse2 = em.find( StringSetEntity.class, sse2.getId() ); - sse1.getStrings().add("sse1_string1"); - sse1.getStrings().add("sse1_string2"); + sse1.getStrings().add( "sse1_string1" ); + sse1.getStrings().add( "sse1_string2" ); - sse2.getStrings().add("sse2_string1"); + sse2.getStrings().add( "sse2_string1" ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 (sse1: removing a non-existing element, sse2: removing one element) - em.getTransaction().begin(); + // Revision 3 (sse1: removing a non-existing element, sse2: removing one element) + em.getTransaction().begin(); - sse1 = em.find(StringSetEntity.class, sse1.getId()); - sse2 = em.find(StringSetEntity.class, sse2.getId()); + sse1 = em.find( StringSetEntity.class, sse1.getId() ); + sse2 = em.find( StringSetEntity.class, sse2.getId() ); - sse1.getStrings().remove("sse1_string3"); - sse2.getStrings().remove("sse2_string1"); + sse1.getStrings().remove( "sse1_string3" ); + sse2.getStrings().remove( "sse2_string1" ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // + // - sse1_id = sse1.getId(); - sse2_id = sse2.getId(); - } + sse1_id = sse1.getId(); + sse2_id = sse2.getId(); + } @Test public void testHasChanged() throws Exception { - List list = queryForPropertyHasChanged(StringSetEntity.class, sse1_id, - "strings"); - assertEquals(2, list.size()); - assertEquals(makeList(1, 2), extractRevisionNumbers(list)); + List list = queryForPropertyHasChanged( + StringSetEntity.class, sse1_id, + "strings" + ); + assertEquals( 2, list.size() ); + assertEquals( makeList( 1, 2 ), extractRevisionNumbers( list ) ); - list = queryForPropertyHasChanged(StringSetEntity.class, sse2_id, - "strings"); - assertEquals(2, list.size()); - assertEquals(makeList(1, 3), extractRevisionNumbers(list)); + list = queryForPropertyHasChanged( + StringSetEntity.class, sse2_id, + "strings" + ); + assertEquals( 2, list.size() ); + assertEquals( makeList( 1, 3 ), extractRevisionNumbers( list ) ); - list = queryForPropertyHasNotChanged(StringSetEntity.class, sse1_id, - "strings"); - assertEquals(0, list.size()); + list = queryForPropertyHasNotChanged( + StringSetEntity.class, sse1_id, + "strings" + ); + assertEquals( 0, list.size() ); - list = queryForPropertyHasNotChanged(StringSetEntity.class, sse2_id, - "strings"); - assertEquals(0, list.size()); + list = queryForPropertyHasNotChanged( + StringSetEntity.class, sse2_id, + "strings" + ); + assertEquals( 0, list.size() ); } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedUnversionedProperties.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedUnversionedProperties.java index 6c3f430726..828c0eff4c 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedUnversionedProperties.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/HasChangedUnversionedProperties.java @@ -23,15 +23,15 @@ */ package org.hibernate.envers.test.integration.modifiedflags; -import java.util.List; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.List; import org.hibernate.QueryException; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.integration.basic.BasicTestEntity2; +import org.junit.Test; + import static junit.framework.Assert.assertEquals; import static org.hibernate.envers.test.tools.TestTools.extractRevisionNumbers; import static org.hibernate.envers.test.tools.TestTools.makeList; @@ -41,52 +41,56 @@ import static org.hibernate.envers.test.tools.TestTools.makeList; * @author Michal Skowronek (mskowr at o2 dot pl) */ public class HasChangedUnversionedProperties extends AbstractModifiedFlagsEntityTest { - private Integer id1; + private Integer id1; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { BasicTestEntity2.class }; - } + return new Class[] {BasicTestEntity2.class}; + } - private Integer addNewEntity(String str1, String str2) { - EntityManager em = getEntityManager(); - em.getTransaction().begin(); - BasicTestEntity2 bte2 = new BasicTestEntity2(str1, str2); - em.persist(bte2); - em.getTransaction().commit(); + private Integer addNewEntity(String str1, String str2) { + EntityManager em = getEntityManager(); + em.getTransaction().begin(); + BasicTestEntity2 bte2 = new BasicTestEntity2( str1, str2 ); + em.persist( bte2 ); + em.getTransaction().commit(); - return bte2.getId(); - } + return bte2.getId(); + } - private void modifyEntity(Integer id, String str1, String str2) { - EntityManager em = getEntityManager(); - em.getTransaction().begin(); - BasicTestEntity2 bte2 = em.find(BasicTestEntity2.class, id); - bte2.setStr1(str1); - bte2.setStr2(str2); - em.getTransaction().commit(); - } + private void modifyEntity(Integer id, String str1, String str2) { + EntityManager em = getEntityManager(); + em.getTransaction().begin(); + BasicTestEntity2 bte2 = em.find( BasicTestEntity2.class, id ); + bte2.setStr1( str1 ); + bte2.setStr2( str2 ); + em.getTransaction().commit(); + } - @Test - @Priority(10) - public void initData() { - id1 = addNewEntity("x", "a"); // rev 1 - modifyEntity(id1, "x", "a"); // no rev - modifyEntity(id1, "y", "b"); // rev 2 - modifyEntity(id1, "y", "c"); // no rev - } + @Test + @Priority(10) + public void initData() { + id1 = addNewEntity( "x", "a" ); // rev 1 + modifyEntity( id1, "x", "a" ); // no rev + modifyEntity( id1, "y", "b" ); // rev 2 + modifyEntity( id1, "y", "c" ); // no rev + } @Test public void testHasChangedQuery() throws Exception { - List list = queryForPropertyHasChanged(BasicTestEntity2.class, - id1, "str1"); - assertEquals(2, list.size()); - assertEquals(makeList(1, 2), extractRevisionNumbers(list)); + List list = queryForPropertyHasChanged( + BasicTestEntity2.class, + id1, "str1" + ); + assertEquals( 2, list.size() ); + assertEquals( makeList( 1, 2 ), extractRevisionNumbers( list ) ); } @Test(expected = QueryException.class) public void testExceptionOnHasChangedQuery() throws Exception { - queryForPropertyHasChangedWithDeleted(BasicTestEntity2.class, - id1, "str2"); + queryForPropertyHasChangedWithDeleted( + BasicTestEntity2.class, + id1, "str2" + ); } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/ModifiedFlagSuffix.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/ModifiedFlagSuffix.java index dcef9d8aa5..a88b79d180 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/ModifiedFlagSuffix.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/ModifiedFlagSuffix.java @@ -23,11 +23,9 @@ */ package org.hibernate.envers.test.integration.modifiedflags; +import javax.persistence.EntityManager; import java.util.List; import java.util.Map; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.configuration.EnversSettings; import org.hibernate.envers.query.AuditEntity; @@ -35,6 +33,8 @@ import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.integration.basic.BasicTestEntity1; import org.hibernate.envers.test.tools.TestTools; +import org.junit.Test; + import static junit.framework.Assert.assertEquals; import static org.hibernate.envers.test.tools.TestTools.extractRevisionNumbers; import static org.hibernate.envers.test.tools.TestTools.makeList; @@ -44,60 +44,69 @@ import static org.hibernate.envers.test.tools.TestTools.makeList; * @author Michal Skowronek (mskowr at o2 dot pl) */ public class ModifiedFlagSuffix extends AbstractModifiedFlagsEntityTest { - private Integer id1; + private Integer id1; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { BasicTestEntity1.class }; - } + return new Class[] {BasicTestEntity1.class}; + } @Override protected void addConfigOptions(Map options) { - super.addConfigOptions(options); - options.put(EnversSettings.MODIFIED_FLAG_SUFFIX, "_CHANGED"); + super.addConfigOptions( options ); + options.put( EnversSettings.MODIFIED_FLAG_SUFFIX, "_CHANGED" ); } private Integer addNewEntity(String str, long lng) { - EntityManager em = getEntityManager(); - em.getTransaction().begin(); - BasicTestEntity1 bte1 = new BasicTestEntity1(str, lng); - em.persist(bte1); - em.getTransaction().commit(); + EntityManager em = getEntityManager(); + em.getTransaction().begin(); + BasicTestEntity1 bte1 = new BasicTestEntity1( str, lng ); + em.persist( bte1 ); + em.getTransaction().commit(); - return bte1.getId(); - } + return bte1.getId(); + } - @Test - @Priority(10) - public void initData() { - id1 = addNewEntity("x", 1); // rev 1 - } + @Test + @Priority(10) + public void initData() { + id1 = addNewEntity( "x", 1 ); // rev 1 + } @Test public void testModFlagProperties() { - assertEquals(TestTools.makeSet("str1_CHANGED", "long1_CHANGED"), - TestTools.extractModProperties(getCfg().getClassMapping( - "org.hibernate.envers.test.integration.basic.BasicTestEntity1_AUD"), - "_CHANGED")); + assertEquals( + TestTools.makeSet( "str1_CHANGED", "long1_CHANGED" ), + TestTools.extractModProperties( + getCfg().getClassMapping( + "org.hibernate.envers.test.integration.basic.BasicTestEntity1_AUD" + ), + "_CHANGED" + ) + ); } @Test public void testHasChanged() throws Exception { - List list = queryForPropertyHasChangedWithDeleted(BasicTestEntity1.class, - id1, "str1"); - assertEquals(1, list.size()); - assertEquals(makeList(1), extractRevisionNumbers(list)); + List list = queryForPropertyHasChangedWithDeleted( + BasicTestEntity1.class, + id1, "str1" + ); + assertEquals( 1, list.size() ); + assertEquals( makeList( 1 ), extractRevisionNumbers( list ) ); - list = queryForPropertyHasChangedWithDeleted(BasicTestEntity1.class, - id1, "long1"); - assertEquals(1, list.size()); - assertEquals(makeList(1), extractRevisionNumbers(list)); + list = queryForPropertyHasChangedWithDeleted( + BasicTestEntity1.class, + id1, "long1" + ); + assertEquals( 1, list.size() ); + assertEquals( makeList( 1 ), extractRevisionNumbers( list ) ); - list = getAuditReader().createQuery().forRevisionsOfEntity(BasicTestEntity1.class, false, true) - .add(AuditEntity.property("str1").hasChanged()) - .add(AuditEntity.property("long1").hasChanged()) + list = getAuditReader().createQuery().forRevisionsOfEntity( BasicTestEntity1.class, false, true ) + .add( AuditEntity.property( "str1" ).hasChanged() ) + .add( AuditEntity.property( "long1" ).hasChanged() ) .getResultList(); - assertEquals(1, list.size()); - assertEquals(makeList(1), extractRevisionNumbers(list)); + assertEquals( 1, list.size() ); + assertEquals( makeList( 1 ), extractRevisionNumbers( list ) ); } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/entities/PartialModifiedFlagsEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/entities/PartialModifiedFlagsEntity.java index d06d16e5af..76e22e31b6 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/entities/PartialModifiedFlagsEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/entities/PartialModifiedFlagsEntity.java @@ -23,10 +23,6 @@ */ package org.hibernate.envers.test.integration.modifiedflags.entities; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; import javax.persistence.CollectionTable; import javax.persistence.ElementCollection; import javax.persistence.Embedded; @@ -37,6 +33,10 @@ import javax.persistence.ManyToMany; import javax.persistence.MapKeyColumn; import javax.persistence.OneToOne; import javax.persistence.Table; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; import org.hibernate.envers.AuditJoinTable; import org.hibernate.envers.Audited; @@ -51,51 +51,51 @@ import org.hibernate.envers.test.entities.components.Component2; @Table(name = "PartialModFlags") @Audited(withModifiedFlag = false) public class PartialModifiedFlagsEntity { - @Id - private Integer id; + @Id + private Integer id; - @Audited(withModifiedFlag = true) - private String data; + @Audited(withModifiedFlag = true) + private String data; @Audited(withModifiedFlag = true) @Embedded - private Component1 comp1; + private Component1 comp1; @Audited(withModifiedFlag = false) @Embedded - private Component2 comp2; + private Component2 comp2; - @Audited(withModifiedFlag = true) - @OneToOne(mappedBy="reference") - private WithModifiedFlagReferencingEntity referencing; + @Audited(withModifiedFlag = true) + @OneToOne(mappedBy = "reference") + private WithModifiedFlagReferencingEntity referencing; @Audited(withModifiedFlag = false) - @OneToOne(mappedBy="secondReference") - private WithModifiedFlagReferencingEntity referencing2; + @OneToOne(mappedBy = "secondReference") + private WithModifiedFlagReferencingEntity referencing2; - @Audited(withModifiedFlag = true) - @ElementCollection - @JoinTable(name = "PartialModFlags_StrSet") - @AuditJoinTable(name = "PartialModFlags_StrSet_AUD") - private Set stringSet = new HashSet(); + @Audited(withModifiedFlag = true) + @ElementCollection + @JoinTable(name = "PartialModFlags_StrSet") + @AuditJoinTable(name = "PartialModFlags_StrSet_AUD") + private Set stringSet = new HashSet(); @Audited(withModifiedFlag = true) @ManyToMany @CollectionTable(name = "ENTITIESSET") - private Set entitiesSet = new HashSet(); + private Set entitiesSet = new HashSet(); @Audited(withModifiedFlag = true) @ElementCollection - @MapKeyColumn(nullable=false) - @JoinTable(name = "PartialModFlags_StrMap") - @AuditJoinTable(name = "PartialModFlags_StrMap_AUD") - private Map stringMap = new HashMap(); + @MapKeyColumn(nullable = false) + @JoinTable(name = "PartialModFlags_StrMap") + @AuditJoinTable(name = "PartialModFlags_StrMap_AUD") + private Map stringMap = new HashMap(); @Audited(withModifiedFlag = true) - @ManyToMany - @CollectionTable(name = "ENTITIESMAP") - @MapKeyColumn(nullable = false) - private Map entitiesMap = + @ManyToMany + @CollectionTable(name = "ENTITIESMAP") + @MapKeyColumn(nullable = false) + private Map entitiesMap = new HashMap(); public PartialModifiedFlagsEntity() { @@ -106,36 +106,36 @@ public class PartialModifiedFlagsEntity { } public Integer getId() { - return id; - } + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public WithModifiedFlagReferencingEntity getReferencing() { - return referencing; - } + public WithModifiedFlagReferencingEntity getReferencing() { + return referencing; + } - public void setReferencing(WithModifiedFlagReferencingEntity referencing) { - this.referencing = referencing; - } + public void setReferencing(WithModifiedFlagReferencingEntity referencing) { + this.referencing = referencing; + } public WithModifiedFlagReferencingEntity getReferencing2() { - return referencing2; - } + return referencing2; + } - public void setReferencing2(WithModifiedFlagReferencingEntity referencing) { - this.referencing2 = referencing; - } + public void setReferencing2(WithModifiedFlagReferencingEntity referencing) { + this.referencing2 = referencing; + } public Component1 getComp1() { return comp1; @@ -186,21 +186,29 @@ public class PartialModifiedFlagsEntity { } public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof PartialModifiedFlagsEntity)) return false; + if ( this == o ) { + return true; + } + if ( !(o instanceof PartialModifiedFlagsEntity) ) { + return false; + } - PartialModifiedFlagsEntity that = (PartialModifiedFlagsEntity) o; + PartialModifiedFlagsEntity that = (PartialModifiedFlagsEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/entities/WithModifiedFlagReferencingEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/entities/WithModifiedFlagReferencingEntity.java index fcb799c54f..a0c8ca7ef7 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/entities/WithModifiedFlagReferencingEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/modifiedflags/entities/WithModifiedFlagReferencingEntity.java @@ -37,73 +37,81 @@ import org.hibernate.envers.Audited; @Table(name = "WithModFlagRefIng") @Audited(withModifiedFlag = true) public class WithModifiedFlagReferencingEntity { - @Id - private Integer id; + @Id + private Integer id; - private String data; - - @OneToOne - private PartialModifiedFlagsEntity reference; + private String data; @OneToOne - private PartialModifiedFlagsEntity secondReference; + private PartialModifiedFlagsEntity reference; - public WithModifiedFlagReferencingEntity() { - } + @OneToOne + private PartialModifiedFlagsEntity secondReference; - public WithModifiedFlagReferencingEntity(Integer id, String data) { - this.id = id; - this.data = data; - } + public WithModifiedFlagReferencingEntity() { + } - public Integer getId() { - return id; - } + public WithModifiedFlagReferencingEntity(Integer id, String data) { + this.id = id; + this.data = data; + } - public void setId(Integer id) { - this.id = id; - } + public Integer getId() { + return id; + } - public String getData() { - return data; - } + public void setId(Integer id) { + this.id = id; + } - public void setData(String data) { - this.data = data; - } + public String getData() { + return data; + } - public PartialModifiedFlagsEntity getReference() { - return reference; - } + public void setData(String data) { + this.data = data; + } - public void setReference(PartialModifiedFlagsEntity reference) { - this.reference = reference; - } + public PartialModifiedFlagsEntity getReference() { + return reference; + } + + public void setReference(PartialModifiedFlagsEntity reference) { + this.reference = reference; + } public PartialModifiedFlagsEntity getSecondReference() { - return secondReference; - } + return secondReference; + } - public void setSecondReference(PartialModifiedFlagsEntity reference) { - this.secondReference = reference; - } + public void setSecondReference(PartialModifiedFlagsEntity reference) { + this.secondReference = reference; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof WithModifiedFlagReferencingEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof WithModifiedFlagReferencingEntity) ) { + return false; + } - WithModifiedFlagReferencingEntity that = (WithModifiedFlagReferencingEntity) o; + WithModifiedFlagReferencingEntity that = (WithModifiedFlagReferencingEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/multiplerelations/Address.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/multiplerelations/Address.java index 4517995d41..cc75fa807b 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/multiplerelations/Address.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/multiplerelations/Address.java @@ -1,8 +1,5 @@ package org.hibernate.envers.test.integration.multiplerelations; -import java.io.Serializable; -import java.util.HashSet; -import java.util.Set; import javax.persistence.CascadeType; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -10,6 +7,9 @@ import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToMany; import javax.persistence.ManyToOne; +import java.io.Serializable; +import java.util.HashSet; +import java.util.Set; import org.hibernate.envers.Audited; @@ -19,85 +19,93 @@ import org.hibernate.envers.Audited; @Entity @Audited public class Address implements Serializable { - @Id - @GeneratedValue - private long id; + @Id + @GeneratedValue + private long id; - private String city; + private String city; - @ManyToMany(cascade = {CascadeType.PERSIST}) - private Set tenants = new HashSet(); + @ManyToMany(cascade = {CascadeType.PERSIST}) + private Set tenants = new HashSet(); - @ManyToOne - @JoinColumn(nullable = false) - Person landlord; + @ManyToOne + @JoinColumn(nullable = false) + Person landlord; - public Address() { - } + public Address() { + } - public Address(String city) { - this.city = city; - } + public Address(String city) { + this.city = city; + } - public Address(String city, long id) { - this.id = id; - this.city = city; - } + public Address(String city, long id) { + this.id = id; + this.city = city; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof Address)) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof Address) ) { + return false; + } - Address address = (Address) o; + Address address = (Address) o; - if (id != address.id) return false; - if (city != null ? !city.equals(address.city) : address.city != null) return false; + if ( id != address.id ) { + return false; + } + if ( city != null ? !city.equals( address.city ) : address.city != null ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - int result = (int) (id ^ (id >>> 32)); - result = 31 * result + (city != null ? city.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = (int) (id ^ (id >>> 32)); + result = 31 * result + (city != null ? city.hashCode() : 0); + return result; + } - @Override - public String toString() { - return "Address(id = " + id + ", city = " + city + ")"; - } + @Override + public String toString() { + return "Address(id = " + id + ", city = " + city + ")"; + } - public long getId() { - return id; - } + public long getId() { + return id; + } - public void setId(long id) { - this.id = id; - } + public void setId(long id) { + this.id = id; + } - public String getCity() { - return city; - } + public String getCity() { + return city; + } - public void setCity(String city) { - this.city = city; - } + public void setCity(String city) { + this.city = city; + } - public Set getTenants() { - return tenants; - } + public Set getTenants() { + return tenants; + } - public void setTenants(Set tenants) { - this.tenants = tenants; - } + public void setTenants(Set tenants) { + this.tenants = tenants; + } - public Person getLandlord() { - return landlord; - } + public Person getLandlord() { + return landlord; + } - public void setLandlord(Person landlord) { - this.landlord = landlord; - } + public void setLandlord(Person landlord) { + this.landlord = landlord; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/multiplerelations/MultipleAssociationsTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/multiplerelations/MultipleAssociationsTest.java index 7a9dad0ff2..52dcb42f5a 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/multiplerelations/MultipleAssociationsTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/multiplerelations/MultipleAssociationsTest.java @@ -1,14 +1,15 @@ package org.hibernate.envers.test.integration.multiplerelations; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Assert; -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.tools.TestTools; + +import org.junit.Assert; +import org.junit.Test; + import org.hibernate.testing.TestForIssue; /** @@ -16,175 +17,178 @@ import org.hibernate.testing.TestForIssue; */ @TestForIssue(jiraKey = "HHH-7073") public class MultipleAssociationsTest extends BaseEnversJPAFunctionalTestCase { - private long lukaszId = 0; - private long kingaId = 0; - private long warsawId = 0; - private long cracowId = 0; + private long lukaszId = 0; + private long kingaId = 0; + private long warsawId = 0; + private long cracowId = 0; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { Person.class, Address.class }; - } + return new Class[] {Person.class, Address.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - // Revision 1 - em.getTransaction().begin(); - Person lukasz = new Person("Lukasz"); - Person kinga = new Person("Kinga"); - Address warsaw = new Address("Warsaw"); - warsaw.getTenants().add(lukasz); - warsaw.setLandlord(lukasz); - warsaw.getTenants().add(kinga); - lukasz.getAddresses().add(warsaw); - lukasz.getOwnedAddresses().add(warsaw); - kinga.getAddresses().add(warsaw); - em.persist(lukasz); - em.persist(kinga); - em.persist(warsaw); - em.getTransaction().commit(); + // Revision 1 + em.getTransaction().begin(); + Person lukasz = new Person( "Lukasz" ); + Person kinga = new Person( "Kinga" ); + Address warsaw = new Address( "Warsaw" ); + warsaw.getTenants().add( lukasz ); + warsaw.setLandlord( lukasz ); + warsaw.getTenants().add( kinga ); + lukasz.getAddresses().add( warsaw ); + lukasz.getOwnedAddresses().add( warsaw ); + kinga.getAddresses().add( warsaw ); + em.persist( lukasz ); + em.persist( kinga ); + em.persist( warsaw ); + em.getTransaction().commit(); - lukaszId = lukasz.getId(); - kingaId = kinga.getId(); - warsawId = warsaw.getId(); + lukaszId = lukasz.getId(); + kingaId = kinga.getId(); + warsawId = warsaw.getId(); - // Revision 2 - em.getTransaction().begin(); - kinga = em.find(Person.class, kinga.getId()); - Address cracow = new Address("Cracow"); - kinga.getAddresses().add(cracow); - cracow.getTenants().add(kinga); - cracow.setLandlord(kinga); - em.persist(cracow); - em.getTransaction().commit(); + // Revision 2 + em.getTransaction().begin(); + kinga = em.find( Person.class, kinga.getId() ); + Address cracow = new Address( "Cracow" ); + kinga.getAddresses().add( cracow ); + cracow.getTenants().add( kinga ); + cracow.setLandlord( kinga ); + em.persist( cracow ); + em.getTransaction().commit(); - cracowId = cracow.getId(); + cracowId = cracow.getId(); - // Revision 3 - em.getTransaction().begin(); - cracow = em.find(Address.class, cracow.getId()); - cracow.setCity("Krakow"); - em.merge(cracow); - em.getTransaction().commit(); + // Revision 3 + em.getTransaction().begin(); + cracow = em.find( Address.class, cracow.getId() ); + cracow.setCity( "Krakow" ); + em.merge( cracow ); + em.getTransaction().commit(); - // Revision 4 - em.getTransaction().begin(); - lukasz = em.find(Person.class, lukasz.getId()); - lukasz.setName("Lucas"); - em.merge(lukasz); - em.getTransaction().commit(); + // Revision 4 + em.getTransaction().begin(); + lukasz = em.find( Person.class, lukasz.getId() ); + lukasz.setName( "Lucas" ); + em.merge( lukasz ); + em.getTransaction().commit(); - // Revision 5 - em.getTransaction().begin(); - warsaw = em.find(Address.class, warsaw.getId()); - lukasz = em.find(Person.class, lukasz.getId()); - kinga = em.find(Person.class, kinga.getId()); - warsaw.setLandlord(kinga); - kinga.getOwnedAddresses().add(warsaw); - lukasz.getOwnedAddresses().remove(warsaw); - em.merge(warsaw); - em.merge(lukasz); - em.merge(kinga); - em.getTransaction().commit(); - } + // Revision 5 + em.getTransaction().begin(); + warsaw = em.find( Address.class, warsaw.getId() ); + lukasz = em.find( Person.class, lukasz.getId() ); + kinga = em.find( Person.class, kinga.getId() ); + warsaw.setLandlord( kinga ); + kinga.getOwnedAddresses().add( warsaw ); + lukasz.getOwnedAddresses().remove( warsaw ); + em.merge( warsaw ); + em.merge( lukasz ); + em.merge( kinga ); + em.getTransaction().commit(); + } - @Test - public void testRevisionsCounts() { - Assert.assertEquals(Arrays.asList(1, 4, 5), getAuditReader().getRevisions(Person.class, lukaszId)); - Assert.assertEquals(Arrays.asList(1, 2, 5), getAuditReader().getRevisions(Person.class, kingaId)); - Assert.assertEquals(Arrays.asList(1, 5), getAuditReader().getRevisions(Address.class, warsawId)); - Assert.assertEquals(Arrays.asList(2, 3), getAuditReader().getRevisions(Address.class, cracowId)); - } + @Test + public void testRevisionsCounts() { + Assert.assertEquals( Arrays.asList( 1, 4, 5 ), getAuditReader().getRevisions( Person.class, lukaszId ) ); + Assert.assertEquals( Arrays.asList( 1, 2, 5 ), getAuditReader().getRevisions( Person.class, kingaId ) ); + Assert.assertEquals( Arrays.asList( 1, 5 ), getAuditReader().getRevisions( Address.class, warsawId ) ); + Assert.assertEquals( Arrays.asList( 2, 3 ), getAuditReader().getRevisions( Address.class, cracowId ) ); + } - @Test - public void testHistoryOfLukasz() { - Person lukasz = new Person("Lukasz", lukaszId); - Address warsaw = new Address("Warsaw", warsawId); - lukasz.getAddresses().add(warsaw); - lukasz.getOwnedAddresses().add(warsaw); + @Test + public void testHistoryOfLukasz() { + Person lukasz = new Person( "Lukasz", lukaszId ); + Address warsaw = new Address( "Warsaw", warsawId ); + lukasz.getAddresses().add( warsaw ); + lukasz.getOwnedAddresses().add( warsaw ); - Person ver1 = getAuditReader().find(Person.class, lukaszId, 1); - Assert.assertEquals(lukasz, ver1); - Assert.assertEquals(lukasz.getAddresses(), ver1.getAddresses()); - Assert.assertEquals(lukasz.getOwnedAddresses(), ver1.getOwnedAddresses()); + Person ver1 = getAuditReader().find( Person.class, lukaszId, 1 ); + Assert.assertEquals( lukasz, ver1 ); + Assert.assertEquals( lukasz.getAddresses(), ver1.getAddresses() ); + Assert.assertEquals( lukasz.getOwnedAddresses(), ver1.getOwnedAddresses() ); - lukasz.setName("Lucas"); + lukasz.setName( "Lucas" ); - Person ver4 = getAuditReader().find(Person.class, lukaszId, 4); - Assert.assertEquals(lukasz, ver4); + Person ver4 = getAuditReader().find( Person.class, lukaszId, 4 ); + Assert.assertEquals( lukasz, ver4 ); - lukasz.getOwnedAddresses().remove(warsaw); + lukasz.getOwnedAddresses().remove( warsaw ); - Person ver5 = getAuditReader().find(Person.class, lukaszId, 5); - Assert.assertEquals(lukasz.getOwnedAddresses(), ver5.getOwnedAddresses()); - } + Person ver5 = getAuditReader().find( Person.class, lukaszId, 5 ); + Assert.assertEquals( lukasz.getOwnedAddresses(), ver5.getOwnedAddresses() ); + } - @Test - public void testHistoryOfKinga() { - Person kinga = new Person("Kinga", kingaId); - Address warsaw = new Address("Warsaw", warsawId); - kinga.getAddresses().add(warsaw); + @Test + public void testHistoryOfKinga() { + Person kinga = new Person( "Kinga", kingaId ); + Address warsaw = new Address( "Warsaw", warsawId ); + kinga.getAddresses().add( warsaw ); - Person ver1 = getAuditReader().find(Person.class, kingaId, 1); - Assert.assertEquals(kinga, ver1); - Assert.assertEquals(kinga.getAddresses(), ver1.getAddresses()); - Assert.assertEquals(kinga.getOwnedAddresses(), ver1.getOwnedAddresses()); + Person ver1 = getAuditReader().find( Person.class, kingaId, 1 ); + Assert.assertEquals( kinga, ver1 ); + Assert.assertEquals( kinga.getAddresses(), ver1.getAddresses() ); + Assert.assertEquals( kinga.getOwnedAddresses(), ver1.getOwnedAddresses() ); - Address cracow = new Address("Cracow", cracowId); - kinga.getOwnedAddresses().add(cracow); - kinga.getAddresses().add(cracow); + Address cracow = new Address( "Cracow", cracowId ); + kinga.getOwnedAddresses().add( cracow ); + kinga.getAddresses().add( cracow ); - Person ver2 = getAuditReader().find(Person.class, kingaId, 2); - Assert.assertEquals(kinga, ver2); - Assert.assertEquals(kinga.getAddresses(), ver2.getAddresses()); - Assert.assertEquals(kinga.getOwnedAddresses(), ver2.getOwnedAddresses()); + Person ver2 = getAuditReader().find( Person.class, kingaId, 2 ); + Assert.assertEquals( kinga, ver2 ); + Assert.assertEquals( kinga.getAddresses(), ver2.getAddresses() ); + Assert.assertEquals( kinga.getOwnedAddresses(), ver2.getOwnedAddresses() ); - kinga.getOwnedAddresses().add(warsaw); - cracow.setCity("Krakow"); + kinga.getOwnedAddresses().add( warsaw ); + cracow.setCity( "Krakow" ); - Person ver5 = getAuditReader().find(Person.class, kingaId, 5); - Assert.assertEquals(TestTools.makeSet(kinga.getAddresses()), TestTools.makeSet(ver5.getAddresses())); - Assert.assertEquals(TestTools.makeSet(kinga.getOwnedAddresses()), TestTools.makeSet(ver5.getOwnedAddresses())); - } + Person ver5 = getAuditReader().find( Person.class, kingaId, 5 ); + Assert.assertEquals( TestTools.makeSet( kinga.getAddresses() ), TestTools.makeSet( ver5.getAddresses() ) ); + Assert.assertEquals( + TestTools.makeSet( kinga.getOwnedAddresses() ), + TestTools.makeSet( ver5.getOwnedAddresses() ) + ); + } - @Test - public void testHistoryOfCracow() { - Address cracow = new Address("Cracow", cracowId); - Person kinga = new Person("Kinga", kingaId); - cracow.getTenants().add(kinga); - cracow.setLandlord(kinga); + @Test + public void testHistoryOfCracow() { + Address cracow = new Address( "Cracow", cracowId ); + Person kinga = new Person( "Kinga", kingaId ); + cracow.getTenants().add( kinga ); + cracow.setLandlord( kinga ); - Address ver2 = getAuditReader().find(Address.class, cracowId, 2); - Assert.assertEquals(cracow, ver2); - Assert.assertEquals(cracow.getTenants(), ver2.getTenants()); - Assert.assertEquals(cracow.getLandlord().getId(), ver2.getLandlord().getId()); + Address ver2 = getAuditReader().find( Address.class, cracowId, 2 ); + Assert.assertEquals( cracow, ver2 ); + Assert.assertEquals( cracow.getTenants(), ver2.getTenants() ); + Assert.assertEquals( cracow.getLandlord().getId(), ver2.getLandlord().getId() ); - cracow.setCity("Krakow"); + cracow.setCity( "Krakow" ); - Address ver3 = getAuditReader().find(Address.class, cracowId, 3); - Assert.assertEquals(cracow, ver3); - } + Address ver3 = getAuditReader().find( Address.class, cracowId, 3 ); + Assert.assertEquals( cracow, ver3 ); + } - @Test - public void testHistoryOfWarsaw() { - Address warsaw = new Address("Warsaw", warsawId); - Person kinga = new Person("Kinga", kingaId); - Person lukasz = new Person("Lukasz", lukaszId); - warsaw.getTenants().add(lukasz); - warsaw.getTenants().add(kinga); - warsaw.setLandlord(lukasz); + @Test + public void testHistoryOfWarsaw() { + Address warsaw = new Address( "Warsaw", warsawId ); + Person kinga = new Person( "Kinga", kingaId ); + Person lukasz = new Person( "Lukasz", lukaszId ); + warsaw.getTenants().add( lukasz ); + warsaw.getTenants().add( kinga ); + warsaw.setLandlord( lukasz ); - Address ver1 = getAuditReader().find(Address.class, warsawId, 1); - Assert.assertEquals(warsaw, ver1); - Assert.assertEquals(warsaw.getTenants(), ver1.getTenants()); - Assert.assertEquals(warsaw.getLandlord().getId(), ver1.getLandlord().getId()); + Address ver1 = getAuditReader().find( Address.class, warsawId, 1 ); + Assert.assertEquals( warsaw, ver1 ); + Assert.assertEquals( warsaw.getTenants(), ver1.getTenants() ); + Assert.assertEquals( warsaw.getLandlord().getId(), ver1.getLandlord().getId() ); - warsaw.setLandlord(kinga); + warsaw.setLandlord( kinga ); - Address ver5 = getAuditReader().find(Address.class, warsawId, 5); - Assert.assertEquals(warsaw.getLandlord().getId(), ver5.getLandlord().getId()); - } + Address ver5 = getAuditReader().find( Address.class, warsawId, 5 ); + Assert.assertEquals( warsaw.getLandlord().getId(), ver5.getLandlord().getId() ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/multiplerelations/Person.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/multiplerelations/Person.java index 4a44c5a452..3084762c5a 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/multiplerelations/Person.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/multiplerelations/Person.java @@ -1,8 +1,5 @@ package org.hibernate.envers.test.integration.multiplerelations; -import java.io.Serializable; -import java.util.HashSet; -import java.util.Set; import javax.persistence.CascadeType; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -11,6 +8,9 @@ import javax.persistence.JoinColumn; import javax.persistence.JoinTable; import javax.persistence.ManyToMany; import javax.persistence.OneToMany; +import java.io.Serializable; +import java.util.HashSet; +import java.util.Set; import org.hibernate.envers.Audited; @@ -20,87 +20,95 @@ import org.hibernate.envers.Audited; @Entity @Audited public class Person implements Serializable { - @Id - @GeneratedValue - private long id; + @Id + @GeneratedValue + private long id; - private String name; + private String name; - @ManyToMany(cascade = {CascadeType.PERSIST}) - @JoinTable(name = "PERSON_ADDRESS", - joinColumns = {@JoinColumn(name = "personId", nullable = false)}, - inverseJoinColumns = {@JoinColumn(name = "addressId", nullable = false)}) - private Set
addresses = new HashSet
(); + @ManyToMany(cascade = {CascadeType.PERSIST}) + @JoinTable(name = "PERSON_ADDRESS", + joinColumns = {@JoinColumn(name = "personId", nullable = false)}, + inverseJoinColumns = {@JoinColumn(name = "addressId", nullable = false)}) + private Set
addresses = new HashSet
(); - @OneToMany(mappedBy = "landlord", cascade = {CascadeType.PERSIST}, orphanRemoval = true) - private Set
ownedAddresses = new HashSet
(); + @OneToMany(mappedBy = "landlord", cascade = {CascadeType.PERSIST}, orphanRemoval = true) + private Set
ownedAddresses = new HashSet
(); - public Person() { - } + public Person() { + } - public Person(String name) { - this.name = name; - } + public Person(String name) { + this.name = name; + } - public Person(String name, long id) { - this.id = id; - this.name = name; - } + public Person(String name, long id) { + this.id = id; + this.name = name; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof Person)) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof Person) ) { + return false; + } - Person person = (Person) o; + Person person = (Person) o; - if (id != person.id) return false; - if (name != null ? !name.equals(person.name) : person.name != null) return false; + if ( id != person.id ) { + return false; + } + if ( name != null ? !name.equals( person.name ) : person.name != null ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - int result = (int) (id ^ (id >>> 32)); - result = 31 * result + (name != null ? name.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = (int) (id ^ (id >>> 32)); + result = 31 * result + (name != null ? name.hashCode() : 0); + return result; + } - @Override - public String toString() { - return "Person(id = " + id + ", name = " + name + ")"; - } + @Override + public String toString() { + return "Person(id = " + id + ", name = " + name + ")"; + } - public long getId() { - return id; - } + public long getId() { + return id; + } - public void setId(long id) { - this.id = id; - } + public void setId(long id) { + this.id = id; + } - public String getName() { - return name; - } + public String getName() { + return name; + } - public void setName(String name) { - this.name = name; - } + public void setName(String name) { + this.name = name; + } - public Set
getAddresses() { - return addresses; - } + public Set
getAddresses() { + return addresses; + } - public void setAddresses(Set
addresses) { - this.addresses = addresses; - } + public void setAddresses(Set
addresses) { + this.addresses = addresses; + } - public Set
getOwnedAddresses() { - return ownedAddresses; - } + public Set
getOwnedAddresses() { + return ownedAddresses; + } - public void setOwnedAddresses(Set
ownedAddresses) { - this.ownedAddresses = ownedAddresses; - } + public void setOwnedAddresses(Set
ownedAddresses) { + this.ownedAddresses = ownedAddresses; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/BasicNaming.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/BasicNaming.java index ec1e229d0d..99711705d3 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/BasicNaming.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/BasicNaming.java @@ -23,94 +23,95 @@ */ package org.hibernate.envers.test.integration.naming; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class BasicNaming extends BaseEnversJPAFunctionalTestCase { - private Integer id1; - private Integer id2; + private Integer id1; + private Integer id2; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { NamingTestEntity1.class }; - } + return new Class[] {NamingTestEntity1.class}; + } - @Test - @Priority(10) - public void initData() { - NamingTestEntity1 nte1 = new NamingTestEntity1("data1"); - NamingTestEntity1 nte2 = new NamingTestEntity1("data2"); + @Test + @Priority(10) + public void initData() { + NamingTestEntity1 nte1 = new NamingTestEntity1( "data1" ); + NamingTestEntity1 nte2 = new NamingTestEntity1( "data2" ); - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); - em.persist(nte1); - em.persist(nte2); + em.persist( nte1 ); + em.persist( nte2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); + // Revision 2 + em.getTransaction().begin(); - nte1 = em.find(NamingTestEntity1.class, nte1.getId()); - nte1.setData("data1'"); + nte1 = em.find( NamingTestEntity1.class, nte1.getId() ); + nte1.setData( "data1'" ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 - em.getTransaction().begin(); + // Revision 3 + em.getTransaction().begin(); - nte2 = em.find(NamingTestEntity1.class, nte2.getId()); - nte2.setData("data2'"); + nte2 = em.find( NamingTestEntity1.class, nte2.getId() ); + nte2.setData( "data2'" ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // + // - id1 = nte1.getId(); - id2 = nte2.getId(); - } + id1 = nte1.getId(); + id2 = nte2.getId(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(NamingTestEntity1.class, id1)); + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( NamingTestEntity1.class, id1 ) ); - assert Arrays.asList(1, 3).equals(getAuditReader().getRevisions(NamingTestEntity1.class, id2)); - } + assert Arrays.asList( 1, 3 ).equals( getAuditReader().getRevisions( NamingTestEntity1.class, id2 ) ); + } - @Test - public void testHistoryOfId1() { - NamingTestEntity1 ver1 = new NamingTestEntity1(id1, "data1"); - NamingTestEntity1 ver2 = new NamingTestEntity1(id1, "data1'"); + @Test + public void testHistoryOfId1() { + NamingTestEntity1 ver1 = new NamingTestEntity1( id1, "data1" ); + NamingTestEntity1 ver2 = new NamingTestEntity1( id1, "data1'" ); - assert getAuditReader().find(NamingTestEntity1.class, id1, 1).equals(ver1); - assert getAuditReader().find(NamingTestEntity1.class, id1, 2).equals(ver2); - assert getAuditReader().find(NamingTestEntity1.class, id1, 3).equals(ver2); - } + assert getAuditReader().find( NamingTestEntity1.class, id1, 1 ).equals( ver1 ); + assert getAuditReader().find( NamingTestEntity1.class, id1, 2 ).equals( ver2 ); + assert getAuditReader().find( NamingTestEntity1.class, id1, 3 ).equals( ver2 ); + } - @Test - public void testHistoryOfId2() { - NamingTestEntity1 ver1 = new NamingTestEntity1(id2, "data2"); - NamingTestEntity1 ver2 = new NamingTestEntity1(id2, "data2'"); + @Test + public void testHistoryOfId2() { + NamingTestEntity1 ver1 = new NamingTestEntity1( id2, "data2" ); + NamingTestEntity1 ver2 = new NamingTestEntity1( id2, "data2'" ); - assert getAuditReader().find(NamingTestEntity1.class, id2, 1).equals(ver1); - assert getAuditReader().find(NamingTestEntity1.class, id2, 2).equals(ver1); - assert getAuditReader().find(NamingTestEntity1.class, id2, 3).equals(ver2); - } + assert getAuditReader().find( NamingTestEntity1.class, id2, 1 ).equals( ver1 ); + assert getAuditReader().find( NamingTestEntity1.class, id2, 2 ).equals( ver1 ); + assert getAuditReader().find( NamingTestEntity1.class, id2, 3 ).equals( ver2 ); + } - @Test - public void testTableName() { - assert "naming_test_entity_1_versions".equals( - getCfg().getClassMapping("org.hibernate.envers.test.integration.naming.NamingTestEntity1_AUD") - .getTable().getName()); - } + @Test + public void testTableName() { + assert "naming_test_entity_1_versions".equals( + getCfg().getClassMapping( "org.hibernate.envers.test.integration.naming.NamingTestEntity1_AUD" ) + .getTable().getName() + ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/DetachedNamingTestEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/DetachedNamingTestEntity.java index eafec7f691..8c7dbf3a3d 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/DetachedNamingTestEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/DetachedNamingTestEntity.java @@ -22,12 +22,13 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.naming; -import java.util.Set; + import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; import javax.persistence.OneToMany; +import java.util.Set; import org.hibernate.envers.Audited; import org.hibernate.envers.test.entities.StrTestEntity; @@ -37,75 +38,83 @@ import org.hibernate.envers.test.entities.StrTestEntity; */ @Entity public class DetachedNamingTestEntity { - @Id - private Integer id; + @Id + private Integer id; - @Audited - private String data; + @Audited + private String data; - @Audited - @OneToMany - @JoinTable(name = "UNI_NAMING_TEST", - joinColumns = @JoinColumn(name = "ID_1"), - inverseJoinColumns = @JoinColumn(name = "ID_2")) - private Set collection; + @Audited + @OneToMany + @JoinTable(name = "UNI_NAMING_TEST", + joinColumns = @JoinColumn(name = "ID_1"), + inverseJoinColumns = @JoinColumn(name = "ID_2")) + private Set collection; - public DetachedNamingTestEntity() { - } + public DetachedNamingTestEntity() { + } - public DetachedNamingTestEntity(Integer id, String data) { - this.id = id; - this.data = data; - } + public DetachedNamingTestEntity(Integer id, String data) { + this.id = id; + this.data = data; + } - public DetachedNamingTestEntity(String data) { - this.data = data; - } + public DetachedNamingTestEntity(String data) { + this.data = data; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public Set getCollection() { - return collection; - } + public Set getCollection() { + return collection; + } - public void setCollection(Set collection) { - this.collection = collection; - } + public void setCollection(Set collection) { + this.collection = collection; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof DetachedNamingTestEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof DetachedNamingTestEntity) ) { + return false; + } - DetachedNamingTestEntity that = (DetachedNamingTestEntity) o; + DetachedNamingTestEntity that = (DetachedNamingTestEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "DetachedNamingTestEntity(id = " + id + ", data = " + data + ")"; - } + public String toString() { + return "DetachedNamingTestEntity(id = " + id + ", data = " + data + ")"; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/EstonianTableAlias.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/EstonianTableAlias.java index 4ca09d9a1d..14aa4ebaf7 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/EstonianTableAlias.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/EstonianTableAlias.java @@ -4,12 +4,14 @@ import javax.persistence.EntityManager; import ee.estonia.entities.Child; import ee.estonia.entities.Parent; -import org.junit.Assert; -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.tools.TestTools; + +import org.junit.Assert; +import org.junit.Test; + import org.hibernate.testing.TestForIssue; /** @@ -17,40 +19,40 @@ import org.hibernate.testing.TestForIssue; */ @TestForIssue(jiraKey = "HHH-6738") public class EstonianTableAlias extends BaseEnversJPAFunctionalTestCase { - private Long parentId = null; - private Long childId = null; + private Long parentId = null; + private Long childId = null; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { Parent.class, Child.class }; - } + return new Class[] {Parent.class, Child.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - // Revision 1 - em.getTransaction().begin(); - Parent parent = new Parent("parent"); - Child child = new Child("child"); - parent.getCollection().add(child); - em.persist(child); - em.persist(parent); - em.getTransaction().commit(); + // Revision 1 + em.getTransaction().begin(); + Parent parent = new Parent( "parent" ); + Child child = new Child( "child" ); + parent.getCollection().add( child ); + em.persist( child ); + em.persist( parent ); + em.getTransaction().commit(); - parentId = parent.getId(); - childId = child.getId(); - } + parentId = parent.getId(); + childId = child.getId(); + } - @Test - public void testAuditChildTableAlias() { - Parent parent = new Parent("parent", parentId); - Child child = new Child("child", childId); + @Test + public void testAuditChildTableAlias() { + Parent parent = new Parent( "parent", parentId ); + Child child = new Child( "child", childId ); - Parent ver1 = getAuditReader().find(Parent.class, parentId, 1); + Parent ver1 = getAuditReader().find( Parent.class, parentId, 1 ); - Assert.assertEquals(parent, ver1); - Assert.assertEquals(TestTools.makeSet(child), ver1.getCollection()); - } + Assert.assertEquals( parent, ver1 ); + Assert.assertEquals( TestTools.makeSet( child ), ver1.getCollection() ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/JoinNaming.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/JoinNaming.java index fcc6b7ddd1..166635d22c 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/JoinNaming.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/JoinNaming.java @@ -23,16 +23,16 @@ */ package org.hibernate.envers.test.integration.naming; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.Iterator; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.mapping.Column; +import org.junit.Test; + import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertTrue; @@ -41,96 +41,98 @@ import static junit.framework.Assert.assertTrue; * @author Adam Warski (adam at warski dot org) */ public class JoinNaming extends BaseEnversJPAFunctionalTestCase { - private Integer ed_id1; - private Integer ed_id2; - private Integer ing_id1; + private Integer ed_id1; + private Integer ed_id2; + private Integer ing_id1; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { JoinNamingRefEdEntity.class, JoinNamingRefIngEntity.class }; - } + return new Class[] {JoinNamingRefEdEntity.class, JoinNamingRefIngEntity.class}; + } - @Test - @Priority(10) - public void initData() { - JoinNamingRefEdEntity ed1 = new JoinNamingRefEdEntity("data1"); - JoinNamingRefEdEntity ed2 = new JoinNamingRefEdEntity("data2"); + @Test + @Priority(10) + public void initData() { + JoinNamingRefEdEntity ed1 = new JoinNamingRefEdEntity( "data1" ); + JoinNamingRefEdEntity ed2 = new JoinNamingRefEdEntity( "data2" ); - JoinNamingRefIngEntity ing1 = new JoinNamingRefIngEntity("x", ed1); + JoinNamingRefIngEntity ing1 = new JoinNamingRefIngEntity( "x", ed1 ); - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); - em.persist(ed1); - em.persist(ed2); - em.persist(ing1); + em.persist( ed1 ); + em.persist( ed2 ); + em.persist( ing1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); + // Revision 2 + em.getTransaction().begin(); - ed2 = em.find(JoinNamingRefEdEntity.class, ed2.getId()); + ed2 = em.find( JoinNamingRefEdEntity.class, ed2.getId() ); - ing1 = em.find(JoinNamingRefIngEntity.class, ing1.getId()); - ing1.setData("y"); - ing1.setReference(ed2); + ing1 = em.find( JoinNamingRefIngEntity.class, ing1.getId() ); + ing1.setData( "y" ); + ing1.setReference( ed2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // + // - ed_id1 = ed1.getId(); - ed_id2 = ed2.getId(); - ing_id1 = ing1.getId(); - } + ed_id1 = ed1.getId(); + ed_id2 = ed2.getId(); + ing_id1 = ing1.getId(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(JoinNamingRefEdEntity.class, ed_id1)); - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(JoinNamingRefEdEntity.class, ed_id2)); - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(JoinNamingRefIngEntity.class, ing_id1)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( JoinNamingRefEdEntity.class, ed_id1 ) ); + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( JoinNamingRefEdEntity.class, ed_id2 ) ); + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( JoinNamingRefIngEntity.class, ing_id1 ) ); + } - @Test - public void testHistoryOfEdId1() { - JoinNamingRefEdEntity ver1 = new JoinNamingRefEdEntity(ed_id1, "data1"); + @Test + public void testHistoryOfEdId1() { + JoinNamingRefEdEntity ver1 = new JoinNamingRefEdEntity( ed_id1, "data1" ); - assert getAuditReader().find(JoinNamingRefEdEntity.class, ed_id1, 1).equals(ver1); - assert getAuditReader().find(JoinNamingRefEdEntity.class, ed_id1, 2).equals(ver1); - } + assert getAuditReader().find( JoinNamingRefEdEntity.class, ed_id1, 1 ).equals( ver1 ); + assert getAuditReader().find( JoinNamingRefEdEntity.class, ed_id1, 2 ).equals( ver1 ); + } - @Test - public void testHistoryOfEdId2() { - JoinNamingRefEdEntity ver1 = new JoinNamingRefEdEntity(ed_id2, "data2"); + @Test + public void testHistoryOfEdId2() { + JoinNamingRefEdEntity ver1 = new JoinNamingRefEdEntity( ed_id2, "data2" ); - assert getAuditReader().find(JoinNamingRefEdEntity.class, ed_id2, 1).equals(ver1); - assert getAuditReader().find(JoinNamingRefEdEntity.class, ed_id2, 2).equals(ver1); - } + assert getAuditReader().find( JoinNamingRefEdEntity.class, ed_id2, 1 ).equals( ver1 ); + assert getAuditReader().find( JoinNamingRefEdEntity.class, ed_id2, 2 ).equals( ver1 ); + } - @Test - public void testHistoryOfIngId1() { - JoinNamingRefIngEntity ver1 = new JoinNamingRefIngEntity(ing_id1, "x", null); - JoinNamingRefIngEntity ver2 = new JoinNamingRefIngEntity(ing_id1, "y", null); + @Test + public void testHistoryOfIngId1() { + JoinNamingRefIngEntity ver1 = new JoinNamingRefIngEntity( ing_id1, "x", null ); + JoinNamingRefIngEntity ver2 = new JoinNamingRefIngEntity( ing_id1, "y", null ); - assert getAuditReader().find(JoinNamingRefIngEntity.class, ing_id1, 1).equals(ver1); - assert getAuditReader().find(JoinNamingRefIngEntity.class, ing_id1, 2).equals(ver2); + assert getAuditReader().find( JoinNamingRefIngEntity.class, ing_id1, 1 ).equals( ver1 ); + assert getAuditReader().find( JoinNamingRefIngEntity.class, ing_id1, 2 ).equals( ver2 ); - assert getAuditReader().find(JoinNamingRefIngEntity.class, ing_id1, 1).getReference().equals( - new JoinNamingRefEdEntity(ed_id1, "data1")); - assert getAuditReader().find(JoinNamingRefIngEntity.class, ing_id1, 2).getReference().equals( - new JoinNamingRefEdEntity(ed_id2, "data2")); - } + assert getAuditReader().find( JoinNamingRefIngEntity.class, ing_id1, 1 ).getReference().equals( + new JoinNamingRefEdEntity( ed_id1, "data1" ) + ); + assert getAuditReader().find( JoinNamingRefIngEntity.class, ing_id1, 2 ).getReference().equals( + new JoinNamingRefEdEntity( ed_id2, "data2" ) + ); + } - @SuppressWarnings({"unchecked"}) - @Test - public void testJoinColumnName() { + @SuppressWarnings({"unchecked"}) + @Test + public void testJoinColumnName() { Iterator columns = - getCfg().getClassMapping("org.hibernate.envers.test.integration.naming.JoinNamingRefIngEntity_AUD") - .getProperty("reference_id").getColumnIterator(); - assertTrue(columns.hasNext()); - assertEquals("jnree_column_reference", columns.next().getName()); - assertFalse(columns.hasNext()); + getCfg().getClassMapping( "org.hibernate.envers.test.integration.naming.JoinNamingRefIngEntity_AUD" ) + .getProperty( "reference_id" ).getColumnIterator(); + assertTrue( columns.hasNext() ); + assertEquals( "jnree_column_reference", columns.next().getName() ); + assertFalse( columns.hasNext() ); } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/JoinNamingRefEdEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/JoinNamingRefEdEntity.java index 78da95d41e..0ef8f74a1d 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/JoinNamingRefEdEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/JoinNamingRefEdEntity.java @@ -22,89 +22,99 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.naming; -import java.util.List; + import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.OneToMany; +import java.util.List; import org.hibernate.envers.Audited; /** * ReferencEd entity + * * @author Adam Warski (adam at warski dot org) */ @Entity public class JoinNamingRefEdEntity { - @Id - @GeneratedValue - @Column(name = "jnree_id") - private Integer id; + @Id + @GeneratedValue + @Column(name = "jnree_id") + private Integer id; - @Audited - private String data; + @Audited + private String data; - @Audited - @OneToMany(mappedBy="reference") - private List reffering; + @Audited + @OneToMany(mappedBy = "reference") + private List reffering; - public JoinNamingRefEdEntity() { - } + public JoinNamingRefEdEntity() { + } - public JoinNamingRefEdEntity(Integer id, String data) { - this.id = id; - this.data = data; - } + public JoinNamingRefEdEntity(Integer id, String data) { + this.id = id; + this.data = data; + } - public JoinNamingRefEdEntity(String data) { - this.data = data; - } + public JoinNamingRefEdEntity(String data) { + this.data = data; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public List getReffering() { - return reffering; - } + public List getReffering() { + return reffering; + } - public void setReffering(List reffering) { - this.reffering = reffering; - } + public void setReffering(List reffering) { + this.reffering = reffering; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof JoinNamingRefEdEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof JoinNamingRefEdEntity) ) { + return false; + } - JoinNamingRefEdEntity that = (JoinNamingRefEdEntity) o; + JoinNamingRefEdEntity that = (JoinNamingRefEdEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "JoinNamingRefEdEntity(id = " + id + ", data = " + data + ")"; - } + public String toString() { + return "JoinNamingRefEdEntity(id = " + id + ", data = " + data + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/JoinNamingRefIngEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/JoinNamingRefIngEntity.java index 269894d40e..680e3b756e 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/JoinNamingRefIngEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/JoinNamingRefIngEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.naming; + import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -33,80 +34,90 @@ import org.hibernate.envers.Audited; /** * ReferencIng entity + * * @author Adam Warski (adam at warski dot org) */ @Entity public class JoinNamingRefIngEntity { - @Id - @GeneratedValue - @Column(name = "jnrie_id") - private Integer id; + @Id + @GeneratedValue + @Column(name = "jnrie_id") + private Integer id; - @Audited - private String data; + @Audited + private String data; - @Audited - @ManyToOne - @JoinColumn(name = "jnree_column_reference") - private JoinNamingRefEdEntity reference; + @Audited + @ManyToOne + @JoinColumn(name = "jnree_column_reference") + private JoinNamingRefEdEntity reference; - public JoinNamingRefIngEntity() { } + public JoinNamingRefIngEntity() { + } - public JoinNamingRefIngEntity(Integer id, String data, JoinNamingRefEdEntity reference) { - this.id = id; - this.data = data; - this.reference = reference; - } + public JoinNamingRefIngEntity(Integer id, String data, JoinNamingRefEdEntity reference) { + this.id = id; + this.data = data; + this.reference = reference; + } - public JoinNamingRefIngEntity(String data, JoinNamingRefEdEntity reference) { - this.data = data; - this.reference = reference; - } + public JoinNamingRefIngEntity(String data, JoinNamingRefEdEntity reference) { + this.data = data; + this.reference = reference; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public JoinNamingRefEdEntity getReference() { - return reference; - } + public JoinNamingRefEdEntity getReference() { + return reference; + } - public void setReference(JoinNamingRefEdEntity reference) { - this.reference = reference; - } + public void setReference(JoinNamingRefEdEntity reference) { + this.reference = reference; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof JoinNamingRefIngEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof JoinNamingRefIngEntity) ) { + return false; + } - JoinNamingRefIngEntity that = (JoinNamingRefIngEntity) o; + JoinNamingRefIngEntity that = (JoinNamingRefIngEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "JoinNamingRefIngEntity(id = " + id + ", data = " + data + ")"; - } + public String toString() { + return "JoinNamingRefIngEntity(id = " + id + ", data = " + data + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/NamingTestEntity1.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/NamingTestEntity1.java index a5d3b7df74..0be00ef816 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/NamingTestEntity1.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/NamingTestEntity1.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.naming; + import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -35,62 +36,70 @@ import org.hibernate.envers.Audited; * @author Adam Warski (adam at warski dot org) */ @Entity -@Table(name="naming_test_entity_1") +@Table(name = "naming_test_entity_1") @AuditTable("naming_test_entity_1_versions") public class NamingTestEntity1 { - @Id - @GeneratedValue - @Column(name = "nte_id") - private Integer id; + @Id + @GeneratedValue + @Column(name = "nte_id") + private Integer id; - @Column(name = "nte_data") - @Audited - private String data; + @Column(name = "nte_data") + @Audited + private String data; - public NamingTestEntity1() { - } + public NamingTestEntity1() { + } - public NamingTestEntity1(String data) { - this.data = data; - } + public NamingTestEntity1(String data) { + this.data = data; + } - public NamingTestEntity1(Integer id, String data) { - this.id = id; - this.data = data; - } + public NamingTestEntity1(Integer id, String data) { + this.id = id; + this.data = data; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof NamingTestEntity1)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof NamingTestEntity1) ) { + return false; + } - NamingTestEntity1 that = (NamingTestEntity1) o; + NamingTestEntity1 that = (NamingTestEntity1) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/OneToManyUnidirectionalNaming.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/OneToManyUnidirectionalNaming.java index cada8de416..cb52a4abbf 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/OneToManyUnidirectionalNaming.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/OneToManyUnidirectionalNaming.java @@ -23,12 +23,10 @@ */ package org.hibernate.envers.test.integration.naming; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.HashSet; import java.util.Iterator; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; @@ -36,96 +34,100 @@ import org.hibernate.envers.test.entities.StrTestEntity; import org.hibernate.envers.test.tools.TestTools; import org.hibernate.mapping.Column; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class OneToManyUnidirectionalNaming extends BaseEnversJPAFunctionalTestCase { - private Integer uni1_id; - private Integer str1_id; + private Integer uni1_id; + private Integer str1_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { DetachedNamingTestEntity.class, StrTestEntity.class }; - } + return new Class[] {DetachedNamingTestEntity.class, StrTestEntity.class}; + } - @Test - @Priority(10) - public void initData() { - DetachedNamingTestEntity uni1 = new DetachedNamingTestEntity(1, "data1"); - StrTestEntity str1 = new StrTestEntity("str1"); + @Test + @Priority(10) + public void initData() { + DetachedNamingTestEntity uni1 = new DetachedNamingTestEntity( 1, "data1" ); + StrTestEntity str1 = new StrTestEntity( "str1" ); - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); - uni1.setCollection(new HashSet()); - em.persist(uni1); - em.persist(str1); + uni1.setCollection( new HashSet() ); + em.persist( uni1 ); + em.persist( str1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); + // Revision 2 + em.getTransaction().begin(); - uni1 = em.find(DetachedNamingTestEntity.class, uni1.getId()); - str1 = em.find(StrTestEntity.class, str1.getId()); - uni1.getCollection().add(str1); + uni1 = em.find( DetachedNamingTestEntity.class, uni1.getId() ); + str1 = em.find( StrTestEntity.class, str1.getId() ); + uni1.getCollection().add( str1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // + // - uni1_id = uni1.getId(); - str1_id = str1.getId(); - } + uni1_id = uni1.getId(); + str1_id = str1.getId(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(DetachedNamingTestEntity.class, uni1_id)); - assert Arrays.asList(1).equals(getAuditReader().getRevisions(StrTestEntity.class, str1_id)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( DetachedNamingTestEntity.class, uni1_id ) ); + assert Arrays.asList( 1 ).equals( getAuditReader().getRevisions( StrTestEntity.class, str1_id ) ); + } - @Test - public void testHistoryOfUniId1() { - StrTestEntity str1 = getEntityManager().find(StrTestEntity.class, str1_id); + @Test + public void testHistoryOfUniId1() { + StrTestEntity str1 = getEntityManager().find( StrTestEntity.class, str1_id ); - DetachedNamingTestEntity rev1 = getAuditReader().find(DetachedNamingTestEntity.class, uni1_id, 1); - DetachedNamingTestEntity rev2 = getAuditReader().find(DetachedNamingTestEntity.class, uni1_id, 2); + DetachedNamingTestEntity rev1 = getAuditReader().find( DetachedNamingTestEntity.class, uni1_id, 1 ); + DetachedNamingTestEntity rev2 = getAuditReader().find( DetachedNamingTestEntity.class, uni1_id, 2 ); - assert rev1.getCollection().equals(TestTools.makeSet()); - assert rev2.getCollection().equals(TestTools.makeSet(str1)); + assert rev1.getCollection().equals( TestTools.makeSet() ); + assert rev2.getCollection().equals( TestTools.makeSet( str1 ) ); - assert "data1".equals(rev1.getData()); - assert "data1".equals(rev2.getData()); - } + assert "data1".equals( rev1.getData() ); + assert "data1".equals( rev2.getData() ); + } - private final static String MIDDLE_VERSIONS_ENTITY_NAME = "UNI_NAMING_TEST_AUD"; - @Test - public void testTableName() { - assert MIDDLE_VERSIONS_ENTITY_NAME.equals( - getCfg().getClassMapping(MIDDLE_VERSIONS_ENTITY_NAME).getTable().getName()); - } + private final static String MIDDLE_VERSIONS_ENTITY_NAME = "UNI_NAMING_TEST_AUD"; - @SuppressWarnings({"unchecked"}) - @Test - public void testJoinColumnName() { - Iterator columns = - getCfg().getClassMapping(MIDDLE_VERSIONS_ENTITY_NAME).getTable().getColumnIterator(); + @Test + public void testTableName() { + assert MIDDLE_VERSIONS_ENTITY_NAME.equals( + getCfg().getClassMapping( MIDDLE_VERSIONS_ENTITY_NAME ).getTable().getName() + ); + } - boolean id1Found = false; - boolean id2Found = false; + @SuppressWarnings({"unchecked"}) + @Test + public void testJoinColumnName() { + Iterator columns = + getCfg().getClassMapping( MIDDLE_VERSIONS_ENTITY_NAME ).getTable().getColumnIterator(); - while (columns.hasNext()) { - Column column = columns.next(); - if ("ID_1".equals(column.getName())) { - id1Found = true; - } + boolean id1Found = false; + boolean id2Found = false; - if ("ID_2".equals(column.getName())) { - id2Found = true; - } - } + while ( columns.hasNext() ) { + Column column = columns.next(); + if ( "ID_1".equals( column.getName() ) ) { + id1Found = true; + } - assert id1Found && id2Found; - } + if ( "ID_2".equals( column.getName() ) ) { + id2Found = true; + } + } + + assert id1Found && id2Found; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/VersionsJoinTableNaming.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/VersionsJoinTableNaming.java index 26b2eef8ce..70d410d043 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/VersionsJoinTableNaming.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/VersionsJoinTableNaming.java @@ -23,12 +23,10 @@ */ package org.hibernate.envers.test.integration.naming; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.HashSet; import java.util.Iterator; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; @@ -36,97 +34,105 @@ import org.hibernate.envers.test.entities.StrTestEntity; import org.hibernate.envers.test.tools.TestTools; import org.hibernate.mapping.Column; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class VersionsJoinTableNaming extends BaseEnversJPAFunctionalTestCase { - private Integer uni1_id; - private Integer str1_id; + private Integer uni1_id; + private Integer str1_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { VersionsJoinTableTestEntity.class, StrTestEntity.class }; - } + return new Class[] {VersionsJoinTableTestEntity.class, StrTestEntity.class}; + } - @Test - @Priority(10) - public void initData() { - VersionsJoinTableTestEntity uni1 = new VersionsJoinTableTestEntity(1, "data1"); - StrTestEntity str1 = new StrTestEntity("str1"); + @Test + @Priority(10) + public void initData() { + VersionsJoinTableTestEntity uni1 = new VersionsJoinTableTestEntity( 1, "data1" ); + StrTestEntity str1 = new StrTestEntity( "str1" ); - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); - uni1.setCollection(new HashSet()); - em.persist(uni1); - em.persist(str1); + uni1.setCollection( new HashSet() ); + em.persist( uni1 ); + em.persist( str1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); + // Revision 2 + em.getTransaction().begin(); - uni1 = em.find(VersionsJoinTableTestEntity.class, uni1.getId()); - str1 = em.find(StrTestEntity.class, str1.getId()); - uni1.getCollection().add(str1); + uni1 = em.find( VersionsJoinTableTestEntity.class, uni1.getId() ); + str1 = em.find( StrTestEntity.class, str1.getId() ); + uni1.getCollection().add( str1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // + // - uni1_id = uni1.getId(); - str1_id = str1.getId(); - } + uni1_id = uni1.getId(); + str1_id = str1.getId(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(VersionsJoinTableTestEntity.class, uni1_id)); - assert Arrays.asList(1).equals(getAuditReader().getRevisions(StrTestEntity.class, str1_id)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( + getAuditReader().getRevisions( + VersionsJoinTableTestEntity.class, + uni1_id + ) + ); + assert Arrays.asList( 1 ).equals( getAuditReader().getRevisions( StrTestEntity.class, str1_id ) ); + } - @Test - public void testHistoryOfUniId1() { - StrTestEntity str1 = getEntityManager().find(StrTestEntity.class, str1_id); + @Test + public void testHistoryOfUniId1() { + StrTestEntity str1 = getEntityManager().find( StrTestEntity.class, str1_id ); - VersionsJoinTableTestEntity rev1 = getAuditReader().find(VersionsJoinTableTestEntity.class, uni1_id, 1); - VersionsJoinTableTestEntity rev2 = getAuditReader().find(VersionsJoinTableTestEntity.class, uni1_id, 2); + VersionsJoinTableTestEntity rev1 = getAuditReader().find( VersionsJoinTableTestEntity.class, uni1_id, 1 ); + VersionsJoinTableTestEntity rev2 = getAuditReader().find( VersionsJoinTableTestEntity.class, uni1_id, 2 ); - assert rev1.getCollection().equals(TestTools.makeSet()); - assert rev2.getCollection().equals(TestTools.makeSet(str1)); + assert rev1.getCollection().equals( TestTools.makeSet() ); + assert rev2.getCollection().equals( TestTools.makeSet( str1 ) ); - assert "data1".equals(rev1.getData()); - assert "data1".equals(rev2.getData()); - } + assert "data1".equals( rev1.getData() ); + assert "data1".equals( rev2.getData() ); + } - private final static String MIDDLE_VERSIONS_ENTITY_NAME = "VERSIONS_JOIN_TABLE_TEST"; - - @Test - public void testTableName() { - assert MIDDLE_VERSIONS_ENTITY_NAME.equals( - getCfg().getClassMapping(MIDDLE_VERSIONS_ENTITY_NAME).getTable().getName()); - } + private final static String MIDDLE_VERSIONS_ENTITY_NAME = "VERSIONS_JOIN_TABLE_TEST"; - @SuppressWarnings({"unchecked"}) - @Test - public void testJoinColumnName() { - Iterator columns = - getCfg().getClassMapping(MIDDLE_VERSIONS_ENTITY_NAME).getTable().getColumnIterator(); + @Test + public void testTableName() { + assert MIDDLE_VERSIONS_ENTITY_NAME.equals( + getCfg().getClassMapping( MIDDLE_VERSIONS_ENTITY_NAME ).getTable().getName() + ); + } - boolean id1Found = false; - boolean id2Found = false; + @SuppressWarnings({"unchecked"}) + @Test + public void testJoinColumnName() { + Iterator columns = + getCfg().getClassMapping( MIDDLE_VERSIONS_ENTITY_NAME ).getTable().getColumnIterator(); - while (columns.hasNext()) { - Column column = columns.next(); - if ("VJT_ID".equals(column.getName())) { - id1Found = true; - } + boolean id1Found = false; + boolean id2Found = false; - if ("STR_ID".equals(column.getName())) { - id2Found = true; - } - } + while ( columns.hasNext() ) { + Column column = columns.next(); + if ( "VJT_ID".equals( column.getName() ) ) { + id1Found = true; + } - assert id1Found && id2Found; - } + if ( "STR_ID".equals( column.getName() ) ) { + id2Found = true; + } + } + + assert id1Found && id2Found; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/VersionsJoinTableRangeComponent.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/VersionsJoinTableRangeComponent.java index f7b16ce402..a1d0641ab9 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/VersionsJoinTableRangeComponent.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/VersionsJoinTableRangeComponent.java @@ -1,32 +1,35 @@ package org.hibernate.envers.test.integration.naming; -import java.util.ArrayList; -import java.util.List; + import javax.persistence.CascadeType; import javax.persistence.Embeddable; import javax.persistence.FetchType; import javax.persistence.JoinColumn; import javax.persistence.OneToMany; +import java.util.ArrayList; +import java.util.List; import org.hibernate.annotations.FetchMode; /** * An embeddable component containing a list of * {@link VersionsJoinTableRangeTestEntitySuperClass}-instances - * - * @author Erik-Berndt Scheper + * * @param + * + * @author Erik-Berndt Scheper */ @Embeddable public final class VersionsJoinTableRangeComponent { @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL) - @org.hibernate.annotations.Fetch(value = FetchMode.SUBSELECT) + @org.hibernate.annotations.Fetch(value = FetchMode.SUBSELECT) @org.hibernate.annotations.Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN) @JoinColumn(name = "VJTRCTE_ID", insertable = true, updatable = false, nullable = false) // Note: If this is processed without override annotation, then we should get a // org.hibernate.DuplicateMappingException: // Duplicate class/entity mapping JOIN_TABLE_COMPONENT_1_AUD - @org.hibernate.envers.AuditJoinTable(name = "JOIN_TABLE_COMPONENT_1_AUD", inverseJoinColumns = @JoinColumn(name = "VJTRTE_ID")) + @org.hibernate.envers.AuditJoinTable(name = "JOIN_TABLE_COMPONENT_1_AUD", + inverseJoinColumns = @JoinColumn(name = "VJTRTE_ID")) private List range = new ArrayList(); // ********************** Accessor Methods ********************** // @@ -47,18 +50,24 @@ public final class VersionsJoinTableRangeComponent other = (VersionsJoinTableRangeComponent) obj; - if (range == null) { - if (other.range != null) + if ( range == null ) { + if ( other.range != null ) { return false; - } else if (!range.equals(other.range)) + } + } + else if ( !range.equals( other.range ) ) { return false; + } return true; } @@ -66,12 +75,12 @@ public final class VersionsJoinTableRangeComponent ent1List = vjrcte .getComponent1().getRange(); assert ent1List.size() == 1; - assert vjtrte.equals(ent1List.get(0)); + assert vjtrte.equals( ent1List.get( 0 ) ); List ent2List = vjrcte .getComponent2().getRange(); assert ent2List.size() == 1; - assert vjtrtae1.equals(ent2List.get(0)); + assert vjtrtae1.equals( ent2List.get( 0 ) ); em.getTransaction().commit(); @@ -136,39 +142,50 @@ public class VersionsJoinTableRangeComponentNamingTest extends @Test public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals( + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( VersionsJoinTableRangeComponentTestEntity.class, - vjrcte_id)); - assert Arrays.asList(2).equals( + vjrcte_id + ) + ); + assert Arrays.asList( 2 ).equals( getAuditReader().getRevisions( - VersionsJoinTableRangeTestEntity.class, vjtrte_id)); - assert Arrays.asList(2).equals( + VersionsJoinTableRangeTestEntity.class, vjtrte_id + ) + ); + assert Arrays.asList( 2 ).equals( getAuditReader().getRevisions( VersionsJoinTableRangeTestAlternateEntity.class, - vjtrtae_id1)); + vjtrtae_id1 + ) + ); } @Test public void testHistoryOfUniId1() { VersionsJoinTableRangeTestEntity vjtrte = getEntityManager().find( - VersionsJoinTableRangeTestEntity.class, vjtrte_id); + VersionsJoinTableRangeTestEntity.class, vjtrte_id + ); VersionsJoinTableRangeTestAlternateEntity vjtrtae = getEntityManager() - .find(VersionsJoinTableRangeTestAlternateEntity.class, - vjtrtae_id1); + .find( + VersionsJoinTableRangeTestAlternateEntity.class, + vjtrtae_id1 + ); VersionsJoinTableRangeComponentTestEntity rev1 = getAuditReader().find( - VersionsJoinTableRangeComponentTestEntity.class, vjrcte_id, 1); + VersionsJoinTableRangeComponentTestEntity.class, vjrcte_id, 1 + ); VersionsJoinTableRangeComponentTestEntity rev2 = getAuditReader().find( - VersionsJoinTableRangeComponentTestEntity.class, vjrcte_id, 2); + VersionsJoinTableRangeComponentTestEntity.class, vjrcte_id, 2 + ); assert rev1.getComponent1().getRange().size() == 0; assert rev1.getComponent2().getRange().size() == 0; assert rev2.getComponent1().getRange().size() == 1; - assert rev2.getComponent1().getRange().get(0).equals(vjtrte); + assert rev2.getComponent1().getRange().get( 0 ).equals( vjtrte ); assert rev2.getComponent2().getRange().size() == 1; - assert rev2.getComponent2().getRange().get(0).equals(vjtrtae); + assert rev2.getComponent2().getRange().get( 0 ).equals( vjtrtae ); } /* The Audit join tables we expect */ @@ -182,54 +199,63 @@ public class VersionsJoinTableRangeComponentNamingTest extends @Test public void testExpectedTableNameComponent1() { PersistentClass auditClass = getCfg().getClassMapping( - COMPONENT_1_AUDIT_JOIN_TABLE_NAME); + COMPONENT_1_AUDIT_JOIN_TABLE_NAME + ); assert auditClass != null; - assert COMPONENT_1_AUDIT_JOIN_TABLE_NAME.equals(auditClass.getTable() - .getName()); + assert COMPONENT_1_AUDIT_JOIN_TABLE_NAME.equals( + auditClass.getTable() + .getName() + ); } @Test public void testExpectedTableNameComponent2() { PersistentClass auditClass = getCfg().getClassMapping( - COMPONENT_2_AUDIT_JOIN_TABLE_NAME); + COMPONENT_2_AUDIT_JOIN_TABLE_NAME + ); assert auditClass != null; - assert COMPONENT_2_AUDIT_JOIN_TABLE_NAME.equals(auditClass.getTable() - .getName()); + assert COMPONENT_2_AUDIT_JOIN_TABLE_NAME.equals( + auditClass.getTable() + .getName() + ); } @Test public void testWrongTableNameComponent1() { PersistentClass auditClass = getCfg().getClassMapping( - UNMODIFIED_COMPONENT_1_AUDIT_JOIN_TABLE_NAME); + UNMODIFIED_COMPONENT_1_AUDIT_JOIN_TABLE_NAME + ); assert auditClass == null; } @Test public void testWrongTableNameComponent2() { PersistentClass auditClass = getCfg().getClassMapping( - UNMODIFIED_COMPONENT_2_AUDIT_JOIN_TABLE_NAME); + UNMODIFIED_COMPONENT_2_AUDIT_JOIN_TABLE_NAME + ); assert auditClass == null; } @Test public void testJoinColumnNamesComponent1() { PersistentClass auditClass = getCfg().getClassMapping( - COMPONENT_1_AUDIT_JOIN_TABLE_NAME); + COMPONENT_1_AUDIT_JOIN_TABLE_NAME + ); assert auditClass != null; - @SuppressWarnings( { "unchecked" }) + @SuppressWarnings({"unchecked"}) Iterator columns = auditClass.getTable().getColumnIterator(); boolean id1Found = false; boolean id2Found = false; - while (columns.hasNext()) { + while ( columns.hasNext() ) { Column column = columns.next(); - if ("VJTRCTE1_ID".equals(column.getName())) { + if ( "VJTRCTE1_ID".equals( column.getName() ) ) { id1Found = true; } - if ("VJTRTE_ID".equals(column.getName())) { + if ( "VJTRTE_ID".equals( column.getName() ) ) { id2Found = true; } } @@ -240,22 +266,23 @@ public class VersionsJoinTableRangeComponentNamingTest extends @Test public void testJoinColumnNamesComponent2() { PersistentClass auditClass = getCfg().getClassMapping( - COMPONENT_2_AUDIT_JOIN_TABLE_NAME); + COMPONENT_2_AUDIT_JOIN_TABLE_NAME + ); assert auditClass != null; - @SuppressWarnings( { "unchecked" }) + @SuppressWarnings({"unchecked"}) Iterator columns = auditClass.getTable().getColumnIterator(); boolean id1Found = false; boolean id2Found = false; - while (columns.hasNext()) { + while ( columns.hasNext() ) { Column column = columns.next(); - if ("VJTRCTE2_ID".equals(column.getName())) { + if ( "VJTRCTE2_ID".equals( column.getName() ) ) { id1Found = true; } - if ("VJTRTAE_ID".equals(column.getName())) { + if ( "VJTRTAE_ID".equals( column.getName() ) ) { id2Found = true; } } @@ -272,22 +299,23 @@ public class VersionsJoinTableRangeComponentNamingTest extends public void testOverrideNotAudited() { PersistentClass auditClass = getCfg().getClassMapping( VersionsJoinTableRangeComponentTestEntity.class.getName() - + "_AUD"); + + "_AUD" + ); assert auditClass != null; - @SuppressWarnings( { "unchecked" }) + @SuppressWarnings({"unchecked"}) Iterator columns = auditClass.getTable().getColumnIterator(); boolean auditColumn1Found = false; boolean auditColumn2Found = false; - while (columns.hasNext()) { + while ( columns.hasNext() ) { Column column = columns.next(); - if ("STR1".equals(column.getName())) { + if ( "STR1".equals( column.getName() ) ) { auditColumn1Found = true; } - if ("STR2".equals(column.getName())) { + if ( "STR2".equals( column.getName() ) ) { auditColumn2Found = true; } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/VersionsJoinTableRangeComponentTestEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/VersionsJoinTableRangeComponentTestEntity.java index a78ee7ba8e..40c7025a11 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/VersionsJoinTableRangeComponentTestEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/VersionsJoinTableRangeComponentTestEntity.java @@ -1,4 +1,5 @@ package org.hibernate.envers.test.integration.naming; + import javax.persistence.AssociationOverride; import javax.persistence.AttributeOverride; import javax.persistence.AttributeOverrides; @@ -17,7 +18,7 @@ import org.hibernate.envers.test.entities.components.Component1; /** * Test entity, containing two embedded components, which each contain a list of * {@link VersionsJoinTableRangeTestEntitySuperClass}-instances - * + * * @author Erik-Berndt Scheper */ @Entity @@ -33,9 +34,17 @@ public class VersionsJoinTableRangeComponentTestEntity { * {@link VersionsJoinTableRangeTestEntity}-instances. */ @Embedded - @AssociationOverride(name = "range", joinColumns = { @JoinColumn(name = "VJTRCTE1_ID", insertable = true, updatable = false, nullable = false) }) + @AssociationOverride(name = "range", + joinColumns = { + @JoinColumn(name = "VJTRCTE1_ID", + insertable = true, + updatable = false, + nullable = false) + }) @org.hibernate.envers.Audited - @AuditOverride(name = "range", auditJoinTable = @org.hibernate.envers.AuditJoinTable(name = "JOIN_TABLE_COMPONENT_1_AUD", inverseJoinColumns = @JoinColumn(name = "VJTRTE_ID"))) + @AuditOverride(name = "range", + auditJoinTable = @org.hibernate.envers.AuditJoinTable(name = "JOIN_TABLE_COMPONENT_1_AUD", + inverseJoinColumns = @JoinColumn(name = "VJTRTE_ID"))) private VersionsJoinTableRangeComponent component1 = new VersionsJoinTableRangeComponent(); /** @@ -43,20 +52,33 @@ public class VersionsJoinTableRangeComponentTestEntity { * {@link VersionsJoinTableRangeTestAlternateEntity}-instances. */ @Embedded - @AssociationOverride(name = "range", joinColumns = { @JoinColumn(name = "VJTRCTE2_ID", insertable = true, updatable = false, nullable = false) }) + @AssociationOverride(name = "range", + joinColumns = { + @JoinColumn(name = "VJTRCTE2_ID", + insertable = true, + updatable = false, + nullable = false) + }) @org.hibernate.envers.Audited - @AuditOverrides(value = { @AuditOverride(name = "range", auditJoinTable = @org.hibernate.envers.AuditJoinTable(name = "JOIN_TABLE_COMPONENT_2_AUD", inverseJoinColumns = @JoinColumn(name = "VJTRTAE_ID"))) }) + @AuditOverrides(value = { + @AuditOverride(name = "range", + auditJoinTable = @org.hibernate.envers.AuditJoinTable(name = "JOIN_TABLE_COMPONENT_2_AUD", + inverseJoinColumns = @JoinColumn(name = "VJTRTAE_ID"))) + }) private VersionsJoinTableRangeComponent component2 = new VersionsJoinTableRangeComponent(); /** * An embedded component, containing a list of NOT AUDITED * {@link VersionsJoinTableRangeTestAlternateEntity}-instances. */ - @Embedded - @AttributeOverrides(value={@AttributeOverride(name="str1", column=@Column(name="STR1")), @AttributeOverride(name="str2", column=@Column(name="STR2"))}) + @Embedded + @AttributeOverrides(value = { + @AttributeOverride(name = "str1", column = @Column(name = "STR1")), + @AttributeOverride(name = "str2", column = @Column(name = "STR2")) + }) @org.hibernate.envers.Audited - @AuditOverrides(value={@AuditOverride(name="str2", isAudited = false)}) - private Component1 component3; + @AuditOverrides(value = {@AuditOverride(name = "str2", isAudited = false)}) + private Component1 component3; /** * Default constructor @@ -73,8 +95,7 @@ public class VersionsJoinTableRangeComponentTestEntity { } /** - * @param id - * the id to set + * @param id the id to set */ protected void setId(Integer id) { this.id = id; @@ -88,8 +109,7 @@ public class VersionsJoinTableRangeComponentTestEntity { } /** - * @param component1 - * the component1 to set + * @param component1 the component1 to set */ public void setComponent1( VersionsJoinTableRangeComponent component1) { @@ -104,8 +124,7 @@ public class VersionsJoinTableRangeComponentTestEntity { } /** - * @param component2 - * the component2 to set + * @param component2 the component2 to set */ public void setComponent2( VersionsJoinTableRangeComponent component2) { @@ -120,8 +139,7 @@ public class VersionsJoinTableRangeComponentTestEntity { } /** - * @param component3 - * the component3 to set + * @param component3 the component3 to set */ public void setComponent3(Component1 component3) { this.component3 = component3; @@ -143,33 +161,48 @@ public class VersionsJoinTableRangeComponentTestEntity { @Override public boolean equals(Object obj) { - if (this == obj) + if ( this == obj ) { return true; - if (obj == null) + } + if ( obj == null ) { return false; - if (getClass() != obj.getClass()) + } + if ( getClass() != obj.getClass() ) { return false; + } VersionsJoinTableRangeComponentTestEntity other = (VersionsJoinTableRangeComponentTestEntity) obj; - if (component1 == null) { - if (other.component1 != null) + if ( component1 == null ) { + if ( other.component1 != null ) { return false; - } else if (!component1.equals(other.component1)) + } + } + else if ( !component1.equals( other.component1 ) ) { return false; - if (component2 == null) { - if (other.component2 != null) + } + if ( component2 == null ) { + if ( other.component2 != null ) { return false; - } else if (!component2.equals(other.component2)) + } + } + else if ( !component2.equals( other.component2 ) ) { return false; - if (component3 == null) { - if (other.component3 != null) + } + if ( component3 == null ) { + if ( other.component3 != null ) { return false; - } else if (!component3.equals(other.component3)) + } + } + else if ( !component3.equals( other.component3 ) ) { return false; - if (id == null) { - if (other.id != null) + } + if ( id == null ) { + if ( other.id != null ) { return false; - } else if (!id.equals(other.id)) + } + } + else if ( !id.equals( other.id ) ) { return false; + } return true; } @@ -177,12 +210,12 @@ public class VersionsJoinTableRangeComponentTestEntity { public String toString() { StringBuilder output = new StringBuilder(); - output.append("VersionsJoinTableRangeComponentTestEntity {"); - output.append(" id = \"").append(this.getId()).append("\","); - output.append(" component1 = \"").append(this.component1) - .append("\", "); - output.append(" component2 = \"").append(this.component2).append("\"}"); - output.append(" component3 = \"").append(this.component3).append("\"}"); + output.append( "VersionsJoinTableRangeComponentTestEntity {" ); + output.append( " id = \"" ).append( this.getId() ).append( "\"," ); + output.append( " component1 = \"" ).append( this.component1 ) + .append( "\", " ); + output.append( " component2 = \"" ).append( this.component2 ).append( "\"}" ); + output.append( " component3 = \"" ).append( this.component3 ).append( "\"}" ); return output.toString(); } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/VersionsJoinTableRangeTestAlternateEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/VersionsJoinTableRangeTestAlternateEntity.java index 94470bb4be..eb7f608359 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/VersionsJoinTableRangeTestAlternateEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/VersionsJoinTableRangeTestAlternateEntity.java @@ -1,10 +1,11 @@ package org.hibernate.envers.test.integration.naming; + import javax.persistence.Entity; import javax.persistence.Table; /** * Alternate implementation of mapped superclass for Audit join table test. - * + * * @author Erik-Berndt Scheper * @see VersionsJoinTableRangeTestEntity * @see VersionsJoinTableRangeTestEntitySuperClass @@ -13,7 +14,7 @@ import javax.persistence.Table; @Table(name = "RANGE_TEST_ALTERNATE_ENT") @org.hibernate.envers.Audited public class VersionsJoinTableRangeTestAlternateEntity extends - VersionsJoinTableRangeTestEntitySuperClass { + VersionsJoinTableRangeTestEntitySuperClass { private String alternateValue; @@ -32,8 +33,7 @@ public class VersionsJoinTableRangeTestAlternateEntity extends } /** - * @param alternateValue - * the alternateValue to set + * @param alternateValue the alternateValue to set */ public void setAlternateValue(String alternateValue) { this.alternateValue = alternateValue; @@ -50,18 +50,24 @@ public class VersionsJoinTableRangeTestAlternateEntity extends @Override public boolean equals(Object obj) { - if (this == obj) + if ( this == obj ) { return true; - if (!super.equals(obj)) + } + if ( !super.equals( obj ) ) { return false; - if (getClass() != obj.getClass()) + } + if ( getClass() != obj.getClass() ) { return false; + } VersionsJoinTableRangeTestAlternateEntity other = (VersionsJoinTableRangeTestAlternateEntity) obj; - if (alternateValue == null) { - if (other.alternateValue != null) + if ( alternateValue == null ) { + if ( other.alternateValue != null ) { return false; - } else if (!alternateValue.equals(other.alternateValue)) + } + } + else if ( !alternateValue.equals( other.alternateValue ) ) { return false; + } return true; } @@ -69,12 +75,13 @@ public class VersionsJoinTableRangeTestAlternateEntity extends public String toString() { StringBuilder output = new StringBuilder(); - output.append("VersionsJoinTableRangeComponentTestEntity {"); - output.append(" id = \"").append(getId()).append("\", "); - output.append(" genericValue = \"").append(getGenericValue()).append( - "\", "); - output.append(" alternateValue = \"").append(this.alternateValue) - .append("\"}"); + output.append( "VersionsJoinTableRangeComponentTestEntity {" ); + output.append( " id = \"" ).append( getId() ).append( "\", " ); + output.append( " genericValue = \"" ).append( getGenericValue() ).append( + "\", " + ); + output.append( " alternateValue = \"" ).append( this.alternateValue ) + .append( "\"}" ); return output.toString(); } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/VersionsJoinTableRangeTestEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/VersionsJoinTableRangeTestEntity.java index a0c9ccfa4c..ec943a7aaf 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/VersionsJoinTableRangeTestEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/VersionsJoinTableRangeTestEntity.java @@ -1,10 +1,11 @@ package org.hibernate.envers.test.integration.naming; + import javax.persistence.Entity; import javax.persistence.Table; /** * Concrete implementation of mapped superclass for Audit join table test. - * + * * @author Erik-Berndt Scheper * @see VersionsJoinTableRangeTestAlternateEntity * @see VersionsJoinTableRangeTestEntitySuperClass @@ -13,7 +14,7 @@ import javax.persistence.Table; @Table(name = "RANGE_TEST_ENTITY") @org.hibernate.envers.Audited public class VersionsJoinTableRangeTestEntity extends - VersionsJoinTableRangeTestEntitySuperClass { + VersionsJoinTableRangeTestEntitySuperClass { private String value; @@ -32,8 +33,7 @@ public class VersionsJoinTableRangeTestEntity extends } /** - * @param value - * the value to set + * @param value the value to set */ public void setValue(String value) { this.value = value; @@ -49,18 +49,24 @@ public class VersionsJoinTableRangeTestEntity extends @Override public boolean equals(Object obj) { - if (this == obj) + if ( this == obj ) { return true; - if (!super.equals(obj)) + } + if ( !super.equals( obj ) ) { return false; - if (getClass() != obj.getClass()) + } + if ( getClass() != obj.getClass() ) { return false; + } VersionsJoinTableRangeTestEntity other = (VersionsJoinTableRangeTestEntity) obj; - if (value == null) { - if (other.value != null) + if ( value == null ) { + if ( other.value != null ) { return false; - } else if (!value.equals(other.value)) + } + } + else if ( !value.equals( other.value ) ) { return false; + } return true; } @@ -68,11 +74,12 @@ public class VersionsJoinTableRangeTestEntity extends public String toString() { StringBuilder output = new StringBuilder(); - output.append("VersionsJoinTableRangeComponentTestEntity {"); - output.append(" id = \"").append(getId()).append("\", "); - output.append(" genericValue = \"").append(getGenericValue()).append( - "\", "); - output.append(" value = \"").append(this.value).append("\"}"); + output.append( "VersionsJoinTableRangeComponentTestEntity {" ); + output.append( " id = \"" ).append( getId() ).append( "\", " ); + output.append( " genericValue = \"" ).append( getGenericValue() ).append( + "\", " + ); + output.append( " value = \"" ).append( this.value ).append( "\"}" ); return output.toString(); } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/VersionsJoinTableRangeTestEntitySuperClass.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/VersionsJoinTableRangeTestEntitySuperClass.java index a93a901185..bd770f95cf 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/VersionsJoinTableRangeTestEntitySuperClass.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/VersionsJoinTableRangeTestEntitySuperClass.java @@ -1,11 +1,12 @@ package org.hibernate.envers.test.integration.naming; + import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.MappedSuperclass; /** * Mapped superclass for Audit join table test. - * + * * @author Erik-Berndt Scheper */ @MappedSuperclass @@ -26,8 +27,7 @@ public abstract class VersionsJoinTableRangeTestEntitySuperClass { } /** - * @param id - * the id to set + * @param id the id to set */ protected void setId(Integer id) { this.id = id; @@ -41,8 +41,7 @@ public abstract class VersionsJoinTableRangeTestEntitySuperClass { } /** - * @param genericValue - * the genericValue to set + * @param genericValue the genericValue to set */ public void setGenericValue(String genericValue) { this.genericValue = genericValue; @@ -60,23 +59,32 @@ public abstract class VersionsJoinTableRangeTestEntitySuperClass { @Override public boolean equals(Object obj) { - if (this == obj) + if ( this == obj ) { return true; - if (obj == null) + } + if ( obj == null ) { return false; - if (getClass() != obj.getClass()) + } + if ( getClass() != obj.getClass() ) { return false; + } VersionsJoinTableRangeTestEntitySuperClass other = (VersionsJoinTableRangeTestEntitySuperClass) obj; - if (genericValue == null) { - if (other.genericValue != null) + if ( genericValue == null ) { + if ( other.genericValue != null ) { return false; - } else if (!genericValue.equals(other.genericValue)) + } + } + else if ( !genericValue.equals( other.genericValue ) ) { return false; - if (id == null) { - if (other.id != null) + } + if ( id == null ) { + if ( other.id != null ) { return false; - } else if (!id.equals(other.id)) + } + } + else if ( !id.equals( other.id ) ) { return false; + } return true; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/VersionsJoinTableTestEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/VersionsJoinTableTestEntity.java index a1eca35046..cbfce2348d 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/VersionsJoinTableTestEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/VersionsJoinTableTestEntity.java @@ -22,12 +22,13 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.naming; -import java.util.Set; + import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.OneToMany; import javax.persistence.Table; +import java.util.Set; import org.hibernate.envers.AuditJoinTable; import org.hibernate.envers.Audited; @@ -39,74 +40,82 @@ import org.hibernate.envers.test.entities.StrTestEntity; @Entity @Table(name = "VersionsJoinTable") public class VersionsJoinTableTestEntity { - @Id - private Integer id; + @Id + private Integer id; - @Audited - private String data; + @Audited + private String data; - @Audited - @OneToMany - @JoinColumn(name = "VJT_ID") - @AuditJoinTable(name = "VERSIONS_JOIN_TABLE_TEST", inverseJoinColumns = @JoinColumn(name = "STR_ID")) - private Set collection; + @Audited + @OneToMany + @JoinColumn(name = "VJT_ID") + @AuditJoinTable(name = "VERSIONS_JOIN_TABLE_TEST", inverseJoinColumns = @JoinColumn(name = "STR_ID")) + private Set collection; - public VersionsJoinTableTestEntity() { - } + public VersionsJoinTableTestEntity() { + } - public VersionsJoinTableTestEntity(Integer id, String data) { - this.id = id; - this.data = data; - } + public VersionsJoinTableTestEntity(Integer id, String data) { + this.id = id; + this.data = data; + } - public VersionsJoinTableTestEntity(String data) { - this.data = data; - } + public VersionsJoinTableTestEntity(String data) { + this.data = data; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public Set getCollection() { - return collection; - } + public Set getCollection() { + return collection; + } - public void setCollection(Set collection) { - this.collection = collection; - } + public void setCollection(Set collection) { + this.collection = collection; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof VersionsJoinTableTestEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof VersionsJoinTableTestEntity) ) { + return false; + } - VersionsJoinTableTestEntity that = (VersionsJoinTableTestEntity) o; + VersionsJoinTableTestEntity that = (VersionsJoinTableTestEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "VersionsJoinTableTestEntity(id = " + id + ", data = " + data + ")"; - } + public String toString() { + return "VersionsJoinTableTestEntity(id = " + id + ", data = " + data + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/ids/EmbIdNaming.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/ids/EmbIdNaming.java index bf0ea35f7b..33189ad0bb 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/ids/EmbIdNaming.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/ids/EmbIdNaming.java @@ -22,65 +22,74 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.naming.ids; -import java.io.Serializable; + import javax.persistence.Column; import javax.persistence.Embeddable; +import java.io.Serializable; /** * @author Adam Warski (adam at warski dot org) */ @Embeddable public class EmbIdNaming implements Serializable { - @Column(name = "XX") - private Integer x; + @Column(name = "XX") + private Integer x; - @Column(name = "YY") - private Integer y; + @Column(name = "YY") + private Integer y; - public EmbIdNaming() { - } + public EmbIdNaming() { + } - public EmbIdNaming(Integer x, Integer y) { - this.x = x; - this.y = y; - } + public EmbIdNaming(Integer x, Integer y) { + this.x = x; + this.y = y; + } - public Integer getX() { - return x; - } + public Integer getX() { + return x; + } - public void setX(Integer x) { - this.x = x; - } + public void setX(Integer x) { + this.x = x; + } - public Integer getY() { - return y; - } + public Integer getY() { + return y; + } - public void setY(Integer y) { - this.y = y; - } + public void setY(Integer y) { + this.y = y; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof EmbIdNaming)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof EmbIdNaming) ) { + return false; + } - EmbIdNaming embId = (EmbIdNaming) o; + EmbIdNaming embId = (EmbIdNaming) o; - if (x != null ? !x.equals(embId.x) : embId.x != null) return false; - if (y != null ? !y.equals(embId.y) : embId.y != null) return false; + if ( x != null ? !x.equals( embId.x ) : embId.x != null ) { + return false; + } + if ( y != null ? !y.equals( embId.y ) : embId.y != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (x != null ? x.hashCode() : 0); - result = 31 * result + (y != null ? y.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (x != null ? x.hashCode() : 0); + result = 31 * result + (y != null ? y.hashCode() : 0); + return result; + } - public String toString() { - return "EmbIdNaming(" + x + ", " + y + ")"; - } + public String toString() { + return "EmbIdNaming(" + x + ", " + y + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/ids/JoinEmbIdNaming.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/ids/JoinEmbIdNaming.java index 2825cbe802..cbb4ac50c8 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/ids/JoinEmbIdNaming.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/ids/JoinEmbIdNaming.java @@ -23,16 +23,16 @@ */ package org.hibernate.envers.test.integration.naming.ids; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.Iterator; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.mapping.Column; +import org.junit.Test; + import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertTrue; @@ -41,101 +41,122 @@ import static junit.framework.Assert.assertTrue; * @author Adam Warski (adam at warski dot org) */ public class JoinEmbIdNaming extends BaseEnversJPAFunctionalTestCase { - private EmbIdNaming ed_id1; - private EmbIdNaming ed_id2; - private EmbIdNaming ing_id1; + private EmbIdNaming ed_id1; + private EmbIdNaming ed_id2; + private EmbIdNaming ing_id1; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { JoinEmbIdNamingRefEdEntity.class, JoinEmbIdNamingRefIngEntity.class }; - } + return new Class[] {JoinEmbIdNamingRefEdEntity.class, JoinEmbIdNamingRefIngEntity.class}; + } - @Test - @Priority(10) - public void initData() { - ed_id1 = new EmbIdNaming(10, 20); - ed_id2 = new EmbIdNaming(11, 21); - ing_id1 = new EmbIdNaming(12, 22); + @Test + @Priority(10) + public void initData() { + ed_id1 = new EmbIdNaming( 10, 20 ); + ed_id2 = new EmbIdNaming( 11, 21 ); + ing_id1 = new EmbIdNaming( 12, 22 ); - JoinEmbIdNamingRefEdEntity ed1 = new JoinEmbIdNamingRefEdEntity(ed_id1, "data1"); - JoinEmbIdNamingRefEdEntity ed2 = new JoinEmbIdNamingRefEdEntity(ed_id2, "data2"); + JoinEmbIdNamingRefEdEntity ed1 = new JoinEmbIdNamingRefEdEntity( ed_id1, "data1" ); + JoinEmbIdNamingRefEdEntity ed2 = new JoinEmbIdNamingRefEdEntity( ed_id2, "data2" ); - JoinEmbIdNamingRefIngEntity ing1 = new JoinEmbIdNamingRefIngEntity(ing_id1, "x", ed1); + JoinEmbIdNamingRefIngEntity ing1 = new JoinEmbIdNamingRefIngEntity( ing_id1, "x", ed1 ); - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); - em.persist(ed1); - em.persist(ed2); - em.persist(ing1); + em.persist( ed1 ); + em.persist( ed2 ); + em.persist( ing1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); + // Revision 2 + em.getTransaction().begin(); - ed2 = em.find(JoinEmbIdNamingRefEdEntity.class, ed2.getId()); + ed2 = em.find( JoinEmbIdNamingRefEdEntity.class, ed2.getId() ); - ing1 = em.find(JoinEmbIdNamingRefIngEntity.class, ing1.getId()); - ing1.setData("y"); - ing1.setReference(ed2); + ing1 = em.find( JoinEmbIdNamingRefIngEntity.class, ing1.getId() ); + ing1.setData( "y" ); + ing1.setReference( ed2 ); - em.getTransaction().commit(); - } + em.getTransaction().commit(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(JoinEmbIdNamingRefEdEntity.class, ed_id1)); - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(JoinEmbIdNamingRefEdEntity.class, ed_id2)); - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(JoinEmbIdNamingRefIngEntity.class, ing_id1)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( + getAuditReader().getRevisions( + JoinEmbIdNamingRefEdEntity.class, + ed_id1 + ) + ); + assert Arrays.asList( 1, 2 ).equals( + getAuditReader().getRevisions( + JoinEmbIdNamingRefEdEntity.class, + ed_id2 + ) + ); + assert Arrays.asList( 1, 2 ).equals( + getAuditReader().getRevisions( + JoinEmbIdNamingRefIngEntity.class, + ing_id1 + ) + ); + } - @Test - public void testHistoryOfEdId1() { - JoinEmbIdNamingRefEdEntity ver1 = new JoinEmbIdNamingRefEdEntity(ed_id1, "data1"); + @Test + public void testHistoryOfEdId1() { + JoinEmbIdNamingRefEdEntity ver1 = new JoinEmbIdNamingRefEdEntity( ed_id1, "data1" ); - assert getAuditReader().find(JoinEmbIdNamingRefEdEntity.class, ed_id1, 1).equals(ver1); - assert getAuditReader().find(JoinEmbIdNamingRefEdEntity.class, ed_id1, 2).equals(ver1); - } + assert getAuditReader().find( JoinEmbIdNamingRefEdEntity.class, ed_id1, 1 ).equals( ver1 ); + assert getAuditReader().find( JoinEmbIdNamingRefEdEntity.class, ed_id1, 2 ).equals( ver1 ); + } - @Test - public void testHistoryOfEdId2() { - JoinEmbIdNamingRefEdEntity ver1 = new JoinEmbIdNamingRefEdEntity(ed_id2, "data2"); + @Test + public void testHistoryOfEdId2() { + JoinEmbIdNamingRefEdEntity ver1 = new JoinEmbIdNamingRefEdEntity( ed_id2, "data2" ); - assert getAuditReader().find(JoinEmbIdNamingRefEdEntity.class, ed_id2, 1).equals(ver1); - assert getAuditReader().find(JoinEmbIdNamingRefEdEntity.class, ed_id2, 2).equals(ver1); - } + assert getAuditReader().find( JoinEmbIdNamingRefEdEntity.class, ed_id2, 1 ).equals( ver1 ); + assert getAuditReader().find( JoinEmbIdNamingRefEdEntity.class, ed_id2, 2 ).equals( ver1 ); + } - @Test - public void testHistoryOfIngId1() { - JoinEmbIdNamingRefIngEntity ver1 = new JoinEmbIdNamingRefIngEntity(ing_id1, "x", null); - JoinEmbIdNamingRefIngEntity ver2 = new JoinEmbIdNamingRefIngEntity(ing_id1, "y", null); + @Test + public void testHistoryOfIngId1() { + JoinEmbIdNamingRefIngEntity ver1 = new JoinEmbIdNamingRefIngEntity( ing_id1, "x", null ); + JoinEmbIdNamingRefIngEntity ver2 = new JoinEmbIdNamingRefIngEntity( ing_id1, "y", null ); - assert getAuditReader().find(JoinEmbIdNamingRefIngEntity.class, ing_id1, 1).equals(ver1); - assert getAuditReader().find(JoinEmbIdNamingRefIngEntity.class, ing_id1, 2).equals(ver2); + assert getAuditReader().find( JoinEmbIdNamingRefIngEntity.class, ing_id1, 1 ).equals( ver1 ); + assert getAuditReader().find( JoinEmbIdNamingRefIngEntity.class, ing_id1, 2 ).equals( ver2 ); - assert getAuditReader().find(JoinEmbIdNamingRefIngEntity.class, ing_id1, 1).getReference().equals( - new JoinEmbIdNamingRefEdEntity(ed_id1, "data1")); - assert getAuditReader().find(JoinEmbIdNamingRefIngEntity.class, ing_id1, 2).getReference().equals( - new JoinEmbIdNamingRefEdEntity(ed_id2, "data2")); - } + assert getAuditReader().find( JoinEmbIdNamingRefIngEntity.class, ing_id1, 1 ).getReference().equals( + new JoinEmbIdNamingRefEdEntity( ed_id1, "data1" ) + ); + assert getAuditReader().find( JoinEmbIdNamingRefIngEntity.class, ing_id1, 2 ).getReference().equals( + new JoinEmbIdNamingRefEdEntity( ed_id2, "data2" ) + ); + } - @SuppressWarnings({"unchecked"}) - @Test - public void testJoinColumnNames() { + @SuppressWarnings({"unchecked"}) + @Test + public void testJoinColumnNames() { Iterator columns = - getCfg().getClassMapping("org.hibernate.envers.test.integration.naming.ids.JoinEmbIdNamingRefIngEntity_AUD") - .getProperty("reference_x").getColumnIterator(); - assertTrue(columns.hasNext()); - assertEquals("XX_reference", columns.next().getName()); - assertFalse(columns.hasNext()); + getCfg().getClassMapping( + "org.hibernate.envers.test.integration.naming.ids.JoinEmbIdNamingRefIngEntity_AUD" + ) + .getProperty( "reference_x" ).getColumnIterator(); + assertTrue( columns.hasNext() ); + assertEquals( "XX_reference", columns.next().getName() ); + assertFalse( columns.hasNext() ); - columns = getCfg().getClassMapping("org.hibernate.envers.test.integration.naming.ids.JoinEmbIdNamingRefIngEntity_AUD") - .getProperty("reference_y").getColumnIterator(); + columns = getCfg().getClassMapping( + "org.hibernate.envers.test.integration.naming.ids.JoinEmbIdNamingRefIngEntity_AUD" + ) + .getProperty( "reference_y" ).getColumnIterator(); - assertTrue(columns.hasNext()); - assertEquals("YY_reference", columns.next().getName()); - assertFalse(columns.hasNext()); + assertTrue( columns.hasNext() ); + assertEquals( "YY_reference", columns.next().getName() ); + assertFalse( columns.hasNext() ); } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/ids/JoinEmbIdNamingRefEdEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/ids/JoinEmbIdNamingRefEdEntity.java index af87776956..af8bd17527 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/ids/JoinEmbIdNamingRefEdEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/ids/JoinEmbIdNamingRefEdEntity.java @@ -22,89 +22,99 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.naming.ids; -import java.util.List; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.OneToMany; import javax.persistence.Table; +import java.util.List; import org.hibernate.envers.Audited; /** * ReferencEd entity + * * @author Adam Warski (adam at warski dot org) */ @Entity @Table(name = "JoinEmbIdRefEd") public class JoinEmbIdNamingRefEdEntity { - @Id - @GeneratedValue - private EmbIdNaming id; + @Id + @GeneratedValue + private EmbIdNaming id; - @Audited - private String data; + @Audited + private String data; - @Audited - @OneToMany(mappedBy="reference") - private List reffering; + @Audited + @OneToMany(mappedBy = "reference") + private List reffering; - public JoinEmbIdNamingRefEdEntity() { - } + public JoinEmbIdNamingRefEdEntity() { + } - public JoinEmbIdNamingRefEdEntity(EmbIdNaming id, String data) { - this.id = id; - this.data = data; - } + public JoinEmbIdNamingRefEdEntity(EmbIdNaming id, String data) { + this.id = id; + this.data = data; + } - public JoinEmbIdNamingRefEdEntity(String data) { - this.data = data; - } + public JoinEmbIdNamingRefEdEntity(String data) { + this.data = data; + } - public EmbIdNaming getId() { - return id; - } + public EmbIdNaming getId() { + return id; + } - public void setId(EmbIdNaming id) { - this.id = id; - } + public void setId(EmbIdNaming id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public List getReffering() { - return reffering; - } + public List getReffering() { + return reffering; + } - public void setReffering(List reffering) { - this.reffering = reffering; - } + public void setReffering(List reffering) { + this.reffering = reffering; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof JoinEmbIdNamingRefEdEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof JoinEmbIdNamingRefEdEntity) ) { + return false; + } - JoinEmbIdNamingRefEdEntity that = (JoinEmbIdNamingRefEdEntity) o; + JoinEmbIdNamingRefEdEntity that = (JoinEmbIdNamingRefEdEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "JoinEmbIdNamingRefEdEntity(id = " + id + ", data = " + data + ")"; - } + public String toString() { + return "JoinEmbIdNamingRefEdEntity(id = " + id + ", data = " + data + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/ids/JoinEmbIdNamingRefIngEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/ids/JoinEmbIdNamingRefIngEntity.java index ef563ad7b1..4ff6573840 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/ids/JoinEmbIdNamingRefIngEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/ids/JoinEmbIdNamingRefIngEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.naming.ids; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; @@ -34,81 +35,93 @@ import org.hibernate.envers.Audited; /** * ReferencIng entity + * * @author Adam Warski (adam at warski dot org) */ @Entity @Table(name = "JoinEmbIdRefIng") public class JoinEmbIdNamingRefIngEntity { - @Id - @GeneratedValue - private EmbIdNaming id; + @Id + @GeneratedValue + private EmbIdNaming id; - @Audited - private String data; + @Audited + private String data; - @Audited - @ManyToOne - @JoinColumns({@JoinColumn(name = "XX_reference", referencedColumnName = "XX"), - @JoinColumn(name = "YY_reference", referencedColumnName = "YY")}) - private JoinEmbIdNamingRefEdEntity reference; + @Audited + @ManyToOne + @JoinColumns({ + @JoinColumn(name = "XX_reference", referencedColumnName = "XX"), + @JoinColumn(name = "YY_reference", referencedColumnName = "YY") + }) + private JoinEmbIdNamingRefEdEntity reference; - public JoinEmbIdNamingRefIngEntity() { } + public JoinEmbIdNamingRefIngEntity() { + } - public JoinEmbIdNamingRefIngEntity(EmbIdNaming id, String data, JoinEmbIdNamingRefEdEntity reference) { - this.id = id; - this.data = data; - this.reference = reference; - } + public JoinEmbIdNamingRefIngEntity(EmbIdNaming id, String data, JoinEmbIdNamingRefEdEntity reference) { + this.id = id; + this.data = data; + this.reference = reference; + } - public JoinEmbIdNamingRefIngEntity(String data, JoinEmbIdNamingRefEdEntity reference) { - this.data = data; - this.reference = reference; - } + public JoinEmbIdNamingRefIngEntity(String data, JoinEmbIdNamingRefEdEntity reference) { + this.data = data; + this.reference = reference; + } - public EmbIdNaming getId() { - return id; - } + public EmbIdNaming getId() { + return id; + } - public void setId(EmbIdNaming id) { - this.id = id; - } + public void setId(EmbIdNaming id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public JoinEmbIdNamingRefEdEntity getReference() { - return reference; - } + public JoinEmbIdNamingRefEdEntity getReference() { + return reference; + } - public void setReference(JoinEmbIdNamingRefEdEntity reference) { - this.reference = reference; - } + public void setReference(JoinEmbIdNamingRefEdEntity reference) { + this.reference = reference; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof JoinEmbIdNamingRefIngEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof JoinEmbIdNamingRefIngEntity) ) { + return false; + } - JoinEmbIdNamingRefIngEntity that = (JoinEmbIdNamingRefIngEntity) o; + JoinEmbIdNamingRefIngEntity that = (JoinEmbIdNamingRefIngEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "JoinEmbIdNamingRefIngEntity(id = " + id + ", data = " + data + ")"; - } + public String toString() { + return "JoinEmbIdNamingRefIngEntity(id = " + id + ", data = " + data + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/ids/JoinMulIdNaming.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/ids/JoinMulIdNaming.java index 84f96a30b6..9d3a050172 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/ids/JoinMulIdNaming.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/ids/JoinMulIdNaming.java @@ -23,16 +23,16 @@ */ package org.hibernate.envers.test.integration.naming.ids; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.Iterator; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.mapping.Column; +import org.junit.Test; + import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertTrue; @@ -41,100 +41,121 @@ import static junit.framework.Assert.assertTrue; * @author Adam Warski (adam at warski dot org) */ public class JoinMulIdNaming extends BaseEnversJPAFunctionalTestCase { - private MulIdNaming ed_id1; - private MulIdNaming ed_id2; - private MulIdNaming ing_id1; + private MulIdNaming ed_id1; + private MulIdNaming ed_id2; + private MulIdNaming ing_id1; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { JoinMulIdNamingRefEdEntity.class, JoinMulIdNamingRefIngEntity.class }; - } + return new Class[] {JoinMulIdNamingRefEdEntity.class, JoinMulIdNamingRefIngEntity.class}; + } - @Test - @Priority(10) - public void initData() { - ed_id1 = new MulIdNaming(10, 20); - ed_id2 = new MulIdNaming(11, 21); - ing_id1 = new MulIdNaming(12, 22); + @Test + @Priority(10) + public void initData() { + ed_id1 = new MulIdNaming( 10, 20 ); + ed_id2 = new MulIdNaming( 11, 21 ); + ing_id1 = new MulIdNaming( 12, 22 ); - JoinMulIdNamingRefEdEntity ed1 = new JoinMulIdNamingRefEdEntity(ed_id1, "data1"); - JoinMulIdNamingRefEdEntity ed2 = new JoinMulIdNamingRefEdEntity(ed_id2, "data2"); + JoinMulIdNamingRefEdEntity ed1 = new JoinMulIdNamingRefEdEntity( ed_id1, "data1" ); + JoinMulIdNamingRefEdEntity ed2 = new JoinMulIdNamingRefEdEntity( ed_id2, "data2" ); - JoinMulIdNamingRefIngEntity ing1 = new JoinMulIdNamingRefIngEntity(ing_id1, "x", ed1); + JoinMulIdNamingRefIngEntity ing1 = new JoinMulIdNamingRefIngEntity( ing_id1, "x", ed1 ); - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); - em.persist(ed1); - em.persist(ed2); - em.persist(ing1); + em.persist( ed1 ); + em.persist( ed2 ); + em.persist( ing1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); + // Revision 2 + em.getTransaction().begin(); - ed2 = em.find(JoinMulIdNamingRefEdEntity.class, ed_id2); + ed2 = em.find( JoinMulIdNamingRefEdEntity.class, ed_id2 ); - ing1 = em.find(JoinMulIdNamingRefIngEntity.class, ing_id1); - ing1.setData("y"); - ing1.setReference(ed2); + ing1 = em.find( JoinMulIdNamingRefIngEntity.class, ing_id1 ); + ing1.setData( "y" ); + ing1.setReference( ed2 ); - em.getTransaction().commit(); - } + em.getTransaction().commit(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(JoinMulIdNamingRefEdEntity.class, ed_id1)); - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(JoinMulIdNamingRefEdEntity.class, ed_id2)); - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(JoinMulIdNamingRefIngEntity.class, ing_id1)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( + getAuditReader().getRevisions( + JoinMulIdNamingRefEdEntity.class, + ed_id1 + ) + ); + assert Arrays.asList( 1, 2 ).equals( + getAuditReader().getRevisions( + JoinMulIdNamingRefEdEntity.class, + ed_id2 + ) + ); + assert Arrays.asList( 1, 2 ).equals( + getAuditReader().getRevisions( + JoinMulIdNamingRefIngEntity.class, + ing_id1 + ) + ); + } - @Test - public void testHistoryOfEdId1() { - JoinMulIdNamingRefEdEntity ver1 = new JoinMulIdNamingRefEdEntity(ed_id1, "data1"); + @Test + public void testHistoryOfEdId1() { + JoinMulIdNamingRefEdEntity ver1 = new JoinMulIdNamingRefEdEntity( ed_id1, "data1" ); - assert getAuditReader().find(JoinMulIdNamingRefEdEntity.class, ed_id1, 1).equals(ver1); - assert getAuditReader().find(JoinMulIdNamingRefEdEntity.class, ed_id1, 2).equals(ver1); - } + assert getAuditReader().find( JoinMulIdNamingRefEdEntity.class, ed_id1, 1 ).equals( ver1 ); + assert getAuditReader().find( JoinMulIdNamingRefEdEntity.class, ed_id1, 2 ).equals( ver1 ); + } - @Test - public void testHistoryOfEdId2() { - JoinMulIdNamingRefEdEntity ver1 = new JoinMulIdNamingRefEdEntity(ed_id2, "data2"); + @Test + public void testHistoryOfEdId2() { + JoinMulIdNamingRefEdEntity ver1 = new JoinMulIdNamingRefEdEntity( ed_id2, "data2" ); - assert getAuditReader().find(JoinMulIdNamingRefEdEntity.class, ed_id2, 1).equals(ver1); - assert getAuditReader().find(JoinMulIdNamingRefEdEntity.class, ed_id2, 2).equals(ver1); - } + assert getAuditReader().find( JoinMulIdNamingRefEdEntity.class, ed_id2, 1 ).equals( ver1 ); + assert getAuditReader().find( JoinMulIdNamingRefEdEntity.class, ed_id2, 2 ).equals( ver1 ); + } - @Test - public void testHistoryOfIngId1() { - JoinMulIdNamingRefIngEntity ver1 = new JoinMulIdNamingRefIngEntity(ing_id1, "x", null); - JoinMulIdNamingRefIngEntity ver2 = new JoinMulIdNamingRefIngEntity(ing_id1, "y", null); + @Test + public void testHistoryOfIngId1() { + JoinMulIdNamingRefIngEntity ver1 = new JoinMulIdNamingRefIngEntity( ing_id1, "x", null ); + JoinMulIdNamingRefIngEntity ver2 = new JoinMulIdNamingRefIngEntity( ing_id1, "y", null ); - assert getAuditReader().find(JoinMulIdNamingRefIngEntity.class, ing_id1, 1).equals(ver1); - assert getAuditReader().find(JoinMulIdNamingRefIngEntity.class, ing_id1, 2).equals(ver2); + assert getAuditReader().find( JoinMulIdNamingRefIngEntity.class, ing_id1, 1 ).equals( ver1 ); + assert getAuditReader().find( JoinMulIdNamingRefIngEntity.class, ing_id1, 2 ).equals( ver2 ); - assert getAuditReader().find(JoinMulIdNamingRefIngEntity.class, ing_id1, 1).getReference().equals( - new JoinMulIdNamingRefEdEntity(ed_id1, "data1")); - assert getAuditReader().find(JoinMulIdNamingRefIngEntity.class, ing_id1, 2).getReference().equals( - new JoinMulIdNamingRefEdEntity(ed_id2, "data2")); - } + assert getAuditReader().find( JoinMulIdNamingRefIngEntity.class, ing_id1, 1 ).getReference().equals( + new JoinMulIdNamingRefEdEntity( ed_id1, "data1" ) + ); + assert getAuditReader().find( JoinMulIdNamingRefIngEntity.class, ing_id1, 2 ).getReference().equals( + new JoinMulIdNamingRefEdEntity( ed_id2, "data2" ) + ); + } - @SuppressWarnings({"unchecked"}) - @Test - public void testJoinColumnNames() { + @SuppressWarnings({"unchecked"}) + @Test + public void testJoinColumnNames() { Iterator columns = - getCfg().getClassMapping("org.hibernate.envers.test.integration.naming.ids.JoinMulIdNamingRefIngEntity_AUD") - .getProperty("reference_id1").getColumnIterator(); - assertTrue(columns.hasNext()); - assertEquals("ID1_reference", columns.next().getName()); - assertFalse(columns.hasNext()); + getCfg().getClassMapping( + "org.hibernate.envers.test.integration.naming.ids.JoinMulIdNamingRefIngEntity_AUD" + ) + .getProperty( "reference_id1" ).getColumnIterator(); + assertTrue( columns.hasNext() ); + assertEquals( "ID1_reference", columns.next().getName() ); + assertFalse( columns.hasNext() ); - columns = getCfg().getClassMapping("org.hibernate.envers.test.integration.naming.ids.JoinMulIdNamingRefIngEntity_AUD") - .getProperty("reference_id2").getColumnIterator(); - assertTrue(columns.hasNext()); - assertEquals("ID2_reference", columns.next().getName()); - assertFalse(columns.hasNext()); + columns = getCfg().getClassMapping( + "org.hibernate.envers.test.integration.naming.ids.JoinMulIdNamingRefIngEntity_AUD" + ) + .getProperty( "reference_id2" ).getColumnIterator(); + assertTrue( columns.hasNext() ); + assertEquals( "ID2_reference", columns.next().getName() ); + assertFalse( columns.hasNext() ); } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/ids/JoinMulIdNamingRefEdEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/ids/JoinMulIdNamingRefEdEntity.java index 08c0f93147..38b2830947 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/ids/JoinMulIdNamingRefEdEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/ids/JoinMulIdNamingRefEdEntity.java @@ -22,103 +22,115 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.naming.ids; -import java.util.List; + import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.IdClass; import javax.persistence.OneToMany; import javax.persistence.Table; +import java.util.List; import org.hibernate.envers.Audited; /** * ReferencEd entity + * * @author Adam Warski (adam at warski dot org) */ @Entity @Table(name = "JoinMulIdRefEd") @IdClass(MulIdNaming.class) public class JoinMulIdNamingRefEdEntity { - @Id - private Integer id1; + @Id + private Integer id1; - @Id - private Integer id2; + @Id + private Integer id2; - @Audited - private String data; + @Audited + private String data; - @Audited - @OneToMany(mappedBy="reference") - private List reffering; + @Audited + @OneToMany(mappedBy = "reference") + private List reffering; - public JoinMulIdNamingRefEdEntity() { - } + public JoinMulIdNamingRefEdEntity() { + } - public JoinMulIdNamingRefEdEntity(MulIdNaming id, String data) { - this.id1 = id.getId1(); - this.id2 = id.getId2(); - this.data = data; - } + public JoinMulIdNamingRefEdEntity(MulIdNaming id, String data) { + this.id1 = id.getId1(); + this.id2 = id.getId2(); + this.data = data; + } - public JoinMulIdNamingRefEdEntity(String data) { - this.data = data; - } + public JoinMulIdNamingRefEdEntity(String data) { + this.data = data; + } - public Integer getId1() { - return id1; - } + public Integer getId1() { + return id1; + } - public void setId1(Integer id1) { - this.id1 = id1; - } + public void setId1(Integer id1) { + this.id1 = id1; + } - public Integer getId2() { - return id2; - } + public Integer getId2() { + return id2; + } - public void setId2(Integer id2) { - this.id2 = id2; - } + public void setId2(Integer id2) { + this.id2 = id2; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public List getReffering() { - return reffering; - } + public List getReffering() { + return reffering; + } - public void setReffering(List reffering) { - this.reffering = reffering; - } + public void setReffering(List reffering) { + this.reffering = reffering; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof JoinMulIdNamingRefEdEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof JoinMulIdNamingRefEdEntity) ) { + return false; + } - JoinMulIdNamingRefEdEntity that = (JoinMulIdNamingRefEdEntity) o; + JoinMulIdNamingRefEdEntity that = (JoinMulIdNamingRefEdEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id1 != null ? !id1.equals(that.id1) : that.id1 != null) return false; - if (id2 != null ? !id2.equals(that.id2) : that.id2 != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id1 != null ? !id1.equals( that.id1 ) : that.id1 != null ) { + return false; + } + if ( id2 != null ? !id2.equals( that.id2 ) : that.id2 != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id1 != null ? id1.hashCode() : 0); - result = 31 * result + (id2 != null ? id2.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id1 != null ? id1.hashCode() : 0); + result = 31 * result + (id2 != null ? id2.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "JoinMulIdNamingRefEdEntity(id1 = " + id1 + ", id2 = " + id2 + ", data = " + data + ")"; - } + public String toString() { + return "JoinMulIdNamingRefEdEntity(id1 = " + id1 + ", id2 = " + id2 + ", data = " + data + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/ids/JoinMulIdNamingRefIngEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/ids/JoinMulIdNamingRefIngEntity.java index a211b42ba5..3ea8273a83 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/ids/JoinMulIdNamingRefIngEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/ids/JoinMulIdNamingRefIngEntity.java @@ -35,87 +35,101 @@ import org.hibernate.envers.Audited; /** * ReferencIng entity + * * @author Adam Warski (adam at warski dot org) */ @Entity @Table(name = "JoinMulIdRefIng") @IdClass(MulIdNaming.class) -public class JoinMulIdNamingRefIngEntity { - @Id - private Integer id1; +public class JoinMulIdNamingRefIngEntity { + @Id + private Integer id1; - @Id - private Integer id2; + @Id + private Integer id2; - @Audited - private String data; + @Audited + private String data; - @Audited - @ManyToOne - @JoinColumns({@JoinColumn(name = "ID2_reference", referencedColumnName = "ID_2"), - @JoinColumn(name = "ID1_reference", referencedColumnName = "ID_1")}) - private JoinMulIdNamingRefEdEntity reference; + @Audited + @ManyToOne + @JoinColumns({ + @JoinColumn(name = "ID2_reference", referencedColumnName = "ID_2"), + @JoinColumn(name = "ID1_reference", referencedColumnName = "ID_1") + }) + private JoinMulIdNamingRefEdEntity reference; - public JoinMulIdNamingRefIngEntity() { } + public JoinMulIdNamingRefIngEntity() { + } - public JoinMulIdNamingRefIngEntity(MulIdNaming id, String data, JoinMulIdNamingRefEdEntity reference) { - this.id1 = id.getId1(); - this.id2 = id.getId2(); - this.data = data; - this.reference = reference; - } + public JoinMulIdNamingRefIngEntity(MulIdNaming id, String data, JoinMulIdNamingRefEdEntity reference) { + this.id1 = id.getId1(); + this.id2 = id.getId2(); + this.data = data; + this.reference = reference; + } - public JoinMulIdNamingRefIngEntity(String data, JoinMulIdNamingRefEdEntity reference) { - this.data = data; - this.reference = reference; - } + public JoinMulIdNamingRefIngEntity(String data, JoinMulIdNamingRefEdEntity reference) { + this.data = data; + this.reference = reference; + } - public void setId1(Integer id1) { - this.id1 = id1; - } + public void setId1(Integer id1) { + this.id1 = id1; + } - public void setId2(Integer id2) { - this.id2 = id2; - } + public void setId2(Integer id2) { + this.id2 = id2; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public JoinMulIdNamingRefEdEntity getReference() { - return reference; - } + public JoinMulIdNamingRefEdEntity getReference() { + return reference; + } - public void setReference(JoinMulIdNamingRefEdEntity reference) { - this.reference = reference; - } + public void setReference(JoinMulIdNamingRefEdEntity reference) { + this.reference = reference; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof JoinMulIdNamingRefIngEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof JoinMulIdNamingRefIngEntity) ) { + return false; + } - JoinMulIdNamingRefIngEntity that = (JoinMulIdNamingRefIngEntity) o; + JoinMulIdNamingRefIngEntity that = (JoinMulIdNamingRefIngEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id1 != null ? !id1.equals(that.id1) : that.id1 != null) return false; - if (id2 != null ? !id2.equals(that.id2) : that.id2 != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id1 != null ? !id1.equals( that.id1 ) : that.id1 != null ) { + return false; + } + if ( id2 != null ? !id2.equals( that.id2 ) : that.id2 != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id1 != null ? id1.hashCode() : 0); - result = 31 * result + (id2 != null ? id2.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id1 != null ? id1.hashCode() : 0); + result = 31 * result + (id2 != null ? id2.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - public String toString() { - return "JoinMulIdNamingRefIngEntity(id1 = " + id1 + ", id2 = " + id2 + ", data = " + data + ")"; - } + public String toString() { + return "JoinMulIdNamingRefIngEntity(id1 = " + id1 + ", id2 = " + id2 + ", data = " + data + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/ids/MulIdNaming.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/ids/MulIdNaming.java index f52caa845d..4a4d3928b7 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/ids/MulIdNaming.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/ids/MulIdNaming.java @@ -22,63 +22,72 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.naming.ids; -import java.io.Serializable; + import javax.persistence.Column; +import java.io.Serializable; /** * @author Adam Warski (adam at warski dot org) */ public class MulIdNaming implements Serializable { - @Column(name = "ID_1") - private Integer id1; + @Column(name = "ID_1") + private Integer id1; - @Column(name = "ID_2") - private Integer id2; + @Column(name = "ID_2") + private Integer id2; - public MulIdNaming() { - } + public MulIdNaming() { + } - public MulIdNaming(Integer id1, Integer id2) { - this.id1 = id1; - this.id2 = id2; - } + public MulIdNaming(Integer id1, Integer id2) { + this.id1 = id1; + this.id2 = id2; + } - public Integer getId1() { - return id1; - } + public Integer getId1() { + return id1; + } - public void setId1(Integer id1) { - this.id1 = id1; - } + public void setId1(Integer id1) { + this.id1 = id1; + } - public Integer getId2() { - return id2; - } + public Integer getId2() { + return id2; + } - public void setId2(Integer id2) { - this.id2 = id2; - } + public void setId2(Integer id2) { + this.id2 = id2; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof MulIdNaming)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof MulIdNaming) ) { + return false; + } - MulIdNaming mulId = (MulIdNaming) o; + MulIdNaming mulId = (MulIdNaming) o; - if (id1 != null ? !id1.equals(mulId.id1) : mulId.id1 != null) return false; - if (id2 != null ? !id2.equals(mulId.id2) : mulId.id2 != null) return false; + if ( id1 != null ? !id1.equals( mulId.id1 ) : mulId.id1 != null ) { + return false; + } + if ( id2 != null ? !id2.equals( mulId.id2 ) : mulId.id2 != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id1 != null ? id1.hashCode() : 0); - result = 31 * result + (id2 != null ? id2.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id1 != null ? id1.hashCode() : 0); + result = 31 * result + (id2 != null ? id2.hashCode() : 0); + return result; + } - public String toString() { - return "MulIdNaming(" + id1 + ", " + id2 + ")"; - } + public String toString() { + return "MulIdNaming(" + id1 + ", " + id2 + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/quotation/QuotedFieldsEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/quotation/QuotedFieldsEntity.java index d6013f25dc..c4ffc34207 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/quotation/QuotedFieldsEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/quotation/QuotedFieldsEntity.java @@ -12,84 +12,94 @@ import org.hibernate.envers.Audited; */ @Entity public class QuotedFieldsEntity { - @Id - @GeneratedValue - @Column(name = "`id`") - private Long id; + @Id + @GeneratedValue + @Column(name = "`id`") + private Long id; - @Column(name = "`data1`") - @Audited - private String data1; + @Column(name = "`data1`") + @Audited + private String data1; - @Column(name = "`data2`") - @Audited - private Integer data2; + @Column(name = "`data2`") + @Audited + private Integer data2; - public QuotedFieldsEntity() { - } + public QuotedFieldsEntity() { + } - public QuotedFieldsEntity(String data1, Integer data2) { - this.data1 = data1; - this.data2 = data2; - } + public QuotedFieldsEntity(String data1, Integer data2) { + this.data1 = data1; + this.data2 = data2; + } - public QuotedFieldsEntity(Long id, String data1, Integer data2) { - this.id = id; - this.data1 = data1; - this.data2 = data2; - } + public QuotedFieldsEntity(Long id, String data1, Integer data2) { + this.id = id; + this.data1 = data1; + this.data2 = data2; + } - public Long getId() { - return id; - } + public Long getId() { + return id; + } - public void setId(Long id) { - this.id = id; - } + public void setId(Long id) { + this.id = id; + } - public String getData1() { - return data1; - } + public String getData1() { + return data1; + } - public void setData1(String data1) { - this.data1 = data1; - } + public void setData1(String data1) { + this.data1 = data1; + } - public Integer getData2() { - return data2; - } + public Integer getData2() { + return data2; + } - public void setData2(Integer data2) { - this.data2 = data2; - } + public void setData2(Integer data2) { + this.data2 = data2; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof QuotedFieldsEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof QuotedFieldsEntity) ) { + return false; + } - QuotedFieldsEntity that = (QuotedFieldsEntity) o; + QuotedFieldsEntity that = (QuotedFieldsEntity) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; - if (data1 != null ? !data1.equals(that.data1) : that.data1 != null) return false; - if (data2 != null ? !data2.equals(that.data2) : that.data2 != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } + if ( data1 != null ? !data1.equals( that.data1 ) : that.data1 != null ) { + return false; + } + if ( data2 != null ? !data2.equals( that.data2 ) : that.data2 != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data1 != null ? data1.hashCode() : 0); - result = 31 * result + (data2 != null ? data2.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data1 != null ? data1.hashCode() : 0); + result = 31 * result + (data2 != null ? data2.hashCode() : 0); + return result; + } - @Override - public String toString() { - return "QuotedFieldsEntity{" + - "id=" + id + - ", data1='" + data1 + '\'' + - ", data2=" + data2 + - '}'; - } + @Override + public String toString() { + return "QuotedFieldsEntity{" + + "id=" + id + + ", data1='" + data1 + '\'' + + ", data2=" + data2 + + '}'; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/quotation/QuotedFieldsTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/quotation/QuotedFieldsTest.java index 1e32f31edf..8ba87cdf0c 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/quotation/QuotedFieldsTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/quotation/QuotedFieldsTest.java @@ -1,105 +1,107 @@ package org.hibernate.envers.test.integration.naming.quotation; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.Iterator; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.mapping.Column; import org.hibernate.mapping.Table; +import org.junit.Test; + /** * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public class QuotedFieldsTest extends BaseEnversJPAFunctionalTestCase { - private Long qfeId1 = null; - private Long qfeId2 = null; + private Long qfeId1 = null; + private Long qfeId2 = null; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { QuotedFieldsEntity.class }; - } + return new Class[] {QuotedFieldsEntity.class}; + } - @Test - @Priority(10) - public void initData() { - QuotedFieldsEntity qfe1 = new QuotedFieldsEntity("data1", 1); - QuotedFieldsEntity qfe2 = new QuotedFieldsEntity("data2", 2); + @Test + @Priority(10) + public void initData() { + QuotedFieldsEntity qfe1 = new QuotedFieldsEntity( "data1", 1 ); + QuotedFieldsEntity qfe2 = new QuotedFieldsEntity( "data2", 2 ); - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); - em.persist(qfe1); - em.persist(qfe2); - em.getTransaction().commit(); + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); + em.persist( qfe1 ); + em.persist( qfe2 ); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); - qfe1 = em.find(QuotedFieldsEntity.class, qfe1.getId()); - qfe1.setData1("data1 changed"); - em.getTransaction().commit(); + // Revision 2 + em.getTransaction().begin(); + qfe1 = em.find( QuotedFieldsEntity.class, qfe1.getId() ); + qfe1.setData1( "data1 changed" ); + em.getTransaction().commit(); - // Revision 3 - em.getTransaction().begin(); - qfe2 = em.find(QuotedFieldsEntity.class, qfe2.getId()); - qfe2.setData2(3); - em.getTransaction().commit(); + // Revision 3 + em.getTransaction().begin(); + qfe2 = em.find( QuotedFieldsEntity.class, qfe2.getId() ); + qfe2.setData2( 3 ); + em.getTransaction().commit(); - qfeId1 = qfe1.getId(); - qfeId2 = qfe2.getId(); - } + qfeId1 = qfe1.getId(); + qfeId2 = qfe2.getId(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(QuotedFieldsEntity.class, qfeId1)); - assert Arrays.asList(1, 3).equals(getAuditReader().getRevisions(QuotedFieldsEntity.class, qfeId2)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( QuotedFieldsEntity.class, qfeId1 ) ); + assert Arrays.asList( 1, 3 ).equals( getAuditReader().getRevisions( QuotedFieldsEntity.class, qfeId2 ) ); + } - @Test - public void testHistoryOfId1() { - QuotedFieldsEntity ver1 = new QuotedFieldsEntity(qfeId1, "data1", 1); - QuotedFieldsEntity ver2 = new QuotedFieldsEntity(qfeId1, "data1 changed", 1); + @Test + public void testHistoryOfId1() { + QuotedFieldsEntity ver1 = new QuotedFieldsEntity( qfeId1, "data1", 1 ); + QuotedFieldsEntity ver2 = new QuotedFieldsEntity( qfeId1, "data1 changed", 1 ); - assert getAuditReader().find(QuotedFieldsEntity.class, qfeId1, 1).equals(ver1); - assert getAuditReader().find(QuotedFieldsEntity.class, qfeId1, 2).equals(ver2); - assert getAuditReader().find(QuotedFieldsEntity.class, qfeId1, 3).equals(ver2); - } + assert getAuditReader().find( QuotedFieldsEntity.class, qfeId1, 1 ).equals( ver1 ); + assert getAuditReader().find( QuotedFieldsEntity.class, qfeId1, 2 ).equals( ver2 ); + assert getAuditReader().find( QuotedFieldsEntity.class, qfeId1, 3 ).equals( ver2 ); + } - @Test - public void testHistoryOfId2() { - QuotedFieldsEntity ver1 = new QuotedFieldsEntity(qfeId2, "data2", 2); - QuotedFieldsEntity ver2 = new QuotedFieldsEntity(qfeId2, "data2", 3); + @Test + public void testHistoryOfId2() { + QuotedFieldsEntity ver1 = new QuotedFieldsEntity( qfeId2, "data2", 2 ); + QuotedFieldsEntity ver2 = new QuotedFieldsEntity( qfeId2, "data2", 3 ); - assert getAuditReader().find(QuotedFieldsEntity.class, qfeId2, 1).equals(ver1); - assert getAuditReader().find(QuotedFieldsEntity.class, qfeId2, 2).equals(ver1); - assert getAuditReader().find(QuotedFieldsEntity.class, qfeId2, 3).equals(ver2); - } + assert getAuditReader().find( QuotedFieldsEntity.class, qfeId2, 1 ).equals( ver1 ); + assert getAuditReader().find( QuotedFieldsEntity.class, qfeId2, 2 ).equals( ver1 ); + assert getAuditReader().find( QuotedFieldsEntity.class, qfeId2, 3 ).equals( ver2 ); + } - @Test - public void testEscapeEntityField() { - Table table = getCfg().getClassMapping("org.hibernate.envers.test.integration.naming.quotation.QuotedFieldsEntity_AUD").getTable(); - Column column1 = getColumnByName(table, "id"); - Column column2 = getColumnByName(table, "data1"); - Column column3 = getColumnByName(table, "data2"); - assert column1 != null; - assert column2 != null; - assert column3 != null; - assert column1.isQuoted(); - assert column2.isQuoted(); - assert column3.isQuoted(); - } + @Test + public void testEscapeEntityField() { + Table table = getCfg().getClassMapping( + "org.hibernate.envers.test.integration.naming.quotation.QuotedFieldsEntity_AUD" + ).getTable(); + Column column1 = getColumnByName( table, "id" ); + Column column2 = getColumnByName( table, "data1" ); + Column column3 = getColumnByName( table, "data2" ); + assert column1 != null; + assert column2 != null; + assert column3 != null; + assert column1.isQuoted(); + assert column2.isQuoted(); + assert column3.isQuoted(); + } - private Column getColumnByName(Table table, String columnName) { - Iterator columnIterator = table.getColumnIterator(); - while (columnIterator.hasNext()) { - Column column = columnIterator.next(); - if (columnName.equals(column.getName())) { - return column; - } - } - return null; - } + private Column getColumnByName(Table table, String columnName) { + Iterator columnIterator = table.getColumnIterator(); + while ( columnIterator.hasNext() ) { + Column column = columnIterator.next(); + if ( columnName.equals( column.getName() ) ) { + return column; + } + } + return null; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/notinsertable/NotInsertable.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/notinsertable/NotInsertable.java index 4e7e0fa426..36faba5fd0 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/notinsertable/NotInsertable.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/notinsertable/NotInsertable.java @@ -23,52 +23,52 @@ */ package org.hibernate.envers.test.integration.notinsertable; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class NotInsertable extends BaseEnversJPAFunctionalTestCase { - private Integer id1; + private Integer id1; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { NotInsertableTestEntity.class }; - } + return new Class[] {NotInsertableTestEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); - em.getTransaction().begin(); - NotInsertableTestEntity dte = new NotInsertableTestEntity("data1"); - em.persist(dte); - id1 = dte.getId(); - em.getTransaction().commit(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); + em.getTransaction().begin(); + NotInsertableTestEntity dte = new NotInsertableTestEntity( "data1" ); + em.persist( dte ); + id1 = dte.getId(); + em.getTransaction().commit(); - em.getTransaction().begin(); - dte = em.find(NotInsertableTestEntity.class, id1); - dte.setData("data2"); - em.getTransaction().commit(); - } + em.getTransaction().begin(); + dte = em.find( NotInsertableTestEntity.class, id1 ); + dte.setData( "data2" ); + em.getTransaction().commit(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(NotInsertableTestEntity.class, id1)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( NotInsertableTestEntity.class, id1 ) ); + } - @Test - public void testHistoryOfId1() { - NotInsertableTestEntity ver1 = new NotInsertableTestEntity(id1, "data1", "data1"); - NotInsertableTestEntity ver2 = new NotInsertableTestEntity(id1, "data2", "data2"); + @Test + public void testHistoryOfId1() { + NotInsertableTestEntity ver1 = new NotInsertableTestEntity( id1, "data1", "data1" ); + NotInsertableTestEntity ver2 = new NotInsertableTestEntity( id1, "data2", "data2" ); - assert getAuditReader().find(NotInsertableTestEntity.class, id1, 1).equals(ver1); - assert getAuditReader().find(NotInsertableTestEntity.class, id1, 2).equals(ver2); - } + assert getAuditReader().find( NotInsertableTestEntity.class, id1, 1 ).equals( ver1 ); + assert getAuditReader().find( NotInsertableTestEntity.class, id1, 2 ).equals( ver2 ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/notinsertable/NotInsertableTestEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/notinsertable/NotInsertableTestEntity.java index 24adfcc32d..b1e83f070f 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/notinsertable/NotInsertableTestEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/notinsertable/NotInsertableTestEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.notinsertable; + import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -35,71 +36,81 @@ import org.hibernate.envers.Audited; @Entity @Audited public class NotInsertableTestEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - @Column(name = "data") - private String data; + @Column(name = "data") + private String data; - @Column(name = "data", insertable = false, updatable = false) - private String dataCopy; + @Column(name = "data", insertable = false, updatable = false) + private String dataCopy; - public NotInsertableTestEntity() { - } + public NotInsertableTestEntity() { + } - public NotInsertableTestEntity(Integer id, String data, String dataCopy) { - this.id = id; - this.data = data; - this.dataCopy = dataCopy; - } + public NotInsertableTestEntity(Integer id, String data, String dataCopy) { + this.id = id; + this.data = data; + this.dataCopy = dataCopy; + } - public NotInsertableTestEntity(String data) { - this.data = data; - } + public NotInsertableTestEntity(String data) { + this.data = data; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public String getDataCopy() { - return dataCopy; - } + public String getDataCopy() { + return dataCopy; + } - public void setDataCopy(String dataCopy) { - this.dataCopy = dataCopy; - } + public void setDataCopy(String dataCopy) { + this.dataCopy = dataCopy; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof NotInsertableTestEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof NotInsertableTestEntity) ) { + return false; + } - NotInsertableTestEntity that = (NotInsertableTestEntity) o; + NotInsertableTestEntity that = (NotInsertableTestEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (dataCopy != null ? !dataCopy.equals(that.dataCopy) : that.dataCopy != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( dataCopy != null ? !dataCopy.equals( that.dataCopy ) : that.dataCopy != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - result = 31 * result + (dataCopy != null ? dataCopy.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + result = 31 * result + (dataCopy != null ? dataCopy.hashCode() : 0); + return result; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/notinsertable/manytoone/ManyToOneNotInsertable.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/notinsertable/manytoone/ManyToOneNotInsertable.java index f22e3977c9..d8842cfae1 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/notinsertable/manytoone/ManyToOneNotInsertable.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/notinsertable/manytoone/ManyToOneNotInsertable.java @@ -1,80 +1,85 @@ package org.hibernate.envers.test.integration.notinsertable.manytoone; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; +import org.junit.Test; + public class ManyToOneNotInsertable extends BaseEnversJPAFunctionalTestCase { - private Integer mto_id1; - private Integer type_id1; - private Integer type_id2; + private Integer mto_id1; + private Integer type_id1; + private Integer type_id2; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { ManyToOneNotInsertableEntity.class, NotInsertableEntityType.class }; - } + return new Class[] {ManyToOneNotInsertableEntity.class, NotInsertableEntityType.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - mto_id1 = 1; - type_id1 = 2; - type_id2 = 3; + mto_id1 = 1; + type_id1 = 2; + type_id2 = 3; // Rev 1 // Preparing the types em.getTransaction().begin(); - NotInsertableEntityType type1 = new NotInsertableEntityType(type_id1, "type1"); - NotInsertableEntityType type2 = new NotInsertableEntityType(type_id2, "type2"); + NotInsertableEntityType type1 = new NotInsertableEntityType( type_id1, "type1" ); + NotInsertableEntityType type2 = new NotInsertableEntityType( type_id2, "type2" ); - em.persist(type1); - em.persist(type2); + em.persist( type1 ); + em.persist( type2 ); em.getTransaction().commit(); - // Rev 2 - em.getTransaction().begin(); + // Rev 2 + em.getTransaction().begin(); - ManyToOneNotInsertableEntity master = new ManyToOneNotInsertableEntity(mto_id1, type_id1, type1); - em.persist(master); + ManyToOneNotInsertableEntity master = new ManyToOneNotInsertableEntity( mto_id1, type_id1, type1 ); + em.persist( master ); - em.getTransaction().commit(); + em.getTransaction().commit(); // Rev 2 - em.getTransaction().begin(); + em.getTransaction().begin(); - master = em.find(ManyToOneNotInsertableEntity.class, mto_id1); - master.setNumber(type_id2); + master = em.find( ManyToOneNotInsertableEntity.class, mto_id1 ); + master.setNumber( type_id2 ); - em.getTransaction().commit(); - } + em.getTransaction().commit(); + } - @Test - public void testRevisionCounts() { - assert Arrays.asList(1).equals(getAuditReader().getRevisions(NotInsertableEntityType.class, type_id1)); - assert Arrays.asList(1).equals(getAuditReader().getRevisions(NotInsertableEntityType.class, type_id2)); + @Test + public void testRevisionCounts() { + assert Arrays.asList( 1 ).equals( getAuditReader().getRevisions( NotInsertableEntityType.class, type_id1 ) ); + assert Arrays.asList( 1 ).equals( getAuditReader().getRevisions( NotInsertableEntityType.class, type_id2 ) ); - assert Arrays.asList(2, 3).equals(getAuditReader().getRevisions(ManyToOneNotInsertableEntity.class, mto_id1)); - } + assert Arrays.asList( 2, 3 ).equals( + getAuditReader().getRevisions( + ManyToOneNotInsertableEntity.class, + mto_id1 + ) + ); + } - @Test - public void testNotInsertableEntity() { - ManyToOneNotInsertableEntity ver1 = getAuditReader().find(ManyToOneNotInsertableEntity.class, mto_id1, 1); - ManyToOneNotInsertableEntity ver2 = getAuditReader().find(ManyToOneNotInsertableEntity.class, mto_id1, 2); - ManyToOneNotInsertableEntity ver3 = getAuditReader().find(ManyToOneNotInsertableEntity.class, mto_id1, 3); + @Test + public void testNotInsertableEntity() { + ManyToOneNotInsertableEntity ver1 = getAuditReader().find( ManyToOneNotInsertableEntity.class, mto_id1, 1 ); + ManyToOneNotInsertableEntity ver2 = getAuditReader().find( ManyToOneNotInsertableEntity.class, mto_id1, 2 ); + ManyToOneNotInsertableEntity ver3 = getAuditReader().find( ManyToOneNotInsertableEntity.class, mto_id1, 3 ); - NotInsertableEntityType type1 = getEntityManager().find(NotInsertableEntityType.class, type_id1); - NotInsertableEntityType type2 = getEntityManager().find(NotInsertableEntityType.class, type_id2); + NotInsertableEntityType type1 = getEntityManager().find( NotInsertableEntityType.class, type_id1 ); + NotInsertableEntityType type2 = getEntityManager().find( NotInsertableEntityType.class, type_id2 ); assert ver1 == null; - assert ver2.getType().equals(type1); - assert ver3.getType().equals(type2); - } + assert ver2.getType().equals( type1 ); + assert ver3.getType().equals( type2 ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/notinsertable/manytoone/ManyToOneNotInsertableEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/notinsertable/manytoone/ManyToOneNotInsertableEntity.java index b46086c412..9ff826149c 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/notinsertable/manytoone/ManyToOneNotInsertableEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/notinsertable/manytoone/ManyToOneNotInsertableEntity.java @@ -1,4 +1,5 @@ package org.hibernate.envers.test.integration.notinsertable.manytoone; + import javax.persistence.Basic; import javax.persistence.Column; import javax.persistence.Entity; @@ -13,18 +14,19 @@ import org.hibernate.envers.Audited; @Table(name = "ManyToOneNotIns") @Audited public class ManyToOneNotInsertableEntity { - @Id - private Integer id; + @Id + private Integer id; - @Basic + @Basic @Column(name = "numVal") - private Integer number; + private Integer number; @ManyToOne @JoinColumn(name = "numVal", insertable = false, updatable = false) private NotInsertableEntityType type; - public ManyToOneNotInsertableEntity() { } + public ManyToOneNotInsertableEntity() { + } public ManyToOneNotInsertableEntity(Integer id, Integer number, NotInsertableEntityType type) { this.id = id; diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/notinsertable/manytoone/NotInsertableEntityType.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/notinsertable/manytoone/NotInsertableEntityType.java index 31be0e82b2..faae5ab6fb 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/notinsertable/manytoone/NotInsertableEntityType.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/notinsertable/manytoone/NotInsertableEntityType.java @@ -1,4 +1,5 @@ package org.hibernate.envers.test.integration.notinsertable.manytoone; + import javax.persistence.Basic; import javax.persistence.Entity; import javax.persistence.Id; @@ -8,18 +9,19 @@ import org.hibernate.envers.Audited; @Entity @Audited public class NotInsertableEntityType { - public NotInsertableEntityType(Integer typeId, String type) { - this.typeId = typeId; - this.type = type; - } + public NotInsertableEntityType(Integer typeId, String type) { + this.typeId = typeId; + this.type = type; + } - public NotInsertableEntityType() { } + public NotInsertableEntityType() { + } - @Id - private Integer typeId; + @Id + private Integer typeId; - @Basic - private String type; + @Basic + private String type; public Integer getTypeId() { return typeId; @@ -39,13 +41,21 @@ public class NotInsertableEntityType { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } NotInsertableEntityType that = (NotInsertableEntityType) o; - if (type != null ? !type.equals(that.type) : that.type != null) return false; - if (typeId != null ? !typeId.equals(that.typeId) : that.typeId != null) return false; + if ( type != null ? !type.equals( that.type ) : that.type != null ) { + return false; + } + if ( typeId != null ? !typeId.equals( that.typeId ) : that.typeId != null ) { + return false; + } return true; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/notupdatable/PropertyNotUpdatableEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/notupdatable/PropertyNotUpdatableEntity.java index a2518649cb..b62af259f6 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/notupdatable/PropertyNotUpdatableEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/notupdatable/PropertyNotUpdatableEntity.java @@ -1,10 +1,10 @@ package org.hibernate.envers.test.integration.notupdatable; -import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; +import java.io.Serializable; import org.hibernate.envers.Audited; @@ -14,92 +14,104 @@ import org.hibernate.envers.Audited; @Entity @Audited public class PropertyNotUpdatableEntity implements Serializable { - @Id - @GeneratedValue - private Long id; + @Id + @GeneratedValue + private Long id; - private String data; + private String data; - @Column(updatable = false) - private String constantData1; + @Column(updatable = false) + private String constantData1; - @Column(updatable = false) - private String constantData2; + @Column(updatable = false) + private String constantData2; - public PropertyNotUpdatableEntity() { - } + public PropertyNotUpdatableEntity() { + } - public PropertyNotUpdatableEntity(String data, String constantData1, String constantData2) { - this.constantData1 = constantData1; - this.constantData2 = constantData2; - this.data = data; - } + public PropertyNotUpdatableEntity(String data, String constantData1, String constantData2) { + this.constantData1 = constantData1; + this.constantData2 = constantData2; + this.data = data; + } - public PropertyNotUpdatableEntity(String data, String constantData1, String constantData2, Long id) { - this.data = data; - this.id = id; - this.constantData1 = constantData1; - this.constantData2 = constantData2; - } + public PropertyNotUpdatableEntity(String data, String constantData1, String constantData2, Long id) { + this.data = data; + this.id = id; + this.constantData1 = constantData1; + this.constantData2 = constantData2; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof PropertyNotUpdatableEntity)) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof PropertyNotUpdatableEntity) ) { + return false; + } - PropertyNotUpdatableEntity that = (PropertyNotUpdatableEntity) o; + PropertyNotUpdatableEntity that = (PropertyNotUpdatableEntity) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (constantData1 != null ? !constantData1.equals(that.constantData1) : that.constantData1 != null) return false; - if (constantData2 != null ? !constantData2.equals(that.constantData2) : that.constantData2 != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( constantData1 != null ? !constantData1.equals( that.constantData1 ) : that.constantData1 != null ) { + return false; + } + if ( constantData2 != null ? !constantData2.equals( that.constantData2 ) : that.constantData2 != null ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - int result = id != null ? id.hashCode() : 0; - result = 31 * result + (data != null ? data.hashCode() : 0); - result = 31 * result + (constantData1 != null ? constantData1.hashCode() : 0); - result = 31 * result + (constantData2 != null ? constantData2.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = id != null ? id.hashCode() : 0; + result = 31 * result + (data != null ? data.hashCode() : 0); + result = 31 * result + (constantData1 != null ? constantData1.hashCode() : 0); + result = 31 * result + (constantData2 != null ? constantData2.hashCode() : 0); + return result; + } - @Override - public String toString() { - return "PropertyNotUpdatableEntity(id = " + id + ", data = " + data + ", constantData1 = " + constantData1 + ", constantData2 = " + constantData2 + ")"; - } + @Override + public String toString() { + return "PropertyNotUpdatableEntity(id = " + id + ", data = " + data + ", constantData1 = " + constantData1 + ", constantData2 = " + constantData2 + ")"; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public Long getId() { - return id; - } + public Long getId() { + return id; + } - public void setId(Long id) { - this.id = id; - } + public void setId(Long id) { + this.id = id; + } - public String getConstantData1() { - return constantData1; - } + public String getConstantData1() { + return constantData1; + } - public void setConstantData1(String constantData1) { - this.constantData1 = constantData1; - } + public void setConstantData1(String constantData1) { + this.constantData1 = constantData1; + } - public String getConstantData2() { - return constantData2; - } + public String getConstantData2() { + return constantData2; + } - public void setConstantData2(String constantData2) { - this.constantData2 = constantData2; - } + public void setConstantData2(String constantData2) { + this.constantData2 = constantData2; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/notupdatable/PropertyNotUpdatableTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/notupdatable/PropertyNotUpdatableTest.java index e9abc7425c..6d450c2bd8 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/notupdatable/PropertyNotUpdatableTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/notupdatable/PropertyNotUpdatableTest.java @@ -1,16 +1,17 @@ package org.hibernate.envers.test.integration.notupdatable; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.List; import java.util.Map; -import javax.persistence.EntityManager; - -import junit.framework.Assert; -import org.junit.Test; import org.hibernate.envers.configuration.EnversSettings; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; + +import org.junit.Test; +import junit.framework.Assert; + import org.hibernate.testing.TestForIssue; /** @@ -18,79 +19,110 @@ import org.hibernate.testing.TestForIssue; */ @TestForIssue(jiraKey = "HHH-5411") public class PropertyNotUpdatableTest extends BaseEnversJPAFunctionalTestCase { - private Long id = null; + private Long id = null; - @Override - protected void addConfigOptions(Map options) { - options.put(EnversSettings.STORE_DATA_AT_DELETE, "true"); - } + @Override + protected void addConfigOptions(Map options) { + options.put( EnversSettings.STORE_DATA_AT_DELETE, "true" ); + } - @Override - protected Class[] getAnnotatedClasses() { - return new Class[] { PropertyNotUpdatableEntity.class }; - } + @Override + protected Class[] getAnnotatedClasses() { + return new Class[] {PropertyNotUpdatableEntity.class}; + } - @Test - @Priority(10) - public void initData() { - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); - PropertyNotUpdatableEntity entity = new PropertyNotUpdatableEntity("data", "constant data 1", "constant data 2"); - em.persist(entity); - em.getTransaction().commit(); + @Test + @Priority(10) + public void initData() { + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); + PropertyNotUpdatableEntity entity = new PropertyNotUpdatableEntity( + "data", + "constant data 1", + "constant data 2" + ); + em.persist( entity ); + em.getTransaction().commit(); - id = entity.getId(); + id = entity.getId(); - // Revision 2 - em.getTransaction().begin(); - entity = em.find(PropertyNotUpdatableEntity.class, entity.getId()); - entity.setData("modified data"); - entity.setConstantData1(null); - em.merge(entity); - em.getTransaction().commit(); + // Revision 2 + em.getTransaction().begin(); + entity = em.find( PropertyNotUpdatableEntity.class, entity.getId() ); + entity.setData( "modified data" ); + entity.setConstantData1( null ); + em.merge( entity ); + em.getTransaction().commit(); - em.close(); - em = getEntityManager(); // Re-opening entity manager to re-initialize non-updatable fields - // with database values. Otherwise PostUpdateEvent#getOldState() returns previous - // memory state. This can be achieved using EntityManager#refresh(Object) method as well. + em.close(); + em = getEntityManager(); // Re-opening entity manager to re-initialize non-updatable fields + // with database values. Otherwise PostUpdateEvent#getOldState() returns previous + // memory state. This can be achieved using EntityManager#refresh(Object) method as well. - // Revision 3 - em.getTransaction().begin(); - entity = em.find(PropertyNotUpdatableEntity.class, entity.getId()); - entity.setData("another modified data"); - entity.setConstantData2("invalid data"); - em.merge(entity); - em.getTransaction().commit(); + // Revision 3 + em.getTransaction().begin(); + entity = em.find( PropertyNotUpdatableEntity.class, entity.getId() ); + entity.setData( "another modified data" ); + entity.setConstantData2( "invalid data" ); + em.merge( entity ); + em.getTransaction().commit(); - // Revision 4 - em.getTransaction().begin(); - em.refresh(entity); - em.remove(entity); - em.getTransaction().commit(); - } + // Revision 4 + em.getTransaction().begin(); + em.refresh( entity ); + em.remove( entity ); + em.getTransaction().commit(); + } - @Test - public void testRevisionsCounts() { - Assert.assertEquals(Arrays.asList(1, 2, 3, 4), getAuditReader().getRevisions(PropertyNotUpdatableEntity.class, id)); - } + @Test + public void testRevisionsCounts() { + Assert.assertEquals( + Arrays.asList( 1, 2, 3, 4 ), + getAuditReader().getRevisions( PropertyNotUpdatableEntity.class, id ) + ); + } - @Test - public void testHistoryOfId() { - PropertyNotUpdatableEntity ver1 = new PropertyNotUpdatableEntity("data", "constant data 1", "constant data 2", id); - Assert.assertEquals(ver1, getAuditReader().find(PropertyNotUpdatableEntity.class, id, 1)); + @Test + public void testHistoryOfId() { + PropertyNotUpdatableEntity ver1 = new PropertyNotUpdatableEntity( + "data", + "constant data 1", + "constant data 2", + id + ); + Assert.assertEquals( ver1, getAuditReader().find( PropertyNotUpdatableEntity.class, id, 1 ) ); - PropertyNotUpdatableEntity ver2 = new PropertyNotUpdatableEntity("modified data", "constant data 1", "constant data 2", id); - Assert.assertEquals(ver2, getAuditReader().find(PropertyNotUpdatableEntity.class, id, 2)); + PropertyNotUpdatableEntity ver2 = new PropertyNotUpdatableEntity( + "modified data", + "constant data 1", + "constant data 2", + id + ); + Assert.assertEquals( ver2, getAuditReader().find( PropertyNotUpdatableEntity.class, id, 2 ) ); - PropertyNotUpdatableEntity ver3 = new PropertyNotUpdatableEntity("another modified data", "constant data 1", "constant data 2", id); - Assert.assertEquals(ver3, getAuditReader().find(PropertyNotUpdatableEntity.class, id, 3)); - } + PropertyNotUpdatableEntity ver3 = new PropertyNotUpdatableEntity( + "another modified data", + "constant data 1", + "constant data 2", + id + ); + Assert.assertEquals( ver3, getAuditReader().find( PropertyNotUpdatableEntity.class, id, 3 ) ); + } - @Test - public void testDeleteState() { - PropertyNotUpdatableEntity delete = new PropertyNotUpdatableEntity("another modified data", "constant data 1", "constant data 2", id); - List results = getAuditReader().createQuery().forRevisionsOfEntity(PropertyNotUpdatableEntity.class, true, true).getResultList(); - Assert.assertEquals(delete, results.get(3)); - } + @Test + public void testDeleteState() { + PropertyNotUpdatableEntity delete = new PropertyNotUpdatableEntity( + "another modified data", + "constant data 1", + "constant data 2", + id + ); + List results = getAuditReader().createQuery().forRevisionsOfEntity( + PropertyNotUpdatableEntity.class, + true, + true + ).getResultList(); + Assert.assertEquals( delete, results.get( 3 ) ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/BasicCollection.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/BasicCollection.java index ccb0c7a57f..85d2b8efc2 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/BasicCollection.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/BasicCollection.java @@ -23,165 +23,167 @@ */ package org.hibernate.envers.test.integration.onetomany; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.Set; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.onetomany.CollectionRefEdEntity; import org.hibernate.envers.test.entities.onetomany.CollectionRefIngEntity; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class BasicCollection extends BaseEnversJPAFunctionalTestCase { - private Integer ed1_id; - private Integer ed2_id; + private Integer ed1_id; + private Integer ed2_id; - private Integer ing1_id; - private Integer ing2_id; + private Integer ing1_id; + private Integer ing2_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { CollectionRefEdEntity.class, CollectionRefIngEntity.class }; - } + return new Class[] {CollectionRefEdEntity.class, CollectionRefIngEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - CollectionRefEdEntity ed1 = new CollectionRefEdEntity(1, "data_ed_1"); - CollectionRefEdEntity ed2 = new CollectionRefEdEntity(2, "data_ed_2"); + CollectionRefEdEntity ed1 = new CollectionRefEdEntity( 1, "data_ed_1" ); + CollectionRefEdEntity ed2 = new CollectionRefEdEntity( 2, "data_ed_2" ); - CollectionRefIngEntity ing1 = new CollectionRefIngEntity(3, "data_ing_1", ed1); - CollectionRefIngEntity ing2 = new CollectionRefIngEntity(4, "data_ing_2", ed1); + CollectionRefIngEntity ing1 = new CollectionRefIngEntity( 3, "data_ing_1", ed1 ); + CollectionRefIngEntity ing2 = new CollectionRefIngEntity( 4, "data_ing_2", ed1 ); - // Revision 1 - em.getTransaction().begin(); + // Revision 1 + em.getTransaction().begin(); - em.persist(ed1); - em.persist(ed2); + em.persist( ed1 ); + em.persist( ed2 ); - em.persist(ing1); - em.persist(ing2); + em.persist( ing1 ); + em.persist( ing2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); + // Revision 2 + em.getTransaction().begin(); - ing1 = em.find(CollectionRefIngEntity.class, ing1.getId()); - ed2 = em.find(CollectionRefEdEntity.class, ed2.getId()); + ing1 = em.find( CollectionRefIngEntity.class, ing1.getId() ); + ed2 = em.find( CollectionRefEdEntity.class, ed2.getId() ); - ing1.setReference(ed2); + ing1.setReference( ed2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 - em.getTransaction().begin(); + // Revision 3 + em.getTransaction().begin(); - ing2 = em.find(CollectionRefIngEntity.class, ing2.getId()); - ed2 = em.find(CollectionRefEdEntity.class, ed2.getId()); + ing2 = em.find( CollectionRefIngEntity.class, ing2.getId() ); + ed2 = em.find( CollectionRefEdEntity.class, ed2.getId() ); - ing2.setReference(ed2); + ing2.setReference( ed2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // + // - ed1_id = ed1.getId(); - ed2_id = ed2.getId(); + ed1_id = ed1.getId(); + ed2_id = ed2.getId(); - ing1_id = ing1.getId(); - ing2_id = ing2.getId(); - } + ing1_id = ing1.getId(); + ing2_id = ing2.getId(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2, 3).equals(getAuditReader().getRevisions(CollectionRefEdEntity.class, ed1_id)); - assert Arrays.asList(1, 2, 3).equals(getAuditReader().getRevisions(CollectionRefEdEntity.class, ed2_id)); + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2, 3 ).equals( getAuditReader().getRevisions( CollectionRefEdEntity.class, ed1_id ) ); + assert Arrays.asList( 1, 2, 3 ).equals( getAuditReader().getRevisions( CollectionRefEdEntity.class, ed2_id ) ); - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(CollectionRefIngEntity.class, ing1_id)); - assert Arrays.asList(1, 3).equals(getAuditReader().getRevisions(CollectionRefIngEntity.class, ing2_id)); - } + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( CollectionRefIngEntity.class, ing1_id ) ); + assert Arrays.asList( 1, 3 ).equals( getAuditReader().getRevisions( CollectionRefIngEntity.class, ing2_id ) ); + } - private Set makeSet(T... objects) { - Set ret = new HashSet(); - //noinspection ManualArrayToCollectionCopy - for (T obj : objects) { ret.add(obj); } - return ret; - } + private Set makeSet(T... objects) { + Set ret = new HashSet(); + //noinspection ManualArrayToCollectionCopy + for ( T obj : objects ) { + ret.add( obj ); + } + return ret; + } - @Test - public void testHistoryOfEdId1() { - CollectionRefIngEntity ing1 = getEntityManager().find(CollectionRefIngEntity.class, ing1_id); - CollectionRefIngEntity ing2 = getEntityManager().find(CollectionRefIngEntity.class, ing2_id); + @Test + public void testHistoryOfEdId1() { + CollectionRefIngEntity ing1 = getEntityManager().find( CollectionRefIngEntity.class, ing1_id ); + CollectionRefIngEntity ing2 = getEntityManager().find( CollectionRefIngEntity.class, ing2_id ); - CollectionRefEdEntity rev1 = getAuditReader().find(CollectionRefEdEntity.class, ed1_id, 1); - CollectionRefEdEntity rev2 = getAuditReader().find(CollectionRefEdEntity.class, ed1_id, 2); - CollectionRefEdEntity rev3 = getAuditReader().find(CollectionRefEdEntity.class, ed1_id, 3); + CollectionRefEdEntity rev1 = getAuditReader().find( CollectionRefEdEntity.class, ed1_id, 1 ); + CollectionRefEdEntity rev2 = getAuditReader().find( CollectionRefEdEntity.class, ed1_id, 2 ); + CollectionRefEdEntity rev3 = getAuditReader().find( CollectionRefEdEntity.class, ed1_id, 3 ); - assert rev1.getReffering().containsAll(makeSet(ing1, ing2)); - assert rev1.getReffering().size() == 2; + assert rev1.getReffering().containsAll( makeSet( ing1, ing2 ) ); + assert rev1.getReffering().size() == 2; - assert rev2.getReffering().containsAll(makeSet(ing2)); - assert rev2.getReffering().size() == 1; + assert rev2.getReffering().containsAll( makeSet( ing2 ) ); + assert rev2.getReffering().size() == 1; - assert rev3.getReffering().containsAll(Collections.EMPTY_SET); - assert rev3.getReffering().size() == 0; - } + assert rev3.getReffering().containsAll( Collections.EMPTY_SET ); + assert rev3.getReffering().size() == 0; + } - @Test - public void testHistoryOfEdId2() { - CollectionRefIngEntity ing1 = getEntityManager().find(CollectionRefIngEntity.class, ing1_id); - CollectionRefIngEntity ing2 = getEntityManager().find(CollectionRefIngEntity.class, ing2_id); + @Test + public void testHistoryOfEdId2() { + CollectionRefIngEntity ing1 = getEntityManager().find( CollectionRefIngEntity.class, ing1_id ); + CollectionRefIngEntity ing2 = getEntityManager().find( CollectionRefIngEntity.class, ing2_id ); - CollectionRefEdEntity rev1 = getAuditReader().find(CollectionRefEdEntity.class, ed2_id, 1); - CollectionRefEdEntity rev2 = getAuditReader().find(CollectionRefEdEntity.class, ed2_id, 2); - CollectionRefEdEntity rev3 = getAuditReader().find(CollectionRefEdEntity.class, ed2_id, 3); + CollectionRefEdEntity rev1 = getAuditReader().find( CollectionRefEdEntity.class, ed2_id, 1 ); + CollectionRefEdEntity rev2 = getAuditReader().find( CollectionRefEdEntity.class, ed2_id, 2 ); + CollectionRefEdEntity rev3 = getAuditReader().find( CollectionRefEdEntity.class, ed2_id, 3 ); - assert rev1.getReffering().containsAll(Collections.EMPTY_SET); - assert rev1.getReffering().size() == 0; + assert rev1.getReffering().containsAll( Collections.EMPTY_SET ); + assert rev1.getReffering().size() == 0; - assert rev2.getReffering().containsAll(makeSet(ing1)); - assert rev2.getReffering().size() == 1; + assert rev2.getReffering().containsAll( makeSet( ing1 ) ); + assert rev2.getReffering().size() == 1; - assert rev3.getReffering().containsAll(makeSet(ing1, ing2)); - assert rev3.getReffering().size() == 2; + assert rev3.getReffering().containsAll( makeSet( ing1, ing2 ) ); + assert rev3.getReffering().size() == 2; - } + } - @Test - public void testHistoryOfEdIng1() { - CollectionRefEdEntity ed1 = getEntityManager().find(CollectionRefEdEntity.class, ed1_id); - CollectionRefEdEntity ed2 = getEntityManager().find(CollectionRefEdEntity.class, ed2_id); + @Test + public void testHistoryOfEdIng1() { + CollectionRefEdEntity ed1 = getEntityManager().find( CollectionRefEdEntity.class, ed1_id ); + CollectionRefEdEntity ed2 = getEntityManager().find( CollectionRefEdEntity.class, ed2_id ); - CollectionRefIngEntity rev1 = getAuditReader().find(CollectionRefIngEntity.class, ing1_id, 1); - CollectionRefIngEntity rev2 = getAuditReader().find(CollectionRefIngEntity.class, ing1_id, 2); - CollectionRefIngEntity rev3 = getAuditReader().find(CollectionRefIngEntity.class, ing1_id, 3); + CollectionRefIngEntity rev1 = getAuditReader().find( CollectionRefIngEntity.class, ing1_id, 1 ); + CollectionRefIngEntity rev2 = getAuditReader().find( CollectionRefIngEntity.class, ing1_id, 2 ); + CollectionRefIngEntity rev3 = getAuditReader().find( CollectionRefIngEntity.class, ing1_id, 3 ); - assert rev1.getReference().equals(ed1); - assert rev2.getReference().equals(ed2); - assert rev3.getReference().equals(ed2); - } + assert rev1.getReference().equals( ed1 ); + assert rev2.getReference().equals( ed2 ); + assert rev3.getReference().equals( ed2 ); + } - @Test - public void testHistoryOfEdIng2() { - CollectionRefEdEntity ed1 = getEntityManager().find(CollectionRefEdEntity.class, ed1_id); - CollectionRefEdEntity ed2 = getEntityManager().find(CollectionRefEdEntity.class, ed2_id); + @Test + public void testHistoryOfEdIng2() { + CollectionRefEdEntity ed1 = getEntityManager().find( CollectionRefEdEntity.class, ed1_id ); + CollectionRefEdEntity ed2 = getEntityManager().find( CollectionRefEdEntity.class, ed2_id ); - CollectionRefIngEntity rev1 = getAuditReader().find(CollectionRefIngEntity.class, ing2_id, 1); - CollectionRefIngEntity rev2 = getAuditReader().find(CollectionRefIngEntity.class, ing2_id, 2); - CollectionRefIngEntity rev3 = getAuditReader().find(CollectionRefIngEntity.class, ing2_id, 3); + CollectionRefIngEntity rev1 = getAuditReader().find( CollectionRefIngEntity.class, ing2_id, 1 ); + CollectionRefIngEntity rev2 = getAuditReader().find( CollectionRefIngEntity.class, ing2_id, 2 ); + CollectionRefIngEntity rev3 = getAuditReader().find( CollectionRefIngEntity.class, ing2_id, 3 ); - assert rev1.getReference().equals(ed1); - assert rev2.getReference().equals(ed1); - assert rev3.getReference().equals(ed2); - } + assert rev1.getReference().equals( ed1 ); + assert rev2.getReference().equals( ed1 ); + assert rev3.getReference().equals( ed2 ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/BasicList.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/BasicList.java index e2ae66a345..267e5e191e 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/BasicList.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/BasicList.java @@ -23,10 +23,8 @@ */ package org.hibernate.envers.test.integration.onetomany; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; @@ -34,133 +32,136 @@ import org.hibernate.envers.test.entities.onetomany.ListRefEdEntity; import org.hibernate.envers.test.entities.onetomany.ListRefIngEntity; import org.hibernate.envers.test.tools.TestTools; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ -public class BasicList extends BaseEnversJPAFunctionalTestCase { - private Integer ed1_id; - private Integer ed2_id; +public class BasicList extends BaseEnversJPAFunctionalTestCase { + private Integer ed1_id; + private Integer ed2_id; - private Integer ing1_id; - private Integer ing2_id; + private Integer ing1_id; + private Integer ing2_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { ListRefEdEntity.class, ListRefIngEntity.class }; - } + return new Class[] {ListRefEdEntity.class, ListRefIngEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - ListRefEdEntity ed1 = new ListRefEdEntity(1, "data_ed_1"); - ListRefEdEntity ed2 = new ListRefEdEntity(2, "data_ed_2"); + ListRefEdEntity ed1 = new ListRefEdEntity( 1, "data_ed_1" ); + ListRefEdEntity ed2 = new ListRefEdEntity( 2, "data_ed_2" ); - ListRefIngEntity ing1 = new ListRefIngEntity(3, "data_ing_1", ed1); - ListRefIngEntity ing2 = new ListRefIngEntity(4, "data_ing_2", ed1); + ListRefIngEntity ing1 = new ListRefIngEntity( 3, "data_ing_1", ed1 ); + ListRefIngEntity ing2 = new ListRefIngEntity( 4, "data_ing_2", ed1 ); - // Revision 1 - em.getTransaction().begin(); + // Revision 1 + em.getTransaction().begin(); - em.persist(ed1); - em.persist(ed2); + em.persist( ed1 ); + em.persist( ed2 ); - em.persist(ing1); - em.persist(ing2); + em.persist( ing1 ); + em.persist( ing2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); + // Revision 2 + em.getTransaction().begin(); - ing1 = em.find(ListRefIngEntity.class, ing1.getId()); - ed2 = em.find(ListRefEdEntity.class, ed2.getId()); + ing1 = em.find( ListRefIngEntity.class, ing1.getId() ); + ed2 = em.find( ListRefEdEntity.class, ed2.getId() ); - ing1.setReference(ed2); + ing1.setReference( ed2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 - em.getTransaction().begin(); + // Revision 3 + em.getTransaction().begin(); - ing2 = em.find(ListRefIngEntity.class, ing2.getId()); - ed2 = em.find(ListRefEdEntity.class, ed2.getId()); + ing2 = em.find( ListRefIngEntity.class, ing2.getId() ); + ed2 = em.find( ListRefEdEntity.class, ed2.getId() ); - ing2.setReference(ed2); + ing2.setReference( ed2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // + // - ed1_id = ed1.getId(); - ed2_id = ed2.getId(); + ed1_id = ed1.getId(); + ed2_id = ed2.getId(); - ing1_id = ing1.getId(); - ing2_id = ing2.getId(); - } + ing1_id = ing1.getId(); + ing2_id = ing2.getId(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2, 3).equals(getAuditReader().getRevisions(ListRefEdEntity.class, ed1_id)); - assert Arrays.asList(1, 2, 3).equals(getAuditReader().getRevisions(ListRefEdEntity.class, ed2_id)); + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2, 3 ).equals( getAuditReader().getRevisions( ListRefEdEntity.class, ed1_id ) ); + assert Arrays.asList( 1, 2, 3 ).equals( getAuditReader().getRevisions( ListRefEdEntity.class, ed2_id ) ); - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(ListRefIngEntity.class, ing1_id)); - assert Arrays.asList(1, 3).equals(getAuditReader().getRevisions(ListRefIngEntity.class, ing2_id)); - } - @Test - public void testHistoryOfEdId1() { - ListRefIngEntity ing1 = getEntityManager().find(ListRefIngEntity.class, ing1_id); - ListRefIngEntity ing2 = getEntityManager().find(ListRefIngEntity.class, ing2_id); + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( ListRefIngEntity.class, ing1_id ) ); + assert Arrays.asList( 1, 3 ).equals( getAuditReader().getRevisions( ListRefIngEntity.class, ing2_id ) ); + } - ListRefEdEntity rev1 = getAuditReader().find(ListRefEdEntity.class, ed1_id, 1); - ListRefEdEntity rev2 = getAuditReader().find(ListRefEdEntity.class, ed1_id, 2); - ListRefEdEntity rev3 = getAuditReader().find(ListRefEdEntity.class, ed1_id, 3); + @Test + public void testHistoryOfEdId1() { + ListRefIngEntity ing1 = getEntityManager().find( ListRefIngEntity.class, ing1_id ); + ListRefIngEntity ing2 = getEntityManager().find( ListRefIngEntity.class, ing2_id ); - assert TestTools.checkList(rev1.getReffering(), ing1, ing2); - assert TestTools.checkList(rev2.getReffering(), ing2); - assert TestTools.checkList(rev3.getReffering()); - } + ListRefEdEntity rev1 = getAuditReader().find( ListRefEdEntity.class, ed1_id, 1 ); + ListRefEdEntity rev2 = getAuditReader().find( ListRefEdEntity.class, ed1_id, 2 ); + ListRefEdEntity rev3 = getAuditReader().find( ListRefEdEntity.class, ed1_id, 3 ); - @Test - public void testHistoryOfEdId2() { - ListRefIngEntity ing1 = getEntityManager().find(ListRefIngEntity.class, ing1_id); - ListRefIngEntity ing2 = getEntityManager().find(ListRefIngEntity.class, ing2_id); + assert TestTools.checkList( rev1.getReffering(), ing1, ing2 ); + assert TestTools.checkList( rev2.getReffering(), ing2 ); + assert TestTools.checkList( rev3.getReffering() ); + } - ListRefEdEntity rev1 = getAuditReader().find(ListRefEdEntity.class, ed2_id, 1); - ListRefEdEntity rev2 = getAuditReader().find(ListRefEdEntity.class, ed2_id, 2); - ListRefEdEntity rev3 = getAuditReader().find(ListRefEdEntity.class, ed2_id, 3); + @Test + public void testHistoryOfEdId2() { + ListRefIngEntity ing1 = getEntityManager().find( ListRefIngEntity.class, ing1_id ); + ListRefIngEntity ing2 = getEntityManager().find( ListRefIngEntity.class, ing2_id ); - assert TestTools.checkList(rev1.getReffering()); - assert TestTools.checkList(rev2.getReffering(), ing1); - assert TestTools.checkList(rev3.getReffering(), ing1, ing2); - } + ListRefEdEntity rev1 = getAuditReader().find( ListRefEdEntity.class, ed2_id, 1 ); + ListRefEdEntity rev2 = getAuditReader().find( ListRefEdEntity.class, ed2_id, 2 ); + ListRefEdEntity rev3 = getAuditReader().find( ListRefEdEntity.class, ed2_id, 3 ); - @Test - public void testHistoryOfEdIng1() { - ListRefEdEntity ed1 = getEntityManager().find(ListRefEdEntity.class, ed1_id); - ListRefEdEntity ed2 = getEntityManager().find(ListRefEdEntity.class, ed2_id); + assert TestTools.checkList( rev1.getReffering() ); + assert TestTools.checkList( rev2.getReffering(), ing1 ); + assert TestTools.checkList( rev3.getReffering(), ing1, ing2 ); + } - ListRefIngEntity rev1 = getAuditReader().find(ListRefIngEntity.class, ing1_id, 1); - ListRefIngEntity rev2 = getAuditReader().find(ListRefIngEntity.class, ing1_id, 2); - ListRefIngEntity rev3 = getAuditReader().find(ListRefIngEntity.class, ing1_id, 3); + @Test + public void testHistoryOfEdIng1() { + ListRefEdEntity ed1 = getEntityManager().find( ListRefEdEntity.class, ed1_id ); + ListRefEdEntity ed2 = getEntityManager().find( ListRefEdEntity.class, ed2_id ); - assert rev1.getReference().equals(ed1); - assert rev2.getReference().equals(ed2); - assert rev3.getReference().equals(ed2); - } + ListRefIngEntity rev1 = getAuditReader().find( ListRefIngEntity.class, ing1_id, 1 ); + ListRefIngEntity rev2 = getAuditReader().find( ListRefIngEntity.class, ing1_id, 2 ); + ListRefIngEntity rev3 = getAuditReader().find( ListRefIngEntity.class, ing1_id, 3 ); - @Test - public void testHistoryOfEdIng2() { - ListRefEdEntity ed1 = getEntityManager().find(ListRefEdEntity.class, ed1_id); - ListRefEdEntity ed2 = getEntityManager().find(ListRefEdEntity.class, ed2_id); + assert rev1.getReference().equals( ed1 ); + assert rev2.getReference().equals( ed2 ); + assert rev3.getReference().equals( ed2 ); + } - ListRefIngEntity rev1 = getAuditReader().find(ListRefIngEntity.class, ing2_id, 1); - ListRefIngEntity rev2 = getAuditReader().find(ListRefIngEntity.class, ing2_id, 2); - ListRefIngEntity rev3 = getAuditReader().find(ListRefIngEntity.class, ing2_id, 3); + @Test + public void testHistoryOfEdIng2() { + ListRefEdEntity ed1 = getEntityManager().find( ListRefEdEntity.class, ed1_id ); + ListRefEdEntity ed2 = getEntityManager().find( ListRefEdEntity.class, ed2_id ); - assert rev1.getReference().equals(ed1); - assert rev2.getReference().equals(ed1); - assert rev3.getReference().equals(ed2); - } + ListRefIngEntity rev1 = getAuditReader().find( ListRefIngEntity.class, ing2_id, 1 ); + ListRefIngEntity rev2 = getAuditReader().find( ListRefIngEntity.class, ing2_id, 2 ); + ListRefIngEntity rev3 = getAuditReader().find( ListRefIngEntity.class, ing2_id, 3 ); + + assert rev1.getReference().equals( ed1 ); + assert rev2.getReference().equals( ed1 ); + assert rev3.getReference().equals( ed2 ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/BasicSet.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/BasicSet.java index fe0d1e52d4..2c7a7ebfba 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/BasicSet.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/BasicSet.java @@ -23,11 +23,9 @@ */ package org.hibernate.envers.test.integration.onetomany; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.Collections; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; @@ -35,153 +33,155 @@ import org.hibernate.envers.test.entities.onetomany.SetRefEdEntity; import org.hibernate.envers.test.entities.onetomany.SetRefIngEntity; import org.hibernate.envers.test.tools.TestTools; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class BasicSet extends BaseEnversJPAFunctionalTestCase { - private Integer ed1_id; - private Integer ed2_id; + private Integer ed1_id; + private Integer ed2_id; - private Integer ing1_id; - private Integer ing2_id; + private Integer ing1_id; + private Integer ing2_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { SetRefEdEntity.class, SetRefIngEntity.class }; - } + return new Class[] {SetRefEdEntity.class, SetRefIngEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - SetRefEdEntity ed1 = new SetRefEdEntity(1, "data_ed_1"); - SetRefEdEntity ed2 = new SetRefEdEntity(2, "data_ed_2"); + SetRefEdEntity ed1 = new SetRefEdEntity( 1, "data_ed_1" ); + SetRefEdEntity ed2 = new SetRefEdEntity( 2, "data_ed_2" ); - SetRefIngEntity ing1 = new SetRefIngEntity(3, "data_ing_1"); - SetRefIngEntity ing2 = new SetRefIngEntity(4, "data_ing_2"); + SetRefIngEntity ing1 = new SetRefIngEntity( 3, "data_ing_1" ); + SetRefIngEntity ing2 = new SetRefIngEntity( 4, "data_ing_2" ); - // Revision 1 - em.getTransaction().begin(); + // Revision 1 + em.getTransaction().begin(); - em.persist(ed1); - em.persist(ed2); + em.persist( ed1 ); + em.persist( ed2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 + // Revision 2 - em.getTransaction().begin(); + em.getTransaction().begin(); - ed1 = em.find(SetRefEdEntity.class, ed1.getId()); + ed1 = em.find( SetRefEdEntity.class, ed1.getId() ); - ing1.setReference(ed1); - ing2.setReference(ed1); + ing1.setReference( ed1 ); + ing2.setReference( ed1 ); - em.persist(ing1); - em.persist(ing2); + em.persist( ing1 ); + em.persist( ing2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 - em.getTransaction().begin(); + // Revision 3 + em.getTransaction().begin(); - ing1 = em.find(SetRefIngEntity.class, ing1.getId()); - ed2 = em.find(SetRefEdEntity.class, ed2.getId()); + ing1 = em.find( SetRefIngEntity.class, ing1.getId() ); + ed2 = em.find( SetRefEdEntity.class, ed2.getId() ); - ing1.setReference(ed2); + ing1.setReference( ed2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 4 - em.getTransaction().begin(); + // Revision 4 + em.getTransaction().begin(); - ing2 = em.find(SetRefIngEntity.class, ing2.getId()); - ed2 = em.find(SetRefEdEntity.class, ed2.getId()); + ing2 = em.find( SetRefIngEntity.class, ing2.getId() ); + ed2 = em.find( SetRefEdEntity.class, ed2.getId() ); - ing2.setReference(ed2); + ing2.setReference( ed2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // + // - ed1_id = ed1.getId(); - ed2_id = ed2.getId(); + ed1_id = ed1.getId(); + ed2_id = ed2.getId(); - ing1_id = ing1.getId(); - ing2_id = ing2.getId(); - } + ing1_id = ing1.getId(); + ing2_id = ing2.getId(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2, 3, 4).equals(getAuditReader().getRevisions(SetRefEdEntity.class, ed1_id)); - assert Arrays.asList(1, 3, 4).equals(getAuditReader().getRevisions(SetRefEdEntity.class, ed2_id)); + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2, 3, 4 ).equals( getAuditReader().getRevisions( SetRefEdEntity.class, ed1_id ) ); + assert Arrays.asList( 1, 3, 4 ).equals( getAuditReader().getRevisions( SetRefEdEntity.class, ed2_id ) ); - assert Arrays.asList(2, 3).equals(getAuditReader().getRevisions(SetRefIngEntity.class, ing1_id)); - assert Arrays.asList(2, 4).equals(getAuditReader().getRevisions(SetRefIngEntity.class, ing2_id)); - } + assert Arrays.asList( 2, 3 ).equals( getAuditReader().getRevisions( SetRefIngEntity.class, ing1_id ) ); + assert Arrays.asList( 2, 4 ).equals( getAuditReader().getRevisions( SetRefIngEntity.class, ing2_id ) ); + } - @Test - public void testHistoryOfEdId1() { - SetRefIngEntity ing1 = getEntityManager().find(SetRefIngEntity.class, ing1_id); - SetRefIngEntity ing2 = getEntityManager().find(SetRefIngEntity.class, ing2_id); + @Test + public void testHistoryOfEdId1() { + SetRefIngEntity ing1 = getEntityManager().find( SetRefIngEntity.class, ing1_id ); + SetRefIngEntity ing2 = getEntityManager().find( SetRefIngEntity.class, ing2_id ); - SetRefEdEntity rev1 = getAuditReader().find(SetRefEdEntity.class, ed1_id, 1); - SetRefEdEntity rev2 = getAuditReader().find(SetRefEdEntity.class, ed1_id, 2); - SetRefEdEntity rev3 = getAuditReader().find(SetRefEdEntity.class, ed1_id, 3); - SetRefEdEntity rev4 = getAuditReader().find(SetRefEdEntity.class, ed1_id, 4); + SetRefEdEntity rev1 = getAuditReader().find( SetRefEdEntity.class, ed1_id, 1 ); + SetRefEdEntity rev2 = getAuditReader().find( SetRefEdEntity.class, ed1_id, 2 ); + SetRefEdEntity rev3 = getAuditReader().find( SetRefEdEntity.class, ed1_id, 3 ); + SetRefEdEntity rev4 = getAuditReader().find( SetRefEdEntity.class, ed1_id, 4 ); - assert rev1.getReffering().equals(Collections.EMPTY_SET); - assert rev2.getReffering().equals(TestTools.makeSet(ing1, ing2)); - assert rev3.getReffering().equals(TestTools.makeSet(ing2)); - assert rev4.getReffering().equals(Collections.EMPTY_SET); - } + assert rev1.getReffering().equals( Collections.EMPTY_SET ); + assert rev2.getReffering().equals( TestTools.makeSet( ing1, ing2 ) ); + assert rev3.getReffering().equals( TestTools.makeSet( ing2 ) ); + assert rev4.getReffering().equals( Collections.EMPTY_SET ); + } - @Test - public void testHistoryOfEdId2() { - SetRefIngEntity ing1 = getEntityManager().find(SetRefIngEntity.class, ing1_id); - SetRefIngEntity ing2 = getEntityManager().find(SetRefIngEntity.class, ing2_id); + @Test + public void testHistoryOfEdId2() { + SetRefIngEntity ing1 = getEntityManager().find( SetRefIngEntity.class, ing1_id ); + SetRefIngEntity ing2 = getEntityManager().find( SetRefIngEntity.class, ing2_id ); - SetRefEdEntity rev1 = getAuditReader().find(SetRefEdEntity.class, ed2_id, 1); - SetRefEdEntity rev2 = getAuditReader().find(SetRefEdEntity.class, ed2_id, 2); - SetRefEdEntity rev3 = getAuditReader().find(SetRefEdEntity.class, ed2_id, 3); - SetRefEdEntity rev4 = getAuditReader().find(SetRefEdEntity.class, ed2_id, 4); + SetRefEdEntity rev1 = getAuditReader().find( SetRefEdEntity.class, ed2_id, 1 ); + SetRefEdEntity rev2 = getAuditReader().find( SetRefEdEntity.class, ed2_id, 2 ); + SetRefEdEntity rev3 = getAuditReader().find( SetRefEdEntity.class, ed2_id, 3 ); + SetRefEdEntity rev4 = getAuditReader().find( SetRefEdEntity.class, ed2_id, 4 ); - assert rev1.getReffering().equals(Collections.EMPTY_SET); - assert rev2.getReffering().equals(Collections.EMPTY_SET); - assert rev3.getReffering().equals(TestTools.makeSet(ing1)); - assert rev4.getReffering().equals(TestTools.makeSet(ing1, ing2)); - } + assert rev1.getReffering().equals( Collections.EMPTY_SET ); + assert rev2.getReffering().equals( Collections.EMPTY_SET ); + assert rev3.getReffering().equals( TestTools.makeSet( ing1 ) ); + assert rev4.getReffering().equals( TestTools.makeSet( ing1, ing2 ) ); + } - @Test - public void testHistoryOfEdIng1() { - SetRefEdEntity ed1 = getEntityManager().find(SetRefEdEntity.class, ed1_id); - SetRefEdEntity ed2 = getEntityManager().find(SetRefEdEntity.class, ed2_id); + @Test + public void testHistoryOfEdIng1() { + SetRefEdEntity ed1 = getEntityManager().find( SetRefEdEntity.class, ed1_id ); + SetRefEdEntity ed2 = getEntityManager().find( SetRefEdEntity.class, ed2_id ); - SetRefIngEntity rev1 = getAuditReader().find(SetRefIngEntity.class, ing1_id, 1); - SetRefIngEntity rev2 = getAuditReader().find(SetRefIngEntity.class, ing1_id, 2); - SetRefIngEntity rev3 = getAuditReader().find(SetRefIngEntity.class, ing1_id, 3); - SetRefIngEntity rev4 = getAuditReader().find(SetRefIngEntity.class, ing1_id, 4); + SetRefIngEntity rev1 = getAuditReader().find( SetRefIngEntity.class, ing1_id, 1 ); + SetRefIngEntity rev2 = getAuditReader().find( SetRefIngEntity.class, ing1_id, 2 ); + SetRefIngEntity rev3 = getAuditReader().find( SetRefIngEntity.class, ing1_id, 3 ); + SetRefIngEntity rev4 = getAuditReader().find( SetRefIngEntity.class, ing1_id, 4 ); - assert rev1 == null; - assert rev2.getReference().equals(ed1); - assert rev3.getReference().equals(ed2); - assert rev4.getReference().equals(ed2); - } + assert rev1 == null; + assert rev2.getReference().equals( ed1 ); + assert rev3.getReference().equals( ed2 ); + assert rev4.getReference().equals( ed2 ); + } - @Test - public void testHistoryOfEdIng2() { - SetRefEdEntity ed1 = getEntityManager().find(SetRefEdEntity.class, ed1_id); - SetRefEdEntity ed2 = getEntityManager().find(SetRefEdEntity.class, ed2_id); + @Test + public void testHistoryOfEdIng2() { + SetRefEdEntity ed1 = getEntityManager().find( SetRefEdEntity.class, ed1_id ); + SetRefEdEntity ed2 = getEntityManager().find( SetRefEdEntity.class, ed2_id ); - SetRefIngEntity rev1 = getAuditReader().find(SetRefIngEntity.class, ing2_id, 1); - SetRefIngEntity rev2 = getAuditReader().find(SetRefIngEntity.class, ing2_id, 2); - SetRefIngEntity rev3 = getAuditReader().find(SetRefIngEntity.class, ing2_id, 3); - SetRefIngEntity rev4 = getAuditReader().find(SetRefIngEntity.class, ing2_id, 4); + SetRefIngEntity rev1 = getAuditReader().find( SetRefIngEntity.class, ing2_id, 1 ); + SetRefIngEntity rev2 = getAuditReader().find( SetRefIngEntity.class, ing2_id, 2 ); + SetRefIngEntity rev3 = getAuditReader().find( SetRefIngEntity.class, ing2_id, 3 ); + SetRefIngEntity rev4 = getAuditReader().find( SetRefIngEntity.class, ing2_id, 4 ); - assert rev1 == null; - assert rev2.getReference().equals(ed1); - assert rev3.getReference().equals(ed1); - assert rev4.getReference().equals(ed2); - } + assert rev1 == null; + assert rev2.getReference().equals( ed1 ); + assert rev3.getReference().equals( ed1 ); + assert rev4.getReference().equals( ed2 ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/BasicSetWithEmbId.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/BasicSetWithEmbId.java index 375b69afed..af713707f4 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/BasicSetWithEmbId.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/BasicSetWithEmbId.java @@ -23,13 +23,11 @@ */ package org.hibernate.envers.test.integration.onetomany; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.Set; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; @@ -37,139 +35,143 @@ import org.hibernate.envers.test.entities.ids.EmbId; import org.hibernate.envers.test.entities.onetomany.ids.SetRefEdEmbIdEntity; import org.hibernate.envers.test.entities.onetomany.ids.SetRefIngEmbIdEntity; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class BasicSetWithEmbId extends BaseEnversJPAFunctionalTestCase { - private EmbId ed1_id; - private EmbId ed2_id; + private EmbId ed1_id; + private EmbId ed2_id; - private EmbId ing1_id; - private EmbId ing2_id; + private EmbId ing1_id; + private EmbId ing2_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { SetRefEdEmbIdEntity.class, SetRefIngEmbIdEntity.class }; - } + return new Class[] {SetRefEdEmbIdEntity.class, SetRefIngEmbIdEntity.class}; + } - @Test - @Priority(10) - public void initData() { - ed1_id = new EmbId(0, 1); - ed2_id = new EmbId(2, 3); + @Test + @Priority(10) + public void initData() { + ed1_id = new EmbId( 0, 1 ); + ed2_id = new EmbId( 2, 3 ); - ing2_id = new EmbId(4, 5); - ing1_id = new EmbId(6, 7); + ing2_id = new EmbId( 4, 5 ); + ing1_id = new EmbId( 6, 7 ); - EntityManager em = getEntityManager(); + EntityManager em = getEntityManager(); - SetRefEdEmbIdEntity ed1 = new SetRefEdEmbIdEntity(ed1_id, "data_ed_1"); - SetRefEdEmbIdEntity ed2 = new SetRefEdEmbIdEntity(ed2_id, "data_ed_2"); + SetRefEdEmbIdEntity ed1 = new SetRefEdEmbIdEntity( ed1_id, "data_ed_1" ); + SetRefEdEmbIdEntity ed2 = new SetRefEdEmbIdEntity( ed2_id, "data_ed_2" ); - SetRefIngEmbIdEntity ing1 = new SetRefIngEmbIdEntity(ing1_id, "data_ing_1", ed1); - SetRefIngEmbIdEntity ing2 = new SetRefIngEmbIdEntity(ing2_id, "data_ing_2", ed1); + SetRefIngEmbIdEntity ing1 = new SetRefIngEmbIdEntity( ing1_id, "data_ing_1", ed1 ); + SetRefIngEmbIdEntity ing2 = new SetRefIngEmbIdEntity( ing2_id, "data_ing_2", ed1 ); - // Revision 1 - em.getTransaction().begin(); + // Revision 1 + em.getTransaction().begin(); - em.persist(ed1); - em.persist(ed2); + em.persist( ed1 ); + em.persist( ed2 ); - em.persist(ing1); - em.persist(ing2); + em.persist( ing1 ); + em.persist( ing2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); + // Revision 2 + em.getTransaction().begin(); - ing1 = em.find(SetRefIngEmbIdEntity.class, ing1.getId()); - ed2 = em.find(SetRefEdEmbIdEntity.class, ed2.getId()); + ing1 = em.find( SetRefIngEmbIdEntity.class, ing1.getId() ); + ed2 = em.find( SetRefEdEmbIdEntity.class, ed2.getId() ); - ing1.setReference(ed2); + ing1.setReference( ed2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 - em.getTransaction().begin(); + // Revision 3 + em.getTransaction().begin(); - ing2 = em.find(SetRefIngEmbIdEntity.class, ing2.getId()); - ed2 = em.find(SetRefEdEmbIdEntity.class, ed2.getId()); + ing2 = em.find( SetRefIngEmbIdEntity.class, ing2.getId() ); + ed2 = em.find( SetRefEdEmbIdEntity.class, ed2.getId() ); - ing2.setReference(ed2); + ing2.setReference( ed2 ); - em.getTransaction().commit(); - } + em.getTransaction().commit(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2, 3).equals(getAuditReader().getRevisions(SetRefEdEmbIdEntity.class, ed1_id)); - assert Arrays.asList(1, 2, 3).equals(getAuditReader().getRevisions(SetRefEdEmbIdEntity.class, ed2_id)); + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2, 3 ).equals( getAuditReader().getRevisions( SetRefEdEmbIdEntity.class, ed1_id ) ); + assert Arrays.asList( 1, 2, 3 ).equals( getAuditReader().getRevisions( SetRefEdEmbIdEntity.class, ed2_id ) ); - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(SetRefIngEmbIdEntity.class, ing1_id)); - assert Arrays.asList(1, 3).equals(getAuditReader().getRevisions(SetRefIngEmbIdEntity.class, ing2_id)); - } + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( SetRefIngEmbIdEntity.class, ing1_id ) ); + assert Arrays.asList( 1, 3 ).equals( getAuditReader().getRevisions( SetRefIngEmbIdEntity.class, ing2_id ) ); + } - private Set makeSet(T... objects) { - Set ret = new HashSet(); - //noinspection ManualArrayToCollectionCopy - for (T obj : objects) { ret.add(obj); } - return ret; - } + private Set makeSet(T... objects) { + Set ret = new HashSet(); + //noinspection ManualArrayToCollectionCopy + for ( T obj : objects ) { + ret.add( obj ); + } + return ret; + } - @Test - public void testHistoryOfEdId1() { - SetRefIngEmbIdEntity ing1 = getEntityManager().find(SetRefIngEmbIdEntity.class, ing1_id); - SetRefIngEmbIdEntity ing2 = getEntityManager().find(SetRefIngEmbIdEntity.class, ing2_id); + @Test + public void testHistoryOfEdId1() { + SetRefIngEmbIdEntity ing1 = getEntityManager().find( SetRefIngEmbIdEntity.class, ing1_id ); + SetRefIngEmbIdEntity ing2 = getEntityManager().find( SetRefIngEmbIdEntity.class, ing2_id ); - SetRefEdEmbIdEntity rev1 = getAuditReader().find(SetRefEdEmbIdEntity.class, ed1_id, 1); - SetRefEdEmbIdEntity rev2 = getAuditReader().find(SetRefEdEmbIdEntity.class, ed1_id, 2); - SetRefEdEmbIdEntity rev3 = getAuditReader().find(SetRefEdEmbIdEntity.class, ed1_id, 3); + SetRefEdEmbIdEntity rev1 = getAuditReader().find( SetRefEdEmbIdEntity.class, ed1_id, 1 ); + SetRefEdEmbIdEntity rev2 = getAuditReader().find( SetRefEdEmbIdEntity.class, ed1_id, 2 ); + SetRefEdEmbIdEntity rev3 = getAuditReader().find( SetRefEdEmbIdEntity.class, ed1_id, 3 ); - assert rev1.getReffering().equals(makeSet(ing1, ing2)); - assert rev2.getReffering().equals(makeSet(ing2)); - assert rev3.getReffering().equals(Collections.EMPTY_SET); - } + assert rev1.getReffering().equals( makeSet( ing1, ing2 ) ); + assert rev2.getReffering().equals( makeSet( ing2 ) ); + assert rev3.getReffering().equals( Collections.EMPTY_SET ); + } - @Test - public void testHistoryOfEdId2() { - SetRefIngEmbIdEntity ing1 = getEntityManager().find(SetRefIngEmbIdEntity.class, ing1_id); - SetRefIngEmbIdEntity ing2 = getEntityManager().find(SetRefIngEmbIdEntity.class, ing2_id); + @Test + public void testHistoryOfEdId2() { + SetRefIngEmbIdEntity ing1 = getEntityManager().find( SetRefIngEmbIdEntity.class, ing1_id ); + SetRefIngEmbIdEntity ing2 = getEntityManager().find( SetRefIngEmbIdEntity.class, ing2_id ); - SetRefEdEmbIdEntity rev1 = getAuditReader().find(SetRefEdEmbIdEntity.class, ed2_id, 1); - SetRefEdEmbIdEntity rev2 = getAuditReader().find(SetRefEdEmbIdEntity.class, ed2_id, 2); - SetRefEdEmbIdEntity rev3 = getAuditReader().find(SetRefEdEmbIdEntity.class, ed2_id, 3); + SetRefEdEmbIdEntity rev1 = getAuditReader().find( SetRefEdEmbIdEntity.class, ed2_id, 1 ); + SetRefEdEmbIdEntity rev2 = getAuditReader().find( SetRefEdEmbIdEntity.class, ed2_id, 2 ); + SetRefEdEmbIdEntity rev3 = getAuditReader().find( SetRefEdEmbIdEntity.class, ed2_id, 3 ); - assert rev1.getReffering().equals(Collections.EMPTY_SET); - assert rev2.getReffering().equals(makeSet(ing1)); - assert rev3.getReffering().equals(makeSet(ing1, ing2)); - } + assert rev1.getReffering().equals( Collections.EMPTY_SET ); + assert rev2.getReffering().equals( makeSet( ing1 ) ); + assert rev3.getReffering().equals( makeSet( ing1, ing2 ) ); + } - @Test - public void testHistoryOfEdIng1() { - SetRefEdEmbIdEntity ed1 = getEntityManager().find(SetRefEdEmbIdEntity.class, ed1_id); - SetRefEdEmbIdEntity ed2 = getEntityManager().find(SetRefEdEmbIdEntity.class, ed2_id); + @Test + public void testHistoryOfEdIng1() { + SetRefEdEmbIdEntity ed1 = getEntityManager().find( SetRefEdEmbIdEntity.class, ed1_id ); + SetRefEdEmbIdEntity ed2 = getEntityManager().find( SetRefEdEmbIdEntity.class, ed2_id ); - SetRefIngEmbIdEntity rev1 = getAuditReader().find(SetRefIngEmbIdEntity.class, ing1_id, 1); - SetRefIngEmbIdEntity rev2 = getAuditReader().find(SetRefIngEmbIdEntity.class, ing1_id, 2); - SetRefIngEmbIdEntity rev3 = getAuditReader().find(SetRefIngEmbIdEntity.class, ing1_id, 3); + SetRefIngEmbIdEntity rev1 = getAuditReader().find( SetRefIngEmbIdEntity.class, ing1_id, 1 ); + SetRefIngEmbIdEntity rev2 = getAuditReader().find( SetRefIngEmbIdEntity.class, ing1_id, 2 ); + SetRefIngEmbIdEntity rev3 = getAuditReader().find( SetRefIngEmbIdEntity.class, ing1_id, 3 ); - assert rev1.getReference().equals(ed1); - assert rev2.getReference().equals(ed2); - assert rev3.getReference().equals(ed2); - } + assert rev1.getReference().equals( ed1 ); + assert rev2.getReference().equals( ed2 ); + assert rev3.getReference().equals( ed2 ); + } - @Test - public void testHistoryOfEdIng2() { - SetRefEdEmbIdEntity ed1 = getEntityManager().find(SetRefEdEmbIdEntity.class, ed1_id); - SetRefEdEmbIdEntity ed2 = getEntityManager().find(SetRefEdEmbIdEntity.class, ed2_id); + @Test + public void testHistoryOfEdIng2() { + SetRefEdEmbIdEntity ed1 = getEntityManager().find( SetRefEdEmbIdEntity.class, ed1_id ); + SetRefEdEmbIdEntity ed2 = getEntityManager().find( SetRefEdEmbIdEntity.class, ed2_id ); - SetRefIngEmbIdEntity rev1 = getAuditReader().find(SetRefIngEmbIdEntity.class, ing2_id, 1); - SetRefIngEmbIdEntity rev2 = getAuditReader().find(SetRefIngEmbIdEntity.class, ing2_id, 2); - SetRefIngEmbIdEntity rev3 = getAuditReader().find(SetRefIngEmbIdEntity.class, ing2_id, 3); + SetRefIngEmbIdEntity rev1 = getAuditReader().find( SetRefIngEmbIdEntity.class, ing2_id, 1 ); + SetRefIngEmbIdEntity rev2 = getAuditReader().find( SetRefIngEmbIdEntity.class, ing2_id, 2 ); + SetRefIngEmbIdEntity rev3 = getAuditReader().find( SetRefIngEmbIdEntity.class, ing2_id, 3 ); - assert rev1.getReference().equals(ed1); - assert rev2.getReference().equals(ed1); - assert rev3.getReference().equals(ed2); - } + assert rev1.getReference().equals( ed1 ); + assert rev2.getReference().equals( ed1 ); + assert rev3.getReference().equals( ed2 ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/BasicSetWithMulId.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/BasicSetWithMulId.java index 61d1456f48..c2adab7ad1 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/BasicSetWithMulId.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/BasicSetWithMulId.java @@ -23,13 +23,11 @@ */ package org.hibernate.envers.test.integration.onetomany; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.Set; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; @@ -37,139 +35,143 @@ import org.hibernate.envers.test.entities.ids.MulId; import org.hibernate.envers.test.entities.onetomany.ids.SetRefEdMulIdEntity; import org.hibernate.envers.test.entities.onetomany.ids.SetRefIngMulIdEntity; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class BasicSetWithMulId extends BaseEnversJPAFunctionalTestCase { - private MulId ed1_id; - private MulId ed2_id; + private MulId ed1_id; + private MulId ed2_id; - private MulId ing1_id; - private MulId ing2_id; + private MulId ing1_id; + private MulId ing2_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { SetRefEdMulIdEntity.class, SetRefIngMulIdEntity.class }; - } + return new Class[] {SetRefEdMulIdEntity.class, SetRefIngMulIdEntity.class}; + } - @Test - @Priority(10) - public void initData() { - ed1_id = new MulId(0, 1); - ed2_id = new MulId(2, 3); + @Test + @Priority(10) + public void initData() { + ed1_id = new MulId( 0, 1 ); + ed2_id = new MulId( 2, 3 ); - ing2_id = new MulId(4, 5); - ing1_id = new MulId(6, 7); + ing2_id = new MulId( 4, 5 ); + ing1_id = new MulId( 6, 7 ); - EntityManager em = getEntityManager(); + EntityManager em = getEntityManager(); - SetRefEdMulIdEntity ed1 = new SetRefEdMulIdEntity(ed1_id.getId1(), ed1_id.getId2(), "data_ed_1"); - SetRefEdMulIdEntity ed2 = new SetRefEdMulIdEntity(ed2_id.getId1(), ed2_id.getId2(), "data_ed_2"); + SetRefEdMulIdEntity ed1 = new SetRefEdMulIdEntity( ed1_id.getId1(), ed1_id.getId2(), "data_ed_1" ); + SetRefEdMulIdEntity ed2 = new SetRefEdMulIdEntity( ed2_id.getId1(), ed2_id.getId2(), "data_ed_2" ); - SetRefIngMulIdEntity ing1 = new SetRefIngMulIdEntity(ing1_id.getId1(), ing1_id.getId2(), "data_ing_1", ed1); - SetRefIngMulIdEntity ing2 = new SetRefIngMulIdEntity(ing2_id.getId1(), ing2_id.getId2(), "data_ing_2", ed1); + SetRefIngMulIdEntity ing1 = new SetRefIngMulIdEntity( ing1_id.getId1(), ing1_id.getId2(), "data_ing_1", ed1 ); + SetRefIngMulIdEntity ing2 = new SetRefIngMulIdEntity( ing2_id.getId1(), ing2_id.getId2(), "data_ing_2", ed1 ); - // Revision 1 - em.getTransaction().begin(); + // Revision 1 + em.getTransaction().begin(); - em.persist(ed1); - em.persist(ed2); + em.persist( ed1 ); + em.persist( ed2 ); - em.persist(ing1); - em.persist(ing2); + em.persist( ing1 ); + em.persist( ing2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); + // Revision 2 + em.getTransaction().begin(); - ing1 = em.find(SetRefIngMulIdEntity.class, ing1_id); - ed2 = em.find(SetRefEdMulIdEntity.class, ed2_id); + ing1 = em.find( SetRefIngMulIdEntity.class, ing1_id ); + ed2 = em.find( SetRefEdMulIdEntity.class, ed2_id ); - ing1.setReference(ed2); + ing1.setReference( ed2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 - em.getTransaction().begin(); + // Revision 3 + em.getTransaction().begin(); - ing2 = em.find(SetRefIngMulIdEntity.class, ing2_id); - ed2 = em.find(SetRefEdMulIdEntity.class, ed2_id); + ing2 = em.find( SetRefIngMulIdEntity.class, ing2_id ); + ed2 = em.find( SetRefEdMulIdEntity.class, ed2_id ); - ing2.setReference(ed2); + ing2.setReference( ed2 ); - em.getTransaction().commit(); - } + em.getTransaction().commit(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2, 3).equals(getAuditReader().getRevisions(SetRefEdMulIdEntity.class, ed1_id)); - assert Arrays.asList(1, 2, 3).equals(getAuditReader().getRevisions(SetRefEdMulIdEntity.class, ed2_id)); + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2, 3 ).equals( getAuditReader().getRevisions( SetRefEdMulIdEntity.class, ed1_id ) ); + assert Arrays.asList( 1, 2, 3 ).equals( getAuditReader().getRevisions( SetRefEdMulIdEntity.class, ed2_id ) ); - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(SetRefIngMulIdEntity.class, ing1_id)); - assert Arrays.asList(1, 3).equals(getAuditReader().getRevisions(SetRefIngMulIdEntity.class, ing2_id)); - } + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( SetRefIngMulIdEntity.class, ing1_id ) ); + assert Arrays.asList( 1, 3 ).equals( getAuditReader().getRevisions( SetRefIngMulIdEntity.class, ing2_id ) ); + } - private Set makeSet(T... objects) { - Set ret = new HashSet(); - //noinspection ManualArrayToCollectionCopy - for (T obj : objects) { ret.add(obj); } - return ret; - } + private Set makeSet(T... objects) { + Set ret = new HashSet(); + //noinspection ManualArrayToCollectionCopy + for ( T obj : objects ) { + ret.add( obj ); + } + return ret; + } - @Test - public void testHistoryOfEdId1() { - SetRefIngMulIdEntity ing1 = getEntityManager().find(SetRefIngMulIdEntity.class, ing1_id); - SetRefIngMulIdEntity ing2 = getEntityManager().find(SetRefIngMulIdEntity.class, ing2_id); + @Test + public void testHistoryOfEdId1() { + SetRefIngMulIdEntity ing1 = getEntityManager().find( SetRefIngMulIdEntity.class, ing1_id ); + SetRefIngMulIdEntity ing2 = getEntityManager().find( SetRefIngMulIdEntity.class, ing2_id ); - SetRefEdMulIdEntity rev1 = getAuditReader().find(SetRefEdMulIdEntity.class, ed1_id, 1); - SetRefEdMulIdEntity rev2 = getAuditReader().find(SetRefEdMulIdEntity.class, ed1_id, 2); - SetRefEdMulIdEntity rev3 = getAuditReader().find(SetRefEdMulIdEntity.class, ed1_id, 3); + SetRefEdMulIdEntity rev1 = getAuditReader().find( SetRefEdMulIdEntity.class, ed1_id, 1 ); + SetRefEdMulIdEntity rev2 = getAuditReader().find( SetRefEdMulIdEntity.class, ed1_id, 2 ); + SetRefEdMulIdEntity rev3 = getAuditReader().find( SetRefEdMulIdEntity.class, ed1_id, 3 ); - assert rev1.getReffering().equals(makeSet(ing1, ing2)); - assert rev2.getReffering().equals(makeSet(ing2)); - assert rev3.getReffering().equals(Collections.EMPTY_SET); - } + assert rev1.getReffering().equals( makeSet( ing1, ing2 ) ); + assert rev2.getReffering().equals( makeSet( ing2 ) ); + assert rev3.getReffering().equals( Collections.EMPTY_SET ); + } - @Test - public void testHistoryOfEdId2() { - SetRefIngMulIdEntity ing1 = getEntityManager().find(SetRefIngMulIdEntity.class, ing1_id); - SetRefIngMulIdEntity ing2 = getEntityManager().find(SetRefIngMulIdEntity.class, ing2_id); + @Test + public void testHistoryOfEdId2() { + SetRefIngMulIdEntity ing1 = getEntityManager().find( SetRefIngMulIdEntity.class, ing1_id ); + SetRefIngMulIdEntity ing2 = getEntityManager().find( SetRefIngMulIdEntity.class, ing2_id ); - SetRefEdMulIdEntity rev1 = getAuditReader().find(SetRefEdMulIdEntity.class, ed2_id, 1); - SetRefEdMulIdEntity rev2 = getAuditReader().find(SetRefEdMulIdEntity.class, ed2_id, 2); - SetRefEdMulIdEntity rev3 = getAuditReader().find(SetRefEdMulIdEntity.class, ed2_id, 3); + SetRefEdMulIdEntity rev1 = getAuditReader().find( SetRefEdMulIdEntity.class, ed2_id, 1 ); + SetRefEdMulIdEntity rev2 = getAuditReader().find( SetRefEdMulIdEntity.class, ed2_id, 2 ); + SetRefEdMulIdEntity rev3 = getAuditReader().find( SetRefEdMulIdEntity.class, ed2_id, 3 ); - assert rev1.getReffering().equals(Collections.EMPTY_SET); - assert rev2.getReffering().equals(makeSet(ing1)); - assert rev3.getReffering().equals(makeSet(ing1, ing2)); - } + assert rev1.getReffering().equals( Collections.EMPTY_SET ); + assert rev2.getReffering().equals( makeSet( ing1 ) ); + assert rev3.getReffering().equals( makeSet( ing1, ing2 ) ); + } - @Test - public void testHistoryOfEdIng1() { - SetRefEdMulIdEntity ed1 = getEntityManager().find(SetRefEdMulIdEntity.class, ed1_id); - SetRefEdMulIdEntity ed2 = getEntityManager().find(SetRefEdMulIdEntity.class, ed2_id); + @Test + public void testHistoryOfEdIng1() { + SetRefEdMulIdEntity ed1 = getEntityManager().find( SetRefEdMulIdEntity.class, ed1_id ); + SetRefEdMulIdEntity ed2 = getEntityManager().find( SetRefEdMulIdEntity.class, ed2_id ); - SetRefIngMulIdEntity rev1 = getAuditReader().find(SetRefIngMulIdEntity.class, ing1_id, 1); - SetRefIngMulIdEntity rev2 = getAuditReader().find(SetRefIngMulIdEntity.class, ing1_id, 2); - SetRefIngMulIdEntity rev3 = getAuditReader().find(SetRefIngMulIdEntity.class, ing1_id, 3); + SetRefIngMulIdEntity rev1 = getAuditReader().find( SetRefIngMulIdEntity.class, ing1_id, 1 ); + SetRefIngMulIdEntity rev2 = getAuditReader().find( SetRefIngMulIdEntity.class, ing1_id, 2 ); + SetRefIngMulIdEntity rev3 = getAuditReader().find( SetRefIngMulIdEntity.class, ing1_id, 3 ); - assert rev1.getReference().equals(ed1); - assert rev2.getReference().equals(ed2); - assert rev3.getReference().equals(ed2); - } + assert rev1.getReference().equals( ed1 ); + assert rev2.getReference().equals( ed2 ); + assert rev3.getReference().equals( ed2 ); + } - @Test - public void testHistoryOfEdIng2() { - SetRefEdMulIdEntity ed1 = getEntityManager().find(SetRefEdMulIdEntity.class, ed1_id); - SetRefEdMulIdEntity ed2 = getEntityManager().find(SetRefEdMulIdEntity.class, ed2_id); + @Test + public void testHistoryOfEdIng2() { + SetRefEdMulIdEntity ed1 = getEntityManager().find( SetRefEdMulIdEntity.class, ed1_id ); + SetRefEdMulIdEntity ed2 = getEntityManager().find( SetRefEdMulIdEntity.class, ed2_id ); - SetRefIngMulIdEntity rev1 = getAuditReader().find(SetRefIngMulIdEntity.class, ing2_id, 1); - SetRefIngMulIdEntity rev2 = getAuditReader().find(SetRefIngMulIdEntity.class, ing2_id, 2); - SetRefIngMulIdEntity rev3 = getAuditReader().find(SetRefIngMulIdEntity.class, ing2_id, 3); + SetRefIngMulIdEntity rev1 = getAuditReader().find( SetRefIngMulIdEntity.class, ing2_id, 1 ); + SetRefIngMulIdEntity rev2 = getAuditReader().find( SetRefIngMulIdEntity.class, ing2_id, 2 ); + SetRefIngMulIdEntity rev3 = getAuditReader().find( SetRefIngMulIdEntity.class, ing2_id, 3 ); - assert rev1.getReference().equals(ed1); - assert rev2.getReference().equals(ed1); - assert rev3.getReference().equals(ed2); - } + assert rev1.getReference().equals( ed1 ); + assert rev2.getReference().equals( ed1 ); + assert rev3.getReference().equals( ed2 ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/BasicSetWithNullsDelete.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/BasicSetWithNullsDelete.java index d71ef643eb..c1aa3dc541 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/BasicSetWithNullsDelete.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/BasicSetWithNullsDelete.java @@ -23,229 +23,231 @@ */ package org.hibernate.envers.test.integration.onetomany; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.Set; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.onetomany.SetRefEdEntity; import org.hibernate.envers.test.entities.onetomany.SetRefIngEntity; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class BasicSetWithNullsDelete extends BaseEnversJPAFunctionalTestCase { - private Integer ed1_id; - private Integer ed2_id; + private Integer ed1_id; + private Integer ed2_id; - private Integer ing1_id; - private Integer ing2_id; - private Integer ing3_id; - private Integer ing4_id; + private Integer ing1_id; + private Integer ing2_id; + private Integer ing3_id; + private Integer ing4_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { SetRefEdEntity.class, SetRefIngEntity.class }; - } + return new Class[] {SetRefEdEntity.class, SetRefIngEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - SetRefEdEntity ed1 = new SetRefEdEntity(1, "data_ed_1"); - SetRefEdEntity ed2 = new SetRefEdEntity(2, "data_ed_2"); + SetRefEdEntity ed1 = new SetRefEdEntity( 1, "data_ed_1" ); + SetRefEdEntity ed2 = new SetRefEdEntity( 2, "data_ed_2" ); - SetRefIngEntity ing1 = new SetRefIngEntity(3, "data_ing_1", ed1); - SetRefIngEntity ing2 = new SetRefIngEntity(4, "data_ing_2", ed1); - SetRefIngEntity ing3 = new SetRefIngEntity(5, "data_ing_3", ed1); - SetRefIngEntity ing4 = new SetRefIngEntity(6, "data_ing_4", ed1); + SetRefIngEntity ing1 = new SetRefIngEntity( 3, "data_ing_1", ed1 ); + SetRefIngEntity ing2 = new SetRefIngEntity( 4, "data_ing_2", ed1 ); + SetRefIngEntity ing3 = new SetRefIngEntity( 5, "data_ing_3", ed1 ); + SetRefIngEntity ing4 = new SetRefIngEntity( 6, "data_ing_4", ed1 ); - // Revision 1 - em.getTransaction().begin(); + // Revision 1 + em.getTransaction().begin(); - em.persist(ed1); - em.persist(ed2); + em.persist( ed1 ); + em.persist( ed2 ); - em.persist(ing1); - em.persist(ing2); - em.persist(ing3); - em.persist(ing4); + em.persist( ing1 ); + em.persist( ing2 ); + em.persist( ing3 ); + em.persist( ing4 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); + // Revision 2 + em.getTransaction().begin(); - ing1 = em.find(SetRefIngEntity.class, ing1.getId()); + ing1 = em.find( SetRefIngEntity.class, ing1.getId() ); - ing1.setReference(null); + ing1.setReference( null ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 - em.getTransaction().begin(); + // Revision 3 + em.getTransaction().begin(); - ing2 = em.find(SetRefIngEntity.class, ing2.getId()); - em.remove(ing2); + ing2 = em.find( SetRefIngEntity.class, ing2.getId() ); + em.remove( ing2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 4 - em.getTransaction().begin(); + // Revision 4 + em.getTransaction().begin(); - ing3 = em.find(SetRefIngEntity.class, ing3.getId()); - ed2 = em.find(SetRefEdEntity.class, ed2.getId()); - ing3.setReference(ed2); + ing3 = em.find( SetRefIngEntity.class, ing3.getId() ); + ed2 = em.find( SetRefEdEntity.class, ed2.getId() ); + ing3.setReference( ed2 ); - em.getTransaction().commit(); - // Revision 5 - em.getTransaction().begin(); + em.getTransaction().commit(); + // Revision 5 + em.getTransaction().begin(); - ing4 = em.find(SetRefIngEntity.class, ing4.getId()); - ed1 = em.find(SetRefEdEntity.class, ed1.getId()); - em.remove(ed1); - ing4.setReference(null); + ing4 = em.find( SetRefIngEntity.class, ing4.getId() ); + ed1 = em.find( SetRefEdEntity.class, ed1.getId() ); + em.remove( ed1 ); + ing4.setReference( null ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // + // - ed1_id = ed1.getId(); - ed2_id = ed2.getId(); + ed1_id = ed1.getId(); + ed2_id = ed2.getId(); - ing1_id = ing1.getId(); - ing2_id = ing2.getId(); - ing3_id = ing3.getId(); - ing4_id = ing4.getId(); - } + ing1_id = ing1.getId(); + ing2_id = ing2.getId(); + ing3_id = ing3.getId(); + ing4_id = ing4.getId(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2, 3, 4, 5).equals(getAuditReader().getRevisions(SetRefEdEntity.class, ed1_id)); - assert Arrays.asList(1, 4).equals(getAuditReader().getRevisions(SetRefEdEntity.class, ed2_id)); + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2, 3, 4, 5 ).equals( getAuditReader().getRevisions( SetRefEdEntity.class, ed1_id ) ); + assert Arrays.asList( 1, 4 ).equals( getAuditReader().getRevisions( SetRefEdEntity.class, ed2_id ) ); - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(SetRefIngEntity.class, ing1_id)); - assert Arrays.asList(1, 3).equals(getAuditReader().getRevisions(SetRefIngEntity.class, ing2_id)); - assert Arrays.asList(1, 4).equals(getAuditReader().getRevisions(SetRefIngEntity.class, ing3_id)); - assert Arrays.asList(1, 5).equals(getAuditReader().getRevisions(SetRefIngEntity.class, ing4_id)); - } + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( SetRefIngEntity.class, ing1_id ) ); + assert Arrays.asList( 1, 3 ).equals( getAuditReader().getRevisions( SetRefIngEntity.class, ing2_id ) ); + assert Arrays.asList( 1, 4 ).equals( getAuditReader().getRevisions( SetRefIngEntity.class, ing3_id ) ); + assert Arrays.asList( 1, 5 ).equals( getAuditReader().getRevisions( SetRefIngEntity.class, ing4_id ) ); + } - private Set makeSet(T... objects) { - Set ret = new HashSet(); - //noinspection ManualArrayToCollectionCopy - for (T obj : objects) { ret.add(obj); } - return ret; - } + private Set makeSet(T... objects) { + Set ret = new HashSet(); + //noinspection ManualArrayToCollectionCopy + for ( T obj : objects ) { + ret.add( obj ); + } + return ret; + } - @Test - public void testHistoryOfEdId1() { - SetRefIngEntity ing1 = getEntityManager().find(SetRefIngEntity.class, ing1_id); - SetRefIngEntity ing2 = new SetRefIngEntity(4, "data_ing_2", new SetRefEdEntity(1, "data_ed_1")); - SetRefIngEntity ing3 = getEntityManager().find(SetRefIngEntity.class, ing3_id); - SetRefIngEntity ing4 = getEntityManager().find(SetRefIngEntity.class, ing4_id); + @Test + public void testHistoryOfEdId1() { + SetRefIngEntity ing1 = getEntityManager().find( SetRefIngEntity.class, ing1_id ); + SetRefIngEntity ing2 = new SetRefIngEntity( 4, "data_ing_2", new SetRefEdEntity( 1, "data_ed_1" ) ); + SetRefIngEntity ing3 = getEntityManager().find( SetRefIngEntity.class, ing3_id ); + SetRefIngEntity ing4 = getEntityManager().find( SetRefIngEntity.class, ing4_id ); - SetRefEdEntity rev1 = getAuditReader().find(SetRefEdEntity.class, ed1_id, 1); - SetRefEdEntity rev2 = getAuditReader().find(SetRefEdEntity.class, ed1_id, 2); - SetRefEdEntity rev3 = getAuditReader().find(SetRefEdEntity.class, ed1_id, 3); - SetRefEdEntity rev4 = getAuditReader().find(SetRefEdEntity.class, ed1_id, 4); - SetRefEdEntity rev5 = getAuditReader().find(SetRefEdEntity.class, ed1_id, 5); + SetRefEdEntity rev1 = getAuditReader().find( SetRefEdEntity.class, ed1_id, 1 ); + SetRefEdEntity rev2 = getAuditReader().find( SetRefEdEntity.class, ed1_id, 2 ); + SetRefEdEntity rev3 = getAuditReader().find( SetRefEdEntity.class, ed1_id, 3 ); + SetRefEdEntity rev4 = getAuditReader().find( SetRefEdEntity.class, ed1_id, 4 ); + SetRefEdEntity rev5 = getAuditReader().find( SetRefEdEntity.class, ed1_id, 5 ); - assert rev1.getReffering().equals(makeSet(ing1, ing2, ing3, ing4)); - assert rev2.getReffering().equals(makeSet(ing2, ing3, ing4)); - assert rev3.getReffering().equals(makeSet(ing3, ing4)); - assert rev4.getReffering().equals(makeSet(ing4)); - assert rev5 == null; - } + assert rev1.getReffering().equals( makeSet( ing1, ing2, ing3, ing4 ) ); + assert rev2.getReffering().equals( makeSet( ing2, ing3, ing4 ) ); + assert rev3.getReffering().equals( makeSet( ing3, ing4 ) ); + assert rev4.getReffering().equals( makeSet( ing4 ) ); + assert rev5 == null; + } - @Test - public void testHistoryOfEdId2() { - SetRefIngEntity ing3 = getEntityManager().find(SetRefIngEntity.class, ing3_id); + @Test + public void testHistoryOfEdId2() { + SetRefIngEntity ing3 = getEntityManager().find( SetRefIngEntity.class, ing3_id ); - SetRefEdEntity rev1 = getAuditReader().find(SetRefEdEntity.class, ed2_id, 1); - SetRefEdEntity rev2 = getAuditReader().find(SetRefEdEntity.class, ed2_id, 2); - SetRefEdEntity rev3 = getAuditReader().find(SetRefEdEntity.class, ed2_id, 3); - SetRefEdEntity rev4 = getAuditReader().find(SetRefEdEntity.class, ed2_id, 4); - SetRefEdEntity rev5 = getAuditReader().find(SetRefEdEntity.class, ed2_id, 5); + SetRefEdEntity rev1 = getAuditReader().find( SetRefEdEntity.class, ed2_id, 1 ); + SetRefEdEntity rev2 = getAuditReader().find( SetRefEdEntity.class, ed2_id, 2 ); + SetRefEdEntity rev3 = getAuditReader().find( SetRefEdEntity.class, ed2_id, 3 ); + SetRefEdEntity rev4 = getAuditReader().find( SetRefEdEntity.class, ed2_id, 4 ); + SetRefEdEntity rev5 = getAuditReader().find( SetRefEdEntity.class, ed2_id, 5 ); - assert rev1.getReffering().equals(Collections.EMPTY_SET); - assert rev2.getReffering().equals(Collections.EMPTY_SET); - assert rev3.getReffering().equals(Collections.EMPTY_SET); - assert rev4.getReffering().equals(makeSet(ing3)); - assert rev5.getReffering().equals(makeSet(ing3)); - } + assert rev1.getReffering().equals( Collections.EMPTY_SET ); + assert rev2.getReffering().equals( Collections.EMPTY_SET ); + assert rev3.getReffering().equals( Collections.EMPTY_SET ); + assert rev4.getReffering().equals( makeSet( ing3 ) ); + assert rev5.getReffering().equals( makeSet( ing3 ) ); + } - @Test - public void testHistoryOfEdIng1() { - SetRefEdEntity ed1 = new SetRefEdEntity(1, "data_ed_1"); + @Test + public void testHistoryOfEdIng1() { + SetRefEdEntity ed1 = new SetRefEdEntity( 1, "data_ed_1" ); - SetRefIngEntity rev1 = getAuditReader().find(SetRefIngEntity.class, ing1_id, 1); - SetRefIngEntity rev2 = getAuditReader().find(SetRefIngEntity.class, ing1_id, 2); - SetRefIngEntity rev3 = getAuditReader().find(SetRefIngEntity.class, ing1_id, 3); - SetRefIngEntity rev4 = getAuditReader().find(SetRefIngEntity.class, ing1_id, 4); - SetRefIngEntity rev5 = getAuditReader().find(SetRefIngEntity.class, ing1_id, 5); + SetRefIngEntity rev1 = getAuditReader().find( SetRefIngEntity.class, ing1_id, 1 ); + SetRefIngEntity rev2 = getAuditReader().find( SetRefIngEntity.class, ing1_id, 2 ); + SetRefIngEntity rev3 = getAuditReader().find( SetRefIngEntity.class, ing1_id, 3 ); + SetRefIngEntity rev4 = getAuditReader().find( SetRefIngEntity.class, ing1_id, 4 ); + SetRefIngEntity rev5 = getAuditReader().find( SetRefIngEntity.class, ing1_id, 5 ); - assert rev1.getReference().equals(ed1); - assert rev2.getReference() == null; - assert rev3.getReference() == null; - assert rev4.getReference() == null; - assert rev5.getReference() == null; - } + assert rev1.getReference().equals( ed1 ); + assert rev2.getReference() == null; + assert rev3.getReference() == null; + assert rev4.getReference() == null; + assert rev5.getReference() == null; + } - @Test - public void testHistoryOfEdIng2() { - SetRefEdEntity ed1 = new SetRefEdEntity(1, "data_ed_1"); + @Test + public void testHistoryOfEdIng2() { + SetRefEdEntity ed1 = new SetRefEdEntity( 1, "data_ed_1" ); - SetRefIngEntity rev1 = getAuditReader().find(SetRefIngEntity.class, ing2_id, 1); - SetRefIngEntity rev2 = getAuditReader().find(SetRefIngEntity.class, ing2_id, 2); - SetRefIngEntity rev3 = getAuditReader().find(SetRefIngEntity.class, ing2_id, 3); - SetRefIngEntity rev4 = getAuditReader().find(SetRefIngEntity.class, ing2_id, 4); - SetRefIngEntity rev5 = getAuditReader().find(SetRefIngEntity.class, ing2_id, 5); + SetRefIngEntity rev1 = getAuditReader().find( SetRefIngEntity.class, ing2_id, 1 ); + SetRefIngEntity rev2 = getAuditReader().find( SetRefIngEntity.class, ing2_id, 2 ); + SetRefIngEntity rev3 = getAuditReader().find( SetRefIngEntity.class, ing2_id, 3 ); + SetRefIngEntity rev4 = getAuditReader().find( SetRefIngEntity.class, ing2_id, 4 ); + SetRefIngEntity rev5 = getAuditReader().find( SetRefIngEntity.class, ing2_id, 5 ); - assert rev1.getReference().equals(ed1); - assert rev2.getReference().equals(ed1); - assert rev3 == null; - assert rev4 == null; - assert rev5 == null; - } + assert rev1.getReference().equals( ed1 ); + assert rev2.getReference().equals( ed1 ); + assert rev3 == null; + assert rev4 == null; + assert rev5 == null; + } - @Test - public void testHistoryOfEdIng3() { - SetRefEdEntity ed1 = new SetRefEdEntity(1, "data_ed_1"); - SetRefEdEntity ed2 = new SetRefEdEntity(2, "data_ed_2"); - - SetRefIngEntity rev1 = getAuditReader().find(SetRefIngEntity.class, ing3_id, 1); - SetRefIngEntity rev2 = getAuditReader().find(SetRefIngEntity.class, ing3_id, 2); - SetRefIngEntity rev3 = getAuditReader().find(SetRefIngEntity.class, ing3_id, 3); - SetRefIngEntity rev4 = getAuditReader().find(SetRefIngEntity.class, ing3_id, 4); - SetRefIngEntity rev5 = getAuditReader().find(SetRefIngEntity.class, ing3_id, 5); + @Test + public void testHistoryOfEdIng3() { + SetRefEdEntity ed1 = new SetRefEdEntity( 1, "data_ed_1" ); + SetRefEdEntity ed2 = new SetRefEdEntity( 2, "data_ed_2" ); - assert rev1.getReference().equals(ed1); - assert rev2.getReference().equals(ed1); - assert rev3.getReference().equals(ed1); - assert rev4.getReference().equals(ed2); - assert rev5.getReference().equals(ed2); - } + SetRefIngEntity rev1 = getAuditReader().find( SetRefIngEntity.class, ing3_id, 1 ); + SetRefIngEntity rev2 = getAuditReader().find( SetRefIngEntity.class, ing3_id, 2 ); + SetRefIngEntity rev3 = getAuditReader().find( SetRefIngEntity.class, ing3_id, 3 ); + SetRefIngEntity rev4 = getAuditReader().find( SetRefIngEntity.class, ing3_id, 4 ); + SetRefIngEntity rev5 = getAuditReader().find( SetRefIngEntity.class, ing3_id, 5 ); - @Test - public void testHistoryOfEdIng4() { - SetRefEdEntity ed1 = new SetRefEdEntity(1, "data_ed_1"); + assert rev1.getReference().equals( ed1 ); + assert rev2.getReference().equals( ed1 ); + assert rev3.getReference().equals( ed1 ); + assert rev4.getReference().equals( ed2 ); + assert rev5.getReference().equals( ed2 ); + } - SetRefIngEntity rev1 = getAuditReader().find(SetRefIngEntity.class, ing4_id, 1); - SetRefIngEntity rev2 = getAuditReader().find(SetRefIngEntity.class, ing4_id, 2); - SetRefIngEntity rev3 = getAuditReader().find(SetRefIngEntity.class, ing4_id, 3); - SetRefIngEntity rev4 = getAuditReader().find(SetRefIngEntity.class, ing4_id, 4); - SetRefIngEntity rev5 = getAuditReader().find(SetRefIngEntity.class, ing4_id, 5); + @Test + public void testHistoryOfEdIng4() { + SetRefEdEntity ed1 = new SetRefEdEntity( 1, "data_ed_1" ); - assert rev1.getReference().equals(ed1); - assert rev2.getReference().equals(ed1); - assert rev3.getReference().equals(ed1); - assert rev4.getReference().equals(ed1); - assert rev5.getReference() == null; - } + SetRefIngEntity rev1 = getAuditReader().find( SetRefIngEntity.class, ing4_id, 1 ); + SetRefIngEntity rev2 = getAuditReader().find( SetRefIngEntity.class, ing4_id, 2 ); + SetRefIngEntity rev3 = getAuditReader().find( SetRefIngEntity.class, ing4_id, 3 ); + SetRefIngEntity rev4 = getAuditReader().find( SetRefIngEntity.class, ing4_id, 4 ); + SetRefIngEntity rev5 = getAuditReader().find( SetRefIngEntity.class, ing4_id, 5 ); + + assert rev1.getReference().equals( ed1 ); + assert rev2.getReference().equals( ed1 ); + assert rev3.getReference().equals( ed1 ); + assert rev4.getReference().equals( ed1 ); + assert rev5.getReference() == null; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/BidirectionalMapKey.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/BidirectionalMapKey.java index 843b617e33..494c4cc0ed 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/BidirectionalMapKey.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/BidirectionalMapKey.java @@ -23,88 +23,88 @@ */ package org.hibernate.envers.test.integration.onetomany; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.tools.TestTools; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class BidirectionalMapKey extends BaseEnversJPAFunctionalTestCase { - private Integer ed_id; + private Integer ed_id; - private Integer ing1_id; - private Integer ing2_id; + private Integer ing1_id; + private Integer ing2_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { RefIngMapKeyEntity.class, RefEdMapKeyEntity.class }; - } + return new Class[] {RefIngMapKeyEntity.class, RefEdMapKeyEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - // Revision 1 (intialy 1 relation: ing1 -> ed) - em.getTransaction().begin(); + // Revision 1 (intialy 1 relation: ing1 -> ed) + em.getTransaction().begin(); - RefEdMapKeyEntity ed = new RefEdMapKeyEntity(); + RefEdMapKeyEntity ed = new RefEdMapKeyEntity(); - em.persist(ed); + em.persist( ed ); - RefIngMapKeyEntity ing1 = new RefIngMapKeyEntity(); - ing1.setData("a"); - ing1.setReference(ed); + RefIngMapKeyEntity ing1 = new RefIngMapKeyEntity(); + ing1.setData( "a" ); + ing1.setReference( ed ); - RefIngMapKeyEntity ing2 = new RefIngMapKeyEntity(); - ing2.setData("b"); + RefIngMapKeyEntity ing2 = new RefIngMapKeyEntity(); + ing2.setData( "b" ); - em.persist(ing1); - em.persist(ing2); + em.persist( ing1 ); + em.persist( ing2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 (adding second relation: ing2 -> ed) - em.getTransaction().begin(); + // Revision 2 (adding second relation: ing2 -> ed) + em.getTransaction().begin(); - ed = em.find(RefEdMapKeyEntity.class, ed.getId()); - ing2 = em.find(RefIngMapKeyEntity.class, ing2.getId()); + ed = em.find( RefEdMapKeyEntity.class, ed.getId() ); + ing2 = em.find( RefIngMapKeyEntity.class, ing2.getId() ); - ing2.setReference(ed); + ing2.setReference( ed ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // + // - ed_id = ed.getId(); + ed_id = ed.getId(); - ing1_id = ing1.getId(); - ing2_id = ing2.getId(); - } + ing1_id = ing1.getId(); + ing2_id = ing2.getId(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(RefEdMapKeyEntity.class, ed_id)); + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( RefEdMapKeyEntity.class, ed_id ) ); - assert Arrays.asList(1).equals(getAuditReader().getRevisions(RefIngMapKeyEntity.class, ing1_id)); - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(RefIngMapKeyEntity.class, ing2_id)); - } + assert Arrays.asList( 1 ).equals( getAuditReader().getRevisions( RefIngMapKeyEntity.class, ing1_id ) ); + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( RefIngMapKeyEntity.class, ing2_id ) ); + } - @Test - public void testHistoryOfEd() { - RefIngMapKeyEntity ing1 = getEntityManager().find(RefIngMapKeyEntity.class, ing1_id); - RefIngMapKeyEntity ing2 = getEntityManager().find(RefIngMapKeyEntity.class, ing2_id); + @Test + public void testHistoryOfEd() { + RefIngMapKeyEntity ing1 = getEntityManager().find( RefIngMapKeyEntity.class, ing1_id ); + RefIngMapKeyEntity ing2 = getEntityManager().find( RefIngMapKeyEntity.class, ing2_id ); - RefEdMapKeyEntity rev1 = getAuditReader().find(RefEdMapKeyEntity.class, ed_id, 1); - RefEdMapKeyEntity rev2 = getAuditReader().find(RefEdMapKeyEntity.class, ed_id, 2); + RefEdMapKeyEntity rev1 = getAuditReader().find( RefEdMapKeyEntity.class, ed_id, 1 ); + RefEdMapKeyEntity rev2 = getAuditReader().find( RefEdMapKeyEntity.class, ed_id, 2 ); - assert rev1.getIdmap().equals(TestTools.makeMap("a", ing1)); - assert rev2.getIdmap().equals(TestTools.makeMap("a", ing1, "b", ing2)); - } + assert rev1.getIdmap().equals( TestTools.makeMap( "a", ing1 ) ); + assert rev2.getIdmap().equals( TestTools.makeMap( "a", ing1, "b", ing2 ) ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/InverseSideChanges.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/InverseSideChanges.java index ec652dd7e3..79eeb5d789 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/InverseSideChanges.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/InverseSideChanges.java @@ -24,85 +24,85 @@ package org.hibernate.envers.test.integration.onetomany; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.onetomany.SetRefEdEntity; import org.hibernate.envers.test.entities.onetomany.SetRefIngEntity; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class InverseSideChanges extends BaseEnversJPAFunctionalTestCase { - private Integer ed1_id; + private Integer ed1_id; - private Integer ing1_id; + private Integer ing1_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { SetRefEdEntity.class, SetRefIngEntity.class }; - } + return new Class[] {SetRefEdEntity.class, SetRefIngEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - SetRefEdEntity ed1 = new SetRefEdEntity(1, "data_ed_1"); + SetRefEdEntity ed1 = new SetRefEdEntity( 1, "data_ed_1" ); - SetRefIngEntity ing1 = new SetRefIngEntity(3, "data_ing_1"); + SetRefIngEntity ing1 = new SetRefIngEntity( 3, "data_ing_1" ); - // Revision 1 - em.getTransaction().begin(); + // Revision 1 + em.getTransaction().begin(); - em.persist(ed1); + em.persist( ed1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 + // Revision 2 - em.getTransaction().begin(); + em.getTransaction().begin(); - ed1 = em.find(SetRefEdEntity.class, ed1.getId()); - - em.persist(ing1); + ed1 = em.find( SetRefEdEntity.class, ed1.getId() ); - ed1.setReffering(new HashSet()); - ed1.getReffering().add(ing1); + em.persist( ing1 ); - em.getTransaction().commit(); + ed1.setReffering( new HashSet() ); + ed1.getReffering().add( ing1 ); - // + em.getTransaction().commit(); - ed1_id = ed1.getId(); + // - ing1_id = ing1.getId(); - } + ed1_id = ed1.getId(); - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1).equals(getAuditReader().getRevisions(SetRefEdEntity.class, ed1_id)); + ing1_id = ing1.getId(); + } - assert Arrays.asList(2).equals(getAuditReader().getRevisions(SetRefIngEntity.class, ing1_id)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1 ).equals( getAuditReader().getRevisions( SetRefEdEntity.class, ed1_id ) ); - @Test - public void testHistoryOfEdId1() { - SetRefEdEntity rev1 = getAuditReader().find(SetRefEdEntity.class, ed1_id, 1); + assert Arrays.asList( 2 ).equals( getAuditReader().getRevisions( SetRefIngEntity.class, ing1_id ) ); + } - assert rev1.getReffering().equals(Collections.EMPTY_SET); - } + @Test + public void testHistoryOfEdId1() { + SetRefEdEntity rev1 = getAuditReader().find( SetRefEdEntity.class, ed1_id, 1 ); - @Test - public void testHistoryOfEdIng1() { - SetRefIngEntity rev2 = getAuditReader().find(SetRefIngEntity.class, ing1_id, 2); + assert rev1.getReffering().equals( Collections.EMPTY_SET ); + } - assert rev2.getReference() == null; - } + @Test + public void testHistoryOfEdIng1() { + SetRefIngEntity rev2 = getAuditReader().find( SetRefIngEntity.class, ing1_id, 2 ); + + assert rev2.getReference() == null; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/RefEdMapKeyEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/RefEdMapKeyEntity.java index 1c63c61674..6abbb75fc9 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/RefEdMapKeyEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/RefEdMapKeyEntity.java @@ -22,13 +22,14 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.onetomany; -import java.util.HashMap; -import java.util.Map; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.MapKey; import javax.persistence.OneToMany; +import java.util.HashMap; +import java.util.Map; import org.hibernate.envers.Audited; @@ -37,51 +38,57 @@ import org.hibernate.envers.Audited; */ @Entity public class RefEdMapKeyEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - @Audited - @OneToMany(mappedBy="reference") - @MapKey(name = "data") - private Map idmap; + @Audited + @OneToMany(mappedBy = "reference") + @MapKey(name = "data") + private Map idmap; - public RefEdMapKeyEntity() { - idmap = new HashMap(); - } + public RefEdMapKeyEntity() { + idmap = new HashMap(); + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public Map getIdmap() { - return idmap; - } + public Map getIdmap() { + return idmap; + } - public void setIdmap(Map idmap) { - this.idmap = idmap; - } + public void setIdmap(Map idmap) { + this.idmap = idmap; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof RefEdMapKeyEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof RefEdMapKeyEntity) ) { + return false; + } - RefEdMapKeyEntity that = (RefEdMapKeyEntity) o; + RefEdMapKeyEntity that = (RefEdMapKeyEntity) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - return (id != null ? id.hashCode() : 0); - } + public int hashCode() { + return (id != null ? id.hashCode() : 0); + } - public String toString() { - return "RedMKE(id = " + id + ", idmap = " + idmap + ")"; - } + public String toString() { + return "RedMKE(id = " + id + ", idmap = " + idmap + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/RefIngMapKeyEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/RefIngMapKeyEntity.java index a674bac718..e337700d63 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/RefIngMapKeyEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/RefIngMapKeyEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.onetomany; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; @@ -34,57 +35,63 @@ import org.hibernate.envers.Audited; */ @Entity public class RefIngMapKeyEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - @Audited - @ManyToOne - private RefEdMapKeyEntity reference; + @Audited + @ManyToOne + private RefEdMapKeyEntity reference; - @Audited - private String data; + @Audited + private String data; - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public RefEdMapKeyEntity getReference() { - return reference; - } + public RefEdMapKeyEntity getReference() { + return reference; + } - public void setReference(RefEdMapKeyEntity reference) { - this.reference = reference; - } + public void setReference(RefEdMapKeyEntity reference) { + this.reference = reference; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof RefIngMapKeyEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof RefIngMapKeyEntity) ) { + return false; + } - RefIngMapKeyEntity that = (RefIngMapKeyEntity) o; + RefIngMapKeyEntity that = (RefIngMapKeyEntity) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - return (id != null ? id.hashCode() : 0); - } + public int hashCode() { + return (id != null ? id.hashCode() : 0); + } - public String toString() { - return "RingMKE(id = " + id + ", data = " + data + ", reference = " + reference + ")"; - } + public String toString() { + return "RingMKE(id = " + id + ", data = " + data + ", reference = " + reference + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/BasicDetachedList.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/BasicDetachedList.java index 81bd37bb80..682b52ed63 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/BasicDetachedList.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/BasicDetachedList.java @@ -23,11 +23,9 @@ */ package org.hibernate.envers.test.integration.onetomany.detached; +import javax.persistence.EntityManager; import java.util.ArrayList; import java.util.Arrays; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; @@ -35,105 +33,107 @@ import org.hibernate.envers.test.entities.StrTestEntity; import org.hibernate.envers.test.entities.onetomany.detached.ListRefCollEntity; import org.hibernate.envers.test.tools.TestTools; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class BasicDetachedList extends BaseEnversJPAFunctionalTestCase { - private Integer str1_id; - private Integer str2_id; + private Integer str1_id; + private Integer str2_id; - private Integer coll1_id; + private Integer coll1_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { StrTestEntity.class, ListRefCollEntity.class }; - } + return new Class[] {StrTestEntity.class, ListRefCollEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - StrTestEntity str1 = new StrTestEntity("str1"); - StrTestEntity str2 = new StrTestEntity("str2"); + StrTestEntity str1 = new StrTestEntity( "str1" ); + StrTestEntity str2 = new StrTestEntity( "str2" ); - ListRefCollEntity coll1 = new ListRefCollEntity(3, "coll1"); + ListRefCollEntity coll1 = new ListRefCollEntity( 3, "coll1" ); - // Revision 1 - em.getTransaction().begin(); + // Revision 1 + em.getTransaction().begin(); - em.persist(str1); - em.persist(str2); + em.persist( str1 ); + em.persist( str2 ); - coll1.setCollection(new ArrayList()); - coll1.getCollection().add(str1); - em.persist(coll1); + coll1.setCollection( new ArrayList() ); + coll1.getCollection().add( str1 ); + em.persist( coll1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); + // Revision 2 + em.getTransaction().begin(); - str2 = em.find(StrTestEntity.class, str2.getId()); - coll1 = em.find(ListRefCollEntity.class, coll1.getId()); + str2 = em.find( StrTestEntity.class, str2.getId() ); + coll1 = em.find( ListRefCollEntity.class, coll1.getId() ); - coll1.getCollection().add(str2); + coll1.getCollection().add( str2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 - em.getTransaction().begin(); + // Revision 3 + em.getTransaction().begin(); - str1 = em.find(StrTestEntity.class, str1.getId()); - coll1 = em.find(ListRefCollEntity.class, coll1.getId()); + str1 = em.find( StrTestEntity.class, str1.getId() ); + coll1 = em.find( ListRefCollEntity.class, coll1.getId() ); - coll1.getCollection().remove(str1); + coll1.getCollection().remove( str1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 4 - em.getTransaction().begin(); + // Revision 4 + em.getTransaction().begin(); - coll1 = em.find(ListRefCollEntity.class, coll1.getId()); + coll1 = em.find( ListRefCollEntity.class, coll1.getId() ); - coll1.getCollection().clear(); + coll1.getCollection().clear(); - em.getTransaction().commit(); + em.getTransaction().commit(); - // + // - str1_id = str1.getId(); - str2_id = str2.getId(); + str1_id = str1.getId(); + str2_id = str2.getId(); - coll1_id = coll1.getId(); - } + coll1_id = coll1.getId(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2, 3, 4).equals(getAuditReader().getRevisions(ListRefCollEntity.class, coll1_id)); + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2, 3, 4 ).equals( getAuditReader().getRevisions( ListRefCollEntity.class, coll1_id ) ); - assert Arrays.asList(1).equals(getAuditReader().getRevisions(StrTestEntity.class, str1_id)); - assert Arrays.asList(1).equals(getAuditReader().getRevisions(StrTestEntity.class, str2_id)); - } + assert Arrays.asList( 1 ).equals( getAuditReader().getRevisions( StrTestEntity.class, str1_id ) ); + assert Arrays.asList( 1 ).equals( getAuditReader().getRevisions( StrTestEntity.class, str2_id ) ); + } - @Test - public void testHistoryOfColl1() { - StrTestEntity str1 = getEntityManager().find(StrTestEntity.class, str1_id); - StrTestEntity str2 = getEntityManager().find(StrTestEntity.class, str2_id); + @Test + public void testHistoryOfColl1() { + StrTestEntity str1 = getEntityManager().find( StrTestEntity.class, str1_id ); + StrTestEntity str2 = getEntityManager().find( StrTestEntity.class, str2_id ); - ListRefCollEntity rev1 = getAuditReader().find(ListRefCollEntity.class, coll1_id, 1); - ListRefCollEntity rev2 = getAuditReader().find(ListRefCollEntity.class, coll1_id, 2); - ListRefCollEntity rev3 = getAuditReader().find(ListRefCollEntity.class, coll1_id, 3); - ListRefCollEntity rev4 = getAuditReader().find(ListRefCollEntity.class, coll1_id, 4); + ListRefCollEntity rev1 = getAuditReader().find( ListRefCollEntity.class, coll1_id, 1 ); + ListRefCollEntity rev2 = getAuditReader().find( ListRefCollEntity.class, coll1_id, 2 ); + ListRefCollEntity rev3 = getAuditReader().find( ListRefCollEntity.class, coll1_id, 3 ); + ListRefCollEntity rev4 = getAuditReader().find( ListRefCollEntity.class, coll1_id, 4 ); - assert TestTools.checkList(rev1.getCollection(), str1); - assert TestTools.checkList(rev2.getCollection(), str1, str2); - assert TestTools.checkList(rev3.getCollection(), str2); - assert TestTools.checkList(rev4.getCollection()); - - assert "coll1".equals(rev1.getData()); - assert "coll1".equals(rev2.getData()); - assert "coll1".equals(rev3.getData()); - assert "coll1".equals(rev4.getData()); - } + assert TestTools.checkList( rev1.getCollection(), str1 ); + assert TestTools.checkList( rev2.getCollection(), str1, str2 ); + assert TestTools.checkList( rev3.getCollection(), str2 ); + assert TestTools.checkList( rev4.getCollection() ); + + assert "coll1".equals( rev1.getData() ); + assert "coll1".equals( rev2.getData() ); + assert "coll1".equals( rev3.getData() ); + assert "coll1".equals( rev4.getData() ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/BasicDetachedSet.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/BasicDetachedSet.java index 8e1f763e96..e19e18aedd 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/BasicDetachedSet.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/BasicDetachedSet.java @@ -23,11 +23,9 @@ */ package org.hibernate.envers.test.integration.onetomany.detached; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.HashSet; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; @@ -35,105 +33,107 @@ import org.hibernate.envers.test.entities.StrTestEntity; import org.hibernate.envers.test.entities.onetomany.detached.SetRefCollEntity; import org.hibernate.envers.test.tools.TestTools; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class BasicDetachedSet extends BaseEnversJPAFunctionalTestCase { - private Integer str1_id; - private Integer str2_id; + private Integer str1_id; + private Integer str2_id; - private Integer coll1_id; + private Integer coll1_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { StrTestEntity.class, SetRefCollEntity.class }; - } + return new Class[] {StrTestEntity.class, SetRefCollEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - StrTestEntity str1 = new StrTestEntity("str1"); - StrTestEntity str2 = new StrTestEntity("str2"); + StrTestEntity str1 = new StrTestEntity( "str1" ); + StrTestEntity str2 = new StrTestEntity( "str2" ); - SetRefCollEntity coll1 = new SetRefCollEntity(3, "coll1"); + SetRefCollEntity coll1 = new SetRefCollEntity( 3, "coll1" ); - // Revision 1 - em.getTransaction().begin(); + // Revision 1 + em.getTransaction().begin(); - em.persist(str1); - em.persist(str2); + em.persist( str1 ); + em.persist( str2 ); - coll1.setCollection(new HashSet()); - coll1.getCollection().add(str1); - em.persist(coll1); + coll1.setCollection( new HashSet() ); + coll1.getCollection().add( str1 ); + em.persist( coll1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); + // Revision 2 + em.getTransaction().begin(); - str2 = em.find(StrTestEntity.class, str2.getId()); - coll1 = em.find(SetRefCollEntity.class, coll1.getId()); + str2 = em.find( StrTestEntity.class, str2.getId() ); + coll1 = em.find( SetRefCollEntity.class, coll1.getId() ); - coll1.getCollection().add(str2); + coll1.getCollection().add( str2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 - em.getTransaction().begin(); + // Revision 3 + em.getTransaction().begin(); - str1 = em.find(StrTestEntity.class, str1.getId()); - coll1 = em.find(SetRefCollEntity.class, coll1.getId()); + str1 = em.find( StrTestEntity.class, str1.getId() ); + coll1 = em.find( SetRefCollEntity.class, coll1.getId() ); - coll1.getCollection().remove(str1); + coll1.getCollection().remove( str1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 4 - em.getTransaction().begin(); + // Revision 4 + em.getTransaction().begin(); - coll1 = em.find(SetRefCollEntity.class, coll1.getId()); + coll1 = em.find( SetRefCollEntity.class, coll1.getId() ); - coll1.getCollection().clear(); + coll1.getCollection().clear(); - em.getTransaction().commit(); + em.getTransaction().commit(); - // + // - str1_id = str1.getId(); - str2_id = str2.getId(); + str1_id = str1.getId(); + str2_id = str2.getId(); - coll1_id = coll1.getId(); - } + coll1_id = coll1.getId(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2, 3, 4).equals(getAuditReader().getRevisions(SetRefCollEntity.class, coll1_id)); + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2, 3, 4 ).equals( getAuditReader().getRevisions( SetRefCollEntity.class, coll1_id ) ); - assert Arrays.asList(1).equals(getAuditReader().getRevisions(StrTestEntity.class, str1_id)); - assert Arrays.asList(1).equals(getAuditReader().getRevisions(StrTestEntity.class, str2_id)); - } + assert Arrays.asList( 1 ).equals( getAuditReader().getRevisions( StrTestEntity.class, str1_id ) ); + assert Arrays.asList( 1 ).equals( getAuditReader().getRevisions( StrTestEntity.class, str2_id ) ); + } - @Test - public void testHistoryOfColl1() { - StrTestEntity str1 = getEntityManager().find(StrTestEntity.class, str1_id); - StrTestEntity str2 = getEntityManager().find(StrTestEntity.class, str2_id); + @Test + public void testHistoryOfColl1() { + StrTestEntity str1 = getEntityManager().find( StrTestEntity.class, str1_id ); + StrTestEntity str2 = getEntityManager().find( StrTestEntity.class, str2_id ); - SetRefCollEntity rev1 = getAuditReader().find(SetRefCollEntity.class, coll1_id, 1); - SetRefCollEntity rev2 = getAuditReader().find(SetRefCollEntity.class, coll1_id, 2); - SetRefCollEntity rev3 = getAuditReader().find(SetRefCollEntity.class, coll1_id, 3); - SetRefCollEntity rev4 = getAuditReader().find(SetRefCollEntity.class, coll1_id, 4); + SetRefCollEntity rev1 = getAuditReader().find( SetRefCollEntity.class, coll1_id, 1 ); + SetRefCollEntity rev2 = getAuditReader().find( SetRefCollEntity.class, coll1_id, 2 ); + SetRefCollEntity rev3 = getAuditReader().find( SetRefCollEntity.class, coll1_id, 3 ); + SetRefCollEntity rev4 = getAuditReader().find( SetRefCollEntity.class, coll1_id, 4 ); - assert rev1.getCollection().equals(TestTools.makeSet(str1)); - assert rev2.getCollection().equals(TestTools.makeSet(str1, str2)); - assert rev3.getCollection().equals(TestTools.makeSet(str2)); - assert rev4.getCollection().equals(TestTools.makeSet()); + assert rev1.getCollection().equals( TestTools.makeSet( str1 ) ); + assert rev2.getCollection().equals( TestTools.makeSet( str1, str2 ) ); + assert rev3.getCollection().equals( TestTools.makeSet( str2 ) ); + assert rev4.getCollection().equals( TestTools.makeSet() ); - assert "coll1".equals(rev1.getData()); - assert "coll1".equals(rev2.getData()); - assert "coll1".equals(rev3.getData()); - assert "coll1".equals(rev4.getData()); - } + assert "coll1".equals( rev1.getData() ); + assert "coll1".equals( rev2.getData() ); + assert "coll1".equals( rev3.getData() ); + assert "coll1".equals( rev4.getData() ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/BasicDetachedSetWithEmbId.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/BasicDetachedSetWithEmbId.java index e60a949091..2b3e9bad8a 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/BasicDetachedSetWithEmbId.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/BasicDetachedSetWithEmbId.java @@ -23,11 +23,9 @@ */ package org.hibernate.envers.test.integration.onetomany.detached; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.HashSet; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; @@ -36,103 +34,110 @@ import org.hibernate.envers.test.entities.ids.EmbIdTestEntity; import org.hibernate.envers.test.entities.onetomany.detached.ids.SetRefCollEntityEmbId; import org.hibernate.envers.test.tools.TestTools; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class BasicDetachedSetWithEmbId extends BaseEnversJPAFunctionalTestCase { - private EmbId str1_id; - private EmbId str2_id; + private EmbId str1_id; + private EmbId str2_id; - private EmbId coll1_id; + private EmbId coll1_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { EmbIdTestEntity.class, SetRefCollEntityEmbId.class }; - } + return new Class[] {EmbIdTestEntity.class, SetRefCollEntityEmbId.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - str1_id = new EmbId(1, 2); - str2_id = new EmbId(3, 4); + str1_id = new EmbId( 1, 2 ); + str2_id = new EmbId( 3, 4 ); - coll1_id = new EmbId(5, 6); + coll1_id = new EmbId( 5, 6 ); - EmbIdTestEntity str1 = new EmbIdTestEntity(str1_id, "str1"); - EmbIdTestEntity str2 = new EmbIdTestEntity(str2_id, "str2"); + EmbIdTestEntity str1 = new EmbIdTestEntity( str1_id, "str1" ); + EmbIdTestEntity str2 = new EmbIdTestEntity( str2_id, "str2" ); - SetRefCollEntityEmbId coll1 = new SetRefCollEntityEmbId(coll1_id, "coll1"); + SetRefCollEntityEmbId coll1 = new SetRefCollEntityEmbId( coll1_id, "coll1" ); - // Revision 1 - em.getTransaction().begin(); + // Revision 1 + em.getTransaction().begin(); - em.persist(str1); - em.persist(str2); + em.persist( str1 ); + em.persist( str2 ); - coll1.setCollection(new HashSet()); - coll1.getCollection().add(str1); - em.persist(coll1); + coll1.setCollection( new HashSet() ); + coll1.getCollection().add( str1 ); + em.persist( coll1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); + // Revision 2 + em.getTransaction().begin(); - str2 = em.find(EmbIdTestEntity.class, str2.getId()); - coll1 = em.find(SetRefCollEntityEmbId.class, coll1.getId()); + str2 = em.find( EmbIdTestEntity.class, str2.getId() ); + coll1 = em.find( SetRefCollEntityEmbId.class, coll1.getId() ); - coll1.getCollection().add(str2); + coll1.getCollection().add( str2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 - em.getTransaction().begin(); + // Revision 3 + em.getTransaction().begin(); - str1 = em.find(EmbIdTestEntity.class, str1.getId()); - coll1 = em.find(SetRefCollEntityEmbId.class, coll1.getId()); + str1 = em.find( EmbIdTestEntity.class, str1.getId() ); + coll1 = em.find( SetRefCollEntityEmbId.class, coll1.getId() ); - coll1.getCollection().remove(str1); + coll1.getCollection().remove( str1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 4 - em.getTransaction().begin(); + // Revision 4 + em.getTransaction().begin(); - coll1 = em.find(SetRefCollEntityEmbId.class, coll1.getId()); + coll1 = em.find( SetRefCollEntityEmbId.class, coll1.getId() ); - coll1.getCollection().clear(); + coll1.getCollection().clear(); - em.getTransaction().commit(); - } + em.getTransaction().commit(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2, 3, 4).equals(getAuditReader().getRevisions(SetRefCollEntityEmbId.class, coll1_id)); + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2, 3, 4 ).equals( + getAuditReader().getRevisions( + SetRefCollEntityEmbId.class, + coll1_id + ) + ); - assert Arrays.asList(1).equals(getAuditReader().getRevisions(EmbIdTestEntity.class, str1_id)); - assert Arrays.asList(1).equals(getAuditReader().getRevisions(EmbIdTestEntity.class, str2_id)); - } + assert Arrays.asList( 1 ).equals( getAuditReader().getRevisions( EmbIdTestEntity.class, str1_id ) ); + assert Arrays.asList( 1 ).equals( getAuditReader().getRevisions( EmbIdTestEntity.class, str2_id ) ); + } - @Test - public void testHistoryOfColl1() { - EmbIdTestEntity str1 = getEntityManager().find(EmbIdTestEntity.class, str1_id); - EmbIdTestEntity str2 = getEntityManager().find(EmbIdTestEntity.class, str2_id); + @Test + public void testHistoryOfColl1() { + EmbIdTestEntity str1 = getEntityManager().find( EmbIdTestEntity.class, str1_id ); + EmbIdTestEntity str2 = getEntityManager().find( EmbIdTestEntity.class, str2_id ); - SetRefCollEntityEmbId rev1 = getAuditReader().find(SetRefCollEntityEmbId.class, coll1_id, 1); - SetRefCollEntityEmbId rev2 = getAuditReader().find(SetRefCollEntityEmbId.class, coll1_id, 2); - SetRefCollEntityEmbId rev3 = getAuditReader().find(SetRefCollEntityEmbId.class, coll1_id, 3); - SetRefCollEntityEmbId rev4 = getAuditReader().find(SetRefCollEntityEmbId.class, coll1_id, 4); + SetRefCollEntityEmbId rev1 = getAuditReader().find( SetRefCollEntityEmbId.class, coll1_id, 1 ); + SetRefCollEntityEmbId rev2 = getAuditReader().find( SetRefCollEntityEmbId.class, coll1_id, 2 ); + SetRefCollEntityEmbId rev3 = getAuditReader().find( SetRefCollEntityEmbId.class, coll1_id, 3 ); + SetRefCollEntityEmbId rev4 = getAuditReader().find( SetRefCollEntityEmbId.class, coll1_id, 4 ); - assert rev1.getCollection().equals(TestTools.makeSet(str1)); - assert rev2.getCollection().equals(TestTools.makeSet(str1, str2)); - assert rev3.getCollection().equals(TestTools.makeSet(str2)); - assert rev4.getCollection().equals(TestTools.makeSet()); + assert rev1.getCollection().equals( TestTools.makeSet( str1 ) ); + assert rev2.getCollection().equals( TestTools.makeSet( str1, str2 ) ); + assert rev3.getCollection().equals( TestTools.makeSet( str2 ) ); + assert rev4.getCollection().equals( TestTools.makeSet() ); - assert "coll1".equals(rev1.getData()); - assert "coll1".equals(rev2.getData()); - assert "coll1".equals(rev3.getData()); - assert "coll1".equals(rev4.getData()); - } + assert "coll1".equals( rev1.getData() ); + assert "coll1".equals( rev2.getData() ); + assert "coll1".equals( rev3.getData() ); + assert "coll1".equals( rev4.getData() ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/BasicDetachedSetWithMulId.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/BasicDetachedSetWithMulId.java index 21507b8442..3403a7538e 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/BasicDetachedSetWithMulId.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/BasicDetachedSetWithMulId.java @@ -23,11 +23,9 @@ */ package org.hibernate.envers.test.integration.onetomany.detached; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.HashSet; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; @@ -36,103 +34,110 @@ import org.hibernate.envers.test.entities.ids.MulIdTestEntity; import org.hibernate.envers.test.entities.onetomany.detached.ids.SetRefCollEntityMulId; import org.hibernate.envers.test.tools.TestTools; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class BasicDetachedSetWithMulId extends BaseEnversJPAFunctionalTestCase { - private MulId str1_id; - private MulId str2_id; + private MulId str1_id; + private MulId str2_id; - private MulId coll1_id; + private MulId coll1_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { MulIdTestEntity.class, SetRefCollEntityMulId.class }; - } + return new Class[] {MulIdTestEntity.class, SetRefCollEntityMulId.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - str1_id = new MulId(1, 2); - str2_id = new MulId(3, 4); + str1_id = new MulId( 1, 2 ); + str2_id = new MulId( 3, 4 ); - coll1_id = new MulId(5, 6); + coll1_id = new MulId( 5, 6 ); - MulIdTestEntity str1 = new MulIdTestEntity(str1_id.getId1(), str1_id.getId2(), "str1"); - MulIdTestEntity str2 = new MulIdTestEntity(str2_id.getId1(), str2_id.getId2(), "str2"); + MulIdTestEntity str1 = new MulIdTestEntity( str1_id.getId1(), str1_id.getId2(), "str1" ); + MulIdTestEntity str2 = new MulIdTestEntity( str2_id.getId1(), str2_id.getId2(), "str2" ); - SetRefCollEntityMulId coll1 = new SetRefCollEntityMulId(coll1_id.getId1(), coll1_id.getId2(), "coll1"); + SetRefCollEntityMulId coll1 = new SetRefCollEntityMulId( coll1_id.getId1(), coll1_id.getId2(), "coll1" ); - // Revision 1 - em.getTransaction().begin(); + // Revision 1 + em.getTransaction().begin(); - em.persist(str1); - em.persist(str2); + em.persist( str1 ); + em.persist( str2 ); - coll1.setCollection(new HashSet()); - coll1.getCollection().add(str1); - em.persist(coll1); + coll1.setCollection( new HashSet() ); + coll1.getCollection().add( str1 ); + em.persist( coll1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); + // Revision 2 + em.getTransaction().begin(); - str2 = em.find(MulIdTestEntity.class, str2_id); - coll1 = em.find(SetRefCollEntityMulId.class, coll1_id); + str2 = em.find( MulIdTestEntity.class, str2_id ); + coll1 = em.find( SetRefCollEntityMulId.class, coll1_id ); - coll1.getCollection().add(str2); + coll1.getCollection().add( str2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 - em.getTransaction().begin(); + // Revision 3 + em.getTransaction().begin(); - str1 = em.find(MulIdTestEntity.class, str1_id); - coll1 = em.find(SetRefCollEntityMulId.class, coll1_id); + str1 = em.find( MulIdTestEntity.class, str1_id ); + coll1 = em.find( SetRefCollEntityMulId.class, coll1_id ); - coll1.getCollection().remove(str1); + coll1.getCollection().remove( str1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 4 - em.getTransaction().begin(); + // Revision 4 + em.getTransaction().begin(); - coll1 = em.find(SetRefCollEntityMulId.class, coll1_id); + coll1 = em.find( SetRefCollEntityMulId.class, coll1_id ); - coll1.getCollection().clear(); + coll1.getCollection().clear(); - em.getTransaction().commit(); - } + em.getTransaction().commit(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2, 3, 4).equals(getAuditReader().getRevisions(SetRefCollEntityMulId.class, coll1_id)); + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2, 3, 4 ).equals( + getAuditReader().getRevisions( + SetRefCollEntityMulId.class, + coll1_id + ) + ); - assert Arrays.asList(1).equals(getAuditReader().getRevisions(MulIdTestEntity.class, str1_id)); - assert Arrays.asList(1).equals(getAuditReader().getRevisions(MulIdTestEntity.class, str2_id)); - } + assert Arrays.asList( 1 ).equals( getAuditReader().getRevisions( MulIdTestEntity.class, str1_id ) ); + assert Arrays.asList( 1 ).equals( getAuditReader().getRevisions( MulIdTestEntity.class, str2_id ) ); + } - @Test - public void testHistoryOfColl1() { - MulIdTestEntity str1 = getEntityManager().find(MulIdTestEntity.class, str1_id); - MulIdTestEntity str2 = getEntityManager().find(MulIdTestEntity.class, str2_id); + @Test + public void testHistoryOfColl1() { + MulIdTestEntity str1 = getEntityManager().find( MulIdTestEntity.class, str1_id ); + MulIdTestEntity str2 = getEntityManager().find( MulIdTestEntity.class, str2_id ); - SetRefCollEntityMulId rev1 = getAuditReader().find(SetRefCollEntityMulId.class, coll1_id, 1); - SetRefCollEntityMulId rev2 = getAuditReader().find(SetRefCollEntityMulId.class, coll1_id, 2); - SetRefCollEntityMulId rev3 = getAuditReader().find(SetRefCollEntityMulId.class, coll1_id, 3); - SetRefCollEntityMulId rev4 = getAuditReader().find(SetRefCollEntityMulId.class, coll1_id, 4); + SetRefCollEntityMulId rev1 = getAuditReader().find( SetRefCollEntityMulId.class, coll1_id, 1 ); + SetRefCollEntityMulId rev2 = getAuditReader().find( SetRefCollEntityMulId.class, coll1_id, 2 ); + SetRefCollEntityMulId rev3 = getAuditReader().find( SetRefCollEntityMulId.class, coll1_id, 3 ); + SetRefCollEntityMulId rev4 = getAuditReader().find( SetRefCollEntityMulId.class, coll1_id, 4 ); - assert rev1.getCollection().equals(TestTools.makeSet(str1)); - assert rev2.getCollection().equals(TestTools.makeSet(str1, str2)); - assert rev3.getCollection().equals(TestTools.makeSet(str2)); - assert rev4.getCollection().equals(TestTools.makeSet()); + assert rev1.getCollection().equals( TestTools.makeSet( str1 ) ); + assert rev2.getCollection().equals( TestTools.makeSet( str1, str2 ) ); + assert rev3.getCollection().equals( TestTools.makeSet( str2 ) ); + assert rev4.getCollection().equals( TestTools.makeSet() ); - assert "coll1".equals(rev1.getData()); - assert "coll1".equals(rev2.getData()); - assert "coll1".equals(rev3.getData()); - assert "coll1".equals(rev4.getData()); - } + assert "coll1".equals( rev1.getData() ); + assert "coll1".equals( rev2.getData() ); + assert "coll1".equals( rev3.getData() ); + assert "coll1".equals( rev4.getData() ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/BasicJoinColumnSet.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/BasicJoinColumnSet.java index 6864cc4a82..e2edb32eb7 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/BasicJoinColumnSet.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/BasicJoinColumnSet.java @@ -23,11 +23,9 @@ */ package org.hibernate.envers.test.integration.onetomany.detached; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.HashSet; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; @@ -35,105 +33,112 @@ import org.hibernate.envers.test.entities.StrTestEntity; import org.hibernate.envers.test.entities.onetomany.detached.SetJoinColumnRefCollEntity; import org.hibernate.envers.test.tools.TestTools; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class BasicJoinColumnSet extends BaseEnversJPAFunctionalTestCase { - private Integer str1_id; - private Integer str2_id; + private Integer str1_id; + private Integer str2_id; - private Integer coll1_id; + private Integer coll1_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { StrTestEntity.class, SetJoinColumnRefCollEntity.class }; - } + return new Class[] {StrTestEntity.class, SetJoinColumnRefCollEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - StrTestEntity str1 = new StrTestEntity("str1"); - StrTestEntity str2 = new StrTestEntity("str2"); + StrTestEntity str1 = new StrTestEntity( "str1" ); + StrTestEntity str2 = new StrTestEntity( "str2" ); - SetJoinColumnRefCollEntity coll1 = new SetJoinColumnRefCollEntity(3, "coll1"); + SetJoinColumnRefCollEntity coll1 = new SetJoinColumnRefCollEntity( 3, "coll1" ); - // Revision 1 - em.getTransaction().begin(); + // Revision 1 + em.getTransaction().begin(); - em.persist(str1); - em.persist(str2); + em.persist( str1 ); + em.persist( str2 ); - coll1.setCollection(new HashSet()); - coll1.getCollection().add(str1); - em.persist(coll1); + coll1.setCollection( new HashSet() ); + coll1.getCollection().add( str1 ); + em.persist( coll1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); + // Revision 2 + em.getTransaction().begin(); - str2 = em.find(StrTestEntity.class, str2.getId()); - coll1 = em.find(SetJoinColumnRefCollEntity.class, coll1.getId()); + str2 = em.find( StrTestEntity.class, str2.getId() ); + coll1 = em.find( SetJoinColumnRefCollEntity.class, coll1.getId() ); - coll1.getCollection().add(str2); + coll1.getCollection().add( str2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 - em.getTransaction().begin(); + // Revision 3 + em.getTransaction().begin(); - str1 = em.find(StrTestEntity.class, str1.getId()); - coll1 = em.find(SetJoinColumnRefCollEntity.class, coll1.getId()); + str1 = em.find( StrTestEntity.class, str1.getId() ); + coll1 = em.find( SetJoinColumnRefCollEntity.class, coll1.getId() ); - coll1.getCollection().remove(str1); + coll1.getCollection().remove( str1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 4 - em.getTransaction().begin(); + // Revision 4 + em.getTransaction().begin(); - coll1 = em.find(SetJoinColumnRefCollEntity.class, coll1.getId()); + coll1 = em.find( SetJoinColumnRefCollEntity.class, coll1.getId() ); - coll1.getCollection().clear(); + coll1.getCollection().clear(); - em.getTransaction().commit(); + em.getTransaction().commit(); - // + // - str1_id = str1.getId(); - str2_id = str2.getId(); + str1_id = str1.getId(); + str2_id = str2.getId(); - coll1_id = coll1.getId(); - } + coll1_id = coll1.getId(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2, 3, 4).equals(getAuditReader().getRevisions(SetJoinColumnRefCollEntity.class, coll1_id)); + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2, 3, 4 ).equals( + getAuditReader().getRevisions( + SetJoinColumnRefCollEntity.class, + coll1_id + ) + ); - assert Arrays.asList(1).equals(getAuditReader().getRevisions(StrTestEntity.class, str1_id)); - assert Arrays.asList(1).equals(getAuditReader().getRevisions(StrTestEntity.class, str2_id)); - } + assert Arrays.asList( 1 ).equals( getAuditReader().getRevisions( StrTestEntity.class, str1_id ) ); + assert Arrays.asList( 1 ).equals( getAuditReader().getRevisions( StrTestEntity.class, str2_id ) ); + } - @Test - public void testHistoryOfColl1() { - StrTestEntity str1 = getEntityManager().find(StrTestEntity.class, str1_id); - StrTestEntity str2 = getEntityManager().find(StrTestEntity.class, str2_id); + @Test + public void testHistoryOfColl1() { + StrTestEntity str1 = getEntityManager().find( StrTestEntity.class, str1_id ); + StrTestEntity str2 = getEntityManager().find( StrTestEntity.class, str2_id ); - SetJoinColumnRefCollEntity rev1 = getAuditReader().find(SetJoinColumnRefCollEntity.class, coll1_id, 1); - SetJoinColumnRefCollEntity rev2 = getAuditReader().find(SetJoinColumnRefCollEntity.class, coll1_id, 2); - SetJoinColumnRefCollEntity rev3 = getAuditReader().find(SetJoinColumnRefCollEntity.class, coll1_id, 3); - SetJoinColumnRefCollEntity rev4 = getAuditReader().find(SetJoinColumnRefCollEntity.class, coll1_id, 4); + SetJoinColumnRefCollEntity rev1 = getAuditReader().find( SetJoinColumnRefCollEntity.class, coll1_id, 1 ); + SetJoinColumnRefCollEntity rev2 = getAuditReader().find( SetJoinColumnRefCollEntity.class, coll1_id, 2 ); + SetJoinColumnRefCollEntity rev3 = getAuditReader().find( SetJoinColumnRefCollEntity.class, coll1_id, 3 ); + SetJoinColumnRefCollEntity rev4 = getAuditReader().find( SetJoinColumnRefCollEntity.class, coll1_id, 4 ); - assert rev1.getCollection().equals(TestTools.makeSet(str1)); - assert rev2.getCollection().equals(TestTools.makeSet(str1, str2)); - assert rev3.getCollection().equals(TestTools.makeSet(str2)); - assert rev4.getCollection().equals(TestTools.makeSet()); + assert rev1.getCollection().equals( TestTools.makeSet( str1 ) ); + assert rev2.getCollection().equals( TestTools.makeSet( str1, str2 ) ); + assert rev3.getCollection().equals( TestTools.makeSet( str2 ) ); + assert rev4.getCollection().equals( TestTools.makeSet() ); - assert "coll1".equals(rev1.getData()); - assert "coll1".equals(rev2.getData()); - assert "coll1".equals(rev3.getData()); - assert "coll1".equals(rev4.getData()); - } + assert "coll1".equals( rev1.getData() ); + assert "coll1".equals( rev2.getData() ); + assert "coll1".equals( rev3.getData() ); + assert "coll1".equals( rev4.getData() ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/DataChangesDetachedSet.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/DataChangesDetachedSet.java index 0f7645de26..6b1ddccf32 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/DataChangesDetachedSet.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/DataChangesDetachedSet.java @@ -23,11 +23,9 @@ */ package org.hibernate.envers.test.integration.onetomany.detached; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.HashSet; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; @@ -35,74 +33,76 @@ import org.hibernate.envers.test.entities.StrTestEntity; import org.hibernate.envers.test.entities.onetomany.detached.SetRefCollEntity; import org.hibernate.envers.test.tools.TestTools; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ -public class DataChangesDetachedSet extends BaseEnversJPAFunctionalTestCase { - private Integer str1_id; +public class DataChangesDetachedSet extends BaseEnversJPAFunctionalTestCase { + private Integer str1_id; - private Integer coll1_id; + private Integer coll1_id; - @Override - protected Class[] getAnnotatedClasses() { - return new Class[]{StrTestEntity.class, SetRefCollEntity.class}; - } + @Override + protected Class[] getAnnotatedClasses() { + return new Class[] {StrTestEntity.class, SetRefCollEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - StrTestEntity str1 = new StrTestEntity("str1"); + StrTestEntity str1 = new StrTestEntity( "str1" ); - SetRefCollEntity coll1 = new SetRefCollEntity(3, "coll1"); + SetRefCollEntity coll1 = new SetRefCollEntity( 3, "coll1" ); - // Revision 1 - em.getTransaction().begin(); + // Revision 1 + em.getTransaction().begin(); - em.persist(str1); + em.persist( str1 ); - coll1.setCollection(new HashSet()); - em.persist(coll1); + coll1.setCollection( new HashSet() ); + em.persist( coll1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); + // Revision 2 + em.getTransaction().begin(); - str1 = em.find(StrTestEntity.class, str1.getId()); - coll1 = em.find(SetRefCollEntity.class, coll1.getId()); + str1 = em.find( StrTestEntity.class, str1.getId() ); + coll1 = em.find( SetRefCollEntity.class, coll1.getId() ); - coll1.getCollection().add(str1); - coll1.setData("coll2"); + coll1.getCollection().add( str1 ); + coll1.setData( "coll2" ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // + // - str1_id = str1.getId(); + str1_id = str1.getId(); - coll1_id = coll1.getId(); - } + coll1_id = coll1.getId(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(SetRefCollEntity.class, coll1_id)); + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( SetRefCollEntity.class, coll1_id ) ); - assert Arrays.asList(1).equals(getAuditReader().getRevisions(StrTestEntity.class, str1_id)); - } + assert Arrays.asList( 1 ).equals( getAuditReader().getRevisions( StrTestEntity.class, str1_id ) ); + } - @Test - public void testHistoryOfColl1() { - StrTestEntity str1 = getEntityManager().find(StrTestEntity.class, str1_id); + @Test + public void testHistoryOfColl1() { + StrTestEntity str1 = getEntityManager().find( StrTestEntity.class, str1_id ); - SetRefCollEntity rev1 = getAuditReader().find(SetRefCollEntity.class, coll1_id, 1); - SetRefCollEntity rev2 = getAuditReader().find(SetRefCollEntity.class, coll1_id, 2); + SetRefCollEntity rev1 = getAuditReader().find( SetRefCollEntity.class, coll1_id, 1 ); + SetRefCollEntity rev2 = getAuditReader().find( SetRefCollEntity.class, coll1_id, 2 ); - assert rev1.getCollection().equals(TestTools.makeSet()); - assert rev2.getCollection().equals(TestTools.makeSet(str1)); + assert rev1.getCollection().equals( TestTools.makeSet() ); + assert rev2.getCollection().equals( TestTools.makeSet( str1 ) ); - assert "coll1".equals(rev1.getData()); - assert "coll2".equals(rev2.getData()); - } + assert "coll1".equals( rev1.getData() ); + assert "coll2".equals( rev2.getData() ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/DetachedTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/DetachedTest.java index 10e7c65af7..e8d508ef1e 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/DetachedTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/DetachedTest.java @@ -2,14 +2,15 @@ package org.hibernate.envers.test.integration.onetomany.detached; import java.util.Arrays; -import junit.framework.Assert; -import org.junit.Test; - import org.hibernate.Session; import org.hibernate.envers.test.BaseEnversFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrTestEntity; import org.hibernate.envers.test.entities.onetomany.detached.ListRefCollEntity; + +import org.junit.Test; +import junit.framework.Assert; + import org.hibernate.testing.TestForIssue; /** @@ -21,7 +22,7 @@ public class DetachedTest extends BaseEnversFunctionalTestCase { @Override protected Class[] getAnnotatedClasses() { - return new Class[] { ListRefCollEntity.class, StrTestEntity.class }; + return new Class[] {ListRefCollEntity.class, StrTestEntity.class}; } @Test @@ -56,7 +57,12 @@ public class DetachedTest extends BaseEnversFunctionalTestCase { @Test public void testRevisionsCounts() { - Assert.assertEquals( Arrays.asList( 1, 2 ), getAuditReader().getRevisions( ListRefCollEntity.class, parentId ) ); + Assert.assertEquals( + Arrays.asList( 1, 2 ), getAuditReader().getRevisions( + ListRefCollEntity.class, + parentId + ) + ); Assert.assertEquals( Arrays.asList( 1 ), getAuditReader().getRevisions( StrTestEntity.class, childId ) ); } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/DoubleDetachedSet.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/DoubleDetachedSet.java index f3e8a324cd..f819ca2094 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/DoubleDetachedSet.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/DoubleDetachedSet.java @@ -23,11 +23,9 @@ */ package org.hibernate.envers.test.integration.onetomany.detached; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.HashSet; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; @@ -35,98 +33,105 @@ import org.hibernate.envers.test.entities.StrTestEntity; import org.hibernate.envers.test.entities.onetomany.detached.DoubleSetRefCollEntity; import org.hibernate.envers.test.tools.TestTools; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class DoubleDetachedSet extends BaseEnversJPAFunctionalTestCase { - private Integer str1_id; - private Integer str2_id; + private Integer str1_id; + private Integer str2_id; - private Integer coll1_id; + private Integer coll1_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { StrTestEntity.class, DoubleSetRefCollEntity.class }; - } + return new Class[] {StrTestEntity.class, DoubleSetRefCollEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - StrTestEntity str1 = new StrTestEntity("str1"); - StrTestEntity str2 = new StrTestEntity("str2"); + StrTestEntity str1 = new StrTestEntity( "str1" ); + StrTestEntity str2 = new StrTestEntity( "str2" ); - DoubleSetRefCollEntity coll1 = new DoubleSetRefCollEntity(3, "coll1"); + DoubleSetRefCollEntity coll1 = new DoubleSetRefCollEntity( 3, "coll1" ); - // Revision 1 - em.getTransaction().begin(); + // Revision 1 + em.getTransaction().begin(); - em.persist(str1); - em.persist(str2); + em.persist( str1 ); + em.persist( str2 ); - coll1.setCollection(new HashSet()); - coll1.getCollection().add(str1); - em.persist(coll1); + coll1.setCollection( new HashSet() ); + coll1.getCollection().add( str1 ); + em.persist( coll1 ); - coll1.setCollection2(new HashSet()); - coll1.getCollection2().add(str2); - em.persist(coll1); + coll1.setCollection2( new HashSet() ); + coll1.getCollection2().add( str2 ); + em.persist( coll1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); + // Revision 2 + em.getTransaction().begin(); - str2 = em.find(StrTestEntity.class, str2.getId()); - coll1 = em.find(DoubleSetRefCollEntity.class, coll1.getId()); + str2 = em.find( StrTestEntity.class, str2.getId() ); + coll1 = em.find( DoubleSetRefCollEntity.class, coll1.getId() ); - coll1.getCollection().add(str2); + coll1.getCollection().add( str2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 - em.getTransaction().begin(); + // Revision 3 + em.getTransaction().begin(); - str1 = em.find(StrTestEntity.class, str1.getId()); - coll1 = em.find(DoubleSetRefCollEntity.class, coll1.getId()); + str1 = em.find( StrTestEntity.class, str1.getId() ); + coll1 = em.find( DoubleSetRefCollEntity.class, coll1.getId() ); - coll1.getCollection().remove(str1); - coll1.getCollection2().add(str1); + coll1.getCollection().remove( str1 ); + coll1.getCollection2().add( str1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // + // - str1_id = str1.getId(); - str2_id = str2.getId(); + str1_id = str1.getId(); + str2_id = str2.getId(); - coll1_id = coll1.getId(); - } + coll1_id = coll1.getId(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2, 3).equals(getAuditReader().getRevisions(DoubleSetRefCollEntity.class, coll1_id)); + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2, 3 ).equals( + getAuditReader().getRevisions( + DoubleSetRefCollEntity.class, + coll1_id + ) + ); - assert Arrays.asList(1).equals(getAuditReader().getRevisions(StrTestEntity.class, str1_id)); - assert Arrays.asList(1).equals(getAuditReader().getRevisions(StrTestEntity.class, str2_id)); - } + assert Arrays.asList( 1 ).equals( getAuditReader().getRevisions( StrTestEntity.class, str1_id ) ); + assert Arrays.asList( 1 ).equals( getAuditReader().getRevisions( StrTestEntity.class, str2_id ) ); + } - @Test - public void testHistoryOfColl1() { - StrTestEntity str1 = getEntityManager().find(StrTestEntity.class, str1_id); - StrTestEntity str2 = getEntityManager().find(StrTestEntity.class, str2_id); + @Test + public void testHistoryOfColl1() { + StrTestEntity str1 = getEntityManager().find( StrTestEntity.class, str1_id ); + StrTestEntity str2 = getEntityManager().find( StrTestEntity.class, str2_id ); - DoubleSetRefCollEntity rev1 = getAuditReader().find(DoubleSetRefCollEntity.class, coll1_id, 1); - DoubleSetRefCollEntity rev2 = getAuditReader().find(DoubleSetRefCollEntity.class, coll1_id, 2); - DoubleSetRefCollEntity rev3 = getAuditReader().find(DoubleSetRefCollEntity.class, coll1_id, 3); + DoubleSetRefCollEntity rev1 = getAuditReader().find( DoubleSetRefCollEntity.class, coll1_id, 1 ); + DoubleSetRefCollEntity rev2 = getAuditReader().find( DoubleSetRefCollEntity.class, coll1_id, 2 ); + DoubleSetRefCollEntity rev3 = getAuditReader().find( DoubleSetRefCollEntity.class, coll1_id, 3 ); - assert rev1.getCollection().equals(TestTools.makeSet(str1)); - assert rev2.getCollection().equals(TestTools.makeSet(str1, str2)); - assert rev3.getCollection().equals(TestTools.makeSet(str2)); + assert rev1.getCollection().equals( TestTools.makeSet( str1 ) ); + assert rev2.getCollection().equals( TestTools.makeSet( str1, str2 ) ); + assert rev3.getCollection().equals( TestTools.makeSet( str2 ) ); - assert rev1.getCollection2().equals(TestTools.makeSet(str2)); - assert rev2.getCollection2().equals(TestTools.makeSet(str2)); - assert rev3.getCollection2().equals(TestTools.makeSet(str1, str2)); - } + assert rev1.getCollection2().equals( TestTools.makeSet( str2 ) ); + assert rev2.getCollection2().equals( TestTools.makeSet( str2 ) ); + assert rev3.getCollection2().equals( TestTools.makeSet( str1, str2 ) ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/DoubleJoinColumnBidirectionalList.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/DoubleJoinColumnBidirectionalList.java index ce923fdfbd..a25e76827b 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/DoubleJoinColumnBidirectionalList.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/DoubleJoinColumnBidirectionalList.java @@ -23,10 +23,8 @@ */ package org.hibernate.envers.test.integration.onetomany.detached; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; @@ -34,6 +32,8 @@ import org.hibernate.envers.test.entities.onetomany.detached.DoubleListJoinColum import org.hibernate.envers.test.entities.onetomany.detached.DoubleListJoinColumnBidirectionalRefEdEntity2; import org.hibernate.envers.test.entities.onetomany.detached.DoubleListJoinColumnBidirectionalRefIngEntity; +import org.junit.Test; + import static org.hibernate.envers.test.tools.TestTools.checkList; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -41,16 +41,17 @@ import static org.junit.Assert.assertTrue; /** * Test for a double "fake" bidirectional mapping where one side uses @OneToMany+@JoinColumn * (and thus owns the relation), and the other uses a @ManyToOne(insertable=false, updatable=false). + * * @author Adam Warski (adam at warski dot org) */ public class DoubleJoinColumnBidirectionalList extends BaseEnversJPAFunctionalTestCase { - private Integer ed1_1_id; - private Integer ed2_1_id; - private Integer ed1_2_id; - private Integer ed2_2_id; + private Integer ed1_1_id; + private Integer ed2_1_id; + private Integer ed1_2_id; + private Integer ed2_2_id; - private Integer ing1_id; - private Integer ing2_id; + private Integer ing1_id; + private Integer ing2_id; @Override protected Class[] getAnnotatedClasses() { @@ -59,247 +60,445 @@ public class DoubleJoinColumnBidirectionalList extends BaseEnversJPAFunctionalTe DoubleListJoinColumnBidirectionalRefEdEntity1.class, DoubleListJoinColumnBidirectionalRefEdEntity2.class }; - } + } - @Test - @Priority(10) - public void createData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void createData() { + EntityManager em = getEntityManager(); - DoubleListJoinColumnBidirectionalRefEdEntity1 ed1_1 = new DoubleListJoinColumnBidirectionalRefEdEntity1("ed1_1", null); - DoubleListJoinColumnBidirectionalRefEdEntity1 ed1_2 = new DoubleListJoinColumnBidirectionalRefEdEntity1("ed1_2", null); + DoubleListJoinColumnBidirectionalRefEdEntity1 ed1_1 = new DoubleListJoinColumnBidirectionalRefEdEntity1( + "ed1_1", + null + ); + DoubleListJoinColumnBidirectionalRefEdEntity1 ed1_2 = new DoubleListJoinColumnBidirectionalRefEdEntity1( + "ed1_2", + null + ); - DoubleListJoinColumnBidirectionalRefEdEntity2 ed2_1 = new DoubleListJoinColumnBidirectionalRefEdEntity2("ed2_1", null); - DoubleListJoinColumnBidirectionalRefEdEntity2 ed2_2 = new DoubleListJoinColumnBidirectionalRefEdEntity2("ed2_2", null); + DoubleListJoinColumnBidirectionalRefEdEntity2 ed2_1 = new DoubleListJoinColumnBidirectionalRefEdEntity2( + "ed2_1", + null + ); + DoubleListJoinColumnBidirectionalRefEdEntity2 ed2_2 = new DoubleListJoinColumnBidirectionalRefEdEntity2( + "ed2_2", + null + ); - DoubleListJoinColumnBidirectionalRefIngEntity ing1 = new DoubleListJoinColumnBidirectionalRefIngEntity("coll1"); - DoubleListJoinColumnBidirectionalRefIngEntity ing2 = new DoubleListJoinColumnBidirectionalRefIngEntity("coll2"); + DoubleListJoinColumnBidirectionalRefIngEntity ing1 = new DoubleListJoinColumnBidirectionalRefIngEntity( "coll1" ); + DoubleListJoinColumnBidirectionalRefIngEntity ing2 = new DoubleListJoinColumnBidirectionalRefIngEntity( "coll2" ); - // Revision 1 (ing1: ed1_1, ed2_1, ing2: ed1_2, ed2_2) - em.getTransaction().begin(); + // Revision 1 (ing1: ed1_1, ed2_1, ing2: ed1_2, ed2_2) + em.getTransaction().begin(); - ing1.getReferences1().add(ed1_1); - ing1.getReferences2().add(ed2_1); + ing1.getReferences1().add( ed1_1 ); + ing1.getReferences2().add( ed2_1 ); - ing2.getReferences1().add(ed1_2); - ing2.getReferences2().add(ed2_2); + ing2.getReferences1().add( ed1_2 ); + ing2.getReferences2().add( ed2_2 ); - em.persist(ed1_1); - em.persist(ed1_2); - em.persist(ed2_1); - em.persist(ed2_2); - em.persist(ing1); - em.persist(ing2); + em.persist( ed1_1 ); + em.persist( ed1_2 ); + em.persist( ed2_1 ); + em.persist( ed2_2 ); + em.persist( ing1 ); + em.persist( ing2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 (ing1: ed1_1, ed1_2, ed2_1, ed2_2) - em.getTransaction().begin(); + // Revision 2 (ing1: ed1_1, ed1_2, ed2_1, ed2_2) + em.getTransaction().begin(); - ing1 = em.find(DoubleListJoinColumnBidirectionalRefIngEntity.class, ing1.getId()); - ing2 = em.find(DoubleListJoinColumnBidirectionalRefIngEntity.class, ing2.getId()); - ed1_1 = em.find(DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_1.getId()); - ed1_2 = em.find(DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_2.getId()); - ed2_1 = em.find(DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_1.getId()); - ed2_2 = em.find(DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_2.getId()); + ing1 = em.find( DoubleListJoinColumnBidirectionalRefIngEntity.class, ing1.getId() ); + ing2 = em.find( DoubleListJoinColumnBidirectionalRefIngEntity.class, ing2.getId() ); + ed1_1 = em.find( DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_1.getId() ); + ed1_2 = em.find( DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_2.getId() ); + ed2_1 = em.find( DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_1.getId() ); + ed2_2 = em.find( DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_2.getId() ); - ing2.getReferences1().clear(); - ing2.getReferences2().clear(); + ing2.getReferences1().clear(); + ing2.getReferences2().clear(); - ing1.getReferences1().add(ed1_2); - ing1.getReferences2().add(ed2_2); + ing1.getReferences1().add( ed1_2 ); + ing1.getReferences2().add( ed2_2 ); - em.getTransaction().commit(); - em.clear(); + em.getTransaction().commit(); + em.clear(); - // Revision 3 (ing1: ed1_1, ed1_2, ed2_1, ed2_2) - em.getTransaction().begin(); + // Revision 3 (ing1: ed1_1, ed1_2, ed2_1, ed2_2) + em.getTransaction().begin(); - ing1 = em.find(DoubleListJoinColumnBidirectionalRefIngEntity.class, ing1.getId()); - ing2 = em.find(DoubleListJoinColumnBidirectionalRefIngEntity.class, ing2.getId()); - ed1_1 = em.find(DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_1.getId()); - ed1_2 = em.find(DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_2.getId()); - ed2_1 = em.find(DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_1.getId()); - ed2_2 = em.find(DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_2.getId()); + ing1 = em.find( DoubleListJoinColumnBidirectionalRefIngEntity.class, ing1.getId() ); + ing2 = em.find( DoubleListJoinColumnBidirectionalRefIngEntity.class, ing2.getId() ); + ed1_1 = em.find( DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_1.getId() ); + ed1_2 = em.find( DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_2.getId() ); + ed2_1 = em.find( DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_1.getId() ); + ed2_2 = em.find( DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_2.getId() ); - ed1_1.setData("ed1_1 bis"); - ed2_2.setData("ed2_2 bis"); + ed1_1.setData( "ed1_1 bis" ); + ed2_2.setData( "ed2_2 bis" ); - em.getTransaction().commit(); - em.clear(); + em.getTransaction().commit(); + em.clear(); - // Revision 4 (ing1: ed2_2, ing2: ed2_1, ed1_1, ed1_2) - em.getTransaction().begin(); + // Revision 4 (ing1: ed2_2, ing2: ed2_1, ed1_1, ed1_2) + em.getTransaction().begin(); - ing1 = em.find(DoubleListJoinColumnBidirectionalRefIngEntity.class, ing1.getId()); - ing2 = em.find(DoubleListJoinColumnBidirectionalRefIngEntity.class, ing2.getId()); - ed1_1 = em.find(DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_1.getId()); - ed1_2 = em.find(DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_2.getId()); - ed2_1 = em.find(DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_1.getId()); - ed2_2 = em.find(DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_2.getId()); + ing1 = em.find( DoubleListJoinColumnBidirectionalRefIngEntity.class, ing1.getId() ); + ing2 = em.find( DoubleListJoinColumnBidirectionalRefIngEntity.class, ing2.getId() ); + ed1_1 = em.find( DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_1.getId() ); + ed1_2 = em.find( DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_2.getId() ); + ed2_1 = em.find( DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_1.getId() ); + ed2_2 = em.find( DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_2.getId() ); - ing1.getReferences1().clear(); - ing2.getReferences1().add(ed1_1); - ing2.getReferences1().add(ed1_2); + ing1.getReferences1().clear(); + ing2.getReferences1().add( ed1_1 ); + ing2.getReferences1().add( ed1_2 ); - ing1.getReferences2().remove(ed2_1); - ing2.getReferences2().add(ed2_1); + ing1.getReferences2().remove( ed2_1 ); + ing2.getReferences2().add( ed2_1 ); - em.getTransaction().commit(); - em.clear(); + em.getTransaction().commit(); + em.clear(); - // + // - ing1_id = ing1.getId(); - ing2_id = ing2.getId(); + ing1_id = ing1.getId(); + ing2_id = ing2.getId(); - ed1_1_id = ed1_1.getId(); - ed1_2_id = ed1_2.getId(); - ed2_1_id = ed2_1.getId(); - ed2_2_id = ed2_2.getId(); - } + ed1_1_id = ed1_1.getId(); + ed1_2_id = ed1_2.getId(); + ed2_1_id = ed2_1.getId(); + ed2_2_id = ed2_2.getId(); + } - @Test - public void testRevisionsCounts() { - assertEquals(Arrays.asList(1, 2, 4), getAuditReader().getRevisions(DoubleListJoinColumnBidirectionalRefIngEntity.class, ing1_id)); - assertEquals(Arrays.asList(1, 2, 4), getAuditReader().getRevisions(DoubleListJoinColumnBidirectionalRefIngEntity.class, ing2_id)); + @Test + public void testRevisionsCounts() { + assertEquals( + Arrays.asList( 1, 2, 4 ), getAuditReader().getRevisions( + DoubleListJoinColumnBidirectionalRefIngEntity.class, + ing1_id + ) + ); + assertEquals( + Arrays.asList( 1, 2, 4 ), getAuditReader().getRevisions( + DoubleListJoinColumnBidirectionalRefIngEntity.class, + ing2_id + ) + ); - assertEquals(Arrays.asList(1, 3, 4), getAuditReader().getRevisions(DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_1_id)); - assertEquals(Arrays.asList(1, 2, 4), getAuditReader().getRevisions(DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_2_id)); + assertEquals( + Arrays.asList( 1, 3, 4 ), getAuditReader().getRevisions( + DoubleListJoinColumnBidirectionalRefEdEntity1.class, + ed1_1_id + ) + ); + assertEquals( + Arrays.asList( 1, 2, 4 ), getAuditReader().getRevisions( + DoubleListJoinColumnBidirectionalRefEdEntity1.class, + ed1_2_id + ) + ); - assertEquals(Arrays.asList(1, 4), getAuditReader().getRevisions(DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_1_id)); - assertEquals(Arrays.asList(1, 2, 3), getAuditReader().getRevisions(DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_2_id)); - } + assertEquals( + Arrays.asList( 1, 4 ), getAuditReader().getRevisions( + DoubleListJoinColumnBidirectionalRefEdEntity2.class, + ed2_1_id + ) + ); + assertEquals( + Arrays.asList( 1, 2, 3 ), getAuditReader().getRevisions( + DoubleListJoinColumnBidirectionalRefEdEntity2.class, + ed2_2_id + ) + ); + } - @Test - public void testHistoryOfIng1() { - DoubleListJoinColumnBidirectionalRefEdEntity1 ed1_1_fromRev1 = new DoubleListJoinColumnBidirectionalRefEdEntity1(ed1_1_id, "ed1_1", null); - DoubleListJoinColumnBidirectionalRefEdEntity1 ed1_1_fromRev3 = new DoubleListJoinColumnBidirectionalRefEdEntity1(ed1_1_id, "ed1_1 bis", null); - DoubleListJoinColumnBidirectionalRefEdEntity1 ed1_2 = getEntityManager().find(DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_2_id); - DoubleListJoinColumnBidirectionalRefEdEntity2 ed2_1 = getEntityManager().find(DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_1_id); - DoubleListJoinColumnBidirectionalRefEdEntity2 ed2_2_fromRev1 = new DoubleListJoinColumnBidirectionalRefEdEntity2(ed2_2_id, "ed2_2", null); - DoubleListJoinColumnBidirectionalRefEdEntity2 ed2_2_fromRev3 = new DoubleListJoinColumnBidirectionalRefEdEntity2(ed2_2_id, "ed2_2 bis", null); + @Test + public void testHistoryOfIng1() { + DoubleListJoinColumnBidirectionalRefEdEntity1 ed1_1_fromRev1 = new DoubleListJoinColumnBidirectionalRefEdEntity1( + ed1_1_id, + "ed1_1", + null + ); + DoubleListJoinColumnBidirectionalRefEdEntity1 ed1_1_fromRev3 = new DoubleListJoinColumnBidirectionalRefEdEntity1( + ed1_1_id, + "ed1_1 bis", + null + ); + DoubleListJoinColumnBidirectionalRefEdEntity1 ed1_2 = getEntityManager().find( + DoubleListJoinColumnBidirectionalRefEdEntity1.class, + ed1_2_id + ); + DoubleListJoinColumnBidirectionalRefEdEntity2 ed2_1 = getEntityManager().find( + DoubleListJoinColumnBidirectionalRefEdEntity2.class, + ed2_1_id + ); + DoubleListJoinColumnBidirectionalRefEdEntity2 ed2_2_fromRev1 = new DoubleListJoinColumnBidirectionalRefEdEntity2( + ed2_2_id, + "ed2_2", + null + ); + DoubleListJoinColumnBidirectionalRefEdEntity2 ed2_2_fromRev3 = new DoubleListJoinColumnBidirectionalRefEdEntity2( + ed2_2_id, + "ed2_2 bis", + null + ); - DoubleListJoinColumnBidirectionalRefIngEntity rev1 = getAuditReader().find(DoubleListJoinColumnBidirectionalRefIngEntity.class, ing1_id, 1); - DoubleListJoinColumnBidirectionalRefIngEntity rev2 = getAuditReader().find(DoubleListJoinColumnBidirectionalRefIngEntity.class, ing1_id, 2); - DoubleListJoinColumnBidirectionalRefIngEntity rev3 = getAuditReader().find(DoubleListJoinColumnBidirectionalRefIngEntity.class, ing1_id, 3); - DoubleListJoinColumnBidirectionalRefIngEntity rev4 = getAuditReader().find(DoubleListJoinColumnBidirectionalRefIngEntity.class, ing1_id, 4); + DoubleListJoinColumnBidirectionalRefIngEntity rev1 = getAuditReader().find( + DoubleListJoinColumnBidirectionalRefIngEntity.class, + ing1_id, + 1 + ); + DoubleListJoinColumnBidirectionalRefIngEntity rev2 = getAuditReader().find( + DoubleListJoinColumnBidirectionalRefIngEntity.class, + ing1_id, + 2 + ); + DoubleListJoinColumnBidirectionalRefIngEntity rev3 = getAuditReader().find( + DoubleListJoinColumnBidirectionalRefIngEntity.class, + ing1_id, + 3 + ); + DoubleListJoinColumnBidirectionalRefIngEntity rev4 = getAuditReader().find( + DoubleListJoinColumnBidirectionalRefIngEntity.class, + ing1_id, + 4 + ); - assertTrue(checkList(rev1.getReferences1(), ed1_1_fromRev1)); - assertTrue(checkList(rev2.getReferences1(), ed1_1_fromRev1, ed1_2)); - assertTrue(checkList(rev3.getReferences1(), ed1_1_fromRev3, ed1_2)); - assertTrue(checkList(rev4.getReferences1())); + assertTrue( checkList( rev1.getReferences1(), ed1_1_fromRev1 ) ); + assertTrue( checkList( rev2.getReferences1(), ed1_1_fromRev1, ed1_2 ) ); + assertTrue( checkList( rev3.getReferences1(), ed1_1_fromRev3, ed1_2 ) ); + assertTrue( checkList( rev4.getReferences1() ) ); - assertTrue(checkList(rev1.getReferences2(), ed2_1)); - assertTrue(checkList(rev2.getReferences2(), ed2_1, ed2_2_fromRev1)); - assertTrue(checkList(rev3.getReferences2(), ed2_1, ed2_2_fromRev3)); - assertTrue(checkList(rev4.getReferences2(), ed2_2_fromRev3)); - } + assertTrue( checkList( rev1.getReferences2(), ed2_1 ) ); + assertTrue( checkList( rev2.getReferences2(), ed2_1, ed2_2_fromRev1 ) ); + assertTrue( checkList( rev3.getReferences2(), ed2_1, ed2_2_fromRev3 ) ); + assertTrue( checkList( rev4.getReferences2(), ed2_2_fromRev3 ) ); + } - @Test - public void testHistoryOfIng2() { - DoubleListJoinColumnBidirectionalRefEdEntity1 ed1_1_fromRev3 = new DoubleListJoinColumnBidirectionalRefEdEntity1(ed1_1_id, "ed1_1 bis", null); - DoubleListJoinColumnBidirectionalRefEdEntity1 ed1_2 = getEntityManager().find(DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_2_id); - DoubleListJoinColumnBidirectionalRefEdEntity2 ed2_1 = getEntityManager().find(DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_1_id); - DoubleListJoinColumnBidirectionalRefEdEntity2 ed2_2_fromRev1 = new DoubleListJoinColumnBidirectionalRefEdEntity2(ed2_2_id, "ed2_2", null); + @Test + public void testHistoryOfIng2() { + DoubleListJoinColumnBidirectionalRefEdEntity1 ed1_1_fromRev3 = new DoubleListJoinColumnBidirectionalRefEdEntity1( + ed1_1_id, + "ed1_1 bis", + null + ); + DoubleListJoinColumnBidirectionalRefEdEntity1 ed1_2 = getEntityManager().find( + DoubleListJoinColumnBidirectionalRefEdEntity1.class, + ed1_2_id + ); + DoubleListJoinColumnBidirectionalRefEdEntity2 ed2_1 = getEntityManager().find( + DoubleListJoinColumnBidirectionalRefEdEntity2.class, + ed2_1_id + ); + DoubleListJoinColumnBidirectionalRefEdEntity2 ed2_2_fromRev1 = new DoubleListJoinColumnBidirectionalRefEdEntity2( + ed2_2_id, + "ed2_2", + null + ); - DoubleListJoinColumnBidirectionalRefIngEntity rev1 = getAuditReader().find(DoubleListJoinColumnBidirectionalRefIngEntity.class, ing2_id, 1); - DoubleListJoinColumnBidirectionalRefIngEntity rev2 = getAuditReader().find(DoubleListJoinColumnBidirectionalRefIngEntity.class, ing2_id, 2); - DoubleListJoinColumnBidirectionalRefIngEntity rev3 = getAuditReader().find(DoubleListJoinColumnBidirectionalRefIngEntity.class, ing2_id, 3); - DoubleListJoinColumnBidirectionalRefIngEntity rev4 = getAuditReader().find(DoubleListJoinColumnBidirectionalRefIngEntity.class, ing2_id, 4); + DoubleListJoinColumnBidirectionalRefIngEntity rev1 = getAuditReader().find( + DoubleListJoinColumnBidirectionalRefIngEntity.class, + ing2_id, + 1 + ); + DoubleListJoinColumnBidirectionalRefIngEntity rev2 = getAuditReader().find( + DoubleListJoinColumnBidirectionalRefIngEntity.class, + ing2_id, + 2 + ); + DoubleListJoinColumnBidirectionalRefIngEntity rev3 = getAuditReader().find( + DoubleListJoinColumnBidirectionalRefIngEntity.class, + ing2_id, + 3 + ); + DoubleListJoinColumnBidirectionalRefIngEntity rev4 = getAuditReader().find( + DoubleListJoinColumnBidirectionalRefIngEntity.class, + ing2_id, + 4 + ); - assertTrue(checkList(rev1.getReferences1(), ed1_2)); - assertTrue(checkList(rev2.getReferences1())); - assertTrue(checkList(rev3.getReferences1())); - assertTrue(checkList(rev4.getReferences1(), ed1_1_fromRev3, ed1_2)); + assertTrue( checkList( rev1.getReferences1(), ed1_2 ) ); + assertTrue( checkList( rev2.getReferences1() ) ); + assertTrue( checkList( rev3.getReferences1() ) ); + assertTrue( checkList( rev4.getReferences1(), ed1_1_fromRev3, ed1_2 ) ); - assertTrue(checkList(rev1.getReferences2(), ed2_2_fromRev1)); - assertTrue(checkList(rev2.getReferences2())); - assertTrue(checkList(rev3.getReferences2())); - assertTrue(checkList(rev4.getReferences2(), ed2_1)); - } + assertTrue( checkList( rev1.getReferences2(), ed2_2_fromRev1 ) ); + assertTrue( checkList( rev2.getReferences2() ) ); + assertTrue( checkList( rev3.getReferences2() ) ); + assertTrue( checkList( rev4.getReferences2(), ed2_1 ) ); + } - @Test - public void testHistoryOfEd1_1() { - DoubleListJoinColumnBidirectionalRefIngEntity ing1 = getEntityManager().find(DoubleListJoinColumnBidirectionalRefIngEntity.class, ing1_id); - DoubleListJoinColumnBidirectionalRefIngEntity ing2 = getEntityManager().find(DoubleListJoinColumnBidirectionalRefIngEntity.class, ing2_id); + @Test + public void testHistoryOfEd1_1() { + DoubleListJoinColumnBidirectionalRefIngEntity ing1 = getEntityManager().find( + DoubleListJoinColumnBidirectionalRefIngEntity.class, + ing1_id + ); + DoubleListJoinColumnBidirectionalRefIngEntity ing2 = getEntityManager().find( + DoubleListJoinColumnBidirectionalRefIngEntity.class, + ing2_id + ); - DoubleListJoinColumnBidirectionalRefEdEntity1 rev1 = getAuditReader().find(DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_1_id, 1); - DoubleListJoinColumnBidirectionalRefEdEntity1 rev2 = getAuditReader().find(DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_1_id, 2); - DoubleListJoinColumnBidirectionalRefEdEntity1 rev3 = getAuditReader().find(DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_1_id, 3); - DoubleListJoinColumnBidirectionalRefEdEntity1 rev4 = getAuditReader().find(DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_1_id, 4); + DoubleListJoinColumnBidirectionalRefEdEntity1 rev1 = getAuditReader().find( + DoubleListJoinColumnBidirectionalRefEdEntity1.class, + ed1_1_id, + 1 + ); + DoubleListJoinColumnBidirectionalRefEdEntity1 rev2 = getAuditReader().find( + DoubleListJoinColumnBidirectionalRefEdEntity1.class, + ed1_1_id, + 2 + ); + DoubleListJoinColumnBidirectionalRefEdEntity1 rev3 = getAuditReader().find( + DoubleListJoinColumnBidirectionalRefEdEntity1.class, + ed1_1_id, + 3 + ); + DoubleListJoinColumnBidirectionalRefEdEntity1 rev4 = getAuditReader().find( + DoubleListJoinColumnBidirectionalRefEdEntity1.class, + ed1_1_id, + 4 + ); - assertTrue(rev1.getOwner().equals(ing1)); - assertTrue(rev2.getOwner().equals(ing1)); - assertTrue(rev3.getOwner().equals(ing1)); - assertTrue(rev4.getOwner().equals(ing2)); + assertTrue( rev1.getOwner().equals( ing1 ) ); + assertTrue( rev2.getOwner().equals( ing1 ) ); + assertTrue( rev3.getOwner().equals( ing1 ) ); + assertTrue( rev4.getOwner().equals( ing2 ) ); - assertEquals(rev1.getData(), "ed1_1"); - assertEquals(rev2.getData(), "ed1_1"); - assertEquals(rev3.getData(), "ed1_1 bis"); - assertEquals(rev4.getData(), "ed1_1 bis"); - } + assertEquals( rev1.getData(), "ed1_1" ); + assertEquals( rev2.getData(), "ed1_1" ); + assertEquals( rev3.getData(), "ed1_1 bis" ); + assertEquals( rev4.getData(), "ed1_1 bis" ); + } - @Test - public void testHistoryOfEd1_2() { - DoubleListJoinColumnBidirectionalRefIngEntity ing1 = getEntityManager().find(DoubleListJoinColumnBidirectionalRefIngEntity.class, ing1_id); - DoubleListJoinColumnBidirectionalRefIngEntity ing2 = getEntityManager().find(DoubleListJoinColumnBidirectionalRefIngEntity.class, ing2_id); + @Test + public void testHistoryOfEd1_2() { + DoubleListJoinColumnBidirectionalRefIngEntity ing1 = getEntityManager().find( + DoubleListJoinColumnBidirectionalRefIngEntity.class, + ing1_id + ); + DoubleListJoinColumnBidirectionalRefIngEntity ing2 = getEntityManager().find( + DoubleListJoinColumnBidirectionalRefIngEntity.class, + ing2_id + ); - DoubleListJoinColumnBidirectionalRefEdEntity1 rev1 = getAuditReader().find(DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_2_id, 1); - DoubleListJoinColumnBidirectionalRefEdEntity1 rev2 = getAuditReader().find(DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_2_id, 2); - DoubleListJoinColumnBidirectionalRefEdEntity1 rev3 = getAuditReader().find(DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_2_id, 3); - DoubleListJoinColumnBidirectionalRefEdEntity1 rev4 = getAuditReader().find(DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_2_id, 4); + DoubleListJoinColumnBidirectionalRefEdEntity1 rev1 = getAuditReader().find( + DoubleListJoinColumnBidirectionalRefEdEntity1.class, + ed1_2_id, + 1 + ); + DoubleListJoinColumnBidirectionalRefEdEntity1 rev2 = getAuditReader().find( + DoubleListJoinColumnBidirectionalRefEdEntity1.class, + ed1_2_id, + 2 + ); + DoubleListJoinColumnBidirectionalRefEdEntity1 rev3 = getAuditReader().find( + DoubleListJoinColumnBidirectionalRefEdEntity1.class, + ed1_2_id, + 3 + ); + DoubleListJoinColumnBidirectionalRefEdEntity1 rev4 = getAuditReader().find( + DoubleListJoinColumnBidirectionalRefEdEntity1.class, + ed1_2_id, + 4 + ); - assertTrue(rev1.getOwner().equals(ing2)); - assertTrue(rev2.getOwner().equals(ing1)); - assertTrue(rev3.getOwner().equals(ing1)); - assertTrue(rev4.getOwner().equals(ing2)); + assertTrue( rev1.getOwner().equals( ing2 ) ); + assertTrue( rev2.getOwner().equals( ing1 ) ); + assertTrue( rev3.getOwner().equals( ing1 ) ); + assertTrue( rev4.getOwner().equals( ing2 ) ); - assertEquals(rev1.getData(), "ed1_2"); - assertEquals(rev2.getData(), "ed1_2"); - assertEquals(rev3.getData(), "ed1_2"); - assertEquals(rev4.getData(), "ed1_2"); - } + assertEquals( rev1.getData(), "ed1_2" ); + assertEquals( rev2.getData(), "ed1_2" ); + assertEquals( rev3.getData(), "ed1_2" ); + assertEquals( rev4.getData(), "ed1_2" ); + } - @Test - public void testHistoryOfEd2_1() { - DoubleListJoinColumnBidirectionalRefIngEntity ing1 = getEntityManager().find(DoubleListJoinColumnBidirectionalRefIngEntity.class, ing1_id); - DoubleListJoinColumnBidirectionalRefIngEntity ing2 = getEntityManager().find(DoubleListJoinColumnBidirectionalRefIngEntity.class, ing2_id); + @Test + public void testHistoryOfEd2_1() { + DoubleListJoinColumnBidirectionalRefIngEntity ing1 = getEntityManager().find( + DoubleListJoinColumnBidirectionalRefIngEntity.class, + ing1_id + ); + DoubleListJoinColumnBidirectionalRefIngEntity ing2 = getEntityManager().find( + DoubleListJoinColumnBidirectionalRefIngEntity.class, + ing2_id + ); - DoubleListJoinColumnBidirectionalRefEdEntity2 rev1 = getAuditReader().find(DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_1_id, 1); - DoubleListJoinColumnBidirectionalRefEdEntity2 rev2 = getAuditReader().find(DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_1_id, 2); - DoubleListJoinColumnBidirectionalRefEdEntity2 rev3 = getAuditReader().find(DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_1_id, 3); - DoubleListJoinColumnBidirectionalRefEdEntity2 rev4 = getAuditReader().find(DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_1_id, 4); + DoubleListJoinColumnBidirectionalRefEdEntity2 rev1 = getAuditReader().find( + DoubleListJoinColumnBidirectionalRefEdEntity2.class, + ed2_1_id, + 1 + ); + DoubleListJoinColumnBidirectionalRefEdEntity2 rev2 = getAuditReader().find( + DoubleListJoinColumnBidirectionalRefEdEntity2.class, + ed2_1_id, + 2 + ); + DoubleListJoinColumnBidirectionalRefEdEntity2 rev3 = getAuditReader().find( + DoubleListJoinColumnBidirectionalRefEdEntity2.class, + ed2_1_id, + 3 + ); + DoubleListJoinColumnBidirectionalRefEdEntity2 rev4 = getAuditReader().find( + DoubleListJoinColumnBidirectionalRefEdEntity2.class, + ed2_1_id, + 4 + ); - assertTrue(rev1.getOwner().equals(ing1)); - assertTrue(rev2.getOwner().equals(ing1)); - assertTrue(rev3.getOwner().equals(ing1)); - assertTrue(rev4.getOwner().equals(ing2)); + assertTrue( rev1.getOwner().equals( ing1 ) ); + assertTrue( rev2.getOwner().equals( ing1 ) ); + assertTrue( rev3.getOwner().equals( ing1 ) ); + assertTrue( rev4.getOwner().equals( ing2 ) ); - assertEquals(rev1.getData(), "ed2_1"); - assertEquals(rev2.getData(), "ed2_1"); - assertEquals(rev3.getData(), "ed2_1"); - assertEquals(rev4.getData(), "ed2_1"); - } + assertEquals( rev1.getData(), "ed2_1" ); + assertEquals( rev2.getData(), "ed2_1" ); + assertEquals( rev3.getData(), "ed2_1" ); + assertEquals( rev4.getData(), "ed2_1" ); + } - @Test - public void testHistoryOfEd2_2() { - DoubleListJoinColumnBidirectionalRefIngEntity ing1 = getEntityManager().find(DoubleListJoinColumnBidirectionalRefIngEntity.class, ing1_id); - DoubleListJoinColumnBidirectionalRefIngEntity ing2 = getEntityManager().find(DoubleListJoinColumnBidirectionalRefIngEntity.class, ing2_id); + @Test + public void testHistoryOfEd2_2() { + DoubleListJoinColumnBidirectionalRefIngEntity ing1 = getEntityManager().find( + DoubleListJoinColumnBidirectionalRefIngEntity.class, + ing1_id + ); + DoubleListJoinColumnBidirectionalRefIngEntity ing2 = getEntityManager().find( + DoubleListJoinColumnBidirectionalRefIngEntity.class, + ing2_id + ); - DoubleListJoinColumnBidirectionalRefEdEntity2 rev1 = getAuditReader().find(DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_2_id, 1); - DoubleListJoinColumnBidirectionalRefEdEntity2 rev2 = getAuditReader().find(DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_2_id, 2); - DoubleListJoinColumnBidirectionalRefEdEntity2 rev3 = getAuditReader().find(DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_2_id, 3); - DoubleListJoinColumnBidirectionalRefEdEntity2 rev4 = getAuditReader().find(DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_2_id, 4); + DoubleListJoinColumnBidirectionalRefEdEntity2 rev1 = getAuditReader().find( + DoubleListJoinColumnBidirectionalRefEdEntity2.class, + ed2_2_id, + 1 + ); + DoubleListJoinColumnBidirectionalRefEdEntity2 rev2 = getAuditReader().find( + DoubleListJoinColumnBidirectionalRefEdEntity2.class, + ed2_2_id, + 2 + ); + DoubleListJoinColumnBidirectionalRefEdEntity2 rev3 = getAuditReader().find( + DoubleListJoinColumnBidirectionalRefEdEntity2.class, + ed2_2_id, + 3 + ); + DoubleListJoinColumnBidirectionalRefEdEntity2 rev4 = getAuditReader().find( + DoubleListJoinColumnBidirectionalRefEdEntity2.class, + ed2_2_id, + 4 + ); - assertTrue(rev1.getOwner().equals(ing2)); - assertTrue(rev2.getOwner().equals(ing1)); - assertTrue(rev3.getOwner().equals(ing1)); - assertTrue(rev4.getOwner().equals(ing1)); + assertTrue( rev1.getOwner().equals( ing2 ) ); + assertTrue( rev2.getOwner().equals( ing1 ) ); + assertTrue( rev3.getOwner().equals( ing1 ) ); + assertTrue( rev4.getOwner().equals( ing1 ) ); - assertEquals(rev1.getData(), "ed2_2"); - assertEquals(rev2.getData(), "ed2_2"); - assertEquals(rev3.getData(), "ed2_2 bis"); - assertEquals(rev4.getData(), "ed2_2 bis"); - } + assertEquals( rev1.getData(), "ed2_2" ); + assertEquals( rev2.getData(), "ed2_2" ); + assertEquals( rev3.getData(), "ed2_2 bis" ); + assertEquals( rev4.getData(), "ed2_2 bis" ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/IndexedJoinColumnBidirectionalList.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/IndexedJoinColumnBidirectionalList.java index ea186da718..970415b94d 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/IndexedJoinColumnBidirectionalList.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/IndexedJoinColumnBidirectionalList.java @@ -23,231 +23,380 @@ */ package org.hibernate.envers.test.integration.onetomany.detached; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.onetomany.detached.IndexedListJoinColumnBidirectionalRefEdEntity; import org.hibernate.envers.test.entities.onetomany.detached.IndexedListJoinColumnBidirectionalRefIngEntity; +import org.junit.Test; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; /** * Test for a "fake" bidirectional mapping where one side uses @OneToMany+@JoinColumn (and thus owns the relatin), * and the other uses a @ManyToOne(insertable=false, updatable=false). + * * @author Adam Warski (adam at warski dot org) */ public class IndexedJoinColumnBidirectionalList extends BaseEnversJPAFunctionalTestCase { - private Integer ed1_id; - private Integer ed2_id; - private Integer ed3_id; + private Integer ed1_id; + private Integer ed2_id; + private Integer ed3_id; - private Integer ing1_id; - private Integer ing2_id; + private Integer ing1_id; + private Integer ing2_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { IndexedListJoinColumnBidirectionalRefIngEntity.class, IndexedListJoinColumnBidirectionalRefEdEntity.class }; - } + return new Class[] { + IndexedListJoinColumnBidirectionalRefIngEntity.class, + IndexedListJoinColumnBidirectionalRefEdEntity.class + }; + } - @Test - @Priority(10) - public void createData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void createData() { + EntityManager em = getEntityManager(); - IndexedListJoinColumnBidirectionalRefEdEntity ed1 = new IndexedListJoinColumnBidirectionalRefEdEntity("ed1", null); - IndexedListJoinColumnBidirectionalRefEdEntity ed2 = new IndexedListJoinColumnBidirectionalRefEdEntity("ed2", null); - IndexedListJoinColumnBidirectionalRefEdEntity ed3 = new IndexedListJoinColumnBidirectionalRefEdEntity("ed3", null); + IndexedListJoinColumnBidirectionalRefEdEntity ed1 = new IndexedListJoinColumnBidirectionalRefEdEntity( + "ed1", + null + ); + IndexedListJoinColumnBidirectionalRefEdEntity ed2 = new IndexedListJoinColumnBidirectionalRefEdEntity( + "ed2", + null + ); + IndexedListJoinColumnBidirectionalRefEdEntity ed3 = new IndexedListJoinColumnBidirectionalRefEdEntity( + "ed3", + null + ); - IndexedListJoinColumnBidirectionalRefIngEntity ing1 = new IndexedListJoinColumnBidirectionalRefIngEntity("coll1", ed1, ed2, ed3); - IndexedListJoinColumnBidirectionalRefIngEntity ing2 = new IndexedListJoinColumnBidirectionalRefIngEntity("coll1"); + IndexedListJoinColumnBidirectionalRefIngEntity ing1 = new IndexedListJoinColumnBidirectionalRefIngEntity( + "coll1", + ed1, + ed2, + ed3 + ); + IndexedListJoinColumnBidirectionalRefIngEntity ing2 = new IndexedListJoinColumnBidirectionalRefIngEntity( + "coll1" + ); - // Revision 1 (ing1: ed1, ed2, ed3) - em.getTransaction().begin(); + // Revision 1 (ing1: ed1, ed2, ed3) + em.getTransaction().begin(); - em.persist(ed1); - em.persist(ed2); - em.persist(ed3); - em.persist(ing1); - em.persist(ing2); + em.persist( ed1 ); + em.persist( ed2 ); + em.persist( ed3 ); + em.persist( ing1 ); + em.persist( ing2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 (ing1: ed1, ed3, ing2: ed2) - em.getTransaction().begin(); + // Revision 2 (ing1: ed1, ed3, ing2: ed2) + em.getTransaction().begin(); - ing1 = em.find(IndexedListJoinColumnBidirectionalRefIngEntity.class, ing1.getId()); - ing2 = em.find(IndexedListJoinColumnBidirectionalRefIngEntity.class, ing2.getId()); - ed2 = em.find(IndexedListJoinColumnBidirectionalRefEdEntity.class, ed2.getId()); + ing1 = em.find( IndexedListJoinColumnBidirectionalRefIngEntity.class, ing1.getId() ); + ing2 = em.find( IndexedListJoinColumnBidirectionalRefIngEntity.class, ing2.getId() ); + ed2 = em.find( IndexedListJoinColumnBidirectionalRefEdEntity.class, ed2.getId() ); - ing1.getReferences().remove(ed2); - ing2.getReferences().add(ed2); + ing1.getReferences().remove( ed2 ); + ing2.getReferences().add( ed2 ); - em.getTransaction().commit(); - em.clear(); + em.getTransaction().commit(); + em.clear(); - // Revision 3 (ing1: ed3, ed1, ing2: ed2) - em.getTransaction().begin(); + // Revision 3 (ing1: ed3, ed1, ing2: ed2) + em.getTransaction().begin(); - ing1 = em.find(IndexedListJoinColumnBidirectionalRefIngEntity.class, ing1.getId()); - ing2 = em.find(IndexedListJoinColumnBidirectionalRefIngEntity.class, ing2.getId()); - ed1 = em.find(IndexedListJoinColumnBidirectionalRefEdEntity.class, ed1.getId()); - ed2 = em.find(IndexedListJoinColumnBidirectionalRefEdEntity.class, ed2.getId()); - ed3 = em.find(IndexedListJoinColumnBidirectionalRefEdEntity.class, ed3.getId()); + ing1 = em.find( IndexedListJoinColumnBidirectionalRefIngEntity.class, ing1.getId() ); + ing2 = em.find( IndexedListJoinColumnBidirectionalRefIngEntity.class, ing2.getId() ); + ed1 = em.find( IndexedListJoinColumnBidirectionalRefEdEntity.class, ed1.getId() ); + ed2 = em.find( IndexedListJoinColumnBidirectionalRefEdEntity.class, ed2.getId() ); + ed3 = em.find( IndexedListJoinColumnBidirectionalRefEdEntity.class, ed3.getId() ); - ing1.getReferences().remove(ed3); - ing1.getReferences().add(0, ed3); + ing1.getReferences().remove( ed3 ); + ing1.getReferences().add( 0, ed3 ); - em.getTransaction().commit(); - em.clear(); + em.getTransaction().commit(); + em.clear(); - // Revision 4 (ing1: ed2, ed3, ed1) - em.getTransaction().begin(); + // Revision 4 (ing1: ed2, ed3, ed1) + em.getTransaction().begin(); - ing1 = em.find(IndexedListJoinColumnBidirectionalRefIngEntity.class, ing1.getId()); - ing2 = em.find(IndexedListJoinColumnBidirectionalRefIngEntity.class, ing2.getId()); - ed1 = em.find(IndexedListJoinColumnBidirectionalRefEdEntity.class, ed1.getId()); - ed2 = em.find(IndexedListJoinColumnBidirectionalRefEdEntity.class, ed2.getId()); - ed3 = em.find(IndexedListJoinColumnBidirectionalRefEdEntity.class, ed3.getId()); + ing1 = em.find( IndexedListJoinColumnBidirectionalRefIngEntity.class, ing1.getId() ); + ing2 = em.find( IndexedListJoinColumnBidirectionalRefIngEntity.class, ing2.getId() ); + ed1 = em.find( IndexedListJoinColumnBidirectionalRefEdEntity.class, ed1.getId() ); + ed2 = em.find( IndexedListJoinColumnBidirectionalRefEdEntity.class, ed2.getId() ); + ed3 = em.find( IndexedListJoinColumnBidirectionalRefEdEntity.class, ed3.getId() ); - ing2.getReferences().remove(ed2); - ing1.getReferences().add(0, ed2); + ing2.getReferences().remove( ed2 ); + ing1.getReferences().add( 0, ed2 ); - em.getTransaction().commit(); - em.clear(); + em.getTransaction().commit(); + em.clear(); - // + // - ing1_id = ing1.getId(); - ing2_id = ing2.getId(); + ing1_id = ing1.getId(); + ing2_id = ing2.getId(); - ed1_id = ed1.getId(); - ed2_id = ed2.getId(); - ed3_id = ed3.getId(); - } + ed1_id = ed1.getId(); + ed2_id = ed2.getId(); + ed3_id = ed3.getId(); + } - @Test - public void testRevisionsCounts() { - assertEquals(Arrays.asList(1, 2, 3, 4), getAuditReader().getRevisions(IndexedListJoinColumnBidirectionalRefIngEntity.class, ing1_id)); - assertEquals(Arrays.asList(1, 2, 4), getAuditReader().getRevisions(IndexedListJoinColumnBidirectionalRefIngEntity.class, ing2_id)); + @Test + public void testRevisionsCounts() { + assertEquals( + Arrays.asList( 1, 2, 3, 4 ), getAuditReader().getRevisions( + IndexedListJoinColumnBidirectionalRefIngEntity.class, + ing1_id + ) + ); + assertEquals( + Arrays.asList( 1, 2, 4 ), getAuditReader().getRevisions( + IndexedListJoinColumnBidirectionalRefIngEntity.class, + ing2_id + ) + ); - assertEquals(Arrays.asList(1, 3, 4), getAuditReader().getRevisions(IndexedListJoinColumnBidirectionalRefEdEntity.class, ed1_id)); - assertEquals(Arrays.asList(1, 2, 4), getAuditReader().getRevisions(IndexedListJoinColumnBidirectionalRefEdEntity.class, ed2_id)); - assertEquals(Arrays.asList(1, 2, 3, 4), getAuditReader().getRevisions(IndexedListJoinColumnBidirectionalRefEdEntity.class, ed3_id)); - } + assertEquals( + Arrays.asList( 1, 3, 4 ), getAuditReader().getRevisions( + IndexedListJoinColumnBidirectionalRefEdEntity.class, + ed1_id + ) + ); + assertEquals( + Arrays.asList( 1, 2, 4 ), getAuditReader().getRevisions( + IndexedListJoinColumnBidirectionalRefEdEntity.class, + ed2_id + ) + ); + assertEquals( + Arrays.asList( 1, 2, 3, 4 ), getAuditReader().getRevisions( + IndexedListJoinColumnBidirectionalRefEdEntity.class, + ed3_id + ) + ); + } - @Test - public void testHistoryOfIng1() { - IndexedListJoinColumnBidirectionalRefEdEntity ed1 = getEntityManager().find(IndexedListJoinColumnBidirectionalRefEdEntity.class, ed1_id); - IndexedListJoinColumnBidirectionalRefEdEntity ed2 = getEntityManager().find(IndexedListJoinColumnBidirectionalRefEdEntity.class, ed2_id); - IndexedListJoinColumnBidirectionalRefEdEntity ed3 = getEntityManager().find(IndexedListJoinColumnBidirectionalRefEdEntity.class, ed3_id); + @Test + public void testHistoryOfIng1() { + IndexedListJoinColumnBidirectionalRefEdEntity ed1 = getEntityManager().find( + IndexedListJoinColumnBidirectionalRefEdEntity.class, + ed1_id + ); + IndexedListJoinColumnBidirectionalRefEdEntity ed2 = getEntityManager().find( + IndexedListJoinColumnBidirectionalRefEdEntity.class, + ed2_id + ); + IndexedListJoinColumnBidirectionalRefEdEntity ed3 = getEntityManager().find( + IndexedListJoinColumnBidirectionalRefEdEntity.class, + ed3_id + ); - IndexedListJoinColumnBidirectionalRefIngEntity rev1 = getAuditReader().find(IndexedListJoinColumnBidirectionalRefIngEntity.class, ing1_id, 1); - IndexedListJoinColumnBidirectionalRefIngEntity rev2 = getAuditReader().find(IndexedListJoinColumnBidirectionalRefIngEntity.class, ing1_id, 2); - IndexedListJoinColumnBidirectionalRefIngEntity rev3 = getAuditReader().find(IndexedListJoinColumnBidirectionalRefIngEntity.class, ing1_id, 3); - IndexedListJoinColumnBidirectionalRefIngEntity rev4 = getAuditReader().find(IndexedListJoinColumnBidirectionalRefIngEntity.class, ing1_id, 4); + IndexedListJoinColumnBidirectionalRefIngEntity rev1 = getAuditReader().find( + IndexedListJoinColumnBidirectionalRefIngEntity.class, + ing1_id, + 1 + ); + IndexedListJoinColumnBidirectionalRefIngEntity rev2 = getAuditReader().find( + IndexedListJoinColumnBidirectionalRefIngEntity.class, + ing1_id, + 2 + ); + IndexedListJoinColumnBidirectionalRefIngEntity rev3 = getAuditReader().find( + IndexedListJoinColumnBidirectionalRefIngEntity.class, + ing1_id, + 3 + ); + IndexedListJoinColumnBidirectionalRefIngEntity rev4 = getAuditReader().find( + IndexedListJoinColumnBidirectionalRefIngEntity.class, + ing1_id, + 4 + ); - assertEquals(rev1.getReferences().size(), 3); - assertEquals(rev1.getReferences().get(0), ed1); - assertEquals(rev1.getReferences().get(1), ed2); - assertEquals(rev1.getReferences().get(2), ed3); + assertEquals( rev1.getReferences().size(), 3 ); + assertEquals( rev1.getReferences().get( 0 ), ed1 ); + assertEquals( rev1.getReferences().get( 1 ), ed2 ); + assertEquals( rev1.getReferences().get( 2 ), ed3 ); - assertEquals(rev2.getReferences().size(), 2); - assertEquals(rev2.getReferences().get(0), ed1); - assertEquals(rev2.getReferences().get(1), ed3); + assertEquals( rev2.getReferences().size(), 2 ); + assertEquals( rev2.getReferences().get( 0 ), ed1 ); + assertEquals( rev2.getReferences().get( 1 ), ed3 ); - assertEquals(rev3.getReferences().size(), 2); - assertEquals(rev3.getReferences().get(0), ed3); - assertEquals(rev3.getReferences().get(1), ed1); + assertEquals( rev3.getReferences().size(), 2 ); + assertEquals( rev3.getReferences().get( 0 ), ed3 ); + assertEquals( rev3.getReferences().get( 1 ), ed1 ); - assertEquals(rev4.getReferences().size(), 3); - assertEquals(rev4.getReferences().get(0), ed2); - assertEquals(rev4.getReferences().get(1), ed3); - assertEquals(rev4.getReferences().get(2), ed1); - } + assertEquals( rev4.getReferences().size(), 3 ); + assertEquals( rev4.getReferences().get( 0 ), ed2 ); + assertEquals( rev4.getReferences().get( 1 ), ed3 ); + assertEquals( rev4.getReferences().get( 2 ), ed1 ); + } - @Test - public void testHistoryOfIng2() { - IndexedListJoinColumnBidirectionalRefEdEntity ed2 = getEntityManager().find(IndexedListJoinColumnBidirectionalRefEdEntity.class, ed2_id); + @Test + public void testHistoryOfIng2() { + IndexedListJoinColumnBidirectionalRefEdEntity ed2 = getEntityManager().find( + IndexedListJoinColumnBidirectionalRefEdEntity.class, + ed2_id + ); - IndexedListJoinColumnBidirectionalRefIngEntity rev1 = getAuditReader().find(IndexedListJoinColumnBidirectionalRefIngEntity.class, ing2_id, 1); - IndexedListJoinColumnBidirectionalRefIngEntity rev2 = getAuditReader().find(IndexedListJoinColumnBidirectionalRefIngEntity.class, ing2_id, 2); - IndexedListJoinColumnBidirectionalRefIngEntity rev3 = getAuditReader().find(IndexedListJoinColumnBidirectionalRefIngEntity.class, ing2_id, 3); - IndexedListJoinColumnBidirectionalRefIngEntity rev4 = getAuditReader().find(IndexedListJoinColumnBidirectionalRefIngEntity.class, ing2_id, 4); + IndexedListJoinColumnBidirectionalRefIngEntity rev1 = getAuditReader().find( + IndexedListJoinColumnBidirectionalRefIngEntity.class, + ing2_id, + 1 + ); + IndexedListJoinColumnBidirectionalRefIngEntity rev2 = getAuditReader().find( + IndexedListJoinColumnBidirectionalRefIngEntity.class, + ing2_id, + 2 + ); + IndexedListJoinColumnBidirectionalRefIngEntity rev3 = getAuditReader().find( + IndexedListJoinColumnBidirectionalRefIngEntity.class, + ing2_id, + 3 + ); + IndexedListJoinColumnBidirectionalRefIngEntity rev4 = getAuditReader().find( + IndexedListJoinColumnBidirectionalRefIngEntity.class, + ing2_id, + 4 + ); - assertEquals(rev1.getReferences().size(), 0); + assertEquals( rev1.getReferences().size(), 0 ); - assertEquals(rev2.getReferences().size(), 1); - assertEquals(rev2.getReferences().get(0), ed2); + assertEquals( rev2.getReferences().size(), 1 ); + assertEquals( rev2.getReferences().get( 0 ), ed2 ); - assertEquals(rev3.getReferences().size(), 1); - assertEquals(rev3.getReferences().get(0), ed2); + assertEquals( rev3.getReferences().size(), 1 ); + assertEquals( rev3.getReferences().get( 0 ), ed2 ); - assertEquals(rev4.getReferences().size(), 0); - } + assertEquals( rev4.getReferences().size(), 0 ); + } - @Test - public void testHistoryOfEd1() { - IndexedListJoinColumnBidirectionalRefIngEntity ing1 = getEntityManager().find(IndexedListJoinColumnBidirectionalRefIngEntity.class, ing1_id); + @Test + public void testHistoryOfEd1() { + IndexedListJoinColumnBidirectionalRefIngEntity ing1 = getEntityManager().find( + IndexedListJoinColumnBidirectionalRefIngEntity.class, + ing1_id + ); - IndexedListJoinColumnBidirectionalRefEdEntity rev1 = getAuditReader().find(IndexedListJoinColumnBidirectionalRefEdEntity.class, ed1_id, 1); - IndexedListJoinColumnBidirectionalRefEdEntity rev2 = getAuditReader().find(IndexedListJoinColumnBidirectionalRefEdEntity.class, ed1_id, 2); - IndexedListJoinColumnBidirectionalRefEdEntity rev3 = getAuditReader().find(IndexedListJoinColumnBidirectionalRefEdEntity.class, ed1_id, 3); - IndexedListJoinColumnBidirectionalRefEdEntity rev4 = getAuditReader().find(IndexedListJoinColumnBidirectionalRefEdEntity.class, ed1_id, 4); + IndexedListJoinColumnBidirectionalRefEdEntity rev1 = getAuditReader().find( + IndexedListJoinColumnBidirectionalRefEdEntity.class, + ed1_id, + 1 + ); + IndexedListJoinColumnBidirectionalRefEdEntity rev2 = getAuditReader().find( + IndexedListJoinColumnBidirectionalRefEdEntity.class, + ed1_id, + 2 + ); + IndexedListJoinColumnBidirectionalRefEdEntity rev3 = getAuditReader().find( + IndexedListJoinColumnBidirectionalRefEdEntity.class, + ed1_id, + 3 + ); + IndexedListJoinColumnBidirectionalRefEdEntity rev4 = getAuditReader().find( + IndexedListJoinColumnBidirectionalRefEdEntity.class, + ed1_id, + 4 + ); - assertTrue(rev1.getOwner().equals(ing1)); - assertTrue(rev2.getOwner().equals(ing1)); - assertTrue(rev3.getOwner().equals(ing1)); - assertTrue(rev4.getOwner().equals(ing1)); + assertTrue( rev1.getOwner().equals( ing1 ) ); + assertTrue( rev2.getOwner().equals( ing1 ) ); + assertTrue( rev3.getOwner().equals( ing1 ) ); + assertTrue( rev4.getOwner().equals( ing1 ) ); - assertEquals( rev1.getPosition(), Integer.valueOf( 0 ) ); - assertEquals( rev2.getPosition(), Integer.valueOf( 0 ) ); - assertEquals( rev3.getPosition(), Integer.valueOf( 1 ) ); - assertEquals( rev4.getPosition(), Integer.valueOf( 2 ) ); - } + assertEquals( rev1.getPosition(), Integer.valueOf( 0 ) ); + assertEquals( rev2.getPosition(), Integer.valueOf( 0 ) ); + assertEquals( rev3.getPosition(), Integer.valueOf( 1 ) ); + assertEquals( rev4.getPosition(), Integer.valueOf( 2 ) ); + } - @Test - public void testHistoryOfEd2() { - IndexedListJoinColumnBidirectionalRefIngEntity ing1 = getEntityManager().find(IndexedListJoinColumnBidirectionalRefIngEntity.class, ing1_id); - IndexedListJoinColumnBidirectionalRefIngEntity ing2 = getEntityManager().find(IndexedListJoinColumnBidirectionalRefIngEntity.class, ing2_id); + @Test + public void testHistoryOfEd2() { + IndexedListJoinColumnBidirectionalRefIngEntity ing1 = getEntityManager().find( + IndexedListJoinColumnBidirectionalRefIngEntity.class, + ing1_id + ); + IndexedListJoinColumnBidirectionalRefIngEntity ing2 = getEntityManager().find( + IndexedListJoinColumnBidirectionalRefIngEntity.class, + ing2_id + ); - IndexedListJoinColumnBidirectionalRefEdEntity rev1 = getAuditReader().find(IndexedListJoinColumnBidirectionalRefEdEntity.class, ed2_id, 1); - IndexedListJoinColumnBidirectionalRefEdEntity rev2 = getAuditReader().find(IndexedListJoinColumnBidirectionalRefEdEntity.class, ed2_id, 2); - IndexedListJoinColumnBidirectionalRefEdEntity rev3 = getAuditReader().find(IndexedListJoinColumnBidirectionalRefEdEntity.class, ed2_id, 3); - IndexedListJoinColumnBidirectionalRefEdEntity rev4 = getAuditReader().find(IndexedListJoinColumnBidirectionalRefEdEntity.class, ed2_id, 4); + IndexedListJoinColumnBidirectionalRefEdEntity rev1 = getAuditReader().find( + IndexedListJoinColumnBidirectionalRefEdEntity.class, + ed2_id, + 1 + ); + IndexedListJoinColumnBidirectionalRefEdEntity rev2 = getAuditReader().find( + IndexedListJoinColumnBidirectionalRefEdEntity.class, + ed2_id, + 2 + ); + IndexedListJoinColumnBidirectionalRefEdEntity rev3 = getAuditReader().find( + IndexedListJoinColumnBidirectionalRefEdEntity.class, + ed2_id, + 3 + ); + IndexedListJoinColumnBidirectionalRefEdEntity rev4 = getAuditReader().find( + IndexedListJoinColumnBidirectionalRefEdEntity.class, + ed2_id, + 4 + ); - assertTrue(rev1.getOwner().equals(ing1)); - assertTrue(rev2.getOwner().equals(ing2)); - assertTrue(rev3.getOwner().equals(ing2)); - assertTrue(rev4.getOwner().equals(ing1)); + assertTrue( rev1.getOwner().equals( ing1 ) ); + assertTrue( rev2.getOwner().equals( ing2 ) ); + assertTrue( rev3.getOwner().equals( ing2 ) ); + assertTrue( rev4.getOwner().equals( ing1 ) ); - assertEquals( rev1.getPosition(), Integer.valueOf( 1 ) ); - assertEquals( rev2.getPosition(), Integer.valueOf( 0 ) ); - assertEquals( rev3.getPosition(), Integer.valueOf( 0 ) ); - assertEquals( rev4.getPosition(), Integer.valueOf( 0 ) ); - } + assertEquals( rev1.getPosition(), Integer.valueOf( 1 ) ); + assertEquals( rev2.getPosition(), Integer.valueOf( 0 ) ); + assertEquals( rev3.getPosition(), Integer.valueOf( 0 ) ); + assertEquals( rev4.getPosition(), Integer.valueOf( 0 ) ); + } - @Test - public void testHistoryOfEd3() { - IndexedListJoinColumnBidirectionalRefIngEntity ing1 = getEntityManager().find(IndexedListJoinColumnBidirectionalRefIngEntity.class, ing1_id); + @Test + public void testHistoryOfEd3() { + IndexedListJoinColumnBidirectionalRefIngEntity ing1 = getEntityManager().find( + IndexedListJoinColumnBidirectionalRefIngEntity.class, + ing1_id + ); - IndexedListJoinColumnBidirectionalRefEdEntity rev1 = getAuditReader().find(IndexedListJoinColumnBidirectionalRefEdEntity.class, ed3_id, 1); - IndexedListJoinColumnBidirectionalRefEdEntity rev2 = getAuditReader().find(IndexedListJoinColumnBidirectionalRefEdEntity.class, ed3_id, 2); - IndexedListJoinColumnBidirectionalRefEdEntity rev3 = getAuditReader().find(IndexedListJoinColumnBidirectionalRefEdEntity.class, ed3_id, 3); - IndexedListJoinColumnBidirectionalRefEdEntity rev4 = getAuditReader().find(IndexedListJoinColumnBidirectionalRefEdEntity.class, ed3_id, 4); + IndexedListJoinColumnBidirectionalRefEdEntity rev1 = getAuditReader().find( + IndexedListJoinColumnBidirectionalRefEdEntity.class, + ed3_id, + 1 + ); + IndexedListJoinColumnBidirectionalRefEdEntity rev2 = getAuditReader().find( + IndexedListJoinColumnBidirectionalRefEdEntity.class, + ed3_id, + 2 + ); + IndexedListJoinColumnBidirectionalRefEdEntity rev3 = getAuditReader().find( + IndexedListJoinColumnBidirectionalRefEdEntity.class, + ed3_id, + 3 + ); + IndexedListJoinColumnBidirectionalRefEdEntity rev4 = getAuditReader().find( + IndexedListJoinColumnBidirectionalRefEdEntity.class, + ed3_id, + 4 + ); - assertTrue(rev1.getOwner().equals(ing1)); - assertTrue(rev2.getOwner().equals(ing1)); - assertTrue(rev3.getOwner().equals(ing1)); - assertTrue(rev4.getOwner().equals(ing1)); + assertTrue( rev1.getOwner().equals( ing1 ) ); + assertTrue( rev2.getOwner().equals( ing1 ) ); + assertTrue( rev3.getOwner().equals( ing1 ) ); + assertTrue( rev4.getOwner().equals( ing1 ) ); - assertEquals( rev1.getPosition(), Integer.valueOf( 2 ) ); - assertEquals( rev2.getPosition(), Integer.valueOf( 1 ) ); - assertEquals( rev3.getPosition(), Integer.valueOf( 0 ) ); - assertEquals( rev4.getPosition(), Integer.valueOf( 1 ) ); - } + assertEquals( rev1.getPosition(), Integer.valueOf( 2 ) ); + assertEquals( rev2.getPosition(), Integer.valueOf( 1 ) ); + assertEquals( rev3.getPosition(), Integer.valueOf( 0 ) ); + assertEquals( rev4.getPosition(), Integer.valueOf( 1 ) ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/InheritanceIndexedJoinColumnBidirectionalList.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/InheritanceIndexedJoinColumnBidirectionalList.java index a9845ad1f1..5439ce127f 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/InheritanceIndexedJoinColumnBidirectionalList.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/InheritanceIndexedJoinColumnBidirectionalList.java @@ -23,10 +23,8 @@ */ package org.hibernate.envers.test.integration.onetomany.detached; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; @@ -34,21 +32,24 @@ import org.hibernate.envers.test.entities.onetomany.detached.inheritance.ChildIn import org.hibernate.envers.test.entities.onetomany.detached.inheritance.ParentIndexedListJoinColumnBidirectionalRefIngEntity; import org.hibernate.envers.test.entities.onetomany.detached.inheritance.ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity; +import org.junit.Test; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; /** * Test for a "fake" bidirectional mapping where one side uses @OneToMany+@JoinColumn (and thus owns the relation), * in the parent entity, and the other uses a @ManyToOne(insertable=false, updatable=false). + * * @author Adam Warski (adam at warski dot org) */ public class InheritanceIndexedJoinColumnBidirectionalList extends BaseEnversJPAFunctionalTestCase { - private Integer ed1_id; - private Integer ed2_id; - private Integer ed3_id; + private Integer ed1_id; + private Integer ed2_id; + private Integer ed3_id; - private Integer ing1_id; - private Integer ing2_id; + private Integer ing1_id; + private Integer ing2_id; @Override protected Class[] getAnnotatedClasses() { @@ -57,202 +58,349 @@ public class InheritanceIndexedJoinColumnBidirectionalList extends BaseEnversJPA ChildIndexedListJoinColumnBidirectionalRefIngEntity.class, ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class }; - } + } - @Test - @Priority(10) - public void createData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void createData() { + EntityManager em = getEntityManager(); - ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity ed1 = new ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity("ed1", null); - ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity ed2 = new ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity("ed2", null); - ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity ed3 = new ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity("ed3", null); + ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity ed1 = new ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity( + "ed1", + null + ); + ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity ed2 = new ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity( + "ed2", + null + ); + ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity ed3 = new ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity( + "ed3", + null + ); - ChildIndexedListJoinColumnBidirectionalRefIngEntity ing1 = new ChildIndexedListJoinColumnBidirectionalRefIngEntity("coll1", "coll1bis", ed1, ed2, ed3); - ChildIndexedListJoinColumnBidirectionalRefIngEntity ing2 = new ChildIndexedListJoinColumnBidirectionalRefIngEntity("coll1", "coll1bis"); + ChildIndexedListJoinColumnBidirectionalRefIngEntity ing1 = new ChildIndexedListJoinColumnBidirectionalRefIngEntity( + "coll1", + "coll1bis", + ed1, + ed2, + ed3 + ); + ChildIndexedListJoinColumnBidirectionalRefIngEntity ing2 = new ChildIndexedListJoinColumnBidirectionalRefIngEntity( + "coll1", + "coll1bis" + ); - // Revision 1 (ing1: ed1, ed2, ed3) - em.getTransaction().begin(); + // Revision 1 (ing1: ed1, ed2, ed3) + em.getTransaction().begin(); - em.persist(ed1); - em.persist(ed2); - em.persist(ed3); - em.persist(ing1); - em.persist(ing2); + em.persist( ed1 ); + em.persist( ed2 ); + em.persist( ed3 ); + em.persist( ing1 ); + em.persist( ing2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 (ing1: ed1, ed3, ing2: ed2) - em.getTransaction().begin(); + // Revision 2 (ing1: ed1, ed3, ing2: ed2) + em.getTransaction().begin(); - ing1 = em.find(ChildIndexedListJoinColumnBidirectionalRefIngEntity.class, ing1.getId()); - ing2 = em.find(ChildIndexedListJoinColumnBidirectionalRefIngEntity.class, ing2.getId()); - ed2 = em.find(ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, ed2.getId()); + ing1 = em.find( ChildIndexedListJoinColumnBidirectionalRefIngEntity.class, ing1.getId() ); + ing2 = em.find( ChildIndexedListJoinColumnBidirectionalRefIngEntity.class, ing2.getId() ); + ed2 = em.find( ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, ed2.getId() ); - ing1.getReferences().remove(ed2); - ing2.getReferences().add(ed2); + ing1.getReferences().remove( ed2 ); + ing2.getReferences().add( ed2 ); - em.getTransaction().commit(); - em.clear(); + em.getTransaction().commit(); + em.clear(); - // Revision 3 (ing1: ed3, ed1, ing2: ed2) - em.getTransaction().begin(); + // Revision 3 (ing1: ed3, ed1, ing2: ed2) + em.getTransaction().begin(); - ing1 = em.find(ChildIndexedListJoinColumnBidirectionalRefIngEntity.class, ing1.getId()); - ing2 = em.find(ChildIndexedListJoinColumnBidirectionalRefIngEntity.class, ing2.getId()); - ed1 = em.find(ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, ed1.getId()); - ed2 = em.find(ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, ed2.getId()); - ed3 = em.find(ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, ed3.getId()); + ing1 = em.find( ChildIndexedListJoinColumnBidirectionalRefIngEntity.class, ing1.getId() ); + ing2 = em.find( ChildIndexedListJoinColumnBidirectionalRefIngEntity.class, ing2.getId() ); + ed1 = em.find( ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, ed1.getId() ); + ed2 = em.find( ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, ed2.getId() ); + ed3 = em.find( ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, ed3.getId() ); - ing1.getReferences().remove(ed3); - ing1.getReferences().add(0, ed3); + ing1.getReferences().remove( ed3 ); + ing1.getReferences().add( 0, ed3 ); - em.getTransaction().commit(); - em.clear(); + em.getTransaction().commit(); + em.clear(); - // Revision 4 (ing1: ed2, ed3, ed1) - em.getTransaction().begin(); + // Revision 4 (ing1: ed2, ed3, ed1) + em.getTransaction().begin(); - ing1 = em.find(ChildIndexedListJoinColumnBidirectionalRefIngEntity.class, ing1.getId()); - ing2 = em.find(ChildIndexedListJoinColumnBidirectionalRefIngEntity.class, ing2.getId()); - ed1 = em.find(ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, ed1.getId()); - ed2 = em.find(ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, ed2.getId()); - ed3 = em.find(ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, ed3.getId()); + ing1 = em.find( ChildIndexedListJoinColumnBidirectionalRefIngEntity.class, ing1.getId() ); + ing2 = em.find( ChildIndexedListJoinColumnBidirectionalRefIngEntity.class, ing2.getId() ); + ed1 = em.find( ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, ed1.getId() ); + ed2 = em.find( ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, ed2.getId() ); + ed3 = em.find( ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, ed3.getId() ); - ing2.getReferences().remove(ed2); - ing1.getReferences().add(0, ed2); + ing2.getReferences().remove( ed2 ); + ing1.getReferences().add( 0, ed2 ); - em.getTransaction().commit(); - em.clear(); + em.getTransaction().commit(); + em.clear(); - // + // - ing1_id = ing1.getId(); - ing2_id = ing2.getId(); + ing1_id = ing1.getId(); + ing2_id = ing2.getId(); - ed1_id = ed1.getId(); - ed2_id = ed2.getId(); - ed3_id = ed3.getId(); - } + ed1_id = ed1.getId(); + ed2_id = ed2.getId(); + ed3_id = ed3.getId(); + } - @Test - public void testRevisionsCounts() { - assertEquals(Arrays.asList(1, 2, 3, 4), getAuditReader().getRevisions(ChildIndexedListJoinColumnBidirectionalRefIngEntity.class, ing1_id)); - assertEquals(Arrays.asList(1, 2, 4), getAuditReader().getRevisions(ChildIndexedListJoinColumnBidirectionalRefIngEntity.class, ing2_id)); + @Test + public void testRevisionsCounts() { + assertEquals( + Arrays.asList( 1, 2, 3, 4 ), getAuditReader().getRevisions( + ChildIndexedListJoinColumnBidirectionalRefIngEntity.class, + ing1_id + ) + ); + assertEquals( + Arrays.asList( 1, 2, 4 ), getAuditReader().getRevisions( + ChildIndexedListJoinColumnBidirectionalRefIngEntity.class, + ing2_id + ) + ); - assertEquals(Arrays.asList(1, 3, 4), getAuditReader().getRevisions(ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, ed1_id)); - assertEquals(Arrays.asList(1, 2, 4), getAuditReader().getRevisions(ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, ed2_id)); - assertEquals(Arrays.asList(1, 2, 3, 4), getAuditReader().getRevisions(ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, ed3_id)); - } + assertEquals( + Arrays.asList( 1, 3, 4 ), getAuditReader().getRevisions( + ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, + ed1_id + ) + ); + assertEquals( + Arrays.asList( 1, 2, 4 ), getAuditReader().getRevisions( + ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, + ed2_id + ) + ); + assertEquals( + Arrays.asList( 1, 2, 3, 4 ), getAuditReader().getRevisions( + ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, + ed3_id + ) + ); + } - @Test - public void testHistoryOfIng1() { - ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity ed1 = getEntityManager().find(ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, ed1_id); - ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity ed2 = getEntityManager().find(ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, ed2_id); - ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity ed3 = getEntityManager().find(ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, ed3_id); + @Test + public void testHistoryOfIng1() { + ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity ed1 = getEntityManager().find( + ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, + ed1_id + ); + ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity ed2 = getEntityManager().find( + ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, + ed2_id + ); + ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity ed3 = getEntityManager().find( + ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, + ed3_id + ); - ChildIndexedListJoinColumnBidirectionalRefIngEntity rev1 = getAuditReader().find(ChildIndexedListJoinColumnBidirectionalRefIngEntity.class, ing1_id, 1); - ChildIndexedListJoinColumnBidirectionalRefIngEntity rev2 = getAuditReader().find(ChildIndexedListJoinColumnBidirectionalRefIngEntity.class, ing1_id, 2); - ChildIndexedListJoinColumnBidirectionalRefIngEntity rev3 = getAuditReader().find(ChildIndexedListJoinColumnBidirectionalRefIngEntity.class, ing1_id, 3); - ChildIndexedListJoinColumnBidirectionalRefIngEntity rev4 = getAuditReader().find(ChildIndexedListJoinColumnBidirectionalRefIngEntity.class, ing1_id, 4); + ChildIndexedListJoinColumnBidirectionalRefIngEntity rev1 = getAuditReader().find( + ChildIndexedListJoinColumnBidirectionalRefIngEntity.class, + ing1_id, + 1 + ); + ChildIndexedListJoinColumnBidirectionalRefIngEntity rev2 = getAuditReader().find( + ChildIndexedListJoinColumnBidirectionalRefIngEntity.class, + ing1_id, + 2 + ); + ChildIndexedListJoinColumnBidirectionalRefIngEntity rev3 = getAuditReader().find( + ChildIndexedListJoinColumnBidirectionalRefIngEntity.class, + ing1_id, + 3 + ); + ChildIndexedListJoinColumnBidirectionalRefIngEntity rev4 = getAuditReader().find( + ChildIndexedListJoinColumnBidirectionalRefIngEntity.class, + ing1_id, + 4 + ); - assertEquals(rev1.getReferences().size(), 3); - assertEquals(rev1.getReferences().get(0), ed1); - assertEquals(rev1.getReferences().get(1), ed2); - assertEquals(rev1.getReferences().get(2), ed3); + assertEquals( rev1.getReferences().size(), 3 ); + assertEquals( rev1.getReferences().get( 0 ), ed1 ); + assertEquals( rev1.getReferences().get( 1 ), ed2 ); + assertEquals( rev1.getReferences().get( 2 ), ed3 ); - assertEquals(rev2.getReferences().size(), 2); - assertEquals(rev2.getReferences().get(0), ed1); - assertEquals(rev2.getReferences().get(1), ed3); + assertEquals( rev2.getReferences().size(), 2 ); + assertEquals( rev2.getReferences().get( 0 ), ed1 ); + assertEquals( rev2.getReferences().get( 1 ), ed3 ); - assertEquals(rev3.getReferences().size(), 2); - assertEquals(rev3.getReferences().get(0), ed3); - assertEquals(rev3.getReferences().get(1), ed1); + assertEquals( rev3.getReferences().size(), 2 ); + assertEquals( rev3.getReferences().get( 0 ), ed3 ); + assertEquals( rev3.getReferences().get( 1 ), ed1 ); - assertEquals(rev4.getReferences().size(), 3); - assertEquals(rev4.getReferences().get(0), ed2); - assertEquals(rev4.getReferences().get(1), ed3); - assertEquals(rev4.getReferences().get(2), ed1); - } + assertEquals( rev4.getReferences().size(), 3 ); + assertEquals( rev4.getReferences().get( 0 ), ed2 ); + assertEquals( rev4.getReferences().get( 1 ), ed3 ); + assertEquals( rev4.getReferences().get( 2 ), ed1 ); + } - @Test - public void testHistoryOfIng2() { - ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity ed2 = getEntityManager().find(ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, ed2_id); + @Test + public void testHistoryOfIng2() { + ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity ed2 = getEntityManager().find( + ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, + ed2_id + ); - ChildIndexedListJoinColumnBidirectionalRefIngEntity rev1 = getAuditReader().find(ChildIndexedListJoinColumnBidirectionalRefIngEntity.class, ing2_id, 1); - ChildIndexedListJoinColumnBidirectionalRefIngEntity rev2 = getAuditReader().find(ChildIndexedListJoinColumnBidirectionalRefIngEntity.class, ing2_id, 2); - ChildIndexedListJoinColumnBidirectionalRefIngEntity rev3 = getAuditReader().find(ChildIndexedListJoinColumnBidirectionalRefIngEntity.class, ing2_id, 3); - ChildIndexedListJoinColumnBidirectionalRefIngEntity rev4 = getAuditReader().find(ChildIndexedListJoinColumnBidirectionalRefIngEntity.class, ing2_id, 4); + ChildIndexedListJoinColumnBidirectionalRefIngEntity rev1 = getAuditReader().find( + ChildIndexedListJoinColumnBidirectionalRefIngEntity.class, + ing2_id, + 1 + ); + ChildIndexedListJoinColumnBidirectionalRefIngEntity rev2 = getAuditReader().find( + ChildIndexedListJoinColumnBidirectionalRefIngEntity.class, + ing2_id, + 2 + ); + ChildIndexedListJoinColumnBidirectionalRefIngEntity rev3 = getAuditReader().find( + ChildIndexedListJoinColumnBidirectionalRefIngEntity.class, + ing2_id, + 3 + ); + ChildIndexedListJoinColumnBidirectionalRefIngEntity rev4 = getAuditReader().find( + ChildIndexedListJoinColumnBidirectionalRefIngEntity.class, + ing2_id, + 4 + ); - assertEquals(rev1.getReferences().size(), 0); + assertEquals( rev1.getReferences().size(), 0 ); - assertEquals(rev2.getReferences().size(), 1); - assertEquals(rev2.getReferences().get(0), ed2); + assertEquals( rev2.getReferences().size(), 1 ); + assertEquals( rev2.getReferences().get( 0 ), ed2 ); - assertEquals(rev3.getReferences().size(), 1); - assertEquals(rev3.getReferences().get(0), ed2); + assertEquals( rev3.getReferences().size(), 1 ); + assertEquals( rev3.getReferences().get( 0 ), ed2 ); - assertEquals(rev4.getReferences().size(), 0); - } + assertEquals( rev4.getReferences().size(), 0 ); + } - @Test - public void testHistoryOfEd1() { - ChildIndexedListJoinColumnBidirectionalRefIngEntity ing1 = getEntityManager().find(ChildIndexedListJoinColumnBidirectionalRefIngEntity.class, ing1_id); + @Test + public void testHistoryOfEd1() { + ChildIndexedListJoinColumnBidirectionalRefIngEntity ing1 = getEntityManager().find( + ChildIndexedListJoinColumnBidirectionalRefIngEntity.class, + ing1_id + ); - ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity rev1 = getAuditReader().find(ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, ed1_id, 1); - ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity rev2 = getAuditReader().find(ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, ed1_id, 2); - ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity rev3 = getAuditReader().find(ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, ed1_id, 3); - ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity rev4 = getAuditReader().find(ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, ed1_id, 4); + ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity rev1 = getAuditReader().find( + ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, + ed1_id, + 1 + ); + ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity rev2 = getAuditReader().find( + ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, + ed1_id, + 2 + ); + ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity rev3 = getAuditReader().find( + ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, + ed1_id, + 3 + ); + ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity rev4 = getAuditReader().find( + ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, + ed1_id, + 4 + ); - assertTrue(rev1.getOwner().equals(ing1)); - assertTrue(rev2.getOwner().equals(ing1)); - assertTrue(rev3.getOwner().equals(ing1)); - assertTrue(rev4.getOwner().equals(ing1)); + assertTrue( rev1.getOwner().equals( ing1 ) ); + assertTrue( rev2.getOwner().equals( ing1 ) ); + assertTrue( rev3.getOwner().equals( ing1 ) ); + assertTrue( rev4.getOwner().equals( ing1 ) ); - assertEquals( rev1.getPosition(), Integer.valueOf( 0 ) ); - assertEquals( rev2.getPosition(), Integer.valueOf( 0 ) ); - assertEquals( rev3.getPosition(), Integer.valueOf( 1 ) ); - assertEquals( rev4.getPosition(), Integer.valueOf( 2 ) ); - } + assertEquals( rev1.getPosition(), Integer.valueOf( 0 ) ); + assertEquals( rev2.getPosition(), Integer.valueOf( 0 ) ); + assertEquals( rev3.getPosition(), Integer.valueOf( 1 ) ); + assertEquals( rev4.getPosition(), Integer.valueOf( 2 ) ); + } - @Test - public void testHistoryOfEd2() { - ChildIndexedListJoinColumnBidirectionalRefIngEntity ing1 = getEntityManager().find(ChildIndexedListJoinColumnBidirectionalRefIngEntity.class, ing1_id); - ChildIndexedListJoinColumnBidirectionalRefIngEntity ing2 = getEntityManager().find(ChildIndexedListJoinColumnBidirectionalRefIngEntity.class, ing2_id); + @Test + public void testHistoryOfEd2() { + ChildIndexedListJoinColumnBidirectionalRefIngEntity ing1 = getEntityManager().find( + ChildIndexedListJoinColumnBidirectionalRefIngEntity.class, + ing1_id + ); + ChildIndexedListJoinColumnBidirectionalRefIngEntity ing2 = getEntityManager().find( + ChildIndexedListJoinColumnBidirectionalRefIngEntity.class, + ing2_id + ); - ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity rev1 = getAuditReader().find(ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, ed2_id, 1); - ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity rev2 = getAuditReader().find(ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, ed2_id, 2); - ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity rev3 = getAuditReader().find(ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, ed2_id, 3); - ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity rev4 = getAuditReader().find(ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, ed2_id, 4); + ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity rev1 = getAuditReader().find( + ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, + ed2_id, + 1 + ); + ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity rev2 = getAuditReader().find( + ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, + ed2_id, + 2 + ); + ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity rev3 = getAuditReader().find( + ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, + ed2_id, + 3 + ); + ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity rev4 = getAuditReader().find( + ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, + ed2_id, + 4 + ); - assertTrue(rev1.getOwner().equals(ing1)); - assertTrue(rev2.getOwner().equals(ing2)); - assertTrue(rev3.getOwner().equals(ing2)); - assertTrue(rev4.getOwner().equals(ing1)); + assertTrue( rev1.getOwner().equals( ing1 ) ); + assertTrue( rev2.getOwner().equals( ing2 ) ); + assertTrue( rev3.getOwner().equals( ing2 ) ); + assertTrue( rev4.getOwner().equals( ing1 ) ); - assertEquals( rev1.getPosition(), Integer.valueOf( 1 ) ); - assertEquals( rev2.getPosition(), Integer.valueOf( 0 ) ); - assertEquals( rev3.getPosition(), Integer.valueOf( 0 ) ); - assertEquals( rev4.getPosition(), Integer.valueOf( 0 ) ); - } + assertEquals( rev1.getPosition(), Integer.valueOf( 1 ) ); + assertEquals( rev2.getPosition(), Integer.valueOf( 0 ) ); + assertEquals( rev3.getPosition(), Integer.valueOf( 0 ) ); + assertEquals( rev4.getPosition(), Integer.valueOf( 0 ) ); + } - @Test - public void testHistoryOfEd3() { - ChildIndexedListJoinColumnBidirectionalRefIngEntity ing1 = getEntityManager().find(ChildIndexedListJoinColumnBidirectionalRefIngEntity.class, ing1_id); + @Test + public void testHistoryOfEd3() { + ChildIndexedListJoinColumnBidirectionalRefIngEntity ing1 = getEntityManager().find( + ChildIndexedListJoinColumnBidirectionalRefIngEntity.class, + ing1_id + ); - ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity rev1 = getAuditReader().find(ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, ed3_id, 1); - ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity rev2 = getAuditReader().find(ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, ed3_id, 2); - ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity rev3 = getAuditReader().find(ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, ed3_id, 3); - ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity rev4 = getAuditReader().find(ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, ed3_id, 4); + ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity rev1 = getAuditReader().find( + ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, + ed3_id, + 1 + ); + ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity rev2 = getAuditReader().find( + ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, + ed3_id, + 2 + ); + ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity rev3 = getAuditReader().find( + ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, + ed3_id, + 3 + ); + ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity rev4 = getAuditReader().find( + ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, + ed3_id, + 4 + ); - assertTrue(rev1.getOwner().equals(ing1)); - assertTrue(rev2.getOwner().equals(ing1)); - assertTrue(rev3.getOwner().equals(ing1)); - assertTrue(rev4.getOwner().equals(ing1)); + assertTrue( rev1.getOwner().equals( ing1 ) ); + assertTrue( rev2.getOwner().equals( ing1 ) ); + assertTrue( rev3.getOwner().equals( ing1 ) ); + assertTrue( rev4.getOwner().equals( ing1 ) ); - assertEquals( rev1.getPosition(), Integer.valueOf( 2 ) ); - assertEquals( rev2.getPosition(), Integer.valueOf( 1 ) ); - assertEquals( rev3.getPosition(), Integer.valueOf( 0 ) ); - assertEquals( rev4.getPosition(), Integer.valueOf( 1 ) ); - } + assertEquals( rev1.getPosition(), Integer.valueOf( 2 ) ); + assertEquals( rev2.getPosition(), Integer.valueOf( 1 ) ); + assertEquals( rev3.getPosition(), Integer.valueOf( 0 ) ); + assertEquals( rev4.getPosition(), Integer.valueOf( 1 ) ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/JoinColumnBidirectionalList.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/JoinColumnBidirectionalList.java index 27221556a5..173fc57639 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/JoinColumnBidirectionalList.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/JoinColumnBidirectionalList.java @@ -23,16 +23,16 @@ */ package org.hibernate.envers.test.integration.onetomany.detached; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.onetomany.detached.ListJoinColumnBidirectionalRefEdEntity; import org.hibernate.envers.test.entities.onetomany.detached.ListJoinColumnBidirectionalRefIngEntity; +import org.junit.Test; + import static org.hibernate.envers.test.tools.TestTools.checkList; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -40,183 +40,292 @@ import static org.junit.Assert.assertTrue; /** * Test for a "fake" bidirectional mapping where one side uses @OneToMany+@JoinColumn (and thus owns the relatin), * and the other uses a @ManyToOne(insertable=false, updatable=false). + * * @author Adam Warski (adam at warski dot org) */ public class JoinColumnBidirectionalList extends BaseEnversJPAFunctionalTestCase { - private Integer ed1_id; - private Integer ed2_id; + private Integer ed1_id; + private Integer ed2_id; - private Integer ing1_id; - private Integer ing2_id; + private Integer ing1_id; + private Integer ing2_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { ListJoinColumnBidirectionalRefIngEntity.class, ListJoinColumnBidirectionalRefEdEntity.class }; - } + return new Class[] { + ListJoinColumnBidirectionalRefIngEntity.class, + ListJoinColumnBidirectionalRefEdEntity.class + }; + } - @Test - @Priority(10) - public void createData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void createData() { + EntityManager em = getEntityManager(); - ListJoinColumnBidirectionalRefEdEntity ed1 = new ListJoinColumnBidirectionalRefEdEntity("ed1", null); - ListJoinColumnBidirectionalRefEdEntity ed2 = new ListJoinColumnBidirectionalRefEdEntity("ed2", null); + ListJoinColumnBidirectionalRefEdEntity ed1 = new ListJoinColumnBidirectionalRefEdEntity( "ed1", null ); + ListJoinColumnBidirectionalRefEdEntity ed2 = new ListJoinColumnBidirectionalRefEdEntity( "ed2", null ); - ListJoinColumnBidirectionalRefIngEntity ing1 = new ListJoinColumnBidirectionalRefIngEntity("coll1", ed1); - ListJoinColumnBidirectionalRefIngEntity ing2 = new ListJoinColumnBidirectionalRefIngEntity("coll1", ed2); + ListJoinColumnBidirectionalRefIngEntity ing1 = new ListJoinColumnBidirectionalRefIngEntity( "coll1", ed1 ); + ListJoinColumnBidirectionalRefIngEntity ing2 = new ListJoinColumnBidirectionalRefIngEntity( "coll1", ed2 ); - // Revision 1 (ing1: ed1, ing2: ed2) - em.getTransaction().begin(); + // Revision 1 (ing1: ed1, ing2: ed2) + em.getTransaction().begin(); - em.persist(ed1); - em.persist(ed2); - em.persist(ing1); - em.persist(ing2); + em.persist( ed1 ); + em.persist( ed2 ); + em.persist( ing1 ); + em.persist( ing2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 (ing1: ed1, ed2) - em.getTransaction().begin(); + // Revision 2 (ing1: ed1, ed2) + em.getTransaction().begin(); - ing1 = em.find(ListJoinColumnBidirectionalRefIngEntity.class, ing1.getId()); - ing2 = em.find(ListJoinColumnBidirectionalRefIngEntity.class, ing2.getId()); - ed1 = em.find(ListJoinColumnBidirectionalRefEdEntity.class, ed1.getId()); - ed2 = em.find(ListJoinColumnBidirectionalRefEdEntity.class, ed2.getId()); + ing1 = em.find( ListJoinColumnBidirectionalRefIngEntity.class, ing1.getId() ); + ing2 = em.find( ListJoinColumnBidirectionalRefIngEntity.class, ing2.getId() ); + ed1 = em.find( ListJoinColumnBidirectionalRefEdEntity.class, ed1.getId() ); + ed2 = em.find( ListJoinColumnBidirectionalRefEdEntity.class, ed2.getId() ); - ing2.getReferences().remove(ed2); - ing1.getReferences().add(ed2); + ing2.getReferences().remove( ed2 ); + ing1.getReferences().add( ed2 ); - em.getTransaction().commit(); - em.clear(); + em.getTransaction().commit(); + em.clear(); - // No revision - no changes - em.getTransaction().begin(); + // No revision - no changes + em.getTransaction().begin(); - ing1 = em.find(ListJoinColumnBidirectionalRefIngEntity.class, ing1.getId()); - ing2 = em.find(ListJoinColumnBidirectionalRefIngEntity.class, ing2.getId()); - ed1 = em.find(ListJoinColumnBidirectionalRefEdEntity.class, ed1.getId()); - ed2 = em.find(ListJoinColumnBidirectionalRefEdEntity.class, ed2.getId()); + ing1 = em.find( ListJoinColumnBidirectionalRefIngEntity.class, ing1.getId() ); + ing2 = em.find( ListJoinColumnBidirectionalRefIngEntity.class, ing2.getId() ); + ed1 = em.find( ListJoinColumnBidirectionalRefEdEntity.class, ed1.getId() ); + ed2 = em.find( ListJoinColumnBidirectionalRefEdEntity.class, ed2.getId() ); - ed2.setOwner(ing2); + ed2.setOwner( ing2 ); - em.getTransaction().commit(); - em.clear(); + em.getTransaction().commit(); + em.clear(); - // Revision 3 (ing1: ed1, ed2) - em.getTransaction().begin(); + // Revision 3 (ing1: ed1, ed2) + em.getTransaction().begin(); - ed1 = em.find(ListJoinColumnBidirectionalRefEdEntity.class, ed1.getId()); + ed1 = em.find( ListJoinColumnBidirectionalRefEdEntity.class, ed1.getId() ); - ed1.setData("ed1 bis"); - // Shouldn't get written - ed1.setOwner(ing2); + ed1.setData( "ed1 bis" ); + // Shouldn't get written + ed1.setOwner( ing2 ); - em.getTransaction().commit(); - em.clear(); + em.getTransaction().commit(); + em.clear(); - // Revision 4 (ing2: ed1, ed2) - em.getTransaction().begin(); + // Revision 4 (ing2: ed1, ed2) + em.getTransaction().begin(); - ing1 = em.find(ListJoinColumnBidirectionalRefIngEntity.class, ing1.getId()); - ing2 = em.find(ListJoinColumnBidirectionalRefIngEntity.class, ing2.getId()); + ing1 = em.find( ListJoinColumnBidirectionalRefIngEntity.class, ing1.getId() ); + ing2 = em.find( ListJoinColumnBidirectionalRefIngEntity.class, ing2.getId() ); - ing1.getReferences().clear(); - ing2.getReferences().add(ed1); - ing2.getReferences().add(ed2); + ing1.getReferences().clear(); + ing2.getReferences().add( ed1 ); + ing2.getReferences().add( ed2 ); - em.getTransaction().commit(); - em.clear(); + em.getTransaction().commit(); + em.clear(); - // + // - ing1_id = ing1.getId(); - ing2_id = ing2.getId(); + ing1_id = ing1.getId(); + ing2_id = ing2.getId(); - ed1_id = ed1.getId(); - ed2_id = ed2.getId(); - } + ed1_id = ed1.getId(); + ed2_id = ed2.getId(); + } - @Test - public void testRevisionsCounts() { - assertEquals(Arrays.asList(1, 2, 4), getAuditReader().getRevisions(ListJoinColumnBidirectionalRefIngEntity.class, ing1_id)); - assertEquals(Arrays.asList(1, 2, 4), getAuditReader().getRevisions(ListJoinColumnBidirectionalRefIngEntity.class, ing2_id)); + @Test + public void testRevisionsCounts() { + assertEquals( + Arrays.asList( 1, 2, 4 ), + getAuditReader().getRevisions( ListJoinColumnBidirectionalRefIngEntity.class, ing1_id ) + ); + assertEquals( + Arrays.asList( 1, 2, 4 ), + getAuditReader().getRevisions( ListJoinColumnBidirectionalRefIngEntity.class, ing2_id ) + ); - assertEquals(Arrays.asList(1, 3, 4), getAuditReader().getRevisions(ListJoinColumnBidirectionalRefEdEntity.class, ed1_id)); - assertEquals(Arrays.asList(1, 2, 4), getAuditReader().getRevisions(ListJoinColumnBidirectionalRefEdEntity.class, ed2_id)); - } + assertEquals( + Arrays.asList( 1, 3, 4 ), + getAuditReader().getRevisions( ListJoinColumnBidirectionalRefEdEntity.class, ed1_id ) + ); + assertEquals( + Arrays.asList( 1, 2, 4 ), + getAuditReader().getRevisions( ListJoinColumnBidirectionalRefEdEntity.class, ed2_id ) + ); + } - @Test - public void testHistoryOfIng1() { - ListJoinColumnBidirectionalRefEdEntity ed1_fromRev1 = new ListJoinColumnBidirectionalRefEdEntity(ed1_id, "ed1", null); - ListJoinColumnBidirectionalRefEdEntity ed1_fromRev3 = new ListJoinColumnBidirectionalRefEdEntity(ed1_id, "ed1 bis", null); - ListJoinColumnBidirectionalRefEdEntity ed2 = getEntityManager().find(ListJoinColumnBidirectionalRefEdEntity.class, ed2_id); + @Test + public void testHistoryOfIng1() { + ListJoinColumnBidirectionalRefEdEntity ed1_fromRev1 = new ListJoinColumnBidirectionalRefEdEntity( + ed1_id, + "ed1", + null + ); + ListJoinColumnBidirectionalRefEdEntity ed1_fromRev3 = new ListJoinColumnBidirectionalRefEdEntity( + ed1_id, + "ed1 bis", + null + ); + ListJoinColumnBidirectionalRefEdEntity ed2 = getEntityManager().find( + ListJoinColumnBidirectionalRefEdEntity.class, + ed2_id + ); - ListJoinColumnBidirectionalRefIngEntity rev1 = getAuditReader().find(ListJoinColumnBidirectionalRefIngEntity.class, ing1_id, 1); - ListJoinColumnBidirectionalRefIngEntity rev2 = getAuditReader().find(ListJoinColumnBidirectionalRefIngEntity.class, ing1_id, 2); - ListJoinColumnBidirectionalRefIngEntity rev3 = getAuditReader().find(ListJoinColumnBidirectionalRefIngEntity.class, ing1_id, 3); - ListJoinColumnBidirectionalRefIngEntity rev4 = getAuditReader().find(ListJoinColumnBidirectionalRefIngEntity.class, ing1_id, 4); + ListJoinColumnBidirectionalRefIngEntity rev1 = getAuditReader().find( + ListJoinColumnBidirectionalRefIngEntity.class, + ing1_id, + 1 + ); + ListJoinColumnBidirectionalRefIngEntity rev2 = getAuditReader().find( + ListJoinColumnBidirectionalRefIngEntity.class, + ing1_id, + 2 + ); + ListJoinColumnBidirectionalRefIngEntity rev3 = getAuditReader().find( + ListJoinColumnBidirectionalRefIngEntity.class, + ing1_id, + 3 + ); + ListJoinColumnBidirectionalRefIngEntity rev4 = getAuditReader().find( + ListJoinColumnBidirectionalRefIngEntity.class, + ing1_id, + 4 + ); - assertTrue(checkList(rev1.getReferences(), ed1_fromRev1)); - assertTrue(checkList(rev2.getReferences(), ed1_fromRev1, ed2)); - assertTrue(checkList(rev3.getReferences(), ed1_fromRev3, ed2)); - assertTrue(checkList(rev4.getReferences())); - } + assertTrue( checkList( rev1.getReferences(), ed1_fromRev1 ) ); + assertTrue( checkList( rev2.getReferences(), ed1_fromRev1, ed2 ) ); + assertTrue( checkList( rev3.getReferences(), ed1_fromRev3, ed2 ) ); + assertTrue( checkList( rev4.getReferences() ) ); + } - @Test - public void testHistoryOfIng2() { - ListJoinColumnBidirectionalRefEdEntity ed1 = getEntityManager().find(ListJoinColumnBidirectionalRefEdEntity.class, ed1_id); - ListJoinColumnBidirectionalRefEdEntity ed2 = getEntityManager().find(ListJoinColumnBidirectionalRefEdEntity.class, ed2_id); + @Test + public void testHistoryOfIng2() { + ListJoinColumnBidirectionalRefEdEntity ed1 = getEntityManager().find( + ListJoinColumnBidirectionalRefEdEntity.class, + ed1_id + ); + ListJoinColumnBidirectionalRefEdEntity ed2 = getEntityManager().find( + ListJoinColumnBidirectionalRefEdEntity.class, + ed2_id + ); - ListJoinColumnBidirectionalRefIngEntity rev1 = getAuditReader().find(ListJoinColumnBidirectionalRefIngEntity.class, ing2_id, 1); - ListJoinColumnBidirectionalRefIngEntity rev2 = getAuditReader().find(ListJoinColumnBidirectionalRefIngEntity.class, ing2_id, 2); - ListJoinColumnBidirectionalRefIngEntity rev3 = getAuditReader().find(ListJoinColumnBidirectionalRefIngEntity.class, ing2_id, 3); - ListJoinColumnBidirectionalRefIngEntity rev4 = getAuditReader().find(ListJoinColumnBidirectionalRefIngEntity.class, ing2_id, 4); + ListJoinColumnBidirectionalRefIngEntity rev1 = getAuditReader().find( + ListJoinColumnBidirectionalRefIngEntity.class, + ing2_id, + 1 + ); + ListJoinColumnBidirectionalRefIngEntity rev2 = getAuditReader().find( + ListJoinColumnBidirectionalRefIngEntity.class, + ing2_id, + 2 + ); + ListJoinColumnBidirectionalRefIngEntity rev3 = getAuditReader().find( + ListJoinColumnBidirectionalRefIngEntity.class, + ing2_id, + 3 + ); + ListJoinColumnBidirectionalRefIngEntity rev4 = getAuditReader().find( + ListJoinColumnBidirectionalRefIngEntity.class, + ing2_id, + 4 + ); - assertTrue(checkList(rev1.getReferences(), ed2)); - assertTrue(checkList(rev2.getReferences())); - assertTrue(checkList(rev3.getReferences())); - assertTrue(checkList(rev4.getReferences(), ed1, ed2)); - } + assertTrue( checkList( rev1.getReferences(), ed2 ) ); + assertTrue( checkList( rev2.getReferences() ) ); + assertTrue( checkList( rev3.getReferences() ) ); + assertTrue( checkList( rev4.getReferences(), ed1, ed2 ) ); + } - @Test - public void testHistoryOfEd1() { - ListJoinColumnBidirectionalRefIngEntity ing1 = getEntityManager().find(ListJoinColumnBidirectionalRefIngEntity.class, ing1_id); - ListJoinColumnBidirectionalRefIngEntity ing2 = getEntityManager().find(ListJoinColumnBidirectionalRefIngEntity.class, ing2_id); + @Test + public void testHistoryOfEd1() { + ListJoinColumnBidirectionalRefIngEntity ing1 = getEntityManager().find( + ListJoinColumnBidirectionalRefIngEntity.class, + ing1_id + ); + ListJoinColumnBidirectionalRefIngEntity ing2 = getEntityManager().find( + ListJoinColumnBidirectionalRefIngEntity.class, + ing2_id + ); - ListJoinColumnBidirectionalRefEdEntity rev1 = getAuditReader().find(ListJoinColumnBidirectionalRefEdEntity.class, ed1_id, 1); - ListJoinColumnBidirectionalRefEdEntity rev2 = getAuditReader().find(ListJoinColumnBidirectionalRefEdEntity.class, ed1_id, 2); - ListJoinColumnBidirectionalRefEdEntity rev3 = getAuditReader().find(ListJoinColumnBidirectionalRefEdEntity.class, ed1_id, 3); - ListJoinColumnBidirectionalRefEdEntity rev4 = getAuditReader().find(ListJoinColumnBidirectionalRefEdEntity.class, ed1_id, 4); + ListJoinColumnBidirectionalRefEdEntity rev1 = getAuditReader().find( + ListJoinColumnBidirectionalRefEdEntity.class, + ed1_id, + 1 + ); + ListJoinColumnBidirectionalRefEdEntity rev2 = getAuditReader().find( + ListJoinColumnBidirectionalRefEdEntity.class, + ed1_id, + 2 + ); + ListJoinColumnBidirectionalRefEdEntity rev3 = getAuditReader().find( + ListJoinColumnBidirectionalRefEdEntity.class, + ed1_id, + 3 + ); + ListJoinColumnBidirectionalRefEdEntity rev4 = getAuditReader().find( + ListJoinColumnBidirectionalRefEdEntity.class, + ed1_id, + 4 + ); - assertTrue(rev1.getOwner().equals(ing1)); - assertTrue(rev2.getOwner().equals(ing1)); - assertTrue(rev3.getOwner().equals(ing1)); - assertTrue(rev4.getOwner().equals(ing2)); + assertTrue( rev1.getOwner().equals( ing1 ) ); + assertTrue( rev2.getOwner().equals( ing1 ) ); + assertTrue( rev3.getOwner().equals( ing1 ) ); + assertTrue( rev4.getOwner().equals( ing2 ) ); - assertEquals(rev1.getData(), "ed1"); - assertEquals(rev2.getData(), "ed1"); - assertEquals(rev3.getData(), "ed1 bis"); - assertEquals(rev4.getData(), "ed1 bis"); - } + assertEquals( rev1.getData(), "ed1" ); + assertEquals( rev2.getData(), "ed1" ); + assertEquals( rev3.getData(), "ed1 bis" ); + assertEquals( rev4.getData(), "ed1 bis" ); + } - @Test - public void testHistoryOfEd2() { - ListJoinColumnBidirectionalRefIngEntity ing1 = getEntityManager().find(ListJoinColumnBidirectionalRefIngEntity.class, ing1_id); - ListJoinColumnBidirectionalRefIngEntity ing2 = getEntityManager().find(ListJoinColumnBidirectionalRefIngEntity.class, ing2_id); + @Test + public void testHistoryOfEd2() { + ListJoinColumnBidirectionalRefIngEntity ing1 = getEntityManager().find( + ListJoinColumnBidirectionalRefIngEntity.class, + ing1_id + ); + ListJoinColumnBidirectionalRefIngEntity ing2 = getEntityManager().find( + ListJoinColumnBidirectionalRefIngEntity.class, + ing2_id + ); - ListJoinColumnBidirectionalRefEdEntity rev1 = getAuditReader().find(ListJoinColumnBidirectionalRefEdEntity.class, ed2_id, 1); - ListJoinColumnBidirectionalRefEdEntity rev2 = getAuditReader().find(ListJoinColumnBidirectionalRefEdEntity.class, ed2_id, 2); - ListJoinColumnBidirectionalRefEdEntity rev3 = getAuditReader().find(ListJoinColumnBidirectionalRefEdEntity.class, ed2_id, 3); - ListJoinColumnBidirectionalRefEdEntity rev4 = getAuditReader().find(ListJoinColumnBidirectionalRefEdEntity.class, ed2_id, 4); + ListJoinColumnBidirectionalRefEdEntity rev1 = getAuditReader().find( + ListJoinColumnBidirectionalRefEdEntity.class, + ed2_id, + 1 + ); + ListJoinColumnBidirectionalRefEdEntity rev2 = getAuditReader().find( + ListJoinColumnBidirectionalRefEdEntity.class, + ed2_id, + 2 + ); + ListJoinColumnBidirectionalRefEdEntity rev3 = getAuditReader().find( + ListJoinColumnBidirectionalRefEdEntity.class, + ed2_id, + 3 + ); + ListJoinColumnBidirectionalRefEdEntity rev4 = getAuditReader().find( + ListJoinColumnBidirectionalRefEdEntity.class, + ed2_id, + 4 + ); - assertTrue(rev1.getOwner().equals(ing2)); - assertTrue(rev2.getOwner().equals(ing1)); - assertTrue(rev3.getOwner().equals(ing1)); - assertTrue(rev4.getOwner().equals(ing2)); + assertTrue( rev1.getOwner().equals( ing2 ) ); + assertTrue( rev2.getOwner().equals( ing1 ) ); + assertTrue( rev3.getOwner().equals( ing1 ) ); + assertTrue( rev4.getOwner().equals( ing2 ) ); - assertEquals(rev1.getData(), "ed2"); - assertEquals(rev2.getData(), "ed2"); - assertEquals(rev3.getData(), "ed2"); - assertEquals(rev4.getData(), "ed2"); - } + assertEquals( rev1.getData(), "ed2" ); + assertEquals( rev2.getData(), "ed2" ); + assertEquals( rev3.getData(), "ed2" ); + assertEquals( rev4.getData(), "ed2" ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/JoinColumnBidirectionalListWithInheritance.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/JoinColumnBidirectionalListWithInheritance.java index 25914b9dcc..f592416a19 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/JoinColumnBidirectionalListWithInheritance.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/detached/JoinColumnBidirectionalListWithInheritance.java @@ -23,10 +23,8 @@ */ package org.hibernate.envers.test.integration.onetomany.detached; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; @@ -34,6 +32,8 @@ import org.hibernate.envers.test.entities.onetomany.detached.ListJoinColumnBidir import org.hibernate.envers.test.entities.onetomany.detached.ListJoinColumnBidirectionalInheritanceRefEdParentEntity; import org.hibernate.envers.test.entities.onetomany.detached.ListJoinColumnBidirectionalInheritanceRefIngEntity; +import org.junit.Test; + import static org.hibernate.envers.test.tools.TestTools.checkList; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -41,14 +41,15 @@ import static org.junit.Assert.assertTrue; /** * Test for a "fake" bidirectional mapping where one side uses @OneToMany+@JoinColumn (and thus owns the relatin), * and the other uses a @ManyToOne(insertable=false, updatable=false). + * * @author Adam Warski (adam at warski dot org) */ public class JoinColumnBidirectionalListWithInheritance extends BaseEnversJPAFunctionalTestCase { - private Integer ed1_id; - private Integer ed2_id; + private Integer ed1_id; + private Integer ed2_id; - private Integer ing1_id; - private Integer ing2_id; + private Integer ing1_id; + private Integer ing2_id; @Override protected Class[] getAnnotatedClasses() { @@ -57,105 +58,189 @@ public class JoinColumnBidirectionalListWithInheritance extends BaseEnversJPAFun ListJoinColumnBidirectionalInheritanceRefEdChildEntity.class, ListJoinColumnBidirectionalInheritanceRefEdParentEntity.class }; - } + } - @Test - @Priority(10) - public void createData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void createData() { + EntityManager em = getEntityManager(); - ListJoinColumnBidirectionalInheritanceRefEdParentEntity ed1 = new ListJoinColumnBidirectionalInheritanceRefEdChildEntity("ed1", null, "ed1 child"); - ListJoinColumnBidirectionalInheritanceRefEdParentEntity ed2 = new ListJoinColumnBidirectionalInheritanceRefEdChildEntity("ed2", null, "ed2 child"); + ListJoinColumnBidirectionalInheritanceRefEdParentEntity ed1 = new ListJoinColumnBidirectionalInheritanceRefEdChildEntity( + "ed1", + null, + "ed1 child" + ); + ListJoinColumnBidirectionalInheritanceRefEdParentEntity ed2 = new ListJoinColumnBidirectionalInheritanceRefEdChildEntity( + "ed2", + null, + "ed2 child" + ); - ListJoinColumnBidirectionalInheritanceRefIngEntity ing1 = new ListJoinColumnBidirectionalInheritanceRefIngEntity("coll1", ed1); - ListJoinColumnBidirectionalInheritanceRefIngEntity ing2 = new ListJoinColumnBidirectionalInheritanceRefIngEntity("coll1", ed2); + ListJoinColumnBidirectionalInheritanceRefIngEntity ing1 = new ListJoinColumnBidirectionalInheritanceRefIngEntity( + "coll1", + ed1 + ); + ListJoinColumnBidirectionalInheritanceRefIngEntity ing2 = new ListJoinColumnBidirectionalInheritanceRefIngEntity( + "coll1", + ed2 + ); - // Revision 1 (ing1: ed1, ing2: ed2) - em.getTransaction().begin(); + // Revision 1 (ing1: ed1, ing2: ed2) + em.getTransaction().begin(); - em.persist(ed1); - em.persist(ed2); - em.persist(ing1); - em.persist(ing2); + em.persist( ed1 ); + em.persist( ed2 ); + em.persist( ing1 ); + em.persist( ing2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 (ing1: ed1, ed2) - em.getTransaction().begin(); + // Revision 2 (ing1: ed1, ed2) + em.getTransaction().begin(); - ing1 = em.find(ListJoinColumnBidirectionalInheritanceRefIngEntity.class, ing1.getId()); - ing2 = em.find(ListJoinColumnBidirectionalInheritanceRefIngEntity.class, ing2.getId()); - ed1 = em.find(ListJoinColumnBidirectionalInheritanceRefEdParentEntity.class, ed1.getId()); - ed2 = em.find(ListJoinColumnBidirectionalInheritanceRefEdParentEntity.class, ed2.getId()); + ing1 = em.find( ListJoinColumnBidirectionalInheritanceRefIngEntity.class, ing1.getId() ); + ing2 = em.find( ListJoinColumnBidirectionalInheritanceRefIngEntity.class, ing2.getId() ); + ed1 = em.find( ListJoinColumnBidirectionalInheritanceRefEdParentEntity.class, ed1.getId() ); + ed2 = em.find( ListJoinColumnBidirectionalInheritanceRefEdParentEntity.class, ed2.getId() ); - ing2.getReferences().remove(ed2); - ing1.getReferences().add(ed2); + ing2.getReferences().remove( ed2 ); + ing1.getReferences().add( ed2 ); - em.getTransaction().commit(); - em.clear(); + em.getTransaction().commit(); + em.clear(); - // + // - ing1_id = ing1.getId(); - ing2_id = ing2.getId(); + ing1_id = ing1.getId(); + ing2_id = ing2.getId(); - ed1_id = ed1.getId(); - ed2_id = ed2.getId(); - } + ed1_id = ed1.getId(); + ed2_id = ed2.getId(); + } - @Test - public void testRevisionsCounts() { - assertEquals(Arrays.asList(1, 2), getAuditReader().getRevisions(ListJoinColumnBidirectionalInheritanceRefIngEntity.class, ing1_id)); - assertEquals(Arrays.asList(1, 2), getAuditReader().getRevisions(ListJoinColumnBidirectionalInheritanceRefIngEntity.class, ing2_id)); + @Test + public void testRevisionsCounts() { + assertEquals( + Arrays.asList( 1, 2 ), getAuditReader().getRevisions( + ListJoinColumnBidirectionalInheritanceRefIngEntity.class, + ing1_id + ) + ); + assertEquals( + Arrays.asList( 1, 2 ), getAuditReader().getRevisions( + ListJoinColumnBidirectionalInheritanceRefIngEntity.class, + ing2_id + ) + ); - assertEquals(Arrays.asList(1), getAuditReader().getRevisions(ListJoinColumnBidirectionalInheritanceRefEdParentEntity.class, ed1_id)); - assertEquals(Arrays.asList(1, 2), getAuditReader().getRevisions(ListJoinColumnBidirectionalInheritanceRefEdParentEntity.class, ed2_id)); - } + assertEquals( + Arrays.asList( 1 ), getAuditReader().getRevisions( + ListJoinColumnBidirectionalInheritanceRefEdParentEntity.class, + ed1_id + ) + ); + assertEquals( + Arrays.asList( 1, 2 ), getAuditReader().getRevisions( + ListJoinColumnBidirectionalInheritanceRefEdParentEntity.class, + ed2_id + ) + ); + } - @Test - public void testHistoryOfIng1() { - ListJoinColumnBidirectionalInheritanceRefEdParentEntity ed1 = getEntityManager().find(ListJoinColumnBidirectionalInheritanceRefEdParentEntity.class, ed1_id); - ListJoinColumnBidirectionalInheritanceRefEdParentEntity ed2 = getEntityManager().find(ListJoinColumnBidirectionalInheritanceRefEdParentEntity.class, ed2_id); + @Test + public void testHistoryOfIng1() { + ListJoinColumnBidirectionalInheritanceRefEdParentEntity ed1 = getEntityManager().find( + ListJoinColumnBidirectionalInheritanceRefEdParentEntity.class, + ed1_id + ); + ListJoinColumnBidirectionalInheritanceRefEdParentEntity ed2 = getEntityManager().find( + ListJoinColumnBidirectionalInheritanceRefEdParentEntity.class, + ed2_id + ); - ListJoinColumnBidirectionalInheritanceRefIngEntity rev1 = getAuditReader().find(ListJoinColumnBidirectionalInheritanceRefIngEntity.class, ing1_id, 1); - ListJoinColumnBidirectionalInheritanceRefIngEntity rev2 = getAuditReader().find(ListJoinColumnBidirectionalInheritanceRefIngEntity.class, ing1_id, 2); + ListJoinColumnBidirectionalInheritanceRefIngEntity rev1 = getAuditReader().find( + ListJoinColumnBidirectionalInheritanceRefIngEntity.class, + ing1_id, + 1 + ); + ListJoinColumnBidirectionalInheritanceRefIngEntity rev2 = getAuditReader().find( + ListJoinColumnBidirectionalInheritanceRefIngEntity.class, + ing1_id, + 2 + ); - assertTrue(checkList(rev1.getReferences(), ed1)); - assertTrue(checkList(rev2.getReferences(), ed1, ed2)); - } + assertTrue( checkList( rev1.getReferences(), ed1 ) ); + assertTrue( checkList( rev2.getReferences(), ed1, ed2 ) ); + } - @Test - public void testHistoryOfIng2() { - ListJoinColumnBidirectionalInheritanceRefEdParentEntity ed2 = getEntityManager().find(ListJoinColumnBidirectionalInheritanceRefEdParentEntity.class, ed2_id); + @Test + public void testHistoryOfIng2() { + ListJoinColumnBidirectionalInheritanceRefEdParentEntity ed2 = getEntityManager().find( + ListJoinColumnBidirectionalInheritanceRefEdParentEntity.class, + ed2_id + ); - ListJoinColumnBidirectionalInheritanceRefIngEntity rev1 = getAuditReader().find(ListJoinColumnBidirectionalInheritanceRefIngEntity.class, ing2_id, 1); - ListJoinColumnBidirectionalInheritanceRefIngEntity rev2 = getAuditReader().find(ListJoinColumnBidirectionalInheritanceRefIngEntity.class, ing2_id, 2); + ListJoinColumnBidirectionalInheritanceRefIngEntity rev1 = getAuditReader().find( + ListJoinColumnBidirectionalInheritanceRefIngEntity.class, + ing2_id, + 1 + ); + ListJoinColumnBidirectionalInheritanceRefIngEntity rev2 = getAuditReader().find( + ListJoinColumnBidirectionalInheritanceRefIngEntity.class, + ing2_id, + 2 + ); - assertTrue(checkList(rev1.getReferences(), ed2)); - assertTrue(checkList(rev2.getReferences())); - } + assertTrue( checkList( rev1.getReferences(), ed2 ) ); + assertTrue( checkList( rev2.getReferences() ) ); + } - @Test - public void testHistoryOfEd1() { - ListJoinColumnBidirectionalInheritanceRefIngEntity ing1 = getEntityManager().find(ListJoinColumnBidirectionalInheritanceRefIngEntity.class, ing1_id); + @Test + public void testHistoryOfEd1() { + ListJoinColumnBidirectionalInheritanceRefIngEntity ing1 = getEntityManager().find( + ListJoinColumnBidirectionalInheritanceRefIngEntity.class, + ing1_id + ); - ListJoinColumnBidirectionalInheritanceRefEdParentEntity rev1 = getAuditReader().find(ListJoinColumnBidirectionalInheritanceRefEdParentEntity.class, ed1_id, 1); - ListJoinColumnBidirectionalInheritanceRefEdParentEntity rev2 = getAuditReader().find(ListJoinColumnBidirectionalInheritanceRefEdParentEntity.class, ed1_id, 2); + ListJoinColumnBidirectionalInheritanceRefEdParentEntity rev1 = getAuditReader().find( + ListJoinColumnBidirectionalInheritanceRefEdParentEntity.class, + ed1_id, + 1 + ); + ListJoinColumnBidirectionalInheritanceRefEdParentEntity rev2 = getAuditReader().find( + ListJoinColumnBidirectionalInheritanceRefEdParentEntity.class, + ed1_id, + 2 + ); - assertTrue(rev1.getOwner().equals(ing1)); - assertTrue(rev2.getOwner().equals(ing1)); - } + assertTrue( rev1.getOwner().equals( ing1 ) ); + assertTrue( rev2.getOwner().equals( ing1 ) ); + } - @Test - public void testHistoryOfEd2() { - ListJoinColumnBidirectionalInheritanceRefIngEntity ing1 = getEntityManager().find(ListJoinColumnBidirectionalInheritanceRefIngEntity.class, ing1_id); - ListJoinColumnBidirectionalInheritanceRefIngEntity ing2 = getEntityManager().find(ListJoinColumnBidirectionalInheritanceRefIngEntity.class, ing2_id); + @Test + public void testHistoryOfEd2() { + ListJoinColumnBidirectionalInheritanceRefIngEntity ing1 = getEntityManager().find( + ListJoinColumnBidirectionalInheritanceRefIngEntity.class, + ing1_id + ); + ListJoinColumnBidirectionalInheritanceRefIngEntity ing2 = getEntityManager().find( + ListJoinColumnBidirectionalInheritanceRefIngEntity.class, + ing2_id + ); - ListJoinColumnBidirectionalInheritanceRefEdParentEntity rev1 = getAuditReader().find(ListJoinColumnBidirectionalInheritanceRefEdParentEntity.class, ed2_id, 1); - ListJoinColumnBidirectionalInheritanceRefEdParentEntity rev2 = getAuditReader().find(ListJoinColumnBidirectionalInheritanceRefEdParentEntity.class, ed2_id, 2); + ListJoinColumnBidirectionalInheritanceRefEdParentEntity rev1 = getAuditReader().find( + ListJoinColumnBidirectionalInheritanceRefEdParentEntity.class, + ed2_id, + 1 + ); + ListJoinColumnBidirectionalInheritanceRefEdParentEntity rev2 = getAuditReader().find( + ListJoinColumnBidirectionalInheritanceRefEdParentEntity.class, + ed2_id, + 2 + ); - assertTrue(rev1.getOwner().equals(ing2)); - assertTrue(rev2.getOwner().equals(ing1)); - } + assertTrue( rev1.getOwner().equals( ing2 ) ); + assertTrue( rev2.getOwner().equals( ing1 ) ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/embeddedid/Constant.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/embeddedid/Constant.java index 9db330a594..678c9486a3 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/embeddedid/Constant.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/embeddedid/Constant.java @@ -1,9 +1,9 @@ package org.hibernate.envers.test.integration.onetomany.embeddedid; -import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; +import java.io.Serializable; import org.hibernate.envers.Audited; @@ -13,58 +13,66 @@ import org.hibernate.envers.Audited; @Entity @Audited public class Constant implements Serializable { - @Id - @Column(length = 3) - private String id; + @Id + @Column(length = 3) + private String id; - private String name; + private String name; - public Constant() { - } + public Constant() { + } - public Constant(String id, String name) { - this.id = id; - this.name = name; - } + public Constant(String id, String name) { + this.id = id; + this.name = name; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof Constant)) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof Constant) ) { + return false; + } - Constant constant = (Constant) o; + Constant constant = (Constant) o; - if (id != null ? !id.equals(constant.id) : constant.id != null) return false; - if (name != null ? !name.equals(constant.name) : constant.name != null) return false; + if ( id != null ? !id.equals( constant.id ) : constant.id != null ) { + return false; + } + if ( name != null ? !name.equals( constant.name ) : constant.name != null ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - int result = id != null ? id.hashCode() : 0; - result = 31 * result + (name != null ? name.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = id != null ? id.hashCode() : 0; + result = 31 * result + (name != null ? name.hashCode() : 0); + return result; + } - @Override - public String toString() { - return "Constant(id = " + id + ", name = " + name + ")"; - } + @Override + public String toString() { + return "Constant(id = " + id + ", name = " + name + ")"; + } - public String getId() { - return id; - } + public String getId() { + return id; + } - public void setId(String id) { - this.id = id; - } + public void setId(String id) { + this.id = id; + } - public String getName() { - return name; - } + public String getName() { + return name; + } - public void setName(String name) { - this.name = name; - } + public void setName(String name) { + this.name = name; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/embeddedid/MapsIdTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/embeddedid/MapsIdTest.java index a785b53263..115d61b1c9 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/embeddedid/MapsIdTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/embeddedid/MapsIdTest.java @@ -1,13 +1,14 @@ package org.hibernate.envers.test.integration.onetomany.embeddedid; -import java.util.Arrays; import javax.persistence.EntityManager; +import java.util.Arrays; + +import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; +import org.hibernate.envers.test.Priority; import org.junit.Assert; import org.junit.Test; -import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; -import org.hibernate.envers.test.Priority; import org.hibernate.testing.TestForIssue; /** @@ -15,115 +16,145 @@ import org.hibernate.testing.TestForIssue; */ @TestForIssue(jiraKey = "HHH-7157") public class MapsIdTest extends BaseEnversJPAFunctionalTestCase { - private PersonTuple tuple1Ver1 = null; - private PersonTuple tuple2Ver1 = null; - private PersonTuple tuple2Ver2 = null; - private Person personCVer1 = null; - private Person personCVer2 = null; + private PersonTuple tuple1Ver1 = null; + private PersonTuple tuple2Ver1 = null; + private PersonTuple tuple2Ver2 = null; + private Person personCVer1 = null; + private Person personCVer2 = null; - @Override - protected Class[] getAnnotatedClasses() { - return new Class[]{Person.class, PersonTuple.class, Constant.class}; - } + @Override + protected Class[] getAnnotatedClasses() { + return new Class[] {Person.class, PersonTuple.class, Constant.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - // Revision 1 - em.getTransaction().begin(); - Person personA = new Person("Peter"); - Person personB = new Person("Mary"); - em.persist(personA); - em.persist(personB); - Constant cons = new Constant("USD", "US Dollar"); - em.persist(cons); - PersonTuple tuple1 = new PersonTuple(true, personA, personB, cons); - em.persist(tuple1); - em.getTransaction().commit(); + // Revision 1 + em.getTransaction().begin(); + Person personA = new Person( "Peter" ); + Person personB = new Person( "Mary" ); + em.persist( personA ); + em.persist( personB ); + Constant cons = new Constant( "USD", "US Dollar" ); + em.persist( cons ); + PersonTuple tuple1 = new PersonTuple( true, personA, personB, cons ); + em.persist( tuple1 ); + em.getTransaction().commit(); - tuple1Ver1 = new PersonTuple(tuple1.isHelloWorld(), tuple1.getPersonA(), tuple1.getPersonB(), tuple1.getConstant()); + tuple1Ver1 = new PersonTuple( + tuple1.isHelloWorld(), + tuple1.getPersonA(), + tuple1.getPersonB(), + tuple1.getConstant() + ); - // Revision 2 - em.getTransaction().begin(); - cons = em.find(Constant.class, cons.getId()); - Person personC1 = new Person("Lukasz"); - em.persist(personC1); - PersonTuple tuple2 = new PersonTuple(true, personA, personC1, cons); - em.persist(tuple2); - em.getTransaction().commit(); + // Revision 2 + em.getTransaction().begin(); + cons = em.find( Constant.class, cons.getId() ); + Person personC1 = new Person( "Lukasz" ); + em.persist( personC1 ); + PersonTuple tuple2 = new PersonTuple( true, personA, personC1, cons ); + em.persist( tuple2 ); + em.getTransaction().commit(); - tuple2Ver1 = new PersonTuple(tuple2.isHelloWorld(), tuple2.getPersonA(), tuple2.getPersonB(), tuple2.getConstant()); - personCVer1 = new Person(personC1.getId(), personC1.getName()); - personCVer1.getPersonBTuples().add(tuple2Ver1); + tuple2Ver1 = new PersonTuple( + tuple2.isHelloWorld(), + tuple2.getPersonA(), + tuple2.getPersonB(), + tuple2.getConstant() + ); + personCVer1 = new Person( personC1.getId(), personC1.getName() ); + personCVer1.getPersonBTuples().add( tuple2Ver1 ); - // Revision 3 - em.getTransaction().begin(); - tuple2 = em.find(PersonTuple.class, tuple2.getPersonTupleId()); - tuple2.setHelloWorld(false); - em.merge(tuple2); - em.getTransaction().commit(); + // Revision 3 + em.getTransaction().begin(); + tuple2 = em.find( PersonTuple.class, tuple2.getPersonTupleId() ); + tuple2.setHelloWorld( false ); + em.merge( tuple2 ); + em.getTransaction().commit(); - tuple2Ver2 = new PersonTuple(tuple2.isHelloWorld(), tuple2.getPersonA(), tuple2.getPersonB(), tuple2.getConstant()); + tuple2Ver2 = new PersonTuple( + tuple2.isHelloWorld(), + tuple2.getPersonA(), + tuple2.getPersonB(), + tuple2.getConstant() + ); - // Revision 4 - em.getTransaction().begin(); - Person personC2 = em.find(Person.class, personC1.getId()); - personC2.setName("Robert"); - em.merge(personC2); - em.getTransaction().commit(); + // Revision 4 + em.getTransaction().begin(); + Person personC2 = em.find( Person.class, personC1.getId() ); + personC2.setName( "Robert" ); + em.merge( personC2 ); + em.getTransaction().commit(); - personCVer2 = new Person(personC2.getId(), personC2.getName()); - personCVer2.getPersonBTuples().add(tuple2Ver1); + personCVer2 = new Person( personC2.getId(), personC2.getName() ); + personCVer2.getPersonBTuples().add( tuple2Ver1 ); - em.close(); - } + em.close(); + } - @Test - public void testRevisionsCounts() { - Assert.assertEquals(Arrays.asList(1), getAuditReader().getRevisions(PersonTuple.class, tuple1Ver1.getPersonTupleId())); - Assert.assertEquals(Arrays.asList(2, 3), getAuditReader().getRevisions(PersonTuple.class, tuple2Ver1.getPersonTupleId())); - Assert.assertEquals(Arrays.asList(2, 4), getAuditReader().getRevisions(Person.class, personCVer1.getId())); - } + @Test + public void testRevisionsCounts() { + Assert.assertEquals( + Arrays.asList( 1 ), getAuditReader().getRevisions( + PersonTuple.class, + tuple1Ver1.getPersonTupleId() + ) + ); + Assert.assertEquals( + Arrays.asList( 2, 3 ), getAuditReader().getRevisions( + PersonTuple.class, + tuple2Ver1.getPersonTupleId() + ) + ); + Assert.assertEquals( + Arrays.asList( 2, 4 ), getAuditReader().getRevisions( + Person.class, + personCVer1.getId() + ) + ); + } - @Test - public void testHistoryOfTuple1() { - PersonTuple tuple = getAuditReader().find(PersonTuple.class, tuple1Ver1.getPersonTupleId(), 1); + @Test + public void testHistoryOfTuple1() { + PersonTuple tuple = getAuditReader().find( PersonTuple.class, tuple1Ver1.getPersonTupleId(), 1 ); - Assert.assertEquals(tuple1Ver1, tuple); - Assert.assertEquals(tuple1Ver1.isHelloWorld(), tuple.isHelloWorld()); - Assert.assertEquals(tuple1Ver1.getPersonA().getId(), tuple.getPersonA().getId()); - Assert.assertEquals(tuple1Ver1.getPersonB().getId(), tuple.getPersonB().getId()); - } + Assert.assertEquals( tuple1Ver1, tuple ); + Assert.assertEquals( tuple1Ver1.isHelloWorld(), tuple.isHelloWorld() ); + Assert.assertEquals( tuple1Ver1.getPersonA().getId(), tuple.getPersonA().getId() ); + Assert.assertEquals( tuple1Ver1.getPersonB().getId(), tuple.getPersonB().getId() ); + } - @Test - public void testHistoryOfTuple2() { - PersonTuple tuple = getAuditReader().find(PersonTuple.class, tuple2Ver2.getPersonTupleId(), 2); + @Test + public void testHistoryOfTuple2() { + PersonTuple tuple = getAuditReader().find( PersonTuple.class, tuple2Ver2.getPersonTupleId(), 2 ); - Assert.assertEquals(tuple2Ver1, tuple); - Assert.assertEquals(tuple2Ver1.isHelloWorld(), tuple.isHelloWorld()); - Assert.assertEquals(tuple2Ver1.getPersonA().getId(), tuple.getPersonA().getId()); - Assert.assertEquals(tuple2Ver1.getPersonB().getId(), tuple.getPersonB().getId()); + Assert.assertEquals( tuple2Ver1, tuple ); + Assert.assertEquals( tuple2Ver1.isHelloWorld(), tuple.isHelloWorld() ); + Assert.assertEquals( tuple2Ver1.getPersonA().getId(), tuple.getPersonA().getId() ); + Assert.assertEquals( tuple2Ver1.getPersonB().getId(), tuple.getPersonB().getId() ); - tuple = getAuditReader().find(PersonTuple.class, tuple2Ver2.getPersonTupleId(), 3); + tuple = getAuditReader().find( PersonTuple.class, tuple2Ver2.getPersonTupleId(), 3 ); - Assert.assertEquals(tuple2Ver2, tuple); - Assert.assertEquals(tuple2Ver2.isHelloWorld(), tuple.isHelloWorld()); - Assert.assertEquals(tuple2Ver2.getPersonA().getId(), tuple.getPersonA().getId()); - Assert.assertEquals(tuple2Ver2.getPersonB().getId(), tuple.getPersonB().getId()); - } + Assert.assertEquals( tuple2Ver2, tuple ); + Assert.assertEquals( tuple2Ver2.isHelloWorld(), tuple.isHelloWorld() ); + Assert.assertEquals( tuple2Ver2.getPersonA().getId(), tuple.getPersonA().getId() ); + Assert.assertEquals( tuple2Ver2.getPersonB().getId(), tuple.getPersonB().getId() ); + } - @Test - public void testHistoryOfPersonC() { - Person person = getAuditReader().find(Person.class, personCVer1.getId(), 2); + @Test + public void testHistoryOfPersonC() { + Person person = getAuditReader().find( Person.class, personCVer1.getId(), 2 ); - Assert.assertEquals(personCVer1, person); - Assert.assertEquals(personCVer1.getPersonATuples(), person.getPersonATuples()); - Assert.assertEquals(personCVer1.getPersonBTuples(), person.getPersonBTuples()); + Assert.assertEquals( personCVer1, person ); + Assert.assertEquals( personCVer1.getPersonATuples(), person.getPersonATuples() ); + Assert.assertEquals( personCVer1.getPersonBTuples(), person.getPersonBTuples() ); - person = getAuditReader().find(Person.class, personCVer2.getId(), 4); + person = getAuditReader().find( Person.class, personCVer2.getId(), 4 ); - Assert.assertEquals(personCVer2, person); - } + Assert.assertEquals( personCVer2, person ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/embeddedid/Person.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/embeddedid/Person.java index 5c834a651d..bb71de9a43 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/embeddedid/Person.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/embeddedid/Person.java @@ -1,12 +1,12 @@ package org.hibernate.envers.test.integration.onetomany.embeddedid; -import java.io.Serializable; -import java.util.HashSet; -import java.util.Set; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.OneToMany; +import java.io.Serializable; +import java.util.HashSet; +import java.util.Set; import org.hibernate.envers.Audited; @@ -16,84 +16,92 @@ import org.hibernate.envers.Audited; @Entity @Audited public class Person implements Serializable { - @Id - @GeneratedValue - private long id; + @Id + @GeneratedValue + private long id; - private String name; + private String name; - @OneToMany(mappedBy = "personA") - private Set personATuples = new HashSet(); + @OneToMany(mappedBy = "personA") + private Set personATuples = new HashSet(); - @OneToMany(mappedBy = "personB") - private Set personBTuples = new HashSet(); + @OneToMany(mappedBy = "personB") + private Set personBTuples = new HashSet(); - public Person() { - } + public Person() { + } - public Person(String name) { - this.name = name; - } + public Person(String name) { + this.name = name; + } - public Person(long id, String name) { - this.id = id; - this.name = name; - } + public Person(long id, String name) { + this.id = id; + this.name = name; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof Person)) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof Person) ) { + return false; + } - Person person = (Person) o; + Person person = (Person) o; - if (id != person.id) return false; - if (name != null ? !name.equals(person.name) : person.name != null) return false; + if ( id != person.id ) { + return false; + } + if ( name != null ? !name.equals( person.name ) : person.name != null ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - int result = (int) (id ^ (id >>> 32)); - result = 31 * result + (name != null ? name.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = (int) (id ^ (id >>> 32)); + result = 31 * result + (name != null ? name.hashCode() : 0); + return result; + } - @Override - public String toString() { - return "Person(id = " + id + ", name = " + name + ")"; - } + @Override + public String toString() { + return "Person(id = " + id + ", name = " + name + ")"; + } - public long getId() { - return id; - } + public long getId() { + return id; + } - public void setId(long id) { - this.id = id; - } + public void setId(long id) { + this.id = id; + } - public String getName() { - return name; - } + public String getName() { + return name; + } - public void setName(String name) { - this.name = name; - } + public void setName(String name) { + this.name = name; + } - public Set getPersonBTuples() { - return personBTuples; - } + public Set getPersonBTuples() { + return personBTuples; + } - public void setPersonBTuples(Set personBTuples) { - this.personBTuples = personBTuples; - } + public void setPersonBTuples(Set personBTuples) { + this.personBTuples = personBTuples; + } - public Set getPersonATuples() { - return personATuples; - } + public Set getPersonATuples() { + return personATuples; + } - public void setPersonATuples(Set personATuples) { - this.personATuples = personATuples; - } + public void setPersonATuples(Set personATuples) { + this.personATuples = personATuples; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/embeddedid/PersonTuple.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/embeddedid/PersonTuple.java index 0767999040..4a452ad679 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/embeddedid/PersonTuple.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/embeddedid/PersonTuple.java @@ -1,6 +1,5 @@ package org.hibernate.envers.test.integration.onetomany.embeddedid; -import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Embeddable; import javax.persistence.EmbeddedId; @@ -8,6 +7,7 @@ import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.MapsId; +import java.io.Serializable; import org.hibernate.envers.Audited; @@ -17,164 +17,178 @@ import org.hibernate.envers.Audited; @Entity @Audited public class PersonTuple implements Serializable { - @Embeddable - public static class PersonTupleId implements Serializable { - @Column(nullable = false) - private long personAId; + @Embeddable + public static class PersonTupleId implements Serializable { + @Column(nullable = false) + private long personAId; - @Column(nullable = false) - private long personBId; + @Column(nullable = false) + private long personBId; - @Column(nullable = false) - private String constantId; + @Column(nullable = false) + private String constantId; - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof PersonTupleId)) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof PersonTupleId) ) { + return false; + } - PersonTupleId that = (PersonTupleId) o; + PersonTupleId that = (PersonTupleId) o; - if (personAId != that.personAId) return false; - if (personBId != that.personBId) return false; - if (constantId != null ? !constantId.equals(that.constantId) : that.constantId != null) return false; + if ( personAId != that.personAId ) { + return false; + } + if ( personBId != that.personBId ) { + return false; + } + if ( constantId != null ? !constantId.equals( that.constantId ) : that.constantId != null ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - int result = (int) (personAId ^ (personAId >>> 32)); - result = 31 * result + (int) (personBId ^ (personBId >>> 32)); - result = 31 * result + (constantId != null ? constantId.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = (int) (personAId ^ (personAId >>> 32)); + result = 31 * result + (int) (personBId ^ (personBId >>> 32)); + result = 31 * result + (constantId != null ? constantId.hashCode() : 0); + return result; + } - @Override - public String toString() { - return "PersonTupleId(personAId = " + personAId + ", personBId = " + personBId + ", constantId = " + constantId + ")"; - } + @Override + public String toString() { + return "PersonTupleId(personAId = " + personAId + ", personBId = " + personBId + ", constantId = " + constantId + ")"; + } - public long getPersonAId() { - return personAId; - } + public long getPersonAId() { + return personAId; + } - public void setPersonAId(long personAId) { - this.personAId = personAId; - } + public void setPersonAId(long personAId) { + this.personAId = personAId; + } - public long getPersonBId() { - return personBId; - } + public long getPersonBId() { + return personBId; + } - public void setPersonBId(long personBId) { - this.personBId = personBId; - } + public void setPersonBId(long personBId) { + this.personBId = personBId; + } - public String getConstantId() { - return constantId; - } + public String getConstantId() { + return constantId; + } - public void setConstantId(String constantId) { - this.constantId = constantId; - } - } + public void setConstantId(String constantId) { + this.constantId = constantId; + } + } - @EmbeddedId - private PersonTupleId personTupleId = new PersonTupleId(); + @EmbeddedId + private PersonTupleId personTupleId = new PersonTupleId(); - @MapsId("personAId") - @ManyToOne(optional = false) - @JoinColumn(insertable = false, updatable = false, nullable=false) - private Person personA; + @MapsId("personAId") + @ManyToOne(optional = false) + @JoinColumn(insertable = false, updatable = false, nullable = false) + private Person personA; - @MapsId("personBId") - @ManyToOne(optional = false) - @JoinColumn(insertable = false, updatable = false, nullable=false) - private Person personB; + @MapsId("personBId") + @ManyToOne(optional = false) + @JoinColumn(insertable = false, updatable = false, nullable = false) + private Person personB; - @MapsId("constantId") - @ManyToOne(optional = false) - @JoinColumn(insertable = false, updatable = false, nullable=false) - private Constant constant; + @MapsId("constantId") + @ManyToOne(optional = false) + @JoinColumn(insertable = false, updatable = false, nullable = false) + private Constant constant; - @Column(nullable = false) - private boolean helloWorld = false; + @Column(nullable = false) + private boolean helloWorld = false; - public PersonTuple() { - } + public PersonTuple() { + } - public PersonTuple(boolean helloWorld, Person personA, Person personB, Constant constant) { - this.helloWorld = helloWorld; - this.personA = personA; - this.personB = personB; - this.constant = constant; + public PersonTuple(boolean helloWorld, Person personA, Person personB, Constant constant) { + this.helloWorld = helloWorld; + this.personA = personA; + this.personB = personB; + this.constant = constant; - this.personTupleId.personAId = personA.getId(); - this.personTupleId.personBId = personB.getId(); - this.personTupleId.constantId = constant.getId(); + this.personTupleId.personAId = personA.getId(); + this.personTupleId.personBId = personB.getId(); + this.personTupleId.constantId = constant.getId(); - personA.getPersonATuples().add(this); - personB.getPersonBTuples().add(this); - } + personA.getPersonATuples().add( this ); + personB.getPersonBTuples().add( this ); + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof PersonTuple)) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof PersonTuple) ) { + return false; + } - PersonTuple that = (PersonTuple) o; + PersonTuple that = (PersonTuple) o; - return personTupleId.equals(that.personTupleId); - } + return personTupleId.equals( that.personTupleId ); + } - @Override - public int hashCode() { - return personTupleId.hashCode(); - } + @Override + public int hashCode() { + return personTupleId.hashCode(); + } - @Override - public String toString() { - return "PersonTuple(id = " + personTupleId + ", helloWorld = " + helloWorld + ")"; - } + @Override + public String toString() { + return "PersonTuple(id = " + personTupleId + ", helloWorld = " + helloWorld + ")"; + } - public PersonTupleId getPersonTupleId() { - return personTupleId; - } + public PersonTupleId getPersonTupleId() { + return personTupleId; + } - public void setPersonTupleId(PersonTupleId personTupleId) { - this.personTupleId = personTupleId; - } + public void setPersonTupleId(PersonTupleId personTupleId) { + this.personTupleId = personTupleId; + } - public Person getPersonA() { - return personA; - } + public Person getPersonA() { + return personA; + } - public void setPersonA(Person personA) { - this.personA = personA; - } + public void setPersonA(Person personA) { + this.personA = personA; + } - public Person getPersonB() { - return personB; - } + public Person getPersonB() { + return personB; + } - public void setPersonB(Person personB) { - this.personB = personB; - } + public void setPersonB(Person personB) { + this.personB = personB; + } - public Constant getConstant() { - return constant; - } + public Constant getConstant() { + return constant; + } - public void setConstant(Constant constant) { - this.constant = constant; - } + public void setConstant(Constant constant) { + this.constant = constant; + } - public boolean isHelloWorld() { - return helloWorld; - } + public boolean isHelloWorld() { + return helloWorld; + } - public void setHelloWorld(boolean helloWorld) { - this.helloWorld = helloWorld; - } + public void setHelloWorld(boolean helloWorld) { + this.helloWorld = helloWorld; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/hierarchy/HierarchyTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/hierarchy/HierarchyTest.java index ea7cef8db2..d9dbd07e60 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/hierarchy/HierarchyTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/hierarchy/HierarchyTest.java @@ -1,14 +1,15 @@ package org.hibernate.envers.test.integration.onetomany.hierarchy; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Assert; -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.tools.TestTools; + +import org.junit.Assert; +import org.junit.Test; + import org.hibernate.testing.TestForIssue; /** @@ -16,92 +17,92 @@ import org.hibernate.testing.TestForIssue; */ @TestForIssue(jiraKey = "HHH-6661") public class HierarchyTest extends BaseEnversJPAFunctionalTestCase { - private Long parentId = null; - private Long child1Id = null; - private Long child2Id = null; + private Long parentId = null; + private Long child1Id = null; + private Long child2Id = null; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { Node.class }; - } + return new Class[] {Node.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - // Revision 1 - em.getTransaction().begin(); - Node parent = new Node("parent", (Node)null); - Node child1 = new Node("child1", parent); - Node child2 = new Node("child2", parent); - parent.getChildren().add(child1); - parent.getChildren().add(child2); - em.persist(parent); - em.persist(child1); - em.persist(child2); - em.getTransaction().commit(); + // Revision 1 + em.getTransaction().begin(); + Node parent = new Node( "parent", (Node) null ); + Node child1 = new Node( "child1", parent ); + Node child2 = new Node( "child2", parent ); + parent.getChildren().add( child1 ); + parent.getChildren().add( child2 ); + em.persist( parent ); + em.persist( child1 ); + em.persist( child2 ); + em.getTransaction().commit(); - parentId = parent.getId(); - child1Id = child1.getId(); - child2Id = child2.getId(); + parentId = parent.getId(); + child1Id = child1.getId(); + child2Id = child2.getId(); - // Revision 2 - em.getTransaction().begin(); - parent = em.find(Node.class, parent.getId()); - parent.getChildren().get(0).setData("child1 modified"); - em.getTransaction().commit(); + // Revision 2 + em.getTransaction().begin(); + parent = em.find( Node.class, parent.getId() ); + parent.getChildren().get( 0 ).setData( "child1 modified" ); + em.getTransaction().commit(); - // Revision 3 - em.getTransaction().begin(); - child2 = em.find(Node.class, child2.getId()); - em.remove(child2); - em.getTransaction().commit(); - } + // Revision 3 + em.getTransaction().begin(); + child2 = em.find( Node.class, child2.getId() ); + em.remove( child2 ); + em.getTransaction().commit(); + } - @Test - public void testRevisionsCounts() { - Assert.assertEquals(Arrays.asList(1, 3), getAuditReader().getRevisions(Node.class, parentId)); - Assert.assertEquals(Arrays.asList(1, 2), getAuditReader().getRevisions(Node.class, child1Id)); - Assert.assertEquals(Arrays.asList(1, 3), getAuditReader().getRevisions(Node.class, child2Id)); - } + @Test + public void testRevisionsCounts() { + Assert.assertEquals( Arrays.asList( 1, 3 ), getAuditReader().getRevisions( Node.class, parentId ) ); + Assert.assertEquals( Arrays.asList( 1, 2 ), getAuditReader().getRevisions( Node.class, child1Id ) ); + Assert.assertEquals( Arrays.asList( 1, 3 ), getAuditReader().getRevisions( Node.class, child2Id ) ); + } - @Test - public void testHistoryOfParentNode() { - Node parent = new Node("parent", parentId); - Node child1 = new Node("child1", child1Id); - Node child2 = new Node("child2", child2Id); + @Test + public void testHistoryOfParentNode() { + Node parent = new Node( "parent", parentId ); + Node child1 = new Node( "child1", child1Id ); + Node child2 = new Node( "child2", child2Id ); - Node ver1 = getAuditReader().find(Node.class, parentId, 1); - Assert.assertEquals(parent, ver1); - Assert.assertTrue(TestTools.checkList(ver1.getChildren(), child1, child2)); + Node ver1 = getAuditReader().find( Node.class, parentId, 1 ); + Assert.assertEquals( parent, ver1 ); + Assert.assertTrue( TestTools.checkList( ver1.getChildren(), child1, child2 ) ); - child1.setData("child1 modified"); + child1.setData( "child1 modified" ); - Node ver2 = getAuditReader().find(Node.class, parentId, 2); - Assert.assertEquals(parent, ver2); - Assert.assertTrue(TestTools.checkList(ver2.getChildren(), child1, child2)); + Node ver2 = getAuditReader().find( Node.class, parentId, 2 ); + Assert.assertEquals( parent, ver2 ); + Assert.assertTrue( TestTools.checkList( ver2.getChildren(), child1, child2 ) ); - Node ver3 = getAuditReader().find(Node.class, parentId, 3); - Assert.assertEquals(parent, ver3); - Assert.assertTrue(TestTools.checkList(ver3.getChildren(), child1)); - } + Node ver3 = getAuditReader().find( Node.class, parentId, 3 ); + Assert.assertEquals( parent, ver3 ); + Assert.assertTrue( TestTools.checkList( ver3.getChildren(), child1 ) ); + } - @Test - public void testHistoryOfChild1Node() { - Node parent = new Node("parent", parentId); - Node child1 = new Node("child1", child1Id); + @Test + public void testHistoryOfChild1Node() { + Node parent = new Node( "parent", parentId ); + Node child1 = new Node( "child1", child1Id ); - Node ver1 = getAuditReader().find(Node.class, child1Id, 1); - Assert.assertEquals(child1, ver1); - Assert.assertEquals(parent.getId(), ver1.getParent().getId()); - Assert.assertEquals(parent.getData(), ver1.getParent().getData()); + Node ver1 = getAuditReader().find( Node.class, child1Id, 1 ); + Assert.assertEquals( child1, ver1 ); + Assert.assertEquals( parent.getId(), ver1.getParent().getId() ); + Assert.assertEquals( parent.getData(), ver1.getParent().getData() ); - child1.setData("child1 modified"); + child1.setData( "child1 modified" ); - Node ver2 = getAuditReader().find(Node.class, child1Id, 2); - Assert.assertEquals(child1, ver2); - Assert.assertEquals(parent.getId(), ver2.getParent().getId()); - Assert.assertEquals(parent.getData(), ver2.getParent().getData()); - } + Node ver2 = getAuditReader().find( Node.class, child1Id, 2 ); + Assert.assertEquals( child1, ver2 ); + Assert.assertEquals( parent.getId(), ver2.getParent().getId() ); + Assert.assertEquals( parent.getData(), ver2.getParent().getData() ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/hierarchy/Node.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/hierarchy/Node.java index c8265cb50c..e936e19b06 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/hierarchy/Node.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/hierarchy/Node.java @@ -1,8 +1,5 @@ package org.hibernate.envers.test.integration.onetomany.hierarchy; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; @@ -12,6 +9,9 @@ import javax.persistence.JoinTable; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.Table; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; import org.hibernate.envers.AuditJoinTable; import org.hibernate.envers.Audited; @@ -23,90 +23,98 @@ import org.hibernate.envers.Audited; @Table(name = "NODES") @Audited public class Node implements Serializable { - @Id - @GeneratedValue - private Long id; + @Id + @GeneratedValue + private Long id; - private String data; + private String data; - @ManyToOne(fetch = FetchType.LAZY, optional = true) - @AuditJoinTable(name = "NODES_JOIN_TABLE_AUD", - inverseJoinColumns = {@JoinColumn(name = "PARENT_ID", nullable = true, updatable = false)}) - @JoinTable(name = "NODES_JOIN_TABLE", - joinColumns = {@JoinColumn(name = "CHILD_ID", nullable = true, updatable = false)}, - inverseJoinColumns = {@JoinColumn(name = "PARENT_ID", nullable = true, updatable = false)}) - private Node parent; + @ManyToOne(fetch = FetchType.LAZY, optional = true) + @AuditJoinTable(name = "NODES_JOIN_TABLE_AUD", + inverseJoinColumns = {@JoinColumn(name = "PARENT_ID", nullable = true, updatable = false)}) + @JoinTable(name = "NODES_JOIN_TABLE", + joinColumns = {@JoinColumn(name = "CHILD_ID", nullable = true, updatable = false)}, + inverseJoinColumns = {@JoinColumn(name = "PARENT_ID", nullable = true, updatable = false)}) + private Node parent; - @OneToMany(mappedBy = "parent") - private List children = new ArrayList(); + @OneToMany(mappedBy = "parent") + private List children = new ArrayList(); - public Node() { - } + public Node() { + } - public Node(String data, Node parent) { - this.data = data; - this.parent = parent; - } + public Node(String data, Node parent) { + this.data = data; + this.parent = parent; + } - public Node(String data, Long id) { - this.id = id; - this.data = data; - } + public Node(String data, Long id) { + this.id = id; + this.data = data; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof Node)) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof Node) ) { + return false; + } - Node node = (Node) o; + Node node = (Node) o; - if (data != null ? !data.equals(node.data) : node.data != null) return false; - if (id != null ? !id.equals(node.id) : node.id != null) return false; + if ( data != null ? !data.equals( node.data ) : node.data != null ) { + return false; + } + if ( id != null ? !id.equals( node.id ) : node.id != null ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - int result = id != null ? id.hashCode() : 0; - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = id != null ? id.hashCode() : 0; + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - @Override - public String toString() { - return "Node(id = " + id + ", data = " + data + ")"; - } + @Override + public String toString() { + return "Node(id = " + id + ", data = " + data + ")"; + } - public Long getId() { - return id; - } + public Long getId() { + return id; + } - public void setId(Long id) { - this.id = id; - } + public void setId(Long id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public Node getParent() { - return parent; - } + public Node getParent() { + return parent; + } - public void setParent(Node parent) { - this.parent = parent; - } + public void setParent(Node parent) { + this.parent = parent; + } - public List getChildren() { - return children; - } + public List getChildren() { + return children; + } - public void setChildren(List children) { - this.children = children; - } + public void setChildren(List children) { + this.children = children; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/inverseToSuperclass/DetailSubclass.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/inverseToSuperclass/DetailSubclass.java index 5216b11333..0ba21bef2a 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/inverseToSuperclass/DetailSubclass.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/inverseToSuperclass/DetailSubclass.java @@ -1,4 +1,5 @@ package org.hibernate.envers.test.integration.onetomany.inverseToSuperclass; + import org.hibernate.envers.Audited; @Audited diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/inverseToSuperclass/DetailSubclass2.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/inverseToSuperclass/DetailSubclass2.java index ec3c111e34..fc453ad97c 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/inverseToSuperclass/DetailSubclass2.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/inverseToSuperclass/DetailSubclass2.java @@ -1,4 +1,5 @@ package org.hibernate.envers.test.integration.onetomany.inverseToSuperclass; + import org.hibernate.envers.Audited; @Audited @@ -7,7 +8,7 @@ public class DetailSubclass2 extends DetailSubclass { private String str3; public DetailSubclass2() { - + } public String getStr3() { diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/inverseToSuperclass/DetailSuperclass.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/inverseToSuperclass/DetailSuperclass.java index 11de49656f..bfcf346250 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/inverseToSuperclass/DetailSuperclass.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/inverseToSuperclass/DetailSuperclass.java @@ -1,4 +1,5 @@ package org.hibernate.envers.test.integration.onetomany.inverseToSuperclass; + import org.hibernate.envers.Audited; @Audited diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/inverseToSuperclass/Master.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/inverseToSuperclass/Master.java index ba6dccb7a1..bf3a87dc67 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/inverseToSuperclass/Master.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/inverseToSuperclass/Master.java @@ -1,4 +1,5 @@ package org.hibernate.envers.test.integration.onetomany.inverseToSuperclass; + import java.util.List; import org.hibernate.envers.Audited; diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/inverseToSuperclass/OneToManyInverseToSuperclassTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/inverseToSuperclass/OneToManyInverseToSuperclassTest.java index 0097db671b..68daa68379 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/inverseToSuperclass/OneToManyInverseToSuperclassTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetomany/inverseToSuperclass/OneToManyInverseToSuperclassTest.java @@ -1,16 +1,15 @@ package org.hibernate.envers.test.integration.onetomany.inverseToSuperclass; -import java.util.ArrayList; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.ArrayList; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; +import org.junit.Test; + /** * @author Hern�n Chanfreau - * */ public class OneToManyInverseToSuperclassTest extends BaseEnversJPAFunctionalTestCase { @@ -19,11 +18,11 @@ public class OneToManyInverseToSuperclassTest extends BaseEnversJPAFunctionalTes @Override protected String[] getMappings() { - return new String[] { "mappings/oneToMany/inverseToSuperclass/mappings.hbm.xml" }; + return new String[] {"mappings/oneToMany/inverseToSuperclass/mappings.hbm.xml"}; } @Test - @Priority(10) + @Priority(10) public void initData() { EntityManager em = getEntityManager(); @@ -34,66 +33,66 @@ public class OneToManyInverseToSuperclassTest extends BaseEnversJPAFunctionalTes // Revision 1 em.getTransaction().begin(); - det1.setStr2("detail 1"); + det1.setStr2( "detail 1" ); - m1.setStr("master"); - m1.setItems(new ArrayList()); - m1.getItems().add(det1); - det1.setParent(m1); + m1.setStr( "master" ); + m1.setItems( new ArrayList() ); + m1.getItems().add( det1 ); + det1.setParent( m1 ); - em.persist(m1); + em.persist( m1 ); em.getTransaction().commit(); m1_id = m1.getId(); // Revision 2 em.getTransaction().begin(); - m1 = em.find(Master.class, m1_id); + m1 = em.find( Master.class, m1_id ); - det2.setStr2("detail 2"); - det2.setParent(m1); - m1.getItems().add(det2); + det2.setStr2( "detail 2" ); + det2.setParent( m1 ); + m1.getItems().add( det2 ); em.getTransaction().commit(); // Revision 3 em.getTransaction().begin(); - m1 = em.find(Master.class, m1_id); - m1.setStr("new master"); + m1 = em.find( Master.class, m1_id ); + m1.setStr( "new master" ); - det1 = m1.getItems().get(0); - det1.setStr2("new detail"); + det1 = m1.getItems().get( 0 ); + det1.setStr2( "new detail" ); DetailSubclass det3 = new DetailSubclass2(); - det3.setStr2("detail 3"); - det3.setParent(m1); + det3.setStr2( "detail 3" ); + det3.setParent( m1 ); - m1.getItems().get(1).setParent(null); + m1.getItems().get( 1 ).setParent( null ); // m1.getItems().remove(1); - m1.getItems().add(det3); + m1.getItems().add( det3 ); - em.persist(m1); + em.persist( m1 ); em.getTransaction().commit(); // Revision 4 em.getTransaction().begin(); - m1 = em.find(Master.class, m1_id); + m1 = em.find( Master.class, m1_id ); - det1 = m1.getItems().get(0); - det1.setParent(null); + det1 = m1.getItems().get( 0 ); + det1.setParent( null ); // m1.getItems().remove(det1); - em.persist(m1); + em.persist( m1 ); em.getTransaction().commit(); } @Test public void testHistoryExists() { - Master rev1_1 = getAuditReader().find(Master.class, m1_id, 1); - Master rev1_2 = getAuditReader().find(Master.class, m1_id, 2); - Master rev1_3 = getAuditReader().find(Master.class, m1_id, 3); - Master rev1_4 = getAuditReader().find(Master.class, m1_id, 4); + Master rev1_1 = getAuditReader().find( Master.class, m1_id, 1 ); + Master rev1_2 = getAuditReader().find( Master.class, m1_id, 2 ); + Master rev1_3 = getAuditReader().find( Master.class, m1_id, 3 ); + Master rev1_4 = getAuditReader().find( Master.class, m1_id, 4 ); assert (rev1_1 != null); assert (rev1_2 != null); diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/BiRefEdEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/BiRefEdEntity.java index 068c178af9..6cb675f524 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/BiRefEdEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/BiRefEdEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.onetoone.bidirectional; + import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.OneToOne; @@ -33,70 +34,78 @@ import org.hibernate.envers.Audited; */ @Entity public class BiRefEdEntity { - @Id - private Integer id; + @Id + private Integer id; - @Audited - private String data; + @Audited + private String data; - @Audited - @OneToOne(mappedBy="reference") - private BiRefIngEntity referencing; + @Audited + @OneToOne(mappedBy = "reference") + private BiRefIngEntity referencing; - public BiRefEdEntity() { - } + public BiRefEdEntity() { + } - public BiRefEdEntity(Integer id, String data) { - this.id = id; - this.data = data; - } + public BiRefEdEntity(Integer id, String data) { + this.id = id; + this.data = data; + } - public BiRefEdEntity(Integer id, String data, BiRefIngEntity referencing) { - this.id = id; - this.data = data; - this.referencing = referencing; - } + public BiRefEdEntity(Integer id, String data, BiRefIngEntity referencing) { + this.id = id; + this.data = data; + this.referencing = referencing; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public BiRefIngEntity getReferencing() { - return referencing; - } + public BiRefIngEntity getReferencing() { + return referencing; + } - public void setReferencing(BiRefIngEntity referencing) { - this.referencing = referencing; - } + public void setReferencing(BiRefIngEntity referencing) { + this.referencing = referencing; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof BiRefEdEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof BiRefEdEntity) ) { + return false; + } - BiRefEdEntity that = (BiRefEdEntity) o; + BiRefEdEntity that = (BiRefEdEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/BiRefIngEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/BiRefIngEntity.java index b7ef5a7863..dabc358929 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/BiRefIngEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/BiRefIngEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.onetoone.bidirectional; + import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.OneToOne; @@ -33,70 +34,78 @@ import org.hibernate.envers.Audited; */ @Entity public class BiRefIngEntity { - @Id - private Integer id; + @Id + private Integer id; - @Audited - private String data; + @Audited + private String data; - @Audited - @OneToOne - private BiRefEdEntity reference; + @Audited + @OneToOne + private BiRefEdEntity reference; - public BiRefIngEntity() { - } + public BiRefIngEntity() { + } - public BiRefIngEntity(Integer id, String data) { - this.id = id; - this.data = data; - } + public BiRefIngEntity(Integer id, String data) { + this.id = id; + this.data = data; + } - public BiRefIngEntity(Integer id, String data, BiRefEdEntity reference) { - this.id = id; - this.data = data; - this.reference = reference; - } + public BiRefIngEntity(Integer id, String data, BiRefEdEntity reference) { + this.id = id; + this.data = data; + this.reference = reference; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public BiRefEdEntity getReference() { - return reference; - } + public BiRefEdEntity getReference() { + return reference; + } - public void setReference(BiRefEdEntity reference) { - this.reference = reference; - } + public void setReference(BiRefEdEntity reference) { + this.reference = reference; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof BiRefIngEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof BiRefIngEntity) ) { + return false; + } - BiRefIngEntity that = (BiRefIngEntity) o; + BiRefIngEntity that = (BiRefIngEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/Bidirectional.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/Bidirectional.java index b83e565367..bc5086049f 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/Bidirectional.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/Bidirectional.java @@ -23,94 +23,94 @@ */ package org.hibernate.envers.test.integration.onetoone.bidirectional; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class Bidirectional extends BaseEnversJPAFunctionalTestCase { - private Integer ed1_id; - private Integer ed2_id; + private Integer ed1_id; + private Integer ed2_id; - private Integer ing1_id; + private Integer ing1_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { BiRefEdEntity.class, BiRefIngEntity.class }; - } + return new Class[] {BiRefEdEntity.class, BiRefIngEntity.class}; + } - @Test - @Priority(10) - public void initData() { - BiRefEdEntity ed1 = new BiRefEdEntity(1, "data_ed_1"); - BiRefEdEntity ed2 = new BiRefEdEntity(2, "data_ed_2"); + @Test + @Priority(10) + public void initData() { + BiRefEdEntity ed1 = new BiRefEdEntity( 1, "data_ed_1" ); + BiRefEdEntity ed2 = new BiRefEdEntity( 2, "data_ed_2" ); - BiRefIngEntity ing1 = new BiRefIngEntity(3, "data_ing_1"); + BiRefIngEntity ing1 = new BiRefIngEntity( 3, "data_ing_1" ); - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); - ing1.setReference(ed1); + ing1.setReference( ed1 ); - em.persist(ed1); - em.persist(ed2); + em.persist( ed1 ); + em.persist( ed2 ); - em.persist(ing1); + em.persist( ing1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); + // Revision 2 + em.getTransaction().begin(); - ing1 = em.find(BiRefIngEntity.class, ing1.getId()); - ed2 = em.find(BiRefEdEntity.class, ed2.getId()); + ing1 = em.find( BiRefIngEntity.class, ing1.getId() ); + ed2 = em.find( BiRefEdEntity.class, ed2.getId() ); - ing1.setReference(ed2); + ing1.setReference( ed2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // + // - ed1_id = ed1.getId(); - ed2_id = ed2.getId(); + ed1_id = ed1.getId(); + ed2_id = ed2.getId(); - ing1_id = ing1.getId(); - } + ing1_id = ing1.getId(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(BiRefEdEntity.class, ed1_id)); - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(BiRefEdEntity.class, ed2_id)); + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( BiRefEdEntity.class, ed1_id ) ); + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( BiRefEdEntity.class, ed2_id ) ); - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(BiRefIngEntity.class, ing1_id)); - } + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( BiRefIngEntity.class, ing1_id ) ); + } - @Test - public void testHistoryOfEdId1() { - BiRefIngEntity ing1 = getEntityManager().find(BiRefIngEntity.class, ing1_id); + @Test + public void testHistoryOfEdId1() { + BiRefIngEntity ing1 = getEntityManager().find( BiRefIngEntity.class, ing1_id ); - BiRefEdEntity rev1 = getAuditReader().find(BiRefEdEntity.class, ed1_id, 1); - BiRefEdEntity rev2 = getAuditReader().find(BiRefEdEntity.class, ed1_id, 2); + BiRefEdEntity rev1 = getAuditReader().find( BiRefEdEntity.class, ed1_id, 1 ); + BiRefEdEntity rev2 = getAuditReader().find( BiRefEdEntity.class, ed1_id, 2 ); - assert rev1.getReferencing().equals(ing1); - assert rev2.getReferencing() == null; - } + assert rev1.getReferencing().equals( ing1 ); + assert rev2.getReferencing() == null; + } - @Test - public void testHistoryOfEdId2() { - BiRefIngEntity ing1 = getEntityManager().find(BiRefIngEntity.class, ing1_id); + @Test + public void testHistoryOfEdId2() { + BiRefIngEntity ing1 = getEntityManager().find( BiRefIngEntity.class, ing1_id ); - BiRefEdEntity rev1 = getAuditReader().find(BiRefEdEntity.class, ed2_id, 1); - BiRefEdEntity rev2 = getAuditReader().find(BiRefEdEntity.class, ed2_id, 2); - - assert rev1.getReferencing() == null; - assert rev2.getReferencing().equals(ing1); - } + BiRefEdEntity rev1 = getAuditReader().find( BiRefEdEntity.class, ed2_id, 1 ); + BiRefEdEntity rev2 = getAuditReader().find( BiRefEdEntity.class, ed2_id, 2 ); + + assert rev1.getReferencing() == null; + assert rev2.getReferencing().equals( ing1 ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/Bidirectional2.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/Bidirectional2.java index 6ddfcc0084..20bd984779 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/Bidirectional2.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/Bidirectional2.java @@ -23,129 +23,129 @@ */ package org.hibernate.envers.test.integration.onetoone.bidirectional; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class Bidirectional2 extends BaseEnversJPAFunctionalTestCase { - private Integer ed1_id; - private Integer ed2_id; + private Integer ed1_id; + private Integer ed2_id; - private Integer ing1_id; - private Integer ing2_id; + private Integer ing1_id; + private Integer ing2_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { BiRefEdEntity.class, BiRefIngEntity.class }; - } + return new Class[] {BiRefEdEntity.class, BiRefIngEntity.class}; + } - @Test - @Priority(10) - public void initData() { - BiRefEdEntity ed1 = new BiRefEdEntity(1, "data_ed_1"); - BiRefEdEntity ed2 = new BiRefEdEntity(2, "data_ed_2"); + @Test + @Priority(10) + public void initData() { + BiRefEdEntity ed1 = new BiRefEdEntity( 1, "data_ed_1" ); + BiRefEdEntity ed2 = new BiRefEdEntity( 2, "data_ed_2" ); - BiRefIngEntity ing1 = new BiRefIngEntity(3, "data_ing_1"); - BiRefIngEntity ing2 = new BiRefIngEntity(4, "data_ing_2"); + BiRefIngEntity ing1 = new BiRefIngEntity( 3, "data_ing_1" ); + BiRefIngEntity ing2 = new BiRefIngEntity( 4, "data_ing_2" ); - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); - em.persist(ed1); - em.persist(ed2); + em.persist( ed1 ); + em.persist( ed2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); + // Revision 2 + em.getTransaction().begin(); - ed1 = em.find(BiRefEdEntity.class, ed1.getId()); + ed1 = em.find( BiRefEdEntity.class, ed1.getId() ); - ing1.setReference(ed1); + ing1.setReference( ed1 ); - em.persist(ing1); - em.persist(ing2); + em.persist( ing1 ); + em.persist( ing2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 - em.getTransaction().begin(); + // Revision 3 + em.getTransaction().begin(); - ed1 = em.find(BiRefEdEntity.class, ed1.getId()); - ing1 = em.find(BiRefIngEntity.class, ing1.getId()); - ing2 = em.find(BiRefIngEntity.class, ing2.getId()); + ed1 = em.find( BiRefEdEntity.class, ed1.getId() ); + ing1 = em.find( BiRefIngEntity.class, ing1.getId() ); + ing2 = em.find( BiRefIngEntity.class, ing2.getId() ); - ing1.setReference(null); - ing2.setReference(ed1); + ing1.setReference( null ); + ing2.setReference( ed1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 4 - em.getTransaction().begin(); + // Revision 4 + em.getTransaction().begin(); - ed2 = em.find(BiRefEdEntity.class, ed2.getId()); - ing1 = em.find(BiRefIngEntity.class, ing1.getId()); - ing2 = em.find(BiRefIngEntity.class, ing2.getId()); + ed2 = em.find( BiRefEdEntity.class, ed2.getId() ); + ing1 = em.find( BiRefIngEntity.class, ing1.getId() ); + ing2 = em.find( BiRefIngEntity.class, ing2.getId() ); - ing1.setReference(ed2); - ing2.setReference(null); + ing1.setReference( ed2 ); + ing2.setReference( null ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // + // - ed1_id = ed1.getId(); - ed2_id = ed2.getId(); + ed1_id = ed1.getId(); + ed2_id = ed2.getId(); - ing1_id = ing1.getId(); - ing2_id = ing2.getId(); - } + ing1_id = ing1.getId(); + ing2_id = ing2.getId(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2, 3, 4).equals(getAuditReader().getRevisions(BiRefEdEntity.class, ed1_id)); - assert Arrays.asList(1, 4).equals(getAuditReader().getRevisions(BiRefEdEntity.class, ed2_id)); + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2, 3, 4 ).equals( getAuditReader().getRevisions( BiRefEdEntity.class, ed1_id ) ); + assert Arrays.asList( 1, 4 ).equals( getAuditReader().getRevisions( BiRefEdEntity.class, ed2_id ) ); - assert Arrays.asList(2, 3, 4).equals(getAuditReader().getRevisions(BiRefIngEntity.class, ing1_id)); - assert Arrays.asList(2, 3, 4).equals(getAuditReader().getRevisions(BiRefIngEntity.class, ing2_id)); - } + assert Arrays.asList( 2, 3, 4 ).equals( getAuditReader().getRevisions( BiRefIngEntity.class, ing1_id ) ); + assert Arrays.asList( 2, 3, 4 ).equals( getAuditReader().getRevisions( BiRefIngEntity.class, ing2_id ) ); + } - @Test - public void testHistoryOfEdId1() { - BiRefIngEntity ing1 = getEntityManager().find(BiRefIngEntity.class, ing1_id); - BiRefIngEntity ing2 = getEntityManager().find(BiRefIngEntity.class, ing2_id); + @Test + public void testHistoryOfEdId1() { + BiRefIngEntity ing1 = getEntityManager().find( BiRefIngEntity.class, ing1_id ); + BiRefIngEntity ing2 = getEntityManager().find( BiRefIngEntity.class, ing2_id ); - BiRefEdEntity rev1 = getAuditReader().find(BiRefEdEntity.class, ed1_id, 1); - BiRefEdEntity rev2 = getAuditReader().find(BiRefEdEntity.class, ed1_id, 2); - BiRefEdEntity rev3 = getAuditReader().find(BiRefEdEntity.class, ed1_id, 3); - BiRefEdEntity rev4 = getAuditReader().find(BiRefEdEntity.class, ed1_id, 4); + BiRefEdEntity rev1 = getAuditReader().find( BiRefEdEntity.class, ed1_id, 1 ); + BiRefEdEntity rev2 = getAuditReader().find( BiRefEdEntity.class, ed1_id, 2 ); + BiRefEdEntity rev3 = getAuditReader().find( BiRefEdEntity.class, ed1_id, 3 ); + BiRefEdEntity rev4 = getAuditReader().find( BiRefEdEntity.class, ed1_id, 4 ); - assert rev1.getReferencing() == null; - assert rev2.getReferencing().equals(ing1); - assert rev3.getReferencing().equals(ing2); - assert rev4.getReferencing() == null; - } + assert rev1.getReferencing() == null; + assert rev2.getReferencing().equals( ing1 ); + assert rev3.getReferencing().equals( ing2 ); + assert rev4.getReferencing() == null; + } - @Test - public void testHistoryOfEdId2() { - BiRefIngEntity ing1 = getEntityManager().find(BiRefIngEntity.class, ing1_id); + @Test + public void testHistoryOfEdId2() { + BiRefIngEntity ing1 = getEntityManager().find( BiRefIngEntity.class, ing1_id ); - BiRefEdEntity rev1 = getAuditReader().find(BiRefEdEntity.class, ed2_id, 1); - BiRefEdEntity rev2 = getAuditReader().find(BiRefEdEntity.class, ed2_id, 2); - BiRefEdEntity rev3 = getAuditReader().find(BiRefEdEntity.class, ed2_id, 3); - BiRefEdEntity rev4 = getAuditReader().find(BiRefEdEntity.class, ed2_id, 4); + BiRefEdEntity rev1 = getAuditReader().find( BiRefEdEntity.class, ed2_id, 1 ); + BiRefEdEntity rev2 = getAuditReader().find( BiRefEdEntity.class, ed2_id, 2 ); + BiRefEdEntity rev3 = getAuditReader().find( BiRefEdEntity.class, ed2_id, 3 ); + BiRefEdEntity rev4 = getAuditReader().find( BiRefEdEntity.class, ed2_id, 4 ); - assert rev1.getReferencing() == null; - assert rev2.getReferencing() == null; - assert rev3.getReferencing() == null; - assert rev4.getReferencing().equals(ing1); - } + assert rev1.getReferencing() == null; + assert rev2.getReferencing() == null; + assert rev3.getReferencing() == null; + assert rev4.getReferencing().equals( ing1 ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/BidirectionalEagerAnnotationTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/BidirectionalEagerAnnotationTest.java index b64b7f4e1b..50daacec93 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/BidirectionalEagerAnnotationTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/BidirectionalEagerAnnotationTest.java @@ -25,12 +25,13 @@ package org.hibernate.envers.test.integration.onetoone.bidirectional; import javax.persistence.EntityManager; -import org.junit.Test; - import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.onetoone.BidirectionalEagerAnnotationRefEdOneToOne; import org.hibernate.envers.test.entities.onetoone.BidirectionalEagerAnnotationRefIngOneToOne; + +import org.junit.Test; + import org.hibernate.testing.TestForIssue; import static org.junit.Assert.assertNotNull; diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/BidirectionalEagerHbmTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/BidirectionalEagerHbmTest.java index 75c5baf28e..1b5d29d381 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/BidirectionalEagerHbmTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/BidirectionalEagerHbmTest.java @@ -25,12 +25,13 @@ package org.hibernate.envers.test.integration.onetoone.bidirectional; import javax.persistence.EntityManager; -import org.junit.Test; - import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.onetoone.BidirectionalEagerHbmRefEdPK; import org.hibernate.envers.test.entities.onetoone.BidirectionalEagerHbmRefIngPK; + +import org.junit.Test; + import org.hibernate.testing.TestForIssue; import static org.junit.Assert.assertNotNull; @@ -44,7 +45,7 @@ public class BidirectionalEagerHbmTest extends BaseEnversJPAFunctionalTestCase { @Override protected String[] getMappings() { - return new String[] { "mappings/oneToOne/bidirectional/eagerLoading.hbm.xml" }; + return new String[] {"mappings/oneToOne/bidirectional/eagerLoading.hbm.xml"}; } @Test diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/BidirectionalNoNulls.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/BidirectionalNoNulls.java index 9f59dda26f..0621c7d925 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/BidirectionalNoNulls.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/BidirectionalNoNulls.java @@ -23,107 +23,107 @@ */ package org.hibernate.envers.test.integration.onetoone.bidirectional; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class BidirectionalNoNulls extends BaseEnversJPAFunctionalTestCase { - private Integer ed1_id; - private Integer ed2_id; + private Integer ed1_id; + private Integer ed2_id; - private Integer ing1_id; - private Integer ing2_id; + private Integer ing1_id; + private Integer ing2_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { BiRefEdEntity.class, BiRefIngEntity.class }; - } + return new Class[] {BiRefEdEntity.class, BiRefIngEntity.class}; + } - @Test - @Priority(10) - public void initData() { - BiRefEdEntity ed1 = new BiRefEdEntity(1, "data_ed_1"); - BiRefEdEntity ed2 = new BiRefEdEntity(2, "data_ed_2"); + @Test + @Priority(10) + public void initData() { + BiRefEdEntity ed1 = new BiRefEdEntity( 1, "data_ed_1" ); + BiRefEdEntity ed2 = new BiRefEdEntity( 2, "data_ed_2" ); - BiRefIngEntity ing1 = new BiRefIngEntity(3, "data_ing_1"); - BiRefIngEntity ing2 = new BiRefIngEntity(4, "data_ing_2"); + BiRefIngEntity ing1 = new BiRefIngEntity( 3, "data_ing_1" ); + BiRefIngEntity ing2 = new BiRefIngEntity( 4, "data_ing_2" ); - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); - ing1.setReference(ed1); - ing2.setReference(ed2); + ing1.setReference( ed1 ); + ing2.setReference( ed2 ); - em.persist(ed1); - em.persist(ed2); + em.persist( ed1 ); + em.persist( ed2 ); - em.persist(ing1); - em.persist(ing2); + em.persist( ing1 ); + em.persist( ing2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em = getEntityManager(); - em.getTransaction().begin(); + // Revision 2 + em = getEntityManager(); + em.getTransaction().begin(); - ing1 = em.find(BiRefIngEntity.class, ing1.getId()); - ing2 = em.find(BiRefIngEntity.class, ing2.getId()); + ing1 = em.find( BiRefIngEntity.class, ing1.getId() ); + ing2 = em.find( BiRefIngEntity.class, ing2.getId() ); - ed1 = em.find(BiRefEdEntity.class, ed1.getId()); - ed2 = em.find(BiRefEdEntity.class, ed2.getId()); + ed1 = em.find( BiRefEdEntity.class, ed1.getId() ); + ed2 = em.find( BiRefEdEntity.class, ed2.getId() ); - ing1.setReference(ed2); - ing2.setReference(ed1); + ing1.setReference( ed2 ); + ing2.setReference( ed1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // + // - ed1_id = ed1.getId(); - ed2_id = ed2.getId(); + ed1_id = ed1.getId(); + ed2_id = ed2.getId(); - ing1_id = ing1.getId(); - ing2_id = ing2.getId(); - } + ing1_id = ing1.getId(); + ing2_id = ing2.getId(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(BiRefEdEntity.class, ed1_id)); - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(BiRefEdEntity.class, ed2_id)); + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( BiRefEdEntity.class, ed1_id ) ); + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( BiRefEdEntity.class, ed2_id ) ); - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(BiRefIngEntity.class, ing1_id)); - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(BiRefIngEntity.class, ing2_id)); - } + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( BiRefIngEntity.class, ing1_id ) ); + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( BiRefIngEntity.class, ing2_id ) ); + } - @Test - public void testHistoryOfEdId1() { - BiRefIngEntity ing1 = getEntityManager().find(BiRefIngEntity.class, ing1_id); - BiRefIngEntity ing2 = getEntityManager().find(BiRefIngEntity.class, ing2_id); + @Test + public void testHistoryOfEdId1() { + BiRefIngEntity ing1 = getEntityManager().find( BiRefIngEntity.class, ing1_id ); + BiRefIngEntity ing2 = getEntityManager().find( BiRefIngEntity.class, ing2_id ); - BiRefEdEntity rev1 = getAuditReader().find(BiRefEdEntity.class, ed1_id, 1); - BiRefEdEntity rev2 = getAuditReader().find(BiRefEdEntity.class, ed1_id, 2); + BiRefEdEntity rev1 = getAuditReader().find( BiRefEdEntity.class, ed1_id, 1 ); + BiRefEdEntity rev2 = getAuditReader().find( BiRefEdEntity.class, ed1_id, 2 ); - assert rev1.getReferencing().equals(ing1); - assert rev2.getReferencing().equals(ing2); - } + assert rev1.getReferencing().equals( ing1 ); + assert rev2.getReferencing().equals( ing2 ); + } - @Test - public void testHistoryOfEdId2() { - BiRefIngEntity ing1 = getEntityManager().find(BiRefIngEntity.class, ing1_id); - BiRefIngEntity ing2 = getEntityManager().find(BiRefIngEntity.class, ing2_id); + @Test + public void testHistoryOfEdId2() { + BiRefIngEntity ing1 = getEntityManager().find( BiRefIngEntity.class, ing1_id ); + BiRefIngEntity ing2 = getEntityManager().find( BiRefIngEntity.class, ing2_id ); - BiRefEdEntity rev1 = getAuditReader().find(BiRefEdEntity.class, ed2_id, 1); - BiRefEdEntity rev2 = getAuditReader().find(BiRefEdEntity.class, ed2_id, 2); + BiRefEdEntity rev1 = getAuditReader().find( BiRefEdEntity.class, ed2_id, 1 ); + BiRefEdEntity rev2 = getAuditReader().find( BiRefEdEntity.class, ed2_id, 2 ); - assert rev1.getReferencing().equals(ing2); - assert rev2.getReferencing().equals(ing1); - } + assert rev1.getReferencing().equals( ing2 ); + assert rev2.getReferencing().equals( ing1 ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/ids/BiEmbIdRefEdEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/ids/BiEmbIdRefEdEntity.java index 481406872e..bf6b803054 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/ids/BiEmbIdRefEdEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/ids/BiEmbIdRefEdEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.onetoone.bidirectional.ids; + import javax.persistence.EmbeddedId; import javax.persistence.Entity; import javax.persistence.OneToOne; @@ -34,70 +35,78 @@ import org.hibernate.envers.test.entities.ids.EmbId; */ @Entity public class BiEmbIdRefEdEntity { - @EmbeddedId - private EmbId id; + @EmbeddedId + private EmbId id; - @Audited - private String data; + @Audited + private String data; - @Audited - @OneToOne(mappedBy="reference") - private BiEmbIdRefIngEntity referencing; + @Audited + @OneToOne(mappedBy = "reference") + private BiEmbIdRefIngEntity referencing; - public BiEmbIdRefEdEntity() { - } + public BiEmbIdRefEdEntity() { + } - public BiEmbIdRefEdEntity(EmbId id, String data) { - this.id = id; - this.data = data; - } + public BiEmbIdRefEdEntity(EmbId id, String data) { + this.id = id; + this.data = data; + } - public BiEmbIdRefEdEntity(EmbId id, String data, BiEmbIdRefIngEntity referencing) { - this.id = id; - this.data = data; - this.referencing = referencing; - } + public BiEmbIdRefEdEntity(EmbId id, String data, BiEmbIdRefIngEntity referencing) { + this.id = id; + this.data = data; + this.referencing = referencing; + } - public EmbId getId() { - return id; - } + public EmbId getId() { + return id; + } - public void setId(EmbId id) { - this.id = id; - } + public void setId(EmbId id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public BiEmbIdRefIngEntity getReferencing() { - return referencing; - } + public BiEmbIdRefIngEntity getReferencing() { + return referencing; + } - public void setReferencing(BiEmbIdRefIngEntity referencing) { - this.referencing = referencing; - } + public void setReferencing(BiEmbIdRefIngEntity referencing) { + this.referencing = referencing; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof BiEmbIdRefEdEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof BiEmbIdRefEdEntity) ) { + return false; + } - BiEmbIdRefEdEntity that = (BiEmbIdRefEdEntity) o; + BiEmbIdRefEdEntity that = (BiEmbIdRefEdEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/ids/BiEmbIdRefIngEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/ids/BiEmbIdRefIngEntity.java index 7eb93dedf8..e36bf5b991 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/ids/BiEmbIdRefIngEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/ids/BiEmbIdRefIngEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.onetoone.bidirectional.ids; + import javax.persistence.EmbeddedId; import javax.persistence.Entity; import javax.persistence.OneToOne; @@ -34,70 +35,78 @@ import org.hibernate.envers.test.entities.ids.EmbId; */ @Entity public class BiEmbIdRefIngEntity { - @EmbeddedId - private EmbId id; + @EmbeddedId + private EmbId id; - @Audited - private String data; + @Audited + private String data; - @Audited - @OneToOne - private BiEmbIdRefEdEntity reference; + @Audited + @OneToOne + private BiEmbIdRefEdEntity reference; - public BiEmbIdRefIngEntity() { - } + public BiEmbIdRefIngEntity() { + } - public BiEmbIdRefIngEntity(EmbId id, String data) { - this.id = id; - this.data = data; - } + public BiEmbIdRefIngEntity(EmbId id, String data) { + this.id = id; + this.data = data; + } - public BiEmbIdRefIngEntity(EmbId id, String data, BiEmbIdRefEdEntity reference) { - this.id = id; - this.data = data; - this.reference = reference; - } + public BiEmbIdRefIngEntity(EmbId id, String data, BiEmbIdRefEdEntity reference) { + this.id = id; + this.data = data; + this.reference = reference; + } - public EmbId getId() { - return id; - } + public EmbId getId() { + return id; + } - public void setId(EmbId id) { - this.id = id; - } + public void setId(EmbId id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public BiEmbIdRefEdEntity getReference() { - return reference; - } + public BiEmbIdRefEdEntity getReference() { + return reference; + } - public void setReference(BiEmbIdRefEdEntity reference) { - this.reference = reference; - } + public void setReference(BiEmbIdRefEdEntity reference) { + this.reference = reference; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof BiEmbIdRefIngEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof BiEmbIdRefIngEntity) ) { + return false; + } - BiEmbIdRefIngEntity that = (BiEmbIdRefIngEntity) o; + BiEmbIdRefIngEntity that = (BiEmbIdRefIngEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/ids/BiMulIdRefEdEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/ids/BiMulIdRefEdEntity.java index 7ee7ee2419..49cb2cefac 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/ids/BiMulIdRefEdEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/ids/BiMulIdRefEdEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.onetoone.bidirectional.ids; + import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.IdClass; @@ -36,78 +37,88 @@ import org.hibernate.envers.test.entities.ids.MulId; @Entity @IdClass(MulId.class) public class BiMulIdRefEdEntity { - @Id - private Integer id1; + @Id + private Integer id1; - @Id - private Integer id2; + @Id + private Integer id2; - @Audited - private String data; + @Audited + private String data; - @Audited - @OneToOne(mappedBy="reference") - private BiMulIdRefIngEntity referencing; + @Audited + @OneToOne(mappedBy = "reference") + private BiMulIdRefIngEntity referencing; - public BiMulIdRefEdEntity() { - } + public BiMulIdRefEdEntity() { + } - public BiMulIdRefEdEntity(Integer id1, Integer id2, String data) { - this.id1 = id1; - this.id2 = id2; - this.data = data; - } + public BiMulIdRefEdEntity(Integer id1, Integer id2, String data) { + this.id1 = id1; + this.id2 = id2; + this.data = data; + } - public Integer getId1() { - return id1; - } + public Integer getId1() { + return id1; + } - public void setId1(Integer id1) { - this.id1 = id1; - } + public void setId1(Integer id1) { + this.id1 = id1; + } - public Integer getId2() { - return id2; - } + public Integer getId2() { + return id2; + } - public void setId2(Integer id2) { - this.id2 = id2; - } + public void setId2(Integer id2) { + this.id2 = id2; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public BiMulIdRefIngEntity getReferencing() { - return referencing; - } + public BiMulIdRefIngEntity getReferencing() { + return referencing; + } - public void setReferencing(BiMulIdRefIngEntity referencing) { - this.referencing = referencing; - } + public void setReferencing(BiMulIdRefIngEntity referencing) { + this.referencing = referencing; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof BiMulIdRefEdEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof BiMulIdRefEdEntity) ) { + return false; + } - BiMulIdRefEdEntity that = (BiMulIdRefEdEntity) o; + BiMulIdRefEdEntity that = (BiMulIdRefEdEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id1 != null ? !id1.equals(that.id1) : that.id1 != null) return false; - if (id2 != null ? !id2.equals(that.id2) : that.id2 != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id1 != null ? !id1.equals( that.id1 ) : that.id1 != null ) { + return false; + } + if ( id2 != null ? !id2.equals( that.id2 ) : that.id2 != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id1 != null ? id1.hashCode() : 0); - result = 31 * result + (id2 != null ? id2.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id1 != null ? id1.hashCode() : 0); + result = 31 * result + (id2 != null ? id2.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/ids/BiMulIdRefIngEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/ids/BiMulIdRefIngEntity.java index 5973d93f29..a83bad0f28 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/ids/BiMulIdRefIngEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/ids/BiMulIdRefIngEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.onetoone.bidirectional.ids; + import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.IdClass; @@ -36,78 +37,88 @@ import org.hibernate.envers.test.entities.ids.MulId; @Entity @IdClass(MulId.class) public class BiMulIdRefIngEntity { - @Id - private Integer id1; + @Id + private Integer id1; - @Id - private Integer id2; + @Id + private Integer id2; - @Audited - private String data; + @Audited + private String data; - @Audited - @OneToOne - private BiMulIdRefEdEntity reference; + @Audited + @OneToOne + private BiMulIdRefEdEntity reference; - public BiMulIdRefIngEntity() { - } + public BiMulIdRefIngEntity() { + } - public BiMulIdRefIngEntity(Integer id1, Integer id2, String data) { - this.id1 = id1; - this.id2 = id2; - this.data = data; - } + public BiMulIdRefIngEntity(Integer id1, Integer id2, String data) { + this.id1 = id1; + this.id2 = id2; + this.data = data; + } - public Integer getId1() { - return id1; - } + public Integer getId1() { + return id1; + } - public void setId1(Integer id1) { - this.id1 = id1; - } + public void setId1(Integer id1) { + this.id1 = id1; + } - public Integer getId2() { - return id2; - } + public Integer getId2() { + return id2; + } - public void setId2(Integer id2) { - this.id2 = id2; - } + public void setId2(Integer id2) { + this.id2 = id2; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public BiMulIdRefEdEntity getReference() { - return reference; - } + public BiMulIdRefEdEntity getReference() { + return reference; + } - public void setReference(BiMulIdRefEdEntity reference) { - this.reference = reference; - } + public void setReference(BiMulIdRefEdEntity reference) { + this.reference = reference; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof BiMulIdRefIngEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof BiMulIdRefIngEntity) ) { + return false; + } - BiMulIdRefIngEntity that = (BiMulIdRefIngEntity) o; + BiMulIdRefIngEntity that = (BiMulIdRefIngEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id1 != null ? !id1.equals(that.id1) : that.id1 != null) return false; - if (id2 != null ? !id2.equals(that.id2) : that.id2 != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id1 != null ? !id1.equals( that.id1 ) : that.id1 != null ) { + return false; + } + if ( id2 != null ? !id2.equals( that.id2 ) : that.id2 != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id1 != null ? id1.hashCode() : 0); - result = 31 * result + (id2 != null ? id2.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id1 != null ? id1.hashCode() : 0); + result = 31 * result + (id2 != null ? id2.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/ids/EmbIdBidirectional.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/ids/EmbIdBidirectional.java index 6fd81ef659..b713c87056 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/ids/EmbIdBidirectional.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/ids/EmbIdBidirectional.java @@ -23,105 +23,105 @@ */ package org.hibernate.envers.test.integration.onetoone.bidirectional.ids; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.ids.EmbId; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class EmbIdBidirectional extends BaseEnversJPAFunctionalTestCase { - private EmbId ed1_id; - private EmbId ed2_id; + private EmbId ed1_id; + private EmbId ed2_id; - private EmbId ing1_id; + private EmbId ing1_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { BiEmbIdRefEdEntity.class, BiEmbIdRefIngEntity.class }; - } + return new Class[] {BiEmbIdRefEdEntity.class, BiEmbIdRefIngEntity.class}; + } - @Test - @Priority(10) - public void initData() { - ed1_id = new EmbId(1, 2); - ed2_id = new EmbId(3, 4); + @Test + @Priority(10) + public void initData() { + ed1_id = new EmbId( 1, 2 ); + ed2_id = new EmbId( 3, 4 ); - ing1_id = new EmbId(5, 6); + ing1_id = new EmbId( 5, 6 ); - BiEmbIdRefEdEntity ed1 = new BiEmbIdRefEdEntity(ed1_id, "data_ed_1"); - BiEmbIdRefEdEntity ed2 = new BiEmbIdRefEdEntity(ed2_id, "data_ed_2"); + BiEmbIdRefEdEntity ed1 = new BiEmbIdRefEdEntity( ed1_id, "data_ed_1" ); + BiEmbIdRefEdEntity ed2 = new BiEmbIdRefEdEntity( ed2_id, "data_ed_2" ); - BiEmbIdRefIngEntity ing1 = new BiEmbIdRefIngEntity(ing1_id, "data_ing_1"); + BiEmbIdRefIngEntity ing1 = new BiEmbIdRefIngEntity( ing1_id, "data_ing_1" ); - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); - ing1.setReference(ed1); + ing1.setReference( ed1 ); - em.persist(ed1); - em.persist(ed2); + em.persist( ed1 ); + em.persist( ed2 ); - em.persist(ing1); + em.persist( ing1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); + // Revision 2 + em.getTransaction().begin(); - ing1 = em.find(BiEmbIdRefIngEntity.class, ing1.getId()); - ed2 = em.find(BiEmbIdRefEdEntity.class, ed2.getId()); + ing1 = em.find( BiEmbIdRefIngEntity.class, ing1.getId() ); + ed2 = em.find( BiEmbIdRefEdEntity.class, ed2.getId() ); - ing1.setReference(ed2); + ing1.setReference( ed2 ); - em.getTransaction().commit(); - } + em.getTransaction().commit(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(BiEmbIdRefEdEntity.class, ed1_id)); - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(BiEmbIdRefEdEntity.class, ed2_id)); + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( BiEmbIdRefEdEntity.class, ed1_id ) ); + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( BiEmbIdRefEdEntity.class, ed2_id ) ); - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(BiEmbIdRefIngEntity.class, ing1_id)); - } + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( BiEmbIdRefIngEntity.class, ing1_id ) ); + } - @Test - public void testHistoryOfEdId1() { - BiEmbIdRefIngEntity ing1 = getEntityManager().find(BiEmbIdRefIngEntity.class, ing1_id); + @Test + public void testHistoryOfEdId1() { + BiEmbIdRefIngEntity ing1 = getEntityManager().find( BiEmbIdRefIngEntity.class, ing1_id ); - BiEmbIdRefEdEntity rev1 = getAuditReader().find(BiEmbIdRefEdEntity.class, ed1_id, 1); - BiEmbIdRefEdEntity rev2 = getAuditReader().find(BiEmbIdRefEdEntity.class, ed1_id, 2); + BiEmbIdRefEdEntity rev1 = getAuditReader().find( BiEmbIdRefEdEntity.class, ed1_id, 1 ); + BiEmbIdRefEdEntity rev2 = getAuditReader().find( BiEmbIdRefEdEntity.class, ed1_id, 2 ); - assert rev1.getReferencing().equals(ing1); - assert rev2.getReferencing() == null; - } + assert rev1.getReferencing().equals( ing1 ); + assert rev2.getReferencing() == null; + } - @Test - public void testHistoryOfEdId2() { - BiEmbIdRefIngEntity ing1 = getEntityManager().find(BiEmbIdRefIngEntity.class, ing1_id); + @Test + public void testHistoryOfEdId2() { + BiEmbIdRefIngEntity ing1 = getEntityManager().find( BiEmbIdRefIngEntity.class, ing1_id ); - BiEmbIdRefEdEntity rev1 = getAuditReader().find(BiEmbIdRefEdEntity.class, ed2_id, 1); - BiEmbIdRefEdEntity rev2 = getAuditReader().find(BiEmbIdRefEdEntity.class, ed2_id, 2); + BiEmbIdRefEdEntity rev1 = getAuditReader().find( BiEmbIdRefEdEntity.class, ed2_id, 1 ); + BiEmbIdRefEdEntity rev2 = getAuditReader().find( BiEmbIdRefEdEntity.class, ed2_id, 2 ); - assert rev1.getReferencing() == null; - assert rev2.getReferencing().equals(ing1); - } + assert rev1.getReferencing() == null; + assert rev2.getReferencing().equals( ing1 ); + } - @Test - public void testHistoryOfIngId1() { - BiEmbIdRefEdEntity ed1 = getEntityManager().find(BiEmbIdRefEdEntity.class, ed1_id); - BiEmbIdRefEdEntity ed2 = getEntityManager().find(BiEmbIdRefEdEntity.class, ed2_id); + @Test + public void testHistoryOfIngId1() { + BiEmbIdRefEdEntity ed1 = getEntityManager().find( BiEmbIdRefEdEntity.class, ed1_id ); + BiEmbIdRefEdEntity ed2 = getEntityManager().find( BiEmbIdRefEdEntity.class, ed2_id ); - BiEmbIdRefIngEntity rev1 = getAuditReader().find(BiEmbIdRefIngEntity.class, ing1_id, 1); - BiEmbIdRefIngEntity rev2 = getAuditReader().find(BiEmbIdRefIngEntity.class, ing1_id, 2); + BiEmbIdRefIngEntity rev1 = getAuditReader().find( BiEmbIdRefIngEntity.class, ing1_id, 1 ); + BiEmbIdRefIngEntity rev2 = getAuditReader().find( BiEmbIdRefIngEntity.class, ing1_id, 2 ); - assert rev1.getReference().equals(ed1); - assert rev2.getReference().equals(ed2); - } + assert rev1.getReference().equals( ed1 ); + assert rev2.getReference().equals( ed2 ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/ids/MulIdBidirectional.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/ids/MulIdBidirectional.java index 19ee468b4a..da1087c79c 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/ids/MulIdBidirectional.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/ids/MulIdBidirectional.java @@ -23,105 +23,105 @@ */ package org.hibernate.envers.test.integration.onetoone.bidirectional.ids; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.ids.MulId; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class MulIdBidirectional extends BaseEnversJPAFunctionalTestCase { - private MulId ed1_id; - private MulId ed2_id; + private MulId ed1_id; + private MulId ed2_id; - private MulId ing1_id; + private MulId ing1_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { BiMulIdRefEdEntity.class, BiMulIdRefIngEntity.class }; - } + return new Class[] {BiMulIdRefEdEntity.class, BiMulIdRefIngEntity.class}; + } - @Test - @Priority(10) - public void initData() { - ed1_id = new MulId(1, 2); - ed2_id = new MulId(3, 4); + @Test + @Priority(10) + public void initData() { + ed1_id = new MulId( 1, 2 ); + ed2_id = new MulId( 3, 4 ); - ing1_id = new MulId(5, 6); + ing1_id = new MulId( 5, 6 ); - BiMulIdRefEdEntity ed1 = new BiMulIdRefEdEntity(ed1_id.getId1(), ed1_id.getId2(), "data_ed_1"); - BiMulIdRefEdEntity ed2 = new BiMulIdRefEdEntity(ed2_id.getId1(), ed2_id.getId2(), "data_ed_2"); + BiMulIdRefEdEntity ed1 = new BiMulIdRefEdEntity( ed1_id.getId1(), ed1_id.getId2(), "data_ed_1" ); + BiMulIdRefEdEntity ed2 = new BiMulIdRefEdEntity( ed2_id.getId1(), ed2_id.getId2(), "data_ed_2" ); - BiMulIdRefIngEntity ing1 = new BiMulIdRefIngEntity(ing1_id.getId1(), ing1_id.getId2(), "data_ing_1"); + BiMulIdRefIngEntity ing1 = new BiMulIdRefIngEntity( ing1_id.getId1(), ing1_id.getId2(), "data_ing_1" ); - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); - ing1.setReference(ed1); + ing1.setReference( ed1 ); - em.persist(ed1); - em.persist(ed2); + em.persist( ed1 ); + em.persist( ed2 ); - em.persist(ing1); + em.persist( ing1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); + // Revision 2 + em.getTransaction().begin(); - ing1 = em.find(BiMulIdRefIngEntity.class, ing1_id); - ed2 = em.find(BiMulIdRefEdEntity.class, ed2_id); + ing1 = em.find( BiMulIdRefIngEntity.class, ing1_id ); + ed2 = em.find( BiMulIdRefEdEntity.class, ed2_id ); - ing1.setReference(ed2); + ing1.setReference( ed2 ); - em.getTransaction().commit(); - } + em.getTransaction().commit(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(BiMulIdRefEdEntity.class, ed1_id)); - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(BiMulIdRefEdEntity.class, ed2_id)); + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( BiMulIdRefEdEntity.class, ed1_id ) ); + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( BiMulIdRefEdEntity.class, ed2_id ) ); - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(BiMulIdRefIngEntity.class, ing1_id)); - } + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( BiMulIdRefIngEntity.class, ing1_id ) ); + } - @Test - public void testHistoryOfEdId1() { - BiMulIdRefIngEntity ing1 = getEntityManager().find(BiMulIdRefIngEntity.class, ing1_id); + @Test + public void testHistoryOfEdId1() { + BiMulIdRefIngEntity ing1 = getEntityManager().find( BiMulIdRefIngEntity.class, ing1_id ); - BiMulIdRefEdEntity rev1 = getAuditReader().find(BiMulIdRefEdEntity.class, ed1_id, 1); - BiMulIdRefEdEntity rev2 = getAuditReader().find(BiMulIdRefEdEntity.class, ed1_id, 2); + BiMulIdRefEdEntity rev1 = getAuditReader().find( BiMulIdRefEdEntity.class, ed1_id, 1 ); + BiMulIdRefEdEntity rev2 = getAuditReader().find( BiMulIdRefEdEntity.class, ed1_id, 2 ); - assert rev1.getReferencing().equals(ing1); - assert rev2.getReferencing() == null; - } + assert rev1.getReferencing().equals( ing1 ); + assert rev2.getReferencing() == null; + } - @Test - public void testHistoryOfEdId2() { - BiMulIdRefIngEntity ing1 = getEntityManager().find(BiMulIdRefIngEntity.class, ing1_id); + @Test + public void testHistoryOfEdId2() { + BiMulIdRefIngEntity ing1 = getEntityManager().find( BiMulIdRefIngEntity.class, ing1_id ); - BiMulIdRefEdEntity rev1 = getAuditReader().find(BiMulIdRefEdEntity.class, ed2_id, 1); - BiMulIdRefEdEntity rev2 = getAuditReader().find(BiMulIdRefEdEntity.class, ed2_id, 2); + BiMulIdRefEdEntity rev1 = getAuditReader().find( BiMulIdRefEdEntity.class, ed2_id, 1 ); + BiMulIdRefEdEntity rev2 = getAuditReader().find( BiMulIdRefEdEntity.class, ed2_id, 2 ); - assert rev1.getReferencing() == null; - assert rev2.getReferencing().equals(ing1); - } + assert rev1.getReferencing() == null; + assert rev2.getReferencing().equals( ing1 ); + } - @Test - public void testHistoryOfIngId1() { - BiMulIdRefEdEntity ed1 = getEntityManager().find(BiMulIdRefEdEntity.class, ed1_id); - BiMulIdRefEdEntity ed2 = getEntityManager().find(BiMulIdRefEdEntity.class, ed2_id); + @Test + public void testHistoryOfIngId1() { + BiMulIdRefEdEntity ed1 = getEntityManager().find( BiMulIdRefEdEntity.class, ed1_id ); + BiMulIdRefEdEntity ed2 = getEntityManager().find( BiMulIdRefEdEntity.class, ed2_id ); - BiMulIdRefIngEntity rev1 = getAuditReader().find(BiMulIdRefIngEntity.class, ing1_id, 1); - BiMulIdRefIngEntity rev2 = getAuditReader().find(BiMulIdRefIngEntity.class, ing1_id, 2); + BiMulIdRefIngEntity rev1 = getAuditReader().find( BiMulIdRefIngEntity.class, ing1_id, 1 ); + BiMulIdRefIngEntity rev2 = getAuditReader().find( BiMulIdRefIngEntity.class, ing1_id, 2 ); - assert rev1.getReference().equals(ed1); - assert rev2.getReference().equals(ed2); - } + assert rev1.getReference().equals( ed1 ); + assert rev2.getReference().equals( ed2 ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/primarykeyjoincolumn/Account.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/primarykeyjoincolumn/Account.java index 6c011e6584..b2eaa31820 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/primarykeyjoincolumn/Account.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/primarykeyjoincolumn/Account.java @@ -1,12 +1,12 @@ package org.hibernate.envers.test.integration.onetoone.bidirectional.primarykeyjoincolumn; -import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.OneToOne; import javax.persistence.PrimaryKeyJoinColumn; +import java.io.Serializable; import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.Parameter; @@ -18,77 +18,85 @@ import org.hibernate.envers.Audited; @Entity @Audited public class Account implements Serializable { - @Id - @Column(name = "ACCOUNT_ID") - @GeneratedValue(generator = "AccountForeignKeyGenerator") - @GenericGenerator(name = "AccountForeignKeyGenerator", strategy = "foreign", - parameters = {@Parameter(name = "property", value = "owner")}) - private Long accountId; + @Id + @Column(name = "ACCOUNT_ID") + @GeneratedValue(generator = "AccountForeignKeyGenerator") + @GenericGenerator(name = "AccountForeignKeyGenerator", strategy = "foreign", + parameters = {@Parameter(name = "property", value = "owner")}) + private Long accountId; - private String type; + private String type; - @OneToOne(optional = false) - @PrimaryKeyJoinColumn(name = "ACCOUNT_ID", referencedColumnName = "PERSON_ID") - private Person owner; + @OneToOne(optional = false) + @PrimaryKeyJoinColumn(name = "ACCOUNT_ID", referencedColumnName = "PERSON_ID") + private Person owner; - public Account() { - } + public Account() { + } - public Account(String type) { - this.type = type; - } + public Account(String type) { + this.type = type; + } - public Account(Long accountId, String type) { - this.accountId = accountId; - this.type = type; - } + public Account(Long accountId, String type) { + this.accountId = accountId; + this.type = type; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof Account)) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof Account) ) { + return false; + } - Account account = (Account) o; + Account account = (Account) o; - if (accountId != null ? !accountId.equals(account.accountId) : account.accountId != null) return false; - if (type != null ? !type.equals(account.type) : account.type != null) return false; + if ( accountId != null ? !accountId.equals( account.accountId ) : account.accountId != null ) { + return false; + } + if ( type != null ? !type.equals( account.type ) : account.type != null ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - int result = accountId != null ? accountId.hashCode() : 0; - result = 31 * result + (type != null ? type.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = accountId != null ? accountId.hashCode() : 0; + result = 31 * result + (type != null ? type.hashCode() : 0); + return result; + } - @Override - public String toString() { - return "Account(accountId = " + accountId + ", type = " + type + ")"; - } + @Override + public String toString() { + return "Account(accountId = " + accountId + ", type = " + type + ")"; + } - public Long getAccountId() { - return accountId; - } + public Long getAccountId() { + return accountId; + } - public void setAccountId(Long accountId) { - this.accountId = accountId; - } + public void setAccountId(Long accountId) { + this.accountId = accountId; + } - public Person getOwner() { - return owner; - } + public Person getOwner() { + return owner; + } - public void setOwner(Person owner) { - this.owner = owner; - } + public void setOwner(Person owner) { + this.owner = owner; + } - public String getType() { - return type; - } + public String getType() { + return type; + } - public void setType(String type) { - this.type = type; - } + public void setType(String type) { + this.type = type; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/primarykeyjoincolumn/AccountNotAuditedOwners.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/primarykeyjoincolumn/AccountNotAuditedOwners.java index 6a11954bb7..8f9a97d2eb 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/primarykeyjoincolumn/AccountNotAuditedOwners.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/primarykeyjoincolumn/AccountNotAuditedOwners.java @@ -1,12 +1,12 @@ package org.hibernate.envers.test.integration.onetoone.bidirectional.primarykeyjoincolumn; -import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.OneToOne; +import java.io.Serializable; import org.hibernate.envers.Audited; import org.hibernate.envers.RelationTargetAuditMode; @@ -17,87 +17,95 @@ import org.hibernate.envers.RelationTargetAuditMode; @Entity @Audited public class AccountNotAuditedOwners implements Serializable { - @Id - @Column(name = "ACCOUNT_ID") - @GeneratedValue - private Long accountId; + @Id + @Column(name = "ACCOUNT_ID") + @GeneratedValue + private Long accountId; - private String type; + private String type; - @OneToOne(mappedBy = "account", optional = false) - @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED) - private NotAuditedNoProxyPerson owner; + @OneToOne(mappedBy = "account", optional = false) + @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED) + private NotAuditedNoProxyPerson owner; - @OneToOne(mappedBy = "account", optional = false, fetch = FetchType.LAZY) - @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED) - private NotAuditedProxyPerson coOwner; + @OneToOne(mappedBy = "account", optional = false, fetch = FetchType.LAZY) + @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED) + private NotAuditedProxyPerson coOwner; - public AccountNotAuditedOwners() { - } + public AccountNotAuditedOwners() { + } - public AccountNotAuditedOwners(String type) { - this.type = type; - } + public AccountNotAuditedOwners(String type) { + this.type = type; + } - public AccountNotAuditedOwners(Long accountId, String type) { - this.accountId = accountId; - this.type = type; - } + public AccountNotAuditedOwners(Long accountId, String type) { + this.accountId = accountId; + this.type = type; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof AccountNotAuditedOwners)) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof AccountNotAuditedOwners) ) { + return false; + } - AccountNotAuditedOwners account = (AccountNotAuditedOwners) o; + AccountNotAuditedOwners account = (AccountNotAuditedOwners) o; - if (accountId != null ? !accountId.equals(account.accountId) : account.accountId != null) return false; - if (type != null ? !type.equals(account.type) : account.type != null) return false; + if ( accountId != null ? !accountId.equals( account.accountId ) : account.accountId != null ) { + return false; + } + if ( type != null ? !type.equals( account.type ) : account.type != null ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - int result = accountId != null ? accountId.hashCode() : 0; - result = 31 * result + (type != null ? type.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = accountId != null ? accountId.hashCode() : 0; + result = 31 * result + (type != null ? type.hashCode() : 0); + return result; + } - @Override - public String toString() { - return "AccountNotAuditedOwners(accountId = " + accountId + ", type = " + type + ")"; - } + @Override + public String toString() { + return "AccountNotAuditedOwners(accountId = " + accountId + ", type = " + type + ")"; + } - public Long getAccountId() { - return accountId; - } + public Long getAccountId() { + return accountId; + } - public void setAccountId(Long accountId) { - this.accountId = accountId; - } + public void setAccountId(Long accountId) { + this.accountId = accountId; + } - public NotAuditedNoProxyPerson getOwner() { - return owner; - } + public NotAuditedNoProxyPerson getOwner() { + return owner; + } - public void setOwner(NotAuditedNoProxyPerson owner) { - this.owner = owner; - } + public void setOwner(NotAuditedNoProxyPerson owner) { + this.owner = owner; + } - public NotAuditedProxyPerson getCoOwner() { - return coOwner; - } + public NotAuditedProxyPerson getCoOwner() { + return coOwner; + } - public void setCoOwner(NotAuditedProxyPerson coOwner) { - this.coOwner = coOwner; - } + public void setCoOwner(NotAuditedProxyPerson coOwner) { + this.coOwner = coOwner; + } - public String getType() { - return type; - } + public String getType() { + return type; + } - public void setType(String type) { - this.type = type; - } + public void setType(String type) { + this.type = type; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/primarykeyjoincolumn/NotAuditedNoProxyPerson.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/primarykeyjoincolumn/NotAuditedNoProxyPerson.java index c249c556e2..857a6d693a 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/primarykeyjoincolumn/NotAuditedNoProxyPerson.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/primarykeyjoincolumn/NotAuditedNoProxyPerson.java @@ -1,12 +1,12 @@ package org.hibernate.envers.test.integration.onetoone.bidirectional.primarykeyjoincolumn; -import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.OneToOne; import javax.persistence.PrimaryKeyJoinColumn; +import java.io.Serializable; import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.Parameter; @@ -18,77 +18,85 @@ import org.hibernate.annotations.Proxy; @Entity @Proxy(lazy = false) public class NotAuditedNoProxyPerson implements Serializable { - @Id - @Column(name = "PERSON_ID") - @GeneratedValue(generator = "NotAuditedNoProxyKeyGenerator") - @GenericGenerator(name = "NotAuditedNoProxyKeyGenerator", strategy = "foreign", - parameters = {@Parameter(name = "property", value = "account")}) - private Long personId; + @Id + @Column(name = "PERSON_ID") + @GeneratedValue(generator = "NotAuditedNoProxyKeyGenerator") + @GenericGenerator(name = "NotAuditedNoProxyKeyGenerator", strategy = "foreign", + parameters = {@Parameter(name = "property", value = "account")}) + private Long personId; - private String name; + private String name; - @OneToOne(optional = false) - @PrimaryKeyJoinColumn(name = "PERSON_ID", referencedColumnName = "ACCOUNT_ID") - private AccountNotAuditedOwners account; + @OneToOne(optional = false) + @PrimaryKeyJoinColumn(name = "PERSON_ID", referencedColumnName = "ACCOUNT_ID") + private AccountNotAuditedOwners account; - public NotAuditedNoProxyPerson() { - } + public NotAuditedNoProxyPerson() { + } - public NotAuditedNoProxyPerson(String name) { - this.name = name; - } + public NotAuditedNoProxyPerson(String name) { + this.name = name; + } - public NotAuditedNoProxyPerson(Long personId, String name) { - this.personId = personId; - this.name = name; - } + public NotAuditedNoProxyPerson(Long personId, String name) { + this.personId = personId; + this.name = name; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof NotAuditedNoProxyPerson)) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof NotAuditedNoProxyPerson) ) { + return false; + } - NotAuditedNoProxyPerson person = (NotAuditedNoProxyPerson) o; + NotAuditedNoProxyPerson person = (NotAuditedNoProxyPerson) o; - if (personId != null ? !personId.equals(person.personId) : person.personId != null) return false; - if (name != null ? !name.equals(person.name) : person.name != null) return false; + if ( personId != null ? !personId.equals( person.personId ) : person.personId != null ) { + return false; + } + if ( name != null ? !name.equals( person.name ) : person.name != null ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - int result = personId != null ? personId.hashCode() : 0; - result = 31 * result + (name != null ? name.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = personId != null ? personId.hashCode() : 0; + result = 31 * result + (name != null ? name.hashCode() : 0); + return result; + } - @Override - public String toString() { - return "NotAuditedNoProxyPerson(personId = " + personId + ", name = " + name + ")"; - } + @Override + public String toString() { + return "NotAuditedNoProxyPerson(personId = " + personId + ", name = " + name + ")"; + } - public Long getPersonId() { - return personId; - } + public Long getPersonId() { + return personId; + } - public void setPersonId(Long personId) { - this.personId = personId; - } + public void setPersonId(Long personId) { + this.personId = personId; + } - public String getName() { - return name; - } + public String getName() { + return name; + } - public void setName(String name) { - this.name = name; - } + public void setName(String name) { + this.name = name; + } - public AccountNotAuditedOwners getAccount() { - return account; - } + public AccountNotAuditedOwners getAccount() { + return account; + } - public void setAccount(AccountNotAuditedOwners account) { - this.account = account; - } + public void setAccount(AccountNotAuditedOwners account) { + this.account = account; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/primarykeyjoincolumn/NotAuditedProxyPerson.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/primarykeyjoincolumn/NotAuditedProxyPerson.java index ae7c88e151..a19a60d5c9 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/primarykeyjoincolumn/NotAuditedProxyPerson.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/primarykeyjoincolumn/NotAuditedProxyPerson.java @@ -1,6 +1,5 @@ package org.hibernate.envers.test.integration.onetoone.bidirectional.primarykeyjoincolumn; -import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; @@ -8,6 +7,7 @@ import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.OneToOne; import javax.persistence.PrimaryKeyJoinColumn; +import java.io.Serializable; import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.Parameter; @@ -19,77 +19,85 @@ import org.hibernate.annotations.Proxy; @Entity @Proxy(lazy = true) public class NotAuditedProxyPerson implements Serializable { - @Id - @Column(name = "PERSON_ID") - @GeneratedValue(generator = "NotAuditedProxyKeyGenerator") - @GenericGenerator(name = "NotAuditedProxyKeyGenerator", strategy = "foreign", - parameters = {@Parameter(name = "property", value = "account")}) - private Long personId; + @Id + @Column(name = "PERSON_ID") + @GeneratedValue(generator = "NotAuditedProxyKeyGenerator") + @GenericGenerator(name = "NotAuditedProxyKeyGenerator", strategy = "foreign", + parameters = {@Parameter(name = "property", value = "account")}) + private Long personId; - private String name; + private String name; - @OneToOne(optional = false, fetch = FetchType.LAZY) - @PrimaryKeyJoinColumn(name = "PERSON_ID", referencedColumnName = "ACCOUNT_ID") - private AccountNotAuditedOwners account; + @OneToOne(optional = false, fetch = FetchType.LAZY) + @PrimaryKeyJoinColumn(name = "PERSON_ID", referencedColumnName = "ACCOUNT_ID") + private AccountNotAuditedOwners account; - public NotAuditedProxyPerson() { - } + public NotAuditedProxyPerson() { + } - public NotAuditedProxyPerson(String name) { - this.name = name; - } + public NotAuditedProxyPerson(String name) { + this.name = name; + } - public NotAuditedProxyPerson(Long personId, String name) { - this.personId = personId; - this.name = name; - } + public NotAuditedProxyPerson(Long personId, String name) { + this.personId = personId; + this.name = name; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof NotAuditedProxyPerson)) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof NotAuditedProxyPerson) ) { + return false; + } - NotAuditedProxyPerson person = (NotAuditedProxyPerson) o; + NotAuditedProxyPerson person = (NotAuditedProxyPerson) o; - if (personId != null ? !personId.equals(person.personId) : person.personId != null) return false; - if (name != null ? !name.equals(person.name) : person.name != null) return false; + if ( personId != null ? !personId.equals( person.personId ) : person.personId != null ) { + return false; + } + if ( name != null ? !name.equals( person.name ) : person.name != null ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - int result = personId != null ? personId.hashCode() : 0; - result = 31 * result + (name != null ? name.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = personId != null ? personId.hashCode() : 0; + result = 31 * result + (name != null ? name.hashCode() : 0); + return result; + } - @Override - public String toString() { - return "NotAuditedProxyPerson(personId = " + personId + ", name = " + name + ")"; - } + @Override + public String toString() { + return "NotAuditedProxyPerson(personId = " + personId + ", name = " + name + ")"; + } - public Long getPersonId() { - return personId; - } + public Long getPersonId() { + return personId; + } - public void setPersonId(Long personId) { - this.personId = personId; - } + public void setPersonId(Long personId) { + this.personId = personId; + } - public String getName() { - return name; - } + public String getName() { + return name; + } - public void setName(String name) { - this.name = name; - } + public void setName(String name) { + this.name = name; + } - public AccountNotAuditedOwners getAccount() { - return account; - } + public AccountNotAuditedOwners getAccount() { + return account; + } - public void setAccount(AccountNotAuditedOwners account) { - this.account = account; - } + public void setAccount(AccountNotAuditedOwners account) { + this.account = account; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/primarykeyjoincolumn/OneToOneWithPrimaryKeyJoinTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/primarykeyjoincolumn/OneToOneWithPrimaryKeyJoinTest.java index 53a49d44b3..7aea79eb2b 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/primarykeyjoincolumn/OneToOneWithPrimaryKeyJoinTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/primarykeyjoincolumn/OneToOneWithPrimaryKeyJoinTest.java @@ -1,16 +1,17 @@ package org.hibernate.envers.test.integration.onetoone.bidirectional.primarykeyjoincolumn; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Assert; -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.RevisionType; import org.hibernate.envers.query.AuditEntity; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.proxy.HibernateProxy; + +import org.junit.Assert; +import org.junit.Test; + import org.hibernate.testing.TestForIssue; /** @@ -18,11 +19,11 @@ import org.hibernate.testing.TestForIssue; */ @TestForIssue(jiraKey = "HHH-6825") public class OneToOneWithPrimaryKeyJoinTest extends BaseEnversJPAFunctionalTestCase { - private Long personId = null; - private Long accountId = null; - private Long proxyPersonId = null; - private Long noProxyPersonId = null; - private Long accountNotAuditedOwnersId = null; + private Long personId = null; + private Long accountId = null; + private Long proxyPersonId = null; + private Long noProxyPersonId = null; + private Long accountNotAuditedOwnersId = null; @Override protected Class[] getAnnotatedClasses() { @@ -33,109 +34,128 @@ public class OneToOneWithPrimaryKeyJoinTest extends BaseEnversJPAFunctionalTestC NotAuditedNoProxyPerson.class, NotAuditedProxyPerson.class }; - } + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - // Revision 1 - em.getTransaction().begin(); - Person person = new Person("Robert"); - Account account = new Account("Saving"); - person.setAccount(account); - account.setOwner(person); - em.persist(person); - em.persist(account); - em.getTransaction().commit(); + // Revision 1 + em.getTransaction().begin(); + Person person = new Person( "Robert" ); + Account account = new Account( "Saving" ); + person.setAccount( account ); + account.setOwner( person ); + em.persist( person ); + em.persist( account ); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); - NotAuditedNoProxyPerson noProxyPerson = new NotAuditedNoProxyPerson("Kinga"); - NotAuditedProxyPerson proxyPerson = new NotAuditedProxyPerson("Lukasz"); - AccountNotAuditedOwners accountNotAuditedOwners = new AccountNotAuditedOwners("Standard"); - noProxyPerson.setAccount(accountNotAuditedOwners); - proxyPerson.setAccount(accountNotAuditedOwners); - accountNotAuditedOwners.setOwner(noProxyPerson); - accountNotAuditedOwners.setCoOwner(proxyPerson); - em.persist(accountNotAuditedOwners); - em.persist(noProxyPerson); - em.persist(proxyPerson); - em.getTransaction().commit(); + // Revision 2 + em.getTransaction().begin(); + NotAuditedNoProxyPerson noProxyPerson = new NotAuditedNoProxyPerson( "Kinga" ); + NotAuditedProxyPerson proxyPerson = new NotAuditedProxyPerson( "Lukasz" ); + AccountNotAuditedOwners accountNotAuditedOwners = new AccountNotAuditedOwners( "Standard" ); + noProxyPerson.setAccount( accountNotAuditedOwners ); + proxyPerson.setAccount( accountNotAuditedOwners ); + accountNotAuditedOwners.setOwner( noProxyPerson ); + accountNotAuditedOwners.setCoOwner( proxyPerson ); + em.persist( accountNotAuditedOwners ); + em.persist( noProxyPerson ); + em.persist( proxyPerson ); + em.getTransaction().commit(); - personId = person.getPersonId(); - accountId = account.getAccountId(); - accountNotAuditedOwnersId = accountNotAuditedOwners.getAccountId(); - proxyPersonId = proxyPerson.getPersonId(); - noProxyPersonId = noProxyPerson.getPersonId(); - } + personId = person.getPersonId(); + accountId = account.getAccountId(); + accountNotAuditedOwnersId = accountNotAuditedOwners.getAccountId(); + proxyPersonId = proxyPerson.getPersonId(); + noProxyPersonId = noProxyPerson.getPersonId(); + } - @Test - public void testRevisionsCounts() { - Assert.assertEquals(Arrays.asList(1), getAuditReader().getRevisions(Person.class, personId)); - Assert.assertEquals(Arrays.asList(1), getAuditReader().getRevisions(Account.class, accountId)); - Assert.assertEquals(Arrays.asList(2), getAuditReader().getRevisions(AccountNotAuditedOwners.class, accountNotAuditedOwnersId)); - } + @Test + public void testRevisionsCounts() { + Assert.assertEquals( Arrays.asList( 1 ), getAuditReader().getRevisions( Person.class, personId ) ); + Assert.assertEquals( Arrays.asList( 1 ), getAuditReader().getRevisions( Account.class, accountId ) ); + Assert.assertEquals( + Arrays.asList( 2 ), getAuditReader().getRevisions( + AccountNotAuditedOwners.class, + accountNotAuditedOwnersId + ) + ); + } - @Test - public void testHistoryOfPerson() { - Person personVer1 = new Person(personId, "Robert"); - Account accountVer1 = new Account(accountId, "Saving"); - personVer1.setAccount(accountVer1); - accountVer1.setOwner(personVer1); + @Test + public void testHistoryOfPerson() { + Person personVer1 = new Person( personId, "Robert" ); + Account accountVer1 = new Account( accountId, "Saving" ); + personVer1.setAccount( accountVer1 ); + accountVer1.setOwner( personVer1 ); - Object[] result = ((Object[]) getAuditReader().createQuery().forRevisionsOfEntity(Person.class, false, true) - .add(AuditEntity.id().eq(personId)) - .getResultList().get(0)); + Object[] result = ((Object[]) getAuditReader().createQuery().forRevisionsOfEntity( Person.class, false, true ) + .add( AuditEntity.id().eq( personId ) ) + .getResultList().get( 0 )); - Assert.assertEquals(personVer1, result[0]); - Assert.assertEquals(personVer1.getAccount(), ((Person)result[0]).getAccount()); - Assert.assertEquals(RevisionType.ADD, result[2]); + Assert.assertEquals( personVer1, result[0] ); + Assert.assertEquals( personVer1.getAccount(), ((Person) result[0]).getAccount() ); + Assert.assertEquals( RevisionType.ADD, result[2] ); - Assert.assertEquals(personVer1, getAuditReader().find(Person.class, personId, 1)); - } + Assert.assertEquals( personVer1, getAuditReader().find( Person.class, personId, 1 ) ); + } - @Test - public void testHistoryOfAccount() { - Person personVer1 = new Person(personId, "Robert"); - Account accountVer1 = new Account(accountId, "Saving"); - personVer1.setAccount(accountVer1); - accountVer1.setOwner(personVer1); + @Test + public void testHistoryOfAccount() { + Person personVer1 = new Person( personId, "Robert" ); + Account accountVer1 = new Account( accountId, "Saving" ); + personVer1.setAccount( accountVer1 ); + accountVer1.setOwner( personVer1 ); - Object[] result = ((Object[]) getAuditReader().createQuery().forRevisionsOfEntity(Account.class, false, true) - .add(AuditEntity.id().eq(accountId)) - .getResultList().get(0)); + Object[] result = ((Object[]) getAuditReader().createQuery().forRevisionsOfEntity( Account.class, false, true ) + .add( AuditEntity.id().eq( accountId ) ) + .getResultList().get( 0 )); - Assert.assertEquals(accountVer1, result[0]); - Assert.assertEquals(accountVer1.getOwner(), ((Account)result[0]).getOwner()); - Assert.assertEquals(RevisionType.ADD, result[2]); + Assert.assertEquals( accountVer1, result[0] ); + Assert.assertEquals( accountVer1.getOwner(), ((Account) result[0]).getOwner() ); + Assert.assertEquals( RevisionType.ADD, result[2] ); - Assert.assertEquals(accountVer1, getAuditReader().find(Account.class, accountId, 1)); - } + Assert.assertEquals( accountVer1, getAuditReader().find( Account.class, accountId, 1 ) ); + } - @Test - public void testHistoryOfAccountNotAuditedOwners() { - NotAuditedNoProxyPerson noProxyPersonVer1 = new NotAuditedNoProxyPerson(noProxyPersonId, "Kinga"); - NotAuditedProxyPerson proxyPersonVer1 = new NotAuditedProxyPerson(proxyPersonId, "Lukasz"); - AccountNotAuditedOwners accountNotAuditedOwnersVer1 = new AccountNotAuditedOwners(accountNotAuditedOwnersId, "Standard"); - noProxyPersonVer1.setAccount(accountNotAuditedOwnersVer1); - proxyPersonVer1.setAccount(accountNotAuditedOwnersVer1); - accountNotAuditedOwnersVer1.setOwner(noProxyPersonVer1); - accountNotAuditedOwnersVer1.setCoOwner(proxyPersonVer1); + @Test + public void testHistoryOfAccountNotAuditedOwners() { + NotAuditedNoProxyPerson noProxyPersonVer1 = new NotAuditedNoProxyPerson( noProxyPersonId, "Kinga" ); + NotAuditedProxyPerson proxyPersonVer1 = new NotAuditedProxyPerson( proxyPersonId, "Lukasz" ); + AccountNotAuditedOwners accountNotAuditedOwnersVer1 = new AccountNotAuditedOwners( + accountNotAuditedOwnersId, + "Standard" + ); + noProxyPersonVer1.setAccount( accountNotAuditedOwnersVer1 ); + proxyPersonVer1.setAccount( accountNotAuditedOwnersVer1 ); + accountNotAuditedOwnersVer1.setOwner( noProxyPersonVer1 ); + accountNotAuditedOwnersVer1.setCoOwner( proxyPersonVer1 ); - Object[] result = ((Object[]) getAuditReader().createQuery().forRevisionsOfEntity(AccountNotAuditedOwners.class, false, true) - .add(AuditEntity.id().eq(accountNotAuditedOwnersId)) - .getResultList().get(0)); + Object[] result = ((Object[]) getAuditReader().createQuery() + .forRevisionsOfEntity( AccountNotAuditedOwners.class, false, true ) + .add( AuditEntity.id().eq( accountNotAuditedOwnersId ) ) + .getResultList() + .get( 0 )); - Assert.assertEquals(accountNotAuditedOwnersVer1, result[0]); - Assert.assertEquals(RevisionType.ADD, result[2]); - // Checking non-proxy reference - Assert.assertEquals(accountNotAuditedOwnersVer1.getOwner(), ((AccountNotAuditedOwners)result[0]).getOwner()); - // Checking proxy reference - Assert.assertTrue(((AccountNotAuditedOwners)result[0]).getCoOwner() instanceof HibernateProxy); - Assert.assertEquals(proxyPersonVer1.getPersonId(), ((AccountNotAuditedOwners)result[0]).getCoOwner().getPersonId()); + Assert.assertEquals( accountNotAuditedOwnersVer1, result[0] ); + Assert.assertEquals( RevisionType.ADD, result[2] ); + // Checking non-proxy reference + Assert.assertEquals( accountNotAuditedOwnersVer1.getOwner(), ((AccountNotAuditedOwners) result[0]).getOwner() ); + // Checking proxy reference + Assert.assertTrue( ((AccountNotAuditedOwners) result[0]).getCoOwner() instanceof HibernateProxy ); + Assert.assertEquals( + proxyPersonVer1.getPersonId(), + ((AccountNotAuditedOwners) result[0]).getCoOwner().getPersonId() + ); - Assert.assertEquals(accountNotAuditedOwnersVer1, getAuditReader().find(AccountNotAuditedOwners.class, accountNotAuditedOwnersId, 2)); - } + Assert.assertEquals( + accountNotAuditedOwnersVer1, getAuditReader().find( + AccountNotAuditedOwners.class, + accountNotAuditedOwnersId, + 2 + ) + ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/primarykeyjoincolumn/Person.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/primarykeyjoincolumn/Person.java index 963e62afe8..ca75a1dc81 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/primarykeyjoincolumn/Person.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/bidirectional/primarykeyjoincolumn/Person.java @@ -1,11 +1,11 @@ package org.hibernate.envers.test.integration.onetoone.bidirectional.primarykeyjoincolumn; -import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.OneToOne; +import java.io.Serializable; import org.hibernate.envers.Audited; @@ -15,74 +15,82 @@ import org.hibernate.envers.Audited; @Entity @Audited public class Person implements Serializable { - @Id - @Column(name = "PERSON_ID") - @GeneratedValue - private Long personId; + @Id + @Column(name = "PERSON_ID") + @GeneratedValue + private Long personId; - private String name; + private String name; - @OneToOne(mappedBy = "owner") - private Account account; + @OneToOne(mappedBy = "owner") + private Account account; - public Person() { - } + public Person() { + } - public Person(String name) { - this.name = name; - } + public Person(String name) { + this.name = name; + } - public Person(Long personId, String name) { - this.personId = personId; - this.name = name; - } + public Person(Long personId, String name) { + this.personId = personId; + this.name = name; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof Person)) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof Person) ) { + return false; + } - Person person = (Person) o; + Person person = (Person) o; - if (personId != null ? !personId.equals(person.personId) : person.personId != null) return false; - if (name != null ? !name.equals(person.name) : person.name != null) return false; + if ( personId != null ? !personId.equals( person.personId ) : person.personId != null ) { + return false; + } + if ( name != null ? !name.equals( person.name ) : person.name != null ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - int result = personId != null ? personId.hashCode() : 0; - result = 31 * result + (name != null ? name.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = personId != null ? personId.hashCode() : 0; + result = 31 * result + (name != null ? name.hashCode() : 0); + return result; + } - @Override - public String toString() { - return "Person(personId = " + personId + ", name = " + name + ")"; - } + @Override + public String toString() { + return "Person(personId = " + personId + ", name = " + name + ")"; + } - public Long getPersonId() { - return personId; - } + public Long getPersonId() { + return personId; + } - public void setPersonId(Long personId) { - this.personId = personId; - } + public void setPersonId(Long personId) { + this.personId = personId; + } - public String getName() { - return name; - } + public String getName() { + return name; + } - public void setName(String name) { - this.name = name; - } + public void setName(String name) { + this.name = name; + } - public Account getAccount() { - return account; - } + public Account getAccount() { + return account; + } - public void setAccount(Account account) { - this.account = account; - } + public void setAccount(Account account) { + this.account = account; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/unidirectional/UniRefEdEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/unidirectional/UniRefEdEntity.java index bf17d6cdd4..35bb8df464 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/unidirectional/UniRefEdEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/unidirectional/UniRefEdEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.onetoone.unidirectional; + import javax.persistence.Entity; import javax.persistence.Id; @@ -29,56 +30,65 @@ import org.hibernate.envers.Audited; /** * Unidirectional ReferencEd Entity + * * @author Adam Warski (adam at warski dot org) */ @Entity public class UniRefEdEntity { - @Id - private Integer id; + @Id + private Integer id; - @Audited - private String data; + @Audited + private String data; - public UniRefEdEntity() { - } + public UniRefEdEntity() { + } - public UniRefEdEntity(Integer id, String data) { - this.id = id; - this.data = data; - } + public UniRefEdEntity(Integer id, String data) { + this.id = id; + this.data = data; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof UniRefEdEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof UniRefEdEntity) ) { + return false; + } - UniRefEdEntity that = (UniRefEdEntity) o; + UniRefEdEntity that = (UniRefEdEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/unidirectional/UniRefIngEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/unidirectional/UniRefIngEntity.java index 0d1365a57c..ddd9186ca5 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/unidirectional/UniRefIngEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/unidirectional/UniRefIngEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.onetoone.unidirectional; + import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.OneToOne; @@ -30,69 +31,78 @@ import org.hibernate.envers.Audited; /** * Unidirectional ReferencIng Entity + * * @author Adam Warski (adam at warski dot org) */ @Entity public class UniRefIngEntity { - @Id - private Integer id; + @Id + private Integer id; - @Audited - private String data; + @Audited + private String data; - @Audited - @OneToOne - private UniRefEdEntity reference; + @Audited + @OneToOne + private UniRefEdEntity reference; - public UniRefIngEntity() { - } + public UniRefIngEntity() { + } - public UniRefIngEntity(Integer id, String data, UniRefEdEntity reference) { - this.id = id; - this.data = data; - this.reference = reference; - } + public UniRefIngEntity(Integer id, String data, UniRefEdEntity reference) { + this.id = id; + this.data = data; + this.reference = reference; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public UniRefEdEntity getReference() { - return reference; - } + public UniRefEdEntity getReference() { + return reference; + } - public void setReference(UniRefEdEntity reference) { - this.reference = reference; - } + public void setReference(UniRefEdEntity reference) { + this.reference = reference; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof UniRefIngEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof UniRefIngEntity) ) { + return false; + } - UniRefIngEntity that = (UniRefIngEntity) o; + UniRefIngEntity that = (UniRefIngEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/unidirectional/UniRefIngMulIdEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/unidirectional/UniRefIngMulIdEntity.java index 1040cf5b69..a6dd5e7d7c 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/unidirectional/UniRefIngMulIdEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/unidirectional/UniRefIngMulIdEntity.java @@ -12,71 +12,79 @@ import org.hibernate.envers.test.entities.ids.EmbIdTestEntity; */ @Entity public class UniRefIngMulIdEntity { - @Id - private Integer id; + @Id + private Integer id; - @Audited - private String data; + @Audited + private String data; - @Audited - @OneToOne - private EmbIdTestEntity reference; + @Audited + @OneToOne + private EmbIdTestEntity reference; - public UniRefIngMulIdEntity() { - } + public UniRefIngMulIdEntity() { + } - public UniRefIngMulIdEntity(Integer id, String data, EmbIdTestEntity reference) { - this.id = id; - this.data = data; - this.reference = reference; - } + public UniRefIngMulIdEntity(Integer id, String data, EmbIdTestEntity reference) { + this.id = id; + this.data = data; + this.reference = reference; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public EmbIdTestEntity getReference() { - return reference; - } + public EmbIdTestEntity getReference() { + return reference; + } - public void setReference(EmbIdTestEntity reference) { - this.reference = reference; - } + public void setReference(EmbIdTestEntity reference) { + this.reference = reference; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof UniRefIngMulIdEntity)) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof UniRefIngMulIdEntity) ) { + return false; + } - UniRefIngMulIdEntity that = (UniRefIngMulIdEntity) o; + UniRefIngMulIdEntity that = (UniRefIngMulIdEntity) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - int result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } - @Override - public String toString() { - return "UniRefIngMulIdEntity[id = " + id + ", data = " + data + "]"; - } + @Override + public String toString() { + return "UniRefIngMulIdEntity[id = " + id + ", data = " + data + "]"; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/unidirectional/Unidirectional.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/unidirectional/Unidirectional.java index a53fe71f42..464538edb3 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/unidirectional/Unidirectional.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/unidirectional/Unidirectional.java @@ -23,127 +23,127 @@ */ package org.hibernate.envers.test.integration.onetoone.unidirectional; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class Unidirectional extends BaseEnversJPAFunctionalTestCase { - private Integer ed1_id; - private Integer ed2_id; - private Integer ed3_id; - private Integer ed4_id; + private Integer ed1_id; + private Integer ed2_id; + private Integer ed3_id; + private Integer ed4_id; - private Integer ing1_id; - private Integer ing2_id; + private Integer ing1_id; + private Integer ing2_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { UniRefEdEntity.class, UniRefIngEntity.class }; - } + return new Class[] {UniRefEdEntity.class, UniRefIngEntity.class}; + } - @Test - @Priority(10) - public void initData() { - UniRefEdEntity ed1 = new UniRefEdEntity(1, "data_ed_1"); - UniRefEdEntity ed2 = new UniRefEdEntity(2, "data_ed_2"); - UniRefEdEntity ed3 = new UniRefEdEntity(3, "data_ed_2"); - UniRefEdEntity ed4 = new UniRefEdEntity(4, "data_ed_2"); + @Test + @Priority(10) + public void initData() { + UniRefEdEntity ed1 = new UniRefEdEntity( 1, "data_ed_1" ); + UniRefEdEntity ed2 = new UniRefEdEntity( 2, "data_ed_2" ); + UniRefEdEntity ed3 = new UniRefEdEntity( 3, "data_ed_2" ); + UniRefEdEntity ed4 = new UniRefEdEntity( 4, "data_ed_2" ); - UniRefIngEntity ing1 = new UniRefIngEntity(5, "data_ing_1", ed1); - UniRefIngEntity ing2 = new UniRefIngEntity(6, "data_ing_2", ed3); + UniRefIngEntity ing1 = new UniRefIngEntity( 5, "data_ing_1", ed1 ); + UniRefIngEntity ing2 = new UniRefIngEntity( 6, "data_ing_2", ed3 ); - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); - em.persist(ed1); - em.persist(ed2); - em.persist(ed3); - em.persist(ed4); + em.persist( ed1 ); + em.persist( ed2 ); + em.persist( ed3 ); + em.persist( ed4 ); - em.persist(ing1); - em.persist(ing2); + em.persist( ing1 ); + em.persist( ing2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 + // Revision 2 - em = getEntityManager(); - em.getTransaction().begin(); + em = getEntityManager(); + em.getTransaction().begin(); - ing1 = em.find(UniRefIngEntity.class, ing1.getId()); - ed2 = em.find(UniRefEdEntity.class, ed2.getId()); + ing1 = em.find( UniRefIngEntity.class, ing1.getId() ); + ed2 = em.find( UniRefEdEntity.class, ed2.getId() ); - ing1.setReference(ed2); + ing1.setReference( ed2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 + // Revision 3 - em = getEntityManager(); - em.getTransaction().begin(); + em = getEntityManager(); + em.getTransaction().begin(); - ing2 = em.find(UniRefIngEntity.class, ing2.getId()); - ed3 = em.find(UniRefEdEntity.class, ed3.getId()); + ing2 = em.find( UniRefIngEntity.class, ing2.getId() ); + ed3 = em.find( UniRefEdEntity.class, ed3.getId() ); - ing2.setReference(ed4); + ing2.setReference( ed4 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // + // - ed1_id = ed1.getId(); - ed2_id = ed2.getId(); - ed3_id = ed3.getId(); - ed4_id = ed4.getId(); + ed1_id = ed1.getId(); + ed2_id = ed2.getId(); + ed3_id = ed3.getId(); + ed4_id = ed4.getId(); - ing1_id = ing1.getId(); - ing2_id = ing2.getId(); - } + ing1_id = ing1.getId(); + ing2_id = ing2.getId(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1).equals(getAuditReader().getRevisions(UniRefEdEntity.class, ed1_id)); - assert Arrays.asList(1).equals(getAuditReader().getRevisions(UniRefEdEntity.class, ed2_id)); - assert Arrays.asList(1).equals(getAuditReader().getRevisions(UniRefEdEntity.class, ed3_id)); - assert Arrays.asList(1).equals(getAuditReader().getRevisions(UniRefEdEntity.class, ed4_id)); + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1 ).equals( getAuditReader().getRevisions( UniRefEdEntity.class, ed1_id ) ); + assert Arrays.asList( 1 ).equals( getAuditReader().getRevisions( UniRefEdEntity.class, ed2_id ) ); + assert Arrays.asList( 1 ).equals( getAuditReader().getRevisions( UniRefEdEntity.class, ed3_id ) ); + assert Arrays.asList( 1 ).equals( getAuditReader().getRevisions( UniRefEdEntity.class, ed4_id ) ); - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(UniRefIngEntity.class, ing1_id)); - assert Arrays.asList(1, 3).equals(getAuditReader().getRevisions(UniRefIngEntity.class, ing2_id)); - } + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( UniRefIngEntity.class, ing1_id ) ); + assert Arrays.asList( 1, 3 ).equals( getAuditReader().getRevisions( UniRefIngEntity.class, ing2_id ) ); + } - @Test - public void testHistoryOfIngId1() { - UniRefEdEntity ed1 = getEntityManager().find(UniRefEdEntity.class, ed1_id); - UniRefEdEntity ed2 = getEntityManager().find(UniRefEdEntity.class, ed2_id); + @Test + public void testHistoryOfIngId1() { + UniRefEdEntity ed1 = getEntityManager().find( UniRefEdEntity.class, ed1_id ); + UniRefEdEntity ed2 = getEntityManager().find( UniRefEdEntity.class, ed2_id ); - UniRefIngEntity rev1 = getAuditReader().find(UniRefIngEntity.class, ing1_id, 1); - UniRefIngEntity rev2 = getAuditReader().find(UniRefIngEntity.class, ing1_id, 2); - UniRefIngEntity rev3 = getAuditReader().find(UniRefIngEntity.class, ing1_id, 3); + UniRefIngEntity rev1 = getAuditReader().find( UniRefIngEntity.class, ing1_id, 1 ); + UniRefIngEntity rev2 = getAuditReader().find( UniRefIngEntity.class, ing1_id, 2 ); + UniRefIngEntity rev3 = getAuditReader().find( UniRefIngEntity.class, ing1_id, 3 ); - assert rev1.getReference().equals(ed1); - assert rev2.getReference().equals(ed2); - assert rev3.getReference().equals(ed2); - } + assert rev1.getReference().equals( ed1 ); + assert rev2.getReference().equals( ed2 ); + assert rev3.getReference().equals( ed2 ); + } - @Test - public void testHistoryOfIngId2() { - UniRefEdEntity ed3 = getEntityManager().find(UniRefEdEntity.class, ed3_id); - UniRefEdEntity ed4 = getEntityManager().find(UniRefEdEntity.class, ed4_id); + @Test + public void testHistoryOfIngId2() { + UniRefEdEntity ed3 = getEntityManager().find( UniRefEdEntity.class, ed3_id ); + UniRefEdEntity ed4 = getEntityManager().find( UniRefEdEntity.class, ed4_id ); - UniRefIngEntity rev1 = getAuditReader().find(UniRefIngEntity.class, ing2_id, 1); - UniRefIngEntity rev2 = getAuditReader().find(UniRefIngEntity.class, ing2_id, 2); - UniRefIngEntity rev3 = getAuditReader().find(UniRefIngEntity.class, ing2_id, 3); + UniRefIngEntity rev1 = getAuditReader().find( UniRefIngEntity.class, ing2_id, 1 ); + UniRefIngEntity rev2 = getAuditReader().find( UniRefIngEntity.class, ing2_id, 2 ); + UniRefIngEntity rev3 = getAuditReader().find( UniRefIngEntity.class, ing2_id, 3 ); - assert rev1.getReference().equals(ed3); - assert rev2.getReference().equals(ed3); - assert rev3.getReference().equals(ed4); - } + assert rev1.getReference().equals( ed3 ); + assert rev2.getReference().equals( ed3 ); + assert rev3.getReference().equals( ed4 ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/unidirectional/UnidirectionalMulIdWithNulls.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/unidirectional/UnidirectionalMulIdWithNulls.java index df5be2c0e2..8d6bb63ca8 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/unidirectional/UnidirectionalMulIdWithNulls.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/unidirectional/UnidirectionalMulIdWithNulls.java @@ -2,13 +2,13 @@ package org.hibernate.envers.test.integration.onetoone.unidirectional; import javax.persistence.EntityManager; -import org.junit.Test; - import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.ids.EmbId; import org.hibernate.envers.test.entities.ids.EmbIdTestEntity; +import org.junit.Test; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; @@ -17,43 +17,43 @@ import static org.junit.Assert.assertNull; * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public class UnidirectionalMulIdWithNulls extends BaseEnversJPAFunctionalTestCase { - private EmbId ei; + private EmbId ei; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { EmbIdTestEntity.class, UniRefIngMulIdEntity.class }; - } + return new Class[] {EmbIdTestEntity.class, UniRefIngMulIdEntity.class}; + } - @Test - @Priority(10) - public void initData() { - ei = new EmbId(1, 2); + @Test + @Priority(10) + public void initData() { + ei = new EmbId( 1, 2 ); - EntityManager em = getEntityManager(); - - // Revision 1 - EmbIdTestEntity eite = new EmbIdTestEntity(ei, "data"); - UniRefIngMulIdEntity notNullRef = new UniRefIngMulIdEntity(1, "data 1", eite); - UniRefIngMulIdEntity nullRef = new UniRefIngMulIdEntity(2, "data 2", null); + EntityManager em = getEntityManager(); - em.getTransaction().begin(); - em.persist(eite); - em.persist(notNullRef); - em.persist(nullRef); - em.getTransaction().commit(); - } + // Revision 1 + EmbIdTestEntity eite = new EmbIdTestEntity( ei, "data" ); + UniRefIngMulIdEntity notNullRef = new UniRefIngMulIdEntity( 1, "data 1", eite ); + UniRefIngMulIdEntity nullRef = new UniRefIngMulIdEntity( 2, "data 2", null ); - @Test - public void testNullReference() { - UniRefIngMulIdEntity nullRef = getAuditReader().find(UniRefIngMulIdEntity.class, 2, 1); - assertNull(nullRef.getReference()); - } + em.getTransaction().begin(); + em.persist( eite ); + em.persist( notNullRef ); + em.persist( nullRef ); + em.getTransaction().commit(); + } - @Test - public void testNotNullReference() { - EmbIdTestEntity eite = getAuditReader().find(EmbIdTestEntity.class, ei, 1); - UniRefIngMulIdEntity notNullRef = getAuditReader().find(UniRefIngMulIdEntity.class, 1, 1); - assertNotNull(notNullRef.getReference()); - assertEquals(notNullRef.getReference(), eite); - } + @Test + public void testNullReference() { + UniRefIngMulIdEntity nullRef = getAuditReader().find( UniRefIngMulIdEntity.class, 2, 1 ); + assertNull( nullRef.getReference() ); + } + + @Test + public void testNotNullReference() { + EmbIdTestEntity eite = getAuditReader().find( EmbIdTestEntity.class, ei, 1 ); + UniRefIngMulIdEntity notNullRef = getAuditReader().find( UniRefIngMulIdEntity.class, 1, 1 ); + assertNotNull( notNullRef.getReference() ); + assertEquals( notNullRef.getReference(), eite ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/unidirectional/UnidirectionalWithNulls.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/unidirectional/UnidirectionalWithNulls.java index 9b4135359e..86844395bf 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/unidirectional/UnidirectionalWithNulls.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/onetoone/unidirectional/UnidirectionalWithNulls.java @@ -23,114 +23,114 @@ */ package org.hibernate.envers.test.integration.onetoone.unidirectional; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class UnidirectionalWithNulls extends BaseEnversJPAFunctionalTestCase { - private Integer ed1_id; - private Integer ed2_id; + private Integer ed1_id; + private Integer ed2_id; - private Integer ing1_id; - private Integer ing2_id; + private Integer ing1_id; + private Integer ing2_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { UniRefEdEntity.class, UniRefIngEntity.class }; - } + return new Class[] {UniRefEdEntity.class, UniRefIngEntity.class}; + } - @Test - @Priority(10) - public void initData() { - UniRefEdEntity ed1 = new UniRefEdEntity(1, "data_ed_1"); - UniRefEdEntity ed2 = new UniRefEdEntity(2, "data_ed_2"); + @Test + @Priority(10) + public void initData() { + UniRefEdEntity ed1 = new UniRefEdEntity( 1, "data_ed_1" ); + UniRefEdEntity ed2 = new UniRefEdEntity( 2, "data_ed_2" ); - UniRefIngEntity ing1 = new UniRefIngEntity(3, "data_ing_1", ed1); - UniRefIngEntity ing2 = new UniRefIngEntity(4, "data_ing_2", null); + UniRefIngEntity ing1 = new UniRefIngEntity( 3, "data_ing_1", ed1 ); + UniRefIngEntity ing2 = new UniRefIngEntity( 4, "data_ing_2", null ); - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); - em.persist(ed1); - em.persist(ed2); + em.persist( ed1 ); + em.persist( ed2 ); - em.persist(ing1); - em.persist(ing2); + em.persist( ing1 ); + em.persist( ing2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 + // Revision 2 - em = getEntityManager(); - em.getTransaction().begin(); + em = getEntityManager(); + em.getTransaction().begin(); - ing1 = em.find(UniRefIngEntity.class, ing1.getId()); + ing1 = em.find( UniRefIngEntity.class, ing1.getId() ); - ing1.setReference(null); + ing1.setReference( null ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 + // Revision 3 - em = getEntityManager(); - em.getTransaction().begin(); + em = getEntityManager(); + em.getTransaction().begin(); - ing2 = em.find(UniRefIngEntity.class, ing2.getId()); - ed2 = em.find(UniRefEdEntity.class, ed2.getId()); + ing2 = em.find( UniRefIngEntity.class, ing2.getId() ); + ed2 = em.find( UniRefEdEntity.class, ed2.getId() ); - ing2.setReference(ed2); + ing2.setReference( ed2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // + // - ed1_id = ed1.getId(); - ed2_id = ed2.getId(); + ed1_id = ed1.getId(); + ed2_id = ed2.getId(); - ing1_id = ing1.getId(); - ing2_id = ing2.getId(); - } + ing1_id = ing1.getId(); + ing2_id = ing2.getId(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1).equals(getAuditReader().getRevisions(UniRefEdEntity.class, ed1_id)); - assert Arrays.asList(1).equals(getAuditReader().getRevisions(UniRefEdEntity.class, ed2_id)); + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1 ).equals( getAuditReader().getRevisions( UniRefEdEntity.class, ed1_id ) ); + assert Arrays.asList( 1 ).equals( getAuditReader().getRevisions( UniRefEdEntity.class, ed2_id ) ); - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(UniRefIngEntity.class, ing1_id)); - assert Arrays.asList(1, 3).equals(getAuditReader().getRevisions(UniRefIngEntity.class, ing2_id)); - } + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( UniRefIngEntity.class, ing1_id ) ); + assert Arrays.asList( 1, 3 ).equals( getAuditReader().getRevisions( UniRefIngEntity.class, ing2_id ) ); + } - @Test - public void testHistoryOfIngId1() { - UniRefEdEntity ed1 = getEntityManager().find(UniRefEdEntity.class, ed1_id); + @Test + public void testHistoryOfIngId1() { + UniRefEdEntity ed1 = getEntityManager().find( UniRefEdEntity.class, ed1_id ); - UniRefIngEntity rev1 = getAuditReader().find(UniRefIngEntity.class, ing1_id, 1); - UniRefIngEntity rev2 = getAuditReader().find(UniRefIngEntity.class, ing1_id, 2); - UniRefIngEntity rev3 = getAuditReader().find(UniRefIngEntity.class, ing1_id, 3); + UniRefIngEntity rev1 = getAuditReader().find( UniRefIngEntity.class, ing1_id, 1 ); + UniRefIngEntity rev2 = getAuditReader().find( UniRefIngEntity.class, ing1_id, 2 ); + UniRefIngEntity rev3 = getAuditReader().find( UniRefIngEntity.class, ing1_id, 3 ); - assert rev1.getReference().equals(ed1); - assert rev2.getReference() == null; - assert rev3.getReference() == null; - } + assert rev1.getReference().equals( ed1 ); + assert rev2.getReference() == null; + assert rev3.getReference() == null; + } - @Test - public void testHistoryOfIngId2() { - UniRefEdEntity ed2 = getEntityManager().find(UniRefEdEntity.class, ed2_id); + @Test + public void testHistoryOfIngId2() { + UniRefEdEntity ed2 = getEntityManager().find( UniRefEdEntity.class, ed2_id ); - UniRefIngEntity rev1 = getAuditReader().find(UniRefIngEntity.class, ing2_id, 1); - UniRefIngEntity rev2 = getAuditReader().find(UniRefIngEntity.class, ing2_id, 2); - UniRefIngEntity rev3 = getAuditReader().find(UniRefIngEntity.class, ing2_id, 3); + UniRefIngEntity rev1 = getAuditReader().find( UniRefIngEntity.class, ing2_id, 1 ); + UniRefIngEntity rev2 = getAuditReader().find( UniRefIngEntity.class, ing2_id, 2 ); + UniRefIngEntity rev3 = getAuditReader().find( UniRefIngEntity.class, ing2_id, 3 ); - assert rev1.getReference() == null; - assert rev2.getReference() == null; - assert rev3.getReference().equals(ed2); - } + assert rev1.getReference() == null; + assert rev2.getReference() == null; + assert rev3.getReference().equals( ed2 ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/primitive/PrimitiveAddDelete.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/primitive/PrimitiveAddDelete.java index 13c051cf3c..6d79e1bbff 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/primitive/PrimitiveAddDelete.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/primitive/PrimitiveAddDelete.java @@ -23,77 +23,77 @@ */ package org.hibernate.envers.test.integration.primitive; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.List; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.PrimitiveTestEntity; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class PrimitiveAddDelete extends BaseEnversJPAFunctionalTestCase { - private Integer id1; + private Integer id1; - @Override - protected Class[] getAnnotatedClasses() { - return new Class[]{PrimitiveTestEntity.class}; - } + @Override + protected Class[] getAnnotatedClasses() { + return new Class[] {PrimitiveTestEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); // Revision 1 - em.getTransaction().begin(); - PrimitiveTestEntity pte = new PrimitiveTestEntity(10, 11); - em.persist(pte); - id1 = pte.getId(); - em.getTransaction().commit(); + em.getTransaction().begin(); + PrimitiveTestEntity pte = new PrimitiveTestEntity( 10, 11 ); + em.persist( pte ); + id1 = pte.getId(); + em.getTransaction().commit(); // Revision 2 - em.getTransaction().begin(); - pte = em.find(PrimitiveTestEntity.class, id1); - pte.setNumVal1(20); - pte.setNumVal2(21); - em.getTransaction().commit(); + em.getTransaction().begin(); + pte = em.find( PrimitiveTestEntity.class, id1 ); + pte.setNumVal1( 20 ); + pte.setNumVal2( 21 ); + em.getTransaction().commit(); // Revision 3 - em.getTransaction().begin(); - pte = em.find(PrimitiveTestEntity.class, id1); - em.remove(pte); - em.getTransaction().commit(); - } + em.getTransaction().begin(); + pte = em.find( PrimitiveTestEntity.class, id1 ); + em.remove( pte ); + em.getTransaction().commit(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2, 3).equals(getAuditReader().getRevisions(PrimitiveTestEntity.class, id1)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2, 3 ).equals( getAuditReader().getRevisions( PrimitiveTestEntity.class, id1 ) ); + } - @Test - public void testHistoryOfId1() { - PrimitiveTestEntity ver1 = new PrimitiveTestEntity(id1, 10, 0); - PrimitiveTestEntity ver2 = new PrimitiveTestEntity(id1, 20, 0); + @Test + public void testHistoryOfId1() { + PrimitiveTestEntity ver1 = new PrimitiveTestEntity( id1, 10, 0 ); + PrimitiveTestEntity ver2 = new PrimitiveTestEntity( id1, 20, 0 ); - assert getAuditReader().find(PrimitiveTestEntity.class, id1, 1).equals(ver1); - assert getAuditReader().find(PrimitiveTestEntity.class, id1, 2).equals(ver2); - assert getAuditReader().find(PrimitiveTestEntity.class, id1, 3) == null; - } + assert getAuditReader().find( PrimitiveTestEntity.class, id1, 1 ).equals( ver1 ); + assert getAuditReader().find( PrimitiveTestEntity.class, id1, 2 ).equals( ver2 ); + assert getAuditReader().find( PrimitiveTestEntity.class, id1, 3 ) == null; + } @Test public void testQueryWithDeleted() { // Selecting all entities, also the deleted ones - List entities = getAuditReader().createQuery().forRevisionsOfEntity(PrimitiveTestEntity.class, true, true) + List entities = getAuditReader().createQuery().forRevisionsOfEntity( PrimitiveTestEntity.class, true, true ) .getResultList(); assert entities.size() == 3; - assert entities.get(0).equals(new PrimitiveTestEntity(id1, 10, 0)); - assert entities.get(1).equals(new PrimitiveTestEntity(id1, 20, 0)); - assert entities.get(2).equals(new PrimitiveTestEntity(id1, 0, 0)); + assert entities.get( 0 ).equals( new PrimitiveTestEntity( id1, 10, 0 ) ); + assert entities.get( 1 ).equals( new PrimitiveTestEntity( id1, 20, 0 ) ); + assert entities.get( 2 ).equals( new PrimitiveTestEntity( id1, 0, 0 ) ); } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/properties/PropertiesTestEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/properties/PropertiesTestEntity.java index 6b0849e11f..b35991b088 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/properties/PropertiesTestEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/properties/PropertiesTestEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.properties; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; @@ -33,57 +34,65 @@ import org.hibernate.envers.Audited; */ @Entity public class PropertiesTestEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - @Audited - private String str; + @Audited + private String str; - public PropertiesTestEntity() { - } + public PropertiesTestEntity() { + } - public PropertiesTestEntity(String str) { - this.str = str; - } + public PropertiesTestEntity(String str) { + this.str = str; + } - public PropertiesTestEntity(Integer id, String str) { - this.id = id; - this.str = str; - } + public PropertiesTestEntity(Integer id, String str) { + this.id = id; + this.str = str; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getStr() { - return str; -} + public String getStr() { + return str; + } - public void setStr(String str) { - this.str = str; - } + public void setStr(String str) { + this.str = str; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof PropertiesTestEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof PropertiesTestEntity) ) { + return false; + } - PropertiesTestEntity that = (PropertiesTestEntity) o; + PropertiesTestEntity that = (PropertiesTestEntity) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; - if (str != null ? !str.equals(that.str) : that.str != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } + if ( str != null ? !str.equals( that.str ) : that.str != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (str != null ? str.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (str != null ? str.hashCode() : 0); + return result; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/properties/UnversionedOptimisticLockingField.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/properties/UnversionedOptimisticLockingField.java index eef446a43d..655d1f2dc0 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/properties/UnversionedOptimisticLockingField.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/properties/UnversionedOptimisticLockingField.java @@ -23,12 +23,10 @@ */ package org.hibernate.envers.test.integration.properties; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.Iterator; import java.util.Map; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.configuration.EnversSettings; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; @@ -36,6 +34,8 @@ import org.hibernate.envers.test.Priority; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.Property; +import org.junit.Test; + /** * @author Nicolas Doroskevich */ @@ -44,56 +44,59 @@ public class UnversionedOptimisticLockingField extends BaseEnversJPAFunctionalTe @Override protected Class[] getAnnotatedClasses() { - return new Class[] { UnversionedOptimisticLockingFieldEntity.class }; + return new Class[] {UnversionedOptimisticLockingFieldEntity.class}; } @Override public void addConfigOptions(Map configuration) { super.addConfigOptions( configuration ); - configuration.put(EnversSettings.DO_NOT_AUDIT_OPTIMISTIC_LOCKING_FIELD, "true"); + configuration.put( EnversSettings.DO_NOT_AUDIT_OPTIMISTIC_LOCKING_FIELD, "true" ); } @Test - @Priority(10) + @Priority(10) public void initData() { EntityManager em = getEntityManager(); em.getTransaction().begin(); - UnversionedOptimisticLockingFieldEntity olfe = new UnversionedOptimisticLockingFieldEntity("x"); - em.persist(olfe); + UnversionedOptimisticLockingFieldEntity olfe = new UnversionedOptimisticLockingFieldEntity( "x" ); + em.persist( olfe ); id1 = olfe.getId(); em.getTransaction().commit(); em.getTransaction().begin(); - olfe = em.find(UnversionedOptimisticLockingFieldEntity.class, id1); - olfe.setStr("y"); + olfe = em.find( UnversionedOptimisticLockingFieldEntity.class, id1 ); + olfe.setStr( "y" ); em.getTransaction().commit(); } @Test public void testRevisionCounts() { - assert Arrays.asList(1, 2).equals( - getAuditReader().getRevisions(UnversionedOptimisticLockingFieldEntity.class, - id1)); + assert Arrays.asList( 1, 2 ).equals( + getAuditReader().getRevisions( + UnversionedOptimisticLockingFieldEntity.class, + id1 + ) + ); } @Test public void testHistoryOfId1() { - UnversionedOptimisticLockingFieldEntity ver1 = new UnversionedOptimisticLockingFieldEntity(id1, "x"); - UnversionedOptimisticLockingFieldEntity ver2 = new UnversionedOptimisticLockingFieldEntity(id1, "y"); - - assert getAuditReader().find(UnversionedOptimisticLockingFieldEntity.class, id1, 1) - .equals(ver1); - assert getAuditReader().find(UnversionedOptimisticLockingFieldEntity.class, id1, 2) - .equals(ver2); + UnversionedOptimisticLockingFieldEntity ver1 = new UnversionedOptimisticLockingFieldEntity( id1, "x" ); + UnversionedOptimisticLockingFieldEntity ver2 = new UnversionedOptimisticLockingFieldEntity( id1, "y" ); + + assert getAuditReader().find( UnversionedOptimisticLockingFieldEntity.class, id1, 1 ) + .equals( ver1 ); + assert getAuditReader().find( UnversionedOptimisticLockingFieldEntity.class, id1, 2 ) + .equals( ver2 ); } - + @Test public void testMapping() { - PersistentClass pc = getCfg().getClassMapping(UnversionedOptimisticLockingFieldEntity.class.getName() + "_AUD"); + PersistentClass pc = getCfg().getClassMapping( UnversionedOptimisticLockingFieldEntity.class.getName() + "_AUD" ); Iterator pi = pc.getPropertyIterator(); - while(pi.hasNext()) { + while ( pi.hasNext() ) { Property p = (Property) pi.next(); - assert !"optLocking".equals(p.getName()); + assert !"optLocking".equals( p.getName() ); } } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/properties/UnversionedOptimisticLockingFieldEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/properties/UnversionedOptimisticLockingFieldEntity.java index 2835bbe160..28a95924f0 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/properties/UnversionedOptimisticLockingFieldEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/properties/UnversionedOptimisticLockingFieldEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.properties; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; @@ -37,29 +38,29 @@ import org.hibernate.envers.Audited; @Table(name = "UnverOptimLockField") @Entity public class UnversionedOptimisticLockingFieldEntity { - - @Id - @GeneratedValue - private Integer id; - - private String str; - - @Version - private int optLocking; - - public UnversionedOptimisticLockingFieldEntity() { - } - - public UnversionedOptimisticLockingFieldEntity(String str) { - this.str = str; - } - - public UnversionedOptimisticLockingFieldEntity(Integer id, String str) { - this.id = id; - this.str = str; - } - - public Integer getId() { + + @Id + @GeneratedValue + private Integer id; + + private String str; + + @Version + private int optLocking; + + public UnversionedOptimisticLockingFieldEntity() { + } + + public UnversionedOptimisticLockingFieldEntity(String str) { + this.str = str; + } + + public UnversionedOptimisticLockingFieldEntity(Integer id, String str) { + this.id = id; + this.str = str; + } + + public Integer getId() { return id; } @@ -74,7 +75,7 @@ public class UnversionedOptimisticLockingFieldEntity { public void setStr(String str) { this.str = str; } - + public int getOptLocking() { return optLocking; } @@ -82,24 +83,32 @@ public class UnversionedOptimisticLockingFieldEntity { public void setOptLocking(int optLocking) { this.optLocking = optLocking; } - + public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof UnversionedOptimisticLockingFieldEntity)) return false; + if ( this == o ) { + return true; + } + if ( !(o instanceof UnversionedOptimisticLockingFieldEntity) ) { + return false; + } - UnversionedOptimisticLockingFieldEntity that = (UnversionedOptimisticLockingFieldEntity) o; + UnversionedOptimisticLockingFieldEntity that = (UnversionedOptimisticLockingFieldEntity) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; - if (str != null ? !str.equals(that.str) : that.str != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } + if ( str != null ? !str.equals( that.str ) : that.str != null ) { + return false; + } - return true; - } + return true; + } + + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (str != null ? str.hashCode() : 0); + return result; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (str != null ? str.hashCode() : 0); - return result; - } - } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/properties/VersionsProperties.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/properties/VersionsProperties.java index 92c51d991a..6d98af0ec7 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/properties/VersionsProperties.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/properties/VersionsProperties.java @@ -23,63 +23,63 @@ */ package org.hibernate.envers.test.integration.properties; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.Map; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.configuration.EnversSettings; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class VersionsProperties extends BaseEnversJPAFunctionalTestCase { - private Integer id1; + private Integer id1; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { PropertiesTestEntity.class }; + return new Class[] {PropertiesTestEntity.class}; } @Override protected void addConfigOptions(Map options) { super.addConfigOptions( options ); - options.put(EnversSettings.AUDIT_TABLE_PREFIX, "VP_"); - options.put(EnversSettings.AUDIT_TABLE_SUFFIX, "_VS"); - options.put(EnversSettings.REVISION_FIELD_NAME, "ver_rev"); - options.put(EnversSettings.REVISION_TYPE_FIELD_NAME, "ver_rev_type"); + options.put( EnversSettings.AUDIT_TABLE_PREFIX, "VP_" ); + options.put( EnversSettings.AUDIT_TABLE_SUFFIX, "_VS" ); + options.put( EnversSettings.REVISION_FIELD_NAME, "ver_rev" ); + options.put( EnversSettings.REVISION_TYPE_FIELD_NAME, "ver_rev_type" ); } @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); - em.getTransaction().begin(); - PropertiesTestEntity pte = new PropertiesTestEntity("x"); - em.persist(pte); - id1 = pte.getId(); - em.getTransaction().commit(); + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); + em.getTransaction().begin(); + PropertiesTestEntity pte = new PropertiesTestEntity( "x" ); + em.persist( pte ); + id1 = pte.getId(); + em.getTransaction().commit(); - em.getTransaction().begin(); - pte = em.find(PropertiesTestEntity.class, id1); - pte.setStr("y"); - em.getTransaction().commit(); - } + em.getTransaction().begin(); + pte = em.find( PropertiesTestEntity.class, id1 ); + pte.setStr( "y" ); + em.getTransaction().commit(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(PropertiesTestEntity.class, id1)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( PropertiesTestEntity.class, id1 ) ); + } - @Test - public void testHistoryOfId1() { - PropertiesTestEntity ver1 = new PropertiesTestEntity(id1, "x"); - PropertiesTestEntity ver2 = new PropertiesTestEntity(id1, "y"); + @Test + public void testHistoryOfId1() { + PropertiesTestEntity ver1 = new PropertiesTestEntity( id1, "x" ); + PropertiesTestEntity ver2 = new PropertiesTestEntity( id1, "y" ); - assert getAuditReader().find(PropertiesTestEntity.class, id1, 1).equals(ver1); - assert getAuditReader().find(PropertiesTestEntity.class, id1, 2).equals(ver2); - } + assert getAuditReader().find( PropertiesTestEntity.class, id1, 1 ).equals( ver1 ); + assert getAuditReader().find( PropertiesTestEntity.class, id1, 2 ).equals( ver2 ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/proxy/AuditedCollectionProxyTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/proxy/AuditedCollectionProxyTest.java index 12149056ec..c29f86cf80 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/proxy/AuditedCollectionProxyTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/proxy/AuditedCollectionProxyTest.java @@ -25,76 +25,80 @@ package org.hibernate.envers.test.integration.proxy; import javax.persistence.EntityManager; -import org.junit.Test; - import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.onetomany.ListRefEdEntity; import org.hibernate.envers.test.entities.onetomany.ListRefIngEntity; import org.hibernate.proxy.HibernateProxy; +import org.junit.Test; + /** * Test case for HHH-5750: Proxied objects lose the temporary session used to * initialize them. - * + * * @author Erik-Berndt Scheper - * */ public class AuditedCollectionProxyTest extends BaseEnversJPAFunctionalTestCase { - Integer id_ListRefEdEntity1; + Integer id_ListRefEdEntity1; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { ListRefEdEntity.class, ListRefIngEntity.class }; - } + return new Class[] {ListRefEdEntity.class, ListRefIngEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - ListRefEdEntity listReferencedEntity1 = new ListRefEdEntity( - Integer.valueOf(1), "str1"); - ListRefIngEntity refingEntity1 = new ListRefIngEntity( - Integer.valueOf(1), "refing1", listReferencedEntity1); + ListRefEdEntity listReferencedEntity1 = new ListRefEdEntity( + Integer.valueOf( 1 ), "str1" + ); + ListRefIngEntity refingEntity1 = new ListRefIngEntity( + Integer.valueOf( 1 ), "refing1", listReferencedEntity1 + ); - // Revision 1 - em.getTransaction().begin(); - em.persist(listReferencedEntity1); - em.persist(refingEntity1); - em.getTransaction().commit(); + // Revision 1 + em.getTransaction().begin(); + em.persist( listReferencedEntity1 ); + em.persist( refingEntity1 ); + em.getTransaction().commit(); - id_ListRefEdEntity1 = listReferencedEntity1.getId(); + id_ListRefEdEntity1 = listReferencedEntity1.getId(); - // Revision 2 - ListRefIngEntity refingEntity2 = new ListRefIngEntity( - Integer.valueOf(2), "refing2", listReferencedEntity1); + // Revision 2 + ListRefIngEntity refingEntity2 = new ListRefIngEntity( + Integer.valueOf( 2 ), "refing2", listReferencedEntity1 + ); - em.getTransaction().begin(); - em.persist(refingEntity2); - em.getTransaction().commit(); - } + em.getTransaction().begin(); + em.persist( refingEntity2 ); + em.getTransaction().commit(); + } - @Test - public void testProxyIdentifier() { - EntityManager em = getEntityManager(); + @Test + public void testProxyIdentifier() { + EntityManager em = getEntityManager(); - ListRefEdEntity listReferencedEntity1 = em.getReference( - ListRefEdEntity.class, id_ListRefEdEntity1); + ListRefEdEntity listReferencedEntity1 = em.getReference( + ListRefEdEntity.class, id_ListRefEdEntity1 + ); - assert listReferencedEntity1 instanceof HibernateProxy; + assert listReferencedEntity1 instanceof HibernateProxy; - // Revision 3 - ListRefIngEntity refingEntity3 = new ListRefIngEntity( - Integer.valueOf(3), "refing3", listReferencedEntity1); + // Revision 3 + ListRefIngEntity refingEntity3 = new ListRefIngEntity( + Integer.valueOf( 3 ), "refing3", listReferencedEntity1 + ); - em.getTransaction().begin(); - em.persist(refingEntity3); - em.getTransaction().commit(); + em.getTransaction().begin(); + em.persist( refingEntity3 ); + em.getTransaction().commit(); - listReferencedEntity1.getReffering().size(); + listReferencedEntity1.getReffering().size(); - } + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/proxy/ProxyIdentifier.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/proxy/ProxyIdentifier.java index fb08cb875c..95b010430d 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/proxy/ProxyIdentifier.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/proxy/ProxyIdentifier.java @@ -25,8 +25,6 @@ package org.hibernate.envers.test.integration.proxy; import javax.persistence.EntityManager; -import org.junit.Test; - import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.UnversionedStrTestEntity; @@ -34,55 +32,57 @@ import org.hibernate.envers.test.entities.manytoone.unidirectional.TargetNotAudi import org.hibernate.proxy.HibernateProxy; import org.hibernate.proxy.LazyInitializer; +import org.junit.Test; + /** * @author Eugene Goroschenya */ public class ProxyIdentifier extends BaseEnversJPAFunctionalTestCase { - private TargetNotAuditedEntity tnae1; - private UnversionedStrTestEntity uste1; + private TargetNotAuditedEntity tnae1; + private UnversionedStrTestEntity uste1; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { TargetNotAuditedEntity.class, UnversionedStrTestEntity.class }; - } + return new Class[] {TargetNotAuditedEntity.class, UnversionedStrTestEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - uste1 = new UnversionedStrTestEntity("str1"); + uste1 = new UnversionedStrTestEntity( "str1" ); - // No revision - em.getTransaction().begin(); - em.persist(uste1); - em.getTransaction().commit(); + // No revision + em.getTransaction().begin(); + em.persist( uste1 ); + em.getTransaction().commit(); - // Revision 1 - em.getTransaction().begin(); - uste1 = em.find(UnversionedStrTestEntity.class, uste1.getId()); - tnae1 = new TargetNotAuditedEntity(1, "tnae1", uste1); - em.persist(tnae1); - em.getTransaction().commit(); - } + // Revision 1 + em.getTransaction().begin(); + uste1 = em.find( UnversionedStrTestEntity.class, uste1.getId() ); + tnae1 = new TargetNotAuditedEntity( 1, "tnae1", uste1 ); + em.persist( tnae1 ); + em.getTransaction().commit(); + } - @Test - public void testProxyIdentifier() { - TargetNotAuditedEntity rev1 = getAuditReader().find(TargetNotAuditedEntity.class, tnae1.getId(), 1); + @Test + public void testProxyIdentifier() { + TargetNotAuditedEntity rev1 = getAuditReader().find( TargetNotAuditedEntity.class, tnae1.getId(), 1 ); - assert rev1.getReference() instanceof HibernateProxy; + assert rev1.getReference() instanceof HibernateProxy; - HibernateProxy proxyCreateByEnvers = (HibernateProxy) rev1.getReference(); - LazyInitializer lazyInitializer = proxyCreateByEnvers.getHibernateLazyInitializer(); + HibernateProxy proxyCreateByEnvers = (HibernateProxy) rev1.getReference(); + LazyInitializer lazyInitializer = proxyCreateByEnvers.getHibernateLazyInitializer(); - assert lazyInitializer.isUninitialized(); - assert lazyInitializer.getIdentifier() != null; - assert lazyInitializer.getIdentifier().equals(tnae1.getId()); - assert lazyInitializer.isUninitialized(); + assert lazyInitializer.isUninitialized(); + assert lazyInitializer.getIdentifier() != null; + assert lazyInitializer.getIdentifier().equals( tnae1.getId() ); + assert lazyInitializer.isUninitialized(); - assert rev1.getReference().getId().equals(uste1.getId()); - assert rev1.getReference().getStr().equals(uste1.getStr()); - assert !lazyInitializer.isUninitialized(); - } + assert rev1.getReference().getId().equals( uste1.getId() ); + assert rev1.getReference().getStr().equals( uste1.getStr() ); + assert !lazyInitializer.isUninitialized(); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/proxy/QueryingWithProxyObjectTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/proxy/QueryingWithProxyObjectTest.java index effb0f3958..c411e82256 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/proxy/QueryingWithProxyObjectTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/proxy/QueryingWithProxyObjectTest.java @@ -3,62 +3,69 @@ package org.hibernate.envers.test.integration.proxy; import java.util.Arrays; import java.util.List; -import org.junit.Assert; -import org.junit.Test; - import org.hibernate.envers.test.BaseEnversFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrTestEntity; + +import org.junit.Assert; +import org.junit.Test; + import org.hibernate.testing.TestForIssue; /** * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public class QueryingWithProxyObjectTest extends BaseEnversFunctionalTestCase { - private Integer id = null; + private Integer id = null; - @Override - protected Class[] getAnnotatedClasses() { - return new Class[]{ StrTestEntity.class}; - } + @Override + protected Class[] getAnnotatedClasses() { + return new Class[] {StrTestEntity.class}; + } - @Test - @Priority(10) - public void initData() { - // Revision 1 - getSession().getTransaction().begin(); - StrTestEntity ste = new StrTestEntity("data"); - getSession().persist(ste); - getSession().getTransaction().commit(); - id = ste.getId(); - getSession().close(); - } + @Test + @Priority(10) + public void initData() { + // Revision 1 + getSession().getTransaction().begin(); + StrTestEntity ste = new StrTestEntity( "data" ); + getSession().persist( ste ); + getSession().getTransaction().commit(); + id = ste.getId(); + getSession().close(); + } - @Test - @TestForIssue(jiraKey="HHH-4760") - @SuppressWarnings("unchecked") - public void testQueryingWithProxyObject() { - StrTestEntity originalSte = new StrTestEntity("data", id); - // Load the proxy instance - StrTestEntity proxySte = (StrTestEntity) getSession().load(StrTestEntity.class, id); + @Test + @TestForIssue(jiraKey = "HHH-4760") + @SuppressWarnings("unchecked") + public void testQueryingWithProxyObject() { + StrTestEntity originalSte = new StrTestEntity( "data", id ); + // Load the proxy instance + StrTestEntity proxySte = (StrTestEntity) getSession().load( StrTestEntity.class, id ); - Assert.assertTrue(getAuditReader().isEntityClassAudited(proxySte.getClass())); + Assert.assertTrue( getAuditReader().isEntityClassAudited( proxySte.getClass() ) ); - StrTestEntity ste = getAuditReader().find(proxySte.getClass(), proxySte.getId(), 1); - Assert.assertEquals(originalSte, ste); + StrTestEntity ste = getAuditReader().find( proxySte.getClass(), proxySte.getId(), 1 ); + Assert.assertEquals( originalSte, ste ); - List revisions = getAuditReader().getRevisions(proxySte.getClass(), proxySte.getId()); - Assert.assertEquals(Arrays.asList(1), revisions); + List revisions = getAuditReader().getRevisions( proxySte.getClass(), proxySte.getId() ); + Assert.assertEquals( Arrays.asList( 1 ), revisions ); - List entities = getAuditReader().createQuery().forEntitiesAtRevision(proxySte.getClass(), 1).getResultList(); - Assert.assertEquals(Arrays.asList(originalSte), entities); + List entities = getAuditReader().createQuery() + .forEntitiesAtRevision( proxySte.getClass(), 1 ) + .getResultList(); + Assert.assertEquals( Arrays.asList( originalSte ), entities ); - ste = (StrTestEntity) getAuditReader().createQuery().forRevisionsOfEntity(proxySte.getClass(), true, false).getSingleResult(); - Assert.assertEquals(originalSte, ste); + ste = (StrTestEntity) getAuditReader().createQuery() + .forRevisionsOfEntity( proxySte.getClass(), true, false ) + .getSingleResult(); + Assert.assertEquals( originalSte, ste ); - ste = (StrTestEntity) getAuditReader().createQuery().forEntitiesModifiedAtRevision(proxySte.getClass(), 1).getSingleResult(); - Assert.assertEquals(originalSte, ste); + ste = (StrTestEntity) getAuditReader().createQuery() + .forEntitiesModifiedAtRevision( proxySte.getClass(), 1 ) + .getSingleResult(); + Assert.assertEquals( originalSte, ste ); - getSession().close(); - } + getSession().close(); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/proxy/RemovedObjectQueryTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/proxy/RemovedObjectQueryTest.java index 7f56a97947..5fb9cc8d3d 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/proxy/RemovedObjectQueryTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/proxy/RemovedObjectQueryTest.java @@ -1,13 +1,10 @@ package org.hibernate.envers.test.integration.proxy; +import javax.persistence.EntityManager; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; -import javax.persistence.EntityManager; - -import org.junit.Assert; -import org.junit.Test; import org.hibernate.Hibernate; import org.hibernate.envers.RevisionType; @@ -27,6 +24,10 @@ import org.hibernate.envers.test.entities.onetomany.SetRefEdEntity; import org.hibernate.envers.test.entities.onetomany.SetRefIngEntity; import org.hibernate.envers.test.integration.manytomany.ternary.TernaryMapEntity; import org.hibernate.envers.test.tools.TestTools; + +import org.junit.Assert; +import org.junit.Test; + import org.hibernate.testing.TestForIssue; /** @@ -172,7 +173,10 @@ public class RemovedObjectQueryTest extends BaseEnversJPAFunctionalTestCase { em.getTransaction().begin(); unversionedEntity1 = new UnversionedStrTestEntity( "string 1" ); unversionedEntity2 = new UnversionedStrTestEntity( "string 2" ); - M2MIndexedListTargetNotAuditedEntity relationNotAuditedEntity = new M2MIndexedListTargetNotAuditedEntity( 1, "Parent" ); + M2MIndexedListTargetNotAuditedEntity relationNotAuditedEntity = new M2MIndexedListTargetNotAuditedEntity( + 1, + "Parent" + ); relationNotAuditedEntity.getReferences().add( unversionedEntity1 ); relationNotAuditedEntity.getReferences().add( unversionedEntity2 ); em.persist( unversionedEntity1 ); @@ -182,7 +186,10 @@ public class RemovedObjectQueryTest extends BaseEnversJPAFunctionalTestCase { // Revision 14 - removing entity with unversioned relation em.getTransaction().begin(); - relationNotAuditedEntity = em.find( M2MIndexedListTargetNotAuditedEntity.class, relationNotAuditedEntity.getId() ); + relationNotAuditedEntity = em.find( + M2MIndexedListTargetNotAuditedEntity.class, + relationNotAuditedEntity.getId() + ); em.remove( relationNotAuditedEntity ); em.getTransaction().commit(); @@ -225,12 +232,16 @@ public class RemovedObjectQueryTest extends BaseEnversJPAFunctionalTestCase { Assert.assertEquals( 16, getRevisionNumber( objArray[1] ) ); TernaryMapEntity mapEntity = (TernaryMapEntity) objArray[0]; - Assert.assertEquals( TestTools.makeMap( intEntity1, stringEntity1, intEntity2, stringEntity2 ), mapEntity.getMap() ); + Assert.assertEquals( + TestTools.makeMap( intEntity1, stringEntity1, intEntity2, stringEntity2 ), + mapEntity.getMap() + ); } @Test public void testUnversionedRelation() { - List queryResult = getAuditReader().createQuery().forRevisionsOfEntity( M2MIndexedListTargetNotAuditedEntity.class, false, true ) + List queryResult = getAuditReader().createQuery() + .forRevisionsOfEntity( M2MIndexedListTargetNotAuditedEntity.class, false, true ) .add( AuditEntity.id().eq( 1 ) ) .add( AuditEntity.revisionType().eq( RevisionType.DEL ) ) .getResultList(); @@ -440,6 +451,6 @@ public class RemovedObjectQueryTest extends BaseEnversJPAFunctionalTestCase { } private Number getRevisionNumber(Object revisionEntity) { - return ( (SequenceIdRevisionEntity) revisionEntity ).getId(); + return ((SequenceIdRevisionEntity) revisionEntity).getId(); } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/AggregateQuery.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/AggregateQuery.java index 5f04155a06..d0a2c04295 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/AggregateQuery.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/AggregateQuery.java @@ -23,12 +23,9 @@ */ package org.hibernate.envers.test.integration.query; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.List; -import javax.persistence.EntityManager; - -import org.junit.Assert; -import org.junit.Test; import org.hibernate.envers.query.AuditEntity; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; @@ -36,6 +33,10 @@ import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.IntTestEntity; import org.hibernate.envers.test.entities.ids.UnusualIdNamingEntity; import org.hibernate.envers.test.tools.TestTools; + +import org.junit.Assert; +import org.junit.Test; + import org.hibernate.testing.TestForIssue; /** @@ -45,75 +46,75 @@ import org.hibernate.testing.TestForIssue; public class AggregateQuery extends BaseEnversJPAFunctionalTestCase { @Override protected Class[] getAnnotatedClasses() { - return new Class[] { IntTestEntity.class, UnusualIdNamingEntity.class }; + return new Class[] {IntTestEntity.class, UnusualIdNamingEntity.class}; } @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); // Revision 1 - em.getTransaction().begin(); - IntTestEntity ite1 = new IntTestEntity(2); - IntTestEntity ite2 = new IntTestEntity(10); - em.persist(ite1); - em.persist(ite2); - Integer id1 = ite1.getId(); - Integer id2 = ite2.getId(); - em.getTransaction().commit(); + em.getTransaction().begin(); + IntTestEntity ite1 = new IntTestEntity( 2 ); + IntTestEntity ite2 = new IntTestEntity( 10 ); + em.persist( ite1 ); + em.persist( ite2 ); + Integer id1 = ite1.getId(); + Integer id2 = ite2.getId(); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); - IntTestEntity ite3 = new IntTestEntity(8); + // Revision 2 + em.getTransaction().begin(); + IntTestEntity ite3 = new IntTestEntity( 8 ); UnusualIdNamingEntity uine1 = new UnusualIdNamingEntity( "id1", "data1" ); em.persist( uine1 ); - em.persist(ite3); - ite1 = em.find(IntTestEntity.class, id1); - ite1.setNumber(0); - em.getTransaction().commit(); + em.persist( ite3 ); + ite1 = em.find( IntTestEntity.class, id1 ); + ite1.setNumber( 0 ); + em.getTransaction().commit(); - // Revision 3 - em.getTransaction().begin(); - ite2 = em.find(IntTestEntity.class, id2); - ite2.setNumber(52); - em.getTransaction().commit(); + // Revision 3 + em.getTransaction().begin(); + ite2 = em.find( IntTestEntity.class, id2 ); + ite2.setNumber( 52 ); + em.getTransaction().commit(); em.close(); - } - - @Test - public void testEntitiesAvgMaxQuery() { - Object[] ver1 = (Object[]) getAuditReader().createQuery() - .forEntitiesAtRevision(IntTestEntity.class, 1) - .addProjection(AuditEntity.property("number").max()) - .addProjection(AuditEntity.property("number").function("avg")) - .getSingleResult(); - - Object[] ver2 = (Object[]) getAuditReader().createQuery() - .forEntitiesAtRevision(IntTestEntity.class, 2) - .addProjection(AuditEntity.property("number").max()) - .addProjection(AuditEntity.property("number").function("avg")) - .getSingleResult(); - - Object[] ver3 = (Object[]) getAuditReader().createQuery() - .forEntitiesAtRevision(IntTestEntity.class, 3) - .addProjection(AuditEntity.property("number").max()) - .addProjection(AuditEntity.property("number").function("avg")) - .getSingleResult(); - - assert (Integer) ver1[0] == 10; - assert (Double) ver1[1] == 6.0; - - assert (Integer) ver2[0] == 10; - assert (Double) ver2[1] == 6.0; - - assert (Integer) ver3[0] == 52; - assert (Double) ver3[1] == 20.0; - } + } @Test - @TestForIssue( jiraKey = "HHH-8036" ) + public void testEntitiesAvgMaxQuery() { + Object[] ver1 = (Object[]) getAuditReader().createQuery() + .forEntitiesAtRevision( IntTestEntity.class, 1 ) + .addProjection( AuditEntity.property( "number" ).max() ) + .addProjection( AuditEntity.property( "number" ).function( "avg" ) ) + .getSingleResult(); + + Object[] ver2 = (Object[]) getAuditReader().createQuery() + .forEntitiesAtRevision( IntTestEntity.class, 2 ) + .addProjection( AuditEntity.property( "number" ).max() ) + .addProjection( AuditEntity.property( "number" ).function( "avg" ) ) + .getSingleResult(); + + Object[] ver3 = (Object[]) getAuditReader().createQuery() + .forEntitiesAtRevision( IntTestEntity.class, 3 ) + .addProjection( AuditEntity.property( "number" ).max() ) + .addProjection( AuditEntity.property( "number" ).function( "avg" ) ) + .getSingleResult(); + + assert (Integer) ver1[0] == 10; + assert (Double) ver1[1] == 6.0; + + assert (Integer) ver2[0] == 10; + assert (Double) ver2[1] == 6.0; + + assert (Integer) ver3[0] == 52; + assert (Double) ver3[1] == 20.0; + } + + @Test + @TestForIssue(jiraKey = "HHH-8036") public void testEntityIdProjection() { Integer maxId = (Integer) getAuditReader().createQuery().forRevisionsOfEntity( IntTestEntity.class, true, true ) .addProjection( AuditEntity.id().max() ) @@ -123,22 +124,31 @@ public class AggregateQuery extends BaseEnversJPAFunctionalTestCase { } @Test - @TestForIssue( jiraKey = "HHH-8036" ) + @TestForIssue(jiraKey = "HHH-8036") public void testEntityIdRestriction() { - List list = getAuditReader().createQuery().forRevisionsOfEntity( IntTestEntity.class, true, true ) + List list = getAuditReader().createQuery().forRevisionsOfEntity( + IntTestEntity.class, + true, + true + ) .add( AuditEntity.id().between( 2, 3 ) ) .getResultList(); Assert.assertTrue( - TestTools.checkList( list, + TestTools.checkList( + list, new IntTestEntity( 10, 2 ), new IntTestEntity( 8, 3 ), new IntTestEntity( 52, 2 ) ) ); } @Test - @TestForIssue( jiraKey = "HHH-8036" ) + @TestForIssue(jiraKey = "HHH-8036") public void testEntityIdOrdering() { - List list = getAuditReader().createQuery().forRevisionsOfEntity( IntTestEntity.class, true, true ) + List list = getAuditReader().createQuery().forRevisionsOfEntity( + IntTestEntity.class, + true, + true + ) .add( AuditEntity.revisionNumber().lt( 2 ) ) .addOrder( AuditEntity.id().desc() ) .getResultList(); @@ -146,7 +156,7 @@ public class AggregateQuery extends BaseEnversJPAFunctionalTestCase { } @Test - @TestForIssue( jiraKey = "HHH-8036" ) + @TestForIssue(jiraKey = "HHH-8036") public void testUnusualIdFieldName() { UnusualIdNamingEntity entity = (UnusualIdNamingEntity) getAuditReader().createQuery() .forRevisionsOfEntity( UnusualIdNamingEntity.class, true, true ) @@ -156,20 +166,20 @@ public class AggregateQuery extends BaseEnversJPAFunctionalTestCase { } @Test - @TestForIssue( jiraKey = "HHH-8036" ) + @TestForIssue(jiraKey = "HHH-8036") public void testEntityIdModifiedFlagNotSupported() { try { getAuditReader().createQuery().forRevisionsOfEntity( IntTestEntity.class, true, true ) .add( AuditEntity.id().hasChanged() ) .getResultList(); } - catch ( UnsupportedOperationException e1 ) { + catch (UnsupportedOperationException e1) { try { getAuditReader().createQuery().forRevisionsOfEntity( IntTestEntity.class, true, true ) .add( AuditEntity.id().hasNotChanged() ) .getResultList(); } - catch ( UnsupportedOperationException e2 ) { + catch (UnsupportedOperationException e2) { return; } Assert.fail(); diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/CustomRevEntityQuery.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/CustomRevEntityQuery.java index 5403661968..5fb1e47009 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/CustomRevEntityQuery.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/CustomRevEntityQuery.java @@ -23,10 +23,8 @@ */ package org.hibernate.envers.test.integration.query; -import java.util.List; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.List; import org.hibernate.envers.query.AuditEntity; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; @@ -34,93 +32,95 @@ import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrIntTestEntity; import org.hibernate.envers.test.entities.reventity.CustomRevEntity; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ @SuppressWarnings({"unchecked"}) public class CustomRevEntityQuery extends BaseEnversJPAFunctionalTestCase { - private Integer id1; - private Integer id2; - private Long timestamp; + private Integer id1; + private Integer id2; + private Long timestamp; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { StrIntTestEntity.class, CustomRevEntity.class }; - } + return new Class[] {StrIntTestEntity.class, CustomRevEntity.class}; + } - @Test - @Priority(10) - public void initData() throws InterruptedException { - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); + @Test + @Priority(10) + public void initData() throws InterruptedException { + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); - StrIntTestEntity site1 = new StrIntTestEntity("a", 10); - StrIntTestEntity site2 = new StrIntTestEntity("b", 15); + StrIntTestEntity site1 = new StrIntTestEntity( "a", 10 ); + StrIntTestEntity site2 = new StrIntTestEntity( "b", 15 ); - em.persist(site1); - em.persist(site2); + em.persist( site1 ); + em.persist( site2 ); - id1 = site1.getId(); - id2 = site2.getId(); + id1 = site1.getId(); + id2 = site2.getId(); - em.getTransaction().commit(); + em.getTransaction().commit(); - Thread.sleep(100); + Thread.sleep( 100 ); - timestamp = System.currentTimeMillis(); + timestamp = System.currentTimeMillis(); - Thread.sleep(100); + Thread.sleep( 100 ); - // Revision 2 - em.getTransaction().begin(); + // Revision 2 + em.getTransaction().begin(); - site1 = em.find(StrIntTestEntity.class, id1); + site1 = em.find( StrIntTestEntity.class, id1 ); - site1.setStr1("c"); + site1.setStr1( "c" ); - em.getTransaction().commit(); - } + em.getTransaction().commit(); + } - @Test - public void testRevisionsOfId1Query() { - List result = getAuditReader().createQuery() - .forRevisionsOfEntity(StrIntTestEntity.class, false, true) - .add(AuditEntity.id().eq(id1)) - .getResultList(); + @Test + public void testRevisionsOfId1Query() { + List result = getAuditReader().createQuery() + .forRevisionsOfEntity( StrIntTestEntity.class, false, true ) + .add( AuditEntity.id().eq( id1 ) ) + .getResultList(); - assert result.get(0)[0].equals(new StrIntTestEntity("a", 10, id1)); - assert result.get(0)[1] instanceof CustomRevEntity; - assert ((CustomRevEntity) result.get(0)[1]).getCustomId() == 1; + assert result.get( 0 )[0].equals( new StrIntTestEntity( "a", 10, id1 ) ); + assert result.get( 0 )[1] instanceof CustomRevEntity; + assert ((CustomRevEntity) result.get( 0 )[1]).getCustomId() == 1; - assert result.get(1)[0].equals(new StrIntTestEntity("c", 10, id1)); - assert result.get(1)[1] instanceof CustomRevEntity; - assert ((CustomRevEntity) result.get(1)[1]).getCustomId() == 2; - } + assert result.get( 1 )[0].equals( new StrIntTestEntity( "c", 10, id1 ) ); + assert result.get( 1 )[1] instanceof CustomRevEntity; + assert ((CustomRevEntity) result.get( 1 )[1]).getCustomId() == 2; + } - @Test - public void testRevisionsOfId2Query() { - List result = getAuditReader().createQuery() - .forRevisionsOfEntity(StrIntTestEntity.class, false, true) - .add(AuditEntity.id().eq(id2)) - .getResultList(); + @Test + public void testRevisionsOfId2Query() { + List result = getAuditReader().createQuery() + .forRevisionsOfEntity( StrIntTestEntity.class, false, true ) + .add( AuditEntity.id().eq( id2 ) ) + .getResultList(); - assert result.get(0)[0].equals(new StrIntTestEntity("b", 15, id2)); - assert result.get(0)[1] instanceof CustomRevEntity; - assert ((CustomRevEntity) result.get(0)[1]).getCustomId() == 1; - } + assert result.get( 0 )[0].equals( new StrIntTestEntity( "b", 15, id2 ) ); + assert result.get( 0 )[1] instanceof CustomRevEntity; + assert ((CustomRevEntity) result.get( 0 )[1]).getCustomId() == 1; + } - @Test - public void testRevisionPropertyRestriction() { - List result = getAuditReader().createQuery() - .forRevisionsOfEntity(StrIntTestEntity.class, false, true) - .add(AuditEntity.id().eq(id1)) - .add(AuditEntity.revisionProperty("customTimestamp").ge(timestamp)) - .getResultList(); + @Test + public void testRevisionPropertyRestriction() { + List result = getAuditReader().createQuery() + .forRevisionsOfEntity( StrIntTestEntity.class, false, true ) + .add( AuditEntity.id().eq( id1 ) ) + .add( AuditEntity.revisionProperty( "customTimestamp" ).ge( timestamp ) ) + .getResultList(); - assert result.get(0)[0].equals(new StrIntTestEntity("c", 10, id1)); - assert result.get(0)[1] instanceof CustomRevEntity; - assert ((CustomRevEntity) result.get(0)[1]).getCustomId() == 2; - assert ((CustomRevEntity) result.get(0)[1]).getCustomTimestamp() >= timestamp; - } + assert result.get( 0 )[0].equals( new StrIntTestEntity( "c", 10, id1 ) ); + assert result.get( 0 )[1] instanceof CustomRevEntity; + assert ((CustomRevEntity) result.get( 0 )[1]).getCustomId() == 2; + assert ((CustomRevEntity) result.get( 0 )[1]).getCustomTimestamp() >= timestamp; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/DeletedEntities.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/DeletedEntities.java index 88961086c4..32920cbbc1 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/DeletedEntities.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/DeletedEntities.java @@ -23,10 +23,8 @@ */ package org.hibernate.envers.test.integration.query; -import java.util.List; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.List; import org.hibernate.envers.RevisionType; import org.hibernate.envers.enhanced.SequenceIdRevisionEntity; @@ -35,67 +33,69 @@ import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrIntTestEntity; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class DeletedEntities extends BaseEnversJPAFunctionalTestCase { - private Integer id2; + private Integer id2; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { StrIntTestEntity.class }; - } + return new Class[] {StrIntTestEntity.class}; + } - @Test - @Priority(10) - public void initData() { - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); + @Test + @Priority(10) + public void initData() { + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); - StrIntTestEntity site1 = new StrIntTestEntity("a", 10); - StrIntTestEntity site2 = new StrIntTestEntity("b", 11); + StrIntTestEntity site1 = new StrIntTestEntity( "a", 10 ); + StrIntTestEntity site2 = new StrIntTestEntity( "b", 11 ); - em.persist(site1); - em.persist(site2); + em.persist( site1 ); + em.persist( site2 ); - id2 = site2.getId(); + id2 = site2.getId(); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); + // Revision 2 + em.getTransaction().begin(); - site2 = em.find(StrIntTestEntity.class, id2); - em.remove(site2); + site2 = em.find( StrIntTestEntity.class, id2 ); + em.remove( site2 ); - em.getTransaction().commit(); - } + em.getTransaction().commit(); + } - @Test - public void testProjectionsInEntitiesAtRevision() { - assert getAuditReader().createQuery().forEntitiesAtRevision(StrIntTestEntity.class, 1) - .getResultList().size() == 2; - assert getAuditReader().createQuery().forEntitiesAtRevision(StrIntTestEntity.class, 2) - .getResultList().size() == 1; + @Test + public void testProjectionsInEntitiesAtRevision() { + assert getAuditReader().createQuery().forEntitiesAtRevision( StrIntTestEntity.class, 1 ) + .getResultList().size() == 2; + assert getAuditReader().createQuery().forEntitiesAtRevision( StrIntTestEntity.class, 2 ) + .getResultList().size() == 1; - assert (Long) getAuditReader().createQuery().forEntitiesAtRevision(StrIntTestEntity.class, 1) - .addProjection(AuditEntity.id().count("id")).getResultList().get(0) == 2; - assert (Long) getAuditReader().createQuery().forEntitiesAtRevision(StrIntTestEntity.class, 2) - .addProjection(AuditEntity.id().count()).getResultList().get(0) == 1; - } + assert (Long) getAuditReader().createQuery().forEntitiesAtRevision( StrIntTestEntity.class, 1 ) + .addProjection( AuditEntity.id().count( "id" ) ).getResultList().get( 0 ) == 2; + assert (Long) getAuditReader().createQuery().forEntitiesAtRevision( StrIntTestEntity.class, 2 ) + .addProjection( AuditEntity.id().count() ).getResultList().get( 0 ) == 1; + } - @Test - public void testRevisionsOfEntityWithoutDelete() { - List result = getAuditReader().createQuery() - .forRevisionsOfEntity(StrIntTestEntity.class, false, false) - .add(AuditEntity.id().eq(id2)) - .getResultList(); + @Test + public void testRevisionsOfEntityWithoutDelete() { + List result = getAuditReader().createQuery() + .forRevisionsOfEntity( StrIntTestEntity.class, false, false ) + .add( AuditEntity.id().eq( id2 ) ) + .getResultList(); - assert result.size() == 1; + assert result.size() == 1; - assert ((Object []) result.get(0))[0].equals(new StrIntTestEntity("b", 11, id2)); - assert ((SequenceIdRevisionEntity) ((Object []) result.get(0))[1]).getId() == 1; - assert ((Object []) result.get(0))[2].equals(RevisionType.ADD); - } + assert ((Object[]) result.get( 0 ))[0].equals( new StrIntTestEntity( "b", 11, id2 ) ); + assert ((SequenceIdRevisionEntity) ((Object[]) result.get( 0 ))[1]).getId() == 1; + assert ((Object[]) result.get( 0 ))[2].equals( RevisionType.ADD ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/MaximalizePropertyQuery.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/MaximalizePropertyQuery.java index ed80431564..62a322d2ca 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/MaximalizePropertyQuery.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/MaximalizePropertyQuery.java @@ -23,14 +23,11 @@ */ package org.hibernate.envers.test.integration.query; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; -import javax.persistence.EntityManager; - -import org.junit.Assert; -import org.junit.Test; import org.hibernate.envers.RevisionType; import org.hibernate.envers.enhanced.SequenceIdRevisionEntity; @@ -39,6 +36,10 @@ import org.hibernate.envers.query.criteria.AuditDisjunction; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrIntTestEntity; + +import org.junit.Assert; +import org.junit.Test; + import org.hibernate.testing.TestForIssue; /** @@ -47,115 +48,121 @@ import org.hibernate.testing.TestForIssue; */ @SuppressWarnings({"unchecked"}) public class MaximalizePropertyQuery extends BaseEnversJPAFunctionalTestCase { - Integer id1; - Integer id2; - Integer id3; - Integer id4; + Integer id1; + Integer id2; + Integer id3; + Integer id4; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { StrIntTestEntity.class }; - } + return new Class[] {StrIntTestEntity.class}; + } - @Test - @Priority(10) - public void initData() { - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); + @Test + @Priority(10) + public void initData() { + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); - StrIntTestEntity site1 = new StrIntTestEntity("a", 10); - StrIntTestEntity site2 = new StrIntTestEntity("b", 15); - StrIntTestEntity site3 = new StrIntTestEntity("c", 42); - StrIntTestEntity site4 = new StrIntTestEntity("d", 52); + StrIntTestEntity site1 = new StrIntTestEntity( "a", 10 ); + StrIntTestEntity site2 = new StrIntTestEntity( "b", 15 ); + StrIntTestEntity site3 = new StrIntTestEntity( "c", 42 ); + StrIntTestEntity site4 = new StrIntTestEntity( "d", 52 ); - em.persist(site1); - em.persist(site2); - em.persist(site3); - em.persist(site4); + em.persist( site1 ); + em.persist( site2 ); + em.persist( site3 ); + em.persist( site4 ); - id1 = site1.getId(); - id2 = site2.getId(); - id3 = site3.getId(); - id4 = site4.getId(); + id1 = site1.getId(); + id2 = site2.getId(); + id3 = site3.getId(); + id4 = site4.getId(); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); + // Revision 2 + em.getTransaction().begin(); - site1 = em.find(StrIntTestEntity.class, id1); - site2 = em.find(StrIntTestEntity.class, id2); + site1 = em.find( StrIntTestEntity.class, id1 ); + site2 = em.find( StrIntTestEntity.class, id2 ); - site1.setStr1("d"); - site2.setNumber(20); + site1.setStr1( "d" ); + site2.setNumber( 20 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 - em.getTransaction().begin(); + // Revision 3 + em.getTransaction().begin(); - site1 = em.find(StrIntTestEntity.class, id1); - site2 = em.find(StrIntTestEntity.class, id2); + site1 = em.find( StrIntTestEntity.class, id1 ); + site2 = em.find( StrIntTestEntity.class, id2 ); - site1.setNumber(30); - site2.setStr1("z"); + site1.setNumber( 30 ); + site2.setStr1( "z" ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 4 - em.getTransaction().begin(); + // Revision 4 + em.getTransaction().begin(); - site1 = em.find(StrIntTestEntity.class, id1); - site2 = em.find(StrIntTestEntity.class, id2); + site1 = em.find( StrIntTestEntity.class, id1 ); + site2 = em.find( StrIntTestEntity.class, id2 ); - site1.setNumber(5); - site2.setStr1("a"); + site1.setNumber( 5 ); + site2.setStr1( "a" ); - em.getTransaction().commit(); + em.getTransaction().commit(); // Revision 5 em.getTransaction().begin(); site4 = em.find( StrIntTestEntity.class, id4 ); em.remove( site4 ); em.getTransaction().commit(); - } + } - @Test - public void testMaximizeWithIdEq() { - List revs_id1 = getAuditReader().createQuery() - .forRevisionsOfEntity(StrIntTestEntity.class, false, true) - .addProjection(AuditEntity.revisionNumber()) - .add(AuditEntity.property("number").maximize() - .add(AuditEntity.id().eq(id2))) - .getResultList(); + @Test + public void testMaximizeWithIdEq() { + List revs_id1 = getAuditReader().createQuery() + .forRevisionsOfEntity( StrIntTestEntity.class, false, true ) + .addProjection( AuditEntity.revisionNumber() ) + .add( + AuditEntity.property( "number" ).maximize() + .add( AuditEntity.id().eq( id2 ) ) + ) + .getResultList(); - assert Arrays.asList(2, 3, 4).equals(revs_id1); - } + assert Arrays.asList( 2, 3, 4 ).equals( revs_id1 ); + } - @Test - public void testMinimizeWithPropertyEq() { - List result = getAuditReader().createQuery() - .forRevisionsOfEntity(StrIntTestEntity.class, false, true) - .addProjection(AuditEntity.revisionNumber()) - .add(AuditEntity.property("number").minimize() - .add(AuditEntity.property("str1").eq("a"))) - .getResultList(); + @Test + public void testMinimizeWithPropertyEq() { + List result = getAuditReader().createQuery() + .forRevisionsOfEntity( StrIntTestEntity.class, false, true ) + .addProjection( AuditEntity.revisionNumber() ) + .add( + AuditEntity.property( "number" ).minimize() + .add( AuditEntity.property( "str1" ).eq( "a" ) ) + ) + .getResultList(); - assert Arrays.asList(1).equals(result); - } + assert Arrays.asList( 1 ).equals( result ); + } - @Test - public void testMaximizeRevision() { - List result = getAuditReader().createQuery() - .forRevisionsOfEntity(StrIntTestEntity.class, false, true) - .addProjection(AuditEntity.revisionNumber()) - .add(AuditEntity.revisionNumber().maximize() - .add(AuditEntity.property("number").eq(10))) - .getResultList(); + @Test + public void testMaximizeRevision() { + List result = getAuditReader().createQuery() + .forRevisionsOfEntity( StrIntTestEntity.class, false, true ) + .addProjection( AuditEntity.revisionNumber() ) + .add( + AuditEntity.revisionNumber().maximize() + .add( AuditEntity.property( "number" ).eq( 10 ) ) + ) + .getResultList(); - assert Arrays.asList(2).equals(result); - } + assert Arrays.asList( 2 ).equals( result ); + } @Test @TestForIssue(jiraKey = "HHH-7800") @@ -207,7 +214,7 @@ public class MaximalizePropertyQuery extends BaseEnversJPAFunctionalTestCase { private void checkRevisionData(Object[] result, int revision, RevisionType type, StrIntTestEntity entity) { Assert.assertEquals( entity, result[0] ); - Assert.assertEquals( revision, ( (SequenceIdRevisionEntity) result[1] ).getId() ); + Assert.assertEquals( revision, ((SequenceIdRevisionEntity) result[1]).getId() ); Assert.assertEquals( type, result[2] ); } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/NullPropertyQuery.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/NullPropertyQuery.java index ffbd1d9433..1e146e7b47 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/NullPropertyQuery.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/NullPropertyQuery.java @@ -2,8 +2,6 @@ package org.hibernate.envers.test.integration.query; import javax.persistence.EntityManager; -import org.junit.Test; - import org.hibernate.envers.query.AuditEntity; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; @@ -14,15 +12,17 @@ import org.hibernate.envers.test.entities.onetomany.CollectionRefIngEntity; import org.hibernate.envers.test.entities.onetomany.ids.SetRefEdEmbIdEntity; import org.hibernate.envers.test.entities.onetomany.ids.SetRefIngEmbIdEntity; +import org.junit.Test; + /** * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public class NullPropertyQuery extends BaseEnversJPAFunctionalTestCase { - private Integer idSimplePropertyNull = null; - private Integer idSimplePropertyNotNull = null; - private EmbId idMulticolumnReferenceToParentNull = new EmbId(0, 1); - private Integer idReferenceToParentNotNull = 1; - private Integer idParent = 1; + private Integer idSimplePropertyNull = null; + private Integer idSimplePropertyNotNull = null; + private EmbId idMulticolumnReferenceToParentNull = new EmbId( 0, 1 ); + private Integer idReferenceToParentNotNull = 1; + private Integer idParent = 1; @Override protected Class[] getAnnotatedClasses() { @@ -33,74 +33,82 @@ public class NullPropertyQuery extends BaseEnversJPAFunctionalTestCase { CollectionRefEdEntity.class, CollectionRefIngEntity.class }; - } + } - @Test - @Priority(10) - public void initData() { - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); - StrIntTestEntity nullSite = new StrIntTestEntity(null, 1); - StrIntTestEntity notNullSite = new StrIntTestEntity("data", 2); - em.persist(nullSite); - em.persist(notNullSite); - idSimplePropertyNull = nullSite.getId(); - idSimplePropertyNotNull = notNullSite.getId(); - em.getTransaction().commit(); + @Test + @Priority(10) + public void initData() { + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); + StrIntTestEntity nullSite = new StrIntTestEntity( null, 1 ); + StrIntTestEntity notNullSite = new StrIntTestEntity( "data", 2 ); + em.persist( nullSite ); + em.persist( notNullSite ); + idSimplePropertyNull = nullSite.getId(); + idSimplePropertyNotNull = notNullSite.getId(); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); - SetRefIngEmbIdEntity nullParentSrieie = new SetRefIngEmbIdEntity(idMulticolumnReferenceToParentNull, "data", null); - em.persist(nullParentSrieie); - em.getTransaction().commit(); + // Revision 2 + em.getTransaction().begin(); + SetRefIngEmbIdEntity nullParentSrieie = new SetRefIngEmbIdEntity( + idMulticolumnReferenceToParentNull, + "data", + null + ); + em.persist( nullParentSrieie ); + em.getTransaction().commit(); - // Revision 3 - em.getTransaction().begin(); - CollectionRefEdEntity parent = new CollectionRefEdEntity(idParent, "data"); - CollectionRefIngEntity notNullParentCrie = new CollectionRefIngEntity(idReferenceToParentNotNull, "data", parent); - em.persist(parent); - em.persist(notNullParentCrie); - em.getTransaction().commit(); - } + // Revision 3 + em.getTransaction().begin(); + CollectionRefEdEntity parent = new CollectionRefEdEntity( idParent, "data" ); + CollectionRefIngEntity notNullParentCrie = new CollectionRefIngEntity( + idReferenceToParentNotNull, + "data", + parent + ); + em.persist( parent ); + em.persist( notNullParentCrie ); + em.getTransaction().commit(); + } - @Test - public void testSimplePropertyIsNullQuery() { - StrIntTestEntity ver = (StrIntTestEntity) getAuditReader().createQuery() - .forEntitiesAtRevision(StrIntTestEntity.class, 1) - .add(AuditEntity.property("str1").isNull()) - .getSingleResult(); + @Test + public void testSimplePropertyIsNullQuery() { + StrIntTestEntity ver = (StrIntTestEntity) getAuditReader().createQuery() + .forEntitiesAtRevision( StrIntTestEntity.class, 1 ) + .add( AuditEntity.property( "str1" ).isNull() ) + .getSingleResult(); - assert ver.equals(new StrIntTestEntity(null, 1, idSimplePropertyNull)); - } + assert ver.equals( new StrIntTestEntity( null, 1, idSimplePropertyNull ) ); + } - @Test - public void testSimplePropertyIsNotNullQuery() { - StrIntTestEntity ver = (StrIntTestEntity) getAuditReader().createQuery() - .forEntitiesAtRevision(StrIntTestEntity.class, 1) - .add(AuditEntity.property("str1").isNotNull()) - .getSingleResult(); + @Test + public void testSimplePropertyIsNotNullQuery() { + StrIntTestEntity ver = (StrIntTestEntity) getAuditReader().createQuery() + .forEntitiesAtRevision( StrIntTestEntity.class, 1 ) + .add( AuditEntity.property( "str1" ).isNotNull() ) + .getSingleResult(); - assert ver.equals(new StrIntTestEntity("data", 2, idSimplePropertyNotNull)); - } + assert ver.equals( new StrIntTestEntity( "data", 2, idSimplePropertyNotNull ) ); + } - @Test - public void testReferenceMulticolumnPropertyIsNullQuery() { - SetRefIngEmbIdEntity ver = (SetRefIngEmbIdEntity) getAuditReader().createQuery() - .forEntitiesAtRevision(SetRefIngEmbIdEntity.class, 2) - .add(AuditEntity.property("reference").isNull()) - .getSingleResult(); + @Test + public void testReferenceMulticolumnPropertyIsNullQuery() { + SetRefIngEmbIdEntity ver = (SetRefIngEmbIdEntity) getAuditReader().createQuery() + .forEntitiesAtRevision( SetRefIngEmbIdEntity.class, 2 ) + .add( AuditEntity.property( "reference" ).isNull() ) + .getSingleResult(); - assert ver.getId().equals(idMulticolumnReferenceToParentNull); - } + assert ver.getId().equals( idMulticolumnReferenceToParentNull ); + } - @Test - public void testReferencePropertyIsNotNullQuery() { - CollectionRefIngEntity ver = (CollectionRefIngEntity) getAuditReader().createQuery() - .forEntitiesAtRevision(CollectionRefIngEntity.class, 3) - .add(AuditEntity.property("reference").isNotNull()) - .getSingleResult(); + @Test + public void testReferencePropertyIsNotNullQuery() { + CollectionRefIngEntity ver = (CollectionRefIngEntity) getAuditReader().createQuery() + .forEntitiesAtRevision( CollectionRefIngEntity.class, 3 ) + .add( AuditEntity.property( "reference" ).isNotNull() ) + .getSingleResult(); - assert ver.getId().equals(idReferenceToParentNotNull); - } + assert ver.getId().equals( idReferenceToParentNotNull ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/OrderByLimitQuery.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/OrderByLimitQuery.java index 53458de8c1..91ce3ef192 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/OrderByLimitQuery.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/OrderByLimitQuery.java @@ -23,126 +23,126 @@ */ package org.hibernate.envers.test.integration.query; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.List; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.query.AuditEntity; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.IntTestEntity; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ @SuppressWarnings({"unchecked"}) public class OrderByLimitQuery extends BaseEnversJPAFunctionalTestCase { - private Integer id1; - private Integer id2; - private Integer id3; - private Integer id4; - private Integer id5; + private Integer id1; + private Integer id2; + private Integer id3; + private Integer id4; + private Integer id5; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { IntTestEntity.class }; - } + return new Class[] {IntTestEntity.class}; + } - @Test - @Priority(10) - public void initData() { - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); + @Test + @Priority(10) + public void initData() { + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); - IntTestEntity ite1 = new IntTestEntity(12); - IntTestEntity ite2 = new IntTestEntity(5); - IntTestEntity ite3 = new IntTestEntity(8); - IntTestEntity ite4 = new IntTestEntity(1); + IntTestEntity ite1 = new IntTestEntity( 12 ); + IntTestEntity ite2 = new IntTestEntity( 5 ); + IntTestEntity ite3 = new IntTestEntity( 8 ); + IntTestEntity ite4 = new IntTestEntity( 1 ); - em.persist(ite1); - em.persist(ite2); - em.persist(ite3); - em.persist(ite4); + em.persist( ite1 ); + em.persist( ite2 ); + em.persist( ite3 ); + em.persist( ite4 ); - id1 = ite1.getId(); - id2 = ite2.getId(); - id3 = ite3.getId(); - id4 = ite4.getId(); + id1 = ite1.getId(); + id2 = ite2.getId(); + id3 = ite3.getId(); + id4 = ite4.getId(); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); + // Revision 2 + em.getTransaction().begin(); - IntTestEntity ite5 = new IntTestEntity(3); - em.persist(ite5); - id5 = ite5.getId(); + IntTestEntity ite5 = new IntTestEntity( 3 ); + em.persist( ite5 ); + id5 = ite5.getId(); - ite1 = em.find(IntTestEntity.class, id1); - ite1.setNumber(0); + ite1 = em.find( IntTestEntity.class, id1 ); + ite1.setNumber( 0 ); - ite4 = em.find(IntTestEntity.class, id4); - ite4.setNumber(15); + ite4 = em.find( IntTestEntity.class, id4 ); + ite4.setNumber( 15 ); - em.getTransaction().commit(); - } + em.getTransaction().commit(); + } - @Test - public void testEntitiesOrderLimitByQueryRev1() { - List res_0_to_1 = getAuditReader().createQuery() - .forEntitiesAtRevision(IntTestEntity.class, 1) - .addOrder(AuditEntity.property("number").desc()) - .setFirstResult(0) - .setMaxResults(2) - .getResultList(); + @Test + public void testEntitiesOrderLimitByQueryRev1() { + List res_0_to_1 = getAuditReader().createQuery() + .forEntitiesAtRevision( IntTestEntity.class, 1 ) + .addOrder( AuditEntity.property( "number" ).desc() ) + .setFirstResult( 0 ) + .setMaxResults( 2 ) + .getResultList(); - List res_2_to_3 = getAuditReader().createQuery() - .forEntitiesAtRevision(IntTestEntity.class, 1) - .addOrder(AuditEntity.property("number").desc()) - .setFirstResult(2) - .setMaxResults(2) - .getResultList(); + List res_2_to_3 = getAuditReader().createQuery() + .forEntitiesAtRevision( IntTestEntity.class, 1 ) + .addOrder( AuditEntity.property( "number" ).desc() ) + .setFirstResult( 2 ) + .setMaxResults( 2 ) + .getResultList(); - List res_empty = getAuditReader().createQuery() - .forEntitiesAtRevision(IntTestEntity.class, 1) - .addOrder(AuditEntity.property("number").desc()) - .setFirstResult(4) - .setMaxResults(2) - .getResultList(); + List res_empty = getAuditReader().createQuery() + .forEntitiesAtRevision( IntTestEntity.class, 1 ) + .addOrder( AuditEntity.property( "number" ).desc() ) + .setFirstResult( 4 ) + .setMaxResults( 2 ) + .getResultList(); - assert Arrays.asList(new IntTestEntity(12, id1), new IntTestEntity(8, id3)).equals(res_0_to_1); - assert Arrays.asList(new IntTestEntity(5, id2), new IntTestEntity(1, id4)).equals(res_2_to_3); - assert Arrays.asList().equals(res_empty); - } + assert Arrays.asList( new IntTestEntity( 12, id1 ), new IntTestEntity( 8, id3 ) ).equals( res_0_to_1 ); + assert Arrays.asList( new IntTestEntity( 5, id2 ), new IntTestEntity( 1, id4 ) ).equals( res_2_to_3 ); + assert Arrays.asList().equals( res_empty ); + } - @Test - public void testEntitiesOrderLimitByQueryRev2() { - List res_0_to_1 = getAuditReader().createQuery() - .forEntitiesAtRevision(IntTestEntity.class, 2) - .addOrder(AuditEntity.property("number").desc()) - .setFirstResult(0) - .setMaxResults(2) - .getResultList(); + @Test + public void testEntitiesOrderLimitByQueryRev2() { + List res_0_to_1 = getAuditReader().createQuery() + .forEntitiesAtRevision( IntTestEntity.class, 2 ) + .addOrder( AuditEntity.property( "number" ).desc() ) + .setFirstResult( 0 ) + .setMaxResults( 2 ) + .getResultList(); - List res_2_to_3 = getAuditReader().createQuery() - .forEntitiesAtRevision(IntTestEntity.class, 2) - .addOrder(AuditEntity.property("number").desc()) - .setFirstResult(2) - .setMaxResults(2) - .getResultList(); + List res_2_to_3 = getAuditReader().createQuery() + .forEntitiesAtRevision( IntTestEntity.class, 2 ) + .addOrder( AuditEntity.property( "number" ).desc() ) + .setFirstResult( 2 ) + .setMaxResults( 2 ) + .getResultList(); - List res_4 = getAuditReader().createQuery() - .forEntitiesAtRevision(IntTestEntity.class, 2) - .addOrder(AuditEntity.property("number").desc()) - .setFirstResult(4) - .setMaxResults(2) - .getResultList(); + List res_4 = getAuditReader().createQuery() + .forEntitiesAtRevision( IntTestEntity.class, 2 ) + .addOrder( AuditEntity.property( "number" ).desc() ) + .setFirstResult( 4 ) + .setMaxResults( 2 ) + .getResultList(); - assert Arrays.asList(new IntTestEntity(15, id4), new IntTestEntity(8, id3)).equals(res_0_to_1); - assert Arrays.asList(new IntTestEntity(5, id2), new IntTestEntity(3, id5)).equals(res_2_to_3); - assert Arrays.asList(new IntTestEntity(0, id1)).equals(res_4); - } + assert Arrays.asList( new IntTestEntity( 15, id4 ), new IntTestEntity( 8, id3 ) ).equals( res_0_to_1 ); + assert Arrays.asList( new IntTestEntity( 5, id2 ), new IntTestEntity( 3, id5 ) ).equals( res_2_to_3 ); + assert Arrays.asList( new IntTestEntity( 0, id1 ) ).equals( res_4 ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/RevisionConstraintQuery.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/RevisionConstraintQuery.java index e8b361ea3b..0b4bef14d1 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/RevisionConstraintQuery.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/RevisionConstraintQuery.java @@ -23,13 +23,10 @@ */ package org.hibernate.envers.test.integration.query; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.HashSet; import java.util.List; -import javax.persistence.EntityManager; - -import org.junit.Assert; -import org.junit.Test; import org.hibernate.envers.RevisionType; import org.hibernate.envers.query.AuditEntity; @@ -38,182 +35,185 @@ import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrIntTestEntity; import org.hibernate.envers.test.tools.TestTools; +import org.junit.Assert; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ @SuppressWarnings({"unchecked"}) public class RevisionConstraintQuery extends BaseEnversJPAFunctionalTestCase { - private Integer id1; + private Integer id1; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { StrIntTestEntity.class }; - } + return new Class[] {StrIntTestEntity.class}; + } - @Test - @Priority(10) - public void initData() { - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); + @Test + @Priority(10) + public void initData() { + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); - StrIntTestEntity site1 = new StrIntTestEntity("a", 10); - StrIntTestEntity site2 = new StrIntTestEntity("b", 15); + StrIntTestEntity site1 = new StrIntTestEntity( "a", 10 ); + StrIntTestEntity site2 = new StrIntTestEntity( "b", 15 ); - em.persist(site1); - em.persist(site2); + em.persist( site1 ); + em.persist( site2 ); - id1 = site1.getId(); - Integer id2 = site2.getId(); + id1 = site1.getId(); + Integer id2 = site2.getId(); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); + // Revision 2 + em.getTransaction().begin(); - site1 = em.find(StrIntTestEntity.class, id1); - site2 = em.find(StrIntTestEntity.class, id2); + site1 = em.find( StrIntTestEntity.class, id1 ); + site2 = em.find( StrIntTestEntity.class, id2 ); - site1.setStr1("d"); - site2.setNumber(20); + site1.setStr1( "d" ); + site2.setNumber( 20 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 - em.getTransaction().begin(); + // Revision 3 + em.getTransaction().begin(); - site1 = em.find(StrIntTestEntity.class, id1); - site2 = em.find(StrIntTestEntity.class, id2); + site1 = em.find( StrIntTestEntity.class, id1 ); + site2 = em.find( StrIntTestEntity.class, id2 ); - site1.setNumber(1); - site2.setStr1("z"); + site1.setNumber( 1 ); + site2.setStr1( "z" ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 4 - em.getTransaction().begin(); + // Revision 4 + em.getTransaction().begin(); - site1 = em.find(StrIntTestEntity.class, id1); - site2 = em.find(StrIntTestEntity.class, id2); + site1 = em.find( StrIntTestEntity.class, id1 ); + site2 = em.find( StrIntTestEntity.class, id2 ); - site1.setNumber(5); - site2.setStr1("a"); + site1.setNumber( 5 ); + site2.setStr1( "a" ); - em.getTransaction().commit(); - } - - @Test - public void testRevisionsLtQuery() { - List result = getAuditReader().createQuery() - .forRevisionsOfEntity(StrIntTestEntity.class, false, true) - .addProjection(AuditEntity.revisionNumber().distinct()) - .add(AuditEntity.revisionNumber().lt(3)) - .getResultList(); + em.getTransaction().commit(); + } - Assert.assertEquals(Arrays.asList(1, 2), result); - } + @Test + public void testRevisionsLtQuery() { + List result = getAuditReader().createQuery() + .forRevisionsOfEntity( StrIntTestEntity.class, false, true ) + .addProjection( AuditEntity.revisionNumber().distinct() ) + .add( AuditEntity.revisionNumber().lt( 3 ) ) + .getResultList(); - @Test - public void testRevisionsGeQuery() { - List result = getAuditReader().createQuery() - .forRevisionsOfEntity(StrIntTestEntity.class, false, true) - .addProjection(AuditEntity.revisionNumber().distinct()) - .add(AuditEntity.revisionNumber().ge(2)) - .getResultList(); + Assert.assertEquals( Arrays.asList( 1, 2 ), result ); + } - Assert.assertEquals(TestTools.makeSet(2, 3, 4), new HashSet(result)); - } + @Test + public void testRevisionsGeQuery() { + List result = getAuditReader().createQuery() + .forRevisionsOfEntity( StrIntTestEntity.class, false, true ) + .addProjection( AuditEntity.revisionNumber().distinct() ) + .add( AuditEntity.revisionNumber().ge( 2 ) ) + .getResultList(); - @Test - public void testRevisionsLeWithPropertyQuery() { - List result = getAuditReader().createQuery() - .forRevisionsOfEntity(StrIntTestEntity.class, false, true) - .addProjection(AuditEntity.revisionNumber()) - .add(AuditEntity.revisionNumber().le(3)) - .add(AuditEntity.property("str1").eq("a")) - .getResultList(); + Assert.assertEquals( TestTools.makeSet( 2, 3, 4 ), new HashSet( result ) ); + } - Assert.assertEquals(Arrays.asList(1), result); - } + @Test + public void testRevisionsLeWithPropertyQuery() { + List result = getAuditReader().createQuery() + .forRevisionsOfEntity( StrIntTestEntity.class, false, true ) + .addProjection( AuditEntity.revisionNumber() ) + .add( AuditEntity.revisionNumber().le( 3 ) ) + .add( AuditEntity.property( "str1" ).eq( "a" ) ) + .getResultList(); - @Test - public void testRevisionsGtWithPropertyQuery() { - List result = getAuditReader().createQuery() - .forRevisionsOfEntity(StrIntTestEntity.class, false, true) - .addProjection(AuditEntity.revisionNumber()) - .add(AuditEntity.revisionNumber().gt(1)) - .add(AuditEntity.property("number").lt(10)) - .getResultList(); + Assert.assertEquals( Arrays.asList( 1 ), result ); + } - Assert.assertEquals(Arrays.asList(3, 4), result); - } + @Test + public void testRevisionsGtWithPropertyQuery() { + List result = getAuditReader().createQuery() + .forRevisionsOfEntity( StrIntTestEntity.class, false, true ) + .addProjection( AuditEntity.revisionNumber() ) + .add( AuditEntity.revisionNumber().gt( 1 ) ) + .add( AuditEntity.property( "number" ).lt( 10 ) ) + .getResultList(); - @Test - public void testRevisionProjectionQuery() { - Object[] result = (Object[]) getAuditReader().createQuery() - .forRevisionsOfEntity(StrIntTestEntity.class, false, true) - .addProjection(AuditEntity.revisionNumber().max()) - .addProjection(AuditEntity.revisionNumber().count()) - .addProjection(AuditEntity.revisionNumber().countDistinct()) - .addProjection(AuditEntity.revisionNumber().min()) - .add(AuditEntity.id().eq(id1)) - .getSingleResult(); + Assert.assertEquals( Arrays.asList( 3, 4 ), result ); + } - Assert.assertEquals(Integer.valueOf(4), result[0] ); - Assert.assertEquals(Long.valueOf(4), result[1] ); - Assert.assertEquals(Long.valueOf(4), result[2]); - Assert.assertEquals(Integer.valueOf(1), result[3] ); - } + @Test + public void testRevisionProjectionQuery() { + Object[] result = (Object[]) getAuditReader().createQuery() + .forRevisionsOfEntity( StrIntTestEntity.class, false, true ) + .addProjection( AuditEntity.revisionNumber().max() ) + .addProjection( AuditEntity.revisionNumber().count() ) + .addProjection( AuditEntity.revisionNumber().countDistinct() ) + .addProjection( AuditEntity.revisionNumber().min() ) + .add( AuditEntity.id().eq( id1 ) ) + .getSingleResult(); - @Test - public void testRevisionOrderQuery() { - List result = getAuditReader().createQuery() - .forRevisionsOfEntity(StrIntTestEntity.class, false, true) - .addProjection(AuditEntity.revisionNumber()) - .add(AuditEntity.id().eq(id1)) - .addOrder(AuditEntity.revisionNumber().desc()) - .getResultList(); + Assert.assertEquals( Integer.valueOf( 4 ), result[0] ); + Assert.assertEquals( Long.valueOf( 4 ), result[1] ); + Assert.assertEquals( Long.valueOf( 4 ), result[2] ); + Assert.assertEquals( Integer.valueOf( 1 ), result[3] ); + } - Assert.assertEquals(Arrays.asList(4, 3, 2, 1), result); - } + @Test + public void testRevisionOrderQuery() { + List result = getAuditReader().createQuery() + .forRevisionsOfEntity( StrIntTestEntity.class, false, true ) + .addProjection( AuditEntity.revisionNumber() ) + .add( AuditEntity.id().eq( id1 ) ) + .addOrder( AuditEntity.revisionNumber().desc() ) + .getResultList(); - @Test - public void testRevisionCountQuery() { - // The query shouldn't be ordered as always, otherwise - we get an exception. - Object result = getAuditReader().createQuery() - .forRevisionsOfEntity(StrIntTestEntity.class, false, true) - .addProjection(AuditEntity.revisionNumber().count()) - .add(AuditEntity.id().eq(id1)) - .getSingleResult(); + Assert.assertEquals( Arrays.asList( 4, 3, 2, 1 ), result ); + } - Assert.assertEquals(Long.valueOf(4), result ); - } + @Test + public void testRevisionCountQuery() { + // The query shouldn't be ordered as always, otherwise - we get an exception. + Object result = getAuditReader().createQuery() + .forRevisionsOfEntity( StrIntTestEntity.class, false, true ) + .addProjection( AuditEntity.revisionNumber().count() ) + .add( AuditEntity.id().eq( id1 ) ) + .getSingleResult(); - @Test - public void testRevisionTypeEqQuery() { - // The query shouldn't be ordered as always, otherwise - we get an exception. - List results = getAuditReader().createQuery() - .forRevisionsOfEntity(StrIntTestEntity.class, true, true) - .add(AuditEntity.id().eq(id1)) - .add(AuditEntity.revisionType().eq(RevisionType.MOD)) - .getResultList(); - - Assert.assertEquals(3, results.size()); - Assert.assertEquals(new StrIntTestEntity("d", 10, id1), results.get(0)); - Assert.assertEquals(new StrIntTestEntity("d", 1, id1), results.get(1)); - Assert.assertEquals(new StrIntTestEntity("d", 5, id1), results.get(2)); - } + Assert.assertEquals( Long.valueOf( 4 ), result ); + } - @Test - public void testRevisionTypeNeQuery() { - // The query shouldn't be ordered as always, otherwise - we get an exception. - List results = getAuditReader().createQuery() - .forRevisionsOfEntity(StrIntTestEntity.class, true, true) - .add(AuditEntity.id().eq(id1)) - .add(AuditEntity.revisionType().ne(RevisionType.MOD)) - .getResultList(); + @Test + public void testRevisionTypeEqQuery() { + // The query shouldn't be ordered as always, otherwise - we get an exception. + List results = getAuditReader().createQuery() + .forRevisionsOfEntity( StrIntTestEntity.class, true, true ) + .add( AuditEntity.id().eq( id1 ) ) + .add( AuditEntity.revisionType().eq( RevisionType.MOD ) ) + .getResultList(); - Assert.assertEquals(1, results.size()); - Assert.assertEquals(new StrIntTestEntity("a", 10, id1), results.get(0)); - } + Assert.assertEquals( 3, results.size() ); + Assert.assertEquals( new StrIntTestEntity( "d", 10, id1 ), results.get( 0 ) ); + Assert.assertEquals( new StrIntTestEntity( "d", 1, id1 ), results.get( 1 ) ); + Assert.assertEquals( new StrIntTestEntity( "d", 5, id1 ), results.get( 2 ) ); + } + + @Test + public void testRevisionTypeNeQuery() { + // The query shouldn't be ordered as always, otherwise - we get an exception. + List results = getAuditReader().createQuery() + .forRevisionsOfEntity( StrIntTestEntity.class, true, true ) + .add( AuditEntity.id().eq( id1 ) ) + .add( AuditEntity.revisionType().ne( RevisionType.MOD ) ) + .getResultList(); + + Assert.assertEquals( 1, results.size() ); + Assert.assertEquals( new StrIntTestEntity( "a", 10, id1 ), results.get( 0 ) ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/SimpleQuery.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/SimpleQuery.java index f74e9667a8..88237e2a25 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/SimpleQuery.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/SimpleQuery.java @@ -23,13 +23,10 @@ */ package org.hibernate.envers.test.integration.query; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.HashSet; import java.util.List; -import javax.persistence.EntityManager; - -import org.junit.Assert; -import org.junit.Test; import org.hibernate.envers.RevisionType; import org.hibernate.envers.enhanced.SequenceIdRevisionEntity; @@ -38,6 +35,10 @@ import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrIntTestEntity; import org.hibernate.envers.test.tools.TestTools; + +import org.junit.Assert; +import org.junit.Test; + import org.hibernate.testing.TestForIssue; /** @@ -46,301 +47,342 @@ import org.hibernate.testing.TestForIssue; */ @SuppressWarnings({"unchecked"}) public class SimpleQuery extends BaseEnversJPAFunctionalTestCase { - private Integer id1; - private Integer id2; - private Integer id3; + private Integer id1; + private Integer id2; + private Integer id3; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { StrIntTestEntity.class }; - } + return new Class[] {StrIntTestEntity.class}; + } - @Test - @Priority(10) - public void initData() { - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); + @Test + @Priority(10) + public void initData() { + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); - StrIntTestEntity site1 = new StrIntTestEntity("a", 10); - StrIntTestEntity site2 = new StrIntTestEntity("a", 10); - StrIntTestEntity site3 = new StrIntTestEntity("b", 5); + StrIntTestEntity site1 = new StrIntTestEntity( "a", 10 ); + StrIntTestEntity site2 = new StrIntTestEntity( "a", 10 ); + StrIntTestEntity site3 = new StrIntTestEntity( "b", 5 ); - em.persist(site1); - em.persist(site2); - em.persist(site3); + em.persist( site1 ); + em.persist( site2 ); + em.persist( site3 ); - id1 = site1.getId(); - id2 = site2.getId(); - id3 = site3.getId(); + id1 = site1.getId(); + id2 = site2.getId(); + id3 = site3.getId(); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); + // Revision 2 + em.getTransaction().begin(); - site1 = em.find(StrIntTestEntity.class, id1); - site2 = em.find(StrIntTestEntity.class, id2); + site1 = em.find( StrIntTestEntity.class, id1 ); + site2 = em.find( StrIntTestEntity.class, id2 ); - site1.setStr1("c"); - site2.setNumber(20); + site1.setStr1( "c" ); + site2.setNumber( 20 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 - em.getTransaction().begin(); + // Revision 3 + em.getTransaction().begin(); - site3 = em.find(StrIntTestEntity.class, id3); + site3 = em.find( StrIntTestEntity.class, id3 ); - site3.setStr1("a"); + site3.setStr1( "a" ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 4 - em.getTransaction().begin(); + // Revision 4 + em.getTransaction().begin(); - site1 = em.find(StrIntTestEntity.class, id1); + site1 = em.find( StrIntTestEntity.class, id1 ); - em.remove(site1); + em.remove( site1 ); - em.getTransaction().commit(); - } + em.getTransaction().commit(); + } - @Test - public void testEntitiesIdQuery() { - StrIntTestEntity ver2 = (StrIntTestEntity) getAuditReader().createQuery() - .forEntitiesAtRevision(StrIntTestEntity.class, 2) - .add(AuditEntity.id().eq(id2)) - .getSingleResult(); + @Test + public void testEntitiesIdQuery() { + StrIntTestEntity ver2 = (StrIntTestEntity) getAuditReader().createQuery() + .forEntitiesAtRevision( StrIntTestEntity.class, 2 ) + .add( AuditEntity.id().eq( id2 ) ) + .getSingleResult(); - assert ver2.equals(new StrIntTestEntity("a", 20, id2)); - } + assert ver2.equals( new StrIntTestEntity( "a", 20, id2 ) ); + } - @Test - public void testEntitiesPropertyEqualsQuery() { - List ver1 = getAuditReader().createQuery() - .forEntitiesAtRevision(StrIntTestEntity.class, 1) - .add(AuditEntity.property("str1").eq("a")) - .getResultList(); + @Test + public void testEntitiesPropertyEqualsQuery() { + List ver1 = getAuditReader().createQuery() + .forEntitiesAtRevision( StrIntTestEntity.class, 1 ) + .add( AuditEntity.property( "str1" ).eq( "a" ) ) + .getResultList(); - List ver2 = getAuditReader().createQuery() - .forEntitiesAtRevision(StrIntTestEntity.class, 2) - .add(AuditEntity.property("str1").eq("a")) - .getResultList(); + List ver2 = getAuditReader().createQuery() + .forEntitiesAtRevision( StrIntTestEntity.class, 2 ) + .add( AuditEntity.property( "str1" ).eq( "a" ) ) + .getResultList(); - List ver3 = getAuditReader().createQuery() - .forEntitiesAtRevision(StrIntTestEntity.class, 3) - .add(AuditEntity.property("str1").eq("a")) - .getResultList(); + List ver3 = getAuditReader().createQuery() + .forEntitiesAtRevision( StrIntTestEntity.class, 3 ) + .add( AuditEntity.property( "str1" ).eq( "a" ) ) + .getResultList(); - assert new HashSet(ver1).equals(TestTools.makeSet(new StrIntTestEntity("a", 10, id1), - new StrIntTestEntity("a", 10, id2))); - assert new HashSet(ver2).equals(TestTools.makeSet(new StrIntTestEntity("a", 20, id2))); - assert new HashSet(ver3).equals(TestTools.makeSet(new StrIntTestEntity("a", 20, id2), - new StrIntTestEntity("a", 5, id3))); - } + assert new HashSet( ver1 ).equals( + TestTools.makeSet( + new StrIntTestEntity( "a", 10, id1 ), + new StrIntTestEntity( "a", 10, id2 ) + ) + ); + assert new HashSet( ver2 ).equals( TestTools.makeSet( new StrIntTestEntity( "a", 20, id2 ) ) ); + assert new HashSet( ver3 ).equals( + TestTools.makeSet( + new StrIntTestEntity( "a", 20, id2 ), + new StrIntTestEntity( "a", 5, id3 ) + ) + ); + } - @Test - public void testEntitiesPropertyLeQuery() { - List ver1 = getAuditReader().createQuery() - .forEntitiesAtRevision(StrIntTestEntity.class, 1) - .add(AuditEntity.property("number").le(10)) - .getResultList(); + @Test + public void testEntitiesPropertyLeQuery() { + List ver1 = getAuditReader().createQuery() + .forEntitiesAtRevision( StrIntTestEntity.class, 1 ) + .add( AuditEntity.property( "number" ).le( 10 ) ) + .getResultList(); - List ver2 = getAuditReader().createQuery() - .forEntitiesAtRevision(StrIntTestEntity.class, 2) - .add(AuditEntity.property("number").le(10)) - .getResultList(); + List ver2 = getAuditReader().createQuery() + .forEntitiesAtRevision( StrIntTestEntity.class, 2 ) + .add( AuditEntity.property( "number" ).le( 10 ) ) + .getResultList(); - List ver3 = getAuditReader().createQuery() - .forEntitiesAtRevision(StrIntTestEntity.class, 3) - .add(AuditEntity.property("number").le(10)) - .getResultList(); + List ver3 = getAuditReader().createQuery() + .forEntitiesAtRevision( StrIntTestEntity.class, 3 ) + .add( AuditEntity.property( "number" ).le( 10 ) ) + .getResultList(); - assert new HashSet(ver1).equals(TestTools.makeSet(new StrIntTestEntity("a", 10, id1), - new StrIntTestEntity("a", 10, id2), new StrIntTestEntity("b", 5, id3))); - assert new HashSet(ver2).equals(TestTools.makeSet(new StrIntTestEntity("c", 10, id1), - new StrIntTestEntity("b", 5, id3))); - assert new HashSet(ver3).equals(TestTools.makeSet(new StrIntTestEntity("c", 10, id1), - new StrIntTestEntity("a", 5, id3))); - } + assert new HashSet( ver1 ).equals( + TestTools.makeSet( + new StrIntTestEntity( "a", 10, id1 ), + new StrIntTestEntity( "a", 10, id2 ), new StrIntTestEntity( "b", 5, id3 ) + ) + ); + assert new HashSet( ver2 ).equals( + TestTools.makeSet( + new StrIntTestEntity( "c", 10, id1 ), + new StrIntTestEntity( "b", 5, id3 ) + ) + ); + assert new HashSet( ver3 ).equals( + TestTools.makeSet( + new StrIntTestEntity( "c", 10, id1 ), + new StrIntTestEntity( "a", 5, id3 ) + ) + ); + } - @Test - public void testRevisionsPropertyEqQuery() { - List revs_id1 = getAuditReader().createQuery() - .forRevisionsOfEntity(StrIntTestEntity.class, false, true) - .addProjection(AuditEntity.revisionNumber()) - .add(AuditEntity.property("str1").le("a")) - .add(AuditEntity.id().eq(id1)) - .getResultList(); + @Test + public void testRevisionsPropertyEqQuery() { + List revs_id1 = getAuditReader().createQuery() + .forRevisionsOfEntity( StrIntTestEntity.class, false, true ) + .addProjection( AuditEntity.revisionNumber() ) + .add( AuditEntity.property( "str1" ).le( "a" ) ) + .add( AuditEntity.id().eq( id1 ) ) + .getResultList(); - List revs_id2 = getAuditReader().createQuery() - .forRevisionsOfEntity(StrIntTestEntity.class, false, true) - .addProjection(AuditEntity.revisionNumber()) - .add(AuditEntity.property("str1").le("a")) - .add(AuditEntity.id().eq(id2)) - .getResultList(); + List revs_id2 = getAuditReader().createQuery() + .forRevisionsOfEntity( StrIntTestEntity.class, false, true ) + .addProjection( AuditEntity.revisionNumber() ) + .add( AuditEntity.property( "str1" ).le( "a" ) ) + .add( AuditEntity.id().eq( id2 ) ) + .getResultList(); - List revs_id3 = getAuditReader().createQuery() - .forRevisionsOfEntity(StrIntTestEntity.class, false, true) - .addProjection(AuditEntity.revisionNumber()) - .add(AuditEntity.property("str1").le("a")) - .add(AuditEntity.id().eq(id3)) - .getResultList(); + List revs_id3 = getAuditReader().createQuery() + .forRevisionsOfEntity( StrIntTestEntity.class, false, true ) + .addProjection( AuditEntity.revisionNumber() ) + .add( AuditEntity.property( "str1" ).le( "a" ) ) + .add( AuditEntity.id().eq( id3 ) ) + .getResultList(); - assert Arrays.asList(1).equals(revs_id1); - assert Arrays.asList(1, 2).equals(revs_id2); - assert Arrays.asList(3).equals(revs_id3); - } + assert Arrays.asList( 1 ).equals( revs_id1 ); + assert Arrays.asList( 1, 2 ).equals( revs_id2 ); + assert Arrays.asList( 3 ).equals( revs_id3 ); + } - @Test - public void testSelectEntitiesQuery() { - List result = getAuditReader().createQuery() - .forRevisionsOfEntity(StrIntTestEntity.class, true, false) - .add(AuditEntity.id().eq(id1)) - .getResultList(); + @Test + public void testSelectEntitiesQuery() { + List result = getAuditReader().createQuery() + .forRevisionsOfEntity( StrIntTestEntity.class, true, false ) + .add( AuditEntity.id().eq( id1 ) ) + .getResultList(); - assert result.size() == 2; + assert result.size() == 2; - assert result.get(0).equals(new StrIntTestEntity("a", 10, id1)); - assert result.get(1).equals(new StrIntTestEntity("c", 10, id1)); - } + assert result.get( 0 ).equals( new StrIntTestEntity( "a", 10, id1 ) ); + assert result.get( 1 ).equals( new StrIntTestEntity( "c", 10, id1 ) ); + } - @Test - public void testSelectEntitiesAndRevisionsQuery() { - List result = getAuditReader().createQuery() - .forRevisionsOfEntity(StrIntTestEntity.class, false, true) - .add(AuditEntity.id().eq(id1)) - .getResultList(); + @Test + public void testSelectEntitiesAndRevisionsQuery() { + List result = getAuditReader().createQuery() + .forRevisionsOfEntity( StrIntTestEntity.class, false, true ) + .add( AuditEntity.id().eq( id1 ) ) + .getResultList(); - assert result.size() == 3; + assert result.size() == 3; - assert ((Object []) result.get(0))[0].equals(new StrIntTestEntity("a", 10, id1)); - assert ((Object []) result.get(1))[0].equals(new StrIntTestEntity("c", 10, id1)); - assert ((Object []) result.get(2))[0].equals(new StrIntTestEntity(null, null, id1)); + assert ((Object[]) result.get( 0 ))[0].equals( new StrIntTestEntity( "a", 10, id1 ) ); + assert ((Object[]) result.get( 1 ))[0].equals( new StrIntTestEntity( "c", 10, id1 ) ); + assert ((Object[]) result.get( 2 ))[0].equals( new StrIntTestEntity( null, null, id1 ) ); - assert ((SequenceIdRevisionEntity) ((Object []) result.get(0))[1]).getId() == 1; - assert ((SequenceIdRevisionEntity) ((Object []) result.get(1))[1]).getId() == 2; - assert ((SequenceIdRevisionEntity) ((Object []) result.get(2))[1]).getId() == 4; + assert ((SequenceIdRevisionEntity) ((Object[]) result.get( 0 ))[1]).getId() == 1; + assert ((SequenceIdRevisionEntity) ((Object[]) result.get( 1 ))[1]).getId() == 2; + assert ((SequenceIdRevisionEntity) ((Object[]) result.get( 2 ))[1]).getId() == 4; - assert ((Object []) result.get(0))[2].equals(RevisionType.ADD); - assert ((Object []) result.get(1))[2].equals(RevisionType.MOD); - assert ((Object []) result.get(2))[2].equals(RevisionType.DEL); - } + assert ((Object[]) result.get( 0 ))[2].equals( RevisionType.ADD ); + assert ((Object[]) result.get( 1 ))[2].equals( RevisionType.MOD ); + assert ((Object[]) result.get( 2 ))[2].equals( RevisionType.DEL ); + } - @Test - public void testSelectRevisionTypeQuery() { - List result = getAuditReader().createQuery() - .forRevisionsOfEntity(StrIntTestEntity.class, false, true) - .addProjection(AuditEntity.revisionType()) - .add(AuditEntity.id().eq(id1)) - .getResultList(); + @Test + public void testSelectRevisionTypeQuery() { + List result = getAuditReader().createQuery() + .forRevisionsOfEntity( StrIntTestEntity.class, false, true ) + .addProjection( AuditEntity.revisionType() ) + .add( AuditEntity.id().eq( id1 ) ) + .getResultList(); - assert result.size() == 3; + assert result.size() == 3; - assert result.get(0).equals(RevisionType.ADD); - assert result.get(1).equals(RevisionType.MOD); - assert result.get(2).equals(RevisionType.DEL); - } + assert result.get( 0 ).equals( RevisionType.ADD ); + assert result.get( 1 ).equals( RevisionType.MOD ); + assert result.get( 2 ).equals( RevisionType.DEL ); + } - @Test - public void testEmptyRevisionOfEntityQuery() { - List result = getAuditReader().createQuery() - .forRevisionsOfEntity(StrIntTestEntity.class, false, true) - .getResultList(); + @Test + public void testEmptyRevisionOfEntityQuery() { + List result = getAuditReader().createQuery() + .forRevisionsOfEntity( StrIntTestEntity.class, false, true ) + .getResultList(); - assert result.size() == 7; - } + assert result.size() == 7; + } - @Test - public void testEmptyConjunctionRevisionOfEntityQuery() { - List result = getAuditReader().createQuery() - .forRevisionsOfEntity(StrIntTestEntity.class, false, true) - .add(AuditEntity.conjunction()) - .getResultList(); + @Test + public void testEmptyConjunctionRevisionOfEntityQuery() { + List result = getAuditReader().createQuery() + .forRevisionsOfEntity( StrIntTestEntity.class, false, true ) + .add( AuditEntity.conjunction() ) + .getResultList(); - assert result.size() == 7; - } + assert result.size() == 7; + } - @Test - public void testEmptyDisjunctionRevisionOfEntityQuery() { - List result = getAuditReader().createQuery() - .forRevisionsOfEntity(StrIntTestEntity.class, false, true) - .add(AuditEntity.disjunction()) - .getResultList(); + @Test + public void testEmptyDisjunctionRevisionOfEntityQuery() { + List result = getAuditReader().createQuery() + .forRevisionsOfEntity( StrIntTestEntity.class, false, true ) + .add( AuditEntity.disjunction() ) + .getResultList(); - assert result.size() == 0; - } + assert result.size() == 0; + } - @Test - public void testEntitiesAddedAtRevision() { - StrIntTestEntity site1 = new StrIntTestEntity("a", 10, id1); - StrIntTestEntity site2 = new StrIntTestEntity("a", 10, id2); - StrIntTestEntity site3 = new StrIntTestEntity("b", 5, id3); + @Test + public void testEntitiesAddedAtRevision() { + StrIntTestEntity site1 = new StrIntTestEntity( "a", 10, id1 ); + StrIntTestEntity site2 = new StrIntTestEntity( "a", 10, id2 ); + StrIntTestEntity site3 = new StrIntTestEntity( "b", 5, id3 ); - List result = getAuditReader().createQuery().forEntitiesModifiedAtRevision(StrIntTestEntity.class, StrIntTestEntity.class.getName(), 1).getResultList(); - RevisionType revisionType = (RevisionType) getAuditReader().createQuery().forEntitiesModifiedAtRevision(StrIntTestEntity.class, 1) - .addProjection(AuditEntity.revisionType()).add(AuditEntity.id().eq(id1)) - .getSingleResult(); + List result = getAuditReader().createQuery().forEntitiesModifiedAtRevision( + StrIntTestEntity.class, + StrIntTestEntity.class.getName(), + 1 + ).getResultList(); + RevisionType revisionType = (RevisionType) getAuditReader().createQuery().forEntitiesModifiedAtRevision( + StrIntTestEntity.class, + 1 + ) + .addProjection( AuditEntity.revisionType() ).add( AuditEntity.id().eq( id1 ) ) + .getSingleResult(); - Assert.assertTrue(TestTools.checkList(result, site1, site2, site3)); - Assert.assertEquals(revisionType, RevisionType.ADD); - } + Assert.assertTrue( TestTools.checkList( result, site1, site2, site3 ) ); + Assert.assertEquals( revisionType, RevisionType.ADD ); + } - @Test - public void testEntitiesChangedAtRevision() { - StrIntTestEntity site1 = new StrIntTestEntity("c", 10, id1); - StrIntTestEntity site2 = new StrIntTestEntity("a", 20, id2); + @Test + public void testEntitiesChangedAtRevision() { + StrIntTestEntity site1 = new StrIntTestEntity( "c", 10, id1 ); + StrIntTestEntity site2 = new StrIntTestEntity( "a", 20, id2 ); - List result = getAuditReader().createQuery().forEntitiesModifiedAtRevision(StrIntTestEntity.class, 2).getResultList(); - RevisionType revisionType = (RevisionType) getAuditReader().createQuery().forEntitiesModifiedAtRevision(StrIntTestEntity.class, 2) - .addProjection(AuditEntity.revisionType()).add(AuditEntity.id().eq(id1)) - .getSingleResult(); + List result = getAuditReader().createQuery() + .forEntitiesModifiedAtRevision( StrIntTestEntity.class, 2 ) + .getResultList(); + RevisionType revisionType = (RevisionType) getAuditReader().createQuery().forEntitiesModifiedAtRevision( + StrIntTestEntity.class, + 2 + ) + .addProjection( AuditEntity.revisionType() ).add( AuditEntity.id().eq( id1 ) ) + .getSingleResult(); - Assert.assertTrue(TestTools.checkList(result, site1, site2)); - Assert.assertEquals(revisionType, RevisionType.MOD); - } + Assert.assertTrue( TestTools.checkList( result, site1, site2 ) ); + Assert.assertEquals( revisionType, RevisionType.MOD ); + } - @Test - public void testEntitiesRemovedAtRevision() { - StrIntTestEntity site1 = new StrIntTestEntity(null, null, id1); + @Test + public void testEntitiesRemovedAtRevision() { + StrIntTestEntity site1 = new StrIntTestEntity( null, null, id1 ); - List result = getAuditReader().createQuery().forEntitiesModifiedAtRevision(StrIntTestEntity.class, 4).getResultList(); - RevisionType revisionType = (RevisionType) getAuditReader().createQuery().forEntitiesModifiedAtRevision(StrIntTestEntity.class, 4) - .addProjection(AuditEntity.revisionType()).add(AuditEntity.id().eq(id1)) - .getSingleResult(); - - Assert.assertTrue(TestTools.checkList(result, site1)); - Assert.assertEquals(revisionType, RevisionType.DEL); - } + List result = getAuditReader().createQuery() + .forEntitiesModifiedAtRevision( StrIntTestEntity.class, 4 ) + .getResultList(); + RevisionType revisionType = (RevisionType) getAuditReader().createQuery().forEntitiesModifiedAtRevision( + StrIntTestEntity.class, + 4 + ) + .addProjection( AuditEntity.revisionType() ).add( AuditEntity.id().eq( id1 ) ) + .getSingleResult(); - @Test - public void testEntityNotModifiedAtRevision() { - List result = getAuditReader().createQuery().forEntitiesModifiedAtRevision(StrIntTestEntity.class, 3) - .add(AuditEntity.id().eq(id1)).getResultList(); - Assert.assertTrue(result.isEmpty()); - } + Assert.assertTrue( TestTools.checkList( result, site1 ) ); + Assert.assertEquals( revisionType, RevisionType.DEL ); + } - @Test - public void testNoEntitiesModifiedAtRevision() { - List result = getAuditReader().createQuery().forEntitiesModifiedAtRevision(StrIntTestEntity.class, 5).getResultList(); - Assert.assertTrue(result.isEmpty()); - } + @Test + public void testEntityNotModifiedAtRevision() { + List result = getAuditReader().createQuery().forEntitiesModifiedAtRevision( StrIntTestEntity.class, 3 ) + .add( AuditEntity.id().eq( id1 ) ).getResultList(); + Assert.assertTrue( result.isEmpty() ); + } + + @Test + public void testNoEntitiesModifiedAtRevision() { + List result = getAuditReader().createQuery() + .forEntitiesModifiedAtRevision( StrIntTestEntity.class, 5 ) + .getResultList(); + Assert.assertTrue( result.isEmpty() ); + } @Test @TestForIssue(jiraKey = "HHH-7800") public void testBetweenInsideDisjunction() { List result = getAuditReader().createQuery() .forRevisionsOfEntity( StrIntTestEntity.class, true, true ) - .add( AuditEntity.disjunction() + .add( + AuditEntity.disjunction() .add( AuditEntity.property( "number" ).between( 0, 5 ) ) - .add( AuditEntity.property( "number" ).between( 20, 100 ) ) ) + .add( AuditEntity.property( "number" ).between( 20, 100 ) ) + ) .getResultList(); for ( Object o : result ) { StrIntTestEntity entity = (StrIntTestEntity) o; int number = entity.getNumber(); - Assert.assertTrue( ( number >= 0 && number <= 5 ) || ( number >= 20 && number <= 100 ) ); + Assert.assertTrue( (number >= 0 && number <= 5) || (number >= 20 && number <= 100) ); } } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/StoreDeletedData.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/StoreDeletedData.java index 9ba7e07231..5d5f0dac32 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/StoreDeletedData.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/StoreDeletedData.java @@ -23,13 +23,10 @@ */ package org.hibernate.envers.test.integration.query; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.List; import java.util.Map; -import javax.persistence.EntityManager; - -import junit.framework.Assert; -import org.junit.Test; import org.hibernate.envers.RevisionType; import org.hibernate.envers.configuration.EnversSettings; @@ -40,13 +37,18 @@ import org.hibernate.envers.query.criteria.AuditDisjunction; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrIntTestEntity; + +import org.junit.Test; +import junit.framework.Assert; + import org.hibernate.testing.TestForIssue; /** * A test which checks if the data of a deleted entity is stored when the setting is on. + * * @author Adam Warski (adam at warski dot org) */ -@SuppressWarnings({ "unchecked" }) +@SuppressWarnings({"unchecked"}) public class StoreDeletedData extends BaseEnversJPAFunctionalTestCase { private Integer id1; private Integer id2; @@ -54,7 +56,7 @@ public class StoreDeletedData extends BaseEnversJPAFunctionalTestCase { @Override protected Class[] getAnnotatedClasses() { - return new Class[] { StrIntTestEntity.class }; + return new Class[] {StrIntTestEntity.class}; } @Override @@ -107,8 +109,8 @@ public class StoreDeletedData extends BaseEnversJPAFunctionalTestCase { .getResultList(); Assert.assertEquals( 2, revs_id1.size() ); - Assert.assertEquals( new StrIntTestEntity( "a", 10, id1 ), ( (Object[]) revs_id1.get( 0 ) )[0] ); - Assert.assertEquals( new StrIntTestEntity( "a", 10, id1 ), ( (Object[]) revs_id1.get( 1 ) )[0] ); + Assert.assertEquals( new StrIntTestEntity( "a", 10, id1 ), ((Object[]) revs_id1.get( 0 ))[0] ); + Assert.assertEquals( new StrIntTestEntity( "a", 10, id1 ), ((Object[]) revs_id1.get( 1 ))[0] ); } @Test @@ -139,11 +141,11 @@ public class StoreDeletedData extends BaseEnversJPAFunctionalTestCase { Assert.assertEquals( new StrIntTestEntity( "b", 20, id2 ), result1[0] ); // Making sure that we have received an entity added at revision 3. - Assert.assertEquals( 3, ( (SequenceIdRevisionEntity) result1[1] ).getId() ); + Assert.assertEquals( 3, ((SequenceIdRevisionEntity) result1[1]).getId() ); Assert.assertEquals( RevisionType.ADD, result1[2] ); Assert.assertEquals( new StrIntTestEntity( "c", 30, id3 ), result2[0] ); // Making sure that we have received an entity added at revision 3. - Assert.assertEquals( 3, ( (SequenceIdRevisionEntity) result2[1] ).getId() ); + Assert.assertEquals( 3, ((SequenceIdRevisionEntity) result2[1]).getId() ); Assert.assertEquals( RevisionType.ADD, result2[2] ); } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/ids/EmbIdOneToManyQuery.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/ids/EmbIdOneToManyQuery.java index 56bb879d71..2e53bf689f 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/ids/EmbIdOneToManyQuery.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/ids/EmbIdOneToManyQuery.java @@ -23,12 +23,10 @@ */ package org.hibernate.envers.test.integration.query.ids; +import javax.persistence.EntityManager; import java.util.HashSet; import java.util.List; import java.util.Set; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.query.AuditEntity; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; @@ -38,180 +36,204 @@ import org.hibernate.envers.test.entities.onetomany.ids.SetRefEdEmbIdEntity; import org.hibernate.envers.test.entities.onetomany.ids.SetRefIngEmbIdEntity; import org.hibernate.envers.test.tools.TestTools; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ @SuppressWarnings({"unchecked"}) public class EmbIdOneToManyQuery extends BaseEnversJPAFunctionalTestCase { - private EmbId id1; - private EmbId id2; + private EmbId id1; + private EmbId id2; - private EmbId id3; - private EmbId id4; + private EmbId id3; + private EmbId id4; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { SetRefEdEmbIdEntity.class, SetRefIngEmbIdEntity.class }; - } + return new Class[] {SetRefEdEmbIdEntity.class, SetRefIngEmbIdEntity.class}; + } - @Test - @Priority(10) - public void initData() { - id1 = new EmbId(0, 1); - id2 = new EmbId(10, 11); - id3 = new EmbId(20, 21); - id4 = new EmbId(30, 31); + @Test + @Priority(10) + public void initData() { + id1 = new EmbId( 0, 1 ); + id2 = new EmbId( 10, 11 ); + id3 = new EmbId( 20, 21 ); + id4 = new EmbId( 30, 31 ); - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); - SetRefIngEmbIdEntity refIng1 = new SetRefIngEmbIdEntity(id1, "x", null); - SetRefIngEmbIdEntity refIng2 = new SetRefIngEmbIdEntity(id2, "y", null); + SetRefIngEmbIdEntity refIng1 = new SetRefIngEmbIdEntity( id1, "x", null ); + SetRefIngEmbIdEntity refIng2 = new SetRefIngEmbIdEntity( id2, "y", null ); - em.persist(refIng1); - em.persist(refIng2); + em.persist( refIng1 ); + em.persist( refIng2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); + // Revision 2 + em.getTransaction().begin(); - SetRefEdEmbIdEntity refEd3 = new SetRefEdEmbIdEntity(id3, "a"); - SetRefEdEmbIdEntity refEd4 = new SetRefEdEmbIdEntity(id4, "a"); + SetRefEdEmbIdEntity refEd3 = new SetRefEdEmbIdEntity( id3, "a" ); + SetRefEdEmbIdEntity refEd4 = new SetRefEdEmbIdEntity( id4, "a" ); - em.persist(refEd3); - em.persist(refEd4); + em.persist( refEd3 ); + em.persist( refEd4 ); - refIng1 = em.find(SetRefIngEmbIdEntity.class, id1); - refIng2 = em.find(SetRefIngEmbIdEntity.class, id2); + refIng1 = em.find( SetRefIngEmbIdEntity.class, id1 ); + refIng2 = em.find( SetRefIngEmbIdEntity.class, id2 ); - refIng1.setReference(refEd3); - refIng2.setReference(refEd4); + refIng1.setReference( refEd3 ); + refIng2.setReference( refEd4 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 - em.getTransaction().begin(); + // Revision 3 + em.getTransaction().begin(); - refEd3 = em.find(SetRefEdEmbIdEntity.class, id3); - refIng2 = em.find(SetRefIngEmbIdEntity.class, id2); - refIng2.setReference(refEd3); + refEd3 = em.find( SetRefEdEmbIdEntity.class, id3 ); + refIng2 = em.find( SetRefIngEmbIdEntity.class, id2 ); + refIng2.setReference( refEd3 ); - em.getTransaction().commit(); - } + em.getTransaction().commit(); + } - @Test - public void testEntitiesReferencedToId3() { - Set rev1_related = new HashSet(getAuditReader().createQuery() - .forEntitiesAtRevision(SetRefIngEmbIdEntity.class, 1) - .add(AuditEntity.relatedId("reference").eq(id3)) - .getResultList()); + @Test + public void testEntitiesReferencedToId3() { + Set rev1_related = new HashSet( + getAuditReader().createQuery() + .forEntitiesAtRevision( SetRefIngEmbIdEntity.class, 1 ) + .add( AuditEntity.relatedId( "reference" ).eq( id3 ) ) + .getResultList() + ); - Set rev1 = new HashSet(getAuditReader().createQuery() - .forEntitiesAtRevision(SetRefIngEmbIdEntity.class, 1) - .add(AuditEntity.property("reference").eq(new SetRefEdEmbIdEntity(id3, null))) - .getResultList()); + Set rev1 = new HashSet( + getAuditReader().createQuery() + .forEntitiesAtRevision( SetRefIngEmbIdEntity.class, 1 ) + .add( AuditEntity.property( "reference" ).eq( new SetRefEdEmbIdEntity( id3, null ) ) ) + .getResultList() + ); - Set rev2_related = new HashSet(getAuditReader().createQuery() - .forEntitiesAtRevision(SetRefIngEmbIdEntity.class, 2) - .add(AuditEntity.relatedId("reference").eq(id3)) - .getResultList()); + Set rev2_related = new HashSet( + getAuditReader().createQuery() + .forEntitiesAtRevision( SetRefIngEmbIdEntity.class, 2 ) + .add( AuditEntity.relatedId( "reference" ).eq( id3 ) ) + .getResultList() + ); - Set rev2 = new HashSet(getAuditReader().createQuery() - .forEntitiesAtRevision(SetRefIngEmbIdEntity.class, 2) - .add(AuditEntity.property("reference").eq(new SetRefEdEmbIdEntity(id3, null))) - .getResultList()); + Set rev2 = new HashSet( + getAuditReader().createQuery() + .forEntitiesAtRevision( SetRefIngEmbIdEntity.class, 2 ) + .add( AuditEntity.property( "reference" ).eq( new SetRefEdEmbIdEntity( id3, null ) ) ) + .getResultList() + ); - Set rev3_related = new HashSet(getAuditReader().createQuery() - .forEntitiesAtRevision(SetRefIngEmbIdEntity.class, 3) - .add(AuditEntity.relatedId("reference").eq(id3)) - .getResultList()); + Set rev3_related = new HashSet( + getAuditReader().createQuery() + .forEntitiesAtRevision( SetRefIngEmbIdEntity.class, 3 ) + .add( AuditEntity.relatedId( "reference" ).eq( id3 ) ) + .getResultList() + ); - Set rev3 = new HashSet(getAuditReader().createQuery() - .forEntitiesAtRevision(SetRefIngEmbIdEntity.class, 3) - .add(AuditEntity.property("reference").eq(new SetRefEdEmbIdEntity(id3, null))) - .getResultList()); + Set rev3 = new HashSet( + getAuditReader().createQuery() + .forEntitiesAtRevision( SetRefIngEmbIdEntity.class, 3 ) + .add( AuditEntity.property( "reference" ).eq( new SetRefEdEmbIdEntity( id3, null ) ) ) + .getResultList() + ); - assert rev1.equals(rev1_related); - assert rev2.equals(rev2_related); - assert rev3.equals(rev3_related); + assert rev1.equals( rev1_related ); + assert rev2.equals( rev2_related ); + assert rev3.equals( rev3_related ); - assert rev1.equals(TestTools.makeSet()); - assert rev2.equals(TestTools.makeSet(new SetRefIngEmbIdEntity(id1, "x", null))); - assert rev3.equals(TestTools.makeSet(new SetRefIngEmbIdEntity(id1, "x", null), - new SetRefIngEmbIdEntity(id2, "y", null))); - } + assert rev1.equals( TestTools.makeSet() ); + assert rev2.equals( TestTools.makeSet( new SetRefIngEmbIdEntity( id1, "x", null ) ) ); + assert rev3.equals( + TestTools.makeSet( + new SetRefIngEmbIdEntity( id1, "x", null ), + new SetRefIngEmbIdEntity( id2, "y", null ) + ) + ); + } - @Test - public void testEntitiesReferencedToId4() { - Set rev1_related = new HashSet(getAuditReader().createQuery() - .forEntitiesAtRevision(SetRefIngEmbIdEntity.class, 1) - .add(AuditEntity.relatedId("reference").eq(id4)) - .getResultList()); + @Test + public void testEntitiesReferencedToId4() { + Set rev1_related = new HashSet( + getAuditReader().createQuery() + .forEntitiesAtRevision( SetRefIngEmbIdEntity.class, 1 ) + .add( AuditEntity.relatedId( "reference" ).eq( id4 ) ) + .getResultList() + ); - Set rev2_related = new HashSet(getAuditReader().createQuery() - .forEntitiesAtRevision(SetRefIngEmbIdEntity.class, 2) - .add(AuditEntity.relatedId("reference").eq(id4)) - .getResultList()); + Set rev2_related = new HashSet( + getAuditReader().createQuery() + .forEntitiesAtRevision( SetRefIngEmbIdEntity.class, 2 ) + .add( AuditEntity.relatedId( "reference" ).eq( id4 ) ) + .getResultList() + ); - Set rev3_related = new HashSet(getAuditReader().createQuery() - .forEntitiesAtRevision(SetRefIngEmbIdEntity.class, 3) - .add(AuditEntity.relatedId("reference").eq(id4)) - .getResultList()); + Set rev3_related = new HashSet( + getAuditReader().createQuery() + .forEntitiesAtRevision( SetRefIngEmbIdEntity.class, 3 ) + .add( AuditEntity.relatedId( "reference" ).eq( id4 ) ) + .getResultList() + ); - assert rev1_related.equals(TestTools.makeSet()); - assert rev2_related.equals(TestTools.makeSet(new SetRefIngEmbIdEntity(id2, "y", null))); - assert rev3_related.equals(TestTools.makeSet()); - } + assert rev1_related.equals( TestTools.makeSet() ); + assert rev2_related.equals( TestTools.makeSet( new SetRefIngEmbIdEntity( id2, "y", null ) ) ); + assert rev3_related.equals( TestTools.makeSet() ); + } - @Test - public void testEntitiesReferencedByIng1ToId3() { - List rev1_related = getAuditReader().createQuery() - .forEntitiesAtRevision(SetRefIngEmbIdEntity.class, 1) - .add(AuditEntity.relatedId("reference").eq(id3)) - .add(AuditEntity.id().eq(id1)) - .getResultList(); + @Test + public void testEntitiesReferencedByIng1ToId3() { + List rev1_related = getAuditReader().createQuery() + .forEntitiesAtRevision( SetRefIngEmbIdEntity.class, 1 ) + .add( AuditEntity.relatedId( "reference" ).eq( id3 ) ) + .add( AuditEntity.id().eq( id1 ) ) + .getResultList(); - Object rev2_related = getAuditReader().createQuery() - .forEntitiesAtRevision(SetRefIngEmbIdEntity.class, 2) - .add(AuditEntity.relatedId("reference").eq(id3)) - .add(AuditEntity.id().eq(id1)) - .getSingleResult(); + Object rev2_related = getAuditReader().createQuery() + .forEntitiesAtRevision( SetRefIngEmbIdEntity.class, 2 ) + .add( AuditEntity.relatedId( "reference" ).eq( id3 ) ) + .add( AuditEntity.id().eq( id1 ) ) + .getSingleResult(); - Object rev3_related = getAuditReader().createQuery() - .forEntitiesAtRevision(SetRefIngEmbIdEntity.class, 3) - .add(AuditEntity.relatedId("reference").eq(id3)) - .add(AuditEntity.id().eq(id1)) - .getSingleResult(); + Object rev3_related = getAuditReader().createQuery() + .forEntitiesAtRevision( SetRefIngEmbIdEntity.class, 3 ) + .add( AuditEntity.relatedId( "reference" ).eq( id3 ) ) + .add( AuditEntity.id().eq( id1 ) ) + .getSingleResult(); - assert rev1_related.size() == 0; - assert rev2_related.equals(new SetRefIngEmbIdEntity(id1, "x", null)); - assert rev3_related.equals(new SetRefIngEmbIdEntity(id1, "x", null)); - } + assert rev1_related.size() == 0; + assert rev2_related.equals( new SetRefIngEmbIdEntity( id1, "x", null ) ); + assert rev3_related.equals( new SetRefIngEmbIdEntity( id1, "x", null ) ); + } - @Test - public void testEntitiesReferencedByIng2ToId3() { - List rev1_related = getAuditReader().createQuery() - .forEntitiesAtRevision(SetRefIngEmbIdEntity.class, 1) - .add(AuditEntity.relatedId("reference").eq(id3)) - .add(AuditEntity.id().eq(id2)) - .getResultList(); + @Test + public void testEntitiesReferencedByIng2ToId3() { + List rev1_related = getAuditReader().createQuery() + .forEntitiesAtRevision( SetRefIngEmbIdEntity.class, 1 ) + .add( AuditEntity.relatedId( "reference" ).eq( id3 ) ) + .add( AuditEntity.id().eq( id2 ) ) + .getResultList(); - List rev2_related = getAuditReader().createQuery() - .forEntitiesAtRevision(SetRefIngEmbIdEntity.class, 2) - .add(AuditEntity.relatedId("reference").eq(id3)) - .add(AuditEntity.id().eq(id2)) - .getResultList(); + List rev2_related = getAuditReader().createQuery() + .forEntitiesAtRevision( SetRefIngEmbIdEntity.class, 2 ) + .add( AuditEntity.relatedId( "reference" ).eq( id3 ) ) + .add( AuditEntity.id().eq( id2 ) ) + .getResultList(); - Object rev3_related = getAuditReader().createQuery() - .forEntitiesAtRevision(SetRefIngEmbIdEntity.class, 3) - .add(AuditEntity.relatedId("reference").eq(id3)) - .add(AuditEntity.id().eq(id2)) - .getSingleResult(); + Object rev3_related = getAuditReader().createQuery() + .forEntitiesAtRevision( SetRefIngEmbIdEntity.class, 3 ) + .add( AuditEntity.relatedId( "reference" ).eq( id3 ) ) + .add( AuditEntity.id().eq( id2 ) ) + .getSingleResult(); - assert rev1_related.size() == 0; - assert rev2_related.size() == 0; - assert rev3_related.equals(new SetRefIngEmbIdEntity(id2, "y", null)); - } + assert rev1_related.size() == 0; + assert rev2_related.size() == 0; + assert rev3_related.equals( new SetRefIngEmbIdEntity( id2, "y", null ) ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/ids/MulIdOneToManyQuery.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/ids/MulIdOneToManyQuery.java index ff50d0bd16..f3c58669b0 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/ids/MulIdOneToManyQuery.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/ids/MulIdOneToManyQuery.java @@ -23,12 +23,10 @@ */ package org.hibernate.envers.test.integration.query.ids; +import javax.persistence.EntityManager; import java.util.HashSet; import java.util.List; import java.util.Set; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.query.AuditEntity; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; @@ -38,6 +36,8 @@ import org.hibernate.envers.test.entities.onetomany.ids.SetRefEdMulIdEntity; import org.hibernate.envers.test.entities.onetomany.ids.SetRefIngMulIdEntity; import org.hibernate.envers.test.tools.TestTools; +import org.junit.Test; + import static org.junit.Assert.assertEquals; /** @@ -45,170 +45,192 @@ import static org.junit.Assert.assertEquals; */ @SuppressWarnings({"unchecked"}) public class MulIdOneToManyQuery extends BaseEnversJPAFunctionalTestCase { - private MulId id1; - private MulId id2; + private MulId id1; + private MulId id2; - private MulId id3; - private MulId id4; + private MulId id3; + private MulId id4; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { SetRefEdMulIdEntity.class, SetRefIngMulIdEntity.class }; - } + return new Class[] {SetRefEdMulIdEntity.class, SetRefIngMulIdEntity.class}; + } - @Test - @Priority(10) - public void initData() { - id1 = new MulId(0, 1); - id2 = new MulId(10, 11); - id3 = new MulId(20, 21); - id4 = new MulId(30, 31); + @Test + @Priority(10) + public void initData() { + id1 = new MulId( 0, 1 ); + id2 = new MulId( 10, 11 ); + id3 = new MulId( 20, 21 ); + id4 = new MulId( 30, 31 ); - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); - SetRefIngMulIdEntity refIng1 = new SetRefIngMulIdEntity(id1, "x", null); - SetRefIngMulIdEntity refIng2 = new SetRefIngMulIdEntity(id2, "y", null); + SetRefIngMulIdEntity refIng1 = new SetRefIngMulIdEntity( id1, "x", null ); + SetRefIngMulIdEntity refIng2 = new SetRefIngMulIdEntity( id2, "y", null ); - em.persist(refIng1); - em.persist(refIng2); + em.persist( refIng1 ); + em.persist( refIng2 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); + // Revision 2 + em.getTransaction().begin(); - SetRefEdMulIdEntity refEd3 = new SetRefEdMulIdEntity(id3, "a"); - SetRefEdMulIdEntity refEd4 = new SetRefEdMulIdEntity(id4, "a"); + SetRefEdMulIdEntity refEd3 = new SetRefEdMulIdEntity( id3, "a" ); + SetRefEdMulIdEntity refEd4 = new SetRefEdMulIdEntity( id4, "a" ); - em.persist(refEd3); - em.persist(refEd4); + em.persist( refEd3 ); + em.persist( refEd4 ); - refIng1 = em.find(SetRefIngMulIdEntity.class, id1); - refIng2 = em.find(SetRefIngMulIdEntity.class, id2); + refIng1 = em.find( SetRefIngMulIdEntity.class, id1 ); + refIng2 = em.find( SetRefIngMulIdEntity.class, id2 ); - refIng1.setReference(refEd3); - refIng2.setReference(refEd4); + refIng1.setReference( refEd3 ); + refIng2.setReference( refEd4 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 3 - em.getTransaction().begin(); + // Revision 3 + em.getTransaction().begin(); - refEd3 = em.find(SetRefEdMulIdEntity.class, id3); - refIng2 = em.find(SetRefIngMulIdEntity.class, id2); - refIng2.setReference(refEd3); + refEd3 = em.find( SetRefEdMulIdEntity.class, id3 ); + refIng2 = em.find( SetRefIngMulIdEntity.class, id2 ); + refIng2.setReference( refEd3 ); - em.getTransaction().commit(); - } + em.getTransaction().commit(); + } - @Test - public void testEntitiesReferencedToId3() { - Set rev1_related = new HashSet(getAuditReader().createQuery() - .forEntitiesAtRevision(SetRefIngMulIdEntity.class, 1) - .add(AuditEntity.relatedId("reference").eq(id3)) - .getResultList()); + @Test + public void testEntitiesReferencedToId3() { + Set rev1_related = new HashSet( + getAuditReader().createQuery() + .forEntitiesAtRevision( SetRefIngMulIdEntity.class, 1 ) + .add( AuditEntity.relatedId( "reference" ).eq( id3 ) ) + .getResultList() + ); - Set rev1 = new HashSet(getAuditReader().createQuery() - .forEntitiesAtRevision(SetRefIngMulIdEntity.class, 1) - .add(AuditEntity.property("reference").eq(new SetRefEdMulIdEntity(id3, null))) - .getResultList()); + Set rev1 = new HashSet( + getAuditReader().createQuery() + .forEntitiesAtRevision( SetRefIngMulIdEntity.class, 1 ) + .add( AuditEntity.property( "reference" ).eq( new SetRefEdMulIdEntity( id3, null ) ) ) + .getResultList() + ); - Set rev2_related = new HashSet(getAuditReader().createQuery() - .forEntitiesAtRevision(SetRefIngMulIdEntity.class, 2) - .add(AuditEntity.relatedId("reference").eq(id3)) - .getResultList()); + Set rev2_related = new HashSet( + getAuditReader().createQuery() + .forEntitiesAtRevision( SetRefIngMulIdEntity.class, 2 ) + .add( AuditEntity.relatedId( "reference" ).eq( id3 ) ) + .getResultList() + ); - Set rev2 = new HashSet(getAuditReader().createQuery() - .forEntitiesAtRevision(SetRefIngMulIdEntity.class, 2) - .add(AuditEntity.property("reference").eq(new SetRefEdMulIdEntity(id3, null))) - .getResultList()); + Set rev2 = new HashSet( + getAuditReader().createQuery() + .forEntitiesAtRevision( SetRefIngMulIdEntity.class, 2 ) + .add( AuditEntity.property( "reference" ).eq( new SetRefEdMulIdEntity( id3, null ) ) ) + .getResultList() + ); - Set rev3_related = new HashSet(getAuditReader().createQuery() - .forEntitiesAtRevision(SetRefIngMulIdEntity.class, 3) - .add(AuditEntity.relatedId("reference").eq(id3)) - .getResultList()); + Set rev3_related = new HashSet( + getAuditReader().createQuery() + .forEntitiesAtRevision( SetRefIngMulIdEntity.class, 3 ) + .add( AuditEntity.relatedId( "reference" ).eq( id3 ) ) + .getResultList() + ); - Set rev3 = new HashSet(getAuditReader().createQuery() - .forEntitiesAtRevision(SetRefIngMulIdEntity.class, 3) - .add(AuditEntity.property("reference").eq(new SetRefEdMulIdEntity(id3, null))) - .getResultList()); + Set rev3 = new HashSet( + getAuditReader().createQuery() + .forEntitiesAtRevision( SetRefIngMulIdEntity.class, 3 ) + .add( AuditEntity.property( "reference" ).eq( new SetRefEdMulIdEntity( id3, null ) ) ) + .getResultList() + ); assertEquals( rev1, rev1_related ); assertEquals( rev2, rev2_related ); assertEquals( rev3, rev3_related ); assertEquals( rev1, TestTools.makeSet() ); - assertEquals( rev2, TestTools.makeSet(new SetRefIngMulIdEntity(id1, "x", null)) ); - assertEquals( rev3, TestTools.makeSet(new SetRefIngMulIdEntity(id1, "x", null), - new SetRefIngMulIdEntity(id2, "y", null)) ); - } + assertEquals( rev2, TestTools.makeSet( new SetRefIngMulIdEntity( id1, "x", null ) ) ); + assertEquals( + rev3, TestTools.makeSet( + new SetRefIngMulIdEntity( id1, "x", null ), + new SetRefIngMulIdEntity( id2, "y", null ) + ) + ); + } - @Test - public void testEntitiesReferencedToId4() { - Set rev1_related = new HashSet(getAuditReader().createQuery() - .forEntitiesAtRevision(SetRefIngMulIdEntity.class, 1) - .add(AuditEntity.relatedId("reference").eq(id4)) - .getResultList()); + @Test + public void testEntitiesReferencedToId4() { + Set rev1_related = new HashSet( + getAuditReader().createQuery() + .forEntitiesAtRevision( SetRefIngMulIdEntity.class, 1 ) + .add( AuditEntity.relatedId( "reference" ).eq( id4 ) ) + .getResultList() + ); - Set rev2_related = new HashSet(getAuditReader().createQuery() - .forEntitiesAtRevision(SetRefIngMulIdEntity.class, 2) - .add(AuditEntity.relatedId("reference").eq(id4)) - .getResultList()); + Set rev2_related = new HashSet( + getAuditReader().createQuery() + .forEntitiesAtRevision( SetRefIngMulIdEntity.class, 2 ) + .add( AuditEntity.relatedId( "reference" ).eq( id4 ) ) + .getResultList() + ); - Set rev3_related = new HashSet(getAuditReader().createQuery() - .forEntitiesAtRevision(SetRefIngMulIdEntity.class, 3) - .add(AuditEntity.relatedId("reference").eq(id4)) - .getResultList()); - assertEquals( rev1_related, TestTools.makeSet( )); - assertEquals( rev2_related, TestTools.makeSet(new SetRefIngMulIdEntity(id2, "y", null))); - assertEquals( rev3_related, TestTools.makeSet( )); - } + Set rev3_related = new HashSet( + getAuditReader().createQuery() + .forEntitiesAtRevision( SetRefIngMulIdEntity.class, 3 ) + .add( AuditEntity.relatedId( "reference" ).eq( id4 ) ) + .getResultList() + ); + assertEquals( rev1_related, TestTools.makeSet() ); + assertEquals( rev2_related, TestTools.makeSet( new SetRefIngMulIdEntity( id2, "y", null ) ) ); + assertEquals( rev3_related, TestTools.makeSet() ); + } - @Test - public void testEntitiesReferencedByIng1ToId3() { - List rev1_related = getAuditReader().createQuery() - .forEntitiesAtRevision(SetRefIngMulIdEntity.class, 1) - .add(AuditEntity.relatedId("reference").eq(id3)) - .add(AuditEntity.id().eq(id1)) - .getResultList(); + @Test + public void testEntitiesReferencedByIng1ToId3() { + List rev1_related = getAuditReader().createQuery() + .forEntitiesAtRevision( SetRefIngMulIdEntity.class, 1 ) + .add( AuditEntity.relatedId( "reference" ).eq( id3 ) ) + .add( AuditEntity.id().eq( id1 ) ) + .getResultList(); - Object rev2_related = getAuditReader().createQuery() - .forEntitiesAtRevision(SetRefIngMulIdEntity.class, 2) - .add(AuditEntity.relatedId("reference").eq(id3)) - .add(AuditEntity.id().eq(id1)) - .getSingleResult(); + Object rev2_related = getAuditReader().createQuery() + .forEntitiesAtRevision( SetRefIngMulIdEntity.class, 2 ) + .add( AuditEntity.relatedId( "reference" ).eq( id3 ) ) + .add( AuditEntity.id().eq( id1 ) ) + .getSingleResult(); - Object rev3_related = getAuditReader().createQuery() - .forEntitiesAtRevision(SetRefIngMulIdEntity.class, 3) - .add(AuditEntity.relatedId("reference").eq(id3)) - .add(AuditEntity.id().eq(id1)) - .getSingleResult(); + Object rev3_related = getAuditReader().createQuery() + .forEntitiesAtRevision( SetRefIngMulIdEntity.class, 3 ) + .add( AuditEntity.relatedId( "reference" ).eq( id3 ) ) + .add( AuditEntity.id().eq( id1 ) ) + .getSingleResult(); assertEquals( 0, rev1_related.size() ); - assertEquals( rev2_related,new SetRefIngMulIdEntity(id1, "x", null) ); - assertEquals( rev3_related, new SetRefIngMulIdEntity(id1, "x", null) ); - } + assertEquals( rev2_related, new SetRefIngMulIdEntity( id1, "x", null ) ); + assertEquals( rev3_related, new SetRefIngMulIdEntity( id1, "x", null ) ); + } - @Test - public void testEntitiesReferencedByIng2ToId3() { - List rev1_related = getAuditReader().createQuery() - .forEntitiesAtRevision(SetRefIngMulIdEntity.class, 1) - .add(AuditEntity.relatedId("reference").eq(id3)) - .add(AuditEntity.id().eq(id2)) - .getResultList(); + @Test + public void testEntitiesReferencedByIng2ToId3() { + List rev1_related = getAuditReader().createQuery() + .forEntitiesAtRevision( SetRefIngMulIdEntity.class, 1 ) + .add( AuditEntity.relatedId( "reference" ).eq( id3 ) ) + .add( AuditEntity.id().eq( id2 ) ) + .getResultList(); - List rev2_related = getAuditReader().createQuery() - .forEntitiesAtRevision(SetRefIngMulIdEntity.class, 2) - .add(AuditEntity.relatedId("reference").eq(id3)) - .add(AuditEntity.id().eq(id2)) - .getResultList(); + List rev2_related = getAuditReader().createQuery() + .forEntitiesAtRevision( SetRefIngMulIdEntity.class, 2 ) + .add( AuditEntity.relatedId( "reference" ).eq( id3 ) ) + .add( AuditEntity.id().eq( id2 ) ) + .getResultList(); - Object rev3_related = getAuditReader().createQuery() - .forEntitiesAtRevision(SetRefIngMulIdEntity.class, 3) - .add(AuditEntity.relatedId("reference").eq(id3)) - .add(AuditEntity.id().eq(id2)) - .getSingleResult(); + Object rev3_related = getAuditReader().createQuery() + .forEntitiesAtRevision( SetRefIngMulIdEntity.class, 3 ) + .add( AuditEntity.relatedId( "reference" ).eq( id3 ) ) + .add( AuditEntity.id().eq( id2 ) ) + .getSingleResult(); assertEquals( 0, rev1_related.size() ); assertEquals( 0, rev2_related.size() ); - assertEquals( new SetRefIngMulIdEntity(id2, "y", null), rev3_related ); - } + assertEquals( new SetRefIngMulIdEntity( id2, "y", null ), rev3_related ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/readwriteexpression/ReadWriteExpressionChange.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/readwriteexpression/ReadWriteExpressionChange.java index d1a6edf212..e070f1bf3a 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/readwriteexpression/ReadWriteExpressionChange.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/readwriteexpression/ReadWriteExpressionChange.java @@ -1,60 +1,61 @@ package org.hibernate.envers.test.integration.readwriteexpression; +import javax.persistence.EntityManager; import java.math.BigDecimal; import java.util.List; -import javax.persistence.EntityManager; - -import org.junit.Assert; -import org.junit.Test; import org.hibernate.dialect.Oracle8iDialect; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; +import org.junit.Assert; +import org.junit.Test; + public class ReadWriteExpressionChange extends BaseEnversJPAFunctionalTestCase { - private static final Double HEIGHT_INCHES = 73.0d; - private static final Double HEIGHT_CENTIMETERS = HEIGHT_INCHES * 2.54d; + private static final Double HEIGHT_INCHES = 73.0d; + private static final Double HEIGHT_CENTIMETERS = HEIGHT_INCHES * 2.54d; - private Integer id; + private Integer id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { Staff.class }; - } + return new Class[] {Staff.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); - em.getTransaction().begin(); - Staff staff = new Staff(HEIGHT_INCHES, 1); - em.persist(staff); - em.getTransaction().commit(); - id = staff.getId(); - } + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); + em.getTransaction().begin(); + Staff staff = new Staff( HEIGHT_INCHES, 1 ); + em.persist( staff ); + em.getTransaction().commit(); + id = staff.getId(); + } - @Test - public void shouldRespectWriteExpression() { - EntityManager em = getEntityManager(); - List resultList = em.createNativeQuery("select size_in_cm from t_staff_AUD where id ="+id).getResultList(); - Assert.assertEquals(1, resultList.size()); - Double sizeInCm = null; - if (getDialect() instanceof Oracle8iDialect) { - sizeInCm = ((BigDecimal) resultList.get(0)).doubleValue(); - } else { - sizeInCm = (Double) resultList.get(0); - } - Assert.assertEquals(HEIGHT_CENTIMETERS, sizeInCm.doubleValue(), 0.00000001); - } + @Test + public void shouldRespectWriteExpression() { + EntityManager em = getEntityManager(); + List resultList = em.createNativeQuery( "select size_in_cm from t_staff_AUD where id =" + id ).getResultList(); + Assert.assertEquals( 1, resultList.size() ); + Double sizeInCm = null; + if ( getDialect() instanceof Oracle8iDialect ) { + sizeInCm = ((BigDecimal) resultList.get( 0 )).doubleValue(); + } + else { + sizeInCm = (Double) resultList.get( 0 ); + } + Assert.assertEquals( HEIGHT_CENTIMETERS, sizeInCm.doubleValue(), 0.00000001 ); + } - @Test - public void shouldRespectReadExpression() { - List revisions = getAuditReader().getRevisions(Staff.class, id); - Assert.assertEquals(1, revisions.size()); - Number number = revisions.get(0); - Staff staffRev = getAuditReader().find(Staff.class, id, number); - Assert.assertEquals(HEIGHT_INCHES, staffRev.getSizeInInches(), 0.00000001); - } + @Test + public void shouldRespectReadExpression() { + List revisions = getAuditReader().getRevisions( Staff.class, id ); + Assert.assertEquals( 1, revisions.size() ); + Number number = revisions.get( 0 ); + Staff staffRev = getAuditReader().find( Staff.class, id, number ); + Assert.assertEquals( HEIGHT_INCHES, staffRev.getSizeInInches(), 0.00000001 ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/readwriteexpression/Staff.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/readwriteexpression/Staff.java index 354391c6c2..08f1290c4e 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/readwriteexpression/Staff.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/readwriteexpression/Staff.java @@ -9,30 +9,42 @@ import org.hibernate.annotations.ColumnTransformer; import org.hibernate.envers.Audited; @Entity -@Table(name="t_staff") +@Table(name = "t_staff") public class Staff { - public Staff() { - } + public Staff() { + } - public Staff(double sizeInInches, Integer id) { + public Staff(double sizeInInches, Integer id) { this.sizeInInches = sizeInInches; this.id = id; } @Id - public Integer getId() { return id; } - public void setId(Integer id) { this.id = id; } + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + private Integer id; - @Audited - @Column(name="size_in_cm") + @Audited + @Column(name = "size_in_cm") @ColumnTransformer( forColumn = "size_in_cm", read = "size_in_cm / 2.54E0", - write = "? * 2.54E0" ) - public double getSizeInInches() { return sizeInInches; } - public void setSizeInInches(double sizeInInches) { this.sizeInInches = sizeInInches; } + write = "? * 2.54E0") + public double getSizeInInches() { + return sizeInInches; + } + + public void setSizeInInches(double sizeInInches) { + this.sizeInInches = sizeInInches; + } + private double sizeInInches; diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reference/BidirectionalReference.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reference/BidirectionalReference.java index 77d4812d30..1bd9eccdd6 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reference/BidirectionalReference.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reference/BidirectionalReference.java @@ -23,129 +23,129 @@ */ package org.hibernate.envers.test.integration.reference; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.tools.TestTools; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class BidirectionalReference extends BaseEnversJPAFunctionalTestCase { - private Long set1_id; - private Long set2_id; + private Long set1_id; + private Long set2_id; - private Long g1_id; + private Long g1_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { GreetingPO.class, GreetingSetPO.class }; - } + return new Class[] {GreetingPO.class, GreetingSetPO.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - GreetingSetPO set1 = new GreetingSetPO(); - set1.setName("a1"); + GreetingSetPO set1 = new GreetingSetPO(); + set1.setName( "a1" ); GreetingSetPO set2 = new GreetingSetPO(); - set2.setName("a2"); + set2.setName( "a2" ); - // Revision 1 - em.getTransaction().begin(); + // Revision 1 + em.getTransaction().begin(); - em.persist(set1); - em.persist(set2); + em.persist( set1 ); + em.persist( set2 ); set1_id = set1.getId(); set2_id = set2.getId(); - em.getTransaction().commit(); + em.getTransaction().commit(); em.clear(); - // Revision 2 - em.getTransaction().begin(); + // Revision 2 + em.getTransaction().begin(); - GreetingPO g1 = new GreetingPO(); - g1.setGreeting("g1"); - g1.setGreetingSet(em.getReference(GreetingSetPO.class, set1_id)); + GreetingPO g1 = new GreetingPO(); + g1.setGreeting( "g1" ); + g1.setGreetingSet( em.getReference( GreetingSetPO.class, set1_id ) ); - em.persist(g1); + em.persist( g1 ); g1_id = g1.getId(); - em.getTransaction().commit(); + em.getTransaction().commit(); em.clear(); - // Revision 3 - em.getTransaction().begin(); + // Revision 3 + em.getTransaction().begin(); - g1 = em.find(GreetingPO.class, g1_id); + g1 = em.find( GreetingPO.class, g1_id ); - g1.setGreetingSet(em.getReference(GreetingSetPO.class, set2_id)); + g1.setGreetingSet( em.getReference( GreetingSetPO.class, set2_id ) ); - em.getTransaction().commit(); - } - - @Test - public void testRevisionsCounts() { - assert Arrays.asList(2, 3).equals(getAuditReader().getRevisions(GreetingPO.class, g1_id)); - - assert Arrays.asList(1, 2, 3).equals(getAuditReader().getRevisions(GreetingSetPO.class, set1_id)); - assert Arrays.asList(1, 3).equals(getAuditReader().getRevisions(GreetingSetPO.class, set2_id)); - } - - @Test - public void testHistoryOfG1() { - GreetingPO rev1 = getAuditReader().find(GreetingPO.class, g1_id, 1); - GreetingPO rev2 = getAuditReader().find(GreetingPO.class, g1_id, 2); - GreetingPO rev3 = getAuditReader().find(GreetingPO.class, g1_id, 3); - - assert rev1 == null; - assert rev2.getGreetingSet().getName().equals("a1"); - assert rev3.getGreetingSet().getName().equals("a2"); - } + em.getTransaction().commit(); + } @Test - public void testHistoryOfSet1() { - GreetingSetPO rev1 = getAuditReader().find(GreetingSetPO.class, set1_id, 1); - GreetingSetPO rev2 = getAuditReader().find(GreetingSetPO.class, set1_id, 2); - GreetingSetPO rev3 = getAuditReader().find(GreetingSetPO.class, set1_id, 3); + public void testRevisionsCounts() { + assert Arrays.asList( 2, 3 ).equals( getAuditReader().getRevisions( GreetingPO.class, g1_id ) ); - assert rev1.getName().equals("a1"); - assert rev2.getName().equals("a1"); - assert rev3.getName().equals("a1"); + assert Arrays.asList( 1, 2, 3 ).equals( getAuditReader().getRevisions( GreetingSetPO.class, set1_id ) ); + assert Arrays.asList( 1, 3 ).equals( getAuditReader().getRevisions( GreetingSetPO.class, set2_id ) ); + } + + @Test + public void testHistoryOfG1() { + GreetingPO rev1 = getAuditReader().find( GreetingPO.class, g1_id, 1 ); + GreetingPO rev2 = getAuditReader().find( GreetingPO.class, g1_id, 2 ); + GreetingPO rev3 = getAuditReader().find( GreetingPO.class, g1_id, 3 ); + + assert rev1 == null; + assert rev2.getGreetingSet().getName().equals( "a1" ); + assert rev3.getGreetingSet().getName().equals( "a2" ); + } + + @Test + public void testHistoryOfSet1() { + GreetingSetPO rev1 = getAuditReader().find( GreetingSetPO.class, set1_id, 1 ); + GreetingSetPO rev2 = getAuditReader().find( GreetingSetPO.class, set1_id, 2 ); + GreetingSetPO rev3 = getAuditReader().find( GreetingSetPO.class, set1_id, 3 ); + + assert rev1.getName().equals( "a1" ); + assert rev2.getName().equals( "a1" ); + assert rev3.getName().equals( "a1" ); GreetingPO g1 = new GreetingPO(); - g1.setId(g1_id); - g1.setGreeting("g1"); + g1.setId( g1_id ); + g1.setGreeting( "g1" ); assert rev1.getGreetings().size() == 0; - assert rev2.getGreetings().equals(TestTools.makeSet(g1)); + assert rev2.getGreetings().equals( TestTools.makeSet( g1 ) ); assert rev3.getGreetings().size() == 0; - } + } @Test - public void testHistoryOfSet2() { - GreetingSetPO rev1 = getAuditReader().find(GreetingSetPO.class, set2_id, 1); - GreetingSetPO rev2 = getAuditReader().find(GreetingSetPO.class, set2_id, 2); - GreetingSetPO rev3 = getAuditReader().find(GreetingSetPO.class, set2_id, 3); + public void testHistoryOfSet2() { + GreetingSetPO rev1 = getAuditReader().find( GreetingSetPO.class, set2_id, 1 ); + GreetingSetPO rev2 = getAuditReader().find( GreetingSetPO.class, set2_id, 2 ); + GreetingSetPO rev3 = getAuditReader().find( GreetingSetPO.class, set2_id, 3 ); - assert rev1.getName().equals("a2"); - assert rev2.getName().equals("a2"); - assert rev3.getName().equals("a2"); + assert rev1.getName().equals( "a2" ); + assert rev2.getName().equals( "a2" ); + assert rev3.getName().equals( "a2" ); GreetingPO g1 = new GreetingPO(); - g1.setId(g1_id); - g1.setGreeting("g1"); + g1.setId( g1_id ); + g1.setGreeting( "g1" ); assert rev1.getGreetings().size() == 0; assert rev2.getGreetings().size() == 0; - assert rev3.getGreetings().equals(TestTools.makeSet(g1)); - } + assert rev3.getGreetings().equals( TestTools.makeSet( g1 ) ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reference/GreetingPO.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reference/GreetingPO.java index 94ad941827..b15a85718e 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reference/GreetingPO.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reference/GreetingPO.java @@ -1,4 +1,5 @@ package org.hibernate.envers.test.integration.reference; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; @@ -44,13 +45,21 @@ public class GreetingPO { @Override public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof GreetingPO)) return false; + if ( this == o ) { + return true; + } + if ( !(o instanceof GreetingPO) ) { + return false; + } GreetingPO that = (GreetingPO) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; - if (theGreeting != null ? !theGreeting.equals(that.theGreeting) : that.theGreeting != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } + if ( theGreeting != null ? !theGreeting.equals( that.theGreeting ) : that.theGreeting != null ) { + return false; + } return true; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reference/GreetingSetPO.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reference/GreetingSetPO.java index 275cb74edb..72e6947994 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reference/GreetingSetPO.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reference/GreetingSetPO.java @@ -1,9 +1,10 @@ package org.hibernate.envers.test.integration.reference; -import java.util.Set; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.OneToMany; +import java.util.Set; import org.hibernate.envers.Audited; @@ -45,13 +46,21 @@ public class GreetingSetPO { @Override public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof GreetingSetPO)) return false; + if ( this == o ) { + return true; + } + if ( !(o instanceof GreetingSetPO) ) { + return false; + } GreetingSetPO that = (GreetingSetPO) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; - if (name != null ? !name.equals(that.name) : that.name != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } + if ( name != null ? !name.equals( that.name ) : that.name != null ) { + return false; + } return true; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/CountingRevisionListener.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/CountingRevisionListener.java index e05e82b422..61b26db7ca 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/CountingRevisionListener.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/CountingRevisionListener.java @@ -6,10 +6,10 @@ import org.hibernate.envers.RevisionListener; * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public class CountingRevisionListener implements RevisionListener { - public static int revisionCount = 0; + public static int revisionCount = 0; - @Override - public void newRevision(Object revisionEntity) { - ++revisionCount; - } + @Override + public void newRevision(Object revisionEntity) { + ++revisionCount; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/Custom.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/Custom.java index 381188a7ca..e89dda7391 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/Custom.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/Custom.java @@ -23,14 +23,12 @@ */ package org.hibernate.envers.test.integration.reventity; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.Date; import java.util.HashSet; import java.util.Map; import java.util.Set; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.AuditReader; import org.hibernate.envers.exception.RevisionDoesNotExistException; @@ -39,114 +37,117 @@ import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrTestEntity; import org.hibernate.envers.test.entities.reventity.CustomRevEntity; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class Custom extends BaseEnversJPAFunctionalTestCase { - private Integer id; - private long timestamp1; - private long timestamp2; - private long timestamp3; + private Integer id; + private long timestamp1; + private long timestamp2; + private long timestamp3; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { StrTestEntity.class, CustomRevEntity.class }; - } + return new Class[] {StrTestEntity.class, CustomRevEntity.class}; + } - @Test - @Priority(10) - public void initData() throws InterruptedException { - timestamp1 = System.currentTimeMillis(); + @Test + @Priority(10) + public void initData() throws InterruptedException { + timestamp1 = System.currentTimeMillis(); - Thread.sleep(100); + Thread.sleep( 100 ); - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); - StrTestEntity te = new StrTestEntity("x"); - em.persist(te); - id = te.getId(); - em.getTransaction().commit(); + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); + StrTestEntity te = new StrTestEntity( "x" ); + em.persist( te ); + id = te.getId(); + em.getTransaction().commit(); - timestamp2 = System.currentTimeMillis(); + timestamp2 = System.currentTimeMillis(); - Thread.sleep(100); + Thread.sleep( 100 ); - // Revision 2 - em.getTransaction().begin(); - te = em.find(StrTestEntity.class, id); - te.setStr("y"); - em.getTransaction().commit(); + // Revision 2 + em.getTransaction().begin(); + te = em.find( StrTestEntity.class, id ); + te.setStr( "y" ); + em.getTransaction().commit(); - timestamp3 = System.currentTimeMillis(); - } + timestamp3 = System.currentTimeMillis(); + } - @Test(expected = RevisionDoesNotExistException.class) - public void testTimestamps1() { - getAuditReader().getRevisionNumberForDate(new Date(timestamp1)); - } + @Test(expected = RevisionDoesNotExistException.class) + public void testTimestamps1() { + getAuditReader().getRevisionNumberForDate( new Date( timestamp1 ) ); + } - @Test - public void testTimestamps() { - assert getAuditReader().getRevisionNumberForDate(new Date(timestamp2)).intValue() == 1; - assert getAuditReader().getRevisionNumberForDate(new Date(timestamp3)).intValue() == 2; - } + @Test + public void testTimestamps() { + assert getAuditReader().getRevisionNumberForDate( new Date( timestamp2 ) ).intValue() == 1; + assert getAuditReader().getRevisionNumberForDate( new Date( timestamp3 ) ).intValue() == 2; + } - @Test - public void testDatesForRevisions() { - AuditReader vr = getAuditReader(); - assert vr.getRevisionNumberForDate(vr.getRevisionDate(1)).intValue() == 1; - assert vr.getRevisionNumberForDate(vr.getRevisionDate(2)).intValue() == 2; - } + @Test + public void testDatesForRevisions() { + AuditReader vr = getAuditReader(); + assert vr.getRevisionNumberForDate( vr.getRevisionDate( 1 ) ).intValue() == 1; + assert vr.getRevisionNumberForDate( vr.getRevisionDate( 2 ) ).intValue() == 2; + } - @Test - public void testRevisionsForDates() { - AuditReader vr = getAuditReader(); + @Test + public void testRevisionsForDates() { + AuditReader vr = getAuditReader(); - assert vr.getRevisionDate(vr.getRevisionNumberForDate(new Date(timestamp2))).getTime() <= timestamp2; - assert vr.getRevisionDate(vr.getRevisionNumberForDate(new Date(timestamp2)).intValue()+1).getTime() > timestamp2; + assert vr.getRevisionDate( vr.getRevisionNumberForDate( new Date( timestamp2 ) ) ).getTime() <= timestamp2; + assert vr.getRevisionDate( vr.getRevisionNumberForDate( new Date( timestamp2 ) ).intValue() + 1 ) + .getTime() > timestamp2; - assert vr.getRevisionDate(vr.getRevisionNumberForDate(new Date(timestamp3))).getTime() <= timestamp3; - } + assert vr.getRevisionDate( vr.getRevisionNumberForDate( new Date( timestamp3 ) ) ).getTime() <= timestamp3; + } - @Test - public void testFindRevision() { - AuditReader vr = getAuditReader(); + @Test + public void testFindRevision() { + AuditReader vr = getAuditReader(); - long rev1Timestamp = vr.findRevision(CustomRevEntity.class, 1).getCustomTimestamp(); - assert rev1Timestamp > timestamp1; - assert rev1Timestamp <= timestamp2; + long rev1Timestamp = vr.findRevision( CustomRevEntity.class, 1 ).getCustomTimestamp(); + assert rev1Timestamp > timestamp1; + assert rev1Timestamp <= timestamp2; - long rev2Timestamp = vr.findRevision(CustomRevEntity.class, 2).getCustomTimestamp(); - assert rev2Timestamp > timestamp2; - assert rev2Timestamp <= timestamp3; - } + long rev2Timestamp = vr.findRevision( CustomRevEntity.class, 2 ).getCustomTimestamp(); + assert rev2Timestamp > timestamp2; + assert rev2Timestamp <= timestamp3; + } - @Test - public void testFindRevisions() { - AuditReader vr = getAuditReader(); + @Test + public void testFindRevisions() { + AuditReader vr = getAuditReader(); - Set revNumbers = new HashSet(); - revNumbers.add(1); - revNumbers.add(2); - - Map revisionMap = vr.findRevisions(CustomRevEntity.class, revNumbers); - assert(revisionMap.size() == 2); - assert(revisionMap.get(1).equals(vr.findRevision(CustomRevEntity.class, 1))); - assert(revisionMap.get(2).equals(vr.findRevision(CustomRevEntity.class, 2))); - } + Set revNumbers = new HashSet(); + revNumbers.add( 1 ); + revNumbers.add( 2 ); - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(StrTestEntity.class, id)); - } + Map revisionMap = vr.findRevisions( CustomRevEntity.class, revNumbers ); + assert (revisionMap.size() == 2); + assert (revisionMap.get( 1 ).equals( vr.findRevision( CustomRevEntity.class, 1 ) )); + assert (revisionMap.get( 2 ).equals( vr.findRevision( CustomRevEntity.class, 2 ) )); + } - @Test - public void testHistoryOfId1() { - StrTestEntity ver1 = new StrTestEntity("x", id); - StrTestEntity ver2 = new StrTestEntity("y", id); + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( StrTestEntity.class, id ) ); + } - assert getAuditReader().find(StrTestEntity.class, id, 1).equals(ver1); - assert getAuditReader().find(StrTestEntity.class, id, 2).equals(ver2); - } + @Test + public void testHistoryOfId1() { + StrTestEntity ver1 = new StrTestEntity( "x", id ); + StrTestEntity ver2 = new StrTestEntity( "y", id ); + + assert getAuditReader().find( StrTestEntity.class, id, 1 ).equals( ver1 ); + assert getAuditReader().find( StrTestEntity.class, id, 2 ).equals( ver2 ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/CustomBoxed.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/CustomBoxed.java index 67deef8641..c14288c4d9 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/CustomBoxed.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/CustomBoxed.java @@ -23,14 +23,12 @@ */ package org.hibernate.envers.test.integration.reventity; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.Date; import java.util.HashSet; import java.util.Map; import java.util.Set; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.AuditReader; import org.hibernate.envers.exception.RevisionDoesNotExistException; @@ -38,114 +36,117 @@ import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrTestEntity; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class CustomBoxed extends BaseEnversJPAFunctionalTestCase { - private Integer id; - private long timestamp1; - private long timestamp2; - private long timestamp3; + private Integer id; + private long timestamp1; + private long timestamp2; + private long timestamp3; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { StrTestEntity.class, CustomBoxedRevEntity.class }; - } + return new Class[] {StrTestEntity.class, CustomBoxedRevEntity.class}; + } - @Test - @Priority(10) - public void initData() throws InterruptedException { - timestamp1 = System.currentTimeMillis(); + @Test + @Priority(10) + public void initData() throws InterruptedException { + timestamp1 = System.currentTimeMillis(); - Thread.sleep(100); + Thread.sleep( 100 ); - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); - StrTestEntity te = new StrTestEntity("x"); - em.persist(te); - id = te.getId(); - em.getTransaction().commit(); + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); + StrTestEntity te = new StrTestEntity( "x" ); + em.persist( te ); + id = te.getId(); + em.getTransaction().commit(); - timestamp2 = System.currentTimeMillis(); + timestamp2 = System.currentTimeMillis(); - Thread.sleep(100); + Thread.sleep( 100 ); - // Revision 2 - em.getTransaction().begin(); - te = em.find(StrTestEntity.class, id); - te.setStr("y"); - em.getTransaction().commit(); + // Revision 2 + em.getTransaction().begin(); + te = em.find( StrTestEntity.class, id ); + te.setStr( "y" ); + em.getTransaction().commit(); - timestamp3 = System.currentTimeMillis(); - } + timestamp3 = System.currentTimeMillis(); + } - @Test(expected = RevisionDoesNotExistException.class) - public void testTimestamps1() { - getAuditReader().getRevisionNumberForDate(new Date(timestamp1)); - } + @Test(expected = RevisionDoesNotExistException.class) + public void testTimestamps1() { + getAuditReader().getRevisionNumberForDate( new Date( timestamp1 ) ); + } - @Test - public void testTimestamps() { - assert getAuditReader().getRevisionNumberForDate(new Date(timestamp2)).intValue() == 1; - assert getAuditReader().getRevisionNumberForDate(new Date(timestamp3)).intValue() == 2; - } + @Test + public void testTimestamps() { + assert getAuditReader().getRevisionNumberForDate( new Date( timestamp2 ) ).intValue() == 1; + assert getAuditReader().getRevisionNumberForDate( new Date( timestamp3 ) ).intValue() == 2; + } - @Test - public void testDatesForRevisions() { - AuditReader vr = getAuditReader(); - assert vr.getRevisionNumberForDate(vr.getRevisionDate(1)).intValue() == 1; - assert vr.getRevisionNumberForDate(vr.getRevisionDate(2)).intValue() == 2; - } + @Test + public void testDatesForRevisions() { + AuditReader vr = getAuditReader(); + assert vr.getRevisionNumberForDate( vr.getRevisionDate( 1 ) ).intValue() == 1; + assert vr.getRevisionNumberForDate( vr.getRevisionDate( 2 ) ).intValue() == 2; + } - @Test - public void testRevisionsForDates() { - AuditReader vr = getAuditReader(); + @Test + public void testRevisionsForDates() { + AuditReader vr = getAuditReader(); - assert vr.getRevisionDate(vr.getRevisionNumberForDate(new Date(timestamp2))).getTime() <= timestamp2; - assert vr.getRevisionDate(vr.getRevisionNumberForDate(new Date(timestamp2)).intValue()+1).getTime() > timestamp2; + assert vr.getRevisionDate( vr.getRevisionNumberForDate( new Date( timestamp2 ) ) ).getTime() <= timestamp2; + assert vr.getRevisionDate( vr.getRevisionNumberForDate( new Date( timestamp2 ) ).intValue() + 1 ) + .getTime() > timestamp2; - assert vr.getRevisionDate(vr.getRevisionNumberForDate(new Date(timestamp3))).getTime() <= timestamp3; - } + assert vr.getRevisionDate( vr.getRevisionNumberForDate( new Date( timestamp3 ) ) ).getTime() <= timestamp3; + } - @Test - public void testFindRevision() { - AuditReader vr = getAuditReader(); + @Test + public void testFindRevision() { + AuditReader vr = getAuditReader(); - long rev1Timestamp = vr.findRevision(CustomBoxedRevEntity.class, 1).getCustomTimestamp(); - assert rev1Timestamp > timestamp1; - assert rev1Timestamp <= timestamp2; + long rev1Timestamp = vr.findRevision( CustomBoxedRevEntity.class, 1 ).getCustomTimestamp(); + assert rev1Timestamp > timestamp1; + assert rev1Timestamp <= timestamp2; - long rev2Timestamp = vr.findRevision(CustomBoxedRevEntity.class, 2).getCustomTimestamp(); - assert rev2Timestamp > timestamp2; - assert rev2Timestamp <= timestamp3; - } + long rev2Timestamp = vr.findRevision( CustomBoxedRevEntity.class, 2 ).getCustomTimestamp(); + assert rev2Timestamp > timestamp2; + assert rev2Timestamp <= timestamp3; + } - @Test - public void testFindRevisions() { - AuditReader vr = getAuditReader(); + @Test + public void testFindRevisions() { + AuditReader vr = getAuditReader(); - Set revNumbers = new HashSet(); - revNumbers.add(1); - revNumbers.add(2); - - Map revisionMap = vr.findRevisions(CustomBoxedRevEntity.class, revNumbers); - assert(revisionMap.size() == 2); - assert(revisionMap.get(1).equals(vr.findRevision(CustomBoxedRevEntity.class, 1))); - assert(revisionMap.get(2).equals(vr.findRevision(CustomBoxedRevEntity.class, 2))); - } + Set revNumbers = new HashSet(); + revNumbers.add( 1 ); + revNumbers.add( 2 ); - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(StrTestEntity.class, id)); - } + Map revisionMap = vr.findRevisions( CustomBoxedRevEntity.class, revNumbers ); + assert (revisionMap.size() == 2); + assert (revisionMap.get( 1 ).equals( vr.findRevision( CustomBoxedRevEntity.class, 1 ) )); + assert (revisionMap.get( 2 ).equals( vr.findRevision( CustomBoxedRevEntity.class, 2 ) )); + } - @Test - public void testHistoryOfId1() { - StrTestEntity ver1 = new StrTestEntity("x", id); - StrTestEntity ver2 = new StrTestEntity("y", id); + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( StrTestEntity.class, id ) ); + } - assert getAuditReader().find(StrTestEntity.class, id, 1).equals(ver1); - assert getAuditReader().find(StrTestEntity.class, id, 2).equals(ver2); - } + @Test + public void testHistoryOfId1() { + StrTestEntity ver1 = new StrTestEntity( "x", id ); + StrTestEntity ver2 = new StrTestEntity( "y", id ); + + assert getAuditReader().find( StrTestEntity.class, id, 1 ).equals( ver1 ); + assert getAuditReader().find( StrTestEntity.class, id, 2 ).equals( ver2 ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/CustomBoxedRevEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/CustomBoxedRevEntity.java index c31ba406ff..5d1b5531cd 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/CustomBoxedRevEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/CustomBoxedRevEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.reventity; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; @@ -37,56 +38,66 @@ import org.hibernate.envers.RevisionTimestamp; */ @Entity @GenericGenerator(name = "EnversTestingRevisionGenerator", - strategy = "org.hibernate.id.enhanced.TableGenerator", - parameters = {@Parameter(name = "table_name", value = "REVISION_GENERATOR"), - @Parameter(name = "initial_value", value = "1"), - @Parameter(name = "increment_size", value = "1"), - @Parameter(name = "prefer_entity_table_as_segment_value", value = "true") - } + strategy = "org.hibernate.id.enhanced.TableGenerator", + parameters = { + @Parameter(name = "table_name", value = "REVISION_GENERATOR"), + @Parameter(name = "initial_value", value = "1"), + @Parameter(name = "increment_size", value = "1"), + @Parameter(name = "prefer_entity_table_as_segment_value", value = "true") + } ) @RevisionEntity public class CustomBoxedRevEntity { - @Id - @GeneratedValue(generator = "EnversTestingRevisionGenerator") - @RevisionNumber - private Integer customId; + @Id + @GeneratedValue(generator = "EnversTestingRevisionGenerator") + @RevisionNumber + private Integer customId; - @RevisionTimestamp - private Long customTimestamp; + @RevisionTimestamp + private Long customTimestamp; - public Integer getCustomId() { - return customId; - } + public Integer getCustomId() { + return customId; + } - public void setCustomId(Integer customId) { - this.customId = customId; - } + public void setCustomId(Integer customId) { + this.customId = customId; + } - public Long getCustomTimestamp() { - return customTimestamp; - } + public Long getCustomTimestamp() { + return customTimestamp; + } - public void setCustomTimestamp(Long customTimestamp) { - this.customTimestamp = customTimestamp; - } + public void setCustomTimestamp(Long customTimestamp) { + this.customTimestamp = customTimestamp; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof CustomBoxedRevEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof CustomBoxedRevEntity) ) { + return false; + } - CustomBoxedRevEntity that = (CustomBoxedRevEntity) o; + CustomBoxedRevEntity that = (CustomBoxedRevEntity) o; - if (customId != null ? !customId.equals(that.customId) : that.customId != null) return false; - if (customTimestamp != null ? !customTimestamp.equals(that.customTimestamp) : that.customTimestamp != null) - return false; + if ( customId != null ? !customId.equals( that.customId ) : that.customId != null ) { + return false; + } + if ( customTimestamp != null ? + !customTimestamp.equals( that.customTimestamp ) : + that.customTimestamp != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (customId != null ? customId.hashCode() : 0); - result = 31 * result + (customTimestamp != null ? customTimestamp.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (customId != null ? customId.hashCode() : 0); + result = 31 * result + (customTimestamp != null ? customTimestamp.hashCode() : 0); + return result; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/CustomColumnMapping.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/CustomColumnMapping.java index 30fd2de22f..57cea70248 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/CustomColumnMapping.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/CustomColumnMapping.java @@ -23,11 +23,9 @@ */ package org.hibernate.envers.test.integration.reventity; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.Date; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.AuditReader; import org.hibernate.envers.exception.RevisionDoesNotExistException; @@ -36,102 +34,106 @@ import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrTestEntity; import org.hibernate.envers.test.entities.reventity.CustomRevEntityColumnMapping; +import org.junit.Test; + /** * Test which checks if auditing when the revision number in the revision entity has a @Column annotation with * a columnDefinition specified works. + * * @author Adam Warski (adam at warski dot org) */ public class CustomColumnMapping extends BaseEnversJPAFunctionalTestCase { - private Integer id; - private long timestamp1; - private long timestamp2; - private long timestamp3; + private Integer id; + private long timestamp1; + private long timestamp2; + private long timestamp3; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { StrTestEntity.class, CustomRevEntityColumnMapping.class }; - } + return new Class[] {StrTestEntity.class, CustomRevEntityColumnMapping.class}; + } - @Test - @Priority(10) - public void initData() throws InterruptedException { - timestamp1 = System.currentTimeMillis(); + @Test + @Priority(10) + public void initData() throws InterruptedException { + timestamp1 = System.currentTimeMillis(); - Thread.sleep(100); + Thread.sleep( 100 ); - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); - StrTestEntity te = new StrTestEntity("x"); - em.persist(te); - id = te.getId(); - em.getTransaction().commit(); + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); + StrTestEntity te = new StrTestEntity( "x" ); + em.persist( te ); + id = te.getId(); + em.getTransaction().commit(); - timestamp2 = System.currentTimeMillis(); + timestamp2 = System.currentTimeMillis(); - Thread.sleep(100); + Thread.sleep( 100 ); - // Revision 2 - em.getTransaction().begin(); - te = em.find(StrTestEntity.class, id); - te.setStr("y"); - em.getTransaction().commit(); + // Revision 2 + em.getTransaction().begin(); + te = em.find( StrTestEntity.class, id ); + te.setStr( "y" ); + em.getTransaction().commit(); - timestamp3 = System.currentTimeMillis(); - } + timestamp3 = System.currentTimeMillis(); + } - @Test(expected = RevisionDoesNotExistException.class) - public void testTimestamps1() { - getAuditReader().getRevisionNumberForDate(new Date(timestamp1)); - } + @Test(expected = RevisionDoesNotExistException.class) + public void testTimestamps1() { + getAuditReader().getRevisionNumberForDate( new Date( timestamp1 ) ); + } - @Test - public void testTimestamps() { - assert getAuditReader().getRevisionNumberForDate(new Date(timestamp2)).intValue() == 1; - assert getAuditReader().getRevisionNumberForDate(new Date(timestamp3)).intValue() == 2; - } + @Test + public void testTimestamps() { + assert getAuditReader().getRevisionNumberForDate( new Date( timestamp2 ) ).intValue() == 1; + assert getAuditReader().getRevisionNumberForDate( new Date( timestamp3 ) ).intValue() == 2; + } - @Test - public void testDatesForRevisions() { - AuditReader vr = getAuditReader(); - assert vr.getRevisionNumberForDate(vr.getRevisionDate(1l)).intValue() == 1; - assert vr.getRevisionNumberForDate(vr.getRevisionDate(2l)).intValue() == 2; - } + @Test + public void testDatesForRevisions() { + AuditReader vr = getAuditReader(); + assert vr.getRevisionNumberForDate( vr.getRevisionDate( 1l ) ).intValue() == 1; + assert vr.getRevisionNumberForDate( vr.getRevisionDate( 2l ) ).intValue() == 2; + } - @Test - public void testRevisionsForDates() { - AuditReader vr = getAuditReader(); + @Test + public void testRevisionsForDates() { + AuditReader vr = getAuditReader(); - assert vr.getRevisionDate(vr.getRevisionNumberForDate(new Date(timestamp2))).getTime() <= timestamp2; - assert vr.getRevisionDate(vr.getRevisionNumberForDate(new Date(timestamp2)).longValue()+1l).getTime() > timestamp2; + assert vr.getRevisionDate( vr.getRevisionNumberForDate( new Date( timestamp2 ) ) ).getTime() <= timestamp2; + assert vr.getRevisionDate( vr.getRevisionNumberForDate( new Date( timestamp2 ) ).longValue() + 1l ) + .getTime() > timestamp2; - assert vr.getRevisionDate(vr.getRevisionNumberForDate(new Date(timestamp3))).getTime() <= timestamp3; - } + assert vr.getRevisionDate( vr.getRevisionNumberForDate( new Date( timestamp3 ) ) ).getTime() <= timestamp3; + } - @Test - public void testFindRevision() { - AuditReader vr = getAuditReader(); + @Test + public void testFindRevision() { + AuditReader vr = getAuditReader(); - long rev1Timestamp = vr.findRevision(CustomRevEntityColumnMapping.class, 1l).getCustomTimestamp(); - assert rev1Timestamp > timestamp1; - assert rev1Timestamp <= timestamp2; + long rev1Timestamp = vr.findRevision( CustomRevEntityColumnMapping.class, 1l ).getCustomTimestamp(); + assert rev1Timestamp > timestamp1; + assert rev1Timestamp <= timestamp2; - long rev2Timestamp = vr.findRevision(CustomRevEntityColumnMapping.class, 2l).getCustomTimestamp(); - assert rev2Timestamp > timestamp2; - assert rev2Timestamp <= timestamp3; - } + long rev2Timestamp = vr.findRevision( CustomRevEntityColumnMapping.class, 2l ).getCustomTimestamp(); + assert rev2Timestamp > timestamp2; + assert rev2Timestamp <= timestamp3; + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1l, 2l).equals(getAuditReader().getRevisions(StrTestEntity.class, id)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1l, 2l ).equals( getAuditReader().getRevisions( StrTestEntity.class, id ) ); + } - @Test - public void testHistoryOfId1() { - StrTestEntity ver1 = new StrTestEntity("x", id); - StrTestEntity ver2 = new StrTestEntity("y", id); + @Test + public void testHistoryOfId1() { + StrTestEntity ver1 = new StrTestEntity( "x", id ); + StrTestEntity ver2 = new StrTestEntity( "y", id ); - assert getAuditReader().find(StrTestEntity.class, id, 1l).equals(ver1); - assert getAuditReader().find(StrTestEntity.class, id, 2l).equals(ver2); - } + assert getAuditReader().find( StrTestEntity.class, id, 1l ).equals( ver1 ); + assert getAuditReader().find( StrTestEntity.class, id, 2l ).equals( ver2 ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/CustomDate.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/CustomDate.java index 033daef984..ff56ea34e7 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/CustomDate.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/CustomDate.java @@ -23,11 +23,9 @@ */ package org.hibernate.envers.test.integration.reventity; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.Date; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.AuditReader; import org.hibernate.envers.exception.RevisionDoesNotExistException; @@ -36,102 +34,105 @@ import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrTestEntity; import org.hibernate.envers.test.entities.reventity.CustomDateRevEntity; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class CustomDate extends BaseEnversJPAFunctionalTestCase { - private Integer id; - private long timestamp1; - private long timestamp2; - private long timestamp3; + private Integer id; + private long timestamp1; + private long timestamp2; + private long timestamp3; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { StrTestEntity.class, CustomDateRevEntity.class }; - } + return new Class[] {StrTestEntity.class, CustomDateRevEntity.class}; + } - @Test - @Priority(10) - public void initData() throws InterruptedException { - timestamp1 = System.currentTimeMillis(); + @Test + @Priority(10) + public void initData() throws InterruptedException { + timestamp1 = System.currentTimeMillis(); - Thread.sleep(1100); // CustomDateRevEntity.dateTimestamp field maps to date type which on some RDBMSs gets - // truncated to seconds (for example MySQL 5.1). + Thread.sleep( 1100 ); // CustomDateRevEntity.dateTimestamp field maps to date type which on some RDBMSs gets + // truncated to seconds (for example MySQL 5.1). - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); - StrTestEntity te = new StrTestEntity("x"); - em.persist(te); - id = te.getId(); - em.getTransaction().commit(); + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); + StrTestEntity te = new StrTestEntity( "x" ); + em.persist( te ); + id = te.getId(); + em.getTransaction().commit(); - timestamp2 = System.currentTimeMillis(); + timestamp2 = System.currentTimeMillis(); - Thread.sleep(1100); // CustomDateRevEntity.dateTimestamp field maps to date type which on some RDBMSs gets - // truncated to seconds (for example MySQL 5.1). + Thread.sleep( 1100 ); // CustomDateRevEntity.dateTimestamp field maps to date type which on some RDBMSs gets + // truncated to seconds (for example MySQL 5.1). - // Revision 2 - em.getTransaction().begin(); - te = em.find(StrTestEntity.class, id); - te.setStr("y"); - em.getTransaction().commit(); + // Revision 2 + em.getTransaction().begin(); + te = em.find( StrTestEntity.class, id ); + te.setStr( "y" ); + em.getTransaction().commit(); - timestamp3 = System.currentTimeMillis(); - } + timestamp3 = System.currentTimeMillis(); + } - @Test(expected = RevisionDoesNotExistException.class) - public void testTimestamps1() { - getAuditReader().getRevisionNumberForDate(new Date(timestamp1)); - } + @Test(expected = RevisionDoesNotExistException.class) + public void testTimestamps1() { + getAuditReader().getRevisionNumberForDate( new Date( timestamp1 ) ); + } - @Test - public void testTimestamps() { - assert getAuditReader().getRevisionNumberForDate(new Date(timestamp2)).intValue() == 1; - assert getAuditReader().getRevisionNumberForDate(new Date(timestamp3)).intValue() == 2; - } + @Test + public void testTimestamps() { + assert getAuditReader().getRevisionNumberForDate( new Date( timestamp2 ) ).intValue() == 1; + assert getAuditReader().getRevisionNumberForDate( new Date( timestamp3 ) ).intValue() == 2; + } - @Test - public void testDatesForRevisions() { - AuditReader vr = getAuditReader(); - assert vr.getRevisionNumberForDate(vr.getRevisionDate(1)).intValue() == 1; - assert vr.getRevisionNumberForDate(vr.getRevisionDate(2)).intValue() == 2; - } + @Test + public void testDatesForRevisions() { + AuditReader vr = getAuditReader(); + assert vr.getRevisionNumberForDate( vr.getRevisionDate( 1 ) ).intValue() == 1; + assert vr.getRevisionNumberForDate( vr.getRevisionDate( 2 ) ).intValue() == 2; + } - @Test - public void testRevisionsForDates() { - AuditReader vr = getAuditReader(); + @Test + public void testRevisionsForDates() { + AuditReader vr = getAuditReader(); - assert vr.getRevisionDate(vr.getRevisionNumberForDate(new Date(timestamp2))).getTime() <= timestamp2; - assert vr.getRevisionDate(vr.getRevisionNumberForDate(new Date(timestamp2)).intValue()+1).getTime() > timestamp2; + assert vr.getRevisionDate( vr.getRevisionNumberForDate( new Date( timestamp2 ) ) ).getTime() <= timestamp2; + assert vr.getRevisionDate( vr.getRevisionNumberForDate( new Date( timestamp2 ) ).intValue() + 1 ) + .getTime() > timestamp2; - assert vr.getRevisionDate(vr.getRevisionNumberForDate(new Date(timestamp3))).getTime() <= timestamp3; - } + assert vr.getRevisionDate( vr.getRevisionNumberForDate( new Date( timestamp3 ) ) ).getTime() <= timestamp3; + } - @Test - public void testFindRevision() { - AuditReader vr = getAuditReader(); + @Test + public void testFindRevision() { + AuditReader vr = getAuditReader(); - long rev1Timestamp = vr.findRevision(CustomDateRevEntity.class, 1).getDateTimestamp().getTime(); - assert rev1Timestamp > timestamp1; - assert rev1Timestamp <= timestamp2; + long rev1Timestamp = vr.findRevision( CustomDateRevEntity.class, 1 ).getDateTimestamp().getTime(); + assert rev1Timestamp > timestamp1; + assert rev1Timestamp <= timestamp2; - long rev2Timestamp = vr.findRevision(CustomDateRevEntity.class, 2).getDateTimestamp().getTime(); - assert rev2Timestamp > timestamp2; - assert rev2Timestamp <= timestamp3; - } + long rev2Timestamp = vr.findRevision( CustomDateRevEntity.class, 2 ).getDateTimestamp().getTime(); + assert rev2Timestamp > timestamp2; + assert rev2Timestamp <= timestamp3; + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(StrTestEntity.class, id)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( StrTestEntity.class, id ) ); + } - @Test - public void testHistoryOfId1() { - StrTestEntity ver1 = new StrTestEntity("x", id); - StrTestEntity ver2 = new StrTestEntity("y", id); + @Test + public void testHistoryOfId1() { + StrTestEntity ver1 = new StrTestEntity( "x", id ); + StrTestEntity ver2 = new StrTestEntity( "y", id ); - assert getAuditReader().find(StrTestEntity.class, id, 1).equals(ver1); - assert getAuditReader().find(StrTestEntity.class, id, 2).equals(ver2); - } + assert getAuditReader().find( StrTestEntity.class, id, 1 ).equals( ver1 ); + assert getAuditReader().find( StrTestEntity.class, id, 2 ).equals( ver2 ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/CustomNoListener.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/CustomNoListener.java index ab33abef01..4907bbaf65 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/CustomNoListener.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/CustomNoListener.java @@ -23,10 +23,8 @@ */ package org.hibernate.envers.test.integration.reventity; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.AuditReader; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; @@ -34,102 +32,104 @@ import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrTestEntity; import org.hibernate.envers.test.entities.reventity.CustomDataRevEntity; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class CustomNoListener extends BaseEnversJPAFunctionalTestCase { - private Integer id; + private Integer id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { StrTestEntity.class, CustomDataRevEntity.class }; - } + return new Class[] {StrTestEntity.class, CustomDataRevEntity.class}; + } - @Test - @Priority(10) - public void initData() throws InterruptedException { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() throws InterruptedException { + EntityManager em = getEntityManager(); // Revision 1 - em.getTransaction().begin(); - StrTestEntity te = new StrTestEntity("x"); - em.persist(te); - id = te.getId(); + em.getTransaction().begin(); + StrTestEntity te = new StrTestEntity( "x" ); + em.persist( te ); + id = te.getId(); // Setting the data on the revision entity - CustomDataRevEntity custom = getAuditReader().getCurrentRevision(CustomDataRevEntity.class, false); - custom.setData("data1"); + CustomDataRevEntity custom = getAuditReader().getCurrentRevision( CustomDataRevEntity.class, false ); + custom.setData( "data1" ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); - te = em.find(StrTestEntity.class, id); - te.setStr("y"); + // Revision 2 + em.getTransaction().begin(); + te = em.find( StrTestEntity.class, id ); + te.setStr( "y" ); // Setting the data on the revision entity - custom = getAuditReader().getCurrentRevision(CustomDataRevEntity.class, false); - custom.setData("data2"); + custom = getAuditReader().getCurrentRevision( CustomDataRevEntity.class, false ); + custom.setData( "data2" ); - em.getTransaction().commit(); + em.getTransaction().commit(); // Revision 3 - no changes, but rev entity should be persisted - em.getTransaction().begin(); + em.getTransaction().begin(); // Setting the data on the revision entity - custom = getAuditReader().getCurrentRevision(CustomDataRevEntity.class, true); - custom.setData("data3"); + custom = getAuditReader().getCurrentRevision( CustomDataRevEntity.class, true ); + custom.setData( "data3" ); - em.getTransaction().commit(); + em.getTransaction().commit(); // No changes, rev entity won't be persisted - em.getTransaction().begin(); + em.getTransaction().begin(); // Setting the data on the revision entity - custom = getAuditReader().getCurrentRevision(CustomDataRevEntity.class, false); - custom.setData("data4"); + custom = getAuditReader().getCurrentRevision( CustomDataRevEntity.class, false ); + custom.setData( "data4" ); - em.getTransaction().commit(); + em.getTransaction().commit(); // Revision 4 - em.getTransaction().begin(); - te = em.find(StrTestEntity.class, id); - te.setStr("z"); + em.getTransaction().begin(); + te = em.find( StrTestEntity.class, id ); + te.setStr( "z" ); // Setting the data on the revision entity - custom = getAuditReader().getCurrentRevision(CustomDataRevEntity.class, false); - custom.setData("data5"); + custom = getAuditReader().getCurrentRevision( CustomDataRevEntity.class, false ); + custom.setData( "data5" ); - custom = getAuditReader().getCurrentRevision(CustomDataRevEntity.class, false); - custom.setData("data5bis"); + custom = getAuditReader().getCurrentRevision( CustomDataRevEntity.class, false ); + custom.setData( "data5bis" ); - em.getTransaction().commit(); - } + em.getTransaction().commit(); + } - @Test - public void testFindRevision() { - AuditReader vr = getAuditReader(); + @Test + public void testFindRevision() { + AuditReader vr = getAuditReader(); - assert "data1".equals(vr.findRevision(CustomDataRevEntity.class, 1).getData()); - assert "data2".equals(vr.findRevision(CustomDataRevEntity.class, 2).getData()); - assert "data3".equals(vr.findRevision(CustomDataRevEntity.class, 3).getData()); - assert "data5bis".equals(vr.findRevision(CustomDataRevEntity.class, 4).getData()); - } + assert "data1".equals( vr.findRevision( CustomDataRevEntity.class, 1 ).getData() ); + assert "data2".equals( vr.findRevision( CustomDataRevEntity.class, 2 ).getData() ); + assert "data3".equals( vr.findRevision( CustomDataRevEntity.class, 3 ).getData() ); + assert "data5bis".equals( vr.findRevision( CustomDataRevEntity.class, 4 ).getData() ); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2, 4).equals(getAuditReader().getRevisions(StrTestEntity.class, id)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2, 4 ).equals( getAuditReader().getRevisions( StrTestEntity.class, id ) ); + } - @Test - public void testHistoryOfId1() { - StrTestEntity ver1 = new StrTestEntity("x", id); - StrTestEntity ver2 = new StrTestEntity("y", id); - StrTestEntity ver3 = new StrTestEntity("z", id); + @Test + public void testHistoryOfId1() { + StrTestEntity ver1 = new StrTestEntity( "x", id ); + StrTestEntity ver2 = new StrTestEntity( "y", id ); + StrTestEntity ver3 = new StrTestEntity( "z", id ); - assert getAuditReader().find(StrTestEntity.class, id, 1).equals(ver1); - assert getAuditReader().find(StrTestEntity.class, id, 2).equals(ver2); - assert getAuditReader().find(StrTestEntity.class, id, 3).equals(ver2); - assert getAuditReader().find(StrTestEntity.class, id, 4).equals(ver3); - } + assert getAuditReader().find( StrTestEntity.class, id, 1 ).equals( ver1 ); + assert getAuditReader().find( StrTestEntity.class, id, 2 ).equals( ver2 ); + assert getAuditReader().find( StrTestEntity.class, id, 3 ).equals( ver2 ); + assert getAuditReader().find( StrTestEntity.class, id, 4 ).equals( ver3 ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/CustomPropertyAccess.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/CustomPropertyAccess.java index 84a6c4c1e3..8ca3ea1507 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/CustomPropertyAccess.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/CustomPropertyAccess.java @@ -23,11 +23,9 @@ */ package org.hibernate.envers.test.integration.reventity; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.Date; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.AuditReader; import org.hibernate.envers.exception.RevisionDoesNotExistException; @@ -36,99 +34,102 @@ import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrTestEntity; import org.hibernate.envers.test.entities.reventity.CustomPropertyAccessRevEntity; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class CustomPropertyAccess extends BaseEnversJPAFunctionalTestCase { - private Integer id; - private long timestamp1; - private long timestamp2; - private long timestamp3; + private Integer id; + private long timestamp1; + private long timestamp2; + private long timestamp3; - protected Class[] getAnnotatedClasses() { - return new Class[] { StrTestEntity.class, CustomPropertyAccessRevEntity.class }; - } + protected Class[] getAnnotatedClasses() { + return new Class[] {StrTestEntity.class, CustomPropertyAccessRevEntity.class}; + } - @Test - @Priority(10) - public void initData() throws InterruptedException { - timestamp1 = System.currentTimeMillis(); + @Test + @Priority(10) + public void initData() throws InterruptedException { + timestamp1 = System.currentTimeMillis(); - Thread.sleep(100); + Thread.sleep( 100 ); - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); - StrTestEntity te = new StrTestEntity("x"); - em.persist(te); - id = te.getId(); - em.getTransaction().commit(); + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); + StrTestEntity te = new StrTestEntity( "x" ); + em.persist( te ); + id = te.getId(); + em.getTransaction().commit(); - timestamp2 = System.currentTimeMillis(); + timestamp2 = System.currentTimeMillis(); - Thread.sleep(100); + Thread.sleep( 100 ); - // Revision 2 - em.getTransaction().begin(); - te = em.find(StrTestEntity.class, id); - te.setStr("y"); - em.getTransaction().commit(); + // Revision 2 + em.getTransaction().begin(); + te = em.find( StrTestEntity.class, id ); + te.setStr( "y" ); + em.getTransaction().commit(); - timestamp3 = System.currentTimeMillis(); - } + timestamp3 = System.currentTimeMillis(); + } - @Test(expected = RevisionDoesNotExistException.class) - public void testTimestamps1() { - getAuditReader().getRevisionNumberForDate(new Date(timestamp1)); - } + @Test(expected = RevisionDoesNotExistException.class) + public void testTimestamps1() { + getAuditReader().getRevisionNumberForDate( new Date( timestamp1 ) ); + } - @Test - public void testTimestamps() { - assert getAuditReader().getRevisionNumberForDate(new Date(timestamp2)).intValue() == 1; - assert getAuditReader().getRevisionNumberForDate(new Date(timestamp3)).intValue() == 2; - } + @Test + public void testTimestamps() { + assert getAuditReader().getRevisionNumberForDate( new Date( timestamp2 ) ).intValue() == 1; + assert getAuditReader().getRevisionNumberForDate( new Date( timestamp3 ) ).intValue() == 2; + } - @Test - public void testDatesForRevisions() { - AuditReader vr = getAuditReader(); - assert vr.getRevisionNumberForDate(vr.getRevisionDate(1)).intValue() == 1; - assert vr.getRevisionNumberForDate(vr.getRevisionDate(2)).intValue() == 2; - } + @Test + public void testDatesForRevisions() { + AuditReader vr = getAuditReader(); + assert vr.getRevisionNumberForDate( vr.getRevisionDate( 1 ) ).intValue() == 1; + assert vr.getRevisionNumberForDate( vr.getRevisionDate( 2 ) ).intValue() == 2; + } - @Test - public void testRevisionsForDates() { - AuditReader vr = getAuditReader(); + @Test + public void testRevisionsForDates() { + AuditReader vr = getAuditReader(); - assert vr.getRevisionDate(vr.getRevisionNumberForDate(new Date(timestamp2))).getTime() <= timestamp2; - assert vr.getRevisionDate(vr.getRevisionNumberForDate(new Date(timestamp2)).intValue()+1).getTime() > timestamp2; + assert vr.getRevisionDate( vr.getRevisionNumberForDate( new Date( timestamp2 ) ) ).getTime() <= timestamp2; + assert vr.getRevisionDate( vr.getRevisionNumberForDate( new Date( timestamp2 ) ).intValue() + 1 ) + .getTime() > timestamp2; - assert vr.getRevisionDate(vr.getRevisionNumberForDate(new Date(timestamp3))).getTime() <= timestamp3; - } + assert vr.getRevisionDate( vr.getRevisionNumberForDate( new Date( timestamp3 ) ) ).getTime() <= timestamp3; + } - @Test - public void testFindRevision() { - AuditReader vr = getAuditReader(); + @Test + public void testFindRevision() { + AuditReader vr = getAuditReader(); - long rev1Timestamp = vr.findRevision(CustomPropertyAccessRevEntity.class, 1).getCustomTimestamp(); - assert rev1Timestamp > timestamp1; - assert rev1Timestamp <= timestamp2; + long rev1Timestamp = vr.findRevision( CustomPropertyAccessRevEntity.class, 1 ).getCustomTimestamp(); + assert rev1Timestamp > timestamp1; + assert rev1Timestamp <= timestamp2; - long rev2Timestamp = vr.findRevision(CustomPropertyAccessRevEntity.class, 2).getCustomTimestamp(); - assert rev2Timestamp > timestamp2; - assert rev2Timestamp <= timestamp3; - } + long rev2Timestamp = vr.findRevision( CustomPropertyAccessRevEntity.class, 2 ).getCustomTimestamp(); + assert rev2Timestamp > timestamp2; + assert rev2Timestamp <= timestamp3; + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(StrTestEntity.class, id)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( StrTestEntity.class, id ) ); + } - @Test - public void testHistoryOfId1() { - StrTestEntity ver1 = new StrTestEntity("x", id); - StrTestEntity ver2 = new StrTestEntity("y", id); + @Test + public void testHistoryOfId1() { + StrTestEntity ver1 = new StrTestEntity( "x", id ); + StrTestEntity ver2 = new StrTestEntity( "y", id ); - assert getAuditReader().find(StrTestEntity.class, id, 1).equals(ver1); - assert getAuditReader().find(StrTestEntity.class, id, 2).equals(ver2); - } + assert getAuditReader().find( StrTestEntity.class, id, 1 ).equals( ver1 ); + assert getAuditReader().find( StrTestEntity.class, id, 2 ).equals( ver2 ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/DifferentDBSchemaTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/DifferentDBSchemaTest.java index 4fb540ad74..96b90a80d1 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/DifferentDBSchemaTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/DifferentDBSchemaTest.java @@ -1,10 +1,8 @@ package org.hibernate.envers.test.integration.reventity; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.Map; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.cfg.Environment; import org.hibernate.dialect.H2Dialect; @@ -13,71 +11,76 @@ import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrTestEntity; import org.hibernate.mapping.Table; + +import org.junit.Test; + import org.hibernate.testing.RequiresDialect; /** * Tests simple auditing process (read and write operations) when REVINFO and audit tables * exist in a different database schema. + * * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ @RequiresDialect({H2Dialect.class}) public class DifferentDBSchemaTest extends BaseEnversJPAFunctionalTestCase { - private static final String SCHEMA_NAME = "ENVERS_AUDIT"; - private Integer steId = null; + private static final String SCHEMA_NAME = "ENVERS_AUDIT"; + private Integer steId = null; - @Override - protected void addConfigOptions(Map options) { - super.addConfigOptions(options); - // Creates new schema after establishing connection - options.putAll(Environment.getProperties()); - options.put(EnversSettings.DEFAULT_SCHEMA, SCHEMA_NAME); - } + @Override + protected void addConfigOptions(Map options) { + super.addConfigOptions( options ); + // Creates new schema after establishing connection + options.putAll( Environment.getProperties() ); + options.put( EnversSettings.DEFAULT_SCHEMA, SCHEMA_NAME ); + } - @Override - protected String createSecondSchema() { - return SCHEMA_NAME; - } + @Override + protected String createSecondSchema() { + return SCHEMA_NAME; + } @Override protected Class[] getAnnotatedClasses() { - return new Class[] { StrTestEntity.class }; - } + return new Class[] {StrTestEntity.class}; + } - @Test - @Priority(10) - public void initData() throws InterruptedException { - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); - StrTestEntity ste = new StrTestEntity("x"); - em.persist(ste); - steId = ste.getId(); - em.getTransaction().commit(); + @Test + @Priority(10) + public void initData() throws InterruptedException { + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); + StrTestEntity ste = new StrTestEntity( "x" ); + em.persist( ste ); + steId = ste.getId(); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); - ste = em.find(StrTestEntity.class, steId); - ste.setStr("y"); - em.getTransaction().commit(); - } + // Revision 2 + em.getTransaction().begin(); + ste = em.find( StrTestEntity.class, steId ); + ste.setStr( "y" ); + em.getTransaction().commit(); + } - @Test - public void testRevinfoSchemaName() { - Table revisionTable = getCfg().getClassMapping("org.hibernate.envers.enhanced.SequenceIdRevisionEntity").getTable(); - assert SCHEMA_NAME.equals(revisionTable.getSchema()); - } + @Test + public void testRevinfoSchemaName() { + Table revisionTable = getCfg().getClassMapping( "org.hibernate.envers.enhanced.SequenceIdRevisionEntity" ) + .getTable(); + assert SCHEMA_NAME.equals( revisionTable.getSchema() ); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(StrTestEntity.class, steId)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( StrTestEntity.class, steId ) ); + } - @Test - public void testHistoryOfId1() { - StrTestEntity ver1 = new StrTestEntity("x", steId); - StrTestEntity ver2 = new StrTestEntity("y", steId); + @Test + public void testHistoryOfId1() { + StrTestEntity ver1 = new StrTestEntity( "x", steId ); + StrTestEntity ver2 = new StrTestEntity( "y", steId ); - assert getAuditReader().find(StrTestEntity.class, steId, 1).equals(ver1); - assert getAuditReader().find(StrTestEntity.class, steId, 2).equals(ver2); - } + assert getAuditReader().find( StrTestEntity.class, steId, 1 ).equals( ver1 ); + assert getAuditReader().find( StrTestEntity.class, steId, 2 ).equals( ver2 ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/ExceptionListener.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/ExceptionListener.java index d890550b9c..aaaadb92ae 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/ExceptionListener.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/ExceptionListener.java @@ -25,38 +25,39 @@ package org.hibernate.envers.test.integration.reventity; import javax.persistence.EntityManager; -import org.junit.Test; - import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.entities.StrTestEntity; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class ExceptionListener extends BaseEnversJPAFunctionalTestCase { @Override protected Class[] getAnnotatedClasses() { - return new Class[] { StrTestEntity.class, ExceptionListenerRevEntity.class }; - } + return new Class[] {StrTestEntity.class, ExceptionListenerRevEntity.class}; + } - @Test(expected = RuntimeException.class) - public void testTransactionRollback() throws InterruptedException { - // Trying to persist an entity - however the listener should throw an exception, so the entity + @Test(expected = RuntimeException.class) + public void testTransactionRollback() throws InterruptedException { + // Trying to persist an entity - however the listener should throw an exception, so the entity // shouldn't be persisted - EntityManager em = getEntityManager(); - em.getTransaction().begin(); - StrTestEntity te = new StrTestEntity("x"); - em.persist(te); - em.getTransaction().commit(); - } + EntityManager em = getEntityManager(); + em.getTransaction().begin(); + StrTestEntity te = new StrTestEntity( "x" ); + em.persist( te ); + em.getTransaction().commit(); + } - @Test - public void testDataNotPersisted() { + @Test + public void testDataNotPersisted() { // Checking if the entity became persisted EntityManager em = getEntityManager(); - em.getTransaction().begin(); - Long count = (Long) em.createQuery("select count(s) from StrTestEntity s where s.str = 'x'").getSingleResult(); + em.getTransaction().begin(); + Long count = (Long) em.createQuery( "select count(s) from StrTestEntity s where s.str = 'x'" ) + .getSingleResult(); assert count == 0l; - em.getTransaction().commit(); - } + em.getTransaction().commit(); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/ExceptionListenerRevEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/ExceptionListenerRevEntity.java index aaef924ed1..887f88f76c 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/ExceptionListenerRevEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/ExceptionListenerRevEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.reventity; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; @@ -37,55 +38,64 @@ import org.hibernate.envers.RevisionTimestamp; */ @Entity @GenericGenerator(name = "EnversTestingRevisionGenerator", - strategy = "org.hibernate.id.enhanced.TableGenerator", - parameters = {@Parameter(name = "table_name", value = "REVISION_GENERATOR"), - @Parameter(name = "initial_value", value = "1"), - @Parameter(name = "increment_size", value = "1"), - @Parameter(name = "prefer_entity_table_as_segment_value", value = "true") - } + strategy = "org.hibernate.id.enhanced.TableGenerator", + parameters = { + @Parameter(name = "table_name", value = "REVISION_GENERATOR"), + @Parameter(name = "initial_value", value = "1"), + @Parameter(name = "increment_size", value = "1"), + @Parameter(name = "prefer_entity_table_as_segment_value", value = "true") + } ) @RevisionEntity(TestExceptionRevisionListener.class) public class ExceptionListenerRevEntity { - @Id - @GeneratedValue(generator = "EnversTestingRevisionGenerator") - @RevisionNumber - private int id; + @Id + @GeneratedValue(generator = "EnversTestingRevisionGenerator") + @RevisionNumber + private int id; - @RevisionTimestamp - private long timestamp; + @RevisionTimestamp + private long timestamp; - public int getId() { - return id; - } + public int getId() { + return id; + } - public void setId(int id) { - this.id = id; - } + public void setId(int id) { + this.id = id; + } - public long getTimestamp() { - return timestamp; - } + public long getTimestamp() { + return timestamp; + } - public void setTimestamp(long timestamp) { - this.timestamp = timestamp; - } + public void setTimestamp(long timestamp) { + this.timestamp = timestamp; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ExceptionListenerRevEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ExceptionListenerRevEntity) ) { + return false; + } - ExceptionListenerRevEntity revEntity = (ExceptionListenerRevEntity) o; + ExceptionListenerRevEntity revEntity = (ExceptionListenerRevEntity) o; - if (id != revEntity.id) return false; - if (timestamp != revEntity.timestamp) return false; + if ( id != revEntity.id ) { + return false; + } + if ( timestamp != revEntity.timestamp ) { + return false; + } - return true; - } + return true; + } - 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; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/GloballyConfiguredRevListenerTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/GloballyConfiguredRevListenerTest.java index 00acda9ede..817d7ffcd6 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/GloballyConfiguredRevListenerTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/GloballyConfiguredRevListenerTest.java @@ -1,15 +1,16 @@ package org.hibernate.envers.test.integration.reventity; -import java.util.Map; import javax.persistence.EntityManager; - -import org.junit.Assert; -import org.junit.Test; +import java.util.Map; import org.hibernate.envers.configuration.EnversSettings; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrTestEntity; + +import org.junit.Assert; +import org.junit.Test; + import org.hibernate.testing.TestForIssue; /** @@ -19,28 +20,28 @@ import org.hibernate.testing.TestForIssue; public class GloballyConfiguredRevListenerTest extends BaseEnversJPAFunctionalTestCase { @Override protected Class[] getAnnotatedClasses() { - return new Class[] { StrTestEntity.class }; - } + return new Class[] {StrTestEntity.class}; + } @Override protected void addConfigOptions(Map options) { super.addConfigOptions( options ); - options.put(EnversSettings.REVISION_LISTENER, CountingRevisionListener.class.getName()); + options.put( EnversSettings.REVISION_LISTENER, CountingRevisionListener.class.getName() ); } @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - CountingRevisionListener.revisionCount = 0; + CountingRevisionListener.revisionCount = 0; - // Revision 1 - em.getTransaction().begin(); - StrTestEntity te = new StrTestEntity("data"); - em.persist(te); - em.getTransaction().commit(); + // Revision 1 + em.getTransaction().begin(); + StrTestEntity te = new StrTestEntity( "data" ); + em.persist( te ); + em.getTransaction().commit(); - Assert.assertEquals(1, CountingRevisionListener.revisionCount); - } + Assert.assertEquals( 1, CountingRevisionListener.revisionCount ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/Inherited.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/Inherited.java index 038219d650..8bf05f5d3b 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/Inherited.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/Inherited.java @@ -23,14 +23,12 @@ */ package org.hibernate.envers.test.integration.reventity; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.Date; import java.util.HashSet; import java.util.Map; import java.util.Set; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.AuditReader; import org.hibernate.envers.exception.RevisionDoesNotExistException; @@ -38,113 +36,116 @@ import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrTestEntity; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class Inherited extends BaseEnversJPAFunctionalTestCase { - private Integer id; - private long timestamp1; - private long timestamp2; - private long timestamp3; + private Integer id; + private long timestamp1; + private long timestamp2; + private long timestamp3; - protected Class[] getAnnotatedClasses() { - return new Class[]{StrTestEntity.class, InheritedRevEntity.class}; - } + protected Class[] getAnnotatedClasses() { + return new Class[] {StrTestEntity.class, InheritedRevEntity.class}; + } - @Test - @Priority(10) - public void initData() throws InterruptedException { - timestamp1 = System.currentTimeMillis(); + @Test + @Priority(10) + public void initData() throws InterruptedException { + timestamp1 = System.currentTimeMillis(); - Thread.sleep(100); + Thread.sleep( 100 ); - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); - StrTestEntity te = new StrTestEntity("x"); - em.persist(te); - id = te.getId(); - em.getTransaction().commit(); + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); + StrTestEntity te = new StrTestEntity( "x" ); + em.persist( te ); + id = te.getId(); + em.getTransaction().commit(); - timestamp2 = System.currentTimeMillis(); + timestamp2 = System.currentTimeMillis(); - Thread.sleep(100); + Thread.sleep( 100 ); - // Revision 2 - em.getTransaction().begin(); - te = em.find(StrTestEntity.class, id); - te.setStr("y"); - em.getTransaction().commit(); + // Revision 2 + em.getTransaction().begin(); + te = em.find( StrTestEntity.class, id ); + te.setStr( "y" ); + em.getTransaction().commit(); - timestamp3 = System.currentTimeMillis(); - } + timestamp3 = System.currentTimeMillis(); + } - @Test(expected = RevisionDoesNotExistException.class) - public void testTimestamps1() { - getAuditReader().getRevisionNumberForDate(new Date(timestamp1)); - } + @Test(expected = RevisionDoesNotExistException.class) + public void testTimestamps1() { + getAuditReader().getRevisionNumberForDate( new Date( timestamp1 ) ); + } - @Test - public void testTimestamps() { - assert getAuditReader().getRevisionNumberForDate(new Date(timestamp2)).intValue() == 1; - assert getAuditReader().getRevisionNumberForDate(new Date(timestamp3)).intValue() == 2; - } + @Test + public void testTimestamps() { + assert getAuditReader().getRevisionNumberForDate( new Date( timestamp2 ) ).intValue() == 1; + assert getAuditReader().getRevisionNumberForDate( new Date( timestamp3 ) ).intValue() == 2; + } - @Test - public void testDatesForRevisions() { - AuditReader vr = getAuditReader(); - assert vr.getRevisionNumberForDate(vr.getRevisionDate(1)).intValue() == 1; - assert vr.getRevisionNumberForDate(vr.getRevisionDate(2)).intValue() == 2; - } + @Test + public void testDatesForRevisions() { + AuditReader vr = getAuditReader(); + assert vr.getRevisionNumberForDate( vr.getRevisionDate( 1 ) ).intValue() == 1; + assert vr.getRevisionNumberForDate( vr.getRevisionDate( 2 ) ).intValue() == 2; + } - @Test - public void testRevisionsForDates() { - AuditReader vr = getAuditReader(); + @Test + public void testRevisionsForDates() { + AuditReader vr = getAuditReader(); - assert vr.getRevisionDate(vr.getRevisionNumberForDate(new Date(timestamp2))).getTime() <= timestamp2; - assert vr.getRevisionDate(vr.getRevisionNumberForDate(new Date(timestamp2)).intValue()+1).getTime() > timestamp2; + assert vr.getRevisionDate( vr.getRevisionNumberForDate( new Date( timestamp2 ) ) ).getTime() <= timestamp2; + assert vr.getRevisionDate( vr.getRevisionNumberForDate( new Date( timestamp2 ) ).intValue() + 1 ) + .getTime() > timestamp2; - assert vr.getRevisionDate(vr.getRevisionNumberForDate(new Date(timestamp3))).getTime() <= timestamp3; - } + assert vr.getRevisionDate( vr.getRevisionNumberForDate( new Date( timestamp3 ) ) ).getTime() <= timestamp3; + } - @Test - public void testFindRevision() { - AuditReader vr = getAuditReader(); + @Test + public void testFindRevision() { + AuditReader vr = getAuditReader(); - long rev1Timestamp = vr.findRevision(InheritedRevEntity.class, 1).getTimestamp(); - assert rev1Timestamp > timestamp1; - assert rev1Timestamp <= timestamp2; + long rev1Timestamp = vr.findRevision( InheritedRevEntity.class, 1 ).getTimestamp(); + assert rev1Timestamp > timestamp1; + assert rev1Timestamp <= timestamp2; - long rev2Timestamp = vr.findRevision(InheritedRevEntity.class, 2).getTimestamp(); - assert rev2Timestamp > timestamp2; - assert rev2Timestamp <= timestamp3; - } + long rev2Timestamp = vr.findRevision( InheritedRevEntity.class, 2 ).getTimestamp(); + assert rev2Timestamp > timestamp2; + assert rev2Timestamp <= timestamp3; + } - @Test - public void testFindRevisions() { - AuditReader vr = getAuditReader(); + @Test + public void testFindRevisions() { + AuditReader vr = getAuditReader(); - Set revNumbers = new HashSet(); - revNumbers.add(1); - revNumbers.add(2); + Set revNumbers = new HashSet(); + revNumbers.add( 1 ); + revNumbers.add( 2 ); - Map revisionMap = vr.findRevisions(InheritedRevEntity.class, revNumbers); - assert(revisionMap.size() == 2); - assert(revisionMap.get(1).equals(vr.findRevision(InheritedRevEntity.class, 1))); - assert(revisionMap.get(2).equals(vr.findRevision(InheritedRevEntity.class, 2))); - } + Map revisionMap = vr.findRevisions( InheritedRevEntity.class, revNumbers ); + assert (revisionMap.size() == 2); + assert (revisionMap.get( 1 ).equals( vr.findRevision( InheritedRevEntity.class, 1 ) )); + assert (revisionMap.get( 2 ).equals( vr.findRevision( InheritedRevEntity.class, 2 ) )); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(StrTestEntity.class, id)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( StrTestEntity.class, id ) ); + } - @Test - public void testHistoryOfId1() { - StrTestEntity ver1 = new StrTestEntity("x", id); - StrTestEntity ver2 = new StrTestEntity("y", id); + @Test + public void testHistoryOfId1() { + StrTestEntity ver1 = new StrTestEntity( "x", id ); + StrTestEntity ver2 = new StrTestEntity( "y", id ); - assert getAuditReader().find(StrTestEntity.class, id, 1).equals(ver1); - assert getAuditReader().find(StrTestEntity.class, id, 2).equals(ver2); - } + assert getAuditReader().find( StrTestEntity.class, id, 1 ).equals( ver1 ); + assert getAuditReader().find( StrTestEntity.class, id, 2 ).equals( ver2 ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/Listener.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/Listener.java index daf5cd8881..02d81d9d84 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/Listener.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/Listener.java @@ -23,14 +23,12 @@ */ package org.hibernate.envers.test.integration.reventity; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.Date; import java.util.HashSet; import java.util.Map; import java.util.Set; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.AuditReader; import org.hibernate.envers.exception.RevisionDoesNotExistException; @@ -38,127 +36,130 @@ import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrTestEntity; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class Listener extends BaseEnversJPAFunctionalTestCase { - private Integer id; - private long timestamp1; - private long timestamp2; - private long timestamp3; + private Integer id; + private long timestamp1; + private long timestamp2; + private long timestamp3; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { StrTestEntity.class, ListenerRevEntity.class }; - } + return new Class[] {StrTestEntity.class, ListenerRevEntity.class}; + } - @Test - @Priority(10) - public void initData() throws InterruptedException { - timestamp1 = System.currentTimeMillis(); + @Test + @Priority(10) + public void initData() throws InterruptedException { + timestamp1 = System.currentTimeMillis(); - Thread.sleep(100); + Thread.sleep( 100 ); - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); - TestRevisionListener.data = "data1"; + TestRevisionListener.data = "data1"; - StrTestEntity te = new StrTestEntity("x"); - em.persist(te); - id = te.getId(); - em.getTransaction().commit(); + StrTestEntity te = new StrTestEntity( "x" ); + em.persist( te ); + id = te.getId(); + em.getTransaction().commit(); - timestamp2 = System.currentTimeMillis(); + timestamp2 = System.currentTimeMillis(); - Thread.sleep(100); + Thread.sleep( 100 ); - // Revision 2 - em.getTransaction().begin(); - te = em.find(StrTestEntity.class, id); + // Revision 2 + em.getTransaction().begin(); + te = em.find( StrTestEntity.class, id ); - TestRevisionListener.data = "data2"; + TestRevisionListener.data = "data2"; - te.setStr("y"); - em.getTransaction().commit(); + te.setStr( "y" ); + em.getTransaction().commit(); - timestamp3 = System.currentTimeMillis(); - } + timestamp3 = System.currentTimeMillis(); + } - @Test(expected = RevisionDoesNotExistException.class) - public void testTimestamps1() { - getAuditReader().getRevisionNumberForDate(new Date(timestamp1)); - } + @Test(expected = RevisionDoesNotExistException.class) + public void testTimestamps1() { + getAuditReader().getRevisionNumberForDate( new Date( timestamp1 ) ); + } - @Test - public void testTimestamps() { - assert getAuditReader().getRevisionNumberForDate(new Date(timestamp2)).intValue() == 1; - assert getAuditReader().getRevisionNumberForDate(new Date(timestamp3)).intValue() == 2; - } + @Test + public void testTimestamps() { + assert getAuditReader().getRevisionNumberForDate( new Date( timestamp2 ) ).intValue() == 1; + assert getAuditReader().getRevisionNumberForDate( new Date( timestamp3 ) ).intValue() == 2; + } - @Test - public void testDatesForRevisions() { - AuditReader vr = getAuditReader(); - assert vr.getRevisionNumberForDate(vr.getRevisionDate(1)).intValue() == 1; - assert vr.getRevisionNumberForDate(vr.getRevisionDate(2)).intValue() == 2; - } + @Test + public void testDatesForRevisions() { + AuditReader vr = getAuditReader(); + assert vr.getRevisionNumberForDate( vr.getRevisionDate( 1 ) ).intValue() == 1; + assert vr.getRevisionNumberForDate( vr.getRevisionDate( 2 ) ).intValue() == 2; + } - @Test - public void testRevisionsForDates() { - AuditReader vr = getAuditReader(); + @Test + public void testRevisionsForDates() { + AuditReader vr = getAuditReader(); - assert vr.getRevisionDate(vr.getRevisionNumberForDate(new Date(timestamp2))).getTime() <= timestamp2; - assert vr.getRevisionDate(vr.getRevisionNumberForDate(new Date(timestamp2)).intValue()+1).getTime() > timestamp2; + assert vr.getRevisionDate( vr.getRevisionNumberForDate( new Date( timestamp2 ) ) ).getTime() <= timestamp2; + assert vr.getRevisionDate( vr.getRevisionNumberForDate( new Date( timestamp2 ) ).intValue() + 1 ) + .getTime() > timestamp2; - assert vr.getRevisionDate(vr.getRevisionNumberForDate(new Date(timestamp3))).getTime() <= timestamp3; - } + assert vr.getRevisionDate( vr.getRevisionNumberForDate( new Date( timestamp3 ) ) ).getTime() <= timestamp3; + } - @Test - public void testFindRevision() { - AuditReader vr = getAuditReader(); + @Test + public void testFindRevision() { + AuditReader vr = getAuditReader(); - ListenerRevEntity rev1Data = vr.findRevision(ListenerRevEntity.class, 1); - ListenerRevEntity rev2Data = vr.findRevision(ListenerRevEntity.class, 2); + ListenerRevEntity rev1Data = vr.findRevision( ListenerRevEntity.class, 1 ); + ListenerRevEntity rev2Data = vr.findRevision( ListenerRevEntity.class, 2 ); - long rev1Timestamp = rev1Data.getTimestamp(); - assert rev1Timestamp > timestamp1; - assert rev1Timestamp <= timestamp2; + long rev1Timestamp = rev1Data.getTimestamp(); + assert rev1Timestamp > timestamp1; + assert rev1Timestamp <= timestamp2; - assert "data1".equals(rev1Data.getData()); + assert "data1".equals( rev1Data.getData() ); - long rev2Timestamp = rev2Data.getTimestamp(); - assert rev2Timestamp > timestamp2; - assert rev2Timestamp <= timestamp3; + long rev2Timestamp = rev2Data.getTimestamp(); + assert rev2Timestamp > timestamp2; + assert rev2Timestamp <= timestamp3; - assert "data2".equals(rev2Data.getData()); - } + assert "data2".equals( rev2Data.getData() ); + } - @Test - public void testFindRevisions() { - AuditReader vr = getAuditReader(); + @Test + public void testFindRevisions() { + AuditReader vr = getAuditReader(); - Set revNumbers = new HashSet(); - revNumbers.add(1); - revNumbers.add(2); - - Map revisionMap = vr.findRevisions(ListenerRevEntity.class, revNumbers); - assert(revisionMap.size() == 2); - assert(revisionMap.get(1).equals(vr.findRevision(ListenerRevEntity.class, 1))); - assert(revisionMap.get(2).equals(vr.findRevision(ListenerRevEntity.class, 2))); - } + Set revNumbers = new HashSet(); + revNumbers.add( 1 ); + revNumbers.add( 2 ); - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(StrTestEntity.class, id)); - } + Map revisionMap = vr.findRevisions( ListenerRevEntity.class, revNumbers ); + assert (revisionMap.size() == 2); + assert (revisionMap.get( 1 ).equals( vr.findRevision( ListenerRevEntity.class, 1 ) )); + assert (revisionMap.get( 2 ).equals( vr.findRevision( ListenerRevEntity.class, 2 ) )); + } - @Test - public void testHistoryOfId1() { - StrTestEntity ver1 = new StrTestEntity("x", id); - StrTestEntity ver2 = new StrTestEntity("y", id); + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( StrTestEntity.class, id ) ); + } - assert getAuditReader().find(StrTestEntity.class, id, 1).equals(ver1); - assert getAuditReader().find(StrTestEntity.class, id, 2).equals(ver2); - } + @Test + public void testHistoryOfId1() { + StrTestEntity ver1 = new StrTestEntity( "x", id ); + StrTestEntity ver2 = new StrTestEntity( "y", id ); + + assert getAuditReader().find( StrTestEntity.class, id, 1 ).equals( ver1 ); + assert getAuditReader().find( StrTestEntity.class, id, 2 ).equals( ver2 ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/ListenerRevEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/ListenerRevEntity.java index 8f5111a117..040c32403a 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/ListenerRevEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/ListenerRevEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.reventity; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; @@ -37,65 +38,74 @@ import org.hibernate.envers.RevisionTimestamp; */ @Entity @GenericGenerator(name = "EnversTestingRevisionGenerator", - strategy = "org.hibernate.id.enhanced.TableGenerator", - parameters = {@Parameter(name = "table_name", value = "REVISION_GENERATOR"), - @Parameter(name = "initial_value", value = "1"), - @Parameter(name = "increment_size", value = "1"), - @Parameter(name = "prefer_entity_table_as_segment_value", value = "true") - } + strategy = "org.hibernate.id.enhanced.TableGenerator", + parameters = { + @Parameter(name = "table_name", value = "REVISION_GENERATOR"), + @Parameter(name = "initial_value", value = "1"), + @Parameter(name = "increment_size", value = "1"), + @Parameter(name = "prefer_entity_table_as_segment_value", value = "true") + } ) @RevisionEntity(TestRevisionListener.class) public class ListenerRevEntity { - @Id - @GeneratedValue(generator = "EnversTestingRevisionGenerator") - @RevisionNumber - private int id; + @Id + @GeneratedValue(generator = "EnversTestingRevisionGenerator") + @RevisionNumber + private int id; - @RevisionTimestamp - private long timestamp; + @RevisionTimestamp + private long timestamp; - private String data; + private String data; - public int getId() { - return id; - } + public int getId() { + return id; + } - public void setId(int id) { - this.id = id; - } + public void setId(int id) { + this.id = id; + } - public long getTimestamp() { - return timestamp; - } + public long getTimestamp() { + return timestamp; + } - public void setTimestamp(long timestamp) { - this.timestamp = timestamp; - } + public void setTimestamp(long timestamp) { + this.timestamp = timestamp; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ListenerRevEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ListenerRevEntity) ) { + return false; + } - ListenerRevEntity revEntity = (ListenerRevEntity) o; + ListenerRevEntity revEntity = (ListenerRevEntity) o; - if (id != revEntity.id) return false; - if (timestamp != revEntity.timestamp) return false; + if ( id != revEntity.id ) { + return false; + } + if ( timestamp != revEntity.timestamp ) { + return false; + } - return true; - } + return true; + } - 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; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/LongRevEntityInheritanceChildAuditing.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/LongRevEntityInheritanceChildAuditing.java index 1d6e090c11..c73030cd11 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/LongRevEntityInheritanceChildAuditing.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/LongRevEntityInheritanceChildAuditing.java @@ -26,36 +26,37 @@ package org.hibernate.envers.test.integration.reventity; import java.util.Iterator; -import org.junit.Test; - import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.integration.inheritance.joined.ChildEntity; import org.hibernate.envers.test.integration.inheritance.joined.ParentEntity; import org.hibernate.mapping.Column; +import org.junit.Test; + import static org.junit.Assert.assertEquals; /** * A join-inheritance test using a custom revision entity where the revision number is a long, mapped in the database * as an int. + * * @author Adam Warski (adam at warski dot org) */ public class LongRevEntityInheritanceChildAuditing extends BaseEnversJPAFunctionalTestCase { @Override protected Class[] getAnnotatedClasses() { - return new Class[] { ChildEntity.class, ParentEntity.class, LongRevNumberRevEntity.class }; - } + return new Class[] {ChildEntity.class, ParentEntity.class, LongRevNumberRevEntity.class}; + } - @Test - public void testChildRevColumnType() { - // We need the second column - Iterator childEntityKeyColumnsIterator = getCfg() - .getClassMapping("org.hibernate.envers.test.integration.inheritance.joined.ChildEntity_AUD") - .getKey() - .getColumnIterator(); - childEntityKeyColumnsIterator.next(); - Column second = (Column) childEntityKeyColumnsIterator.next(); + @Test + public void testChildRevColumnType() { + // We need the second column + Iterator childEntityKeyColumnsIterator = getCfg() + .getClassMapping( "org.hibernate.envers.test.integration.inheritance.joined.ChildEntity_AUD" ) + .getKey() + .getColumnIterator(); + childEntityKeyColumnsIterator.next(); + Column second = (Column) childEntityKeyColumnsIterator.next(); - assertEquals(second.getSqlType(), "int"); - } + assertEquals( second.getSqlType(), "int" ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/LongRevNumber.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/LongRevNumber.java index d450830366..a10bf14e51 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/LongRevNumber.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/LongRevNumber.java @@ -23,81 +23,81 @@ */ package org.hibernate.envers.test.integration.reventity; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.HashSet; import java.util.Map; import java.util.Set; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.AuditReader; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrTestEntity; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class LongRevNumber extends BaseEnversJPAFunctionalTestCase { - private Integer id; + private Integer id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { StrTestEntity.class, LongRevNumberRevEntity.class }; - } + return new Class[] {StrTestEntity.class, LongRevNumberRevEntity.class}; + } - @Test - @Priority(10) - public void initData() throws InterruptedException { - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); - StrTestEntity te = new StrTestEntity("x"); - em.persist(te); - id = te.getId(); - em.getTransaction().commit(); + @Test + @Priority(10) + public void initData() throws InterruptedException { + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); + StrTestEntity te = new StrTestEntity( "x" ); + em.persist( te ); + id = te.getId(); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); - te = em.find(StrTestEntity.class, id); - te.setStr("y"); - em.getTransaction().commit(); - } + // Revision 2 + em.getTransaction().begin(); + te = em.find( StrTestEntity.class, id ); + te.setStr( "y" ); + em.getTransaction().commit(); + } - @Test - public void testFindRevision() { - AuditReader vr = getAuditReader(); + @Test + public void testFindRevision() { + AuditReader vr = getAuditReader(); - assert vr.findRevision(LongRevNumberRevEntity.class, 1l).getCustomId() == 1l; - assert vr.findRevision(LongRevNumberRevEntity.class, 2l).getCustomId() == 2l; - } + assert vr.findRevision( LongRevNumberRevEntity.class, 1l ).getCustomId() == 1l; + assert vr.findRevision( LongRevNumberRevEntity.class, 2l ).getCustomId() == 2l; + } - @Test - public void testFindRevisions() { - AuditReader vr = getAuditReader(); + @Test + public void testFindRevisions() { + AuditReader vr = getAuditReader(); - Set revNumbers = new HashSet(); - revNumbers.add(1l); - revNumbers.add(2l); - - Map revisionMap = vr.findRevisions(LongRevNumberRevEntity.class, revNumbers); - assert(revisionMap.size() == 2); - assert(revisionMap.get(1l).equals(vr.findRevision(LongRevNumberRevEntity.class, 1l))); - assert(revisionMap.get(2l).equals(vr.findRevision(LongRevNumberRevEntity.class, 2l))); - } + Set revNumbers = new HashSet(); + revNumbers.add( 1l ); + revNumbers.add( 2l ); - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1l, 2l).equals(getAuditReader().getRevisions(StrTestEntity.class, id)); - } + Map revisionMap = vr.findRevisions( LongRevNumberRevEntity.class, revNumbers ); + assert (revisionMap.size() == 2); + assert (revisionMap.get( 1l ).equals( vr.findRevision( LongRevNumberRevEntity.class, 1l ) )); + assert (revisionMap.get( 2l ).equals( vr.findRevision( LongRevNumberRevEntity.class, 2l ) )); + } - @Test - public void testHistoryOfId1() { - StrTestEntity ver1 = new StrTestEntity("x", id); - StrTestEntity ver2 = new StrTestEntity("y", id); + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1l, 2l ).equals( getAuditReader().getRevisions( StrTestEntity.class, id ) ); + } - assert getAuditReader().find(StrTestEntity.class, id, 1l).equals(ver1); - assert getAuditReader().find(StrTestEntity.class, id, 2l).equals(ver2); - } + @Test + public void testHistoryOfId1() { + StrTestEntity ver1 = new StrTestEntity( "x", id ); + StrTestEntity ver2 = new StrTestEntity( "y", id ); + + assert getAuditReader().find( StrTestEntity.class, id, 1l ).equals( ver1 ); + assert getAuditReader().find( StrTestEntity.class, id, 2l ).equals( ver2 ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/LongRevNumberRevEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/LongRevNumberRevEntity.java index 997617cde9..f5bf854b1a 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/LongRevNumberRevEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/LongRevNumberRevEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.reventity; + import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -38,56 +39,65 @@ import org.hibernate.envers.RevisionTimestamp; */ @Entity @GenericGenerator(name = "EnversTestingRevisionGenerator", - strategy = "org.hibernate.id.enhanced.TableGenerator", - parameters = {@Parameter(name = "table_name", value = "REVISION_GENERATOR"), - @Parameter(name = "initial_value", value = "1"), - @Parameter(name = "increment_size", value = "1"), - @Parameter(name = "prefer_entity_table_as_segment_value", value = "true") - } + strategy = "org.hibernate.id.enhanced.TableGenerator", + parameters = { + @Parameter(name = "table_name", value = "REVISION_GENERATOR"), + @Parameter(name = "initial_value", value = "1"), + @Parameter(name = "increment_size", value = "1"), + @Parameter(name = "prefer_entity_table_as_segment_value", value = "true") + } ) @RevisionEntity public class LongRevNumberRevEntity { - @Id - @GeneratedValue(generator = "EnversTestingRevisionGenerator") - @RevisionNumber - @Column(columnDefinition = "int") - private long customId; + @Id + @GeneratedValue(generator = "EnversTestingRevisionGenerator") + @RevisionNumber + @Column(columnDefinition = "int") + private long customId; - @RevisionTimestamp - private long customTimestamp; + @RevisionTimestamp + private long customTimestamp; - public long getCustomId() { - return customId; - } + public long getCustomId() { + return customId; + } - public void setCustomId(long customId) { - this.customId = customId; - } + public void setCustomId(long customId) { + this.customId = customId; + } - public long getCustomTimestamp() { - return customTimestamp; - } + public long getCustomTimestamp() { + return customTimestamp; + } - public void setCustomTimestamp(long customTimestamp) { - this.customTimestamp = customTimestamp; - } + public void setCustomTimestamp(long customTimestamp) { + this.customTimestamp = customTimestamp; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof LongRevNumberRevEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof LongRevNumberRevEntity) ) { + return false; + } - LongRevNumberRevEntity that = (LongRevNumberRevEntity) o; + LongRevNumberRevEntity that = (LongRevNumberRevEntity) o; - if (customId != that.customId) return false; - if (customTimestamp != that.customTimestamp) return false; + if ( customId != that.customId ) { + return false; + } + if ( customTimestamp != that.customTimestamp ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (int) (customId ^ (customId >>> 32)); - result = 31 * result + (int) (customTimestamp ^ (customTimestamp >>> 32)); - return result; - } + public int hashCode() { + int result; + result = (int) (customId ^ (customId >>> 32)); + result = 31 * result + (int) (customTimestamp ^ (customTimestamp >>> 32)); + return result; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/MonotonicRevisionNumberTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/MonotonicRevisionNumberTest.java index e42dbd66d0..1f33a17b19 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/MonotonicRevisionNumberTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/MonotonicRevisionNumberTest.java @@ -1,8 +1,5 @@ package org.hibernate.envers.test.integration.reventity; -import org.junit.Assert; -import org.junit.Test; - import org.hibernate.dialect.Oracle8iDialect; import org.hibernate.envers.enhanced.OrderedSequenceGenerator; import org.hibernate.envers.enhanced.SequenceIdRevisionEntity; @@ -10,6 +7,10 @@ import org.hibernate.envers.test.BaseEnversFunctionalTestCase; import org.hibernate.envers.test.entities.StrIntTestEntity; import org.hibernate.id.IdentifierGenerator; import org.hibernate.persister.entity.EntityPersister; + +import org.junit.Assert; +import org.junit.Test; + import org.hibernate.testing.RequiresDialect; import org.hibernate.testing.TestForIssue; @@ -21,7 +22,7 @@ import org.hibernate.testing.TestForIssue; public class MonotonicRevisionNumberTest extends BaseEnversFunctionalTestCase { @Override protected Class[] getAnnotatedClasses() { - return new Class[]{ StrIntTestEntity.class }; // Otherwise revision entity is not generated. + return new Class[] {StrIntTestEntity.class}; // Otherwise revision entity is not generated. } @Test diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/OverrideCustomRevListenerTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/OverrideCustomRevListenerTest.java index ccaf0f5aea..96e840bca7 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/OverrideCustomRevListenerTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/OverrideCustomRevListenerTest.java @@ -1,6 +1,7 @@ package org.hibernate.envers.test.integration.reventity; import org.hibernate.internal.util.collections.ArrayHelper; + import org.hibernate.testing.TestForIssue; /** @@ -11,5 +12,5 @@ public class OverrideCustomRevListenerTest extends GloballyConfiguredRevListener @Override protected Class[] getAnnotatedClasses() { return ArrayHelper.join( super.getAnnotatedClasses(), ListenerRevEntity.class ); - } + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/OverrideDefaultRevListenerTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/OverrideDefaultRevListenerTest.java index 097dd41932..d0acecb3ef 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/OverrideDefaultRevListenerTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/OverrideDefaultRevListenerTest.java @@ -1,6 +1,7 @@ package org.hibernate.envers.test.integration.reventity; import org.hibernate.internal.util.collections.ArrayHelper; + import org.hibernate.testing.TestForIssue; /** @@ -11,5 +12,5 @@ public class OverrideDefaultRevListenerTest extends GloballyConfiguredRevListene @Override protected Class[] getAnnotatedClasses() { return ArrayHelper.join( super.getAnnotatedClasses(), LongRevNumberRevEntity.class ); - } + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/TestExceptionRevisionListener.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/TestExceptionRevisionListener.java index 130555b81e..cdc1650169 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/TestExceptionRevisionListener.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/TestExceptionRevisionListener.java @@ -29,7 +29,7 @@ import org.hibernate.envers.RevisionListener; * @author Adam Warski (adam at warski dot org) */ public class TestExceptionRevisionListener implements RevisionListener { - public void newRevision(Object revisionEntity) { - throw new RuntimeException( "forcing transaction failure!" ); - } + public void newRevision(Object revisionEntity) { + throw new RuntimeException( "forcing transaction failure!" ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/TestRevisionListener.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/TestRevisionListener.java index 6f353be284..4ebe846e01 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/TestRevisionListener.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/TestRevisionListener.java @@ -22,15 +22,16 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.reventity; + import org.hibernate.envers.RevisionListener; /** * @author Adam Warski (adam at warski dot org) */ public class TestRevisionListener implements RevisionListener { - public static String data = "data0"; + public static String data = "data0"; - public void newRevision(Object revisionEntity) { - ((ListenerRevEntity) revisionEntity).setData(data); - } + public void newRevision(Object revisionEntity) { + ((ListenerRevEntity) revisionEntity).setData( data ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/trackmodifiedentities/AnnotatedTrackingEntitiesTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/trackmodifiedentities/AnnotatedTrackingEntitiesTest.java index 2d1255dcd4..229251a544 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/trackmodifiedentities/AnnotatedTrackingEntitiesTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/trackmodifiedentities/AnnotatedTrackingEntitiesTest.java @@ -9,17 +9,18 @@ import org.hibernate.internal.util.collections.ArrayHelper; /** * Tests proper behavior of revision entity that utilizes {@link ModifiedEntityNames} annotation. + * * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public class AnnotatedTrackingEntitiesTest extends DefaultTrackingEntitiesTest { @Override protected Class[] getAnnotatedClasses() { return ArrayHelper.join( super.getAnnotatedClasses(), AnnotatedTrackingRevisionEntity.class ); - } + } @Override public void addConfigOptions(Map configuration) { super.addConfigOptions( configuration ); - configuration.put(EnversSettings.TRACK_ENTITIES_CHANGED_IN_REVISION, "false"); + configuration.put( EnversSettings.TRACK_ENTITIES_CHANGED_IN_REVISION, "false" ); } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/trackmodifiedentities/CustomTrackingEntitiesTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/trackmodifiedentities/CustomTrackingEntitiesTest.java index 64d4dd7dd2..7d79a34240 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/trackmodifiedentities/CustomTrackingEntitiesTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/trackmodifiedentities/CustomTrackingEntitiesTest.java @@ -2,8 +2,6 @@ package org.hibernate.envers.test.integration.reventity.trackmodifiedentities; import javax.persistence.EntityManager; -import org.junit.Test; - import org.hibernate.envers.EntityTrackingRevisionListener; import org.hibernate.envers.exception.AuditException; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; @@ -15,16 +13,19 @@ import org.hibernate.envers.test.entities.reventity.trackmodifiedentities.Custom import org.hibernate.envers.test.entities.reventity.trackmodifiedentities.ModifiedEntityTypeEntity; import org.hibernate.envers.test.tools.TestTools; +import org.junit.Test; + /** * Tests proper behavior of entity listener that implements {@link EntityTrackingRevisionListener} * interface. {@link CustomTrackingRevisionListener} shall be notified whenever an entity instance has been * added, modified or removed, so that changed entity name can be persisted. + * * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public class CustomTrackingEntitiesTest extends BaseEnversJPAFunctionalTestCase { - private Integer steId = null; - private Integer siteId = null; + private Integer steId = null; + private Integer siteId = null; @Override protected Class[] getAnnotatedClasses() { @@ -34,75 +35,75 @@ public class CustomTrackingEntitiesTest extends BaseEnversJPAFunctionalTestCase StrIntTestEntity.class, CustomTrackingRevisionEntity.class }; - } + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - // Revision 1 - Adding two entities - em.getTransaction().begin(); - StrTestEntity ste = new StrTestEntity("x"); - StrIntTestEntity site = new StrIntTestEntity("y", 1); - em.persist(ste); - em.persist(site); - steId = ste.getId(); - siteId = site.getId(); - em.getTransaction().commit(); + // Revision 1 - Adding two entities + em.getTransaction().begin(); + StrTestEntity ste = new StrTestEntity( "x" ); + StrIntTestEntity site = new StrIntTestEntity( "y", 1 ); + em.persist( ste ); + em.persist( site ); + steId = ste.getId(); + siteId = site.getId(); + em.getTransaction().commit(); - // Revision 2 - Modifying one entity - em.getTransaction().begin(); - site = em.find(StrIntTestEntity.class, siteId); - site.setNumber(2); - em.getTransaction().commit(); + // Revision 2 - Modifying one entity + em.getTransaction().begin(); + site = em.find( StrIntTestEntity.class, siteId ); + site.setNumber( 2 ); + em.getTransaction().commit(); - // Revision 3 - Deleting both entities - em.getTransaction().begin(); - ste = em.find(StrTestEntity.class, steId); - site = em.find(StrIntTestEntity.class, siteId); - em.remove(ste); - em.remove(site); - em.getTransaction().commit(); - } + // Revision 3 - Deleting both entities + em.getTransaction().begin(); + ste = em.find( StrTestEntity.class, steId ); + site = em.find( StrIntTestEntity.class, siteId ); + em.remove( ste ); + em.remove( site ); + em.getTransaction().commit(); + } - @Test - public void testTrackAddedEntities() { - ModifiedEntityTypeEntity steDescriptor = new ModifiedEntityTypeEntity(StrTestEntity.class.getName()); - ModifiedEntityTypeEntity siteDescriptor = new ModifiedEntityTypeEntity(StrIntTestEntity.class.getName()); + @Test + public void testTrackAddedEntities() { + ModifiedEntityTypeEntity steDescriptor = new ModifiedEntityTypeEntity( StrTestEntity.class.getName() ); + ModifiedEntityTypeEntity siteDescriptor = new ModifiedEntityTypeEntity( StrIntTestEntity.class.getName() ); - CustomTrackingRevisionEntity ctre = getAuditReader().findRevision(CustomTrackingRevisionEntity.class, 1); + CustomTrackingRevisionEntity ctre = getAuditReader().findRevision( CustomTrackingRevisionEntity.class, 1 ); - assert ctre.getModifiedEntityTypes() != null; - assert ctre.getModifiedEntityTypes().size() == 2; - assert TestTools.makeSet(steDescriptor, siteDescriptor).equals(ctre.getModifiedEntityTypes()); - } + assert ctre.getModifiedEntityTypes() != null; + assert ctre.getModifiedEntityTypes().size() == 2; + assert TestTools.makeSet( steDescriptor, siteDescriptor ).equals( ctre.getModifiedEntityTypes() ); + } - @Test - public void testTrackModifiedEntities() { - ModifiedEntityTypeEntity siteDescriptor = new ModifiedEntityTypeEntity(StrIntTestEntity.class.getName()); + @Test + public void testTrackModifiedEntities() { + ModifiedEntityTypeEntity siteDescriptor = new ModifiedEntityTypeEntity( StrIntTestEntity.class.getName() ); - CustomTrackingRevisionEntity ctre = getAuditReader().findRevision(CustomTrackingRevisionEntity.class, 2); + CustomTrackingRevisionEntity ctre = getAuditReader().findRevision( CustomTrackingRevisionEntity.class, 2 ); - assert ctre.getModifiedEntityTypes() != null; - assert ctre.getModifiedEntityTypes().size() == 1; - assert TestTools.makeSet(siteDescriptor).equals(ctre.getModifiedEntityTypes()); - } + assert ctre.getModifiedEntityTypes() != null; + assert ctre.getModifiedEntityTypes().size() == 1; + assert TestTools.makeSet( siteDescriptor ).equals( ctre.getModifiedEntityTypes() ); + } - @Test - public void testTrackDeletedEntities() { - ModifiedEntityTypeEntity steDescriptor = new ModifiedEntityTypeEntity(StrTestEntity.class.getName()); - ModifiedEntityTypeEntity siteDescriptor = new ModifiedEntityTypeEntity(StrIntTestEntity.class.getName()); + @Test + public void testTrackDeletedEntities() { + ModifiedEntityTypeEntity steDescriptor = new ModifiedEntityTypeEntity( StrTestEntity.class.getName() ); + ModifiedEntityTypeEntity siteDescriptor = new ModifiedEntityTypeEntity( StrIntTestEntity.class.getName() ); - CustomTrackingRevisionEntity ctre = getAuditReader().findRevision(CustomTrackingRevisionEntity.class, 3); + CustomTrackingRevisionEntity ctre = getAuditReader().findRevision( CustomTrackingRevisionEntity.class, 3 ); - assert ctre.getModifiedEntityTypes() != null; - assert ctre.getModifiedEntityTypes().size() == 2; - assert TestTools.makeSet(steDescriptor, siteDescriptor).equals(ctre.getModifiedEntityTypes()); - } + assert ctre.getModifiedEntityTypes() != null; + assert ctre.getModifiedEntityTypes().size() == 2; + assert TestTools.makeSet( steDescriptor, siteDescriptor ).equals( ctre.getModifiedEntityTypes() ); + } - @Test(expected = AuditException.class) - public void testFindEntitiesChangedInRevisionException() { - getAuditReader().getCrossTypeRevisionChangesReader(); - } + @Test(expected = AuditException.class) + public void testFindEntitiesChangedInRevisionException() { + getAuditReader().getCrossTypeRevisionChangesReader(); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/trackmodifiedentities/DefaultTrackingEntitiesTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/trackmodifiedentities/DefaultTrackingEntitiesTest.java index 3865b63b90..2cf39b0101 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/trackmodifiedentities/DefaultTrackingEntitiesTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/trackmodifiedentities/DefaultTrackingEntitiesTest.java @@ -1,11 +1,9 @@ package org.hibernate.envers.test.integration.reventity.trackmodifiedentities; +import javax.persistence.EntityManager; import java.util.Iterator; import java.util.List; import java.util.Map; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.CrossTypeRevisionChangesReader; import org.hibernate.envers.RevisionType; @@ -19,170 +17,185 @@ import org.hibernate.envers.tools.Pair; import org.hibernate.mapping.Column; import org.hibernate.mapping.Table; +import org.junit.Test; + /** * Tests proper behavior of tracking modified entity names 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) */ @SuppressWarnings({"unchecked"}) public class DefaultTrackingEntitiesTest extends BaseEnversJPAFunctionalTestCase { - private Integer steId = null; - private Integer siteId = null; + private Integer steId = null; + private Integer siteId = null; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { StrTestEntity.class, StrIntTestEntity.class }; - } + return new Class[] {StrTestEntity.class, StrIntTestEntity.class}; + } @Override public void addConfigOptions(Map configuration) { super.addConfigOptions( configuration ); - configuration.put(EnversSettings.TRACK_ENTITIES_CHANGED_IN_REVISION, "true"); + configuration.put( EnversSettings.TRACK_ENTITIES_CHANGED_IN_REVISION, "true" ); } @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); - - // Revision 1 - Adding two entities - em.getTransaction().begin(); - StrTestEntity ste = new StrTestEntity("x"); - StrIntTestEntity site = new StrIntTestEntity("y", 1); - em.persist(ste); - em.persist(site); - steId = ste.getId(); - siteId = site.getId(); - em.getTransaction().commit(); + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - // Revision 2 - Modifying one entity - em.getTransaction().begin(); - site = em.find(StrIntTestEntity.class, siteId); - site.setNumber(2); - em.getTransaction().commit(); + // Revision 1 - Adding two entities + em.getTransaction().begin(); + StrTestEntity ste = new StrTestEntity( "x" ); + StrIntTestEntity site = new StrIntTestEntity( "y", 1 ); + em.persist( ste ); + em.persist( site ); + steId = ste.getId(); + siteId = site.getId(); + em.getTransaction().commit(); - // Revision 3 - Deleting both entities - em.getTransaction().begin(); - ste = em.find(StrTestEntity.class, steId); - site = em.find(StrIntTestEntity.class, siteId); - em.remove(ste); - em.remove(site); - em.getTransaction().commit(); - } + // Revision 2 - Modifying one entity + em.getTransaction().begin(); + site = em.find( StrIntTestEntity.class, siteId ); + site.setNumber( 2 ); + em.getTransaction().commit(); - @Test - public void testRevEntityTableCreation() { - Iterator tableIterator = getCfg().getTableMappings(); - while (tableIterator.hasNext()) { - Table table = tableIterator.next(); - if ("REVCHANGES".equals(table.getName())) { - assert table.getColumnSpan() == 2; - assert table.getColumn(new Column("REV")) != null; - assert table.getColumn(new Column("ENTITYNAME")) != null; - return; - } - } - assert false; - } + // Revision 3 - Deleting both entities + em.getTransaction().begin(); + ste = em.find( StrTestEntity.class, steId ); + site = em.find( StrIntTestEntity.class, siteId ); + em.remove( ste ); + em.remove( site ); + em.getTransaction().commit(); + } - @Test - public void testTrackAddedEntities() { - StrTestEntity ste = new StrTestEntity("x", steId); - StrIntTestEntity site = new StrIntTestEntity("y", 1, siteId); + @Test + public void testRevEntityTableCreation() { + Iterator
tableIterator = getCfg().getTableMappings(); + while ( tableIterator.hasNext() ) { + Table table = tableIterator.next(); + if ( "REVCHANGES".equals( table.getName() ) ) { + assert table.getColumnSpan() == 2; + assert table.getColumn( new Column( "REV" ) ) != null; + assert table.getColumn( new Column( "ENTITYNAME" ) ) != null; + return; + } + } + assert false; + } - assert TestTools.checkList(getCrossTypeRevisionChangesReader().findEntities(1), ste, site); - } + @Test + public void testTrackAddedEntities() { + StrTestEntity ste = new StrTestEntity( "x", steId ); + StrIntTestEntity site = new StrIntTestEntity( "y", 1, siteId ); - @Test - public void testTrackModifiedEntities() { - StrIntTestEntity site = new StrIntTestEntity("y", 2, siteId); + assert TestTools.checkList( getCrossTypeRevisionChangesReader().findEntities( 1 ), ste, site ); + } - assert TestTools.checkList(getCrossTypeRevisionChangesReader().findEntities(2), site); - } + @Test + public void testTrackModifiedEntities() { + StrIntTestEntity site = new StrIntTestEntity( "y", 2, siteId ); - @Test - public void testTrackDeletedEntities() { - StrTestEntity ste = new StrTestEntity(null, steId); - StrIntTestEntity site = new StrIntTestEntity(null, null, siteId); + assert TestTools.checkList( getCrossTypeRevisionChangesReader().findEntities( 2 ), site ); + } - assert TestTools.checkList(getCrossTypeRevisionChangesReader().findEntities(3), site, ste); - } + @Test + public void testTrackDeletedEntities() { + StrTestEntity ste = new StrTestEntity( null, steId ); + StrIntTestEntity site = new StrIntTestEntity( null, null, siteId ); - @Test - public void testFindChangesInInvalidRevision() { - assert getCrossTypeRevisionChangesReader().findEntities(4).isEmpty(); - } + assert TestTools.checkList( getCrossTypeRevisionChangesReader().findEntities( 3 ), site, ste ); + } - @Test - public void testTrackAddedEntitiesGroupByRevisionType() { - StrTestEntity ste = new StrTestEntity("x", steId); - StrIntTestEntity site = new StrIntTestEntity("y", 1, siteId); + @Test + public void testFindChangesInInvalidRevision() { + assert getCrossTypeRevisionChangesReader().findEntities( 4 ).isEmpty(); + } - Map> result = getCrossTypeRevisionChangesReader().findEntitiesGroupByRevisionType(1); - assert TestTools.checkList(result.get(RevisionType.ADD), site, ste); - assert TestTools.checkList(result.get(RevisionType.MOD)); - assert TestTools.checkList(result.get(RevisionType.DEL)); - } + @Test + public void testTrackAddedEntitiesGroupByRevisionType() { + StrTestEntity ste = new StrTestEntity( "x", steId ); + StrIntTestEntity site = new StrIntTestEntity( "y", 1, siteId ); - @Test - public void testTrackModifiedEntitiesGroupByRevisionType() { - StrIntTestEntity site = new StrIntTestEntity("y", 2, siteId); + Map> result = getCrossTypeRevisionChangesReader().findEntitiesGroupByRevisionType( 1 ); + assert TestTools.checkList( result.get( RevisionType.ADD ), site, ste ); + assert TestTools.checkList( result.get( RevisionType.MOD ) ); + assert TestTools.checkList( result.get( RevisionType.DEL ) ); + } - Map> result = getCrossTypeRevisionChangesReader().findEntitiesGroupByRevisionType(2); - assert TestTools.checkList(result.get(RevisionType.ADD)); - assert TestTools.checkList(result.get(RevisionType.MOD), site); - assert TestTools.checkList(result.get(RevisionType.DEL)); - } + @Test + public void testTrackModifiedEntitiesGroupByRevisionType() { + StrIntTestEntity site = new StrIntTestEntity( "y", 2, siteId ); - @Test - public void testTrackDeletedEntitiesGroupByRevisionType() { - StrTestEntity ste = new StrTestEntity(null, steId); - StrIntTestEntity site = new StrIntTestEntity(null, null, siteId); + Map> result = getCrossTypeRevisionChangesReader().findEntitiesGroupByRevisionType( 2 ); + assert TestTools.checkList( result.get( RevisionType.ADD ) ); + assert TestTools.checkList( result.get( RevisionType.MOD ), site ); + assert TestTools.checkList( result.get( RevisionType.DEL ) ); + } - Map> result = getCrossTypeRevisionChangesReader().findEntitiesGroupByRevisionType(3); - assert TestTools.checkList(result.get(RevisionType.ADD)); - assert TestTools.checkList(result.get(RevisionType.MOD)); - assert TestTools.checkList(result.get(RevisionType.DEL), site, ste); - } + @Test + public void testTrackDeletedEntitiesGroupByRevisionType() { + StrTestEntity ste = new StrTestEntity( null, steId ); + StrIntTestEntity site = new StrIntTestEntity( null, null, siteId ); - @Test - public void testFindChangedEntitiesByRevisionTypeADD() { - StrTestEntity ste = new StrTestEntity("x", steId); - StrIntTestEntity site = new StrIntTestEntity("y", 1, siteId); + Map> result = getCrossTypeRevisionChangesReader().findEntitiesGroupByRevisionType( 3 ); + assert TestTools.checkList( result.get( RevisionType.ADD ) ); + assert TestTools.checkList( result.get( RevisionType.MOD ) ); + assert TestTools.checkList( result.get( RevisionType.DEL ), site, ste ); + } - assert TestTools.checkList(getCrossTypeRevisionChangesReader().findEntities(1, RevisionType.ADD), ste, site); - } + @Test + public void testFindChangedEntitiesByRevisionTypeADD() { + StrTestEntity ste = new StrTestEntity( "x", steId ); + StrIntTestEntity site = new StrIntTestEntity( "y", 1, siteId ); - @Test - public void testFindChangedEntitiesByRevisionTypeMOD() { - StrIntTestEntity site = new StrIntTestEntity("y", 2, siteId); + assert TestTools.checkList( + getCrossTypeRevisionChangesReader().findEntities( 1, RevisionType.ADD ), + ste, + site + ); + } - assert TestTools.checkList(getCrossTypeRevisionChangesReader().findEntities(2, RevisionType.MOD), site); - } + @Test + public void testFindChangedEntitiesByRevisionTypeMOD() { + StrIntTestEntity site = new StrIntTestEntity( "y", 2, siteId ); - @Test - public void testFindChangedEntitiesByRevisionTypeDEL() { - StrTestEntity ste = new StrTestEntity(null, steId); - StrIntTestEntity site = new StrIntTestEntity(null, null, siteId); + assert TestTools.checkList( getCrossTypeRevisionChangesReader().findEntities( 2, RevisionType.MOD ), site ); + } - assert TestTools.checkList(getCrossTypeRevisionChangesReader().findEntities(3, RevisionType.DEL), ste, site); - } + @Test + public void testFindChangedEntitiesByRevisionTypeDEL() { + StrTestEntity ste = new StrTestEntity( null, steId ); + StrIntTestEntity site = new StrIntTestEntity( null, null, siteId ); - @Test - public void testFindEntityTypesChangedInRevision() { - assert TestTools.makeSet(Pair.make(StrTestEntity.class.getName(), StrTestEntity.class), - Pair.make(StrIntTestEntity.class.getName(), StrIntTestEntity.class)) - .equals(getCrossTypeRevisionChangesReader().findEntityTypes(1)); + assert TestTools.checkList( + getCrossTypeRevisionChangesReader().findEntities( 3, RevisionType.DEL ), + ste, + site + ); + } - assert TestTools.makeSet(Pair.make(StrIntTestEntity.class.getName(), StrIntTestEntity.class)) - .equals(getCrossTypeRevisionChangesReader().findEntityTypes(2)); - - assert TestTools.makeSet(Pair.make(StrTestEntity.class.getName(), StrTestEntity.class), - Pair.make(StrIntTestEntity.class.getName(), StrIntTestEntity.class)) - .equals(getCrossTypeRevisionChangesReader().findEntityTypes(3)); - } + @Test + public void testFindEntityTypesChangedInRevision() { + assert TestTools.makeSet( + Pair.make( StrTestEntity.class.getName(), StrTestEntity.class ), + Pair.make( StrIntTestEntity.class.getName(), StrIntTestEntity.class ) + ) + .equals( getCrossTypeRevisionChangesReader().findEntityTypes( 1 ) ); - private CrossTypeRevisionChangesReader getCrossTypeRevisionChangesReader() { - return getAuditReader().getCrossTypeRevisionChangesReader(); - } + assert TestTools.makeSet( Pair.make( StrIntTestEntity.class.getName(), StrIntTestEntity.class ) ) + .equals( getCrossTypeRevisionChangesReader().findEntityTypes( 2 ) ); + + assert TestTools.makeSet( + Pair.make( StrTestEntity.class.getName(), StrTestEntity.class ), + Pair.make( StrIntTestEntity.class.getName(), StrIntTestEntity.class ) + ) + .equals( getCrossTypeRevisionChangesReader().findEntityTypes( 3 ) ); + } + + private CrossTypeRevisionChangesReader getCrossTypeRevisionChangesReader() { + return getAuditReader().getCrossTypeRevisionChangesReader(); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/trackmodifiedentities/EntityNamesTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/trackmodifiedentities/EntityNamesTest.java index 1f9c245d9c..703fe1b19f 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/trackmodifiedentities/EntityNamesTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/trackmodifiedentities/EntityNamesTest.java @@ -3,8 +3,6 @@ package org.hibernate.envers.test.integration.reventity.trackmodifiedentities; import java.util.ArrayList; import java.util.List; -import org.junit.Test; - import org.hibernate.cfg.Configuration; import org.hibernate.envers.configuration.EnversSettings; import org.hibernate.envers.test.BaseEnversFunctionalTestCase; @@ -14,62 +12,68 @@ import org.hibernate.envers.test.integration.entityNames.manyToManyAudited.Perso import org.hibernate.envers.test.tools.TestTools; import org.hibernate.envers.tools.Pair; +import org.junit.Test; + /** * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public class EntityNamesTest extends BaseEnversFunctionalTestCase { - @Override - protected String[] getMappings() { - return new String[]{"mappings/entityNames/manyToManyAudited/mappings.hbm.xml"}; - } + @Override + protected String[] getMappings() { + return new String[] {"mappings/entityNames/manyToManyAudited/mappings.hbm.xml"}; + } - @Override - protected void configure(Configuration configuration) { - configuration.setProperty(EnversSettings.TRACK_ENTITIES_CHANGED_IN_REVISION, "true"); - } + @Override + protected void configure(Configuration configuration) { + configuration.setProperty( EnversSettings.TRACK_ENTITIES_CHANGED_IN_REVISION, "true" ); + } - @Test - @Priority(10) - public void initData() { - Person pers1 = new Person("Hernan", 28); - Person pers2 = new Person("Leandro", 29); - Person pers3 = new Person("Barba", 32); - Person pers4 = new Person("Camomo", 15); + @Test + @Priority(10) + public void initData() { + Person pers1 = new Person( "Hernan", 28 ); + Person pers2 = new Person( "Leandro", 29 ); + Person pers3 = new Person( "Barba", 32 ); + Person pers4 = new Person( "Camomo", 15 ); - // Revision 1 - getSession().getTransaction().begin(); - List owners = new ArrayList(); - owners.add(pers1); - owners.add(pers2); - owners.add(pers3); - Car car1 = new Car(5, owners); - getSession().persist(car1); - getSession().getTransaction().commit(); - long person1Id = pers1.getId(); + // Revision 1 + getSession().getTransaction().begin(); + List owners = new ArrayList(); + owners.add( pers1 ); + owners.add( pers2 ); + owners.add( pers3 ); + Car car1 = new Car( 5, owners ); + getSession().persist( car1 ); + getSession().getTransaction().commit(); + long person1Id = pers1.getId(); - // Revision 2 - owners = new ArrayList(); - owners.add(pers2); - owners.add(pers3); - owners.add(pers4); - Car car2 = new Car(27, owners); - getSession().getTransaction().begin(); - Person person1 = (Person)getSession().get("Personaje", person1Id); - person1.setName("Hernan David"); - person1.setAge(40); - getSession().persist(car1); - getSession().persist(car2); - getSession().getTransaction().commit(); - } + // Revision 2 + owners = new ArrayList(); + owners.add( pers2 ); + owners.add( pers3 ); + owners.add( pers4 ); + Car car2 = new Car( 27, owners ); + getSession().getTransaction().begin(); + Person person1 = (Person) getSession().get( "Personaje", person1Id ); + person1.setName( "Hernan David" ); + person1.setAge( 40 ); + getSession().persist( car1 ); + getSession().persist( car2 ); + getSession().getTransaction().commit(); + } - @Test - @SuppressWarnings("unchecked") - public void testModifiedEntityTypes() { - assert TestTools.makeSet(Pair.make(Car.class.getName(), Car.class), - Pair.make("Personaje", Person.class)) - .equals(getAuditReader().getCrossTypeRevisionChangesReader().findEntityTypes(1)); - assert TestTools.makeSet(Pair.make(Car.class.getName(), Car.class), - Pair.make("Personaje", Person.class)) - .equals(getAuditReader().getCrossTypeRevisionChangesReader().findEntityTypes(2)); - } + @Test + @SuppressWarnings("unchecked") + public void testModifiedEntityTypes() { + assert TestTools.makeSet( + Pair.make( Car.class.getName(), Car.class ), + Pair.make( "Personaje", Person.class ) + ) + .equals( getAuditReader().getCrossTypeRevisionChangesReader().findEntityTypes( 1 ) ); + assert TestTools.makeSet( + Pair.make( Car.class.getName(), Car.class ), + Pair.make( "Personaje", Person.class ) + ) + .equals( getAuditReader().getCrossTypeRevisionChangesReader().findEntityTypes( 2 ) ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/trackmodifiedentities/ExtendedRevisionEntityTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/trackmodifiedentities/ExtendedRevisionEntityTest.java index 39f3385e9b..1b5a3d3643 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/trackmodifiedentities/ExtendedRevisionEntityTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/trackmodifiedentities/ExtendedRevisionEntityTest.java @@ -2,35 +2,36 @@ package org.hibernate.envers.test.integration.reventity.trackmodifiedentities; import java.util.Map; -import org.junit.Assert; -import org.junit.Test; - import org.hibernate.envers.DefaultTrackingModifiedEntitiesRevisionEntity; import org.hibernate.envers.configuration.EnversSettings; import org.hibernate.envers.test.entities.reventity.trackmodifiedentities.ExtendedRevisionEntity; import org.hibernate.envers.test.entities.reventity.trackmodifiedentities.ExtendedRevisionListener; import org.hibernate.internal.util.collections.ArrayHelper; +import org.junit.Assert; +import org.junit.Test; + /** * Tests proper behavior of revision entity that extends {@link DefaultTrackingModifiedEntitiesRevisionEntity}. + * * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public class ExtendedRevisionEntityTest extends DefaultTrackingEntitiesTest { @Override protected Class[] getAnnotatedClasses() { return ArrayHelper.join( super.getAnnotatedClasses(), ExtendedRevisionEntity.class ); - } + } - @Override - public void addConfigOptions(Map configuration) { - super.addConfigOptions(configuration); - configuration.put(EnversSettings.TRACK_ENTITIES_CHANGED_IN_REVISION, "false"); - } + @Override + public void addConfigOptions(Map configuration) { + super.addConfigOptions( configuration ); + configuration.put( EnversSettings.TRACK_ENTITIES_CHANGED_IN_REVISION, "false" ); + } - @Test - public void testCommentPropertyValue() { - ExtendedRevisionEntity ere = getAuditReader().findRevision(ExtendedRevisionEntity.class, 1); + @Test + public void testCommentPropertyValue() { + ExtendedRevisionEntity ere = getAuditReader().findRevision( ExtendedRevisionEntity.class, 1 ); - Assert.assertEquals(ExtendedRevisionListener.COMMENT_VALUE, ere.getComment()); - } + Assert.assertEquals( ExtendedRevisionListener.COMMENT_VALUE, ere.getComment() ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/trackmodifiedentities/TrackingEntitiesMultipleChangesTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/trackmodifiedentities/TrackingEntitiesMultipleChangesTest.java index 59f947b103..826b20b2b0 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/trackmodifiedentities/TrackingEntitiesMultipleChangesTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/trackmodifiedentities/TrackingEntitiesMultipleChangesTest.java @@ -1,11 +1,8 @@ package org.hibernate.envers.test.integration.reventity.trackmodifiedentities; +import javax.persistence.EntityManager; import java.util.HashSet; import java.util.Map; -import javax.persistence.EntityManager; - -import org.junit.Assert; -import org.junit.Test; import org.hibernate.envers.CrossTypeRevisionChangesReader; import org.hibernate.envers.configuration.EnversSettings; @@ -14,80 +11,92 @@ import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrTestEntity; import org.hibernate.envers.test.tools.TestTools; +import org.junit.Assert; +import org.junit.Test; + /** * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public class TrackingEntitiesMultipleChangesTest extends BaseEnversJPAFunctionalTestCase { - private Integer steId1 = null; - private Integer steId2 = null; + private Integer steId1 = null; + private Integer steId2 = null; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { StrTestEntity.class }; - } + return new Class[] {StrTestEntity.class}; + } @Override protected void addConfigOptions(Map options) { super.addConfigOptions( options ); - options.put( EnversSettings.TRACK_ENTITIES_CHANGED_IN_REVISION, "true" ) ; + options.put( EnversSettings.TRACK_ENTITIES_CHANGED_IN_REVISION, "true" ); } @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - // Revision 1 - Adding two entities - em.getTransaction().begin(); - StrTestEntity ste1 = new StrTestEntity("x"); - StrTestEntity ste2 = new StrTestEntity("y"); - em.persist(ste1); - em.persist(ste2); - steId1 = ste1.getId(); - steId2 = ste2.getId(); - em.getTransaction().commit(); + // Revision 1 - Adding two entities + em.getTransaction().begin(); + StrTestEntity ste1 = new StrTestEntity( "x" ); + StrTestEntity ste2 = new StrTestEntity( "y" ); + em.persist( ste1 ); + em.persist( ste2 ); + steId1 = ste1.getId(); + steId2 = ste2.getId(); + em.getTransaction().commit(); - // Revision 2 - Adding first and removing second entity - em.getTransaction().begin(); - ste1 = em.find(StrTestEntity.class, steId1); - ste2 = em.find(StrTestEntity.class, steId2); - ste1.setStr("z"); - em.remove(ste2); - em.getTransaction().commit(); + // Revision 2 - Adding first and removing second entity + em.getTransaction().begin(); + ste1 = em.find( StrTestEntity.class, steId1 ); + ste2 = em.find( StrTestEntity.class, steId2 ); + ste1.setStr( "z" ); + em.remove( ste2 ); + em.getTransaction().commit(); - // Revision 3 - Modifying and removing the same entity. - em.getTransaction().begin(); - ste1 = em.find(StrTestEntity.class, steId1); - ste1.setStr("a"); - em.merge(ste1); - em.remove(ste1); - em.getTransaction().commit(); - } + // Revision 3 - Modifying and removing the same entity. + em.getTransaction().begin(); + ste1 = em.find( StrTestEntity.class, steId1 ); + ste1.setStr( "a" ); + em.merge( ste1 ); + em.remove( ste1 ); + em.getTransaction().commit(); + } - @Test - public void testTrackAddedTwoEntities() { - StrTestEntity ste1 = new StrTestEntity("x", steId1); - StrTestEntity ste2 = new StrTestEntity("y", steId2); + @Test + public void testTrackAddedTwoEntities() { + StrTestEntity ste1 = new StrTestEntity( "x", steId1 ); + StrTestEntity ste2 = new StrTestEntity( "y", steId2 ); - Assert.assertEquals(TestTools.makeSet(ste1, ste2), new HashSet(getCrossTypeRevisionChangesReader().findEntities(1))); - } + Assert.assertEquals( + TestTools.makeSet( ste1, ste2 ), + new HashSet( getCrossTypeRevisionChangesReader().findEntities( 1 ) ) + ); + } - @Test - public void testTrackUpdateAndRemoveDifferentEntities() { - StrTestEntity ste1 = new StrTestEntity("z", steId1); - StrTestEntity ste2 = new StrTestEntity(null, steId2); + @Test + public void testTrackUpdateAndRemoveDifferentEntities() { + StrTestEntity ste1 = new StrTestEntity( "z", steId1 ); + StrTestEntity ste2 = new StrTestEntity( null, steId2 ); - Assert.assertEquals(TestTools.makeSet(ste1, ste2), new HashSet(getCrossTypeRevisionChangesReader().findEntities(2))); - } + Assert.assertEquals( + TestTools.makeSet( ste1, ste2 ), + new HashSet( getCrossTypeRevisionChangesReader().findEntities( 2 ) ) + ); + } - @Test - public void testTrackUpdateAndRemoveTheSameEntity() { - StrTestEntity ste1 = new StrTestEntity(null, steId1); + @Test + public void testTrackUpdateAndRemoveTheSameEntity() { + StrTestEntity ste1 = new StrTestEntity( null, steId1 ); - Assert.assertEquals(TestTools.makeSet(ste1), new HashSet(getCrossTypeRevisionChangesReader().findEntities(3))); - } + Assert.assertEquals( + TestTools.makeSet( ste1 ), + new HashSet( getCrossTypeRevisionChangesReader().findEntities( 3 ) ) + ); + } - private CrossTypeRevisionChangesReader getCrossTypeRevisionChangesReader() { - return getAuditReader().getCrossTypeRevisionChangesReader(); - } + private CrossTypeRevisionChangesReader getCrossTypeRevisionChangesReader() { + return getAuditReader().getCrossTypeRevisionChangesReader(); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/revfordate/RevisionForDate.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/revfordate/RevisionForDate.java index 88b2f7ef63..9ed2bd5a33 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/revfordate/RevisionForDate.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/revfordate/RevisionForDate.java @@ -23,10 +23,8 @@ */ package org.hibernate.envers.test.integration.revfordate; -import java.util.Date; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Date; import org.hibernate.envers.AuditReader; import org.hibernate.envers.exception.RevisionDoesNotExistException; @@ -34,88 +32,92 @@ import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrTestEntity; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class RevisionForDate extends BaseEnversJPAFunctionalTestCase { - private long timestamp1; - private long timestamp2; - private long timestamp3; - private long timestamp4; + private long timestamp1; + private long timestamp2; + private long timestamp3; + private long timestamp4; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { StrTestEntity.class }; - } + return new Class[] {StrTestEntity.class}; + } - @Test - @Priority(10) - public void initData() throws InterruptedException { - timestamp1 = System.currentTimeMillis(); + @Test + @Priority(10) + public void initData() throws InterruptedException { + timestamp1 = System.currentTimeMillis(); - Thread.sleep(100); + Thread.sleep( 100 ); - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); - StrTestEntity rfd = new StrTestEntity("x"); - em.persist(rfd); - Integer id = rfd.getId(); - em.getTransaction().commit(); + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); + StrTestEntity rfd = new StrTestEntity( "x" ); + em.persist( rfd ); + Integer id = rfd.getId(); + em.getTransaction().commit(); - timestamp2 = System.currentTimeMillis(); + timestamp2 = System.currentTimeMillis(); - Thread.sleep(100); + Thread.sleep( 100 ); - // Revision 2 - em.getTransaction().begin(); - rfd = em.find(StrTestEntity.class, id); - rfd.setStr("y"); - em.getTransaction().commit(); + // Revision 2 + em.getTransaction().begin(); + rfd = em.find( StrTestEntity.class, id ); + rfd.setStr( "y" ); + em.getTransaction().commit(); - timestamp3 = System.currentTimeMillis(); + timestamp3 = System.currentTimeMillis(); - Thread.sleep(100); + Thread.sleep( 100 ); - // Revision 3 - em.getTransaction().begin(); - rfd = em.find(StrTestEntity.class, id); - rfd.setStr("z"); - em.getTransaction().commit(); + // Revision 3 + em.getTransaction().begin(); + rfd = em.find( StrTestEntity.class, id ); + rfd.setStr( "z" ); + em.getTransaction().commit(); - timestamp4 = System.currentTimeMillis(); - } + timestamp4 = System.currentTimeMillis(); + } - @Test(expected = RevisionDoesNotExistException.class) - public void testTimestamps1() { - getAuditReader().getRevisionNumberForDate(new Date(timestamp1)); - } + @Test(expected = RevisionDoesNotExistException.class) + public void testTimestamps1() { + getAuditReader().getRevisionNumberForDate( new Date( timestamp1 ) ); + } - @Test - public void testTimestamps() { - assert getAuditReader().getRevisionNumberForDate(new Date(timestamp2)).intValue() == 1; - assert getAuditReader().getRevisionNumberForDate(new Date(timestamp3)).intValue() == 2; - assert getAuditReader().getRevisionNumberForDate(new Date(timestamp4)).intValue() == 3; - } + @Test + public void testTimestamps() { + assert getAuditReader().getRevisionNumberForDate( new Date( timestamp2 ) ).intValue() == 1; + assert getAuditReader().getRevisionNumberForDate( new Date( timestamp3 ) ).intValue() == 2; + assert getAuditReader().getRevisionNumberForDate( new Date( timestamp4 ) ).intValue() == 3; + } - @Test - public void testDatesForRevisions() { - AuditReader vr = getAuditReader(); - assert vr.getRevisionNumberForDate(vr.getRevisionDate(1)).intValue() == 1; - assert vr.getRevisionNumberForDate(vr.getRevisionDate(2)).intValue() == 2; - assert vr.getRevisionNumberForDate(vr.getRevisionDate(3)).intValue() == 3; - } + @Test + public void testDatesForRevisions() { + AuditReader vr = getAuditReader(); + assert vr.getRevisionNumberForDate( vr.getRevisionDate( 1 ) ).intValue() == 1; + assert vr.getRevisionNumberForDate( vr.getRevisionDate( 2 ) ).intValue() == 2; + assert vr.getRevisionNumberForDate( vr.getRevisionDate( 3 ) ).intValue() == 3; + } - @Test - public void testRevisionsForDates() { - AuditReader vr = getAuditReader(); + @Test + public void testRevisionsForDates() { + AuditReader vr = getAuditReader(); - assert vr.getRevisionDate(vr.getRevisionNumberForDate(new Date(timestamp2))).getTime() <= timestamp2; - assert vr.getRevisionDate(vr.getRevisionNumberForDate(new Date(timestamp2)).intValue()+1).getTime() > timestamp2; + assert vr.getRevisionDate( vr.getRevisionNumberForDate( new Date( timestamp2 ) ) ).getTime() <= timestamp2; + assert vr.getRevisionDate( vr.getRevisionNumberForDate( new Date( timestamp2 ) ).intValue() + 1 ) + .getTime() > timestamp2; - assert vr.getRevisionDate(vr.getRevisionNumberForDate(new Date(timestamp3))).getTime() <= timestamp3; - assert vr.getRevisionDate(vr.getRevisionNumberForDate(new Date(timestamp3)).intValue()+1).getTime() > timestamp3; + assert vr.getRevisionDate( vr.getRevisionNumberForDate( new Date( timestamp3 ) ) ).getTime() <= timestamp3; + assert vr.getRevisionDate( vr.getRevisionNumberForDate( new Date( timestamp3 ) ).intValue() + 1 ) + .getTime() > timestamp3; - assert vr.getRevisionDate(vr.getRevisionNumberForDate(new Date(timestamp4))).getTime() <= timestamp4; - } + assert vr.getRevisionDate( vr.getRevisionNumberForDate( new Date( timestamp4 ) ) ).getTime() <= timestamp4; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/sameids/SameIdTestEntity1.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/sameids/SameIdTestEntity1.java index 50cb8e98e4..728ef921b4 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/sameids/SameIdTestEntity1.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/sameids/SameIdTestEntity1.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.sameids; + import javax.persistence.Entity; import javax.persistence.Id; @@ -32,56 +33,64 @@ import org.hibernate.envers.Audited; */ @Entity public class SameIdTestEntity1 { - @Id - private Integer id; + @Id + private Integer id; - @Audited - private String str1; + @Audited + private String str1; - public SameIdTestEntity1() { - } + public SameIdTestEntity1() { + } - public SameIdTestEntity1(String str1) { - this.str1 = str1; - } + public SameIdTestEntity1(String str1) { + this.str1 = str1; + } - public SameIdTestEntity1(Integer id, String str1) { - this.id = id; - this.str1 = str1; - } + public SameIdTestEntity1(Integer id, String str1) { + this.id = id; + this.str1 = str1; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getStr1() { - return str1; - } + public String getStr1() { + return str1; + } - public void setStr1(String str1) { - this.str1 = str1; - } + public void setStr1(String str1) { + this.str1 = str1; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof SameIdTestEntity1)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof SameIdTestEntity1) ) { + return false; + } - SameIdTestEntity1 that = (SameIdTestEntity1) o; + SameIdTestEntity1 that = (SameIdTestEntity1) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; - if (str1 != null ? !str1.equals(that.str1) : that.str1 != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } + if ( str1 != null ? !str1.equals( that.str1 ) : that.str1 != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (str1 != null ? str1.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (str1 != null ? str1.hashCode() : 0); + return result; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/sameids/SameIdTestEntity2.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/sameids/SameIdTestEntity2.java index c5a4b2f9e0..ae203fca56 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/sameids/SameIdTestEntity2.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/sameids/SameIdTestEntity2.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.sameids; + import javax.persistence.Entity; import javax.persistence.Id; @@ -32,56 +33,64 @@ import org.hibernate.envers.Audited; */ @Entity public class SameIdTestEntity2 { - @Id - private Integer id; + @Id + private Integer id; - @Audited - private String str1; + @Audited + private String str1; - public SameIdTestEntity2() { - } + public SameIdTestEntity2() { + } - public SameIdTestEntity2(String str1) { - this.str1 = str1; - } + public SameIdTestEntity2(String str1) { + this.str1 = str1; + } - public SameIdTestEntity2(Integer id, String str1) { - this.id = id; - this.str1 = str1; - } + public SameIdTestEntity2(Integer id, String str1) { + this.id = id; + this.str1 = str1; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getStr1() { - return str1; - } + public String getStr1() { + return str1; + } - public void setStr1(String str1) { - this.str1 = str1; - } + public void setStr1(String str1) { + this.str1 = str1; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof SameIdTestEntity2)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof SameIdTestEntity2) ) { + return false; + } - SameIdTestEntity2 that = (SameIdTestEntity2) o; + SameIdTestEntity2 that = (SameIdTestEntity2) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; - if (str1 != null ? !str1.equals(that.str1) : that.str1 != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } + if ( str1 != null ? !str1.equals( that.str1 ) : that.str1 != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (str1 != null ? str1.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (str1 != null ? str1.hashCode() : 0); + return result; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/sameids/SameIds.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/sameids/SameIds.java index 1b2947dc91..8c698131cb 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/sameids/SameIds.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/sameids/SameIds.java @@ -23,66 +23,67 @@ */ package org.hibernate.envers.test.integration.sameids; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; +import org.junit.Test; + /** * A test which checks that if we add two different entities with the same ids in one revision, they * will both be stored. + * * @author Adam Warski (adam at warski dot org) */ public class SameIds extends BaseEnversJPAFunctionalTestCase { @Override protected Class[] getAnnotatedClasses() { - return new Class[] { SameIdTestEntity1.class, SameIdTestEntity2.class }; - } + return new Class[] {SameIdTestEntity1.class, SameIdTestEntity2.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); - em.getTransaction().begin(); - SameIdTestEntity1 site1 = new SameIdTestEntity1(1, "str1"); - SameIdTestEntity2 site2 = new SameIdTestEntity2(1, "str1"); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); + em.getTransaction().begin(); + SameIdTestEntity1 site1 = new SameIdTestEntity1( 1, "str1" ); + SameIdTestEntity2 site2 = new SameIdTestEntity2( 1, "str1" ); - em.persist(site1); - em.persist(site2); - em.getTransaction().commit(); + em.persist( site1 ); + em.persist( site2 ); + em.getTransaction().commit(); - em.getTransaction().begin(); - site1 = em.find(SameIdTestEntity1.class, 1); - site2 = em.find(SameIdTestEntity2.class, 1); - site1.setStr1("str2"); - site2.setStr1("str2"); - em.getTransaction().commit(); - } + em.getTransaction().begin(); + site1 = em.find( SameIdTestEntity1.class, 1 ); + site2 = em.find( SameIdTestEntity2.class, 1 ); + site1.setStr1( "str2" ); + site2.setStr1( "str2" ); + em.getTransaction().commit(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(SameIdTestEntity1.class, 1)); - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(SameIdTestEntity2.class, 1)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( SameIdTestEntity1.class, 1 ) ); + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( SameIdTestEntity2.class, 1 ) ); + } - @Test - public void testHistoryOfSite1() { - SameIdTestEntity1 ver1 = new SameIdTestEntity1(1, "str1"); - SameIdTestEntity1 ver2 = new SameIdTestEntity1(1, "str2"); + @Test + public void testHistoryOfSite1() { + SameIdTestEntity1 ver1 = new SameIdTestEntity1( 1, "str1" ); + SameIdTestEntity1 ver2 = new SameIdTestEntity1( 1, "str2" ); - assert getAuditReader().find(SameIdTestEntity1.class, 1, 1).equals(ver1); - assert getAuditReader().find(SameIdTestEntity1.class, 1, 2).equals(ver2); - } + assert getAuditReader().find( SameIdTestEntity1.class, 1, 1 ).equals( ver1 ); + assert getAuditReader().find( SameIdTestEntity1.class, 1, 2 ).equals( ver2 ); + } - @Test - public void testHistoryOfSite2() { - SameIdTestEntity2 ver1 = new SameIdTestEntity2(1, "str1"); - SameIdTestEntity2 ver2 = new SameIdTestEntity2(1, "str2"); + @Test + public void testHistoryOfSite2() { + SameIdTestEntity2 ver1 = new SameIdTestEntity2( 1, "str1" ); + SameIdTestEntity2 ver2 = new SameIdTestEntity2( 1, "str2" ); - assert getAuditReader().find(SameIdTestEntity2.class, 1, 1).equals(ver1); - assert getAuditReader().find(SameIdTestEntity2.class, 1, 2).equals(ver2); - } + assert getAuditReader().find( SameIdTestEntity2.class, 1, 1 ).equals( ver1 ); + assert getAuditReader().find( SameIdTestEntity2.class, 1, 2 ).equals( ver2 ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/secondary/BasicSecondary.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/secondary/BasicSecondary.java index 322a86b2da..f09bf20823 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/secondary/BasicSecondary.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/secondary/BasicSecondary.java @@ -23,74 +23,78 @@ */ package org.hibernate.envers.test.integration.secondary; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.Iterator; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.mapping.Join; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class BasicSecondary extends BaseEnversJPAFunctionalTestCase { - private Integer id; + private Integer id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { SecondaryTestEntity.class }; - } + return new Class[] {SecondaryTestEntity.class}; + } - @Test - @Priority(10) - public void initData() { - SecondaryTestEntity ste = new SecondaryTestEntity("a", "1"); + @Test + @Priority(10) + public void initData() { + SecondaryTestEntity ste = new SecondaryTestEntity( "a", "1" ); - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); - em.persist(ste); + em.persist( ste ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); + // Revision 2 + em.getTransaction().begin(); - ste = em.find(SecondaryTestEntity.class, ste.getId()); - ste.setS1("b"); - ste.setS2("2"); + ste = em.find( SecondaryTestEntity.class, ste.getId() ); + ste.setS1( "b" ); + ste.setS2( "2" ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // + // - id = ste.getId(); - } + id = ste.getId(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(SecondaryTestEntity.class, id)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( SecondaryTestEntity.class, id ) ); + } - @Test - public void testHistoryOfId() { - SecondaryTestEntity ver1 = new SecondaryTestEntity(id, "a", "1"); - SecondaryTestEntity ver2 = new SecondaryTestEntity(id, "b", "2"); + @Test + public void testHistoryOfId() { + SecondaryTestEntity ver1 = new SecondaryTestEntity( id, "a", "1" ); + SecondaryTestEntity ver2 = new SecondaryTestEntity( id, "b", "2" ); - assert getAuditReader().find(SecondaryTestEntity.class, id, 1).equals(ver1); - assert getAuditReader().find(SecondaryTestEntity.class, id, 2).equals(ver2); - } + assert getAuditReader().find( SecondaryTestEntity.class, id, 1 ).equals( ver1 ); + assert getAuditReader().find( SecondaryTestEntity.class, id, 2 ).equals( ver2 ); + } - @SuppressWarnings({"unchecked"}) - @Test - public void testTableNames() { - assert "secondary_AUD".equals(((Iterator) - getCfg().getClassMapping("org.hibernate.envers.test.integration.secondary.SecondaryTestEntity_AUD") - .getJoinIterator()) - .next().getTable().getName()); - } + @SuppressWarnings({"unchecked"}) + @Test + public void testTableNames() { + assert "secondary_AUD".equals( + ((Iterator) + getCfg().getClassMapping( + "org.hibernate.envers.test.integration.secondary.SecondaryTestEntity_AUD" + ) + .getJoinIterator()) + .next().getTable().getName() + ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/secondary/NamingSecondary.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/secondary/NamingSecondary.java index bd7af203d9..34122b1a8f 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/secondary/NamingSecondary.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/secondary/NamingSecondary.java @@ -23,74 +23,78 @@ */ package org.hibernate.envers.test.integration.secondary; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.Iterator; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.mapping.Join; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class NamingSecondary extends BaseEnversJPAFunctionalTestCase { - private Integer id; + private Integer id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { SecondaryNamingTestEntity.class }; - } + return new Class[] {SecondaryNamingTestEntity.class}; + } - @Test - @Priority(10) - public void initData() { - SecondaryNamingTestEntity ste = new SecondaryNamingTestEntity("a", "1"); + @Test + @Priority(10) + public void initData() { + SecondaryNamingTestEntity ste = new SecondaryNamingTestEntity( "a", "1" ); - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); - em.persist(ste); + em.persist( ste ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); + // Revision 2 + em.getTransaction().begin(); - ste = em.find(SecondaryNamingTestEntity.class, ste.getId()); - ste.setS1("b"); - ste.setS2("2"); + ste = em.find( SecondaryNamingTestEntity.class, ste.getId() ); + ste.setS1( "b" ); + ste.setS2( "2" ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // + // - id = ste.getId(); - } + id = ste.getId(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(SecondaryNamingTestEntity.class, id)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( SecondaryNamingTestEntity.class, id ) ); + } - @Test - public void testHistoryOfId() { - SecondaryNamingTestEntity ver1 = new SecondaryNamingTestEntity(id, "a", "1"); - SecondaryNamingTestEntity ver2 = new SecondaryNamingTestEntity(id, "b", "2"); + @Test + public void testHistoryOfId() { + SecondaryNamingTestEntity ver1 = new SecondaryNamingTestEntity( id, "a", "1" ); + SecondaryNamingTestEntity ver2 = new SecondaryNamingTestEntity( id, "b", "2" ); - assert getAuditReader().find(SecondaryNamingTestEntity.class, id, 1).equals(ver1); - assert getAuditReader().find(SecondaryNamingTestEntity.class, id, 2).equals(ver2); - } + assert getAuditReader().find( SecondaryNamingTestEntity.class, id, 1 ).equals( ver1 ); + assert getAuditReader().find( SecondaryNamingTestEntity.class, id, 2 ).equals( ver2 ); + } - @SuppressWarnings({"unchecked"}) - @Test - public void testTableNames() { - assert "sec_versions".equals(((Iterator) - getCfg().getClassMapping("org.hibernate.envers.test.integration.secondary.SecondaryNamingTestEntity_AUD") - .getJoinIterator()) - .next().getTable().getName()); - } + @SuppressWarnings({"unchecked"}) + @Test + public void testTableNames() { + assert "sec_versions".equals( + ((Iterator) + getCfg().getClassMapping( + "org.hibernate.envers.test.integration.secondary.SecondaryNamingTestEntity_AUD" + ) + .getJoinIterator()) + .next().getTable().getName() + ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/secondary/SecondaryNamingTestEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/secondary/SecondaryNamingTestEntity.java index d5434bbf2f..85b0d1e654 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/secondary/SecondaryNamingTestEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/secondary/SecondaryNamingTestEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.secondary; + import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -39,71 +40,81 @@ import org.hibernate.envers.SecondaryAuditTable; @SecondaryAuditTable(secondaryTableName = "secondary", secondaryAuditTableName = "sec_versions") @Audited public class SecondaryNamingTestEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - private String s1; + private String s1; - @Column(table = "secondary") - private String s2; + @Column(table = "secondary") + private String s2; - public SecondaryNamingTestEntity(Integer id, String s1, String s2) { - this.id = id; - this.s1 = s1; - this.s2 = s2; - } + public SecondaryNamingTestEntity(Integer id, String s1, String s2) { + this.id = id; + this.s1 = s1; + this.s2 = s2; + } - public SecondaryNamingTestEntity(String s1, String s2) { - this.s1 = s1; - this.s2 = s2; - } + public SecondaryNamingTestEntity(String s1, String s2) { + this.s1 = s1; + this.s2 = s2; + } - public SecondaryNamingTestEntity() { - } + public SecondaryNamingTestEntity() { + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getS1() { - return s1; - } + public String getS1() { + return s1; + } - public void setS1(String s1) { - this.s1 = s1; - } + public void setS1(String s1) { + this.s1 = s1; + } - public String getS2() { - return s2; - } + public String getS2() { + return s2; + } - public void setS2(String s2) { - this.s2 = s2; - } + public void setS2(String s2) { + this.s2 = s2; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof SecondaryNamingTestEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof SecondaryNamingTestEntity) ) { + return false; + } - SecondaryNamingTestEntity that = (SecondaryNamingTestEntity) o; + SecondaryNamingTestEntity that = (SecondaryNamingTestEntity) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; - if (s1 != null ? !s1.equals(that.s1) : that.s1 != null) return false; - if (s2 != null ? !s2.equals(that.s2) : that.s2 != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } + if ( s1 != null ? !s1.equals( that.s1 ) : that.s1 != null ) { + return false; + } + if ( s2 != null ? !s2.equals( that.s2 ) : that.s2 != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (s1 != null ? s1.hashCode() : 0); - result = 31 * result + (s2 != null ? s2.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (s1 != null ? s1.hashCode() : 0); + result = 31 * result + (s2 != null ? s2.hashCode() : 0); + return result; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/secondary/SecondaryTestEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/secondary/SecondaryTestEntity.java index b6546179e1..dbc8cb3ad9 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/secondary/SecondaryTestEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/secondary/SecondaryTestEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.secondary; + import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -37,71 +38,81 @@ import org.hibernate.envers.Audited; @SecondaryTable(name = "secondary") @Audited public class SecondaryTestEntity { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - private String s1; + private String s1; - @Column(table = "secondary") - private String s2; + @Column(table = "secondary") + private String s2; - public SecondaryTestEntity(Integer id, String s1, String s2) { - this.id = id; - this.s1 = s1; - this.s2 = s2; - } + public SecondaryTestEntity(Integer id, String s1, String s2) { + this.id = id; + this.s1 = s1; + this.s2 = s2; + } - public SecondaryTestEntity(String s1, String s2) { - this.s1 = s1; - this.s2 = s2; - } + public SecondaryTestEntity(String s1, String s2) { + this.s1 = s1; + this.s2 = s2; + } - public SecondaryTestEntity() { - } + public SecondaryTestEntity() { + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getS1() { - return s1; - } + public String getS1() { + return s1; + } - public void setS1(String s1) { - this.s1 = s1; - } + public void setS1(String s1) { + this.s1 = s1; + } - public String getS2() { - return s2; - } + public String getS2() { + return s2; + } - public void setS2(String s2) { - this.s2 = s2; - } + public void setS2(String s2) { + this.s2 = s2; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof SecondaryTestEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof SecondaryTestEntity) ) { + return false; + } - SecondaryTestEntity that = (SecondaryTestEntity) o; + SecondaryTestEntity that = (SecondaryTestEntity) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; - if (s1 != null ? !s1.equals(that.s1) : that.s1 != null) return false; - if (s2 != null ? !s2.equals(that.s2) : that.s2 != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } + if ( s1 != null ? !s1.equals( that.s1 ) : that.s1 != null ) { + return false; + } + if ( s2 != null ? !s2.equals( that.s2 ) : that.s2 != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (s1 != null ? s1.hashCode() : 0); - result = 31 * result + (s2 != null ? s2.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (s1 != null ? s1.hashCode() : 0); + result = 31 * result + (s2 != null ? s2.hashCode() : 0); + return result; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/secondary/ids/EmbIdSecondary.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/secondary/ids/EmbIdSecondary.java index acdc146bb0..add9e2dba7 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/secondary/ids/EmbIdSecondary.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/secondary/ids/EmbIdSecondary.java @@ -23,73 +23,77 @@ */ package org.hibernate.envers.test.integration.secondary.ids; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.Iterator; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.ids.EmbId; import org.hibernate.mapping.Join; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class EmbIdSecondary extends BaseEnversJPAFunctionalTestCase { - private EmbId id; + private EmbId id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { SecondaryEmbIdTestEntity.class }; - } + return new Class[] {SecondaryEmbIdTestEntity.class}; + } - @Test - @Priority(10) - public void initData() { - id = new EmbId(1, 2); + @Test + @Priority(10) + public void initData() { + id = new EmbId( 1, 2 ); - SecondaryEmbIdTestEntity ste = new SecondaryEmbIdTestEntity(id, "a", "1"); + SecondaryEmbIdTestEntity ste = new SecondaryEmbIdTestEntity( id, "a", "1" ); - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); - em.persist(ste); + em.persist( ste ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); + // Revision 2 + em.getTransaction().begin(); - ste = em.find(SecondaryEmbIdTestEntity.class, ste.getId()); - ste.setS1("b"); - ste.setS2("2"); + ste = em.find( SecondaryEmbIdTestEntity.class, ste.getId() ); + ste.setS1( "b" ); + ste.setS2( "2" ); - em.getTransaction().commit(); - } + em.getTransaction().commit(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(SecondaryEmbIdTestEntity.class, id)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( SecondaryEmbIdTestEntity.class, id ) ); + } - @Test - public void testHistoryOfId() { - SecondaryEmbIdTestEntity ver1 = new SecondaryEmbIdTestEntity(id, "a", "1"); - SecondaryEmbIdTestEntity ver2 = new SecondaryEmbIdTestEntity(id, "b", "2"); + @Test + public void testHistoryOfId() { + SecondaryEmbIdTestEntity ver1 = new SecondaryEmbIdTestEntity( id, "a", "1" ); + SecondaryEmbIdTestEntity ver2 = new SecondaryEmbIdTestEntity( id, "b", "2" ); - assert getAuditReader().find(SecondaryEmbIdTestEntity.class, id, 1).equals(ver1); - assert getAuditReader().find(SecondaryEmbIdTestEntity.class, id, 2).equals(ver2); - } + assert getAuditReader().find( SecondaryEmbIdTestEntity.class, id, 1 ).equals( ver1 ); + assert getAuditReader().find( SecondaryEmbIdTestEntity.class, id, 2 ).equals( ver2 ); + } - @SuppressWarnings({"unchecked"}) - @Test - public void testTableNames() { - assert "sec_embid_versions".equals(((Iterator) - getCfg().getClassMapping("org.hibernate.envers.test.integration.secondary.ids.SecondaryEmbIdTestEntity_AUD") - .getJoinIterator()) - .next().getTable().getName()); - } + @SuppressWarnings({"unchecked"}) + @Test + public void testTableNames() { + assert "sec_embid_versions".equals( + ((Iterator) + getCfg().getClassMapping( + "org.hibernate.envers.test.integration.secondary.ids.SecondaryEmbIdTestEntity_AUD" + ) + .getJoinIterator()) + .next().getTable().getName() + ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/secondary/ids/MulIdSecondary.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/secondary/ids/MulIdSecondary.java index e7f1c6ceaf..897eb03149 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/secondary/ids/MulIdSecondary.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/secondary/ids/MulIdSecondary.java @@ -23,73 +23,77 @@ */ package org.hibernate.envers.test.integration.secondary.ids; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.Iterator; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.ids.MulId; import org.hibernate.mapping.Join; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class MulIdSecondary extends BaseEnversJPAFunctionalTestCase { - private MulId id; + private MulId id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { SecondaryMulIdTestEntity.class }; - } + return new Class[] {SecondaryMulIdTestEntity.class}; + } - @Test - @Priority(10) - public void initData() { - id = new MulId(1, 2); + @Test + @Priority(10) + public void initData() { + id = new MulId( 1, 2 ); - SecondaryMulIdTestEntity ste = new SecondaryMulIdTestEntity(id, "a", "1"); + SecondaryMulIdTestEntity ste = new SecondaryMulIdTestEntity( id, "a", "1" ); - // Revision 1 - EntityManager em = getEntityManager(); - em.getTransaction().begin(); + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); - em.persist(ste); + em.persist( ste ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); + // Revision 2 + em.getTransaction().begin(); - ste = em.find(SecondaryMulIdTestEntity.class, id); - ste.setS1("b"); - ste.setS2("2"); + ste = em.find( SecondaryMulIdTestEntity.class, id ); + ste.setS1( "b" ); + ste.setS2( "2" ); - em.getTransaction().commit(); - } + em.getTransaction().commit(); + } - @Test - public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(SecondaryMulIdTestEntity.class, id)); - } + @Test + public void testRevisionsCounts() { + assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( SecondaryMulIdTestEntity.class, id ) ); + } - @Test - public void testHistoryOfId() { - SecondaryMulIdTestEntity ver1 = new SecondaryMulIdTestEntity(id, "a", "1"); - SecondaryMulIdTestEntity ver2 = new SecondaryMulIdTestEntity(id, "b", "2"); + @Test + public void testHistoryOfId() { + SecondaryMulIdTestEntity ver1 = new SecondaryMulIdTestEntity( id, "a", "1" ); + SecondaryMulIdTestEntity ver2 = new SecondaryMulIdTestEntity( id, "b", "2" ); - assert getAuditReader().find(SecondaryMulIdTestEntity.class, id, 1).equals(ver1); - assert getAuditReader().find(SecondaryMulIdTestEntity.class, id, 2).equals(ver2); - } + assert getAuditReader().find( SecondaryMulIdTestEntity.class, id, 1 ).equals( ver1 ); + assert getAuditReader().find( SecondaryMulIdTestEntity.class, id, 2 ).equals( ver2 ); + } - @SuppressWarnings({"unchecked"}) - @Test - public void testTableNames() { - assert "sec_mulid_versions".equals(((Iterator) - getCfg().getClassMapping("org.hibernate.envers.test.integration.secondary.ids.SecondaryMulIdTestEntity_AUD") - .getJoinIterator()) - .next().getTable().getName()); - } + @SuppressWarnings({"unchecked"}) + @Test + public void testTableNames() { + assert "sec_mulid_versions".equals( + ((Iterator) + getCfg().getClassMapping( + "org.hibernate.envers.test.integration.secondary.ids.SecondaryMulIdTestEntity_AUD" + ) + .getJoinIterator()) + .next().getTable().getName() + ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/secondary/ids/SecondaryEmbIdTestEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/secondary/ids/SecondaryEmbIdTestEntity.java index 482906c27a..27153f994a 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/secondary/ids/SecondaryEmbIdTestEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/secondary/ids/SecondaryEmbIdTestEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.secondary.ids; + import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; @@ -39,70 +40,80 @@ import org.hibernate.envers.test.entities.ids.EmbId; @SecondaryAuditTable(secondaryTableName = "secondary", secondaryAuditTableName = "sec_embid_versions") @Audited public class SecondaryEmbIdTestEntity { - @Id - private EmbId id; + @Id + private EmbId id; - private String s1; + private String s1; - @Column(table = "secondary") - private String s2; + @Column(table = "secondary") + private String s2; - public SecondaryEmbIdTestEntity(EmbId id, String s1, String s2) { - this.id = id; - this.s1 = s1; - this.s2 = s2; - } + public SecondaryEmbIdTestEntity(EmbId id, String s1, String s2) { + this.id = id; + this.s1 = s1; + this.s2 = s2; + } - public SecondaryEmbIdTestEntity(String s1, String s2) { - this.s1 = s1; - this.s2 = s2; - } + public SecondaryEmbIdTestEntity(String s1, String s2) { + this.s1 = s1; + this.s2 = s2; + } - public SecondaryEmbIdTestEntity() { - } + public SecondaryEmbIdTestEntity() { + } - public EmbId getId() { - return id; - } + public EmbId getId() { + return id; + } - public void setId(EmbId id) { - this.id = id; - } + public void setId(EmbId id) { + this.id = id; + } - public String getS1() { - return s1; - } + public String getS1() { + return s1; + } - public void setS1(String s1) { - this.s1 = s1; - } + public void setS1(String s1) { + this.s1 = s1; + } - public String getS2() { - return s2; - } + public String getS2() { + return s2; + } - public void setS2(String s2) { - this.s2 = s2; - } + public void setS2(String s2) { + this.s2 = s2; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof SecondaryEmbIdTestEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof SecondaryEmbIdTestEntity) ) { + return false; + } - SecondaryEmbIdTestEntity that = (SecondaryEmbIdTestEntity) o; + SecondaryEmbIdTestEntity that = (SecondaryEmbIdTestEntity) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; - if (s1 != null ? !s1.equals(that.s1) : that.s1 != null) return false; - if (s2 != null ? !s2.equals(that.s2) : that.s2 != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } + if ( s1 != null ? !s1.equals( that.s1 ) : that.s1 != null ) { + return false; + } + if ( s2 != null ? !s2.equals( that.s2 ) : that.s2 != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (s1 != null ? s1.hashCode() : 0); - result = 31 * result + (s2 != null ? s2.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (s1 != null ? s1.hashCode() : 0); + result = 31 * result + (s2 != null ? s2.hashCode() : 0); + return result; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/secondary/ids/SecondaryMulIdTestEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/secondary/ids/SecondaryMulIdTestEntity.java index f42da96e67..cdda6a50e5 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/secondary/ids/SecondaryMulIdTestEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/secondary/ids/SecondaryMulIdTestEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.secondary.ids; + import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; @@ -41,84 +42,96 @@ import org.hibernate.envers.test.entities.ids.MulId; @Audited @IdClass(MulId.class) public class SecondaryMulIdTestEntity { - @Id - private Integer id1; + @Id + private Integer id1; - @Id - private Integer id2; + @Id + private Integer id2; - private String s1; + private String s1; - @Column(table = "secondary") - private String s2; + @Column(table = "secondary") + private String s2; - public SecondaryMulIdTestEntity(MulId id, String s1, String s2) { - this.id1 = id.getId1(); - this.id2 = id.getId2(); - this.s1 = s1; - this.s2 = s2; - } + public SecondaryMulIdTestEntity(MulId id, String s1, String s2) { + this.id1 = id.getId1(); + this.id2 = id.getId2(); + this.s1 = s1; + this.s2 = s2; + } - public SecondaryMulIdTestEntity(String s1, String s2) { - this.s1 = s1; - this.s2 = s2; - } + public SecondaryMulIdTestEntity(String s1, String s2) { + this.s1 = s1; + this.s2 = s2; + } - public SecondaryMulIdTestEntity() { - } + public SecondaryMulIdTestEntity() { + } - public Integer getId1() { - return id1; - } + public Integer getId1() { + return id1; + } - public void setId1(Integer id1) { - this.id1 = id1; - } + public void setId1(Integer id1) { + this.id1 = id1; + } - public Integer getId2() { - return id2; - } + public Integer getId2() { + return id2; + } - public void setId2(Integer id2) { - this.id2 = id2; - } + public void setId2(Integer id2) { + this.id2 = id2; + } - public String getS1() { - return s1; - } + public String getS1() { + return s1; + } - public void setS1(String s1) { - this.s1 = s1; - } + public void setS1(String s1) { + this.s1 = s1; + } - public String getS2() { - return s2; - } + public String getS2() { + return s2; + } - public void setS2(String s2) { - this.s2 = s2; - } + public void setS2(String s2) { + this.s2 = s2; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof SecondaryMulIdTestEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof SecondaryMulIdTestEntity) ) { + return false; + } - SecondaryMulIdTestEntity that = (SecondaryMulIdTestEntity) o; + SecondaryMulIdTestEntity that = (SecondaryMulIdTestEntity) o; - if (id1 != null ? !id1.equals(that.id1) : that.id1 != null) return false; - if (id2 != null ? !id2.equals(that.id2) : that.id2 != null) return false; - if (s1 != null ? !s1.equals(that.s1) : that.s1 != null) return false; - if (s2 != null ? !s2.equals(that.s2) : that.s2 != null) return false; + if ( id1 != null ? !id1.equals( that.id1 ) : that.id1 != null ) { + return false; + } + if ( id2 != null ? !id2.equals( that.id2 ) : that.id2 != null ) { + return false; + } + if ( s1 != null ? !s1.equals( that.s1 ) : that.s1 != null ) { + return false; + } + if ( s2 != null ? !s2.equals( that.s2 ) : that.s2 != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id1 != null ? id1.hashCode() : 0); - result = 31 * result + (id2 != null ? id2.hashCode() : 0); - result = 31 * result + (s1 != null ? s1.hashCode() : 0); - result = 31 * result + (s2 != null ? s2.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id1 != null ? id1.hashCode() : 0); + result = 31 * result + (id2 != null ? id2.hashCode() : 0); + result = 31 * result + (s1 != null ? s1.hashCode() : 0); + result = 31 * result + (s2 != null ? s2.hashCode() : 0); + return result; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/serialization/SerializingCollection.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/serialization/SerializingCollection.java index 2002c0cbc0..d42717173e 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/serialization/SerializingCollection.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/serialization/SerializingCollection.java @@ -23,83 +23,85 @@ */ package org.hibernate.envers.test.integration.serialization; +import javax.persistence.EntityManager; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.onetomany.CollectionRefEdEntity; import org.hibernate.envers.test.entities.onetomany.CollectionRefIngEntity; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) */ public class SerializingCollection extends BaseEnversJPAFunctionalTestCase { - private Integer ed1_id; - private Integer ing1_id; + private Integer ed1_id; + private Integer ing1_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { CollectionRefEdEntity.class, CollectionRefIngEntity.class }; - } + return new Class[] {CollectionRefEdEntity.class, CollectionRefIngEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - CollectionRefEdEntity ed1 = new CollectionRefEdEntity(1, "data_ed_1"); + CollectionRefEdEntity ed1 = new CollectionRefEdEntity( 1, "data_ed_1" ); - CollectionRefIngEntity ing1 = new CollectionRefIngEntity(3, "data_ing_1", ed1); + CollectionRefIngEntity ing1 = new CollectionRefIngEntity( 3, "data_ing_1", ed1 ); - // Revision 1 - em.getTransaction().begin(); + // Revision 1 + em.getTransaction().begin(); - em.persist(ed1); - em.persist(ing1); + em.persist( ed1 ); + em.persist( ing1 ); - em.getTransaction().commit(); + em.getTransaction().commit(); - // + // - ed1_id = ed1.getId(); - ing1_id = ing1.getId(); - } + ed1_id = ed1.getId(); + ing1_id = ing1.getId(); + } - @Test - public void testDetach()throws Exception { - CollectionRefIngEntity ing1 = getEntityManager().find(CollectionRefIngEntity.class, ing1_id); - CollectionRefEdEntity rev1 = getAuditReader().find(CollectionRefEdEntity.class, ed1_id, 1); + @Test + public void testDetach() throws Exception { + CollectionRefIngEntity ing1 = getEntityManager().find( CollectionRefIngEntity.class, ing1_id ); + CollectionRefEdEntity rev1 = getAuditReader().find( CollectionRefEdEntity.class, ed1_id, 1 ); // First forcing loading of the collection assert rev1.getReffering().size() == 1; // Now serializing and de-serializing the - rev1 = serializeDeserialize(rev1); + rev1 = serializeDeserialize( rev1 ); // And checking the colleciton again - assert rev1.getReffering().contains(ing1); - assert rev1.getReffering().size() == 1; + assert rev1.getReffering().contains( ing1 ); + assert rev1.getReffering().size() == 1; - } + } @SuppressWarnings({"unchecked"}) public static T serializeDeserialize(T o) throws Exception { - if (o == null) return null; + if ( o == null ) { + return null; + } ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream oos = new ObjectOutputStream(baos); - oos.writeObject(o); + ObjectOutputStream oos = new ObjectOutputStream( baos ); + oos.writeObject( o ); byte[] buffer = baos.toByteArray(); baos.close(); - ByteArrayInputStream bais = new ByteArrayInputStream(buffer); - ObjectInputStream ois = new ObjectInputStream(bais); - return (T) ois.readObject(); + ByteArrayInputStream bais = new ByteArrayInputStream( buffer ); + ObjectInputStream ois = new ObjectInputStream( bais ); + return (T) ois.readObject(); } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/strategy/ValidityAuditStrategyManyToManyTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/strategy/ValidityAuditStrategyManyToManyTest.java index 2e96ea9a7f..a424925d89 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/strategy/ValidityAuditStrategyManyToManyTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/strategy/ValidityAuditStrategyManyToManyTest.java @@ -1,11 +1,9 @@ package org.hibernate.envers.test.integration.strategy; +import javax.persistence.EntityManager; import java.util.Arrays; import java.util.HashSet; import java.util.Map; -import javax.persistence.EntityManager; - -import org.junit.Test; import org.hibernate.envers.configuration.EnversSettings; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; @@ -13,6 +11,8 @@ import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.manytomany.SetOwnedEntity; import org.hibernate.envers.test.entities.manytomany.SetOwningEntity; +import org.junit.Test; + import static org.junit.Assert.assertEquals; /** @@ -26,143 +26,143 @@ import static org.junit.Assert.assertEquals; */ public class ValidityAuditStrategyManyToManyTest extends BaseEnversJPAFunctionalTestCase { - private Integer ing_id; + private Integer ing_id; - private Integer ed_id; + private Integer ed_id; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { SetOwningEntity.class, SetOwnedEntity.class }; - } + return new Class[] {SetOwningEntity.class, SetOwnedEntity.class}; + } @Override protected void addConfigOptions(Map options) { - options.put(EnversSettings.AUDIT_STRATEGY, "org.hibernate.envers.strategy.ValidityAuditStrategy"); + options.put( EnversSettings.AUDIT_STRATEGY, "org.hibernate.envers.strategy.ValidityAuditStrategy" ); } @Test - @Priority(10) - public void initData() { - final EntityManager em = getEntityManager(); + @Priority(10) + public void initData() { + final EntityManager em = getEntityManager(); - final SetOwningEntity setOwningEntity = new SetOwningEntity(1, "parent"); - final SetOwnedEntity setOwnedEntity = new SetOwnedEntity(2, "child"); + final SetOwningEntity setOwningEntity = new SetOwningEntity( 1, "parent" ); + final SetOwnedEntity setOwnedEntity = new SetOwnedEntity( 2, "child" ); - // Revision 1: Initial persist - em.getTransaction().begin(); + // Revision 1: Initial persist + em.getTransaction().begin(); - em.persist(setOwningEntity); - em.persist(setOwnedEntity); + em.persist( setOwningEntity ); + em.persist( setOwnedEntity ); - em.getTransaction().commit(); - em.clear(); + em.getTransaction().commit(); + em.clear(); - ing_id = setOwningEntity.getId(); - ed_id = setOwnedEntity.getId(); - } + ing_id = setOwningEntity.getId(); + ed_id = setOwnedEntity.getId(); + } - @Test - @Priority(5) - public void testMultipleAddAndRemove() { - final EntityManager em = getEntityManager(); + @Test + @Priority(5) + public void testMultipleAddAndRemove() { + final EntityManager em = getEntityManager(); - // Revision 2: add child for first time - em.getTransaction().begin(); + // Revision 2: add child for first time + em.getTransaction().begin(); - SetOwningEntity owningEntity = getEntityManager().find(SetOwningEntity.class, ing_id); - SetOwnedEntity ownedEntity = getEntityManager().find(SetOwnedEntity.class, ed_id); + SetOwningEntity owningEntity = getEntityManager().find( SetOwningEntity.class, ing_id ); + SetOwnedEntity ownedEntity = getEntityManager().find( SetOwnedEntity.class, ed_id ); - owningEntity.setReferences(new HashSet()); - owningEntity.getReferences().add(ownedEntity); + owningEntity.setReferences( new HashSet() ); + owningEntity.getReferences().add( ownedEntity ); - em.getTransaction().commit(); - em.clear(); + em.getTransaction().commit(); + em.clear(); - // Revision 3: remove child - em.getTransaction().begin(); + // Revision 3: remove child + em.getTransaction().begin(); - owningEntity = getEntityManager().find(SetOwningEntity.class, ing_id); - ownedEntity = getEntityManager().find(SetOwnedEntity.class, ed_id); + owningEntity = getEntityManager().find( SetOwningEntity.class, ing_id ); + ownedEntity = getEntityManager().find( SetOwnedEntity.class, ed_id ); - owningEntity.getReferences().remove(ownedEntity); + owningEntity.getReferences().remove( ownedEntity ); - em.getTransaction().commit(); - em.clear(); + em.getTransaction().commit(); + em.clear(); - // Revision 4: add child again - em.getTransaction().begin(); + // Revision 4: add child again + em.getTransaction().begin(); - owningEntity = getEntityManager().find(SetOwningEntity.class, ing_id); - ownedEntity = getEntityManager().find(SetOwnedEntity.class, ed_id); + owningEntity = getEntityManager().find( SetOwningEntity.class, ing_id ); + ownedEntity = getEntityManager().find( SetOwnedEntity.class, ed_id ); - owningEntity.getReferences().add(ownedEntity); + owningEntity.getReferences().add( ownedEntity ); - em.getTransaction().commit(); - em.clear(); + em.getTransaction().commit(); + em.clear(); - // Revision 5: remove child again - em.getTransaction().begin(); + // Revision 5: remove child again + em.getTransaction().begin(); - owningEntity = getEntityManager().find(SetOwningEntity.class, ing_id); - ownedEntity = getEntityManager().find(SetOwnedEntity.class, ed_id); + owningEntity = getEntityManager().find( SetOwningEntity.class, ing_id ); + ownedEntity = getEntityManager().find( SetOwnedEntity.class, ed_id ); - owningEntity.getReferences().remove(ownedEntity); + owningEntity.getReferences().remove( ownedEntity ); - em.getTransaction().commit(); - em.clear(); + em.getTransaction().commit(); + em.clear(); - // now the set owning entity list should be empty again - owningEntity = getEntityManager().find(SetOwningEntity.class, ing_id); - assertEquals(owningEntity.getReferences().size(), 0); - } + // now the set owning entity list should be empty again + owningEntity = getEntityManager().find( SetOwningEntity.class, ing_id ); + assertEquals( owningEntity.getReferences().size(), 0 ); + } - @Test + @Test public void testRevisionsCounts() { - assertEquals(getAuditReader().getRevisions(SetOwningEntity.class, ing_id), Arrays.asList(1, 2, 3, 4, 5)); - assertEquals(getAuditReader().getRevisions(SetOwnedEntity.class, ed_id), Arrays.asList(1, 2, 3, 4, 5)); + assertEquals( getAuditReader().getRevisions( SetOwningEntity.class, ing_id ), Arrays.asList( 1, 2, 3, 4, 5 ) ); + assertEquals( getAuditReader().getRevisions( SetOwnedEntity.class, ed_id ), Arrays.asList( 1, 2, 3, 4, 5 ) ); } @Test public void testHistoryOfIng1() { SetOwningEntity ver_empty = createOwningEntity(); - SetOwningEntity ver_child = createOwningEntity(new SetOwnedEntity(ed_id, "child")); + SetOwningEntity ver_child = createOwningEntity( new SetOwnedEntity( ed_id, "child" ) ); - assertEquals(getAuditReader().find(SetOwningEntity.class, ing_id, 1), ver_empty); - assertEquals(getAuditReader().find(SetOwningEntity.class, ing_id, 2), ver_child); - assertEquals(getAuditReader().find(SetOwningEntity.class, ing_id, 3), ver_empty); - assertEquals(getAuditReader().find(SetOwningEntity.class, ing_id, 4), ver_child); - assertEquals(getAuditReader().find(SetOwningEntity.class, ing_id, 5), ver_empty); + assertEquals( getAuditReader().find( SetOwningEntity.class, ing_id, 1 ), ver_empty ); + assertEquals( getAuditReader().find( SetOwningEntity.class, ing_id, 2 ), ver_child ); + assertEquals( getAuditReader().find( SetOwningEntity.class, ing_id, 3 ), ver_empty ); + assertEquals( getAuditReader().find( SetOwningEntity.class, ing_id, 4 ), ver_child ); + assertEquals( getAuditReader().find( SetOwningEntity.class, ing_id, 5 ), ver_empty ); } - @Test + @Test public void testHistoryOfEd1() { SetOwnedEntity ver_empty = createOwnedEntity(); - SetOwnedEntity ver_child = createOwnedEntity(new SetOwningEntity(ing_id, "parent")); + SetOwnedEntity ver_child = createOwnedEntity( new SetOwningEntity( ing_id, "parent" ) ); - assertEquals(getAuditReader().find(SetOwnedEntity.class, ed_id, 1), ver_empty); - assertEquals(getAuditReader().find(SetOwnedEntity.class, ed_id, 2), ver_child); - assertEquals(getAuditReader().find(SetOwnedEntity.class, ed_id, 3), ver_empty); - assertEquals(getAuditReader().find(SetOwnedEntity.class, ed_id, 4), ver_child); - assertEquals(getAuditReader().find(SetOwnedEntity.class, ed_id, 5), ver_empty); + assertEquals( getAuditReader().find( SetOwnedEntity.class, ed_id, 1 ), ver_empty ); + assertEquals( getAuditReader().find( SetOwnedEntity.class, ed_id, 2 ), ver_child ); + assertEquals( getAuditReader().find( SetOwnedEntity.class, ed_id, 3 ), ver_empty ); + assertEquals( getAuditReader().find( SetOwnedEntity.class, ed_id, 4 ), ver_child ); + assertEquals( getAuditReader().find( SetOwnedEntity.class, ed_id, 5 ), ver_empty ); } - private SetOwningEntity createOwningEntity(SetOwnedEntity... owned) { - SetOwningEntity result = new SetOwningEntity(ing_id, "parent"); - result.setReferences(new HashSet()); - for (SetOwnedEntity setOwnedEntity : owned) { - result.getReferences().add(setOwnedEntity); - } + private SetOwningEntity createOwningEntity(SetOwnedEntity... owned) { + SetOwningEntity result = new SetOwningEntity( ing_id, "parent" ); + result.setReferences( new HashSet() ); + for ( SetOwnedEntity setOwnedEntity : owned ) { + result.getReferences().add( setOwnedEntity ); + } - return result; - } + return result; + } - private SetOwnedEntity createOwnedEntity(SetOwningEntity... owning) { - SetOwnedEntity result = new SetOwnedEntity(ed_id, "child"); - result.setReferencing(new HashSet()); - for (SetOwningEntity setOwningEntity : owning) { - result.getReferencing().add(setOwningEntity); - } + private SetOwnedEntity createOwnedEntity(SetOwningEntity... owning) { + SetOwnedEntity result = new SetOwnedEntity( ed_id, "child" ); + result.setReferencing( new HashSet() ); + for ( SetOwningEntity setOwningEntity : owning ) { + result.getReferencing().add( setOwningEntity ); + } - return result; - } + return result; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/strategy/ValidityAuditStrategyRevEndTestCustomRevEnt.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/strategy/ValidityAuditStrategyRevEndTestCustomRevEnt.java index d0d6007575..214f57f724 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/strategy/ValidityAuditStrategyRevEndTestCustomRevEnt.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/strategy/ValidityAuditStrategyRevEndTestCustomRevEnt.java @@ -23,6 +23,8 @@ */ package org.hibernate.envers.test.integration.strategy; +import javax.persistence.EntityManager; +import javax.persistence.Query; import java.sql.Types; import java.util.Arrays; import java.util.Date; @@ -30,10 +32,6 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; -import javax.persistence.EntityManager; -import javax.persistence.Query; - -import org.junit.Test; import org.hibernate.Session; import org.hibernate.envers.configuration.EnversSettings; @@ -46,10 +44,12 @@ import org.hibernate.envers.test.entities.manytomany.sametable.ParentEntity; import org.hibernate.envers.test.entities.reventity.CustomDateRevEntity; import org.hibernate.envers.test.tools.TestTools; +import org.junit.Test; + /** * Test which checks that the revision end timestamp is correctly set for * {@link ValidityAuditStrategy}. - * + * * @author Erik-Berndt Scheper */ public class ValidityAuditStrategyRevEndTestCustomRevEnt extends BaseEnversJPAFunctionalTestCase { @@ -75,14 +75,14 @@ public class ValidityAuditStrategyRevEndTestCustomRevEnt extends BaseEnversJPAFu @Override protected void addConfigOptions(Map options) { - super.addConfigOptions( options ); - options.put(EnversSettings.AUDIT_STRATEGY, "org.hibernate.envers.strategy.ValidityAuditStrategy"); - options.put(EnversSettings.AUDIT_STRATEGY_VALIDITY_STORE_REVEND_TIMESTAMP, "true"); - options.put(EnversSettings.AUDIT_STRATEGY_VALIDITY_REVEND_TIMESTAMP_FIELD_NAME, revendTimestampColumName); - } + super.addConfigOptions( options ); + options.put( EnversSettings.AUDIT_STRATEGY, "org.hibernate.envers.strategy.ValidityAuditStrategy" ); + options.put( EnversSettings.AUDIT_STRATEGY_VALIDITY_STORE_REVEND_TIMESTAMP, "true" ); + options.put( EnversSettings.AUDIT_STRATEGY_VALIDITY_REVEND_TIMESTAMP_FIELD_NAME, revendTimestampColumName ); + } @Test - @Priority(10) + @Priority(10) public void initData() { EntityManager em = getEntityManager(); @@ -91,45 +91,47 @@ public class ValidityAuditStrategyRevEndTestCustomRevEnt extends BaseEnversJPAFu // to allow this. em.getTransaction().begin(); Session session = (Session) em.getDelegate(); - session.createSQLQuery("DROP TABLE children").executeUpdate(); + session.createSQLQuery( "DROP TABLE children" ).executeUpdate(); session .createSQLQuery( - "CREATE TABLE children ( parent_id " + getDialect().getTypeName(Types.INTEGER) + - ", child1_id " + getDialect().getTypeName(Types.INTEGER) + " NULL" + - ", child2_id " + getDialect().getTypeName(Types.INTEGER) + " NULL )") + "CREATE TABLE children ( parent_id " + getDialect().getTypeName( Types.INTEGER ) + + ", child1_id " + getDialect().getTypeName( Types.INTEGER ) + " NULL" + + ", child2_id " + getDialect().getTypeName( Types.INTEGER ) + " NULL )" + ) .executeUpdate(); - session.createSQLQuery("DROP TABLE children_AUD").executeUpdate(); + session.createSQLQuery( "DROP TABLE children_AUD" ).executeUpdate(); session .createSQLQuery( - "CREATE TABLE children_AUD ( REV " + getDialect().getTypeName(Types.INTEGER) + " NOT NULL" + - ", REVEND " + getDialect().getTypeName(Types.INTEGER) + - ", " + revendTimestampColumName + " " + getDialect().getTypeName(Types.TIMESTAMP) + - ", REVTYPE " + getDialect().getTypeName(Types.TINYINT) + - ", parent_id " + getDialect().getTypeName(Types.INTEGER) + - ", child1_id " + getDialect().getTypeName(Types.INTEGER) + " NULL" + - ", child2_id " + getDialect().getTypeName(Types.INTEGER) + " NULL )") + "CREATE TABLE children_AUD ( REV " + getDialect().getTypeName( Types.INTEGER ) + " NOT NULL" + + ", REVEND " + getDialect().getTypeName( Types.INTEGER ) + + ", " + revendTimestampColumName + " " + getDialect().getTypeName( Types.TIMESTAMP ) + + ", REVTYPE " + getDialect().getTypeName( Types.TINYINT ) + + ", parent_id " + getDialect().getTypeName( Types.INTEGER ) + + ", child1_id " + getDialect().getTypeName( Types.INTEGER ) + " NULL" + + ", child2_id " + getDialect().getTypeName( Types.INTEGER ) + " NULL )" + ) .executeUpdate(); em.getTransaction().commit(); em.clear(); - ParentEntity p1 = new ParentEntity("parent_1"); - ParentEntity p2 = new ParentEntity("parent_2"); + ParentEntity p1 = new ParentEntity( "parent_1" ); + ParentEntity p2 = new ParentEntity( "parent_2" ); - Child1Entity c1_1 = new Child1Entity("child1_1"); - Child1Entity c1_2 = new Child1Entity("child1_2"); + Child1Entity c1_1 = new Child1Entity( "child1_1" ); + Child1Entity c1_2 = new Child1Entity( "child1_2" ); - Child2Entity c2_1 = new Child2Entity("child2_1"); - Child2Entity c2_2 = new Child2Entity("child2_2"); + Child2Entity c2_1 = new Child2Entity( "child2_1" ); + Child2Entity c2_2 = new Child2Entity( "child2_2" ); // Revision 1 em.getTransaction().begin(); - em.persist(p1); - em.persist(p2); - em.persist(c1_1); - em.persist(c1_2); - em.persist(c2_1); - em.persist(c2_2); + em.persist( p1 ); + em.persist( p2 ); + em.persist( c1_1 ); + em.persist( c1_2 ); + em.persist( c2_1 ); + em.persist( c2_2 ); em.getTransaction().commit(); em.clear(); @@ -138,13 +140,13 @@ public class ValidityAuditStrategyRevEndTestCustomRevEnt extends BaseEnversJPAFu em.getTransaction().begin(); - p1 = em.find(ParentEntity.class, p1.getId()); - p2 = em.find(ParentEntity.class, p2.getId()); - c1_1 = em.find(Child1Entity.class, c1_1.getId()); - c2_1 = em.find(Child2Entity.class, c2_1.getId()); + p1 = em.find( ParentEntity.class, p1.getId() ); + p2 = em.find( ParentEntity.class, p2.getId() ); + c1_1 = em.find( Child1Entity.class, c1_1.getId() ); + c2_1 = em.find( Child2Entity.class, c2_1.getId() ); - p1.getChildren1().add(c1_1); - p2.getChildren2().add(c2_1); + p1.getChildren1().add( c1_1 ); + p2.getChildren2().add( c2_1 ); em.getTransaction().commit(); em.clear(); @@ -152,16 +154,16 @@ public class ValidityAuditStrategyRevEndTestCustomRevEnt extends BaseEnversJPAFu // Revision 3 - (p1: c1_1, c1_2, c2_2, p2: c1_1, c2_1) em.getTransaction().begin(); - p1 = em.find(ParentEntity.class, p1.getId()); - p2 = em.find(ParentEntity.class, p2.getId()); - c1_1 = em.find(Child1Entity.class, c1_1.getId()); - c1_2 = em.find(Child1Entity.class, c1_2.getId()); - c2_2 = em.find(Child2Entity.class, c2_2.getId()); + p1 = em.find( ParentEntity.class, p1.getId() ); + p2 = em.find( ParentEntity.class, p2.getId() ); + c1_1 = em.find( Child1Entity.class, c1_1.getId() ); + c1_2 = em.find( Child1Entity.class, c1_2.getId() ); + c2_2 = em.find( Child2Entity.class, c2_2.getId() ); - p1.getChildren1().add(c1_2); - p1.getChildren2().add(c2_2); + p1.getChildren1().add( c1_2 ); + p1.getChildren2().add( c2_2 ); - p2.getChildren1().add(c1_1); + p2.getChildren1().add( c1_1 ); em.getTransaction().commit(); em.clear(); @@ -169,13 +171,13 @@ public class ValidityAuditStrategyRevEndTestCustomRevEnt extends BaseEnversJPAFu // Revision 4 - (p1: c1_2, c2_2, p2: c1_1, c2_1, c2_2) em.getTransaction().begin(); - p1 = em.find(ParentEntity.class, p1.getId()); - p2 = em.find(ParentEntity.class, p2.getId()); - c1_1 = em.find(Child1Entity.class, c1_1.getId()); - c2_2 = em.find(Child2Entity.class, c2_2.getId()); + p1 = em.find( ParentEntity.class, p1.getId() ); + p2 = em.find( ParentEntity.class, p2.getId() ); + c1_1 = em.find( Child1Entity.class, c1_1.getId() ); + c2_2 = em.find( Child2Entity.class, c2_2.getId() ); - p1.getChildren1().remove(c1_1); - p2.getChildren2().add(c2_2); + p1.getChildren1().remove( c1_1 ); + p2.getChildren2().add( c2_2 ); em.getTransaction().commit(); em.clear(); @@ -183,13 +185,13 @@ public class ValidityAuditStrategyRevEndTestCustomRevEnt extends BaseEnversJPAFu // Revision 5 - (p1: c2_2, p2: c1_1, c2_1) em.getTransaction().begin(); - p1 = em.find(ParentEntity.class, p1.getId()); - p2 = em.find(ParentEntity.class, p2.getId()); - c1_2 = em.find(Child1Entity.class, c1_2.getId()); - c2_2 = em.find(Child2Entity.class, c2_2.getId()); + p1 = em.find( ParentEntity.class, p1.getId() ); + p2 = em.find( ParentEntity.class, p2.getId() ); + c1_2 = em.find( Child1Entity.class, c1_2.getId() ); + c2_2 = em.find( Child2Entity.class, c2_2.getId() ); - c2_2.getParents().remove(p2); - c1_2.getParents().remove(p1); + c2_2.getParents().remove( p2 ); + c1_2.getParents().remove( p1 ); em.getTransaction().commit(); em.clear(); @@ -204,52 +206,72 @@ public class ValidityAuditStrategyRevEndTestCustomRevEnt extends BaseEnversJPAFu c2_2_id = c2_2.getId(); Set revisionNumbers = new HashSet(); - revisionNumbers.addAll(Arrays.asList(1, 2, 3, 4, 5)); - revisions = getAuditReader().findRevisions(CustomDateRevEntity.class, - revisionNumbers); + revisionNumbers.addAll( Arrays.asList( 1, 2, 3, 4, 5 ) ); + revisions = getAuditReader().findRevisions( + CustomDateRevEntity.class, + revisionNumbers + ); assert revisions.size() == 5; } @Test public void testRevisionsCounts() { - assert Arrays.asList(1, 2, 3, 4).equals( - getAuditReader().getRevisions(ParentEntity.class, p1_id)); - assert Arrays.asList(1, 2, 3, 4).equals( - getAuditReader().getRevisions(ParentEntity.class, p2_id)); + assert Arrays.asList( 1, 2, 3, 4 ).equals( + getAuditReader().getRevisions( ParentEntity.class, p1_id ) + ); + assert Arrays.asList( 1, 2, 3, 4 ).equals( + getAuditReader().getRevisions( ParentEntity.class, p2_id ) + ); - assert Arrays.asList(1).equals( - getAuditReader().getRevisions(Child1Entity.class, c1_1_id)); - assert Arrays.asList(1, 5).equals( - getAuditReader().getRevisions(Child1Entity.class, c1_2_id)); + assert Arrays.asList( 1 ).equals( + getAuditReader().getRevisions( Child1Entity.class, c1_1_id ) + ); + assert Arrays.asList( 1, 5 ).equals( + getAuditReader().getRevisions( Child1Entity.class, c1_2_id ) + ); - assert Arrays.asList(1).equals( - getAuditReader().getRevisions(Child2Entity.class, c2_1_id)); - assert Arrays.asList(1, 5).equals( - getAuditReader().getRevisions(Child2Entity.class, c2_2_id)); + assert Arrays.asList( 1 ).equals( + getAuditReader().getRevisions( Child2Entity.class, c2_1_id ) + ); + assert Arrays.asList( 1, 5 ).equals( + getAuditReader().getRevisions( Child2Entity.class, c2_2_id ) + ); } @Test public void testAllRevEndTimeStamps() { - List> p1RevList = getRevisions(ParentEntity.class, - p1_id); - List> p2RevList = getRevisions(ParentEntity.class, - p2_id); - List> c1_1_List = getRevisions(Child1Entity.class, - c1_1_id); - List> c1_2_List = getRevisions(Child1Entity.class, - c1_2_id); - List> c2_1_List = getRevisions(Child2Entity.class, - c2_1_id); - List> c2_2_List = getRevisions(Child2Entity.class, - c2_2_id); + List> p1RevList = getRevisions( + ParentEntity.class, + p1_id + ); + List> p2RevList = getRevisions( + ParentEntity.class, + p2_id + ); + List> c1_1_List = getRevisions( + Child1Entity.class, + c1_1_id + ); + List> c1_2_List = getRevisions( + Child1Entity.class, + c1_2_id + ); + List> c2_1_List = getRevisions( + Child2Entity.class, + c2_1_id + ); + List> c2_2_List = getRevisions( + Child2Entity.class, + c2_2_id + ); - verifyRevEndTimeStamps("ParentEntity: " + p1_id, p1RevList); - verifyRevEndTimeStamps("ParentEntity: " + p2_id, p2RevList); - verifyRevEndTimeStamps("Child1Entity: " + c1_1_id, c1_1_List); - verifyRevEndTimeStamps("Child1Entity: " + c1_2_id, c1_2_List); - verifyRevEndTimeStamps("Child2Entity: " + c2_1_id, c2_1_List); - verifyRevEndTimeStamps("Child2Entity: " + c2_2_id, c2_2_List); + verifyRevEndTimeStamps( "ParentEntity: " + p1_id, p1RevList ); + verifyRevEndTimeStamps( "ParentEntity: " + p2_id, p2RevList ); + verifyRevEndTimeStamps( "Child1Entity: " + c1_1_id, c1_1_List ); + verifyRevEndTimeStamps( "Child1Entity: " + c1_2_id, c1_2_List ); + verifyRevEndTimeStamps( "Child2Entity: " + c2_1_id, c2_1_List ); + verifyRevEndTimeStamps( "Child2Entity: " + c2_2_id, c2_2_List ); } @@ -257,148 +279,188 @@ public class ValidityAuditStrategyRevEndTestCustomRevEnt extends BaseEnversJPAFu public void testHistoryOfParent1() { Child1Entity c1_1 = getEntityManager() - .find(Child1Entity.class, c1_1_id); + .find( Child1Entity.class, c1_1_id ); Child1Entity c1_2 = getEntityManager() - .find(Child1Entity.class, c1_2_id); + .find( Child1Entity.class, c1_2_id ); Child2Entity c2_2 = getEntityManager() - .find(Child2Entity.class, c2_2_id); + .find( Child2Entity.class, c2_2_id ); - ParentEntity rev1 = getAuditReader().find(ParentEntity.class, p1_id, 1); - ParentEntity rev2 = getAuditReader().find(ParentEntity.class, p1_id, 2); - ParentEntity rev3 = getAuditReader().find(ParentEntity.class, p1_id, 3); - ParentEntity rev4 = getAuditReader().find(ParentEntity.class, p1_id, 4); - ParentEntity rev5 = getAuditReader().find(ParentEntity.class, p1_id, 5); + ParentEntity rev1 = getAuditReader().find( ParentEntity.class, p1_id, 1 ); + ParentEntity rev2 = getAuditReader().find( ParentEntity.class, p1_id, 2 ); + ParentEntity rev3 = getAuditReader().find( ParentEntity.class, p1_id, 3 ); + ParentEntity rev4 = getAuditReader().find( ParentEntity.class, p1_id, 4 ); + ParentEntity rev5 = getAuditReader().find( ParentEntity.class, p1_id, 5 ); - assert TestTools.checkList(rev1.getChildren1()); - assert TestTools.checkList(rev2.getChildren1(), c1_1); - assert TestTools.checkList(rev3.getChildren1(), c1_1, c1_2); - assert TestTools.checkList(rev4.getChildren1(), c1_2); - assert TestTools.checkList(rev5.getChildren1()); + assert TestTools.checkList( rev1.getChildren1() ); + assert TestTools.checkList( rev2.getChildren1(), c1_1 ); + assert TestTools.checkList( rev3.getChildren1(), c1_1, c1_2 ); + assert TestTools.checkList( rev4.getChildren1(), c1_2 ); + assert TestTools.checkList( rev5.getChildren1() ); - assert TestTools.checkList(rev1.getChildren2()); - assert TestTools.checkList(rev2.getChildren2()); - assert TestTools.checkList(rev3.getChildren2(), c2_2); - assert TestTools.checkList(rev4.getChildren2(), c2_2); - assert TestTools.checkList(rev5.getChildren2(), c2_2); + assert TestTools.checkList( rev1.getChildren2() ); + assert TestTools.checkList( rev2.getChildren2() ); + assert TestTools.checkList( rev3.getChildren2(), c2_2 ); + assert TestTools.checkList( rev4.getChildren2(), c2_2 ); + assert TestTools.checkList( rev5.getChildren2(), c2_2 ); } @Test public void testHistoryOfParent2() { Child1Entity c1_1 = getEntityManager() - .find(Child1Entity.class, c1_1_id); + .find( Child1Entity.class, c1_1_id ); Child2Entity c2_1 = getEntityManager() - .find(Child2Entity.class, c2_1_id); + .find( Child2Entity.class, c2_1_id ); Child2Entity c2_2 = getEntityManager() - .find(Child2Entity.class, c2_2_id); + .find( Child2Entity.class, c2_2_id ); - ParentEntity rev1 = getAuditReader().find(ParentEntity.class, p2_id, 1); - ParentEntity rev2 = getAuditReader().find(ParentEntity.class, p2_id, 2); - ParentEntity rev3 = getAuditReader().find(ParentEntity.class, p2_id, 3); - ParentEntity rev4 = getAuditReader().find(ParentEntity.class, p2_id, 4); - ParentEntity rev5 = getAuditReader().find(ParentEntity.class, p2_id, 5); + ParentEntity rev1 = getAuditReader().find( ParentEntity.class, p2_id, 1 ); + ParentEntity rev2 = getAuditReader().find( ParentEntity.class, p2_id, 2 ); + ParentEntity rev3 = getAuditReader().find( ParentEntity.class, p2_id, 3 ); + ParentEntity rev4 = getAuditReader().find( ParentEntity.class, p2_id, 4 ); + ParentEntity rev5 = getAuditReader().find( ParentEntity.class, p2_id, 5 ); - assert TestTools.checkList(rev1.getChildren1()); - assert TestTools.checkList(rev2.getChildren1()); - assert TestTools.checkList(rev3.getChildren1(), c1_1); - assert TestTools.checkList(rev4.getChildren1(), c1_1); - assert TestTools.checkList(rev5.getChildren1(), c1_1); + assert TestTools.checkList( rev1.getChildren1() ); + assert TestTools.checkList( rev2.getChildren1() ); + assert TestTools.checkList( rev3.getChildren1(), c1_1 ); + assert TestTools.checkList( rev4.getChildren1(), c1_1 ); + assert TestTools.checkList( rev5.getChildren1(), c1_1 ); - assert TestTools.checkList(rev1.getChildren2()); - assert TestTools.checkList(rev2.getChildren2(), c2_1); - assert TestTools.checkList(rev3.getChildren2(), c2_1); - assert TestTools.checkList(rev4.getChildren2(), c2_1, c2_2); - assert TestTools.checkList(rev5.getChildren2(), c2_1); + assert TestTools.checkList( rev1.getChildren2() ); + assert TestTools.checkList( rev2.getChildren2(), c2_1 ); + assert TestTools.checkList( rev3.getChildren2(), c2_1 ); + assert TestTools.checkList( rev4.getChildren2(), c2_1, c2_2 ); + assert TestTools.checkList( rev5.getChildren2(), c2_1 ); } @Test public void testHistoryOfChild1_1() { - ParentEntity p1 = getEntityManager().find(ParentEntity.class, p1_id); - ParentEntity p2 = getEntityManager().find(ParentEntity.class, p2_id); + ParentEntity p1 = getEntityManager().find( ParentEntity.class, p1_id ); + ParentEntity p2 = getEntityManager().find( ParentEntity.class, p2_id ); - Child1Entity rev1 = getAuditReader().find(Child1Entity.class, c1_1_id, - 1); - Child1Entity rev2 = getAuditReader().find(Child1Entity.class, c1_1_id, - 2); - Child1Entity rev3 = getAuditReader().find(Child1Entity.class, c1_1_id, - 3); - Child1Entity rev4 = getAuditReader().find(Child1Entity.class, c1_1_id, - 4); - Child1Entity rev5 = getAuditReader().find(Child1Entity.class, c1_1_id, - 5); + Child1Entity rev1 = getAuditReader().find( + Child1Entity.class, c1_1_id, + 1 + ); + Child1Entity rev2 = getAuditReader().find( + Child1Entity.class, c1_1_id, + 2 + ); + Child1Entity rev3 = getAuditReader().find( + Child1Entity.class, c1_1_id, + 3 + ); + Child1Entity rev4 = getAuditReader().find( + Child1Entity.class, c1_1_id, + 4 + ); + Child1Entity rev5 = getAuditReader().find( + Child1Entity.class, c1_1_id, + 5 + ); - assert TestTools.checkList(rev1.getParents()); - assert TestTools.checkList(rev2.getParents(), p1); - assert TestTools.checkList(rev3.getParents(), p1, p2); - assert TestTools.checkList(rev4.getParents(), p2); - assert TestTools.checkList(rev5.getParents(), p2); + assert TestTools.checkList( rev1.getParents() ); + assert TestTools.checkList( rev2.getParents(), p1 ); + assert TestTools.checkList( rev3.getParents(), p1, p2 ); + assert TestTools.checkList( rev4.getParents(), p2 ); + assert TestTools.checkList( rev5.getParents(), p2 ); } - // TODO: this was disabled? + // TODO: this was disabled? @Test public void testHistoryOfChild1_2() { - ParentEntity p1 = getEntityManager().find(ParentEntity.class, p1_id); + ParentEntity p1 = getEntityManager().find( ParentEntity.class, p1_id ); - Child1Entity rev1 = getAuditReader().find(Child1Entity.class, c1_2_id, - 1); - Child1Entity rev2 = getAuditReader().find(Child1Entity.class, c1_2_id, - 2); - Child1Entity rev3 = getAuditReader().find(Child1Entity.class, c1_2_id, - 3); - Child1Entity rev4 = getAuditReader().find(Child1Entity.class, c1_2_id, - 4); - Child1Entity rev5 = getAuditReader().find(Child1Entity.class, c1_2_id, - 5); + Child1Entity rev1 = getAuditReader().find( + Child1Entity.class, c1_2_id, + 1 + ); + Child1Entity rev2 = getAuditReader().find( + Child1Entity.class, c1_2_id, + 2 + ); + Child1Entity rev3 = getAuditReader().find( + Child1Entity.class, c1_2_id, + 3 + ); + Child1Entity rev4 = getAuditReader().find( + Child1Entity.class, c1_2_id, + 4 + ); + Child1Entity rev5 = getAuditReader().find( + Child1Entity.class, c1_2_id, + 5 + ); - assert TestTools.checkList(rev1.getParents()); - assert TestTools.checkList(rev2.getParents()); - assert TestTools.checkList(rev3.getParents(), p1); - assert TestTools.checkList(rev4.getParents(), p1); - assert TestTools.checkList(rev5.getParents()); + assert TestTools.checkList( rev1.getParents() ); + assert TestTools.checkList( rev2.getParents() ); + assert TestTools.checkList( rev3.getParents(), p1 ); + assert TestTools.checkList( rev4.getParents(), p1 ); + assert TestTools.checkList( rev5.getParents() ); } @Test public void testHistoryOfChild2_1() { - ParentEntity p2 = getEntityManager().find(ParentEntity.class, p2_id); + ParentEntity p2 = getEntityManager().find( ParentEntity.class, p2_id ); - Child2Entity rev1 = getAuditReader().find(Child2Entity.class, c2_1_id, - 1); - Child2Entity rev2 = getAuditReader().find(Child2Entity.class, c2_1_id, - 2); - Child2Entity rev3 = getAuditReader().find(Child2Entity.class, c2_1_id, - 3); - Child2Entity rev4 = getAuditReader().find(Child2Entity.class, c2_1_id, - 4); - Child2Entity rev5 = getAuditReader().find(Child2Entity.class, c2_1_id, - 5); + Child2Entity rev1 = getAuditReader().find( + Child2Entity.class, c2_1_id, + 1 + ); + Child2Entity rev2 = getAuditReader().find( + Child2Entity.class, c2_1_id, + 2 + ); + Child2Entity rev3 = getAuditReader().find( + Child2Entity.class, c2_1_id, + 3 + ); + Child2Entity rev4 = getAuditReader().find( + Child2Entity.class, c2_1_id, + 4 + ); + Child2Entity rev5 = getAuditReader().find( + Child2Entity.class, c2_1_id, + 5 + ); - assert TestTools.checkList(rev1.getParents()); - assert TestTools.checkList(rev2.getParents(), p2); - assert TestTools.checkList(rev3.getParents(), p2); - assert TestTools.checkList(rev4.getParents(), p2); - assert TestTools.checkList(rev5.getParents(), p2); + assert TestTools.checkList( rev1.getParents() ); + assert TestTools.checkList( rev2.getParents(), p2 ); + assert TestTools.checkList( rev3.getParents(), p2 ); + assert TestTools.checkList( rev4.getParents(), p2 ); + assert TestTools.checkList( rev5.getParents(), p2 ); } @Test public void testHistoryOfChild2_2() { - ParentEntity p1 = getEntityManager().find(ParentEntity.class, p1_id); - ParentEntity p2 = getEntityManager().find(ParentEntity.class, p2_id); + ParentEntity p1 = getEntityManager().find( ParentEntity.class, p1_id ); + ParentEntity p2 = getEntityManager().find( ParentEntity.class, p2_id ); - Child2Entity rev1 = getAuditReader().find(Child2Entity.class, c2_2_id, - 1); - Child2Entity rev2 = getAuditReader().find(Child2Entity.class, c2_2_id, - 2); - Child2Entity rev3 = getAuditReader().find(Child2Entity.class, c2_2_id, - 3); - Child2Entity rev4 = getAuditReader().find(Child2Entity.class, c2_2_id, - 4); - Child2Entity rev5 = getAuditReader().find(Child2Entity.class, c2_2_id, - 5); + Child2Entity rev1 = getAuditReader().find( + Child2Entity.class, c2_2_id, + 1 + ); + Child2Entity rev2 = getAuditReader().find( + Child2Entity.class, c2_2_id, + 2 + ); + Child2Entity rev3 = getAuditReader().find( + Child2Entity.class, c2_2_id, + 3 + ); + Child2Entity rev4 = getAuditReader().find( + Child2Entity.class, c2_2_id, + 4 + ); + Child2Entity rev5 = getAuditReader().find( + Child2Entity.class, c2_2_id, + 5 + ); - assert TestTools.checkList(rev1.getParents()); - assert TestTools.checkList(rev2.getParents()); - assert TestTools.checkList(rev3.getParents(), p1); - assert TestTools.checkList(rev4.getParents(), p1, p2); - assert TestTools.checkList(rev5.getParents(), p1); + assert TestTools.checkList( rev1.getParents() ); + assert TestTools.checkList( rev2.getParents() ); + assert TestTools.checkList( rev3.getParents(), p1 ); + assert TestTools.checkList( rev4.getParents(), p1, p2 ); + assert TestTools.checkList( rev5.getParents(), p1 ); } private List> getRevisions( @@ -408,31 +470,33 @@ public class ValidityAuditStrategyRevEndTestCustomRevEnt extends BaseEnversJPAFu // org.hibernate.envers.test.entities.manytomany.sametable.ParentEntity_AUD // auditEntity where auditEntity.originalId.id = :originalEntityId - StringBuilder builder = new StringBuilder("select auditEntity from "); - builder.append(originalEntityClazz.getName()) - .append("_AUD auditEntity"); - builder.append(" where auditEntity.originalId.id = :originalEntityId"); + StringBuilder builder = new StringBuilder( "select auditEntity from " ); + builder.append( originalEntityClazz.getName() ) + .append( "_AUD auditEntity" ); + builder.append( " where auditEntity.originalId.id = :originalEntityId" ); - Query qry = getEntityManager().createQuery(builder.toString()); - qry.setParameter("originalEntityId", originalEntityId); + Query qry = getEntityManager().createQuery( builder.toString() ); + qry.setParameter( "originalEntityId", originalEntityId ); @SuppressWarnings("unchecked") List> resultList = qry.getResultList(); return resultList; } - private void verifyRevEndTimeStamps(String debugInfo, + private void verifyRevEndTimeStamps( + String debugInfo, List> revisionEntities) { - for (Map revisionEntity : revisionEntities) { + for ( Map revisionEntity : revisionEntities ) { Date revendTimestamp = (Date) revisionEntity - .get(revendTimestampColumName); + .get( revendTimestampColumName ); CustomDateRevEntity revEnd = (CustomDateRevEntity) revisionEntity - .get("REVEND"); + .get( "REVEND" ); - if (revendTimestamp == null) { + if ( revendTimestamp == null ) { assert revEnd == null; - } else { + } + else { assert revendTimestamp.getTime() == revEnd.getDateTimestamp().getTime(); } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/strategy/ValidityAuditStrategyRevEndTsTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/strategy/ValidityAuditStrategyRevEndTsTest.java index 6c79992434..0957f120ea 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/strategy/ValidityAuditStrategyRevEndTsTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/strategy/ValidityAuditStrategyRevEndTsTest.java @@ -23,6 +23,8 @@ */ package org.hibernate.envers.test.integration.strategy; +import javax.persistence.EntityManager; +import javax.persistence.Query; import java.sql.Types; import java.util.Arrays; import java.util.Date; @@ -30,11 +32,6 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; -import javax.persistence.EntityManager; -import javax.persistence.Query; - -import org.junit.Assert; -import org.junit.Test; import org.hibernate.Session; import org.hibernate.dialect.MySQL5Dialect; @@ -49,10 +46,13 @@ import org.hibernate.envers.test.entities.manytomany.sametable.Child2Entity; import org.hibernate.envers.test.entities.manytomany.sametable.ParentEntity; import org.hibernate.envers.test.tools.TestTools; +import org.junit.Assert; +import org.junit.Test; + /** * Test which checks that the revision end timestamp is correctly set for * {@link ValidityAuditStrategy}. - * + * * @author Erik-Berndt Scheper */ public class ValidityAuditStrategyRevEndTsTest extends BaseEnversJPAFunctionalTestCase { @@ -68,19 +68,19 @@ public class ValidityAuditStrategyRevEndTsTest extends BaseEnversJPAFunctionalTe @Override protected Class[] getAnnotatedClasses() { - return new Class[] { ParentEntity.class, Child1Entity.class, Child2Entity.class }; + return new Class[] {ParentEntity.class, Child1Entity.class, Child2Entity.class}; } @Override protected void addConfigOptions(Map options) { super.addConfigOptions( options ); - options.put(EnversSettings.AUDIT_STRATEGY, "org.hibernate.envers.strategy.ValidityAuditStrategy"); - options.put(EnversSettings.AUDIT_STRATEGY_VALIDITY_STORE_REVEND_TIMESTAMP, "true"); - options.put(EnversSettings.AUDIT_STRATEGY_VALIDITY_REVEND_TIMESTAMP_FIELD_NAME, revendTimestampColumName); + options.put( EnversSettings.AUDIT_STRATEGY, "org.hibernate.envers.strategy.ValidityAuditStrategy" ); + options.put( EnversSettings.AUDIT_STRATEGY_VALIDITY_STORE_REVEND_TIMESTAMP, "true" ); + options.put( EnversSettings.AUDIT_STRATEGY_VALIDITY_REVEND_TIMESTAMP_FIELD_NAME, revendTimestampColumName ); } @Test - @Priority(10) + @Priority(10) public void initData() { EntityManager em = getEntityManager(); @@ -89,45 +89,47 @@ public class ValidityAuditStrategyRevEndTsTest extends BaseEnversJPAFunctionalTe // to allow this. em.getTransaction().begin(); Session session = (Session) em.getDelegate(); - session.createSQLQuery("DROP TABLE children").executeUpdate(); + session.createSQLQuery( "DROP TABLE children" ).executeUpdate(); session .createSQLQuery( - "CREATE TABLE children ( parent_id " + getDialect().getTypeName(Types.INTEGER) + - ", child1_id " + getDialect().getTypeName(Types.INTEGER) + " NULL" + - ", child2_id " + getDialect().getTypeName(Types.INTEGER) + " NULL )") + "CREATE TABLE children ( parent_id " + getDialect().getTypeName( Types.INTEGER ) + + ", child1_id " + getDialect().getTypeName( Types.INTEGER ) + " NULL" + + ", child2_id " + getDialect().getTypeName( Types.INTEGER ) + " NULL )" + ) .executeUpdate(); - session.createSQLQuery("DROP TABLE children_AUD").executeUpdate(); + session.createSQLQuery( "DROP TABLE children_AUD" ).executeUpdate(); session .createSQLQuery( - "CREATE TABLE children_AUD ( REV " + getDialect().getTypeName(Types.INTEGER) + " NOT NULL" + - ", REVEND " + getDialect().getTypeName(Types.INTEGER) + - ", " + revendTimestampColumName + " " + getDialect().getTypeName(Types.TIMESTAMP) + - ", REVTYPE " + getDialect().getTypeName(Types.TINYINT) + - ", parent_id " + getDialect().getTypeName(Types.INTEGER) + - ", child1_id " + getDialect().getTypeName(Types.INTEGER) + " NULL" + - ", child2_id " + getDialect().getTypeName(Types.INTEGER) + " NULL )") + "CREATE TABLE children_AUD ( REV " + getDialect().getTypeName( Types.INTEGER ) + " NOT NULL" + + ", REVEND " + getDialect().getTypeName( Types.INTEGER ) + + ", " + revendTimestampColumName + " " + getDialect().getTypeName( Types.TIMESTAMP ) + + ", REVTYPE " + getDialect().getTypeName( Types.TINYINT ) + + ", parent_id " + getDialect().getTypeName( Types.INTEGER ) + + ", child1_id " + getDialect().getTypeName( Types.INTEGER ) + " NULL" + + ", child2_id " + getDialect().getTypeName( Types.INTEGER ) + " NULL )" + ) .executeUpdate(); em.getTransaction().commit(); em.clear(); - ParentEntity p1 = new ParentEntity("parent_1"); - ParentEntity p2 = new ParentEntity("parent_2"); + ParentEntity p1 = new ParentEntity( "parent_1" ); + ParentEntity p2 = new ParentEntity( "parent_2" ); - Child1Entity c1_1 = new Child1Entity("child1_1"); - Child1Entity c1_2 = new Child1Entity("child1_2"); + Child1Entity c1_1 = new Child1Entity( "child1_1" ); + Child1Entity c1_2 = new Child1Entity( "child1_2" ); - Child2Entity c2_1 = new Child2Entity("child2_1"); - Child2Entity c2_2 = new Child2Entity("child2_2"); + Child2Entity c2_1 = new Child2Entity( "child2_1" ); + Child2Entity c2_2 = new Child2Entity( "child2_2" ); // Revision 1 em.getTransaction().begin(); - em.persist(p1); - em.persist(p2); - em.persist(c1_1); - em.persist(c1_2); - em.persist(c2_1); - em.persist(c2_2); + em.persist( p1 ); + em.persist( p2 ); + em.persist( c1_1 ); + em.persist( c1_2 ); + em.persist( c2_1 ); + em.persist( c2_2 ); em.getTransaction().commit(); em.clear(); @@ -136,13 +138,13 @@ public class ValidityAuditStrategyRevEndTsTest extends BaseEnversJPAFunctionalTe em.getTransaction().begin(); - p1 = em.find(ParentEntity.class, p1.getId()); - p2 = em.find(ParentEntity.class, p2.getId()); - c1_1 = em.find(Child1Entity.class, c1_1.getId()); - c2_1 = em.find(Child2Entity.class, c2_1.getId()); + p1 = em.find( ParentEntity.class, p1.getId() ); + p2 = em.find( ParentEntity.class, p2.getId() ); + c1_1 = em.find( Child1Entity.class, c1_1.getId() ); + c2_1 = em.find( Child2Entity.class, c2_1.getId() ); - p1.getChildren1().add(c1_1); - p2.getChildren2().add(c2_1); + p1.getChildren1().add( c1_1 ); + p2.getChildren2().add( c2_1 ); em.getTransaction().commit(); em.clear(); @@ -150,16 +152,16 @@ public class ValidityAuditStrategyRevEndTsTest extends BaseEnversJPAFunctionalTe // Revision 3 - (p1: c1_1, c1_2, c2_2, p2: c1_1, c2_1) em.getTransaction().begin(); - p1 = em.find(ParentEntity.class, p1.getId()); - p2 = em.find(ParentEntity.class, p2.getId()); - c1_1 = em.find(Child1Entity.class, c1_1.getId()); - c1_2 = em.find(Child1Entity.class, c1_2.getId()); - c2_2 = em.find(Child2Entity.class, c2_2.getId()); + p1 = em.find( ParentEntity.class, p1.getId() ); + p2 = em.find( ParentEntity.class, p2.getId() ); + c1_1 = em.find( Child1Entity.class, c1_1.getId() ); + c1_2 = em.find( Child1Entity.class, c1_2.getId() ); + c2_2 = em.find( Child2Entity.class, c2_2.getId() ); - p1.getChildren1().add(c1_2); - p1.getChildren2().add(c2_2); + p1.getChildren1().add( c1_2 ); + p1.getChildren2().add( c2_2 ); - p2.getChildren1().add(c1_1); + p2.getChildren1().add( c1_1 ); em.getTransaction().commit(); em.clear(); @@ -167,13 +169,13 @@ public class ValidityAuditStrategyRevEndTsTest extends BaseEnversJPAFunctionalTe // Revision 4 - (p1: c1_2, c2_2, p2: c1_1, c2_1, c2_2) em.getTransaction().begin(); - p1 = em.find(ParentEntity.class, p1.getId()); - p2 = em.find(ParentEntity.class, p2.getId()); - c1_1 = em.find(Child1Entity.class, c1_1.getId()); - c2_2 = em.find(Child2Entity.class, c2_2.getId()); + p1 = em.find( ParentEntity.class, p1.getId() ); + p2 = em.find( ParentEntity.class, p2.getId() ); + c1_1 = em.find( Child1Entity.class, c1_1.getId() ); + c2_2 = em.find( Child2Entity.class, c2_2.getId() ); - p1.getChildren1().remove(c1_1); - p2.getChildren2().add(c2_2); + p1.getChildren1().remove( c1_1 ); + p2.getChildren2().add( c2_2 ); em.getTransaction().commit(); em.clear(); @@ -181,13 +183,13 @@ public class ValidityAuditStrategyRevEndTsTest extends BaseEnversJPAFunctionalTe // Revision 5 - (p1: c2_2, p2: c1_1, c2_1) em.getTransaction().begin(); - p1 = em.find(ParentEntity.class, p1.getId()); - p2 = em.find(ParentEntity.class, p2.getId()); - c1_2 = em.find(Child1Entity.class, c1_2.getId()); - c2_2 = em.find(Child2Entity.class, c2_2.getId()); + p1 = em.find( ParentEntity.class, p1.getId() ); + p2 = em.find( ParentEntity.class, p2.getId() ); + c1_2 = em.find( Child1Entity.class, c1_2.getId() ); + c2_2 = em.find( Child2Entity.class, c2_2.getId() ); - c2_2.getParents().remove(p2); - c1_2.getParents().remove(p1); + c2_2.getParents().remove( p2 ); + c1_2.getParents().remove( p1 ); em.getTransaction().commit(); em.clear(); @@ -202,53 +204,72 @@ public class ValidityAuditStrategyRevEndTsTest extends BaseEnversJPAFunctionalTe c2_2_id = c2_2.getId(); Set revisionNumbers = new HashSet(); - revisionNumbers.addAll(Arrays.asList(1, 2, 3, 4, 5)); + revisionNumbers.addAll( Arrays.asList( 1, 2, 3, 4, 5 ) ); revisions = getAuditReader().findRevisions( SequenceIdRevisionEntity.class, - revisionNumbers); + revisionNumbers + ); assert revisions.size() == 5; } @Test public void testRevisionsCounts() { - assert Arrays.asList(1, 2, 3, 4).equals( - getAuditReader().getRevisions(ParentEntity.class, p1_id)); - assert Arrays.asList(1, 2, 3, 4).equals( - getAuditReader().getRevisions(ParentEntity.class, p2_id)); + assert Arrays.asList( 1, 2, 3, 4 ).equals( + getAuditReader().getRevisions( ParentEntity.class, p1_id ) + ); + assert Arrays.asList( 1, 2, 3, 4 ).equals( + getAuditReader().getRevisions( ParentEntity.class, p2_id ) + ); - assert Arrays.asList(1).equals( - getAuditReader().getRevisions(Child1Entity.class, c1_1_id)); - assert Arrays.asList(1, 5).equals( - getAuditReader().getRevisions(Child1Entity.class, c1_2_id)); + assert Arrays.asList( 1 ).equals( + getAuditReader().getRevisions( Child1Entity.class, c1_1_id ) + ); + assert Arrays.asList( 1, 5 ).equals( + getAuditReader().getRevisions( Child1Entity.class, c1_2_id ) + ); - assert Arrays.asList(1).equals( - getAuditReader().getRevisions(Child2Entity.class, c2_1_id)); - assert Arrays.asList(1, 5).equals( - getAuditReader().getRevisions(Child2Entity.class, c2_2_id)); + assert Arrays.asList( 1 ).equals( + getAuditReader().getRevisions( Child2Entity.class, c2_1_id ) + ); + assert Arrays.asList( 1, 5 ).equals( + getAuditReader().getRevisions( Child2Entity.class, c2_2_id ) + ); } @Test public void testAllRevEndTimeStamps() { - List> p1RevList = getRevisions(ParentEntity.class, - p1_id); - List> p2RevList = getRevisions(ParentEntity.class, - p2_id); - List> c1_1_List = getRevisions(Child1Entity.class, - c1_1_id); - List> c1_2_List = getRevisions(Child1Entity.class, - c1_2_id); - List> c2_1_List = getRevisions(Child2Entity.class, - c2_1_id); - List> c2_2_List = getRevisions(Child2Entity.class, - c2_2_id); + List> p1RevList = getRevisions( + ParentEntity.class, + p1_id + ); + List> p2RevList = getRevisions( + ParentEntity.class, + p2_id + ); + List> c1_1_List = getRevisions( + Child1Entity.class, + c1_1_id + ); + List> c1_2_List = getRevisions( + Child1Entity.class, + c1_2_id + ); + List> c2_1_List = getRevisions( + Child2Entity.class, + c2_1_id + ); + List> c2_2_List = getRevisions( + Child2Entity.class, + c2_2_id + ); - verifyRevEndTimeStamps("ParentEntity: " + p1_id, p1RevList); - verifyRevEndTimeStamps("ParentEntity: " + p2_id, p2RevList); - verifyRevEndTimeStamps("Child1Entity: " + c1_1_id, c1_1_List); - verifyRevEndTimeStamps("Child1Entity: " + c1_2_id, c1_2_List); - verifyRevEndTimeStamps("Child2Entity: " + c2_1_id, c2_1_List); - verifyRevEndTimeStamps("Child2Entity: " + c2_2_id, c2_2_List); + verifyRevEndTimeStamps( "ParentEntity: " + p1_id, p1RevList ); + verifyRevEndTimeStamps( "ParentEntity: " + p2_id, p2RevList ); + verifyRevEndTimeStamps( "Child1Entity: " + c1_1_id, c1_1_List ); + verifyRevEndTimeStamps( "Child1Entity: " + c1_2_id, c1_2_List ); + verifyRevEndTimeStamps( "Child2Entity: " + c2_1_id, c2_1_List ); + verifyRevEndTimeStamps( "Child2Entity: " + c2_2_id, c2_2_List ); } @@ -256,148 +277,188 @@ public class ValidityAuditStrategyRevEndTsTest extends BaseEnversJPAFunctionalTe public void testHistoryOfParent1() { Child1Entity c1_1 = getEntityManager() - .find(Child1Entity.class, c1_1_id); + .find( Child1Entity.class, c1_1_id ); Child1Entity c1_2 = getEntityManager() - .find(Child1Entity.class, c1_2_id); + .find( Child1Entity.class, c1_2_id ); Child2Entity c2_2 = getEntityManager() - .find(Child2Entity.class, c2_2_id); + .find( Child2Entity.class, c2_2_id ); - ParentEntity rev1 = getAuditReader().find(ParentEntity.class, p1_id, 1); - ParentEntity rev2 = getAuditReader().find(ParentEntity.class, p1_id, 2); - ParentEntity rev3 = getAuditReader().find(ParentEntity.class, p1_id, 3); - ParentEntity rev4 = getAuditReader().find(ParentEntity.class, p1_id, 4); - ParentEntity rev5 = getAuditReader().find(ParentEntity.class, p1_id, 5); + ParentEntity rev1 = getAuditReader().find( ParentEntity.class, p1_id, 1 ); + ParentEntity rev2 = getAuditReader().find( ParentEntity.class, p1_id, 2 ); + ParentEntity rev3 = getAuditReader().find( ParentEntity.class, p1_id, 3 ); + ParentEntity rev4 = getAuditReader().find( ParentEntity.class, p1_id, 4 ); + ParentEntity rev5 = getAuditReader().find( ParentEntity.class, p1_id, 5 ); - assert TestTools.checkList(rev1.getChildren1()); - assert TestTools.checkList(rev2.getChildren1(), c1_1); - assert TestTools.checkList(rev3.getChildren1(), c1_1, c1_2); - assert TestTools.checkList(rev4.getChildren1(), c1_2); - assert TestTools.checkList(rev5.getChildren1()); + assert TestTools.checkList( rev1.getChildren1() ); + assert TestTools.checkList( rev2.getChildren1(), c1_1 ); + assert TestTools.checkList( rev3.getChildren1(), c1_1, c1_2 ); + assert TestTools.checkList( rev4.getChildren1(), c1_2 ); + assert TestTools.checkList( rev5.getChildren1() ); - assert TestTools.checkList(rev1.getChildren2()); - assert TestTools.checkList(rev2.getChildren2()); - assert TestTools.checkList(rev3.getChildren2(), c2_2); - assert TestTools.checkList(rev4.getChildren2(), c2_2); - assert TestTools.checkList(rev5.getChildren2(), c2_2); + assert TestTools.checkList( rev1.getChildren2() ); + assert TestTools.checkList( rev2.getChildren2() ); + assert TestTools.checkList( rev3.getChildren2(), c2_2 ); + assert TestTools.checkList( rev4.getChildren2(), c2_2 ); + assert TestTools.checkList( rev5.getChildren2(), c2_2 ); } @Test public void testHistoryOfParent2() { Child1Entity c1_1 = getEntityManager() - .find(Child1Entity.class, c1_1_id); + .find( Child1Entity.class, c1_1_id ); Child2Entity c2_1 = getEntityManager() - .find(Child2Entity.class, c2_1_id); + .find( Child2Entity.class, c2_1_id ); Child2Entity c2_2 = getEntityManager() - .find(Child2Entity.class, c2_2_id); + .find( Child2Entity.class, c2_2_id ); - ParentEntity rev1 = getAuditReader().find(ParentEntity.class, p2_id, 1); - ParentEntity rev2 = getAuditReader().find(ParentEntity.class, p2_id, 2); - ParentEntity rev3 = getAuditReader().find(ParentEntity.class, p2_id, 3); - ParentEntity rev4 = getAuditReader().find(ParentEntity.class, p2_id, 4); - ParentEntity rev5 = getAuditReader().find(ParentEntity.class, p2_id, 5); + ParentEntity rev1 = getAuditReader().find( ParentEntity.class, p2_id, 1 ); + ParentEntity rev2 = getAuditReader().find( ParentEntity.class, p2_id, 2 ); + ParentEntity rev3 = getAuditReader().find( ParentEntity.class, p2_id, 3 ); + ParentEntity rev4 = getAuditReader().find( ParentEntity.class, p2_id, 4 ); + ParentEntity rev5 = getAuditReader().find( ParentEntity.class, p2_id, 5 ); - assert TestTools.checkList(rev1.getChildren1()); - assert TestTools.checkList(rev2.getChildren1()); - assert TestTools.checkList(rev3.getChildren1(), c1_1); - assert TestTools.checkList(rev4.getChildren1(), c1_1); - assert TestTools.checkList(rev5.getChildren1(), c1_1); + assert TestTools.checkList( rev1.getChildren1() ); + assert TestTools.checkList( rev2.getChildren1() ); + assert TestTools.checkList( rev3.getChildren1(), c1_1 ); + assert TestTools.checkList( rev4.getChildren1(), c1_1 ); + assert TestTools.checkList( rev5.getChildren1(), c1_1 ); - assert TestTools.checkList(rev1.getChildren2()); - assert TestTools.checkList(rev2.getChildren2(), c2_1); - assert TestTools.checkList(rev3.getChildren2(), c2_1); - assert TestTools.checkList(rev4.getChildren2(), c2_1, c2_2); - assert TestTools.checkList(rev5.getChildren2(), c2_1); + assert TestTools.checkList( rev1.getChildren2() ); + assert TestTools.checkList( rev2.getChildren2(), c2_1 ); + assert TestTools.checkList( rev3.getChildren2(), c2_1 ); + assert TestTools.checkList( rev4.getChildren2(), c2_1, c2_2 ); + assert TestTools.checkList( rev5.getChildren2(), c2_1 ); } @Test public void testHistoryOfChild1_1() { - ParentEntity p1 = getEntityManager().find(ParentEntity.class, p1_id); - ParentEntity p2 = getEntityManager().find(ParentEntity.class, p2_id); + ParentEntity p1 = getEntityManager().find( ParentEntity.class, p1_id ); + ParentEntity p2 = getEntityManager().find( ParentEntity.class, p2_id ); - Child1Entity rev1 = getAuditReader().find(Child1Entity.class, c1_1_id, - 1); - Child1Entity rev2 = getAuditReader().find(Child1Entity.class, c1_1_id, - 2); - Child1Entity rev3 = getAuditReader().find(Child1Entity.class, c1_1_id, - 3); - Child1Entity rev4 = getAuditReader().find(Child1Entity.class, c1_1_id, - 4); - Child1Entity rev5 = getAuditReader().find(Child1Entity.class, c1_1_id, - 5); + Child1Entity rev1 = getAuditReader().find( + Child1Entity.class, c1_1_id, + 1 + ); + Child1Entity rev2 = getAuditReader().find( + Child1Entity.class, c1_1_id, + 2 + ); + Child1Entity rev3 = getAuditReader().find( + Child1Entity.class, c1_1_id, + 3 + ); + Child1Entity rev4 = getAuditReader().find( + Child1Entity.class, c1_1_id, + 4 + ); + Child1Entity rev5 = getAuditReader().find( + Child1Entity.class, c1_1_id, + 5 + ); - assert TestTools.checkList(rev1.getParents()); - assert TestTools.checkList(rev2.getParents(), p1); - assert TestTools.checkList(rev3.getParents(), p1, p2); - assert TestTools.checkList(rev4.getParents(), p2); - assert TestTools.checkList(rev5.getParents(), p2); + assert TestTools.checkList( rev1.getParents() ); + assert TestTools.checkList( rev2.getParents(), p1 ); + assert TestTools.checkList( rev3.getParents(), p1, p2 ); + assert TestTools.checkList( rev4.getParents(), p2 ); + assert TestTools.checkList( rev5.getParents(), p2 ); } - // TODO: this was disabled? + // TODO: this was disabled? @Test public void testHistoryOfChild1_2() { - ParentEntity p1 = getEntityManager().find(ParentEntity.class, p1_id); + ParentEntity p1 = getEntityManager().find( ParentEntity.class, p1_id ); - Child1Entity rev1 = getAuditReader().find(Child1Entity.class, c1_2_id, - 1); - Child1Entity rev2 = getAuditReader().find(Child1Entity.class, c1_2_id, - 2); - Child1Entity rev3 = getAuditReader().find(Child1Entity.class, c1_2_id, - 3); - Child1Entity rev4 = getAuditReader().find(Child1Entity.class, c1_2_id, - 4); - Child1Entity rev5 = getAuditReader().find(Child1Entity.class, c1_2_id, - 5); + Child1Entity rev1 = getAuditReader().find( + Child1Entity.class, c1_2_id, + 1 + ); + Child1Entity rev2 = getAuditReader().find( + Child1Entity.class, c1_2_id, + 2 + ); + Child1Entity rev3 = getAuditReader().find( + Child1Entity.class, c1_2_id, + 3 + ); + Child1Entity rev4 = getAuditReader().find( + Child1Entity.class, c1_2_id, + 4 + ); + Child1Entity rev5 = getAuditReader().find( + Child1Entity.class, c1_2_id, + 5 + ); - assert TestTools.checkList(rev1.getParents()); - assert TestTools.checkList(rev2.getParents()); - assert TestTools.checkList(rev3.getParents(), p1); - assert TestTools.checkList(rev4.getParents(), p1); - assert TestTools.checkList(rev5.getParents()); + assert TestTools.checkList( rev1.getParents() ); + assert TestTools.checkList( rev2.getParents() ); + assert TestTools.checkList( rev3.getParents(), p1 ); + assert TestTools.checkList( rev4.getParents(), p1 ); + assert TestTools.checkList( rev5.getParents() ); } @Test public void testHistoryOfChild2_1() { - ParentEntity p2 = getEntityManager().find(ParentEntity.class, p2_id); + ParentEntity p2 = getEntityManager().find( ParentEntity.class, p2_id ); - Child2Entity rev1 = getAuditReader().find(Child2Entity.class, c2_1_id, - 1); - Child2Entity rev2 = getAuditReader().find(Child2Entity.class, c2_1_id, - 2); - Child2Entity rev3 = getAuditReader().find(Child2Entity.class, c2_1_id, - 3); - Child2Entity rev4 = getAuditReader().find(Child2Entity.class, c2_1_id, - 4); - Child2Entity rev5 = getAuditReader().find(Child2Entity.class, c2_1_id, - 5); + Child2Entity rev1 = getAuditReader().find( + Child2Entity.class, c2_1_id, + 1 + ); + Child2Entity rev2 = getAuditReader().find( + Child2Entity.class, c2_1_id, + 2 + ); + Child2Entity rev3 = getAuditReader().find( + Child2Entity.class, c2_1_id, + 3 + ); + Child2Entity rev4 = getAuditReader().find( + Child2Entity.class, c2_1_id, + 4 + ); + Child2Entity rev5 = getAuditReader().find( + Child2Entity.class, c2_1_id, + 5 + ); - assert TestTools.checkList(rev1.getParents()); - assert TestTools.checkList(rev2.getParents(), p2); - assert TestTools.checkList(rev3.getParents(), p2); - assert TestTools.checkList(rev4.getParents(), p2); - assert TestTools.checkList(rev5.getParents(), p2); + assert TestTools.checkList( rev1.getParents() ); + assert TestTools.checkList( rev2.getParents(), p2 ); + assert TestTools.checkList( rev3.getParents(), p2 ); + assert TestTools.checkList( rev4.getParents(), p2 ); + assert TestTools.checkList( rev5.getParents(), p2 ); } @Test public void testHistoryOfChild2_2() { - ParentEntity p1 = getEntityManager().find(ParentEntity.class, p1_id); - ParentEntity p2 = getEntityManager().find(ParentEntity.class, p2_id); + ParentEntity p1 = getEntityManager().find( ParentEntity.class, p1_id ); + ParentEntity p2 = getEntityManager().find( ParentEntity.class, p2_id ); - Child2Entity rev1 = getAuditReader().find(Child2Entity.class, c2_2_id, - 1); - Child2Entity rev2 = getAuditReader().find(Child2Entity.class, c2_2_id, - 2); - Child2Entity rev3 = getAuditReader().find(Child2Entity.class, c2_2_id, - 3); - Child2Entity rev4 = getAuditReader().find(Child2Entity.class, c2_2_id, - 4); - Child2Entity rev5 = getAuditReader().find(Child2Entity.class, c2_2_id, - 5); + Child2Entity rev1 = getAuditReader().find( + Child2Entity.class, c2_2_id, + 1 + ); + Child2Entity rev2 = getAuditReader().find( + Child2Entity.class, c2_2_id, + 2 + ); + Child2Entity rev3 = getAuditReader().find( + Child2Entity.class, c2_2_id, + 3 + ); + Child2Entity rev4 = getAuditReader().find( + Child2Entity.class, c2_2_id, + 4 + ); + Child2Entity rev5 = getAuditReader().find( + Child2Entity.class, c2_2_id, + 5 + ); - assert TestTools.checkList(rev1.getParents()); - assert TestTools.checkList(rev2.getParents()); - assert TestTools.checkList(rev3.getParents(), p1); - assert TestTools.checkList(rev4.getParents(), p1, p2); - assert TestTools.checkList(rev5.getParents(), p1); + assert TestTools.checkList( rev1.getParents() ); + assert TestTools.checkList( rev2.getParents() ); + assert TestTools.checkList( rev3.getParents(), p1 ); + assert TestTools.checkList( rev4.getParents(), p1, p2 ); + assert TestTools.checkList( rev5.getParents(), p1 ); } private List> getRevisions( @@ -407,13 +468,13 @@ public class ValidityAuditStrategyRevEndTsTest extends BaseEnversJPAFunctionalTe // org.hibernate.envers.test.entities.manytomany.sametable.ParentEntity_AUD // auditEntity where auditEntity.originalId.id = :originalEntityId - StringBuilder builder = new StringBuilder("select auditEntity from "); - builder.append(originalEntityClazz.getName()) - .append("_AUD auditEntity"); - builder.append(" where auditEntity.originalId.id = :originalEntityId"); + StringBuilder builder = new StringBuilder( "select auditEntity from " ); + builder.append( originalEntityClazz.getName() ) + .append( "_AUD auditEntity" ); + builder.append( " where auditEntity.originalId.id = :originalEntityId" ); - Query qry = getEntityManager().createQuery(builder.toString()); - qry.setParameter("originalEntityId", originalEntityId); + Query qry = getEntityManager().createQuery( builder.toString() ); + qry.setParameter( "originalEntityId", originalEntityId ); @SuppressWarnings("unchecked") List> resultList = qry.getResultList(); @@ -421,23 +482,29 @@ public class ValidityAuditStrategyRevEndTsTest extends BaseEnversJPAFunctionalTe } private void verifyRevEndTimeStamps(String debugInfo, List> revisionEntities) { - for (Map revisionEntity : revisionEntities) { - Date revendTimestamp = (Date) revisionEntity.get(revendTimestampColumName); - SequenceIdRevisionEntity revEnd = (SequenceIdRevisionEntity) revisionEntity.get("REVEND"); + for ( Map revisionEntity : revisionEntities ) { + Date revendTimestamp = (Date) revisionEntity.get( revendTimestampColumName ); + SequenceIdRevisionEntity revEnd = (SequenceIdRevisionEntity) revisionEntity.get( "REVEND" ); - if (revendTimestamp == null) { - Assert.assertNull(revEnd); - } else { - if (getDialect() instanceof MySQL5Dialect) { + if ( revendTimestamp == null ) { + Assert.assertNull( revEnd ); + } + else { + if ( getDialect() instanceof MySQL5Dialect ) { // MySQL5 DATETIME column type does not contain milliseconds. - Assert.assertEquals(revendTimestamp.getTime(), (revEnd.getTimestamp() - (revEnd.getTimestamp() % 1000))); - } else if (getDialect() instanceof SybaseASE15Dialect) { + Assert.assertEquals( + revendTimestamp.getTime(), + (revEnd.getTimestamp() - (revEnd.getTimestamp() % 1000)) + ); + } + else if ( getDialect() instanceof SybaseASE15Dialect ) { // Sybase "DATETIME values are accurate to 1/300 second on platforms that support this level of granularity". Assert.assertEquals( revendTimestamp.getTime() / 1000.0, revEnd.getTimestamp() / 1000.0, 1.0 / 300.0 ); - } else { - Assert.assertEquals(revendTimestamp.getTime(), revEnd.getTimestamp()); + } + else { + Assert.assertEquals( revendTimestamp.getTime(), revEnd.getTimestamp() ); } } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditAtMethodSuperclassLevel/AuditedMethodMappedSuperclass.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditAtMethodSuperclassLevel/AuditedMethodMappedSuperclass.java index 4612664885..0b2f6b7cc7 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditAtMethodSuperclassLevel/AuditedMethodMappedSuperclass.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditAtMethodSuperclassLevel/AuditedMethodMappedSuperclass.java @@ -22,13 +22,13 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.superclass.auditAtMethodSuperclassLevel; + import javax.persistence.MappedSuperclass; import org.hibernate.envers.Audited; /** * @author Adam Warski (adam at warski dot org) - * * @author Hern&aacut;n Chanfreau */ @MappedSuperclass @@ -36,7 +36,7 @@ public class AuditedMethodMappedSuperclass { @Audited private String str; - + private String otherStr; public AuditedMethodMappedSuperclass() { @@ -64,15 +64,18 @@ public class AuditedMethodMappedSuperclass { } public boolean equals(Object o) { - if (this == o) + if ( this == o ) { return true; - if (!(o instanceof AuditedMethodMappedSuperclass)) + } + if ( !(o instanceof AuditedMethodMappedSuperclass) ) { return false; + } AuditedMethodMappedSuperclass that = (AuditedMethodMappedSuperclass) o; - if (str != null ? !str.equals(that.str) : that.str != null) + if ( str != null ? !str.equals( that.str ) : that.str != null ) { return false; + } return true; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditAtMethodSuperclassLevel/NotAuditedSubclassEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditAtMethodSuperclassLevel/NotAuditedSubclassEntity.java index d44bda246c..a1a277150e 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditAtMethodSuperclassLevel/NotAuditedSubclassEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditAtMethodSuperclassLevel/NotAuditedSubclassEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.superclass.auditAtMethodSuperclassLevel; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; @@ -30,9 +31,7 @@ import javax.persistence.Table; /** * @author Adam Warski (adam at warski dot org) - * * @author Hernán Chanfreau - * */ @Entity @Table(name = "NotAuditedSubclass") @@ -40,20 +39,20 @@ public class NotAuditedSubclassEntity extends AuditedMethodMappedSuperclass { @Id @GeneratedValue private Integer id; - + private String notAuditedStr; public NotAuditedSubclassEntity() { } public NotAuditedSubclassEntity(Integer id, String str, String otherStr, String notAuditedStr) { - super(str, otherStr); + super( str, otherStr ); this.notAuditedStr = notAuditedStr; this.id = id; } public NotAuditedSubclassEntity(String str, String otherStr, String notAuditedStr) { - super(str, otherStr); + super( str, otherStr ); this.notAuditedStr = notAuditedStr; } @@ -74,17 +73,21 @@ public class NotAuditedSubclassEntity extends AuditedMethodMappedSuperclass { } public boolean equals(Object o) { - if (this == o) + if ( this == o ) { return true; - if (!(o instanceof NotAuditedSubclassEntity)) + } + if ( !(o instanceof NotAuditedSubclassEntity) ) { return false; - if (!super.equals(o)) + } + if ( !super.equals( o ) ) { return false; + } NotAuditedSubclassEntity that = (NotAuditedSubclassEntity) o; - if (id != null ? !id.equals(that.id) : that.id != null) + if ( id != null ? !id.equals( that.id ) : that.id != null ) { return false; + } return true; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditAtMethodSuperclassLevel/auditAllSubclass/AuditedAllSubclassEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditAtMethodSuperclassLevel/auditAllSubclass/AuditedAllSubclassEntity.java index 37823e9cf8..af3aecdcc8 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditAtMethodSuperclassLevel/auditAllSubclass/AuditedAllSubclassEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditAtMethodSuperclassLevel/auditAllSubclass/AuditedAllSubclassEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.superclass.auditAtMethodSuperclassLevel.auditAllSubclass; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; @@ -36,58 +37,66 @@ import org.hibernate.envers.test.integration.superclass.auditAtMethodSuperclassL @Entity @Audited public class AuditedAllSubclassEntity extends AuditedMethodMappedSuperclass { - @Id - @GeneratedValue - private Integer id; - - private String subAuditedStr; + @Id + @GeneratedValue + private Integer id; + + private String subAuditedStr; public AuditedAllSubclassEntity() { - } + } - public AuditedAllSubclassEntity(Integer id, String str, String otherString, String subAuditedStr) { - super(str, otherString); - this.subAuditedStr = subAuditedStr; - this.id = id; - } + public AuditedAllSubclassEntity(Integer id, String str, String otherString, String subAuditedStr) { + super( str, otherString ); + this.subAuditedStr = subAuditedStr; + this.id = id; + } - public AuditedAllSubclassEntity(String str, String otherString, String subAuditedStr ) { - super(str, otherString); - this.subAuditedStr = subAuditedStr; - } + public AuditedAllSubclassEntity(String str, String otherString, String subAuditedStr) { + super( str, otherString ); + this.subAuditedStr = subAuditedStr; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getSubAuditedStr() { + public String getSubAuditedStr() { return subAuditedStr; } public void setSubAuditedStr(String subAuditedStr) { this.subAuditedStr = subAuditedStr; } - - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof AuditedAllSubclassEntity)) return false; - if (!super.equals(o)) return false; - AuditedAllSubclassEntity that = (AuditedAllSubclassEntity) o; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof AuditedAllSubclassEntity) ) { + return false; + } + if ( !super.equals( o ) ) { + return false; + } - if (id != null ? !id.equals(that.id) : that.id != null) return false; + AuditedAllSubclassEntity that = (AuditedAllSubclassEntity) o; - return true; - } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - public int hashCode() { - int result = super.hashCode(); - result = 31 * result + (id != null ? id.hashCode() : 0); - return result; - } + return true; + } + + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (id != null ? id.hashCode() : 0); + return result; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditAtMethodSuperclassLevel/auditAllSubclass/MappedSubclassingAllAuditedTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditAtMethodSuperclassLevel/auditAllSubclass/MappedSubclassingAllAuditedTest.java index 6fe565e61b..eb8f62e86f 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditAtMethodSuperclassLevel/auditAllSubclass/MappedSubclassingAllAuditedTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditAtMethodSuperclassLevel/auditAllSubclass/MappedSubclassingAllAuditedTest.java @@ -23,10 +23,8 @@ */ package org.hibernate.envers.test.integration.superclass.auditAtMethodSuperclassLevel.auditAllSubclass; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.exception.NotAuditedException; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; @@ -34,11 +32,11 @@ import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.integration.superclass.auditAtMethodSuperclassLevel.AuditedMethodMappedSuperclass; import org.hibernate.envers.test.integration.superclass.auditAtMethodSuperclassLevel.NotAuditedSubclassEntity; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) - * * @author Hern&aacut;n Chanfreau - * */ public class MappedSubclassingAllAuditedTest extends BaseEnversJPAFunctionalTestCase { private Integer id2_1; @@ -46,75 +44,82 @@ public class MappedSubclassingAllAuditedTest extends BaseEnversJPAFunctionalTest @Override protected Class[] getAnnotatedClasses() { - return new Class[] { AuditedMethodMappedSuperclass.class, AuditedAllSubclassEntity.class, NotAuditedSubclassEntity.class }; + return new Class[] { + AuditedMethodMappedSuperclass.class, + AuditedAllSubclassEntity.class, + NotAuditedSubclassEntity.class + }; } @Test - @Priority(10) + @Priority(10) public void initData() { // Revision 1 EntityManager em = getEntityManager(); em.getTransaction().begin(); - NotAuditedSubclassEntity nas = new NotAuditedSubclassEntity("nae","super str","not audited str"); - em.persist(nas); - AuditedAllSubclassEntity ae = new AuditedAllSubclassEntity("ae", "super str", "audited str"); - em.persist(ae); + NotAuditedSubclassEntity nas = new NotAuditedSubclassEntity( "nae", "super str", "not audited str" ); + em.persist( nas ); + AuditedAllSubclassEntity ae = new AuditedAllSubclassEntity( "ae", "super str", "audited str" ); + em.persist( ae ); id1_1 = ae.getId(); id2_1 = nas.getId(); em.getTransaction().commit(); // Revision 2 em.getTransaction().begin(); - ae = em.find(AuditedAllSubclassEntity.class, id1_1); - ae.setStr("ae new"); - ae.setSubAuditedStr("audited str new"); - nas = em.find(NotAuditedSubclassEntity.class, id2_1); - nas.setStr("nae new"); - nas.setNotAuditedStr("not aud str new"); + ae = em.find( AuditedAllSubclassEntity.class, id1_1 ); + ae.setStr( "ae new" ); + ae.setSubAuditedStr( "audited str new" ); + nas = em.find( NotAuditedSubclassEntity.class, id2_1 ); + nas.setStr( "nae new" ); + nas.setNotAuditedStr( "not aud str new" ); em.getTransaction().commit(); } @Test public void testRevisionsCountsForAudited() { - assert Arrays.asList(1, 2).equals( - getAuditReader().getRevisions(AuditedAllSubclassEntity.class, id1_1)); + assert Arrays.asList( 1, 2 ).equals( + getAuditReader().getRevisions( AuditedAllSubclassEntity.class, id1_1 ) + ); } - - @Test(expected= NotAuditedException.class ) + + @Test(expected = NotAuditedException.class) public void testRevisionsCountsForNotAudited() { try { - getAuditReader().getRevisions(NotAuditedSubclassEntity.class, id2_1); - assert(false); - } catch (NotAuditedException nae) { + getAuditReader().getRevisions( NotAuditedSubclassEntity.class, id2_1 ); + assert (false); + } + catch (NotAuditedException nae) { throw nae; } } - + @Test public void testHistoryOfAudited() { - AuditedAllSubclassEntity ver1 = new AuditedAllSubclassEntity(id1_1, "ae", "super str", "audited str"); - AuditedAllSubclassEntity ver2 = new AuditedAllSubclassEntity(id1_1, "ae new", "super str", "audited str new"); - - AuditedAllSubclassEntity rev1 = getAuditReader().find(AuditedAllSubclassEntity.class, id1_1, 1); - AuditedAllSubclassEntity rev2 = getAuditReader().find(AuditedAllSubclassEntity.class, id1_1, 2); - + AuditedAllSubclassEntity ver1 = new AuditedAllSubclassEntity( id1_1, "ae", "super str", "audited str" ); + AuditedAllSubclassEntity ver2 = new AuditedAllSubclassEntity( id1_1, "ae new", "super str", "audited str new" ); + + AuditedAllSubclassEntity rev1 = getAuditReader().find( AuditedAllSubclassEntity.class, id1_1, 1 ); + AuditedAllSubclassEntity rev2 = getAuditReader().find( AuditedAllSubclassEntity.class, id1_1, 2 ); + //this property is not audited on superclass - assert(rev1.getOtherStr() == null); - assert(rev2.getOtherStr() == null); - - assert rev1.equals(ver1); - assert rev2.equals(ver2); + assert (rev1.getOtherStr() == null); + assert (rev2.getOtherStr() == null); + + assert rev1.equals( ver1 ); + assert rev2.equals( ver2 ); } - - @Test(expected=NotAuditedException.class) + + @Test(expected = NotAuditedException.class) public void testHistoryOfNotAudited() { try { - getAuditReader().find(NotAuditedSubclassEntity.class, id2_1, 1); - assert(false); - } catch (NotAuditedException nae) { + getAuditReader().find( NotAuditedSubclassEntity.class, id2_1, 1 ); + assert (false); + } + catch (NotAuditedException nae) { throw nae; } } - + } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditAtMethodSuperclassLevel/auditMethodSubclass/AuditedMethodSubclassEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditAtMethodSuperclassLevel/auditMethodSubclass/AuditedMethodSubclassEntity.java index 7750f124e0..d0650d795e 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditAtMethodSuperclassLevel/auditMethodSubclass/AuditedMethodSubclassEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditAtMethodSuperclassLevel/auditMethodSubclass/AuditedMethodSubclassEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.superclass.auditAtMethodSuperclassLevel.auditMethodSubclass; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; @@ -37,59 +38,67 @@ import org.hibernate.envers.test.integration.superclass.auditAtMethodSuperclassL @Entity @Table(name = "AuditedMethodSubclass") public class AuditedMethodSubclassEntity extends AuditedMethodMappedSuperclass { - @Id - @GeneratedValue - private Integer id; - - @Audited - private String subAuditedStr; + @Id + @GeneratedValue + private Integer id; + + @Audited + private String subAuditedStr; public AuditedMethodSubclassEntity() { - } + } - public AuditedMethodSubclassEntity(Integer id, String str, String otherString, String subAuditedStr) { - super(str, otherString); - this.subAuditedStr = subAuditedStr; - this.id = id; - } + public AuditedMethodSubclassEntity(Integer id, String str, String otherString, String subAuditedStr) { + super( str, otherString ); + this.subAuditedStr = subAuditedStr; + this.id = id; + } - public AuditedMethodSubclassEntity(String str, String otherString, String subAuditedStr ) { - super(str, otherString); - this.subAuditedStr = subAuditedStr; - } + public AuditedMethodSubclassEntity(String str, String otherString, String subAuditedStr) { + super( str, otherString ); + this.subAuditedStr = subAuditedStr; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getSubAuditedStr() { + public String getSubAuditedStr() { return subAuditedStr; } public void setSubAuditedStr(String subAuditedStr) { this.subAuditedStr = subAuditedStr; } - - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof AuditedMethodSubclassEntity)) return false; - if (!super.equals(o)) return false; - AuditedMethodSubclassEntity that = (AuditedMethodSubclassEntity) o; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof AuditedMethodSubclassEntity) ) { + return false; + } + if ( !super.equals( o ) ) { + return false; + } - if (id != null ? !id.equals(that.id) : that.id != null) return false; + AuditedMethodSubclassEntity that = (AuditedMethodSubclassEntity) o; - return true; - } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - public int hashCode() { - int result = super.hashCode(); - result = 31 * result + (id != null ? id.hashCode() : 0); - return result; - } + return true; + } + + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (id != null ? id.hashCode() : 0); + return result; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditAtMethodSuperclassLevel/auditMethodSubclass/MappedSubclassingMethodAuditedTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditAtMethodSuperclassLevel/auditMethodSubclass/MappedSubclassingMethodAuditedTest.java index 22175c351b..788c385ea0 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditAtMethodSuperclassLevel/auditMethodSubclass/MappedSubclassingMethodAuditedTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditAtMethodSuperclassLevel/auditMethodSubclass/MappedSubclassingMethodAuditedTest.java @@ -23,10 +23,8 @@ */ package org.hibernate.envers.test.integration.superclass.auditAtMethodSuperclassLevel.auditMethodSubclass; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.exception.NotAuditedException; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; @@ -34,11 +32,11 @@ import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.integration.superclass.auditAtMethodSuperclassLevel.AuditedMethodMappedSuperclass; import org.hibernate.envers.test.integration.superclass.auditAtMethodSuperclassLevel.NotAuditedSubclassEntity; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) - * * @author Hern&aacut;n Chanfreau - * */ public class MappedSubclassingMethodAuditedTest extends BaseEnversJPAFunctionalTestCase { private Integer id2_1; @@ -54,71 +52,79 @@ public class MappedSubclassingMethodAuditedTest extends BaseEnversJPAFunctionalT } @Test - @Priority(10) + @Priority(10) public void initData() { // Revision 1 EntityManager em = getEntityManager(); em.getTransaction().begin(); - NotAuditedSubclassEntity nas = new NotAuditedSubclassEntity("nae","super str","not audited str"); - em.persist(nas); - AuditedMethodSubclassEntity ae = new AuditedMethodSubclassEntity("ae", "super str", "audited str"); - em.persist(ae); + NotAuditedSubclassEntity nas = new NotAuditedSubclassEntity( "nae", "super str", "not audited str" ); + em.persist( nas ); + AuditedMethodSubclassEntity ae = new AuditedMethodSubclassEntity( "ae", "super str", "audited str" ); + em.persist( ae ); id1_1 = ae.getId(); id2_1 = nas.getId(); em.getTransaction().commit(); // Revision 2 em.getTransaction().begin(); - ae = em.find(AuditedMethodSubclassEntity.class, id1_1); - ae.setStr("ae new"); - ae.setSubAuditedStr("audited str new"); - nas = em.find(NotAuditedSubclassEntity.class, id2_1); - nas.setStr("nae new"); - nas.setNotAuditedStr("not aud str new"); + ae = em.find( AuditedMethodSubclassEntity.class, id1_1 ); + ae.setStr( "ae new" ); + ae.setSubAuditedStr( "audited str new" ); + nas = em.find( NotAuditedSubclassEntity.class, id2_1 ); + nas.setStr( "nae new" ); + nas.setNotAuditedStr( "not aud str new" ); em.getTransaction().commit(); } @Test public void testRevisionsCountsForAudited() { - assert Arrays.asList(1, 2).equals( - getAuditReader().getRevisions(AuditedMethodSubclassEntity.class, id1_1)); + assert Arrays.asList( 1, 2 ).equals( + getAuditReader().getRevisions( AuditedMethodSubclassEntity.class, id1_1 ) + ); } - - @Test(expected= NotAuditedException.class ) + + @Test(expected = NotAuditedException.class) public void testRevisionsCountsForNotAudited() { try { - getAuditReader().getRevisions(NotAuditedSubclassEntity.class, id2_1); - assert(false); - } catch (NotAuditedException nae) { + getAuditReader().getRevisions( NotAuditedSubclassEntity.class, id2_1 ); + assert (false); + } + catch (NotAuditedException nae) { throw nae; } } - + @Test public void testHistoryOfAudited() { - AuditedMethodSubclassEntity ver1 = new AuditedMethodSubclassEntity(id1_1, "ae", "super str", "audited str"); - AuditedMethodSubclassEntity ver2 = new AuditedMethodSubclassEntity(id1_1, "ae new", "super str", "audited str new"); - - AuditedMethodSubclassEntity rev1 = getAuditReader().find(AuditedMethodSubclassEntity.class, id1_1, 1); - AuditedMethodSubclassEntity rev2 = getAuditReader().find(AuditedMethodSubclassEntity.class, id1_1, 2); - + AuditedMethodSubclassEntity ver1 = new AuditedMethodSubclassEntity( id1_1, "ae", "super str", "audited str" ); + AuditedMethodSubclassEntity ver2 = new AuditedMethodSubclassEntity( + id1_1, + "ae new", + "super str", + "audited str new" + ); + + AuditedMethodSubclassEntity rev1 = getAuditReader().find( AuditedMethodSubclassEntity.class, id1_1, 1 ); + AuditedMethodSubclassEntity rev2 = getAuditReader().find( AuditedMethodSubclassEntity.class, id1_1, 2 ); + //this property is not audited on superclass - assert(rev1.getOtherStr() == null); - assert(rev2.getOtherStr() == null); - - assert rev1.equals(ver1); - assert rev2.equals(ver2); + assert (rev1.getOtherStr() == null); + assert (rev2.getOtherStr() == null); + + assert rev1.equals( ver1 ); + assert rev2.equals( ver2 ); } - - @Test(expected=NotAuditedException.class) + + @Test(expected = NotAuditedException.class) public void testHistoryOfNotAudited() { try { - getAuditReader().find(NotAuditedSubclassEntity.class, id2_1, 1); - assert(false); - } catch (NotAuditedException nae) { + getAuditReader().find( NotAuditedSubclassEntity.class, id2_1, 1 ); + assert (false); + } + catch (NotAuditedException nae) { throw nae; } } - + } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditedAtSuperclassLevel/AuditedAllMappedSuperclass.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditedAtSuperclassLevel/AuditedAllMappedSuperclass.java index 7adcaa9628..cce9062251 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditedAtSuperclassLevel/AuditedAllMappedSuperclass.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditedAtSuperclassLevel/AuditedAllMappedSuperclass.java @@ -22,13 +22,13 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.superclass.auditedAtSuperclassLevel; + import javax.persistence.MappedSuperclass; import org.hibernate.envers.Audited; /** * @author Adam Warski (adam at warski dot org) - * * @author Hern&aacut;n Chanfreau */ @MappedSuperclass @@ -36,7 +36,7 @@ import org.hibernate.envers.Audited; public class AuditedAllMappedSuperclass { private String str; - + private String otherStr; public AuditedAllMappedSuperclass() { @@ -64,15 +64,18 @@ public class AuditedAllMappedSuperclass { } public boolean equals(Object o) { - if (this == o) + if ( this == o ) { return true; - if (!(o instanceof AuditedAllMappedSuperclass)) + } + if ( !(o instanceof AuditedAllMappedSuperclass) ) { return false; + } AuditedAllMappedSuperclass that = (AuditedAllMappedSuperclass) o; - if (str != null ? !str.equals(that.str) : that.str != null) + if ( str != null ? !str.equals( that.str ) : that.str != null ) { return false; + } return true; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditedAtSuperclassLevel/NotAuditedSubclassEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditedAtSuperclassLevel/NotAuditedSubclassEntity.java index d128436b05..87d4d1e6bf 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditedAtSuperclassLevel/NotAuditedSubclassEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditedAtSuperclassLevel/NotAuditedSubclassEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.superclass.auditedAtSuperclassLevel; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; @@ -30,9 +31,7 @@ import javax.persistence.Table; /** * @author Adam Warski (adam at warski dot org) - * * @author Hernán Chanfreau - * */ @Entity @Table(name = "NotAuditedSubclass") @@ -40,20 +39,20 @@ public class NotAuditedSubclassEntity extends AuditedAllMappedSuperclass { @Id @GeneratedValue private Integer id; - + private String notAuditedStr; public NotAuditedSubclassEntity() { } public NotAuditedSubclassEntity(Integer id, String str, String otherStr, String notAuditedStr) { - super(str, otherStr); + super( str, otherStr ); this.notAuditedStr = notAuditedStr; this.id = id; } public NotAuditedSubclassEntity(String str, String otherStr, String notAuditedStr) { - super(str, otherStr); + super( str, otherStr ); this.notAuditedStr = notAuditedStr; } @@ -74,17 +73,21 @@ public class NotAuditedSubclassEntity extends AuditedAllMappedSuperclass { } public boolean equals(Object o) { - if (this == o) + if ( this == o ) { return true; - if (!(o instanceof NotAuditedSubclassEntity)) + } + if ( !(o instanceof NotAuditedSubclassEntity) ) { return false; - if (!super.equals(o)) + } + if ( !super.equals( o ) ) { return false; + } NotAuditedSubclassEntity that = (NotAuditedSubclassEntity) o; - if (id != null ? !id.equals(that.id) : that.id != null) + if ( id != null ? !id.equals( that.id ) : that.id != null ) { return false; + } return true; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditedAtSuperclassLevel/auditAllSubclass/AuditedAllSubclassEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditedAtSuperclassLevel/auditAllSubclass/AuditedAllSubclassEntity.java index 380ed6dc62..a40c69c973 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditedAtSuperclassLevel/auditAllSubclass/AuditedAllSubclassEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditedAtSuperclassLevel/auditAllSubclass/AuditedAllSubclassEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.superclass.auditedAtSuperclassLevel.auditAllSubclass; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; @@ -35,59 +36,67 @@ import org.hibernate.envers.test.integration.superclass.auditedAtSuperclassLevel */ @Entity @Audited -public class AuditedAllSubclassEntity extends AuditedAllMappedSuperclass { - @Id - @GeneratedValue - private Integer id; - - private String subAuditedStr; +public class AuditedAllSubclassEntity extends AuditedAllMappedSuperclass { + @Id + @GeneratedValue + private Integer id; + + private String subAuditedStr; public AuditedAllSubclassEntity() { - } + } - public AuditedAllSubclassEntity(Integer id, String str, String otherString, String subAuditedStr) { - super(str, otherString); - this.subAuditedStr = subAuditedStr; - this.id = id; - } + public AuditedAllSubclassEntity(Integer id, String str, String otherString, String subAuditedStr) { + super( str, otherString ); + this.subAuditedStr = subAuditedStr; + this.id = id; + } - public AuditedAllSubclassEntity(String str, String otherString, String subAuditedStr ) { - super(str, otherString); - this.subAuditedStr = subAuditedStr; - } + public AuditedAllSubclassEntity(String str, String otherString, String subAuditedStr) { + super( str, otherString ); + this.subAuditedStr = subAuditedStr; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getSubAuditedStr() { + public String getSubAuditedStr() { return subAuditedStr; } public void setSubAuditedStr(String subAuditedStr) { this.subAuditedStr = subAuditedStr; } - - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof AuditedAllSubclassEntity)) return false; - if (!super.equals(o)) return false; - AuditedAllSubclassEntity that = (AuditedAllSubclassEntity) o; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof AuditedAllSubclassEntity) ) { + return false; + } + if ( !super.equals( o ) ) { + return false; + } - if (id != null ? !id.equals(that.id) : that.id != null) return false; + AuditedAllSubclassEntity that = (AuditedAllSubclassEntity) o; - return true; - } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - public int hashCode() { - int result = super.hashCode(); - result = 31 * result + (id != null ? id.hashCode() : 0); - return result; - } + return true; + } + + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (id != null ? id.hashCode() : 0); + return result; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditedAtSuperclassLevel/auditAllSubclass/MappedSubclassingAllAuditedTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditedAtSuperclassLevel/auditAllSubclass/MappedSubclassingAllAuditedTest.java index 89a621f1b4..d5c38c3572 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditedAtSuperclassLevel/auditAllSubclass/MappedSubclassingAllAuditedTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditedAtSuperclassLevel/auditAllSubclass/MappedSubclassingAllAuditedTest.java @@ -23,10 +23,8 @@ */ package org.hibernate.envers.test.integration.superclass.auditedAtSuperclassLevel.auditAllSubclass; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.exception.NotAuditedException; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; @@ -34,11 +32,11 @@ import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.integration.superclass.auditedAtSuperclassLevel.AuditedAllMappedSuperclass; import org.hibernate.envers.test.integration.superclass.auditedAtSuperclassLevel.NotAuditedSubclassEntity; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) - * * @author Hern&aacut;n Chanfreau - * */ public class MappedSubclassingAllAuditedTest extends BaseEnversJPAFunctionalTestCase { private Integer id2_1; @@ -46,74 +44,81 @@ public class MappedSubclassingAllAuditedTest extends BaseEnversJPAFunctionalTest @Override protected Class[] getAnnotatedClasses() { - return new Class[] { AuditedAllMappedSuperclass.class, AuditedAllSubclassEntity.class, NotAuditedSubclassEntity.class }; + return new Class[] { + AuditedAllMappedSuperclass.class, + AuditedAllSubclassEntity.class, + NotAuditedSubclassEntity.class + }; } @Test - @Priority(10) + @Priority(10) public void initData() { // Revision 1 EntityManager em = getEntityManager(); em.getTransaction().begin(); - NotAuditedSubclassEntity nas = new NotAuditedSubclassEntity("nae","super str","not audited str"); - em.persist(nas); - AuditedAllSubclassEntity ae = new AuditedAllSubclassEntity("ae", "super str", "audited str"); - em.persist(ae); + NotAuditedSubclassEntity nas = new NotAuditedSubclassEntity( "nae", "super str", "not audited str" ); + em.persist( nas ); + AuditedAllSubclassEntity ae = new AuditedAllSubclassEntity( "ae", "super str", "audited str" ); + em.persist( ae ); id1_1 = ae.getId(); id2_1 = nas.getId(); em.getTransaction().commit(); // Revision 2 em.getTransaction().begin(); - ae = em.find(AuditedAllSubclassEntity.class, id1_1); - ae.setStr("ae new"); - ae.setSubAuditedStr("audited str new"); - nas = em.find(NotAuditedSubclassEntity.class, id2_1); - nas.setStr("nae new"); - nas.setNotAuditedStr("not aud str new"); + ae = em.find( AuditedAllSubclassEntity.class, id1_1 ); + ae.setStr( "ae new" ); + ae.setSubAuditedStr( "audited str new" ); + nas = em.find( NotAuditedSubclassEntity.class, id2_1 ); + nas.setStr( "nae new" ); + nas.setNotAuditedStr( "not aud str new" ); em.getTransaction().commit(); } @Test public void testRevisionsCountsForAudited() { - assert Arrays.asList(1, 2).equals( - getAuditReader().getRevisions(AuditedAllSubclassEntity.class, id1_1)); + assert Arrays.asList( 1, 2 ).equals( + getAuditReader().getRevisions( AuditedAllSubclassEntity.class, id1_1 ) + ); } - - @Test(expected= NotAuditedException.class ) + + @Test(expected = NotAuditedException.class) public void testRevisionsCountsForNotAudited() { try { - getAuditReader().getRevisions(NotAuditedSubclassEntity.class, id2_1); - assert(false); - } catch (NotAuditedException nae) { + getAuditReader().getRevisions( NotAuditedSubclassEntity.class, id2_1 ); + assert (false); + } + catch (NotAuditedException nae) { throw nae; } } - + @Test public void testHistoryOfAudited() { - AuditedAllSubclassEntity ver1 = new AuditedAllSubclassEntity(id1_1, "ae", "super str", "audited str"); - AuditedAllSubclassEntity ver2 = new AuditedAllSubclassEntity(id1_1, "ae new", "super str", "audited str new"); + AuditedAllSubclassEntity ver1 = new AuditedAllSubclassEntity( id1_1, "ae", "super str", "audited str" ); + AuditedAllSubclassEntity ver2 = new AuditedAllSubclassEntity( id1_1, "ae new", "super str", "audited str new" ); - AuditedAllSubclassEntity rev1 = getAuditReader().find(AuditedAllSubclassEntity.class, id1_1, 1); - AuditedAllSubclassEntity rev2 = getAuditReader().find(AuditedAllSubclassEntity.class, id1_1, 2); - - assert(rev1.getOtherStr() != null); - assert(rev2.getOtherStr() != null); - - assert rev1.equals(ver1); - assert rev2.equals(ver2); + AuditedAllSubclassEntity rev1 = getAuditReader().find( AuditedAllSubclassEntity.class, id1_1, 1 ); + AuditedAllSubclassEntity rev2 = getAuditReader().find( AuditedAllSubclassEntity.class, id1_1, 2 ); + + assert (rev1.getOtherStr() != null); + assert (rev2.getOtherStr() != null); + + assert rev1.equals( ver1 ); + assert rev2.equals( ver2 ); } - - @Test(expected=NotAuditedException.class) + + @Test(expected = NotAuditedException.class) public void testHistoryOfNotAudited() { try { - getAuditReader().find(NotAuditedSubclassEntity.class, id2_1, 1); - assert(false); - } catch (NotAuditedException nae) { + getAuditReader().find( NotAuditedSubclassEntity.class, id2_1, 1 ); + assert (false); + } + catch (NotAuditedException nae) { throw nae; } -} - + } + } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditedAtSuperclassLevel/auditMethodSubclass/AuditedMethodSubclassEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditedAtSuperclassLevel/auditMethodSubclass/AuditedMethodSubclassEntity.java index a51e103483..c940eb29f7 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditedAtSuperclassLevel/auditMethodSubclass/AuditedMethodSubclassEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditedAtSuperclassLevel/auditMethodSubclass/AuditedMethodSubclassEntity.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.superclass.auditedAtSuperclassLevel.auditMethodSubclass; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; @@ -36,60 +37,68 @@ import org.hibernate.envers.test.integration.superclass.auditedAtSuperclassLevel */ @Entity @Table(name = "AuditedMethodSubclass") -public class AuditedMethodSubclassEntity extends AuditedAllMappedSuperclass { - @Id - @GeneratedValue - private Integer id; - - @Audited - private String subAuditedStr; +public class AuditedMethodSubclassEntity extends AuditedAllMappedSuperclass { + @Id + @GeneratedValue + private Integer id; + + @Audited + private String subAuditedStr; public AuditedMethodSubclassEntity() { - } + } - public AuditedMethodSubclassEntity(Integer id, String str, String otherString, String subAuditedStr) { - super(str, otherString); - this.subAuditedStr = subAuditedStr; - this.id = id; - } + public AuditedMethodSubclassEntity(Integer id, String str, String otherString, String subAuditedStr) { + super( str, otherString ); + this.subAuditedStr = subAuditedStr; + this.id = id; + } - public AuditedMethodSubclassEntity(String str, String otherString, String subAuditedStr ) { - super(str, otherString); - this.subAuditedStr = subAuditedStr; - } + public AuditedMethodSubclassEntity(String str, String otherString, String subAuditedStr) { + super( str, otherString ); + this.subAuditedStr = subAuditedStr; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getSubAuditedStr() { + public String getSubAuditedStr() { return subAuditedStr; } public void setSubAuditedStr(String subAuditedStr) { this.subAuditedStr = subAuditedStr; } - - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof AuditedMethodSubclassEntity)) return false; - if (!super.equals(o)) return false; - AuditedMethodSubclassEntity that = (AuditedMethodSubclassEntity) o; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof AuditedMethodSubclassEntity) ) { + return false; + } + if ( !super.equals( o ) ) { + return false; + } - if (id != null ? !id.equals(that.id) : that.id != null) return false; + AuditedMethodSubclassEntity that = (AuditedMethodSubclassEntity) o; - return true; - } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } - public int hashCode() { - int result = super.hashCode(); - result = 31 * result + (id != null ? id.hashCode() : 0); - return result; - } + return true; + } + + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (id != null ? id.hashCode() : 0); + return result; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditedAtSuperclassLevel/auditMethodSubclass/MappedSubclassingMethodAuditedTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditedAtSuperclassLevel/auditMethodSubclass/MappedSubclassingMethodAuditedTest.java index a35141252b..84e4e08f7a 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditedAtSuperclassLevel/auditMethodSubclass/MappedSubclassingMethodAuditedTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditedAtSuperclassLevel/auditMethodSubclass/MappedSubclassingMethodAuditedTest.java @@ -23,10 +23,8 @@ */ package org.hibernate.envers.test.integration.superclass.auditedAtSuperclassLevel.auditMethodSubclass; -import java.util.Arrays; import javax.persistence.EntityManager; - -import org.junit.Test; +import java.util.Arrays; import org.hibernate.envers.exception.NotAuditedException; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; @@ -34,11 +32,11 @@ import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.integration.superclass.auditedAtSuperclassLevel.AuditedAllMappedSuperclass; import org.hibernate.envers.test.integration.superclass.auditedAtSuperclassLevel.NotAuditedSubclassEntity; +import org.junit.Test; + /** * @author Adam Warski (adam at warski dot org) - * * @author Hern&aacut;n Chanfreau - * */ public class MappedSubclassingMethodAuditedTest extends BaseEnversJPAFunctionalTestCase { private Integer id2_1; @@ -54,70 +52,78 @@ public class MappedSubclassingMethodAuditedTest extends BaseEnversJPAFunctionalT } @Test - @Priority(10) + @Priority(10) public void initData() { // Revision 1 EntityManager em = getEntityManager(); em.getTransaction().begin(); - NotAuditedSubclassEntity nas = new NotAuditedSubclassEntity("nae","super str","not audited str"); - em.persist(nas); - AuditedMethodSubclassEntity ae = new AuditedMethodSubclassEntity("ae", "super str", "audited str"); - em.persist(ae); + NotAuditedSubclassEntity nas = new NotAuditedSubclassEntity( "nae", "super str", "not audited str" ); + em.persist( nas ); + AuditedMethodSubclassEntity ae = new AuditedMethodSubclassEntity( "ae", "super str", "audited str" ); + em.persist( ae ); id1_1 = ae.getId(); id2_1 = nas.getId(); em.getTransaction().commit(); // Revision 2 em.getTransaction().begin(); - ae = em.find(AuditedMethodSubclassEntity.class, id1_1); - ae.setStr("ae new"); - ae.setSubAuditedStr("audited str new"); - nas = em.find(NotAuditedSubclassEntity.class, id2_1); - nas.setStr("nae new"); - nas.setNotAuditedStr("not aud str new"); + ae = em.find( AuditedMethodSubclassEntity.class, id1_1 ); + ae.setStr( "ae new" ); + ae.setSubAuditedStr( "audited str new" ); + nas = em.find( NotAuditedSubclassEntity.class, id2_1 ); + nas.setStr( "nae new" ); + nas.setNotAuditedStr( "not aud str new" ); em.getTransaction().commit(); } @Test public void testRevisionsCountsForAudited() { - assert Arrays.asList(1, 2).equals( - getAuditReader().getRevisions(AuditedMethodSubclassEntity.class, id1_1)); + assert Arrays.asList( 1, 2 ).equals( + getAuditReader().getRevisions( AuditedMethodSubclassEntity.class, id1_1 ) + ); } - - @Test(expected=NotAuditedException.class) + + @Test(expected = NotAuditedException.class) public void testRevisionsCountsForNotAudited() { try { - getAuditReader().getRevisions(NotAuditedSubclassEntity.class, id2_1); - assert(false); - } catch (NotAuditedException nae) { + getAuditReader().getRevisions( NotAuditedSubclassEntity.class, id2_1 ); + assert (false); + } + catch (NotAuditedException nae) { throw nae; } } - + @Test public void testHistoryOfAudited() { - AuditedMethodSubclassEntity ver1 = new AuditedMethodSubclassEntity(id1_1, "ae", "super str", "audited str"); - AuditedMethodSubclassEntity ver2 = new AuditedMethodSubclassEntity(id1_1, "ae new", "super str", "audited str new"); - - AuditedMethodSubclassEntity rev1 = getAuditReader().find(AuditedMethodSubclassEntity.class, id1_1, 1); - AuditedMethodSubclassEntity rev2 = getAuditReader().find(AuditedMethodSubclassEntity.class, id1_1, 2); - - assert(rev1.getOtherStr() != null); - assert(rev2.getOtherStr() != null); - - assert rev1.equals(ver1); - assert rev2.equals(ver2); + AuditedMethodSubclassEntity ver1 = new AuditedMethodSubclassEntity( id1_1, "ae", "super str", "audited str" ); + AuditedMethodSubclassEntity ver2 = new AuditedMethodSubclassEntity( + id1_1, + "ae new", + "super str", + "audited str new" + ); + + AuditedMethodSubclassEntity rev1 = getAuditReader().find( AuditedMethodSubclassEntity.class, id1_1, 1 ); + AuditedMethodSubclassEntity rev2 = getAuditReader().find( AuditedMethodSubclassEntity.class, id1_1, 2 ); + + assert (rev1.getOtherStr() != null); + assert (rev2.getOtherStr() != null); + + assert rev1.equals( ver1 ); + assert rev2.equals( ver2 ); } - - @Test(expected= NotAuditedException.class ) + + @Test(expected = NotAuditedException.class) public void testHistoryOfNotAudited() { try { - getAuditReader().find(NotAuditedSubclassEntity.class, id2_1, 1); - assert(false); - } catch (NotAuditedException nae) { + getAuditReader().find( NotAuditedSubclassEntity.class, id2_1, 1 ); + assert (false); + } + catch (NotAuditedException nae) { throw nae; } -} - + } + } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/AuditClassOverrideTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/AuditClassOverrideTest.java index d5e78e07a8..2d9a2cb159 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/AuditClassOverrideTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/AuditClassOverrideTest.java @@ -2,13 +2,14 @@ package org.hibernate.envers.test.integration.superclass.auditoverride; import javax.persistence.EntityManager; -import org.junit.Assert; -import org.junit.Test; - import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.mapping.Column; import org.hibernate.mapping.Table; + +import org.junit.Assert; +import org.junit.Test; + import org.hibernate.testing.TestForIssue; /** @@ -16,62 +17,81 @@ import org.hibernate.testing.TestForIssue; */ @TestForIssue(jiraKey = "HHH-4439") public class AuditClassOverrideTest extends BaseEnversJPAFunctionalTestCase { - private Integer classAuditedEntityId = null; - private Integer classNotAuditedEntityId = null; - private Table classAuditedTable = null; - private Table classNotAuditedTable = null; + private Integer classAuditedEntityId = null; + private Integer classNotAuditedEntityId = null; + private Table classAuditedTable = null; + private Table classNotAuditedTable = null; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { ClassOverrideAuditedEntity.class, ClassOverrideNotAuditedEntity.class }; - } + return new Class[] {ClassOverrideAuditedEntity.class, ClassOverrideNotAuditedEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - // Revision 1 - em.getTransaction().begin(); - ClassOverrideAuditedEntity classOverrideAuditedEntity = new ClassOverrideAuditedEntity("data 1", 1, "data 2"); - em.persist(classOverrideAuditedEntity); - em.getTransaction().commit(); - classAuditedEntityId = classOverrideAuditedEntity.getId(); + // Revision 1 + em.getTransaction().begin(); + ClassOverrideAuditedEntity classOverrideAuditedEntity = new ClassOverrideAuditedEntity( "data 1", 1, "data 2" ); + em.persist( classOverrideAuditedEntity ); + em.getTransaction().commit(); + classAuditedEntityId = classOverrideAuditedEntity.getId(); - // Revision 2 - em.getTransaction().begin(); - ClassOverrideNotAuditedEntity classOverrideNotAuditedEntity = new ClassOverrideNotAuditedEntity("data 1", 1, "data 2"); - em.persist(classOverrideNotAuditedEntity); - em.getTransaction().commit(); - classNotAuditedEntityId = classOverrideNotAuditedEntity.getId(); + // Revision 2 + em.getTransaction().begin(); + ClassOverrideNotAuditedEntity classOverrideNotAuditedEntity = new ClassOverrideNotAuditedEntity( + "data 1", + 1, + "data 2" + ); + em.persist( classOverrideNotAuditedEntity ); + em.getTransaction().commit(); + classNotAuditedEntityId = classOverrideNotAuditedEntity.getId(); - classAuditedTable = getCfg().getClassMapping("org.hibernate.envers.test.integration.superclass.auditoverride.ClassOverrideAuditedEntity_AUD").getTable(); - classNotAuditedTable = getCfg().getClassMapping("org.hibernate.envers.test.integration.superclass.auditoverride.ClassOverrideNotAuditedEntity_AUD").getTable(); - } + classAuditedTable = getCfg().getClassMapping( + "org.hibernate.envers.test.integration.superclass.auditoverride.ClassOverrideAuditedEntity_AUD" + ).getTable(); + classNotAuditedTable = getCfg().getClassMapping( + "org.hibernate.envers.test.integration.superclass.auditoverride.ClassOverrideNotAuditedEntity_AUD" + ).getTable(); + } - @Test - public void testAuditedProperty() { - Assert.assertNotNull(classAuditedTable.getColumn(new Column("number1"))); - Assert.assertNotNull(classAuditedTable.getColumn(new Column("str1"))); - Assert.assertNotNull(classAuditedTable.getColumn(new Column("str2"))); - Assert.assertNotNull(classNotAuditedTable.getColumn(new Column("str2"))); - } + @Test + public void testAuditedProperty() { + Assert.assertNotNull( classAuditedTable.getColumn( new Column( "number1" ) ) ); + Assert.assertNotNull( classAuditedTable.getColumn( new Column( "str1" ) ) ); + Assert.assertNotNull( classAuditedTable.getColumn( new Column( "str2" ) ) ); + Assert.assertNotNull( classNotAuditedTable.getColumn( new Column( "str2" ) ) ); + } - @Test - public void testNotAuditedProperty() { - Assert.assertNull(classNotAuditedTable.getColumn(new Column("number1"))); - Assert.assertNull(classNotAuditedTable.getColumn(new Column("str1"))); - } + @Test + public void testNotAuditedProperty() { + Assert.assertNull( classNotAuditedTable.getColumn( new Column( "number1" ) ) ); + Assert.assertNull( classNotAuditedTable.getColumn( new Column( "str1" ) ) ); + } - @Test - public void testHistoryOfClassOverrideAuditedEntity() { - ClassOverrideAuditedEntity ver1 = new ClassOverrideAuditedEntity("data 1", 1, classAuditedEntityId, "data 2"); - Assert.assertEquals(ver1, getAuditReader().find(ClassOverrideAuditedEntity.class, classAuditedEntityId, 1)); - } + @Test + public void testHistoryOfClassOverrideAuditedEntity() { + ClassOverrideAuditedEntity ver1 = new ClassOverrideAuditedEntity( "data 1", 1, classAuditedEntityId, "data 2" ); + Assert.assertEquals( ver1, getAuditReader().find( ClassOverrideAuditedEntity.class, classAuditedEntityId, 1 ) ); + } - @Test - public void testHistoryOfClassOverrideNotAuditedEntity() { - ClassOverrideNotAuditedEntity ver1 = new ClassOverrideNotAuditedEntity(null, null, classNotAuditedEntityId, "data 2"); - Assert.assertEquals(ver1, getAuditReader().find(ClassOverrideNotAuditedEntity.class, classNotAuditedEntityId, 2)); - } + @Test + public void testHistoryOfClassOverrideNotAuditedEntity() { + ClassOverrideNotAuditedEntity ver1 = new ClassOverrideNotAuditedEntity( + null, + null, + classNotAuditedEntityId, + "data 2" + ); + Assert.assertEquals( + ver1, getAuditReader().find( + ClassOverrideNotAuditedEntity.class, + classNotAuditedEntityId, + 2 + ) + ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/AuditPropertyOverrideTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/AuditPropertyOverrideTest.java index 512b805a6a..4ee096fb92 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/AuditPropertyOverrideTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/AuditPropertyOverrideTest.java @@ -2,13 +2,14 @@ package org.hibernate.envers.test.integration.superclass.auditoverride; import javax.persistence.EntityManager; -import org.junit.Assert; -import org.junit.Test; - import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.mapping.Column; import org.hibernate.mapping.Table; + +import org.junit.Assert; +import org.junit.Test; + import org.hibernate.testing.TestForIssue; /** @@ -16,82 +17,95 @@ import org.hibernate.testing.TestForIssue; */ @TestForIssue(jiraKey = "HHH-4439") public class AuditPropertyOverrideTest extends BaseEnversJPAFunctionalTestCase { - private Integer propertyEntityId = null; - private Integer transitiveEntityId = null; - private Integer auditedEntityId = null; - private Table propertyTable = null; - private Table transitiveTable = null; - private Table auditedTable = null; + private Integer propertyEntityId = null; + private Integer transitiveEntityId = null; + private Integer auditedEntityId = null; + private Table propertyTable = null; + private Table transitiveTable = null; + private Table auditedTable = null; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { PropertyOverrideEntity.class, TransitiveOverrideEntity.class, AuditedSpecialEntity.class }; - } + return new Class[] {PropertyOverrideEntity.class, TransitiveOverrideEntity.class, AuditedSpecialEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - // Revision 1 - em.getTransaction().begin(); - PropertyOverrideEntity propertyEntity = new PropertyOverrideEntity("data 1", 1, "data 2"); - em.persist(propertyEntity); - em.getTransaction().commit(); - propertyEntityId = propertyEntity.getId(); + // Revision 1 + em.getTransaction().begin(); + PropertyOverrideEntity propertyEntity = new PropertyOverrideEntity( "data 1", 1, "data 2" ); + em.persist( propertyEntity ); + em.getTransaction().commit(); + propertyEntityId = propertyEntity.getId(); - // Revision 2 - em.getTransaction().begin(); - TransitiveOverrideEntity transitiveEntity = new TransitiveOverrideEntity("data 1", 1, "data 2", 2, "data 3"); - em.persist(transitiveEntity); - em.getTransaction().commit(); - transitiveEntityId = transitiveEntity.getId(); + // Revision 2 + em.getTransaction().begin(); + TransitiveOverrideEntity transitiveEntity = new TransitiveOverrideEntity( "data 1", 1, "data 2", 2, "data 3" ); + em.persist( transitiveEntity ); + em.getTransaction().commit(); + transitiveEntityId = transitiveEntity.getId(); - // Revision 3 - em.getTransaction().begin(); - AuditedSpecialEntity auditedEntity = new AuditedSpecialEntity("data 1", 1, "data 2"); - em.persist(auditedEntity); - em.getTransaction().commit(); - auditedEntityId = auditedEntity.getId(); + // Revision 3 + em.getTransaction().begin(); + AuditedSpecialEntity auditedEntity = new AuditedSpecialEntity( "data 1", 1, "data 2" ); + em.persist( auditedEntity ); + em.getTransaction().commit(); + auditedEntityId = auditedEntity.getId(); - propertyTable = getCfg().getClassMapping("org.hibernate.envers.test.integration.superclass.auditoverride.PropertyOverrideEntity_AUD").getTable(); - transitiveTable = getCfg().getClassMapping("org.hibernate.envers.test.integration.superclass.auditoverride.TransitiveOverrideEntity_AUD").getTable(); - auditedTable = getCfg().getClassMapping("org.hibernate.envers.test.integration.superclass.auditoverride.AuditedSpecialEntity_AUD").getTable(); - } + propertyTable = getCfg().getClassMapping( + "org.hibernate.envers.test.integration.superclass.auditoverride.PropertyOverrideEntity_AUD" + ).getTable(); + transitiveTable = getCfg().getClassMapping( + "org.hibernate.envers.test.integration.superclass.auditoverride.TransitiveOverrideEntity_AUD" + ).getTable(); + auditedTable = getCfg().getClassMapping( + "org.hibernate.envers.test.integration.superclass.auditoverride.AuditedSpecialEntity_AUD" + ).getTable(); + } - @Test - public void testNotAuditedProperty() { - Assert.assertNull(propertyTable.getColumn(new Column("str1"))); - } + @Test + public void testNotAuditedProperty() { + Assert.assertNull( propertyTable.getColumn( new Column( "str1" ) ) ); + } - @Test - public void testAuditedProperty() { - Assert.assertNotNull(propertyTable.getColumn(new Column("number1"))); - Assert.assertNotNull(transitiveTable.getColumn(new Column("number2"))); - Assert.assertNotNull(auditedTable.getColumn(new Column("str1"))); - } + @Test + public void testAuditedProperty() { + Assert.assertNotNull( propertyTable.getColumn( new Column( "number1" ) ) ); + Assert.assertNotNull( transitiveTable.getColumn( new Column( "number2" ) ) ); + Assert.assertNotNull( auditedTable.getColumn( new Column( "str1" ) ) ); + } - @Test - public void testTransitiveAuditedProperty() { - Assert.assertNotNull(transitiveTable.getColumn(new Column("number1"))); - Assert.assertNotNull(transitiveTable.getColumn(new Column("str1"))); - } + @Test + public void testTransitiveAuditedProperty() { + Assert.assertNotNull( transitiveTable.getColumn( new Column( "number1" ) ) ); + Assert.assertNotNull( transitiveTable.getColumn( new Column( "str1" ) ) ); + } - @Test - public void testHistoryOfPropertyOverrideEntity() { - PropertyOverrideEntity ver1 = new PropertyOverrideEntity(null, 1, propertyEntityId, "data 2"); - Assert.assertEquals(ver1, getAuditReader().find(PropertyOverrideEntity.class, propertyEntityId, 1)); - } + @Test + public void testHistoryOfPropertyOverrideEntity() { + PropertyOverrideEntity ver1 = new PropertyOverrideEntity( null, 1, propertyEntityId, "data 2" ); + Assert.assertEquals( ver1, getAuditReader().find( PropertyOverrideEntity.class, propertyEntityId, 1 ) ); + } - @Test - public void testHistoryOfTransitiveOverrideEntity() { - TransitiveOverrideEntity ver1 = new TransitiveOverrideEntity("data 1", 1, transitiveEntityId, "data 2", 2, "data 3"); - Assert.assertEquals(ver1, getAuditReader().find(TransitiveOverrideEntity.class, transitiveEntityId, 2)); - } + @Test + public void testHistoryOfTransitiveOverrideEntity() { + TransitiveOverrideEntity ver1 = new TransitiveOverrideEntity( + "data 1", + 1, + transitiveEntityId, + "data 2", + 2, + "data 3" + ); + Assert.assertEquals( ver1, getAuditReader().find( TransitiveOverrideEntity.class, transitiveEntityId, 2 ) ); + } - @Test - public void testHistoryOfAuditedSpecialEntity() { - AuditedSpecialEntity ver1 = new AuditedSpecialEntity("data 1", null, auditedEntityId, "data 2"); - Assert.assertEquals(ver1, getAuditReader().find(AuditedSpecialEntity.class, auditedEntityId, 3)); - } + @Test + public void testHistoryOfAuditedSpecialEntity() { + AuditedSpecialEntity ver1 = new AuditedSpecialEntity( "data 1", null, auditedEntityId, "data 2" ); + Assert.assertEquals( ver1, getAuditReader().find( AuditedSpecialEntity.class, auditedEntityId, 3 ) ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/AuditedBaseEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/AuditedBaseEntity.java index 08c4bb9464..98613404b1 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/AuditedBaseEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/AuditedBaseEntity.java @@ -1,9 +1,9 @@ package org.hibernate.envers.test.integration.superclass.auditoverride; -import java.io.Serializable; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.MappedSuperclass; +import java.io.Serializable; import org.hibernate.envers.Audited; @@ -13,74 +13,84 @@ import org.hibernate.envers.Audited; @Audited @MappedSuperclass public class AuditedBaseEntity implements Serializable { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - private String str1; + private String str1; - private Integer number1; + private Integer number1; - public AuditedBaseEntity() { - } + public AuditedBaseEntity() { + } - public AuditedBaseEntity(String str1, Integer number1, Integer id) { - this.id = id; - this.str1 = str1; - this.number1 = number1; - } + public AuditedBaseEntity(String str1, Integer number1, Integer id) { + this.id = id; + this.str1 = str1; + this.number1 = number1; + } - public AuditedBaseEntity(String str1, Integer number1) { - this.str1 = str1; - this.number1 = number1; - } + public AuditedBaseEntity(String str1, Integer number1) { + this.str1 = str1; + this.number1 = number1; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getStr1() { - return str1; - } + public String getStr1() { + return str1; + } - public void setStr1(String str1) { - this.str1 = str1; - } + public void setStr1(String str1) { + this.str1 = str1; + } - public Integer getNumber1() { - return number1; - } + public Integer getNumber1() { + return number1; + } - public void setNumber1(Integer number1) { - this.number1 = number1; - } + public void setNumber1(Integer number1) { + this.number1 = number1; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof AuditedBaseEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof AuditedBaseEntity) ) { + return false; + } - AuditedBaseEntity that = (AuditedBaseEntity) o; + AuditedBaseEntity that = (AuditedBaseEntity) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; - if (number1 != null ? !number1.equals(that.number1) : that.number1 != null) return false; - if (str1 != null ? !str1.equals(that.str1) : that.str1 != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } + if ( number1 != null ? !number1.equals( that.number1 ) : that.number1 != null ) { + return false; + } + if ( str1 != null ? !str1.equals( that.str1 ) : that.str1 != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (str1 != null ? str1.hashCode() : 0); - result = 31 * result + (number1 != null ? number1.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (str1 != null ? str1.hashCode() : 0); + result = 31 * result + (number1 != null ? number1.hashCode() : 0); + return result; + } - public String toString() { - return "AuditedBaseEntity(id = " + id + ", str1 = " + str1 + ", number1 = " + number1 + ")"; - } + public String toString() { + return "AuditedBaseEntity(id = " + id + ", str1 = " + str1 + ", number1 = " + number1 + ")"; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/AuditedSpecialEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/AuditedSpecialEntity.java index 16461b72d4..2e3b5e1c21 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/AuditedSpecialEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/AuditedSpecialEntity.java @@ -12,52 +12,60 @@ import org.hibernate.envers.Audited; @Entity @AuditOverrides({@AuditOverride(forClass = NotAuditedBaseEntity.class, name = "str1", isAudited = true)}) public class AuditedSpecialEntity extends NotAuditedBaseEntity { - @Audited - private String str2; + @Audited + private String str2; - public AuditedSpecialEntity() { - } + public AuditedSpecialEntity() { + } - public AuditedSpecialEntity(String str1, Integer number, String str2) { - super(str1, number); - this.str2 = str2; - } + public AuditedSpecialEntity(String str1, Integer number, String str2) { + super( str1, number ); + this.str2 = str2; + } - public AuditedSpecialEntity(String str1, Integer number, Integer id, String str2) { - super(str1, number, id); - this.str2 = str2; - } + public AuditedSpecialEntity(String str1, Integer number, Integer id, String str2) { + super( str1, number, id ); + this.str2 = str2; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof AuditedSpecialEntity)) return false; - if (!super.equals(o)) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof AuditedSpecialEntity) ) { + return false; + } + if ( !super.equals( o ) ) { + return false; + } - AuditedSpecialEntity that = (AuditedSpecialEntity) o; + AuditedSpecialEntity that = (AuditedSpecialEntity) o; - if (str2 != null ? !str2.equals(that.str2) : that.str2 != null) return false; + if ( str2 != null ? !str2.equals( that.str2 ) : that.str2 != null ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - int result = super.hashCode(); - result = 31 * result + (str2 != null ? str2.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (str2 != null ? str2.hashCode() : 0); + return result; + } - @Override - public String toString() { - return "AuditedSpecialEntity(" + super.toString() + ", str2 = " + str2 + ")"; - } + @Override + public String toString() { + return "AuditedSpecialEntity(" + super.toString() + ", str2 = " + str2 + ")"; + } - public String getStr2() { - return str2; - } + public String getStr2() { + return str2; + } - public void setStr2(String str2) { - this.str2 = str2; - } + public void setStr2(String str2) { + this.str2 = str2; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/BaseEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/BaseEntity.java index 59599cee64..9cf952d2b5 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/BaseEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/BaseEntity.java @@ -1,9 +1,9 @@ package org.hibernate.envers.test.integration.superclass.auditoverride; -import java.io.Serializable; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.MappedSuperclass; +import java.io.Serializable; import org.hibernate.envers.Audited; import org.hibernate.envers.NotAudited; @@ -13,76 +13,86 @@ import org.hibernate.envers.NotAudited; */ @MappedSuperclass public class BaseEntity implements Serializable { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - @Audited - private String str1; + @Audited + private String str1; - @NotAudited - private Integer number1; + @NotAudited + private Integer number1; - public BaseEntity() { - } + public BaseEntity() { + } - public BaseEntity(String str1, Integer number1, Integer id) { - this.id = id; - this.str1 = str1; - this.number1 = number1; - } + public BaseEntity(String str1, Integer number1, Integer id) { + this.id = id; + this.str1 = str1; + this.number1 = number1; + } - public BaseEntity(String str1, Integer number1) { - this.str1 = str1; - this.number1 = number1; - } + public BaseEntity(String str1, Integer number1) { + this.str1 = str1; + this.number1 = number1; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getStr1() { - return str1; - } + public String getStr1() { + return str1; + } - public void setStr1(String str1) { - this.str1 = str1; - } + public void setStr1(String str1) { + this.str1 = str1; + } - public Integer getNumber1() { - return number1; - } + public Integer getNumber1() { + return number1; + } - public void setNumber1(Integer number1) { - this.number1 = number1; - } + public void setNumber1(Integer number1) { + this.number1 = number1; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof BaseEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof BaseEntity) ) { + return false; + } - BaseEntity that = (BaseEntity) o; + BaseEntity that = (BaseEntity) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; - if (number1 != null ? !number1.equals(that.number1) : that.number1 != null) return false; - if (str1 != null ? !str1.equals(that.str1) : that.str1 != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } + if ( number1 != null ? !number1.equals( that.number1 ) : that.number1 != null ) { + return false; + } + if ( str1 != null ? !str1.equals( that.str1 ) : that.str1 != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (str1 != null ? str1.hashCode() : 0); - result = 31 * result + (number1 != null ? number1.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (str1 != null ? str1.hashCode() : 0); + result = 31 * result + (number1 != null ? number1.hashCode() : 0); + return result; + } - public String toString() { - return "BaseEntity(id = " + id + ", str1 = " + str1 + ", number1 = " + number1 + ")"; - } + public String toString() { + return "BaseEntity(id = " + id + ", str1 = " + str1 + ", number1 = " + number1 + ")"; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/ClassOverrideAuditedEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/ClassOverrideAuditedEntity.java index 1ba841cc08..9b200b27e3 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/ClassOverrideAuditedEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/ClassOverrideAuditedEntity.java @@ -14,52 +14,60 @@ import org.hibernate.envers.Audited; @Table(name = "ClassOverrideAudited") @AuditOverrides({@AuditOverride(forClass = NotAuditedBaseEntity.class, isAudited = true)}) public class ClassOverrideAuditedEntity extends NotAuditedBaseEntity { - @Audited - private String str2; + @Audited + private String str2; - public ClassOverrideAuditedEntity() { - } + public ClassOverrideAuditedEntity() { + } - public ClassOverrideAuditedEntity(String str1, Integer number, String str2) { - super(str1, number); - this.str2 = str2; - } + public ClassOverrideAuditedEntity(String str1, Integer number, String str2) { + super( str1, number ); + this.str2 = str2; + } - public ClassOverrideAuditedEntity(String str1, Integer number, Integer id, String str2) { - super(str1, number, id); - this.str2 = str2; - } + public ClassOverrideAuditedEntity(String str1, Integer number, Integer id, String str2) { + super( str1, number, id ); + this.str2 = str2; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ClassOverrideAuditedEntity)) return false; - if (!super.equals(o)) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ClassOverrideAuditedEntity) ) { + return false; + } + if ( !super.equals( o ) ) { + return false; + } - ClassOverrideAuditedEntity that = (ClassOverrideAuditedEntity) o; + ClassOverrideAuditedEntity that = (ClassOverrideAuditedEntity) o; - if (str2 != null ? !str2.equals(that.str2) : that.str2 != null) return false; + if ( str2 != null ? !str2.equals( that.str2 ) : that.str2 != null ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - int result = super.hashCode(); - result = 31 * result + (str2 != null ? str2.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (str2 != null ? str2.hashCode() : 0); + return result; + } - @Override - public String toString() { - return "ClassOverrideAuditedEntity(" + super.toString() + ", str2 = " + str2 + ")"; - } + @Override + public String toString() { + return "ClassOverrideAuditedEntity(" + super.toString() + ", str2 = " + str2 + ")"; + } - public String getStr2() { - return str2; - } + public String getStr2() { + return str2; + } - public void setStr2(String str2) { - this.str2 = str2; - } + public void setStr2(String str2) { + this.str2 = str2; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/ClassOverrideNotAuditedEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/ClassOverrideNotAuditedEntity.java index d31cbc0773..32803c0b17 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/ClassOverrideNotAuditedEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/ClassOverrideNotAuditedEntity.java @@ -14,52 +14,60 @@ import org.hibernate.envers.Audited; @Table(name = "ClassOverrideNotAudited") @AuditOverrides({@AuditOverride(forClass = AuditedBaseEntity.class, isAudited = false)}) public class ClassOverrideNotAuditedEntity extends AuditedBaseEntity { - @Audited - private String str2; + @Audited + private String str2; - public ClassOverrideNotAuditedEntity() { - } + public ClassOverrideNotAuditedEntity() { + } - public ClassOverrideNotAuditedEntity(String str1, Integer number, String str2) { - super(str1, number); - this.str2 = str2; - } + public ClassOverrideNotAuditedEntity(String str1, Integer number, String str2) { + super( str1, number ); + this.str2 = str2; + } - public ClassOverrideNotAuditedEntity(String str1, Integer number, Integer id, String str2) { - super(str1, number, id); - this.str2 = str2; - } + public ClassOverrideNotAuditedEntity(String str1, Integer number, Integer id, String str2) { + super( str1, number, id ); + this.str2 = str2; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ClassOverrideNotAuditedEntity)) return false; - if (!super.equals(o)) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ClassOverrideNotAuditedEntity) ) { + return false; + } + if ( !super.equals( o ) ) { + return false; + } - ClassOverrideNotAuditedEntity that = (ClassOverrideNotAuditedEntity) o; + ClassOverrideNotAuditedEntity that = (ClassOverrideNotAuditedEntity) o; - if (str2 != null ? !str2.equals(that.str2) : that.str2 != null) return false; + if ( str2 != null ? !str2.equals( that.str2 ) : that.str2 != null ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - int result = super.hashCode(); - result = 31 * result + (str2 != null ? str2.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (str2 != null ? str2.hashCode() : 0); + return result; + } - @Override - public String toString() { - return "ClassOverrideNotAuditedEntity(" + super.toString() + ", str2 = " + str2 + ")"; - } + @Override + public String toString() { + return "ClassOverrideNotAuditedEntity(" + super.toString() + ", str2 = " + str2 + ")"; + } - public String getStr2() { - return str2; - } + public String getStr2() { + return str2; + } - public void setStr2(String str2) { - this.str2 = str2; - } + public void setStr2(String str2) { + this.str2 = str2; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/ExtendedBaseEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/ExtendedBaseEntity.java index 7be515cb33..bda036c637 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/ExtendedBaseEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/ExtendedBaseEntity.java @@ -11,70 +11,82 @@ import org.hibernate.envers.NotAudited; * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ @MappedSuperclass -@AuditOverrides({@AuditOverride(forClass = BaseEntity.class, name = "str1", isAudited = false), - @AuditOverride(forClass = BaseEntity.class, name = "number1", isAudited = true)}) +@AuditOverrides({ + @AuditOverride(forClass = BaseEntity.class, name = "str1", isAudited = false), + @AuditOverride(forClass = BaseEntity.class, name = "number1", isAudited = true) + }) public class ExtendedBaseEntity extends BaseEntity { - @Audited - private String str2; + @Audited + private String str2; - @NotAudited - private Integer number2; + @NotAudited + private Integer number2; - public ExtendedBaseEntity() { - } + public ExtendedBaseEntity() { + } - public ExtendedBaseEntity(String str1, Integer number1, Integer id, String str2, Integer number2) { - super(str1, number1, id); - this.str2 = str2; - this.number2 = number2; - } + public ExtendedBaseEntity(String str1, Integer number1, Integer id, String str2, Integer number2) { + super( str1, number1, id ); + this.str2 = str2; + this.number2 = number2; + } - public ExtendedBaseEntity(String str1, Integer number1, String str2, Integer number2) { - super(str1, number1); - this.str2 = str2; - this.number2 = number2; - } + public ExtendedBaseEntity(String str1, Integer number1, String str2, Integer number2) { + super( str1, number1 ); + this.str2 = str2; + this.number2 = number2; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ExtendedBaseEntity)) return false; - if (!super.equals(o)) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ExtendedBaseEntity) ) { + return false; + } + if ( !super.equals( o ) ) { + return false; + } - ExtendedBaseEntity that = (ExtendedBaseEntity) o; + ExtendedBaseEntity that = (ExtendedBaseEntity) o; - if (number2 != null ? !number2.equals(that.number2) : that.number2 != null) return false; - if (str2 != null ? !str2.equals(that.str2) : that.str2 != null) return false; + if ( number2 != null ? !number2.equals( that.number2 ) : that.number2 != null ) { + return false; + } + if ( str2 != null ? !str2.equals( that.str2 ) : that.str2 != null ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - int result = super.hashCode(); - result = 31 * result + (str2 != null ? str2.hashCode() : 0); - result = 31 * result + (number2 != null ? number2.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (str2 != null ? str2.hashCode() : 0); + result = 31 * result + (number2 != null ? number2.hashCode() : 0); + return result; + } - @Override - public String toString() { - return "ExtendedBaseEntity(" + super.toString() + ", str2 = " + str2 + ", number2 = " + number2 + ")"; - } + @Override + public String toString() { + return "ExtendedBaseEntity(" + super.toString() + ", str2 = " + str2 + ", number2 = " + number2 + ")"; + } - public String getStr2() { - return str2; - } + public String getStr2() { + return str2; + } - public void setStr2(String str2) { - this.str2 = str2; - } + public void setStr2(String str2) { + this.str2 = str2; + } - public Integer getNumber2() { - return number2; - } + public Integer getNumber2() { + return number2; + } - public void setNumber2(Integer number2) { - this.number2 = number2; - } + public void setNumber2(Integer number2) { + this.number2 = number2; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/MixedOverrideEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/MixedOverrideEntity.java index 415bcf34f1..e3f6e20d8e 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/MixedOverrideEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/MixedOverrideEntity.java @@ -11,54 +11,64 @@ import org.hibernate.envers.Audited; */ @Entity @Audited -@AuditOverrides({@AuditOverride(forClass = AuditedBaseEntity.class, isAudited = false), - @AuditOverride(forClass = AuditedBaseEntity.class, name = "number1", isAudited = true)}) +@AuditOverrides({ + @AuditOverride(forClass = AuditedBaseEntity.class, isAudited = false), + @AuditOverride(forClass = AuditedBaseEntity.class, name = "number1", isAudited = true) + }) public class MixedOverrideEntity extends AuditedBaseEntity { - private String str2; + private String str2; - public MixedOverrideEntity() { - } + public MixedOverrideEntity() { + } - public MixedOverrideEntity(String str1, Integer number, String str2) { - super(str1, number); - this.str2 = str2; - } + public MixedOverrideEntity(String str1, Integer number, String str2) { + super( str1, number ); + this.str2 = str2; + } - public MixedOverrideEntity(String str1, Integer number, Integer id, String str2) { - super(str1, number, id); - this.str2 = str2; - } + public MixedOverrideEntity(String str1, Integer number, Integer id, String str2) { + super( str1, number, id ); + this.str2 = str2; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof MixedOverrideEntity)) return false; - if (!super.equals(o)) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof MixedOverrideEntity) ) { + return false; + } + if ( !super.equals( o ) ) { + return false; + } - MixedOverrideEntity that = (MixedOverrideEntity) o; + MixedOverrideEntity that = (MixedOverrideEntity) o; - if (str2 != null ? !str2.equals(that.str2) : that.str2 != null) return false; + if ( str2 != null ? !str2.equals( that.str2 ) : that.str2 != null ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - int result = super.hashCode(); - result = 31 * result + (str2 != null ? str2.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (str2 != null ? str2.hashCode() : 0); + return result; + } - @Override - public String toString() { - return "MixedOverrideEntity(" + super.toString() + ", str2 = " + str2 + ")"; - } + @Override + public String toString() { + return "MixedOverrideEntity(" + super.toString() + ", str2 = " + str2 + ")"; + } - public String getStr2() { - return str2; - } + public String getStr2() { + return str2; + } - public void setStr2(String str2) { - this.str2 = str2; - } + public void setStr2(String str2) { + this.str2 = str2; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/MixedOverrideTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/MixedOverrideTest.java index 97d09f4eee..169d0afb68 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/MixedOverrideTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/MixedOverrideTest.java @@ -2,57 +2,60 @@ package org.hibernate.envers.test.integration.superclass.auditoverride; import javax.persistence.EntityManager; -import org.junit.Assert; -import org.junit.Test; - import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.mapping.Column; import org.hibernate.mapping.Table; + +import org.junit.Assert; +import org.junit.Test; + import org.hibernate.testing.TestForIssue; /** * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ @TestForIssue(jiraKey = "HHH-4439") -public class MixedOverrideTest extends BaseEnversJPAFunctionalTestCase { - private Integer mixedEntityId = null; - private Table mixedTable = null; +public class MixedOverrideTest extends BaseEnversJPAFunctionalTestCase { + private Integer mixedEntityId = null; + private Table mixedTable = null; @Override protected Class[] getAnnotatedClasses() { - return new Class[] { MixedOverrideEntity.class }; - } + return new Class[] {MixedOverrideEntity.class}; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - // Revision 1 - em.getTransaction().begin(); - MixedOverrideEntity mixedEntity = new MixedOverrideEntity("data 1", 1, "data 2"); - em.persist(mixedEntity); - em.getTransaction().commit(); - mixedEntityId = mixedEntity.getId(); + // Revision 1 + em.getTransaction().begin(); + MixedOverrideEntity mixedEntity = new MixedOverrideEntity( "data 1", 1, "data 2" ); + em.persist( mixedEntity ); + em.getTransaction().commit(); + mixedEntityId = mixedEntity.getId(); - mixedTable = getCfg().getClassMapping("org.hibernate.envers.test.integration.superclass.auditoverride.MixedOverrideEntity_AUD").getTable(); - } + mixedTable = getCfg().getClassMapping( + "org.hibernate.envers.test.integration.superclass.auditoverride.MixedOverrideEntity_AUD" + ).getTable(); + } - @Test - public void testAuditedProperty() { - Assert.assertNotNull(mixedTable.getColumn(new Column("number1"))); - Assert.assertNotNull(mixedTable.getColumn(new Column("str2"))); - } + @Test + public void testAuditedProperty() { + Assert.assertNotNull( mixedTable.getColumn( new Column( "number1" ) ) ); + Assert.assertNotNull( mixedTable.getColumn( new Column( "str2" ) ) ); + } - @Test - public void testNotAuditedProperty() { - Assert.assertNull(mixedTable.getColumn(new Column("str1"))); - } + @Test + public void testNotAuditedProperty() { + Assert.assertNull( mixedTable.getColumn( new Column( "str1" ) ) ); + } - @Test - public void testHistoryOfMixedEntity() { - MixedOverrideEntity ver1 = new MixedOverrideEntity(null, 1, mixedEntityId, "data 2"); - Assert.assertEquals(ver1, getAuditReader().find(MixedOverrideEntity.class, mixedEntityId, 1)); - } + @Test + public void testHistoryOfMixedEntity() { + MixedOverrideEntity ver1 = new MixedOverrideEntity( null, 1, mixedEntityId, "data 2" ); + Assert.assertEquals( ver1, getAuditReader().find( MixedOverrideEntity.class, mixedEntityId, 1 ) ); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/NotAuditedBaseEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/NotAuditedBaseEntity.java index e9fefa4cb8..85c9b833f1 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/NotAuditedBaseEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/NotAuditedBaseEntity.java @@ -1,83 +1,93 @@ package org.hibernate.envers.test.integration.superclass.auditoverride; -import java.io.Serializable; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.MappedSuperclass; +import java.io.Serializable; /** * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ @MappedSuperclass public class NotAuditedBaseEntity implements Serializable { - @Id - @GeneratedValue - private Integer id; + @Id + @GeneratedValue + private Integer id; - private String str1; + private String str1; - private Integer number1; + private Integer number1; - public NotAuditedBaseEntity() { - } + public NotAuditedBaseEntity() { + } - public NotAuditedBaseEntity(String str1, Integer number1, Integer id) { - this.id = id; - this.str1 = str1; - this.number1 = number1; - } + public NotAuditedBaseEntity(String str1, Integer number1, Integer id) { + this.id = id; + this.str1 = str1; + this.number1 = number1; + } - public NotAuditedBaseEntity(String str1, Integer number1) { - this.str1 = str1; - this.number1 = number1; - } + public NotAuditedBaseEntity(String str1, Integer number1) { + this.str1 = str1; + this.number1 = number1; + } - public Integer getId() { - return id; - } + public Integer getId() { + return id; + } - public void setId(Integer id) { - this.id = id; - } + public void setId(Integer id) { + this.id = id; + } - public String getStr1() { - return str1; - } + public String getStr1() { + return str1; + } - public void setStr1(String str1) { - this.str1 = str1; - } + public void setStr1(String str1) { + this.str1 = str1; + } - public Integer getNumber1() { - return number1; - } + public Integer getNumber1() { + return number1; + } - public void setNumber1(Integer number1) { - this.number1 = number1; - } + public void setNumber1(Integer number1) { + this.number1 = number1; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof NotAuditedBaseEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof NotAuditedBaseEntity) ) { + return false; + } - NotAuditedBaseEntity that = (NotAuditedBaseEntity) o; + NotAuditedBaseEntity that = (NotAuditedBaseEntity) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; - if (number1 != null ? !number1.equals(that.number1) : that.number1 != null) return false; - if (str1 != null ? !str1.equals(that.str1) : that.str1 != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } + if ( number1 != null ? !number1.equals( that.number1 ) : that.number1 != null ) { + return false; + } + if ( str1 != null ? !str1.equals( that.str1 ) : that.str1 != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (str1 != null ? str1.hashCode() : 0); - result = 31 * result + (number1 != null ? number1.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (str1 != null ? str1.hashCode() : 0); + result = 31 * result + (number1 != null ? number1.hashCode() : 0); + return result; + } - public String toString() { - return "NotAuditedBaseEntity(id = " + id + ", str1 = " + str1 + ", number1 = " + number1 + ")"; - } + public String toString() { + return "NotAuditedBaseEntity(id = " + id + ", str1 = " + str1 + ", number1 = " + number1 + ")"; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/PropertyOverrideEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/PropertyOverrideEntity.java index 1ad72ced95..02d03b8b28 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/PropertyOverrideEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/PropertyOverrideEntity.java @@ -11,54 +11,64 @@ import org.hibernate.envers.Audited; */ @Entity @Audited -@AuditOverrides({@AuditOverride(forClass = BaseEntity.class, name = "str1", isAudited = false), - @AuditOverride(forClass = BaseEntity.class, name = "number1", isAudited = true)}) +@AuditOverrides({ + @AuditOverride(forClass = BaseEntity.class, name = "str1", isAudited = false), + @AuditOverride(forClass = BaseEntity.class, name = "number1", isAudited = true) + }) public class PropertyOverrideEntity extends BaseEntity { - private String str2; + private String str2; - public PropertyOverrideEntity() { - } + public PropertyOverrideEntity() { + } - public PropertyOverrideEntity(String str1, Integer number1, String str2) { - super(str1, number1); - this.str2 = str2; - } + public PropertyOverrideEntity(String str1, Integer number1, String str2) { + super( str1, number1 ); + this.str2 = str2; + } - public PropertyOverrideEntity(String str1, Integer number1, Integer id, String str2) { - super(str1, number1, id); - this.str2 = str2; - } + public PropertyOverrideEntity(String str1, Integer number1, Integer id, String str2) { + super( str1, number1, id ); + this.str2 = str2; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof PropertyOverrideEntity)) return false; - if (!super.equals(o)) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof PropertyOverrideEntity) ) { + return false; + } + if ( !super.equals( o ) ) { + return false; + } - PropertyOverrideEntity that = (PropertyOverrideEntity) o; + PropertyOverrideEntity that = (PropertyOverrideEntity) o; - if (str2 != null ? !str2.equals(that.str2) : that.str2 != null) return false; + if ( str2 != null ? !str2.equals( that.str2 ) : that.str2 != null ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - int result = super.hashCode(); - result = 31 * result + (str2 != null ? str2.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (str2 != null ? str2.hashCode() : 0); + return result; + } - @Override - public String toString() { - return "PropertyOverrideEntity(" + super.toString() + ", str2 = " + str2 + ")"; - } + @Override + public String toString() { + return "PropertyOverrideEntity(" + super.toString() + ", str2 = " + str2 + ")"; + } - public String getStr2() { - return str2; - } + public String getStr2() { + return str2; + } - public void setStr2(String str2) { - this.str2 = str2; - } + public void setStr2(String str2) { + this.str2 = str2; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/TransitiveOverrideEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/TransitiveOverrideEntity.java index 9675ee8608..a5161c7998 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/TransitiveOverrideEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditoverride/TransitiveOverrideEntity.java @@ -11,54 +11,70 @@ import org.hibernate.envers.Audited; */ @Entity @Audited -@AuditOverrides({@AuditOverride(forClass = BaseEntity.class, name = "str1", isAudited = true), - @AuditOverride(forClass = ExtendedBaseEntity.class, name = "number2", isAudited = true)}) +@AuditOverrides({ + @AuditOverride(forClass = BaseEntity.class, name = "str1", isAudited = true), + @AuditOverride(forClass = ExtendedBaseEntity.class, name = "number2", isAudited = true) + }) public class TransitiveOverrideEntity extends ExtendedBaseEntity { - private String str3; + private String str3; - public TransitiveOverrideEntity() { - } + public TransitiveOverrideEntity() { + } - public TransitiveOverrideEntity(String str1, Integer number1, Integer id, String str2, Integer number2, String str3) { - super(str1, number1, id, str2, number2); - this.str3 = str3; - } + public TransitiveOverrideEntity( + String str1, + Integer number1, + Integer id, + String str2, + Integer number2, + String str3) { + super( str1, number1, id, str2, number2 ); + this.str3 = str3; + } - public TransitiveOverrideEntity(String str1, Integer number1, String str2, Integer number2, String str3) { - super(str1, number1, str2, number2); - this.str3 = str3; - } + public TransitiveOverrideEntity(String str1, Integer number1, String str2, Integer number2, String str3) { + super( str1, number1, str2, number2 ); + this.str3 = str3; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof TransitiveOverrideEntity)) return false; - if (!super.equals(o)) return false; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof TransitiveOverrideEntity) ) { + return false; + } + if ( !super.equals( o ) ) { + return false; + } - TransitiveOverrideEntity that = (TransitiveOverrideEntity) o; + TransitiveOverrideEntity that = (TransitiveOverrideEntity) o; - if (str3 != null ? !str3.equals(that.str3) : that.str3 != null) return false; + if ( str3 != null ? !str3.equals( that.str3 ) : that.str3 != null ) { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() { - int result = super.hashCode(); - result = 31 * result + (str3 != null ? str3.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (str3 != null ? str3.hashCode() : 0); + return result; + } - @Override - public String toString() { - return "TransitiveOverrideEntity(" + super.toString() + ", str3 = " + str3 + ")"; - } + @Override + public String toString() { + return "TransitiveOverrideEntity(" + super.toString() + ", str3 = " + str3 + ")"; + } - public String getStr3() { - return str3; - } + public String getStr3() { + return str3; + } - public void setStr3(String str3) { - this.str3 = str3; - } + public void setStr3(String str3) { + this.str3 = str3; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/BabyCompleteEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/BabyCompleteEntity.java index f6e2366772..05d02f744c 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/BabyCompleteEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/BabyCompleteEntity.java @@ -11,43 +11,58 @@ import org.hibernate.envers.test.entities.StrIntTestEntity; @Entity @Audited(auditParents = {MappedParentEntity.class}) public class BabyCompleteEntity extends ChildCompleteEntity { - private String baby; + private String baby; - public BabyCompleteEntity() { - } + public BabyCompleteEntity() { + } - public BabyCompleteEntity(Long id, String grandparent, String notAudited, String parent, String child, StrIntTestEntity relation, String baby) { - super(id, grandparent, notAudited, parent, child, relation); - this.baby = baby; - } + public BabyCompleteEntity( + Long id, + String grandparent, + String notAudited, + String parent, + String child, + StrIntTestEntity relation, + String baby) { + super( id, grandparent, notAudited, parent, child, relation ); + this.baby = baby; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof BabyCompleteEntity)) return false; - if (!super.equals(o)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof BabyCompleteEntity) ) { + return false; + } + if ( !super.equals( o ) ) { + return false; + } - BabyCompleteEntity that = (BabyCompleteEntity) o; + BabyCompleteEntity that = (BabyCompleteEntity) o; - if (baby != null ? !baby.equals(that.baby) : that.baby != null) return false; + if ( baby != null ? !baby.equals( that.baby ) : that.baby != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result = super.hashCode(); - result = 31 * result + (baby != null ? baby.hashCode() : 0); - return result; - } + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (baby != null ? baby.hashCode() : 0); + return result; + } - public String toString() { - return "BabyCompleteEntity(" + super.toString() + ", baby = " + baby + ")"; - } + public String toString() { + return "BabyCompleteEntity(" + super.toString() + ", baby = " + baby + ")"; + } - public String getBaby() { - return baby; - } + public String getBaby() { + return baby; + } - public void setBaby(String baby) { - this.baby = baby; - } + public void setBaby(String baby) { + this.baby = baby; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/ChildCompleteEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/ChildCompleteEntity.java index f0f3e157f6..ea84df73da 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/ChildCompleteEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/ChildCompleteEntity.java @@ -11,44 +11,58 @@ import org.hibernate.envers.test.entities.StrIntTestEntity; @MappedSuperclass @Audited(auditParents = {MappedGrandparentEntity.class}) public class ChildCompleteEntity extends MappedParentEntity { - private String child; + private String child; - public ChildCompleteEntity() { - super(null, null, null, null, null); - } + public ChildCompleteEntity() { + super( null, null, null, null, null ); + } - public ChildCompleteEntity(Long id, String grandparent, String notAudited, String parent, String child, StrIntTestEntity relation) { - super(id, grandparent, notAudited, parent, relation); - this.child = child; - } + public ChildCompleteEntity( + Long id, + String grandparent, + String notAudited, + String parent, + String child, + StrIntTestEntity relation) { + super( id, grandparent, notAudited, parent, relation ); + this.child = child; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ChildCompleteEntity)) return false; - if (!super.equals(o)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ChildCompleteEntity) ) { + return false; + } + if ( !super.equals( o ) ) { + return false; + } - ChildCompleteEntity that = (ChildCompleteEntity) o; + ChildCompleteEntity that = (ChildCompleteEntity) o; - if (child != null ? !child.equals(that.child) : that.child != null) return false; + if ( child != null ? !child.equals( that.child ) : that.child != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result = super.hashCode(); - result = 31 * result + (child != null ? child.hashCode() : 0); - return result; - } + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (child != null ? child.hashCode() : 0); + return result; + } - public String toString() { - return "ChildCompleteEntity(" + super.toString() + ", child = " + child + ")"; - } + public String toString() { + return "ChildCompleteEntity(" + super.toString() + ", child = " + child + ")"; + } - public String getChild() { - return child; - } + public String getChild() { + return child; + } - public void setChild(String child) { - this.child = child; - } + public void setChild(String child) { + this.child = child; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/ChildMultipleParentsEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/ChildMultipleParentsEntity.java index 22f88e9820..fa5ec71c04 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/ChildMultipleParentsEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/ChildMultipleParentsEntity.java @@ -11,45 +11,59 @@ import org.hibernate.envers.test.entities.StrIntTestEntity; @Entity @Audited(auditParents = {MappedParentEntity.class, MappedGrandparentEntity.class}) public class ChildMultipleParentsEntity extends MappedParentEntity { - private String child; + private String child; - public ChildMultipleParentsEntity() { - super(null, null, null, null, null); - } + public ChildMultipleParentsEntity() { + super( null, null, null, null, null ); + } - public ChildMultipleParentsEntity(Long id, String grandparent, String notAudited, String parent, String child, StrIntTestEntity relation) { - super(id, grandparent, notAudited, parent, relation); - this.child = child; - } + public ChildMultipleParentsEntity( + Long id, + String grandparent, + String notAudited, + String parent, + String child, + StrIntTestEntity relation) { + super( id, grandparent, notAudited, parent, relation ); + this.child = child; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ChildMultipleParentsEntity)) return false; - if (!super.equals(o)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ChildMultipleParentsEntity) ) { + return false; + } + if ( !super.equals( o ) ) { + return false; + } - ChildMultipleParentsEntity that = (ChildMultipleParentsEntity) o; + ChildMultipleParentsEntity that = (ChildMultipleParentsEntity) o; - if (child != null ? !child.equals(that.child) : that.child != null) return false; + if ( child != null ? !child.equals( that.child ) : that.child != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result = super.hashCode(); - result = 31 * result + (child != null ? child.hashCode() : 0); - return result; - } + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (child != null ? child.hashCode() : 0); + return result; + } - public String toString() { - return "ChildMultipleParentsEntity(" + super.toString() + ", child = " + child + ")"; - } + public String toString() { + return "ChildMultipleParentsEntity(" + super.toString() + ", child = " + child + ")"; + } - public String getChild() { - return child; - } + public String getChild() { + return child; + } - public void setChild(String child) { - this.child = child; - } + public void setChild(String child) { + this.child = child; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/ChildSingleParentEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/ChildSingleParentEntity.java index 9f92d9b93d..25d50d616b 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/ChildSingleParentEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/ChildSingleParentEntity.java @@ -11,44 +11,58 @@ import org.hibernate.envers.test.entities.StrIntTestEntity; @Entity @Audited(auditParents = {MappedGrandparentEntity.class}) public class ChildSingleParentEntity extends MappedParentEntity { - private String child; + private String child; - public ChildSingleParentEntity() { - super(null, null, null, null, null); - } + public ChildSingleParentEntity() { + super( null, null, null, null, null ); + } - public ChildSingleParentEntity(Long id, String grandparent, String notAudited, String parent, String child, StrIntTestEntity relation) { - super(id, grandparent, notAudited, parent, relation); - this.child = child; - } + public ChildSingleParentEntity( + Long id, + String grandparent, + String notAudited, + String parent, + String child, + StrIntTestEntity relation) { + super( id, grandparent, notAudited, parent, relation ); + this.child = child; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ChildSingleParentEntity)) return false; - if (!super.equals(o)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ChildSingleParentEntity) ) { + return false; + } + if ( !super.equals( o ) ) { + return false; + } - ChildSingleParentEntity that = (ChildSingleParentEntity) o; + ChildSingleParentEntity that = (ChildSingleParentEntity) o; - if (child != null ? !child.equals(that.child) : that.child != null) return false; + if ( child != null ? !child.equals( that.child ) : that.child != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result = super.hashCode(); - result = 31 * result + (child != null ? child.hashCode() : 0); - return result; - } + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (child != null ? child.hashCode() : 0); + return result; + } - public String toString() { - return "ChildSingleParentEntity(" + super.toString() + ", child = " + child + ")"; - } + public String toString() { + return "ChildSingleParentEntity(" + super.toString() + ", child = " + child + ")"; + } - public String getChild() { - return child; - } + public String getChild() { + return child; + } - public void setChild(String child) { - this.child = child; - } + public void setChild(String child) { + this.child = child; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/ExplicitTransitiveChildEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/ExplicitTransitiveChildEntity.java index bc5d1ddb1f..05586965a3 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/ExplicitTransitiveChildEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/ExplicitTransitiveChildEntity.java @@ -12,44 +12,52 @@ import org.hibernate.envers.Audited; @Table(name = "ExplicitTransitiveChild") @Audited(auditParents = {TransitiveParentEntity.class}) public class ExplicitTransitiveChildEntity extends TransitiveParentEntity { - private String child; + private String child; - public ExplicitTransitiveChildEntity() { - super(null, null, null, null); - } + public ExplicitTransitiveChildEntity() { + super( null, null, null, null ); + } - public ExplicitTransitiveChildEntity(Long id, String grandparent, String notAudited, String parent, String child) { - super(id, grandparent, notAudited, parent); - this.child = child; - } + public ExplicitTransitiveChildEntity(Long id, String grandparent, String notAudited, String parent, String child) { + super( id, grandparent, notAudited, parent ); + this.child = child; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ExplicitTransitiveChildEntity)) return false; - if (!super.equals(o)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ExplicitTransitiveChildEntity) ) { + return false; + } + if ( !super.equals( o ) ) { + return false; + } - ExplicitTransitiveChildEntity that = (ExplicitTransitiveChildEntity) o; + ExplicitTransitiveChildEntity that = (ExplicitTransitiveChildEntity) o; - if (child != null ? !child.equals(that.child) : that.child != null) return false; + if ( child != null ? !child.equals( that.child ) : that.child != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result = super.hashCode(); - result = 31 * result + (child != null ? child.hashCode() : 0); - return result; - } + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (child != null ? child.hashCode() : 0); + return result; + } - public String toString() { - return "ExplicitTransitiveChildEntity(" + super.toString() + ", child = " + child + ")"; - } + public String toString() { + return "ExplicitTransitiveChildEntity(" + super.toString() + ", child = " + child + ")"; + } - public String getChild() { - return child; - } + public String getChild() { + return child; + } - public void setChild(String child) { - this.child = child; - } + public void setChild(String child) { + this.child = child; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/ImplicitTransitiveChildEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/ImplicitTransitiveChildEntity.java index ef46f0404b..b8247eb7f5 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/ImplicitTransitiveChildEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/ImplicitTransitiveChildEntity.java @@ -12,44 +12,52 @@ import org.hibernate.envers.Audited; @Table(name = "ImplicitTransitiveChild") @Audited public class ImplicitTransitiveChildEntity extends TransitiveParentEntity { - private String child; + private String child; - public ImplicitTransitiveChildEntity() { - super(null, null, null, null); - } + public ImplicitTransitiveChildEntity() { + super( null, null, null, null ); + } - public ImplicitTransitiveChildEntity(Long id, String grandparent, String notAudited, String parent, String child) { - super(id, grandparent, notAudited, parent); - this.child = child; - } + public ImplicitTransitiveChildEntity(Long id, String grandparent, String notAudited, String parent, String child) { + super( id, grandparent, notAudited, parent ); + this.child = child; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ImplicitTransitiveChildEntity)) return false; - if (!super.equals(o)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ImplicitTransitiveChildEntity) ) { + return false; + } + if ( !super.equals( o ) ) { + return false; + } - ImplicitTransitiveChildEntity that = (ImplicitTransitiveChildEntity) o; + ImplicitTransitiveChildEntity that = (ImplicitTransitiveChildEntity) o; - if (child != null ? !child.equals(that.child) : that.child != null) return false; + if ( child != null ? !child.equals( that.child ) : that.child != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result = super.hashCode(); - result = 31 * result + (child != null ? child.hashCode() : 0); - return result; - } + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (child != null ? child.hashCode() : 0); + return result; + } - public String toString() { - return "ImplicitTransitiveChildEntity(" + super.toString() + ", child = " + child + ")"; - } + public String toString() { + return "ImplicitTransitiveChildEntity(" + super.toString() + ", child = " + child + ")"; + } - public String getChild() { - return child; - } + public String getChild() { + return child; + } - public void setChild(String child) { - this.child = child; - } + public void setChild(String child) { + this.child = child; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/MappedGrandparentEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/MappedGrandparentEntity.java index 642347ecd0..13b520a248 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/MappedGrandparentEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/MappedGrandparentEntity.java @@ -10,65 +10,75 @@ import org.hibernate.envers.NotAudited; */ @MappedSuperclass public class MappedGrandparentEntity { - @Id - private Long id; + @Id + private Long id; - private String grandparent; + private String grandparent; - @NotAudited - private String notAudited; + @NotAudited + private String notAudited; - public MappedGrandparentEntity(Long id, String grandparent, String notAudited) { - this.id = id; - this.grandparent = grandparent; - this.notAudited = notAudited; - } + public MappedGrandparentEntity(Long id, String grandparent, String notAudited) { + this.id = id; + this.grandparent = grandparent; + this.notAudited = notAudited; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof MappedGrandparentEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof MappedGrandparentEntity) ) { + return false; + } - MappedGrandparentEntity that = (MappedGrandparentEntity) o; + MappedGrandparentEntity that = (MappedGrandparentEntity) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; - if (grandparent != null ? !grandparent.equals(that.grandparent) : that.grandparent != null) return false; - if (notAudited != null ? !notAudited.equals(that.notAudited) : that.notAudited != null) return false; + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } + if ( grandparent != null ? !grandparent.equals( that.grandparent ) : that.grandparent != null ) { + return false; + } + if ( notAudited != null ? !notAudited.equals( that.notAudited ) : that.notAudited != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result = (id != null ? id.hashCode() : 0); - result = 31 * result + (grandparent != null ? grandparent.hashCode() : 0); - result = 31 * result + (notAudited != null ? notAudited.hashCode() : 0); - return result; - } + public int hashCode() { + int result = (id != null ? id.hashCode() : 0); + result = 31 * result + (grandparent != null ? grandparent.hashCode() : 0); + result = 31 * result + (notAudited != null ? notAudited.hashCode() : 0); + return result; + } - public String toString() { - return "MappedGrandparentEntity(id = " + id + ", grandparent = " + grandparent + ", notAudited = " + notAudited + ")"; - } + public String toString() { + return "MappedGrandparentEntity(id = " + id + ", grandparent = " + grandparent + ", notAudited = " + notAudited + ")"; + } - public Long getId() { - return id; - } + public Long getId() { + return id; + } - public void setId(Long id) { - this.id = id; - } + public void setId(Long id) { + this.id = id; + } - public String getGrandparent() { - return grandparent; - } + public String getGrandparent() { + return grandparent; + } - public void setGrandparent(String grandparent) { - this.grandparent = grandparent; - } + public void setGrandparent(String grandparent) { + this.grandparent = grandparent; + } - public String getNotAudited() { - return notAudited; - } + public String getNotAudited() { + return notAudited; + } - public void setNotAudited(String notAudited) { - this.notAudited = notAudited; - } + public void setNotAudited(String notAudited) { + this.notAudited = notAudited; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/MappedParentEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/MappedParentEntity.java index 33c4590220..911a44f670 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/MappedParentEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/MappedParentEntity.java @@ -10,52 +10,65 @@ import org.hibernate.envers.test.entities.StrIntTestEntity; */ @MappedSuperclass public class MappedParentEntity extends MappedGrandparentEntity { - private String parent; + private String parent; - @ManyToOne - private StrIntTestEntity relation; + @ManyToOne + private StrIntTestEntity relation; - public MappedParentEntity(Long id, String grandparent, String notAudited, String parent, StrIntTestEntity relation) { - super(id, grandparent, notAudited); - this.parent = parent; - this.relation = relation; - } + public MappedParentEntity( + Long id, + String grandparent, + String notAudited, + String parent, + StrIntTestEntity relation) { + super( id, grandparent, notAudited ); + this.parent = parent; + this.relation = relation; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof MappedParentEntity)) return false; - if (!super.equals(o)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof MappedParentEntity) ) { + return false; + } + if ( !super.equals( o ) ) { + return false; + } - MappedParentEntity that = (MappedParentEntity) o; + MappedParentEntity that = (MappedParentEntity) o; - if (parent != null ? !parent.equals(that.parent) : that.parent != null) return false; + if ( parent != null ? !parent.equals( that.parent ) : that.parent != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result = super.hashCode(); - result = 31 * result + (parent != null ? parent.hashCode() : 0); - return result; - } + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (parent != null ? parent.hashCode() : 0); + return result; + } - public String toString() { - return "MappedParentEntity(" + super.toString() + ", parent = " + parent + ", relation = " + relation + ")"; - } + public String toString() { + return "MappedParentEntity(" + super.toString() + ", parent = " + parent + ", relation = " + relation + ")"; + } - public String getParent() { - return parent; - } + public String getParent() { + return parent; + } - public void setParent(String parent) { - this.parent = parent; - } + public void setParent(String parent) { + this.parent = parent; + } - public StrIntTestEntity getRelation() { - return relation; - } + public StrIntTestEntity getRelation() { + return relation; + } - public void setRelation(StrIntTestEntity relation) { - this.relation = relation; - } + public void setRelation(StrIntTestEntity relation) { + this.relation = relation; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/MultipleAuditParentsTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/MultipleAuditParentsTest.java index 0e957d41ce..760190bd94 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/MultipleAuditParentsTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/MultipleAuditParentsTest.java @@ -1,11 +1,8 @@ package org.hibernate.envers.test.integration.superclass.auditparents; -import java.util.Set; import javax.persistence.EntityManager; import javax.persistence.MappedSuperclass; - -import org.junit.Assert; -import org.junit.Test; +import java.util.Set; import org.hibernate.envers.Audited; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; @@ -15,14 +12,18 @@ import org.hibernate.envers.test.tools.TestTools; import org.hibernate.mapping.Column; import org.hibernate.mapping.Table; +import org.junit.Assert; +import org.junit.Test; + /** * Tests mapping of child entity that declares all of its ancestors as audited with {@link Audited#auditParents()} property. * All supperclasses are marked with {@link MappedSuperclass} annotation but not {@link Audited}. + * * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public class MultipleAuditParentsTest extends BaseEnversJPAFunctionalTestCase { - private long childMultipleId = 1L; - private Integer siteMultipleId = null; + private long childMultipleId = 1L; + private Integer siteMultipleId = null; @Override protected Class[] getAnnotatedClasses() { @@ -32,44 +33,70 @@ public class MultipleAuditParentsTest extends BaseEnversJPAFunctionalTestCase { ChildMultipleParentsEntity.class, StrIntTestEntity.class }; - } + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); - // Revision 1 - em.getTransaction().begin(); - StrIntTestEntity siteMultiple = new StrIntTestEntity("data 1", 1); - em.persist(siteMultiple); - em.persist(new ChildMultipleParentsEntity(childMultipleId, "grandparent 1", "notAudited 1", "parent 1", "child 1", siteMultiple)); - em.getTransaction().commit(); - siteMultipleId = siteMultiple.getId(); - } + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); + // Revision 1 + em.getTransaction().begin(); + StrIntTestEntity siteMultiple = new StrIntTestEntity( "data 1", 1 ); + em.persist( siteMultiple ); + em.persist( + new ChildMultipleParentsEntity( + childMultipleId, + "grandparent 1", + "notAudited 1", + "parent 1", + "child 1", + siteMultiple + ) + ); + em.getTransaction().commit(); + siteMultipleId = siteMultiple.getId(); + } - @Test - public void testCreatedAuditTable() { - Set expectedColumns = TestTools.makeSet("child", "parent", "relation_id", "grandparent", "id"); - Set unexpectedColumns = TestTools.makeSet("notAudited"); + @Test + public void testCreatedAuditTable() { + Set expectedColumns = TestTools.makeSet( "child", "parent", "relation_id", "grandparent", "id" ); + Set unexpectedColumns = TestTools.makeSet( "notAudited" ); - Table table = getCfg().getClassMapping("org.hibernate.envers.test.integration.superclass.auditparents.ChildMultipleParentsEntity_AUD").getTable(); + Table table = getCfg().getClassMapping( + "org.hibernate.envers.test.integration.superclass.auditparents.ChildMultipleParentsEntity_AUD" + ).getTable(); - for (String columnName : expectedColumns) { - // Check whether expected column exists. - Assert.assertNotNull(table.getColumn(new Column(columnName))); - } - for (String columnName : unexpectedColumns) { - // Check whether unexpected column does not exist. - Assert.assertNull(table.getColumn(new Column(columnName))); - } - } + for ( String columnName : expectedColumns ) { + // Check whether expected column exists. + Assert.assertNotNull( table.getColumn( new Column( columnName ) ) ); + } + for ( String columnName : unexpectedColumns ) { + // Check whether unexpected column does not exist. + Assert.assertNull( table.getColumn( new Column( columnName ) ) ); + } + } - @Test - public void testMultipleAuditParents() { - // expectedMultipleChild.notAudited shall be null, because it is not audited. - ChildMultipleParentsEntity expectedMultipleChild = new ChildMultipleParentsEntity(childMultipleId, "grandparent 1", null, "parent 1", "child 1", new StrIntTestEntity("data 1", 1, siteMultipleId)); - ChildMultipleParentsEntity child = getAuditReader().find(ChildMultipleParentsEntity.class, childMultipleId, 1); - Assert.assertEquals(expectedMultipleChild, child); - Assert.assertEquals(expectedMultipleChild.getRelation().getId(), child.getRelation().getId()); - } + @Test + public void testMultipleAuditParents() { + // expectedMultipleChild.notAudited shall be null, because it is not audited. + ChildMultipleParentsEntity expectedMultipleChild = new ChildMultipleParentsEntity( + childMultipleId, + "grandparent 1", + null, + "parent 1", + "child 1", + new StrIntTestEntity( + "data 1", + 1, + siteMultipleId + ) + ); + ChildMultipleParentsEntity child = getAuditReader().find( + ChildMultipleParentsEntity.class, + childMultipleId, + 1 + ); + Assert.assertEquals( expectedMultipleChild, child ); + Assert.assertEquals( expectedMultipleChild.getRelation().getId(), child.getRelation().getId() ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/SingleAuditParentsTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/SingleAuditParentsTest.java index f46196e3be..57e7c38ba6 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/SingleAuditParentsTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/SingleAuditParentsTest.java @@ -1,11 +1,8 @@ package org.hibernate.envers.test.integration.superclass.auditparents; -import java.util.Set; import javax.persistence.EntityManager; import javax.persistence.MappedSuperclass; - -import org.junit.Assert; -import org.junit.Test; +import java.util.Set; import org.hibernate.envers.Audited; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; @@ -15,57 +12,84 @@ import org.hibernate.envers.test.tools.TestTools; import org.hibernate.mapping.Column; import org.hibernate.mapping.Table; +import org.junit.Assert; +import org.junit.Test; + /** * Tests mapping of child entity that declares one of its ancestors as audited with {@link Audited#auditParents()} property. * All supperclasses are marked with {@link MappedSuperclass} annotation but not {@link Audited}. + * * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public class SingleAuditParentsTest extends BaseEnversJPAFunctionalTestCase { - private long childSingleId = 1L; - private Integer siteSingleId = null; + private long childSingleId = 1L; + private Integer siteSingleId = null; - @Override - protected Class[] getAnnotatedClasses() { - return new Class[]{MappedGrandparentEntity.class, MappedParentEntity.class, ChildSingleParentEntity.class, StrIntTestEntity.class}; - } + @Override + protected Class[] getAnnotatedClasses() { + return new Class[] { + MappedGrandparentEntity.class, + MappedParentEntity.class, + ChildSingleParentEntity.class, + StrIntTestEntity.class + }; + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); - // Revision 1 - em.getTransaction().begin(); - StrIntTestEntity siteSingle = new StrIntTestEntity("data 1", 1); - em.persist(siteSingle); - em.persist(new ChildSingleParentEntity(childSingleId, "grandparent 1", "notAudited 1", "parent 1", "child 1", siteSingle)); - em.getTransaction().commit(); - siteSingleId = siteSingle.getId(); - em.close(); - } + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); + // Revision 1 + em.getTransaction().begin(); + StrIntTestEntity siteSingle = new StrIntTestEntity( "data 1", 1 ); + em.persist( siteSingle ); + em.persist( + new ChildSingleParentEntity( + childSingleId, + "grandparent 1", + "notAudited 1", + "parent 1", + "child 1", + siteSingle + ) + ); + em.getTransaction().commit(); + siteSingleId = siteSingle.getId(); + em.close(); + } - @Test - public void testCreatedAuditTable() { - Set expectedColumns = TestTools.makeSet("child", "grandparent", "id"); - Set unexpectedColumns = TestTools.makeSet("parent", "relation_id", "notAudited"); + @Test + public void testCreatedAuditTable() { + Set expectedColumns = TestTools.makeSet( "child", "grandparent", "id" ); + Set unexpectedColumns = TestTools.makeSet( "parent", "relation_id", "notAudited" ); - Table table = getCfg().getClassMapping("org.hibernate.envers.test.integration.superclass.auditparents.ChildSingleParentEntity_AUD").getTable(); + Table table = getCfg().getClassMapping( + "org.hibernate.envers.test.integration.superclass.auditparents.ChildSingleParentEntity_AUD" + ).getTable(); - for (String columnName : expectedColumns) { - // Check whether expected column exists. - Assert.assertNotNull(table.getColumn(new Column(columnName))); - } - for (String columnName : unexpectedColumns) { - // Check whether unexpected column does not exist. - Assert.assertNull(table.getColumn(new Column(columnName))); - } - } + for ( String columnName : expectedColumns ) { + // Check whether expected column exists. + Assert.assertNotNull( table.getColumn( new Column( columnName ) ) ); + } + for ( String columnName : unexpectedColumns ) { + // Check whether unexpected column does not exist. + Assert.assertNull( table.getColumn( new Column( columnName ) ) ); + } + } - @Test - public void testSingleAuditParent() { - // expectedSingleChild.parent, expectedSingleChild.relation and expectedSingleChild.notAudited shall be null, because they are not audited. - ChildSingleParentEntity expectedSingleChild = new ChildSingleParentEntity(childSingleId, "grandparent 1", null, null, "child 1", null); - ChildSingleParentEntity child = getAuditReader().find(ChildSingleParentEntity.class, childSingleId, 1); - Assert.assertEquals(expectedSingleChild, child); - Assert.assertNull(child.getRelation()); - } + @Test + public void testSingleAuditParent() { + // expectedSingleChild.parent, expectedSingleChild.relation and expectedSingleChild.notAudited shall be null, because they are not audited. + ChildSingleParentEntity expectedSingleChild = new ChildSingleParentEntity( + childSingleId, + "grandparent 1", + null, + null, + "child 1", + null + ); + ChildSingleParentEntity child = getAuditReader().find( ChildSingleParentEntity.class, childSingleId, 1 ); + Assert.assertEquals( expectedSingleChild, child ); + Assert.assertNull( child.getRelation() ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/TotalAuditParentsTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/TotalAuditParentsTest.java index 3a6950aea8..5c58a455bc 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/TotalAuditParentsTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/TotalAuditParentsTest.java @@ -1,10 +1,7 @@ package org.hibernate.envers.test.integration.superclass.auditparents; -import java.util.Set; import javax.persistence.EntityManager; - -import org.junit.Assert; -import org.junit.Test; +import java.util.Set; import org.hibernate.envers.Audited; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; @@ -14,15 +11,19 @@ import org.hibernate.envers.test.tools.TestTools; import org.hibernate.mapping.Column; import org.hibernate.mapping.Table; +import org.junit.Assert; +import org.junit.Test; + /** * Tests mapping of baby entity which declares its parent as audited with {@link Audited#auditParents()} property. * Moreover, child class (mapped superclass of baby entity) declares grandparent entity as audited. In this case all * attributes of baby class shall be audited. + * * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public class TotalAuditParentsTest extends BaseEnversJPAFunctionalTestCase { - private long babyCompleteId = 1L; - private Integer siteCompleteId = null; + private long babyCompleteId = 1L; + private Integer siteCompleteId = null; @Override protected Class[] getAnnotatedClasses() { @@ -33,44 +34,71 @@ public class TotalAuditParentsTest extends BaseEnversJPAFunctionalTestCase { ChildCompleteEntity.class, BabyCompleteEntity.class }; - } + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); - // Revision 1 - em.getTransaction().begin(); - StrIntTestEntity siteComplete = new StrIntTestEntity("data 1", 1); - em.persist(siteComplete); - em.persist(new BabyCompleteEntity(babyCompleteId, "grandparent 1", "notAudited 1", "parent 1", "child 1", siteComplete, "baby 1")); - em.getTransaction().commit(); - siteCompleteId = siteComplete.getId(); - } + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); + // Revision 1 + em.getTransaction().begin(); + StrIntTestEntity siteComplete = new StrIntTestEntity( "data 1", 1 ); + em.persist( siteComplete ); + em.persist( + new BabyCompleteEntity( + babyCompleteId, + "grandparent 1", + "notAudited 1", + "parent 1", + "child 1", + siteComplete, + "baby 1" + ) + ); + em.getTransaction().commit(); + siteCompleteId = siteComplete.getId(); + } - @Test - public void testCreatedAuditTable() { - Set expectedColumns = TestTools.makeSet("baby", "child", "parent", "relation_id", "grandparent", "id"); - Set unexpectedColumns = TestTools.makeSet("notAudited"); + @Test + public void testCreatedAuditTable() { + Set expectedColumns = TestTools.makeSet( + "baby", + "child", + "parent", + "relation_id", + "grandparent", + "id" + ); + Set unexpectedColumns = TestTools.makeSet( "notAudited" ); - Table table = getCfg().getClassMapping("org.hibernate.envers.test.integration.superclass.auditparents.BabyCompleteEntity_AUD").getTable(); + Table table = getCfg().getClassMapping( + "org.hibernate.envers.test.integration.superclass.auditparents.BabyCompleteEntity_AUD" + ).getTable(); - for (String columnName : expectedColumns) { - // Check whether expected column exists. - Assert.assertNotNull(table.getColumn(new Column(columnName))); - } - for (String columnName : unexpectedColumns) { - // Check whether unexpected column does not exist. - Assert.assertNull(table.getColumn(new Column(columnName))); - } - } + for ( String columnName : expectedColumns ) { + // Check whether expected column exists. + Assert.assertNotNull( table.getColumn( new Column( columnName ) ) ); + } + for ( String columnName : unexpectedColumns ) { + // Check whether unexpected column does not exist. + Assert.assertNull( table.getColumn( new Column( columnName ) ) ); + } + } - @Test - public void testCompleteAuditParents() { - // expectedBaby.notAudited shall be null, because it is not audited. - BabyCompleteEntity expectedBaby = new BabyCompleteEntity(babyCompleteId, "grandparent 1", null, "parent 1", "child 1", new StrIntTestEntity("data 1", 1, siteCompleteId), "baby 1"); - BabyCompleteEntity baby = getAuditReader().find(BabyCompleteEntity.class, babyCompleteId, 1); - Assert.assertEquals(expectedBaby, baby); - Assert.assertEquals(expectedBaby.getRelation().getId(), baby.getRelation().getId()); - } + @Test + public void testCompleteAuditParents() { + // expectedBaby.notAudited shall be null, because it is not audited. + BabyCompleteEntity expectedBaby = new BabyCompleteEntity( + babyCompleteId, + "grandparent 1", + null, + "parent 1", + "child 1", + new StrIntTestEntity( "data 1", 1, siteCompleteId ), + "baby 1" + ); + BabyCompleteEntity baby = getAuditReader().find( BabyCompleteEntity.class, babyCompleteId, 1 ); + Assert.assertEquals( expectedBaby, baby ); + Assert.assertEquals( expectedBaby.getRelation().getId(), baby.getRelation().getId() ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/TransitiveAuditParentsTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/TransitiveAuditParentsTest.java index 7723028c56..c6add0fe2d 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/TransitiveAuditParentsTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/TransitiveAuditParentsTest.java @@ -1,10 +1,7 @@ package org.hibernate.envers.test.integration.superclass.auditparents; -import java.util.Set; import javax.persistence.EntityManager; - -import org.junit.Assert; -import org.junit.Test; +import java.util.Set; import org.hibernate.envers.Audited; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; @@ -13,14 +10,18 @@ import org.hibernate.envers.test.tools.TestTools; import org.hibernate.mapping.Column; import org.hibernate.mapping.Table; +import org.junit.Assert; +import org.junit.Test; + /** * Tests mapping of child entity which parent declares one of its ancestors as audited with {@link Audited#auditParents()} * property. Child entity may mark explicitly its parent as audited or not. + * * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public class TransitiveAuditParentsTest extends BaseEnversJPAFunctionalTestCase { - private long childImpTransId = 1L; - private long childExpTransId = 2L; + private long childImpTransId = 1L; + private long childExpTransId = 2L; @Override protected Class[] getAnnotatedClasses() { @@ -30,57 +31,105 @@ public class TransitiveAuditParentsTest extends BaseEnversJPAFunctionalTestCase ImplicitTransitiveChildEntity.class, ExplicitTransitiveChildEntity.class }; - } + } - @Test - @Priority(10) - public void initData() { - EntityManager em = getEntityManager(); + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); - // Revision 1 - em.getTransaction().begin(); - em.persist(new ImplicitTransitiveChildEntity(childImpTransId, "grandparent 1", "notAudited 1", "parent 1", "child 1")); - em.getTransaction().commit(); + // Revision 1 + em.getTransaction().begin(); + em.persist( + new ImplicitTransitiveChildEntity( + childImpTransId, + "grandparent 1", + "notAudited 1", + "parent 1", + "child 1" + ) + ); + em.getTransaction().commit(); - // Revision 2 - em.getTransaction().begin(); - em.persist(new ExplicitTransitiveChildEntity(childExpTransId, "grandparent 2", "notAudited 2", "parent 2", "child 2")); - em.getTransaction().commit(); - } + // Revision 2 + em.getTransaction().begin(); + em.persist( + new ExplicitTransitiveChildEntity( + childExpTransId, + "grandparent 2", + "notAudited 2", + "parent 2", + "child 2" + ) + ); + em.getTransaction().commit(); + } - @Test - public void testCreatedAuditTables() { - Table explicitTransChildTable = getCfg().getClassMapping("org.hibernate.envers.test.integration.superclass.auditparents.ExplicitTransitiveChildEntity_AUD").getTable(); - checkTableColumns(TestTools.makeSet("child", "parent", "grandparent", "id"), TestTools.makeSet("notAudited"), explicitTransChildTable); + @Test + public void testCreatedAuditTables() { + Table explicitTransChildTable = getCfg().getClassMapping( + "org.hibernate.envers.test.integration.superclass.auditparents.ExplicitTransitiveChildEntity_AUD" + ).getTable(); + checkTableColumns( + TestTools.makeSet( "child", "parent", "grandparent", "id" ), + TestTools.makeSet( "notAudited" ), + explicitTransChildTable + ); - Table implicitTransChildTable = getCfg().getClassMapping("org.hibernate.envers.test.integration.superclass.auditparents.ImplicitTransitiveChildEntity_AUD").getTable(); - checkTableColumns(TestTools.makeSet("child", "parent", "grandparent", "id"), TestTools.makeSet("notAudited"), implicitTransChildTable); - } + Table implicitTransChildTable = getCfg().getClassMapping( + "org.hibernate.envers.test.integration.superclass.auditparents.ImplicitTransitiveChildEntity_AUD" + ).getTable(); + checkTableColumns( + TestTools.makeSet( "child", "parent", "grandparent", "id" ), + TestTools.makeSet( "notAudited" ), + implicitTransChildTable + ); + } - private void checkTableColumns(Set expectedColumns, Set unexpectedColumns, Table table) { - for (String columnName : expectedColumns) { - // Check whether expected column exists. - Assert.assertNotNull(table.getColumn(new Column(columnName))); - } - for (String columnName : unexpectedColumns) { - // Check whether unexpected column does not exist. - Assert.assertNull(table.getColumn(new Column(columnName))); - } - } + private void checkTableColumns(Set expectedColumns, Set unexpectedColumns, Table table) { + for ( String columnName : expectedColumns ) { + // Check whether expected column exists. + Assert.assertNotNull( table.getColumn( new Column( columnName ) ) ); + } + for ( String columnName : unexpectedColumns ) { + // Check whether unexpected column does not exist. + Assert.assertNull( table.getColumn( new Column( columnName ) ) ); + } + } - @Test - public void testImplicitTransitiveAuditParents() { - // expectedChild.notAudited shall be null, because it is not audited. - ImplicitTransitiveChildEntity expectedChild = new ImplicitTransitiveChildEntity(childImpTransId, "grandparent 1", null, "parent 1", "child 1"); - ImplicitTransitiveChildEntity child = getAuditReader().find(ImplicitTransitiveChildEntity.class, childImpTransId, 1); - Assert.assertEquals(expectedChild, child); - } + @Test + public void testImplicitTransitiveAuditParents() { + // expectedChild.notAudited shall be null, because it is not audited. + ImplicitTransitiveChildEntity expectedChild = new ImplicitTransitiveChildEntity( + childImpTransId, + "grandparent 1", + null, + "parent 1", + "child 1" + ); + ImplicitTransitiveChildEntity child = getAuditReader().find( + ImplicitTransitiveChildEntity.class, + childImpTransId, + 1 + ); + Assert.assertEquals( expectedChild, child ); + } - @Test - public void testExplicitTransitiveAuditParents() { - // expectedChild.notAudited shall be null, because it is not audited. - ExplicitTransitiveChildEntity expectedChild = new ExplicitTransitiveChildEntity(childExpTransId, "grandparent 2", null, "parent 2", "child 2"); - ExplicitTransitiveChildEntity child = getAuditReader().find(ExplicitTransitiveChildEntity.class, childExpTransId, 2); - Assert.assertEquals(expectedChild, child); - } + @Test + public void testExplicitTransitiveAuditParents() { + // expectedChild.notAudited shall be null, because it is not audited. + ExplicitTransitiveChildEntity expectedChild = new ExplicitTransitiveChildEntity( + childExpTransId, + "grandparent 2", + null, + "parent 2", + "child 2" + ); + ExplicitTransitiveChildEntity child = getAuditReader().find( + ExplicitTransitiveChildEntity.class, + childExpTransId, + 2 + ); + Assert.assertEquals( expectedChild, child ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/TransitiveParentEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/TransitiveParentEntity.java index 2047c7aa9e..198abced98 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/TransitiveParentEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/superclass/auditparents/TransitiveParentEntity.java @@ -10,44 +10,52 @@ import org.hibernate.envers.Audited; @MappedSuperclass @Audited(auditParents = {MappedGrandparentEntity.class}) public class TransitiveParentEntity extends MappedGrandparentEntity { - private String parent; + private String parent; - public TransitiveParentEntity() { - super(null, null, null); - } + public TransitiveParentEntity() { + super( null, null, null ); + } - public TransitiveParentEntity(Long id, String grandparent, String notAudited, String parent) { - super(id, grandparent, notAudited); - this.parent = parent; - } + public TransitiveParentEntity(Long id, String grandparent, String notAudited, String parent) { + super( id, grandparent, notAudited ); + this.parent = parent; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof TransitiveParentEntity)) return false; - if (!super.equals(o)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof TransitiveParentEntity) ) { + return false; + } + if ( !super.equals( o ) ) { + return false; + } - TransitiveParentEntity that = (TransitiveParentEntity) o; + TransitiveParentEntity that = (TransitiveParentEntity) o; - if (parent != null ? !parent.equals(that.parent) : that.parent != null) return false; + if ( parent != null ? !parent.equals( that.parent ) : that.parent != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result = super.hashCode(); - result = 31 * result + (parent != null ? parent.hashCode() : 0); - return result; - } + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (parent != null ? parent.hashCode() : 0); + return result; + } - public String toString() { - return "TransitiveParentEntity(" + super.toString() + ", parent = " + parent + ")"; - } + public String toString() { + return "TransitiveParentEntity(" + super.toString() + ", parent = " + parent + ")"; + } - public String getParent() { - return parent; - } + public String getParent() { + return parent; + } - public void setParent(String parent) { - this.parent = parent; - } + public void setParent(String parent) { + this.parent = parent; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/tools/SchemaExportTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/tools/SchemaExportTest.java index 130eea54a4..791ee99801 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/tools/SchemaExportTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/tools/SchemaExportTest.java @@ -2,58 +2,60 @@ package org.hibernate.envers.test.integration.tools; import java.util.Arrays; -import org.junit.Assert; -import org.junit.Test; - import org.hibernate.Session; import org.hibernate.envers.test.BaseEnversFunctionalTestCase; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrTestEntity; import org.hibernate.envers.tools.hbm2ddl.EnversSchemaGenerator; + +import org.junit.Assert; +import org.junit.Test; + import org.hibernate.testing.TestForIssue; /** * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ @TestForIssue(jiraKey = "HHH-7106") -public class SchemaExportTest extends BaseEnversFunctionalTestCase { - private Integer id = null; +public class SchemaExportTest extends BaseEnversFunctionalTestCase { + private Integer id = null; - @Override - protected Class[] getAnnotatedClasses() { - return new Class[] {StrTestEntity.class}; - } + @Override + protected Class[] getAnnotatedClasses() { + return new Class[] {StrTestEntity.class}; + } protected boolean createSchema() { // Disable schema auto generation. return false; } - @Test - @Priority(10) - public void testSchemaCreation() { - // Generate complete schema. - new EnversSchemaGenerator(configuration()).export().create( true, true ); - - // Populate database with test data. - Session session = getSession(); - session.getTransaction().begin(); - StrTestEntity entity = new StrTestEntity("data"); - session.save(entity); - session.getTransaction().commit(); - - id = entity.getId(); - } @Test - @Priority(9) - public void testAuditDataRetrieval() { - Assert.assertEquals(Arrays.asList(1), getAuditReader().getRevisions(StrTestEntity.class, id)); - Assert.assertEquals(new StrTestEntity("data", id), getAuditReader().find(StrTestEntity.class, id, 1)); - } + @Priority(10) + public void testSchemaCreation() { + // Generate complete schema. + new EnversSchemaGenerator( configuration() ).export().create( true, true ); - @Test - @Priority(8) - public void testSchemaDrop() { - new EnversSchemaGenerator(configuration()).export().drop( true, true ); - } + // Populate database with test data. + Session session = getSession(); + session.getTransaction().begin(); + StrTestEntity entity = new StrTestEntity( "data" ); + session.save( entity ); + session.getTransaction().commit(); + + id = entity.getId(); + } + + @Test + @Priority(9) + public void testAuditDataRetrieval() { + Assert.assertEquals( Arrays.asList( 1 ), getAuditReader().getRevisions( StrTestEntity.class, id ) ); + Assert.assertEquals( new StrTestEntity( "data", id ), getAuditReader().find( StrTestEntity.class, id, 1 ) ); + } + + @Test + @Priority(8) + public void testSchemaDrop() { + new EnversSchemaGenerator( configuration() ).export().drop( true, true ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/performance/AbstractEntityManagerTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/performance/AbstractEntityManagerTest.java index d388dc9ecf..e8583f53f9 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/performance/AbstractEntityManagerTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/performance/AbstractEntityManagerTest.java @@ -23,12 +23,10 @@ */ package org.hibernate.envers.test.performance; +import javax.persistence.EntityManager; import java.io.IOException; import java.util.Arrays; import java.util.Properties; -import javax.persistence.EntityManager; - -import org.junit.Before; import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl; @@ -44,6 +42,9 @@ import org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl; import org.hibernate.jpa.boot.spi.Bootstrap; import org.hibernate.jpa.internal.EntityManagerFactoryImpl; import org.hibernate.jpa.test.PersistenceUnitDescriptorAdapter; + +import org.junit.Before; + import org.hibernate.testing.AfterClassOnce; import org.hibernate.testing.BeforeClassOnce; @@ -52,63 +53,63 @@ import org.hibernate.testing.BeforeClassOnce; * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public abstract class AbstractEntityManagerTest extends AbstractEnversTest { - public static final Dialect DIALECT = Dialect.getDialect(); + public static final Dialect DIALECT = Dialect.getDialect(); private EntityManagerFactoryBuilderImpl entityManagerFactoryBuilder; private StandardServiceRegistryImpl serviceRegistry; private EntityManagerFactoryImpl emf; - private EntityManager entityManager; - private AuditReader auditReader; - private boolean audited; + private EntityManager entityManager; + private AuditReader auditReader; + private boolean audited; - public void addConfigurationProperties(Properties configuration) { + public void addConfigurationProperties(Properties configuration) { } - protected static Dialect getDialect() { - return DIALECT; - } + protected static Dialect getDialect() { + return DIALECT; + } - private void closeEntityManager() { - if (entityManager != null) { - entityManager.close(); - entityManager = null; - } - } + private void closeEntityManager() { + if ( entityManager != null ) { + entityManager.close(); + entityManager = null; + } + } - @Before - public void newEntityManager() { - closeEntityManager(); - - entityManager = emf.createEntityManager(); + @Before + public void newEntityManager() { + closeEntityManager(); - if (audited) { - auditReader = AuditReaderFactory.get(entityManager); - } - } + entityManager = emf.createEntityManager(); - @BeforeClassOnce - public void init() throws IOException { - init(true, getAuditStrategy()); - } + if ( audited ) { + auditReader = AuditReaderFactory.get( entityManager ); + } + } - protected void init(boolean audited, String auditStrategy) throws IOException { - this.audited = audited; + @BeforeClassOnce + public void init() throws IOException { + init( true, getAuditStrategy() ); + } - Properties configurationProperties = new Properties(); + protected void init(boolean audited, String auditStrategy) throws IOException { + this.audited = audited; + + Properties configurationProperties = new Properties(); configurationProperties.putAll( Environment.getProperties() ); - if (!audited) { - configurationProperties.setProperty( EnversIntegrator.AUTO_REGISTER, "false"); - } + if ( !audited ) { + configurationProperties.setProperty( EnversIntegrator.AUTO_REGISTER, "false" ); + } if ( createSchema() ) { configurationProperties.setProperty( Environment.HBM2DDL_AUTO, "create-drop" ); configurationProperties.setProperty( Environment.USE_NEW_ID_GENERATOR_MAPPINGS, "true" ); configurationProperties.setProperty( EnversSettings.USE_REVISION_ENTITY_WITH_NATIVE_ID, "false" ); } - if (auditStrategy != null && !"".equals(auditStrategy)) { - configurationProperties.setProperty("org.hibernate.envers.audit_strategy", auditStrategy); - } + if ( auditStrategy != null && !"".equals( auditStrategy ) ) { + configurationProperties.setProperty( "org.hibernate.envers.audit_strategy", auditStrategy ); + } - addConfigurationProperties( configurationProperties ); + addConfigurationProperties( configurationProperties ); configurationProperties.put( AvailableSettings.LOADED_CLASSES, Arrays.asList( getAnnotatedClasses() ) ); @@ -117,12 +118,14 @@ public abstract class AbstractEntityManagerTest extends AbstractEnversTest { configurationProperties ); - emf = (EntityManagerFactoryImpl) entityManagerFactoryBuilder.build(); + emf = (EntityManagerFactoryImpl) entityManagerFactoryBuilder.build(); - serviceRegistry = (StandardServiceRegistryImpl) emf.getSessionFactory().getServiceRegistry().getParentServiceRegistry(); + serviceRegistry = (StandardServiceRegistryImpl) emf.getSessionFactory() + .getServiceRegistry() + .getParentServiceRegistry(); - newEntityManager(); - } + newEntityManager(); + } protected Class[] getAnnotatedClasses() { return new Class[0]; @@ -137,17 +140,17 @@ public abstract class AbstractEntityManagerTest extends AbstractEnversTest { } @AfterClassOnce - public void close() { - closeEntityManager(); - emf.close(); + public void close() { + closeEntityManager(); + emf.close(); //NOTE we don't build the service registry so we don't destroy it - } + } - public EntityManager getEntityManager() { - return entityManager; - } + public EntityManager getEntityManager() { + return entityManager; + } - public AuditReader getAuditReader() { - return auditReader; - } + public AuditReader getAuditReader() { + return auditReader; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/performance/AbstractPerformanceTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/performance/AbstractPerformanceTest.java index 11b543f2e8..a0d889e6dd 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/performance/AbstractPerformanceTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/performance/AbstractPerformanceTest.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.performance; + import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -30,76 +31,76 @@ import java.util.List; * @author Adam Warski (adam at warski dot org) */ public abstract class AbstractPerformanceTest extends AbstractEntityManagerTest { - protected String getSecondsString(long milliseconds) { - return (milliseconds/1000) + "." + (milliseconds%1000); - } + protected String getSecondsString(long milliseconds) { + return (milliseconds / 1000) + "." + (milliseconds % 1000); + } - protected abstract void doTest(); + protected abstract void doTest(); - private void printResults(long unaudited, long audited) { - System.out.println("Unaudited: " + getSecondsString(unaudited)); - System.out.println(" Audited: " + getSecondsString(audited)); - System.out.println(" Delta: " + getSecondsString(audited-unaudited)); - System.out.println(" Factor: " + (double)audited/unaudited); - } + private void printResults(long unaudited, long audited) { + System.out.println( "Unaudited: " + getSecondsString( unaudited ) ); + System.out.println( " Audited: " + getSecondsString( audited ) ); + System.out.println( " Delta: " + getSecondsString( audited - unaudited ) ); + System.out.println( " Factor: " + (double) audited / unaudited ); + } - private long startTime; - private long runTotal; + private long startTime; + private long runTotal; - protected void start() { - startTime = System.currentTimeMillis(); - } + protected void start() { + startTime = System.currentTimeMillis(); + } - protected void stop() { - long stopTime = System.currentTimeMillis(); - runTotal += stopTime - startTime; - } + protected void stop() { + long stopTime = System.currentTimeMillis(); + runTotal += stopTime - startTime; + } - protected void reset() { - runTotal = 0; - } + protected void reset() { + runTotal = 0; + } - public long run(int numberOfRuns, List results) { - long total = 0; - for (int i=0; i<=numberOfRuns; i++) { - System.out.println(); - System.out.println("RUN " + i); - reset(); - doTest(); - results.add(runTotal); - total += runTotal; + public long run(int numberOfRuns, List results) { + long total = 0; + for ( int i = 0; i <= numberOfRuns; i++ ) { + System.out.println(); + System.out.println( "RUN " + i ); + reset(); + doTest(); + results.add( runTotal ); + total += runTotal; - newEntityManager(); + newEntityManager(); /*System.gc(); - System.gc(); + System.gc(); System.gc(); System.out.println(Runtime.getRuntime().freeMemory() + ", " + Runtime.getRuntime().totalMemory() + ", " + (Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory()));*/ - } + } - return total; - } + return total; + } - public void test(int numberOfRuns) throws IOException { - List unauditedRuns = new ArrayList(); - List auditedRuns = new ArrayList(); + public void test(int numberOfRuns) throws IOException { + List unauditedRuns = new ArrayList(); + List auditedRuns = new ArrayList(); - init(true, null); - long audited = run(numberOfRuns, auditedRuns); - close(); + init( true, null ); + long audited = run( numberOfRuns, auditedRuns ); + close(); - init(false, null); - long unaudited = run(numberOfRuns, unauditedRuns); - close(); + init( false, null ); + long unaudited = run( numberOfRuns, unauditedRuns ); + close(); - for (int i=0; i<=numberOfRuns; i++) { - System.out.println("RUN " + i); - printResults(unauditedRuns.get(i), auditedRuns.get(i)); - System.out.println(); - } + for ( int i = 0; i <= numberOfRuns; i++ ) { + System.out.println( "RUN " + i ); + printResults( unauditedRuns.get( i ), auditedRuns.get( i ) ); + System.out.println(); + } - System.out.println("TOTAL"); - printResults(unaudited, audited); - } + System.out.println( "TOTAL" ); + printResults( unaudited, audited ); + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/performance/AllPerformance.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/performance/AllPerformance.java index 002ec72e2b..503f3b625b 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/performance/AllPerformance.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/performance/AllPerformance.java @@ -1,11 +1,12 @@ package org.hibernate.envers.test.performance; + import java.io.IOException; public class AllPerformance { public static void main(String[] args) throws IOException { - new InsertsPerformance().test(10); - new ComplexInsertPerformance().test(10); - new UpdatesPerformance().test(10); - new InsertsOneTransactionPerformance().test(10); + new InsertsPerformance().test( 10 ); + new ComplexInsertPerformance().test( 10 ); + new UpdatesPerformance().test( 10 ); + new InsertsOneTransactionPerformance().test( 10 ); } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/performance/ComplexInsertPerformance.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/performance/ComplexInsertPerformance.java index ac0931392c..6d38bb76dc 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/performance/ComplexInsertPerformance.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/performance/ComplexInsertPerformance.java @@ -24,17 +24,17 @@ package org.hibernate.envers.test.performance; +import javax.persistence.EntityManager; import java.io.IOException; import java.util.Date; import java.util.HashSet; -import javax.persistence.EntityManager; - -import org.junit.Ignore; import org.hibernate.envers.test.performance.complex.ChildEntity1; import org.hibernate.envers.test.performance.complex.ChildEntity2; import org.hibernate.envers.test.performance.complex.RootEntity; +import org.junit.Ignore; + /** * @author Adam Warski (adam at warski dot org) */ @@ -43,64 +43,64 @@ public class ComplexInsertPerformance extends AbstractPerformanceTest { @Override protected Class[] getAnnotatedClasses() { - return new Class[] { RootEntity.class, ChildEntity1.class, ChildEntity2.class }; - } + return new Class[] {RootEntity.class, ChildEntity1.class, ChildEntity2.class}; + } - private final static int NUMBER_INSERTS = 1000; + private final static int NUMBER_INSERTS = 1000; - private long idCounter = 0; + private long idCounter = 0; - private ChildEntity2 createChildEntity2() { - ChildEntity2 ce = new ChildEntity2(); - ce.setId(idCounter++); - ce.setNumber(12345678); - ce.setData("some data, not really meaningful"); - ce.setStrings(new HashSet()); - ce.getStrings().add("aaa"); - ce.getStrings().add("bbb"); - ce.getStrings().add("ccc"); + private ChildEntity2 createChildEntity2() { + ChildEntity2 ce = new ChildEntity2(); + ce.setId( idCounter++ ); + ce.setNumber( 12345678 ); + ce.setData( "some data, not really meaningful" ); + ce.setStrings( new HashSet() ); + ce.getStrings().add( "aaa" ); + ce.getStrings().add( "bbb" ); + ce.getStrings().add( "ccc" ); - return ce; - } + return ce; + } - private ChildEntity1 createChildEntity1() { - ChildEntity1 ce = new ChildEntity1(); - ce.setId(idCounter++); - ce.setData1("xxx"); - ce.setData2("yyy"); - ce.setChild1(createChildEntity2()); - ce.setChild2(createChildEntity2()); + private ChildEntity1 createChildEntity1() { + ChildEntity1 ce = new ChildEntity1(); + ce.setId( idCounter++ ); + ce.setData1( "xxx" ); + ce.setData2( "yyy" ); + ce.setChild1( createChildEntity2() ); + ce.setChild2( createChildEntity2() ); - return ce; - } + return ce; + } - protected void doTest() { - for (int i=0; i[] getAnnotatedClasses() { - return new Class[]{StrTestEntity.class, SetRefEdEntity.class, SetRefIngEntity.class}; - } + @Override + protected Class[] getAnnotatedClasses() { + return new Class[] {StrTestEntity.class, SetRefEdEntity.class, SetRefIngEntity.class}; + } - @Test - @TestForIssue(jiraKey = "HHH-6614") - public void testSessionCacheClear() { - Session session = openSession(); - session.getTransaction().begin(); - StrTestEntity ste = new StrTestEntity("data"); - session.persist(ste); - session.getTransaction().commit(); - checkEmptyAuditSessionCache(session, "org.hibernate.envers.test.entities.StrTestEntity_AUD"); - } + @Test + @TestForIssue(jiraKey = "HHH-6614") + public void testSessionCacheClear() { + Session session = openSession(); + session.getTransaction().begin(); + StrTestEntity ste = new StrTestEntity( "data" ); + session.persist( ste ); + session.getTransaction().commit(); + checkEmptyAuditSessionCache( session, "org.hibernate.envers.test.entities.StrTestEntity_AUD" ); + } - @Test - @TestForIssue(jiraKey = "HHH-6614") - public void testSessionCacheCollectionClear() { - final String[] auditEntityNames = new String[] {"org.hibernate.envers.test.entities.onetomany.SetRefEdEntity_AUD", - "org.hibernate.envers.test.entities.onetomany.SetRefIngEntity_AUD"}; + @Test + @TestForIssue(jiraKey = "HHH-6614") + public void testSessionCacheCollectionClear() { + final String[] auditEntityNames = new String[] { + "org.hibernate.envers.test.entities.onetomany.SetRefEdEntity_AUD", + "org.hibernate.envers.test.entities.onetomany.SetRefIngEntity_AUD" + }; - SetRefEdEntity ed1 = new SetRefEdEntity(1, "data_ed_1"); - SetRefEdEntity ed2 = new SetRefEdEntity(2, "data_ed_2"); - SetRefIngEntity ing1 = new SetRefIngEntity(3, "data_ing_1"); - SetRefIngEntity ing2 = new SetRefIngEntity(4, "data_ing_2"); + SetRefEdEntity ed1 = new SetRefEdEntity( 1, "data_ed_1" ); + SetRefEdEntity ed2 = new SetRefEdEntity( 2, "data_ed_2" ); + SetRefIngEntity ing1 = new SetRefIngEntity( 3, "data_ing_1" ); + SetRefIngEntity ing2 = new SetRefIngEntity( 4, "data_ing_2" ); - Session session = openSession(); - session.getTransaction().begin(); - session.persist(ed1); - session.persist(ed2); - session.persist(ing1); - session.persist(ing2); - session.getTransaction().commit(); - checkEmptyAuditSessionCache(session, auditEntityNames); + Session session = openSession(); + session.getTransaction().begin(); + session.persist( ed1 ); + session.persist( ed2 ); + session.persist( ing1 ); + session.persist( ing2 ); + session.getTransaction().commit(); + checkEmptyAuditSessionCache( session, auditEntityNames ); - session.getTransaction().begin(); - ed1 = (SetRefEdEntity) session.load(SetRefEdEntity.class, ed1.getId()); - ing1.setReference(ed1); - ing2.setReference(ed1); - session.getTransaction().commit(); - checkEmptyAuditSessionCache(session, auditEntityNames); + session.getTransaction().begin(); + ed1 = (SetRefEdEntity) session.load( SetRefEdEntity.class, ed1.getId() ); + ing1.setReference( ed1 ); + ing2.setReference( ed1 ); + session.getTransaction().commit(); + checkEmptyAuditSessionCache( session, auditEntityNames ); - session.getTransaction().begin(); - ed2 = (SetRefEdEntity) session.load(SetRefEdEntity.class, ed2.getId()); - Set reffering = new HashSet(); - reffering.add(ing1); - reffering.add(ing2); - ed2.setReffering(reffering); - session.getTransaction().commit(); - checkEmptyAuditSessionCache(session, auditEntityNames); + session.getTransaction().begin(); + ed2 = (SetRefEdEntity) session.load( SetRefEdEntity.class, ed2.getId() ); + Set reffering = new HashSet(); + reffering.add( ing1 ); + reffering.add( ing2 ); + ed2.setReffering( reffering ); + session.getTransaction().commit(); + checkEmptyAuditSessionCache( session, auditEntityNames ); - session.getTransaction().begin(); - ed2 = (SetRefEdEntity) session.load(SetRefEdEntity.class, ed2.getId()); - ed2.getReffering().remove(ing1); - session.getTransaction().commit(); - checkEmptyAuditSessionCache(session, auditEntityNames); + session.getTransaction().begin(); + ed2 = (SetRefEdEntity) session.load( SetRefEdEntity.class, ed2.getId() ); + ed2.getReffering().remove( ing1 ); + session.getTransaction().commit(); + checkEmptyAuditSessionCache( session, auditEntityNames ); - session.getTransaction().begin(); - ed2 = (SetRefEdEntity) session.load(SetRefEdEntity.class, ed2.getId()); - ed2.getReffering().iterator().next().setData("mod_data_ing_2"); - session.getTransaction().commit(); - checkEmptyAuditSessionCache(session, auditEntityNames); + session.getTransaction().begin(); + ed2 = (SetRefEdEntity) session.load( SetRefEdEntity.class, ed2.getId() ); + ed2.getReffering().iterator().next().setData( "mod_data_ing_2" ); + session.getTransaction().commit(); + checkEmptyAuditSessionCache( session, auditEntityNames ); - session.close(); - } + session.close(); + } - private void checkEmptyAuditSessionCache(Session session, String ... auditEntityNames) { - List entityNames = Arrays.asList(auditEntityNames); - PersistenceContext persistenceContext = ((SessionImplementor) session).getPersistenceContext(); - for ( Map.Entry entrySet : persistenceContext.reentrantSafeEntityEntries() ) { - final EntityEntry entityEntry = entrySet.getValue(); - if (entityNames.contains(entityEntry.getEntityName())) { - assert false : "Audit data shall not be stored in the session level cache. This causes performance issues."; - } - Assert.assertFalse("Revision entity shall not be stored in the session level cache. This causes performance issues.", - SequenceIdRevisionEntity.class.getName().equals(entityEntry.getEntityName())); - } - } + private void checkEmptyAuditSessionCache(Session session, String... auditEntityNames) { + List entityNames = Arrays.asList( auditEntityNames ); + PersistenceContext persistenceContext = ((SessionImplementor) session).getPersistenceContext(); + for ( Map.Entry entrySet : persistenceContext.reentrantSafeEntityEntries() ) { + final EntityEntry entityEntry = entrySet.getValue(); + if ( entityNames.contains( entityEntry.getEntityName() ) ) { + assert false : "Audit data shall not be stored in the session level cache. This causes performance issues."; + } + Assert.assertFalse( + "Revision entity shall not be stored in the session level cache. This causes performance issues.", + SequenceIdRevisionEntity.class.getName().equals( entityEntry.getEntityName() ) + ); + } + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/performance/InsertsOneTransactionPerformance.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/performance/InsertsOneTransactionPerformance.java index a458349c01..e54143e5c3 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/performance/InsertsOneTransactionPerformance.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/performance/InsertsOneTransactionPerformance.java @@ -24,13 +24,13 @@ package org.hibernate.envers.test.performance; -import java.io.IOException; import javax.persistence.EntityManager; - -import org.junit.Ignore; +import java.io.IOException; import org.hibernate.envers.test.entities.StrTestEntity; +import org.junit.Ignore; + /** * @author Adam Warski (adam at warski dot org) */ @@ -38,24 +38,24 @@ import org.hibernate.envers.test.entities.StrTestEntity; public class InsertsOneTransactionPerformance extends AbstractPerformanceTest { @Override protected Class[] getAnnotatedClasses() { - return new Class[] { StrTestEntity.class }; - } + return new Class[] {StrTestEntity.class}; + } - private final static int NUMBER_INSERTS = 5000; + private final static int NUMBER_INSERTS = 5000; - protected void doTest() { - EntityManager entityManager = getEntityManager(); - entityManager.getTransaction().begin(); - start(); - for (int i=0; i ids = new ArrayList(); + private List ids = new ArrayList(); - private void setup() { - EntityManager entityManager = getEntityManager(); - entityManager.getTransaction().begin(); + private void setup() { + EntityManager entityManager = getEntityManager(); + entityManager.getTransaction().begin(); - for (int i=0; i strings; + @ElementCollection + private Set strings; - public Long getId() { - return id; - } + public Long getId() { + return id; + } - public void setId(Long id) { - this.id = id; - } + public void setId(Long id) { + this.id = id; + } - public String getData() { - return data; - } + public String getData() { + return data; + } - public void setData(String data) { - this.data = data; - } + public void setData(String data) { + this.data = data; + } - public Integer getNumber() { - return number; - } + public Integer getNumber() { + return number; + } - public void setNumber(Integer number) { - this.number = number; - } + public void setNumber(Integer number) { + this.number = number; + } - public Set getStrings() { - return strings; - } + public Set getStrings() { + return strings; + } - public void setStrings(Set strings) { - this.strings = strings; - } + public void setStrings(Set strings) { + this.strings = strings; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ChildEntity2)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof ChildEntity2) ) { + return false; + } - ChildEntity2 that = (ChildEntity2) o; + ChildEntity2 that = (ChildEntity2) o; - if (data != null ? !data.equals(that.data) : that.data != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; - if (number != null ? !number.equals(that.number) : that.number != null) return false; + if ( data != null ? !data.equals( that.data ) : that.data != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } + if ( number != null ? !number.equals( that.number ) : that.number != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data != null ? data.hashCode() : 0); - result = 31 * result + (number != null ? number.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + result = 31 * result + (number != null ? number.hashCode() : 0); + return result; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/performance/complex/RootEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/performance/complex/RootEntity.java index 2d5142204b..8bd26eb97b 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/performance/complex/RootEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/performance/complex/RootEntity.java @@ -23,13 +23,14 @@ */ package org.hibernate.envers.test.performance.complex; -import java.util.Date; + import javax.persistence.CascadeType; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.ManyToOne; import javax.persistence.Temporal; import javax.persistence.TemporalType; +import java.util.Date; import org.hibernate.envers.Audited; @@ -39,125 +40,141 @@ import org.hibernate.envers.Audited; @Entity @Audited public class RootEntity { - @Id - private Long id; + @Id + private Long id; - private String data1; + private String data1; - private String data2; + private String data2; - private Integer number1; + private Integer number1; - private Integer number2; + private Integer number2; - @Temporal(TemporalType.TIMESTAMP) - private Date date1; + @Temporal(TemporalType.TIMESTAMP) + private Date date1; - @ManyToOne(cascade = CascadeType.ALL) - private ChildEntity1 child1; + @ManyToOne(cascade = CascadeType.ALL) + private ChildEntity1 child1; - @ManyToOne(cascade = CascadeType.ALL) - private ChildEntity1 child2; + @ManyToOne(cascade = CascadeType.ALL) + private ChildEntity1 child2; - @ManyToOne(cascade = CascadeType.ALL) - private ChildEntity1 child3; + @ManyToOne(cascade = CascadeType.ALL) + private ChildEntity1 child3; - public Long getId() { - return id; - } + public Long getId() { + return id; + } - public void setId(Long id) { - this.id = id; - } + public void setId(Long id) { + this.id = id; + } - public String getData1() { - return data1; - } + public String getData1() { + return data1; + } - public void setData1(String data1) { - this.data1 = data1; - } + public void setData1(String data1) { + this.data1 = data1; + } - public String getData2() { - return data2; - } + public String getData2() { + return data2; + } - public void setData2(String data2) { - this.data2 = data2; - } + public void setData2(String data2) { + this.data2 = data2; + } - public Integer getNumber1() { - return number1; - } + public Integer getNumber1() { + return number1; + } - public void setNumber1(Integer number1) { - this.number1 = number1; - } + public void setNumber1(Integer number1) { + this.number1 = number1; + } - public Integer getNumber2() { - return number2; - } + public Integer getNumber2() { + return number2; + } - public void setNumber2(Integer number2) { - this.number2 = number2; - } + public void setNumber2(Integer number2) { + this.number2 = number2; + } - public Date getDate1() { - return date1; - } + public Date getDate1() { + return date1; + } - public void setDate1(Date date1) { - this.date1 = date1; - } + public void setDate1(Date date1) { + this.date1 = date1; + } - public ChildEntity1 getChild1() { - return child1; - } + public ChildEntity1 getChild1() { + return child1; + } - public void setChild1(ChildEntity1 child1) { - this.child1 = child1; - } + public void setChild1(ChildEntity1 child1) { + this.child1 = child1; + } - public ChildEntity1 getChild2() { - return child2; - } + public ChildEntity1 getChild2() { + return child2; + } - public void setChild2(ChildEntity1 child2) { - this.child2 = child2; - } + public void setChild2(ChildEntity1 child2) { + this.child2 = child2; + } - public ChildEntity1 getChild3() { - return child3; - } + public ChildEntity1 getChild3() { + return child3; + } - public void setChild3(ChildEntity1 child3) { - this.child3 = child3; - } + public void setChild3(ChildEntity1 child3) { + this.child3 = child3; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof RootEntity)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof RootEntity) ) { + return false; + } - RootEntity that = (RootEntity) o; + RootEntity that = (RootEntity) o; - if (data1 != null ? !data1.equals(that.data1) : that.data1 != null) return false; - if (data2 != null ? !data2.equals(that.data2) : that.data2 != null) return false; - if (date1 != null ? !date1.equals(that.date1) : that.date1 != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; - if (number1 != null ? !number1.equals(that.number1) : that.number1 != null) return false; - if (number2 != null ? !number2.equals(that.number2) : that.number2 != null) return false; + if ( data1 != null ? !data1.equals( that.data1 ) : that.data1 != null ) { + return false; + } + if ( data2 != null ? !data2.equals( that.data2 ) : that.data2 != null ) { + return false; + } + if ( date1 != null ? !date1.equals( that.date1 ) : that.date1 != null ) { + return false; + } + if ( id != null ? !id.equals( that.id ) : that.id != null ) { + return false; + } + if ( number1 != null ? !number1.equals( that.number1 ) : that.number1 != null ) { + return false; + } + if ( number2 != null ? !number2.equals( that.number2 ) : that.number2 != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (data1 != null ? data1.hashCode() : 0); - result = 31 * result + (data2 != null ? data2.hashCode() : 0); - result = 31 * result + (number1 != null ? number1.hashCode() : 0); - result = 31 * result + (number2 != null ? number2.hashCode() : 0); - result = 31 * result + (date1 != null ? date1.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data1 != null ? data1.hashCode() : 0); + result = 31 * result + (data2 != null ? data2.hashCode() : 0); + result = 31 * result + (number1 != null ? number1.hashCode() : 0); + result = 31 * result + (number2 != null ? number2.hashCode() : 0); + result = 31 * result + (date1 != null ? date1.hashCode() : 0); + return result; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/tools/TestTools.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/tools/TestTools.java index 1e1e6108e2..aa1b56083d 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/tools/TestTools.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/tools/TestTools.java @@ -78,7 +78,7 @@ public class TestTools { public static List extractRevisionNumbers(List queryResults) { final List result = new ArrayList(); for ( Object queryResult : queryResults ) { - result.add( ( (SequenceIdRevisionEntity) ( (Object[]) queryResult )[1] ).getId() ); + result.add( ((SequenceIdRevisionEntity) ((Object[]) queryResult)[1]).getId() ); } return result; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/various/Address.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/various/Address.java index 0f0cf61495..84e0444744 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/various/Address.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/various/Address.java @@ -22,11 +22,12 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.various; -import java.util.Set; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.OneToMany; +import java.util.Set; import org.hibernate.envers.Audited; @@ -35,83 +36,95 @@ import org.hibernate.envers.Audited; */ @Entity public class Address { - @Id - @GeneratedValue - private int id; + @Id + @GeneratedValue + private int id; - @Audited - private String streetName; + @Audited + private String streetName; - @Audited - private Integer houseNumber; + @Audited + private Integer houseNumber; - @Audited - private Integer flatNumber; + @Audited + private Integer flatNumber; - @Audited - @OneToMany(mappedBy = "address") - private Set persons; + @Audited + @OneToMany(mappedBy = "address") + private Set persons; - public int getId() { - return id; - } + public int getId() { + return id; + } - public void setId(int id) { - this.id = id; - } + public void setId(int id) { + this.id = id; + } - public String getStreetName() { - return streetName; - } + public String getStreetName() { + return streetName; + } - public void setStreetName(String streetName) { - this.streetName = streetName; - } + public void setStreetName(String streetName) { + this.streetName = streetName; + } - public Integer getHouseNumber() { - return houseNumber; - } + public Integer getHouseNumber() { + return houseNumber; + } - public void setHouseNumber(Integer houseNumber) { - this.houseNumber = houseNumber; - } + public void setHouseNumber(Integer houseNumber) { + this.houseNumber = houseNumber; + } - public Integer getFlatNumber() { - return flatNumber; - } + public Integer getFlatNumber() { + return flatNumber; + } - public void setFlatNumber(Integer flatNumber) { - this.flatNumber = flatNumber; - } + public void setFlatNumber(Integer flatNumber) { + this.flatNumber = flatNumber; + } - public Set getPersons() { - return persons; - } + public Set getPersons() { + return persons; + } - public void setPersons(Set persons) { - this.persons = persons; - } + public void setPersons(Set persons) { + this.persons = persons; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof Address)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof Address) ) { + return false; + } - Address address = (Address) o; + Address address = (Address) o; - if (id != address.id) return false; - if (flatNumber != null ? !flatNumber.equals(address.flatNumber) : address.flatNumber != null) return false; - if (houseNumber != null ? !houseNumber.equals(address.houseNumber) : address.houseNumber != null) return false; - if (streetName != null ? !streetName.equals(address.streetName) : address.streetName != null) return false; + if ( id != address.id ) { + return false; + } + if ( flatNumber != null ? !flatNumber.equals( address.flatNumber ) : address.flatNumber != null ) { + return false; + } + if ( houseNumber != null ? !houseNumber.equals( address.houseNumber ) : address.houseNumber != null ) { + return false; + } + if ( streetName != null ? !streetName.equals( address.streetName ) : address.streetName != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = id; - result = 31 * result + (streetName != null ? streetName.hashCode() : 0); - result = 31 * result + (houseNumber != null ? houseNumber.hashCode() : 0); - result = 31 * result + (flatNumber != null ? flatNumber.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = id; + result = 31 * result + (streetName != null ? streetName.hashCode() : 0); + result = 31 * result + (houseNumber != null ? houseNumber.hashCode() : 0); + result = 31 * result + (flatNumber != null ? flatNumber.hashCode() : 0); + return result; + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/various/HsqlTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/various/HsqlTest.java index 9f9d3011bb..8b970586f1 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/various/HsqlTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/various/HsqlTest.java @@ -22,12 +22,13 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.various; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; + import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.Persistence; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; import org.hibernate.Session; @@ -35,7 +36,7 @@ import org.hibernate.Session; * @author Adam Warski (adam at warski dot org) */ public class HsqlTest { - /* + /* Query generated by Hibernate from an old demo, when criteria was used: (works) select @@ -90,62 +91,65 @@ public class HsqlTest { TODO: post hibernate bug */ - public static void main(String[] argv) { - Map configurationOverrides = new HashMap(); - EntityManagerFactory emf = Persistence.createEntityManagerFactory("ConsolePU", configurationOverrides); - EntityManager entityManager = emf.createEntityManager(); + public static void main(String[] argv) { + Map configurationOverrides = new HashMap(); + EntityManagerFactory emf = Persistence.createEntityManagerFactory( "ConsolePU", configurationOverrides ); + EntityManager entityManager = emf.createEntityManager(); - populateTestData(entityManager); + populateTestData( entityManager ); - entityManager.getTransaction().begin(); + entityManager.getTransaction().begin(); - Session sesion = (Session) entityManager.getDelegate(); - System.out.println(sesion.createQuery( - "select e from org.hibernate.envers.demo.Person_versions e " + - "where " + - "e.originalId._revision.id =" + - "(select max(e2.originalId._revision.id) " + - "from org.hibernate.envers.demo.Person_versions e2 " + - "where e.originalId.id = :p0) ") - .setParameter("p0", 1) - .list()); + Session sesion = (Session) entityManager.getDelegate(); + System.out.println( + sesion.createQuery( + "select e from org.hibernate.envers.demo.Person_versions e " + + "where " + + "e.originalId._revision.id =" + + "(select max(e2.originalId._revision.id) " + + "from org.hibernate.envers.demo.Person_versions e2 " + + "where e.originalId.id = :p0) " + ) + .setParameter( "p0", 1 ) + .list() + ); - entityManager.getTransaction().commit(); + entityManager.getTransaction().commit(); - entityManager.close(); - emf.close(); - } + entityManager.close(); + emf.close(); + } - private static void populateTestData(EntityManager entityManager) { - entityManager.getTransaction().begin(); + private static void populateTestData(EntityManager entityManager) { + entityManager.getTransaction().begin(); - if (!hasData(entityManager)) { - Person p1 = new Person(); + if ( !hasData( entityManager ) ) { + Person p1 = new Person(); - Address a1 = new Address(); + Address a1 = new Address(); - p1.setName("James"); - p1.setSurname("Bond"); - p1.setAddress(a1); + p1.setName( "James" ); + p1.setSurname( "Bond" ); + p1.setAddress( a1 ); - a1.setStreetName("MI6"); - a1.setHouseNumber(18); - a1.setFlatNumber(25); - a1.setPersons(new HashSet()); - a1.getPersons().add(p1); + a1.setStreetName( "MI6" ); + a1.setHouseNumber( 18 ); + a1.setFlatNumber( 25 ); + a1.setPersons( new HashSet() ); + a1.getPersons().add( p1 ); - entityManager.persist(a1); + entityManager.persist( a1 ); - entityManager.persist(p1); + entityManager.persist( p1 ); - System.out.println("The DB was populated with example data."); - } + System.out.println( "The DB was populated with example data." ); + } - entityManager.getTransaction().commit(); - } + entityManager.getTransaction().commit(); + } - private static boolean hasData(EntityManager entityManager) { - return (((Long) entityManager.createQuery("select count(a) from Address a").getSingleResult()) + - ((Long) entityManager.createQuery("select count(p) from Person p").getSingleResult())) > 0; - } + private static boolean hasData(EntityManager entityManager) { + return (((Long) entityManager.createQuery( "select count(a) from Address a" ).getSingleResult()) + + ((Long) entityManager.createQuery( "select count(p) from Person p" ).getSingleResult())) > 0; + } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/various/Person.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/various/Person.java index eda68bb7f7..4a75501f4b 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/various/Person.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/various/Person.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.various; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; @@ -34,70 +35,80 @@ import org.hibernate.envers.Audited; */ @Entity public class Person { - @Id - @GeneratedValue - private int id; + @Id + @GeneratedValue + private int id; - @Audited - private String name; + @Audited + private String name; - @Audited - private String surname; + @Audited + private String surname; - @Audited - @ManyToOne - private Address address; + @Audited + @ManyToOne + private Address address; - public int getId() { - return id; - } + public int getId() { + return id; + } - public void setId(int id) { - this.id = id; - } + public void setId(int id) { + this.id = id; + } - public String getName() { - return name; - } + public String getName() { + return name; + } - public void setName(String name) { - this.name = name; - } + public void setName(String name) { + this.name = name; + } - public String getSurname() { - return surname; - } + public String getSurname() { + return surname; + } - public void setSurname(String surname) { - this.surname = surname; - } + public void setSurname(String surname) { + this.surname = surname; + } - public Address getAddress() { - return address; - } + public Address getAddress() { + return address; + } - public void setAddress(Address address) { - this.address = address; - } + public void setAddress(Address address) { + this.address = address; + } - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof Person)) return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !(o instanceof Person) ) { + return false; + } - Person person = (Person) o; + Person person = (Person) o; - if (id != person.id) return false; - if (name != null ? !name.equals(person.name) : person.name != null) return false; - if (surname != null ? !surname.equals(person.surname) : person.surname != null) return false; + if ( id != person.id ) { + return false; + } + if ( name != null ? !name.equals( person.name ) : person.name != null ) { + return false; + } + if ( surname != null ? !surname.equals( person.surname ) : person.surname != null ) { + return false; + } - return true; - } + return true; + } - public int hashCode() { - int result; - result = id; - result = 31 * result + (name != null ? name.hashCode() : 0); - result = 31 * result + (surname != null ? surname.hashCode() : 0); - return result; - } + public int hashCode() { + int result; + result = id; + result = 31 * result + (name != null ? name.hashCode() : 0); + result = 31 * result + (surname != null ? surname.hashCode() : 0); + return result; + } } \ No newline at end of file diff --git a/shared/config/checkstyle/checkstyle.xml b/shared/config/checkstyle/checkstyle.xml index 35417093de..cb92c14394 100644 --- a/shared/config/checkstyle/checkstyle.xml +++ b/shared/config/checkstyle/checkstyle.xml @@ -143,6 +143,7 @@ +