From bab7fc6a473989ad448dfed5d6efe78a9ced5233 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Tue, 25 Mar 2014 21:06:24 -0500 Subject: [PATCH] HHH-9077 - org.hibernate.metamodel.source.spi TLC --- .../cfg/beanvalidation/TypeSafeActivator.java | 6 +- .../internal/SessionFactoryImpl.java | 2 +- .../internal/MetadataBuildingProcess.java | 26 +- .../metamodel/internal/binder/Binder.java | 693 +++++++++++------- .../CollectionTableNamingStrategyHelper.java | 2 +- .../internal/binder/HibernateTypeHelper.java | 59 +- .../binder/RelationalValueBindingHelper.java | 10 +- .../internal/binder/SourceIndex.java | 367 ++++------ .../AssociationRelationalBindingResolver.java | 6 +- ...ociationRelationalBindingResolverImpl.java | 22 +- ...ociationRelationalBindingResolverImpl.java | 10 +- .../reflite/internal/Primitives.java | 12 + .../internal/AbstractAttributeSource.java | 78 -- .../internal/AbstractManagedTypeSource.java | 56 -- ...actSingularAssociationAttributeSource.java | 178 ----- .../AbstractSingularAttributeSource.java | 97 --- .../internal/BasicAttributeSourceImpl.java | 140 ---- ...ementSourceAssociationManyToManyImpl.java} | 15 +- ...bstractPluralAttributeIndexSourceImpl.java | 7 +- ...ctPluralElementSourceAssociationImpl.java} | 8 +- .../AbstractToOneAttributeSourceImpl.java | 29 +- ...gregatedCompositeIdentifierSourceImpl.java | 4 +- .../annotations/BasicAttributeSourceImpl.java | 17 +- .../BasicPluralAttributeIndexSourceImpl.java | 94 --- ...ositePluralAttributeElementSourceImpl.java | 134 ---- ...Adapter.java => EmbeddableSourceImpl.java} | 44 +- .../EmbeddedAttributeSourceImpl.java | 96 ++- .../IdentifiableTypeSourceAdapter.java | 11 +- .../IndexedPluralAttributeSourceImpl.java | 245 ------- ...ToAnyPluralAttributeElementSourceImpl.java | 21 - ...ementSourceAssociationManyToManyImpl.java} | 6 +- ...lementSourceAssociationOneToManyImpl.java} | 6 +- ...ElementSourceAssociationManyToAnyImpl.java | 22 + ...ementSourceAssociationManyToManyImpl.java} | 10 +- ...lementSourceAssociationOneToManyImpl.java} | 15 +- ...luralAttributeElementSourceBasicImpl.java} | 19 +- ...ralAttributeElementSourceEmbeddedImpl.java | 78 ++ .../PluralAttributeIdBagSourceImpl.java | 40 + .../PluralAttributeIndexedSourceImpl.java | 80 ++ ...PluralAttributeMapKeySourceBasicImpl.java} | 51 +- ...ralAttributeMapKeySourceEmbeddedImpl.java} | 65 +- ...ributeMapKeySourceEntityAttributeImpl.java | 150 ++++ .../PluralAttributeMapSourceImpl.java | 102 +++ ...alAttributeSequentialIndexSourceImpl.java} | 52 +- .../PluralAttributeSourceImpl.java | 152 +++- .../SingularAttributeSourceImpl.java | 3 +- .../internal/annotations/SourceHelper.java | 21 +- .../annotations/ToOneAttributeSourceImpl.java | 52 +- .../ToOneMappedByAttributeSourceImpl.java | 15 +- .../VersionAttributeSourceImpl.java | 3 +- .../AbstractPersistentAttribute.java | 7 +- ...ractPluralAttributeIndexDetailsMapKey.java | 70 ++ .../attribute/AbstractSingularAttribute.java | 9 +- .../annotations/attribute/BasicAttribute.java | 8 +- .../attribute/EmbeddedAttribute.java | 10 +- .../attribute/EmbeddedContainer.java | 6 +- .../OverrideAndConverterCollector.java | 2 +- .../attribute/PersistentAttribute.java | 4 +- .../attribute/PluralAttribute.java | 190 ++++- .../PluralAttributeElementDetails.java | 8 + .../PluralAttributeElementDetailsBasic.java | 6 + ...PluralAttributeElementDetailsEmbedded.java | 26 +- .../PluralAttributeElementDetailsEntity.java | 27 + .../PluralAttributeIndexDetails.java | 9 + ...luralAttributeIndexDetailsMapKeyBasic.java | 55 ++ ...alAttributeIndexDetailsMapKeyEmbedded.java | 129 ++++ ...buteIndexDetailsMapKeyEntityAttribute.java | 54 ++ ...luralAttributeIndexDetailsSequential.java} | 10 +- .../PluralAttributeMapKeyDetails.java | 171 ----- .../SingularAssociationAttribute.java | 6 +- .../attribute/SingularAttribute.java | 4 +- .../entity/EmbeddableTypeMetadata.java | 14 +- .../entity/IdentifiableTypeMetadata.java | 2 +- .../entity/ManagedTypeMetadata.java | 14 +- .../entity/RootEntityTypeMetadata.java | 2 +- .../global/SqlResultSetProcessor.java | 13 +- .../util/AnnotationParserHelper.java | 8 +- .../util/ConverterAndOverridesHelper.java | 2 +- .../hbm/AbstractEmbeddableJaxbSource.java | 129 ++++ .../AbstractEmbeddedAttributeSourceImpl.java | 150 ++++ .../hbm/AbstractEntitySourceImpl.java | 77 +- .../AbstractPluralAttributeSourceImpl.java | 41 +- .../hbm/AbstractToOneAttributeSourceImpl.java | 16 +- .../source/internal/hbm/ArraySourceImpl.java | 23 +- .../source/internal/hbm/BagSourceImpl.java | 5 +- .../hbm/ComponentAttributeSourceImpl.java | 164 ----- ...ositePluralAttributeElementSourceImpl.java | 182 ----- ...mpositePluralAttributeIndexSourceImpl.java | 175 ----- .../internal/hbm/EmbeddableJaxbSource.java | 95 +++ ...rceImpl.java => EmbeddableSourceImpl.java} | 278 ++++--- .../hbm/EmbeddedAttributeSourceImpl.java | 211 ++++++ .../hbm/EntityHierarchySourceImpl.java | 157 ++-- .../metamodel/source/internal/hbm/Helper.java | 43 +- .../source/internal/hbm/IdBagSourceImpl.java | 178 +++++ .../hbm/IdentifierKeyAttributeSourceImpl.java | 9 +- .../hbm/IdentifierKeyManyToOneSourceImpl.java | 8 +- .../internal/hbm/KeyAttributeSourceImpl.java | 32 +- .../internal/hbm/KeyManyToOneSourceImpl.java | 29 +- .../source/internal/hbm/ListSourceImpl.java | 39 +- .../hbm/ManyToOneAttributeSourceImpl.java | 29 +- ...ceImpl.java => MapKeySourceBasicImpl.java} | 23 +- .../source/internal/hbm/MapSourceImpl.java | 45 +- .../internal/hbm/NamedQueryBindingHelper.java | 18 +- .../hbm/OneToOneAttributeSourceImpl.java | 29 +- ...luralAttributeElementSourceBasicImpl.java} | 17 +- ...ralAttributeElementSourceEmbeddedImpl.java | 150 ++++ ...AttributeElementSourceManyToManyImpl.java} | 13 +- ...lAttributeElementSourceOneToManyImpl.java} | 13 +- ...uralAttributeMapKeySourceEmbeddedImpl.java | 182 +++++ ...alAttributeSequentialIndexSourceImpl.java} | 24 +- .../hbm/PropertyAttributeSourceImpl.java | 33 +- .../internal/hbm/RootEntitySourceImpl.java | 8 +- .../source/internal/hbm/SetSourceImpl.java | 5 +- ...SingularIdentifierAttributeSourceImpl.java | 32 +- .../hbm/TimestampAttributeSourceImpl.java | 30 +- .../hbm/VersionAttributeSourceImpl.java | 30 +- .../AggregatedCompositeIdentifierSource.java | 2 +- .../metamodel/source/spi/AttributeSource.java | 23 +- .../source/spi/AttributeSourceContainer.java | 13 +- ...entSource.java => CollectionIdSource.java} | 29 +- ...ibuteSource.java => EmbeddableSource.java} | 10 +- .../spi/EmbeddableSourceContributor.java | 38 + .../source/spi/EmbeddedAttributeSource.java | 33 + .../spi/IndexedPluralAttributeSource.java | 5 +- .../spi/PluralAttributeElementSource.java | 27 +- ...ralAttributeElementSourceAssociation.java} | 6 +- ...=> PluralAttributeElementSourceBasic.java} | 6 +- .../PluralAttributeElementSourceEmbedded.java | 35 + ...PluralAttributeElementSourceManyToAny.java | 34 + ...uralAttributeElementSourceManyToMany.java} | 5 +- ...luralAttributeElementSourceOneToMany.java} | 5 +- .../spi/PluralAttributeIndexSource.java | 20 +- .../PluralAttributeIndexSourceResolver.java | 2 +- .../spi/PluralAttributeMapKeySource.java | 64 ++ ... => PluralAttributeMapKeySourceBasic.java} | 2 +- ... PluralAttributeMapKeySourceEmbedded.java} | 4 +- ...AttributeMapKeySourceEntityAttribute.java} | 21 +- ... => PluralAttributeMapKeySourceToOne.java} | 5 +- ...PluralAttributeSequentialIndexSource.java} | 15 +- .../source/spi/PluralAttributeSource.java | 33 +- .../source/spi/SingularAttributeSource.java | 22 +- .../spi/AbstractAttributeKey.java | 2 +- .../{source => }/spi/AttributePath.java | 11 +- .../{source => }/spi/AttributeRole.java | 11 +- .../metamodel/spi/NaturalIdMutability.java | 45 ++ .../spi/PluralAttributeElementNature.java | 73 ++ .../spi/PluralAttributeIndexNature.java | 52 ++ .../PluralAttributeNature.java} | 41 +- .../spi/SingularAttributeNature.java | 40 + .../spi/binding/AbstractAttributeBinding.java | 21 +- .../AbstractAttributeBindingContainer.java | 119 ++- ...er.java => AbstractEmbeddableBinding.java} | 114 ++- ...ralAttributeAssociationElementBinding.java | 6 - .../AbstractPluralAttributeBinding.java | 25 +- ...AbstractPluralAttributeElementBinding.java | 37 - ...ctSingularAssociationAttributeBinding.java | 9 +- .../AbstractSingularAttributeBinding.java | 17 +- .../metamodel/spi/binding/ArrayBinding.java | 27 +- .../spi/binding/AttributeBinding.java | 5 +- .../binding/AttributeBindingContainer.java | 66 +- .../spi/binding/BackRefAttributeBinding.java | 3 + .../metamodel/spi/binding/BagBinding.java | 13 +- .../spi/binding/BasicAttributeBinding.java | 9 +- .../BasicPluralAttributeIndexBinding.java | 5 +- .../binding/CompositeAttributeBinding.java | 554 -------------- ...ompositePluralAttributeElementBinding.java | 109 --- .../CompositePluralAttributeIndexBinding.java | 62 +- ...gContainer.java => EmbeddableBinding.java} | 2 +- .../binding/EmbeddableBindingContributor.java | 31 + .../spi/binding/EmbeddedAttributeBinding.java | 309 ++++++++ .../metamodel/spi/binding/EntityBinding.java | 51 +- .../spi/binding/EntityIdentifier.java | 28 +- .../metamodel/spi/binding/Helper.java | 9 +- .../metamodel/spi/binding/ListBinding.java | 12 +- .../binding/ManyToOneAttributeBinding.java | 7 + .../metamodel/spi/binding/MapBinding.java | 18 +- .../spi/binding/OneToOneAttributeBinding.java | 7 + .../PluralAttributeElementBinding.java | 78 +- ...> PluralAttributeElementBindingBasic.java} | 48 +- ...PluralAttributeElementBindingEmbedded.java | 122 +++ ...uralAttributeElementBindingManyToAny.java} | 14 +- ...ralAttributeElementBindingManyToMany.java} | 19 +- ...uralAttributeElementBindingOneToMany.java} | 19 +- .../binding/PluralAttributeIndexBinding.java | 26 +- .../spi/binding/RelationalValueBinding.java | 7 + .../metamodel/spi/binding/SetBinding.java | 13 +- .../spi/binding/SingularAttributeBinding.java | 8 +- .../domain/AbstractAttributeContainer.java | 33 +- .../metamodel/spi/domain/PluralAttribute.java | 45 +- .../AbstractTableSpecification.java | 12 +- .../AbstractCollectionPersister.java | 30 +- .../collection/OneToManyPersister.java | 8 +- .../entity/AbstractEntityPersister.java | 10 +- .../entity/AbstractPropertyMapping.java | 9 +- .../entity/SingleTableEntityPersister.java | 5 +- .../StandardPersisterClassResolver.java | 4 +- .../org/hibernate/tuple/PojoInstantiator.java | 8 +- .../org/hibernate/tuple/PropertyFactory.java | 7 +- .../component/AbstractComponentTuplizer.java | 22 +- .../tuple/component/ComponentMetamodel.java | 6 +- .../tuple/component/ComponentTuplizer.java | 2 +- .../component/ComponentTuplizerFactory.java | 10 +- .../DynamicMapComponentTuplizer.java | 12 +- .../component/PojoComponentTuplizer.java | 26 +- .../tuple/entity/EntityMetamodel.java | 5 +- .../internal/source/AssertSourcesTest.java | 3 +- .../entity/EmbeddableBindingTest.java | 88 ++- .../entity/NaturalIdBindingTests.java | 9 +- .../binding/AbstractBasicBindingTests.java | 15 +- .../spi/binding/SimpleValueBindingTests.java | 5 +- .../AbstractBasicCollectionBindingTests.java | 25 +- ...ctUnidirectionalOneToManyBindingTests.java | 14 +- .../nested/NestedEmbeddableMetadataTest.java | 14 +- .../override/AttributeOverrideTest.java | 7 +- .../tuplizer/DynamicComponentTuplizer.java | 10 +- .../test/legacy/NonReflectiveBinderTest.java | 10 +- .../metamodel/builder/AttributeBuilder.java | 54 +- .../metamodel/builder/MetamodelBuilder.java | 12 +- .../metadata/AuditMetadataGenerator.java | 6 +- .../metadata/CollectionMetadataGenerator.java | 46 +- .../metadata/ComponentMetadataGenerator.java | 11 +- .../metadata/IdMetadataGenerator.java | 16 +- .../reader/AuditedPropertiesReader.java | 24 +- .../envers/internal/tools/MappingTools.java | 5 +- 224 files changed, 5815 insertions(+), 4595 deletions(-) delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/AbstractAttributeSource.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/AbstractManagedTypeSource.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/AbstractSingularAssociationAttributeSource.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/AbstractSingularAttributeSource.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/BasicAttributeSourceImpl.java rename hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/{AbstractManyToManyPluralAttributeElementSourceImpl.java => AbstractPluralAttributeElementSourceAssociationManyToManyImpl.java} (79%) rename hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/{AbstractPluralAssociationElementSourceImpl.java => AbstractPluralElementSourceAssociationImpl.java} (91%) delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/BasicPluralAttributeIndexSourceImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/CompositePluralAttributeElementSourceImpl.java rename hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/{AbstractEmbeddableAdapter.java => EmbeddableSourceImpl.java} (58%) delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/IndexedPluralAttributeSourceImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/ManyToAnyPluralAttributeElementSourceImpl.java rename hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/{ManyToManyMappedByPluralAttributeElementSourceImpl.java => MappedByPluralAttributeElementSourceAssociationManyToManyImpl.java} (88%) rename hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/{OneToManyMappedByPluralAttributeElementSourceImpl.java => MappedByPluralAttributeElementSourceAssociationOneToManyImpl.java} (84%) create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/PluralAttributeElementSourceAssociationManyToAnyImpl.java rename hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/{ManyToManyPluralAttributeElementSourceImpl.java => PluralAttributeElementSourceAssociationManyToManyImpl.java} (92%) rename hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/{OneToManyPluralAttributeElementSourceImpl.java => PluralAttributeElementSourceAssociationOneToManyImpl.java} (69%) rename hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/{BasicPluralAttributeElementSourceImpl.java => PluralAttributeElementSourceBasicImpl.java} (75%) create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/PluralAttributeElementSourceEmbeddedImpl.java create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/PluralAttributeIdBagSourceImpl.java create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/PluralAttributeIndexedSourceImpl.java rename hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/{MapKeyPluralAttributeIndexSourceImpl.java => PluralAttributeMapKeySourceBasicImpl.java} (53%) rename hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/{CompositePluralAttributeIndexSourceImpl.java => PluralAttributeMapKeySourceEmbeddedImpl.java} (59%) create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/PluralAttributeMapKeySourceEntityAttributeImpl.java create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/PluralAttributeMapSourceImpl.java rename hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/{SequentialPluralAttributeIndexSourceImpl.java => PluralAttributeSequentialIndexSourceImpl.java} (59%) create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/AbstractPluralAttributeIndexDetailsMapKey.java create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PluralAttributeIndexDetailsMapKeyBasic.java create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PluralAttributeIndexDetailsMapKeyEmbedded.java create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PluralAttributeIndexDetailsMapKeyEntityAttribute.java rename hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/{PluralAttributeSequentialIndexDetails.java => PluralAttributeIndexDetailsSequential.java} (90%) delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PluralAttributeMapKeyDetails.java create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractEmbeddableJaxbSource.java create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractEmbeddedAttributeSourceImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ComponentAttributeSourceImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/CompositePluralAttributeElementSourceImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/CompositePluralAttributeIndexSourceImpl.java create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/EmbeddableJaxbSource.java rename hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/{AbstractComponentAttributeSourceImpl.java => EmbeddableSourceImpl.java} (50%) create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/EmbeddedAttributeSourceImpl.java create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/IdBagSourceImpl.java rename hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/{MapKeySourceImpl.java => MapKeySourceBasicImpl.java} (86%) rename hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/{BasicPluralAttributeElementSourceImpl.java => PluralAttributeElementSourceBasicImpl.java} (88%) create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PluralAttributeElementSourceEmbeddedImpl.java rename hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/{ManyToManyPluralAttributeElementSourceImpl.java => PluralAttributeElementSourceManyToManyImpl.java} (94%) rename hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/{OneToManyPluralAttributeElementSourceImpl.java => PluralAttributeElementSourceOneToManyImpl.java} (85%) create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PluralAttributeMapKeySourceEmbeddedImpl.java rename hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/{SequentialPluralAttributeIndexSourceImpl.java => PluralAttributeSequentialIndexSourceImpl.java} (87%) rename hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/{CompositePluralAttributeElementSource.java => CollectionIdSource.java} (62%) rename hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/{ComponentAttributeSource.java => EmbeddableSource.java} (78%) create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/EmbeddableSourceContributor.java create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/EmbeddedAttributeSource.java rename hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/{AssociationPluralAttributeElementSource.java => PluralAttributeElementSourceAssociation.java} (92%) rename hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/{BasicPluralAttributeElementSource.java => PluralAttributeElementSourceBasic.java} (86%) create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeElementSourceEmbedded.java create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeElementSourceManyToAny.java rename hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/{ManyToManyPluralAttributeElementSource.java => PluralAttributeElementSourceManyToMany.java} (89%) rename hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/{OneToManyPluralAttributeElementSource.java => PluralAttributeElementSourceOneToMany.java} (85%) create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeMapKeySource.java rename hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/{BasicPluralAttributeIndexSource.java => PluralAttributeMapKeySourceBasic.java} (92%) rename hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/{SequentialPluralAttributeIndexSource.java => PluralAttributeMapKeySourceEmbedded.java} (90%) rename hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/{CompositePluralAttributeIndexSource.java => PluralAttributeMapKeySourceEntityAttribute.java} (64%) rename hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/{ManyToAnyPluralAttributeElementSource.java => PluralAttributeMapKeySourceToOne.java} (85%) rename hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/{EntityAttributePluralAttributeIndexSource.java => PluralAttributeSequentialIndexSource.java} (75%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{source => }/spi/AbstractAttributeKey.java (98%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{source => }/spi/AttributePath.java (81%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{source => }/spi/AttributeRole.java (81%) create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/spi/NaturalIdMutability.java create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/spi/PluralAttributeElementNature.java create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/spi/PluralAttributeIndexNature.java rename hibernate-core/src/main/java/org/hibernate/metamodel/{source/internal/VersionAttributeSourceImpl.java => spi/PluralAttributeNature.java} (55%) create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/spi/SingularAttributeNature.java rename hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/{AbstractCompositeAttributeBindingContainer.java => AbstractEmbeddableBinding.java} (75%) delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/CompositeAttributeBinding.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/CompositePluralAttributeElementBinding.java rename hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/{CompositeAttributeBindingContainer.java => EmbeddableBinding.java} (94%) create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/EmbeddableBindingContributor.java create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/EmbeddedAttributeBinding.java rename hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/{BasicPluralAttributeElementBinding.java => PluralAttributeElementBindingBasic.java} (62%) create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/PluralAttributeElementBindingEmbedded.java rename hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/{ManyToAnyPluralAttributeElementBinding.java => PluralAttributeElementBindingManyToAny.java} (77%) rename hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/{ManyToManyPluralAttributeElementBinding.java => PluralAttributeElementBindingManyToMany.java} (87%) rename hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/{OneToManyPluralAttributeElementBinding.java => PluralAttributeElementBindingOneToMany.java} (79%) diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/beanvalidation/TypeSafeActivator.java b/hibernate-core/src/main/java/org/hibernate/cfg/beanvalidation/TypeSafeActivator.java index 857ce15015..9dc5886c8b 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/beanvalidation/TypeSafeActivator.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/beanvalidation/TypeSafeActivator.java @@ -55,7 +55,7 @@ import org.hibernate.metamodel.spi.binding.AbstractSingularAssociationAttributeB import org.hibernate.metamodel.spi.binding.AbstractSingularAttributeBinding; import org.hibernate.metamodel.spi.binding.AttributeBinding; import org.hibernate.metamodel.spi.binding.BasicAttributeBinding; -import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding; +import org.hibernate.metamodel.spi.binding.EmbeddedAttributeBinding; import org.hibernate.metamodel.spi.binding.EntityBinding; import org.hibernate.metamodel.spi.binding.InheritanceType; import org.hibernate.metamodel.spi.binding.RelationalValueBinding; @@ -424,8 +424,8 @@ class TypeSafeActivator { if ( !isComposite( attributeBinding ) ) { return null; } - CompositeAttributeBinding compositeAttributeBinding = (CompositeAttributeBinding) attributeBinding; - attributeBinding = compositeAttributeBinding.locateAttributeBinding( element ); + EmbeddedAttributeBinding embeddedAttributeBinding = (EmbeddedAttributeBinding) attributeBinding; + attributeBinding = embeddedAttributeBinding.getEmbeddableBinding().locateAttributeBinding( element ); } } return attributeBinding; diff --git a/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java index 13982080e1..2a6b582e5d 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java @@ -873,7 +873,7 @@ public final class SessionFactoryImpl && model.getCaching().getRequested() == TruthValue.TRUE ) { String baseRegionName = model.getCaching().getRegion(); if ( baseRegionName == null ) { - baseRegionName = model.getAttributePath(); + baseRegionName = model.getAttributePath().getFullPath(); } final String cacheRegionName = StringHelper.makePath( settings.getCacheRegionPrefix(), diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataBuildingProcess.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataBuildingProcess.java index 0379329352..9e9d390445 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataBuildingProcess.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataBuildingProcess.java @@ -84,6 +84,7 @@ import org.hibernate.metamodel.spi.InFlightMetadataCollector; import org.hibernate.metamodel.spi.MetadataBuildingOptions; import org.hibernate.metamodel.spi.MetadataContributor; import org.hibernate.metamodel.spi.MetadataSourceProcessor; +import org.hibernate.metamodel.spi.PluralAttributeElementNature; import org.hibernate.metamodel.spi.TypeContributions; import org.hibernate.metamodel.spi.TypeContributor; import org.hibernate.metamodel.spi.binding.AttributeBinding; @@ -94,7 +95,6 @@ import org.hibernate.metamodel.spi.binding.IdentifierGeneratorDefinition; import org.hibernate.metamodel.spi.binding.IndexedPluralAttributeBinding; import org.hibernate.metamodel.spi.binding.ManyToOneAttributeBinding; import org.hibernate.metamodel.spi.binding.PluralAttributeBinding; -import org.hibernate.metamodel.spi.binding.PluralAttributeElementBinding; import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding; import org.hibernate.metamodel.spi.binding.PluralAttributeKeyBinding; import org.hibernate.metamodel.spi.binding.RelationalValueBinding; @@ -385,7 +385,7 @@ public class MetadataBuildingProcess { PluralAttributeKeyBinding keyBinding = pluralAttributeBinding.getPluralAttributeKeyBinding(); if ( keyBinding.isInverse() || keyBinding.isNullable() || pluralAttributeBinding.getPluralAttributeElementBinding().getNature() != - PluralAttributeElementBinding.Nature.ONE_TO_MANY ) { + PluralAttributeElementNature.ONE_TO_MANY ) { continue; } // Ensure this isn't a bidirectional association by ensuring FK columns don't match relational columns of any @@ -498,8 +498,15 @@ public class MetadataBuildingProcess { } else if ( override.getRegionType() == CacheRegionDefinition.CacheRegionType.COLLECTION ) { + String collectionRole = role; + if ( !role.contains( "#" ) ) { + final int pivotPosition = role.lastIndexOf( '.' ); + if ( pivotPosition > 0 ) { + collectionRole = role.substring( 0, pivotPosition ) + '#' + role.substring( pivotPosition + 1 ); + } + } final PluralAttributeBinding pluralAttributeBinding = bindingContext.getMetadataCollector().getCollection( - role + collectionRole ); if ( pluralAttributeBinding != null ) { pluralAttributeBinding.getCaching().overlay( override ); @@ -1119,20 +1126,11 @@ public class MetadataBuildingProcess { @Override public void addCollection(PluralAttributeBinding pluralAttributeBinding) { - final String owningEntityName = pluralAttributeBinding.getContainer().seekEntityBinding().getEntityName(); - final String containerPathBase = pluralAttributeBinding.getContainer().getPathBase(); - final String attributeName = pluralAttributeBinding.getAttribute().getName(); - final String collectionRole; - if ( StringHelper.isEmpty( containerPathBase ) ) { - collectionRole = owningEntityName + '.' + attributeName; - } - else { - collectionRole = owningEntityName + '.' + containerPathBase + '.' + attributeName; - } + final String collectionRole = pluralAttributeBinding.getAttributeRole().getFullPath(); if ( collectionBindingMap.containsKey( collectionRole ) ) { throw new DuplicateMappingException( DuplicateMappingException.Type.ENTITY, collectionRole ); } - collectionBindingMap.put( collectionRole, pluralAttributeBinding ); + collectionBindingMap.put( pluralAttributeBinding.getAttributeRole().getFullPath(), pluralAttributeBinding ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/binder/Binder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/binder/Binder.java index f6a2e7f735..ab19cf95b0 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/binder/Binder.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/binder/Binder.java @@ -23,9 +23,6 @@ */ package org.hibernate.metamodel.internal.binder; -import static org.hibernate.MultiTenancyStrategy.DISCRIMINATOR; -import static org.hibernate.engine.spi.SyntheticAttributeHelper.SYNTHETIC_COMPOSITE_ID_ATTRIBUTE_NAME; - import java.util.ArrayList; import java.util.Collection; import java.util.Comparator; @@ -34,6 +31,7 @@ import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Properties; import java.util.Set; @@ -67,21 +65,17 @@ import org.hibernate.metamodel.internal.binder.HibernateTypeHelper.ReflectedColl import org.hibernate.metamodel.internal.resolver.AssociationRelationalBindingResolver; import org.hibernate.metamodel.internal.resolver.MappedByAssociationRelationalBindingResolverImpl; import org.hibernate.metamodel.internal.resolver.StandardAssociationRelationalBindingResolverImpl; +import org.hibernate.metamodel.reflite.internal.Primitives; import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptorRepository; import org.hibernate.metamodel.source.spi.AggregatedCompositeIdentifierSource; import org.hibernate.metamodel.source.spi.AttributeSource; import org.hibernate.metamodel.source.spi.AttributeSourceContainer; -import org.hibernate.metamodel.source.spi.BasicPluralAttributeElementSource; -import org.hibernate.metamodel.source.spi.BasicPluralAttributeIndexSource; import org.hibernate.metamodel.source.spi.ColumnSource; -import org.hibernate.metamodel.source.spi.ComponentAttributeSource; -import org.hibernate.metamodel.source.spi.CompositePluralAttributeElementSource; -import org.hibernate.metamodel.source.spi.CompositePluralAttributeIndexSource; import org.hibernate.metamodel.source.spi.ConstraintSource; import org.hibernate.metamodel.source.spi.DerivedValueSource; import org.hibernate.metamodel.source.spi.DiscriminatorSource; -import org.hibernate.metamodel.source.spi.EntityAttributePluralAttributeIndexSource; +import org.hibernate.metamodel.source.spi.EmbeddedAttributeSource; import org.hibernate.metamodel.source.spi.EntityHierarchySource; import org.hibernate.metamodel.source.spi.EntitySource; import org.hibernate.metamodel.source.spi.FilterSource; @@ -90,20 +84,24 @@ import org.hibernate.metamodel.source.spi.IdentifierSource; import org.hibernate.metamodel.source.spi.IndexConstraintSource; import org.hibernate.metamodel.source.spi.IndexedPluralAttributeSource; import org.hibernate.metamodel.source.spi.JoinedSubclassEntitySource; -import org.hibernate.metamodel.source.spi.ManyToManyPluralAttributeElementSource; import org.hibernate.metamodel.source.spi.MappedByAssociationSource; import org.hibernate.metamodel.source.spi.MetaAttributeContext; import org.hibernate.metamodel.source.spi.MultiTenancySource; import org.hibernate.metamodel.source.spi.NonAggregatedCompositeIdentifierSource; -import org.hibernate.metamodel.source.spi.OneToManyPluralAttributeElementSource; import org.hibernate.metamodel.source.spi.Orderable; -import org.hibernate.metamodel.source.spi.PluralAttributeElementSource; +import org.hibernate.metamodel.source.spi.PluralAttributeElementSourceBasic; +import org.hibernate.metamodel.source.spi.PluralAttributeElementSourceEmbedded; +import org.hibernate.metamodel.source.spi.PluralAttributeElementSourceManyToMany; +import org.hibernate.metamodel.source.spi.PluralAttributeElementSourceOneToMany; import org.hibernate.metamodel.source.spi.PluralAttributeIndexSource; +import org.hibernate.metamodel.source.spi.PluralAttributeMapKeySourceBasic; +import org.hibernate.metamodel.source.spi.PluralAttributeMapKeySourceEmbedded; +import org.hibernate.metamodel.source.spi.PluralAttributeMapKeySourceEntityAttribute; +import org.hibernate.metamodel.source.spi.PluralAttributeSequentialIndexSource; import org.hibernate.metamodel.source.spi.PluralAttributeSource; import org.hibernate.metamodel.source.spi.RelationalValueSource; import org.hibernate.metamodel.source.spi.RelationalValueSourceContainer; import org.hibernate.metamodel.source.spi.SecondaryTableSource; -import org.hibernate.metamodel.source.spi.SequentialPluralAttributeIndexSource; import org.hibernate.metamodel.source.spi.SimpleIdentifierSource; import org.hibernate.metamodel.source.spi.SingularAttributeSource; import org.hibernate.metamodel.source.spi.Sortable; @@ -111,19 +109,23 @@ import org.hibernate.metamodel.source.spi.ToOneAttributeSource; import org.hibernate.metamodel.source.spi.ToolingHintSource; import org.hibernate.metamodel.source.spi.UniqueConstraintSource; import org.hibernate.metamodel.source.spi.VersionAttributeSource; +import org.hibernate.metamodel.spi.AttributeRole; import org.hibernate.metamodel.spi.BindingContext; +import org.hibernate.metamodel.spi.NaturalIdMutability; +import org.hibernate.metamodel.spi.PluralAttributeElementNature; +import org.hibernate.metamodel.spi.PluralAttributeIndexNature; +import org.hibernate.metamodel.spi.PluralAttributeNature; +import org.hibernate.metamodel.spi.SingularAttributeNature; import org.hibernate.metamodel.spi.binding.AbstractPluralAttributeBinding; import org.hibernate.metamodel.spi.binding.AttributeBinding; import org.hibernate.metamodel.spi.binding.AttributeBindingContainer; import org.hibernate.metamodel.spi.binding.BasicAttributeBinding; -import org.hibernate.metamodel.spi.binding.BasicPluralAttributeElementBinding; import org.hibernate.metamodel.spi.binding.BasicPluralAttributeIndexBinding; import org.hibernate.metamodel.spi.binding.Caching; import org.hibernate.metamodel.spi.binding.Cascadeable; -import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding; -import org.hibernate.metamodel.spi.binding.CompositeAttributeBindingContainer; -import org.hibernate.metamodel.spi.binding.CompositePluralAttributeElementBinding; import org.hibernate.metamodel.spi.binding.CompositePluralAttributeIndexBinding; +import org.hibernate.metamodel.spi.binding.EmbeddableBinding; +import org.hibernate.metamodel.spi.binding.EmbeddedAttributeBinding; import org.hibernate.metamodel.spi.binding.EntityBinding; import org.hibernate.metamodel.spi.binding.EntityIdentifier; import org.hibernate.metamodel.spi.binding.EntityVersion; @@ -132,13 +134,15 @@ import org.hibernate.metamodel.spi.binding.HierarchyDetails; import org.hibernate.metamodel.spi.binding.IdentifierGeneratorDefinition; import org.hibernate.metamodel.spi.binding.IndexedPluralAttributeBinding; import org.hibernate.metamodel.spi.binding.InheritanceType; -import org.hibernate.metamodel.spi.binding.ManyToManyPluralAttributeElementBinding; import org.hibernate.metamodel.spi.binding.ManyToOneAttributeBinding; import org.hibernate.metamodel.spi.binding.MetaAttribute; -import org.hibernate.metamodel.spi.binding.OneToManyPluralAttributeElementBinding; import org.hibernate.metamodel.spi.binding.OneToOneAttributeBinding; import org.hibernate.metamodel.spi.binding.PluralAttributeBinding; import org.hibernate.metamodel.spi.binding.PluralAttributeElementBinding; +import org.hibernate.metamodel.spi.binding.PluralAttributeElementBindingBasic; +import org.hibernate.metamodel.spi.binding.PluralAttributeElementBindingEmbedded; +import org.hibernate.metamodel.spi.binding.PluralAttributeElementBindingManyToMany; +import org.hibernate.metamodel.spi.binding.PluralAttributeElementBindingOneToMany; import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding; import org.hibernate.metamodel.spi.binding.PluralAttributeKeyBinding; import org.hibernate.metamodel.spi.binding.RelationalValueBinding; @@ -146,7 +150,6 @@ import org.hibernate.metamodel.spi.binding.SecondaryTable; import org.hibernate.metamodel.spi.binding.SetBinding; import org.hibernate.metamodel.spi.binding.SingularAssociationAttributeBinding; import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; -import org.hibernate.metamodel.spi.binding.SingularAttributeBinding.NaturalIdMutability; import org.hibernate.metamodel.spi.domain.Aggregate; import org.hibernate.metamodel.spi.domain.BasicType; import org.hibernate.metamodel.spi.domain.Entity; @@ -169,8 +172,12 @@ import org.hibernate.tuple.component.ComponentTuplizer; import org.hibernate.tuple.entity.EntityTuplizer; import org.hibernate.type.ForeignKeyDirection; import org.hibernate.type.Type; + import org.jboss.jandex.DotName; +import static org.hibernate.MultiTenancyStrategy.DISCRIMINATOR; +import static org.hibernate.engine.spi.SyntheticAttributeHelper.SYNTHETIC_COMPOSITE_ID_ATTRIBUTE_NAME; + /** * The common binder shared between annotations and {@code hbm.xml} processing. * @@ -202,7 +209,6 @@ public class Binder { private final Map> identifierDependencyMap = new HashMap>(); - public Binder(BindingContext rootBindingContext) { this.rootBindingContext = new BinderRootContextImpl( rootBindingContext ); @@ -604,21 +610,21 @@ public class Binder { // At this point, SourceIndex has all necessary information. - // Bind all composite attribute containers. This excludes composite sub-attributes. - applyToAllEntityHierarchies( bindSingularAttributesExecutor( false, SingularAttributeSource.Nature.COMPOSITE ) ); + // Bind all composite attribute containers. This includes composite sub-attributes. + applyToAllEntityHierarchies( bindSingularAttributesExecutor( false, SingularAttributeNature.COMPOSITE ) ); // bind basic singular attributes, including composite sub-attributes that are basic. - applyToAllEntityHierarchies( bindSingularAttributesExecutor( false, SingularAttributeSource.Nature.BASIC ) ); + applyToAllEntityHierarchies( bindSingularAttributesExecutor( false, SingularAttributeNature.BASIC ) ); // many-to-one needs to be bound before one-to-one (um, can't remember why). // bind non-mappedby many-to-one and one-to-one attributes, including composite sub-attributes that are many-to-one/one-to-one. - applyToAllEntityHierarchies( bindSingularAttributesExecutor( false, SingularAttributeSource.Nature.MANY_TO_ONE ) ); - applyToAllEntityHierarchies( bindSingularAttributesExecutor( false, SingularAttributeSource.Nature.ONE_TO_ONE ) ); + applyToAllEntityHierarchies( bindSingularAttributesExecutor( false, SingularAttributeNature.MANY_TO_ONE ) ); + applyToAllEntityHierarchies( bindSingularAttributesExecutor( false, SingularAttributeNature.ONE_TO_ONE ) ); // bind mappedby many-to-one and one-to-one attributes, including composite sub-attributes that are many-to-one/one-to-one. - applyToAllEntityHierarchies( bindSingularAttributesExecutor( true, SingularAttributeSource.Nature.MANY_TO_ONE ) ); - applyToAllEntityHierarchies( bindSingularAttributesExecutor( true, SingularAttributeSource.Nature.ONE_TO_ONE ) ); + applyToAllEntityHierarchies( bindSingularAttributesExecutor( true, SingularAttributeNature.MANY_TO_ONE ) ); + applyToAllEntityHierarchies( bindSingularAttributesExecutor( true, SingularAttributeNature.ONE_TO_ONE ) ); // bind plural attributes (non-mappedBy first), including composite sub-attributes that are plural applyToAllEntityHierarchies( bindPluralAttributesExecutor( false ) ); @@ -893,7 +899,7 @@ public class Binder { final HierarchyDetails binding, final AggregatedCompositeIdentifierSource identifierSource) { // locate the attribute binding - final CompositeAttributeBinding idAttributeBinding = (CompositeAttributeBinding) bindIdentifierAttribute( + final EmbeddedAttributeBinding idAttributeBinding = (EmbeddedAttributeBinding) bindIdentifierAttribute( binding.getRootEntityBinding(), identifierSource.getIdentifierAttributeSource() ); @@ -949,7 +955,7 @@ public class Binder { binding.getRootEntityBinding().getEntity() ); - final CompositeAttributeBinding syntheticAttributeBinding = binding.getRootEntityBinding() + final EmbeddedAttributeBinding syntheticAttributeBinding = binding.getRootEntityBinding() .makeVirtualCompositeAttributeBinding( syntheticAttribute, createMetaAttributeContext( @@ -1079,7 +1085,7 @@ public class Binder { if ( identifierSource.getNature() != EntityIdentifierNature.SIMPLE ) { final List subAttributeSources; if ( identifierSource.getNature() == EntityIdentifierNature.AGGREGATED_COMPOSITE ) { - subAttributeSources = ( (AggregatedCompositeIdentifierSource) identifierSource ).getIdentifierAttributeSource().attributeSources(); + subAttributeSources = ( (AggregatedCompositeIdentifierSource) identifierSource ).getIdentifierAttributeSource().getEmbeddableSource().attributeSources(); } else { subAttributeSources = ( (NonAggregatedCompositeIdentifierSource) identifierSource ).getAttributeSourcesMakingUpIdentifier(); @@ -1088,7 +1094,7 @@ public class Binder { } else { final SimpleIdentifierSource simpleIdentifierSource = (SimpleIdentifierSource) identifierSource; - return simpleIdentifierSource.getIdentifierAttributeSource().getNature() != SingularAttributeSource.Nature.BASIC; + return simpleIdentifierSource.getIdentifierAttributeSource().getSingularAttributeNature() != SingularAttributeNature.BASIC; } } @@ -1101,23 +1107,36 @@ public class Binder { if ( ToOneAttributeSource.class.isInstance( singularAttributeSource ) ) { return true; } - else if ( ( (SingularAttributeSource) attributeSource ).getNature() == SingularAttributeSource.Nature.COMPOSITE ) { - ComponentAttributeSource componentAttributeSource = (ComponentAttributeSource) attributeSource; - return containsSingularAssociation( componentAttributeSource.attributeSources() ); + else if ( ( (SingularAttributeSource) attributeSource ).getSingularAttributeNature() == SingularAttributeNature.COMPOSITE ) { + EmbeddedAttributeSource embeddedAttributeSource = (EmbeddedAttributeSource) attributeSource; + return containsSingularAssociation( embeddedAttributeSource.getEmbeddableSource().attributeSources() ); } } return false; } private AttributeBindingContainer locateAttributeBindingContainer(final EntityBinding entityBinding, final String containerPath) { - return StringHelper.isEmpty( containerPath ) - ? entityBinding - : (AttributeBindingContainer) entityBinding.locateAttributeBindingByPath( containerPath, false ); + if ( StringHelper.isEmpty( containerPath ) ) { + return entityBinding; + } + + final AttributeBinding attributeBinding = entityBinding.locateAttributeBindingByPath( containerPath, false ); + if ( AttributeBindingContainer.class.isInstance( attributeBinding ) ) { + return (AttributeBindingContainer) attributeBinding; + } + else if ( EmbeddedAttributeBinding.class.isInstance( attributeBinding ) ) { + return ( (EmbeddedAttributeBinding) attributeBinding ).getEmbeddableBinding(); + } + + throw localBindingContext().makeMappingException( + "Could not determine how to treat resolved attribute binding [" + attributeBinding + + "] as AttributeBindingContainer" + ); } private BinderStepEntityStrategy bindSingularAttributesExecutor( final boolean isMappedBy, - final SingularAttributeSource.Nature nature) { + final SingularAttributeNature singularAttributeNature) { return new BinderStepEntityStrategy() { @Override public boolean applyToRootEntity() { @@ -1127,59 +1146,95 @@ public class Binder { @Override public void visit(EntitySource source, BinderLocalBindingContext context) { final EntityBinding binding = context.locateBinding( source ); - bindSingularAttributes( binding, isMappedBy, nature ); + bindSingularAttributes( binding, isMappedBy, singularAttributeNature ); } }; } + private Map embeddableToContributingAttributeMap + = new HashMap(); + + // TODO: create separate methods that are more clear for the cases. private void bindSingularAttributes( final EntityBinding entityBinding, final boolean isMappedBy, - final SingularAttributeSource.Nature nature) { + final SingularAttributeNature singularAttributeNature) { // Get the map of all attributes for the entity binding of the specified nature. - Map map = sourceIndex.getSingularAttributeSources( + Map map = sourceIndex.getSingularAttributeSources( entityBinding.getEntityName(), isMappedBy, - nature + singularAttributeNature ); - for ( Map.Entry entry : map.entrySet() ){ - final SourceIndex.AttributeSourceKey attributeSourceKey = entry.getKey(); - final SingularAttributeSource attributeSource = entry.getValue(); - final AttributeBindingContainer attributeBindingContainer = - locateAttributeBindingContainer( entityBinding, attributeSourceKey.containerPath() ); + for ( SingularAttributeSource attributeSource : map.values() ) { + final String containerPath = attributeSource.getAttributePath().getParent() == null + ? "" + : attributeSource.getAttributePath().getParent().getFullPath(); + + final AttributeBindingContainer attributeBindingContainer = locateAttributeBindingContainer( entityBinding, containerPath ); if ( isMappedBy ) { if ( !ToOneAttributeSource.class.isInstance( attributeSource ) ) { throw new AssertionFailure( String.format( - "mappedBy is true, but attributeSouce is not an association: %s", - attributeSourceKey + Locale.ENGLISH, + "mappedBy is true, but attributeSource is not an association: %s", + attributeSource.getAttributeRole().getFullPath() ) ); } bindMappedBySecondaryTableIfNecessary( entityBinding, (ToOneAttributeSource) attributeSource ); } - if ( nature == SingularAttributeSource.Nature.COMPOSITE ) { + if ( singularAttributeNature == SingularAttributeNature.COMPOSITE ) { // This only creates the composite attribute container. - createAggregatedCompositeAttribute( + EmbeddedAttributeBinding attributeBinding = createAggregatedCompositeAttribute( attributeBindingContainer, - (ComponentAttributeSource) attributeSource, + (EmbeddedAttributeSource) attributeSource, null ); + + embeddableToContributingAttributeMap.put( attributeBinding.getEmbeddableBinding(), attributeBinding ); + + Aggregate aggregate = (Aggregate) attributeBinding.getAttribute().getSingularAttributeType(); + + typeHelper().bindAggregatedCompositeAttributeType( + localBindingContext().getServiceRegistry(), + false, + aggregate, + aggregate.getDescriptor(), + attributeBinding + ); } - else if ( attributeBindingContainer instanceof CompositeAttributeBinding ) { + else if ( attributeBindingContainer instanceof EmbeddableBinding ) { // This attribute source is within a composite; skip binding if it is the parent. - final CompositeAttributeBinding compositeAttributeBinding = (CompositeAttributeBinding) attributeBindingContainer; - final ComponentAttributeSource compositeAttributeSource = - (ComponentAttributeSource) sourceIndex.attributeSource( entityBinding, compositeAttributeBinding ); - final SingularAttribute parentReference = compositeAttributeBinding.getParentReference(); + final EmbeddableBinding embeddableBinding = (EmbeddableBinding) attributeBindingContainer; + final SingularAttribute parentReference = embeddableBinding.getParentReference(); + if ( parentReference == null || !parentReference.getName().equals( attributeSource.getName() ) ) { bindAttribute( attributeBindingContainer, attributeSource ); + + final EmbeddedAttributeBinding embeddedAttributeBinding + = embeddableToContributingAttributeMap.get( embeddableBinding ); + if ( embeddedAttributeBinding == null ) { + throw localBindingContext().makeMappingException( + "Could not resolve embeddable binding back to the attribute that contributed it : " + + attributeSource.getAttributeRole().getFullPath() + ); + } + + final EmbeddedAttributeSource embeddedAttributeSource + = (EmbeddedAttributeSource) sourceIndex.attributeSource( embeddedAttributeBinding.getAttributeRole() ); + if ( embeddedAttributeSource == null ) { + throw localBindingContext().makeMappingException( + "Could not resolve embeddable binding back to the attribute source that contributed it : " + + attributeSource.getAttributeRole().getFullPath() + ); + } + completeCompositeAttributeBindingIfPossible( - compositeAttributeBinding, - compositeAttributeSource + embeddedAttributeBinding, + embeddedAttributeSource ); } } @@ -1192,18 +1247,17 @@ public class Binder { // All sub-attributes must be bound before it's type and ComponentMetamodel can be determined. private void completeCompositeAttributeBindingIfPossible( - CompositeAttributeBinding compositeAttributeBinding, - ComponentAttributeSource compositeAttributeSource) { + EmbeddedAttributeBinding embeddedAttributeBinding, + EmbeddedAttributeSource compositeAttributeSource) { // Find out the number of sub-attributes, excluding the parent attribute. - final int nAttributeSourcesExcludingParent = - compositeAttributeBinding.getParentReference() != null - ? compositeAttributeSource.attributeSources().size() - 1 - : compositeAttributeSource.attributeSources().size(); - if ( compositeAttributeBinding.attributeBindingSpan() == nAttributeSourcesExcludingParent ) { + final int nAttributeSourcesExcludingParent = embeddedAttributeBinding.getEmbeddableBinding().getParentReference() != null + ? compositeAttributeSource.getEmbeddableSource().attributeSources().size() - 1 + : compositeAttributeSource.getEmbeddableSource().attributeSources().size(); + if ( embeddedAttributeBinding.getEmbeddableBinding().attributeBindingSpan() == nAttributeSourcesExcludingParent ) { // All sub-attribute bindings are present; now check if all sub-attributes have // their type resolved. boolean allResolved = true; - for ( AttributeBinding attributeBinding : compositeAttributeBinding.attributeBindings() ) { + for ( AttributeBinding attributeBinding : embeddedAttributeBinding.getEmbeddableBinding().attributeBindings() ) { if ( attributeBinding.getHibernateTypeDescriptor().getResolvedTypeMapping() == null ) { // Something is not resolved. allResolved = false; @@ -1211,29 +1265,28 @@ public class Binder { } } if ( allResolved ) { + final Aggregate aggregate = (Aggregate) embeddedAttributeBinding.getAttribute().getSingularAttributeType(); + // All are resolved, so we can bind the type. typeHelper().bindAggregatedCompositeAttributeType( localBindingContext().getServiceRegistry(), false, - (Aggregate) compositeAttributeBinding.getAttribute().getSingularAttributeType(), - null, // TODO: don't have the default value at this point; shouldn't be needed... - compositeAttributeBinding + aggregate, + aggregate.getDescriptor(), + embeddedAttributeBinding ); // Now check the container. - if ( compositeAttributeBinding.getContainer() instanceof CompositeAttributeBindingContainer ) { - // The container is also a CompositeAttributeBindingContainer. + if ( embeddedAttributeBinding.getContainer() instanceof EmbeddableBinding ) { + // The container is also a EmbeddableBinding. // We need this process for the container. - final CompositeAttributeBinding parentCompositeAttributeBinding = - (CompositeAttributeBinding) compositeAttributeBinding.seekEntityBinding().locateAttributeBinding( - ( compositeAttributeBinding.getContainer() ).getPathBase() - ); - final ComponentAttributeSource parentCompositeAttributeSource = - (ComponentAttributeSource) sourceIndex.attributeSource( - parentCompositeAttributeBinding.seekEntityBinding().getEntityName(), - parentCompositeAttributeBinding.getPathBase() - ); + final EmbeddedAttributeBinding parentEmbeddedAttributeBinding = embeddableToContributingAttributeMap.get( + embeddedAttributeBinding.getContainer() + ); + final EmbeddedAttributeSource parentCompositeAttributeSource + = (EmbeddedAttributeSource) sourceIndex.attributeSource( parentEmbeddedAttributeBinding.getAttributeRole() ); + completeCompositeAttributeBindingIfPossible( - parentCompositeAttributeBinding, + parentEmbeddedAttributeBinding, parentCompositeAttributeSource ); } @@ -1253,27 +1306,34 @@ public class Binder { // TODO: may want bind plural attributes of a particular element nature. final EntityBinding entityBinding = context.locateBinding( source ); // Get the map for inverse or non-inverse (as specified) plural attributes - Map map = sourceIndex.getPluralAttributeSources( + Map map = sourceIndex.getPluralAttributeSources( entityBinding.getEntityName(), isInverse ); - for ( Map.Entry entry : map.entrySet() ){ - final SourceIndex.AttributeSourceKey attributeSourceKey = entry.getKey(); - final PluralAttributeSource attributeSource = entry.getValue(); + for ( PluralAttributeSource attributeSource : map.values() ) { // Bind the attribute into the appropriate container. + final String containerPath = attributeSource.getAttributePath().getParent() == null + ? "" + : attributeSource.getAttributePath().getParent().getFullPath(); final AttributeBindingContainer attributeBindingContainer = - locateAttributeBindingContainer( entityBinding, attributeSourceKey.containerPath() ); + locateAttributeBindingContainer( entityBinding, containerPath ); + bindAttribute( attributeBindingContainer, attributeSource ); - if ( attributeBindingContainer instanceof CompositeAttributeBinding ) { - // We just bound a sub-attribute into a CompositeAttributeBinding. - final CompositeAttributeBinding compositeAttributeBinding = (CompositeAttributeBinding) attributeBindingContainer; - final ComponentAttributeSource compositeAttributeSource = - (ComponentAttributeSource) sourceIndex.attributeSource( - entityBinding.getEntityName(), - compositeAttributeBinding.getPathBase() - ); + + if ( attributeBindingContainer instanceof EmbeddableBinding ) { + // We just bound a sub-attribute into a EmbeddedAttributeBinding. + final EmbeddableBinding embeddableBinding = (EmbeddableBinding) attributeBindingContainer; + + final EmbeddedAttributeBinding embeddedAttributeBinding = embeddableToContributingAttributeMap.get( + embeddableBinding + ); + + final EmbeddedAttributeSource compositeAttributeSource = (EmbeddedAttributeSource) sourceIndex.attributeSource( + embeddedAttributeBinding.getAttributeRole() + ); + // Resolve the type if types are resolved for all sub-attributes now. - completeCompositeAttributeBindingIfPossible( compositeAttributeBinding, compositeAttributeSource ); + completeCompositeAttributeBindingIfPossible( embeddedAttributeBinding, compositeAttributeSource ); } } } @@ -1411,7 +1471,8 @@ public class Binder { final MappedByAssociationSource mappedByAssociationSource = (MappedByAssociationSource) attributeSource; final ToOneAttributeSource ownerAttributeSource = (ToOneAttributeSource) sourceIndex.attributeSource( - mappedByAssociationSource.getReferencedEntityName(), mappedByAssociationSource.getMappedBy() + mappedByAssociationSource.getReferencedEntityName(), + mappedByAssociationSource.getMappedBy() ); if ( ownerAttributeSource.isMappedBy() ) { throw new AssertionFailure( "owner attribute source has mappedBy != null" ); @@ -1419,7 +1480,7 @@ public class Binder { final EntityBinding ownerEntityBinding = locateEntityBinding( attributeSource.getReferencedEntityName() ); - if ( ownerAttributeSource.getNature() == SingularAttributeSource.Nature.ONE_TO_ONE || + if ( ownerAttributeSource.getSingularAttributeNature() == SingularAttributeNature.ONE_TO_ONE || ownerAttributeSource.getContainingTableName() == null || ownerAttributeSource.getContainingTableName().equals( ownerEntityBinding.getPrimaryTableName() ) ) { // primary table is used, so no need to bind an inverse secondary table. @@ -1648,20 +1709,19 @@ public class Binder { } private void bindAttributes( - final CompositeAttributeBindingContainer compositeAttributeBindingContainer, + final EmbeddableBinding embeddableBinding, final AttributeSourceContainer attributeSourceContainer) { - if ( compositeAttributeBindingContainer.getParentReference() == null ) { + if ( embeddableBinding.getParentReference() == null ) { bindAttributes( - (AttributeBindingContainer) compositeAttributeBindingContainer, + (AttributeBindingContainer) embeddableBinding, attributeSourceContainer ); } else { for ( final AttributeSource subAttributeSource : attributeSourceContainer.attributeSources() ) { - if ( !subAttributeSource.getName() - .equals( compositeAttributeBindingContainer.getParentReference().getName() ) ) { + if ( !subAttributeSource.getName().equals( embeddableBinding.getParentReference().getName() ) ) { bindAttribute( - compositeAttributeBindingContainer, + embeddableBinding, subAttributeSource ); } @@ -1701,25 +1761,25 @@ public class Binder { if ( attribute == null ) { attribute = createSingularAttribute( attributeBindingContainer, attributeSource ); } - final List relationalValueBindings = - relationalValueBindingHelper().createRelationalValueBindings( - attributeBindingContainer, - attributeSource, - attribute, - locateDefaultTableSpecificationForAttribute( attributeBindingContainer, attributeSource ), - false - ); - final BasicAttributeBinding attributeBinding = - attributeBindingContainer.makeBasicAttributeBinding( - attribute, - relationalValueBindings, - propertyAccessorName( attributeSource ), - attributeSource.isIncludedInOptimisticLocking(), - attributeSource.isLazy(), - attributeSource.getNaturalIdMutability(), - createMetaAttributeContext( attributeBindingContainer, attributeSource ), - attributeSource.getGeneration() - ); + final List relationalValueBindings = relationalValueBindingHelper().createRelationalValueBindings( + attributeBindingContainer, + attributeSource, + attribute, + locateDefaultTableSpecificationForAttribute( attributeBindingContainer, attributeSource ), + false + ); + final BasicAttributeBinding attributeBinding = attributeBindingContainer.makeBasicAttributeBinding( + attribute, + relationalValueBindings, + propertyAccessorName( attributeSource ), + attributeSource.isIncludedInOptimisticLocking(), + attributeSource.isLazy(), + attributeSource.getNaturalIdMutability(), + createMetaAttributeContext( attributeBindingContainer, attributeSource ), + attributeSource.getAttributeRole(), + attributeSource.getAttributePath(), + attributeSource.getGeneration() + ); typeHelper().bindSingularAttributeType( attributeSource, attributeBinding @@ -1732,10 +1792,10 @@ public class Binder { final AttributeBindingContainer attributeBindingContainer, final SingularAttributeSource attributeSource, final boolean isIdentifierAttribute) { - final SingularAttributeSource.Nature nature = attributeSource.getNature(); + final SingularAttributeNature singularAttributeNature = attributeSource.getSingularAttributeNature(); final SingularAttribute attribute = attributeBindingContainer.getAttributeContainer().locateSingularAttribute( attributeSource.getName() ); - switch ( nature ) { + switch ( singularAttributeNature ) { case BASIC: return bindBasicAttribute( attributeBindingContainer, attributeSource, attribute ); case ONE_TO_ONE: @@ -1753,24 +1813,24 @@ public class Binder { case COMPOSITE: return bindAggregatedCompositeAttribute( attributeBindingContainer, - ComponentAttributeSource.class.cast( attributeSource ), + EmbeddedAttributeSource.class.cast( attributeSource ), attribute, isIdentifierAttribute ); default: - throw new NotYetImplementedException( nature.toString() ); + throw new NotYetImplementedException( singularAttributeNature.toString() ); } } - private CompositeAttributeBinding bindAggregatedCompositeAttribute( + private EmbeddedAttributeBinding bindAggregatedCompositeAttribute( final AttributeBindingContainer attributeBindingContainer, - final ComponentAttributeSource attributeSource, + final EmbeddedAttributeSource attributeSource, SingularAttribute attribute, boolean isAttributeIdentifier) { - CompositeAttributeBinding attributeBinding = createAggregatedCompositeAttribute( + EmbeddedAttributeBinding attributeBinding = createAggregatedCompositeAttribute( attributeBindingContainer, attributeSource, attribute ); - bindAttributes( attributeBinding, attributeSource ); + bindAttributes( attributeBinding.getEmbeddableBinding(), attributeSource.getEmbeddableSource() ); typeHelper().bindAggregatedCompositeAttributeType( localBindingContext().getServiceRegistry(), isAttributeIdentifier, @@ -1781,9 +1841,9 @@ public class Binder { return attributeBinding; } - private CompositeAttributeBinding createAggregatedCompositeAttribute( + private EmbeddedAttributeBinding createAggregatedCompositeAttribute( final AttributeBindingContainer attributeBindingContainer, - final ComponentAttributeSource attributeSource, + final EmbeddedAttributeSource attributeSource, SingularAttribute attribute) { final Aggregate composite; if ( attribute == null ) { @@ -1803,8 +1863,8 @@ public class Binder { } else { final JavaTypeDescriptor compositeTypeDescriptor; - if ( attributeSource.getTypeDescriptor() != null ) { - compositeTypeDescriptor = attributeSource.getTypeDescriptor(); + if ( attributeSource.getEmbeddableSource().getTypeDescriptor() != null ) { + compositeTypeDescriptor = attributeSource.getEmbeddableSource().getTypeDescriptor(); } else { final EntityMode entityMode = @@ -1826,26 +1886,30 @@ public class Binder { composite = (Aggregate) attribute.getSingularAttributeType(); } - final SingularAttribute referencingAttribute = StringHelper.isEmpty( attributeSource.getParentReferenceAttributeName() ) + final SingularAttribute referencingAttribute = StringHelper.isEmpty( attributeSource.getEmbeddableSource().getParentReferenceAttributeName() ) ? null - : composite.createSingularAttribute( attributeSource.getParentReferenceAttributeName() ); + : composite.createSingularAttribute( attributeSource.getEmbeddableSource().getParentReferenceAttributeName() ); final NaturalIdMutability naturalIdMutability = attributeSource.getNaturalIdMutability(); - final CompositeAttributeBinding attributeBinding = - attributeBindingContainer.makeAggregatedCompositeAttributeBinding( - attribute, - referencingAttribute, - propertyAccessorName( attributeSource ), - attributeSource.isIncludedInOptimisticLocking(), - attributeSource.isLazy(), - naturalIdMutability, - createMetaAttributeContext( attributeBindingContainer, attributeSource ) - ); - if ( attributeSource.getExplicitTuplizerClassName() != null ) { - Class tuplizerClass = localBindingContext().getBuildingOptions().getServiceRegistry() + + Class tuplizerClass = null; + if ( attributeSource.getEmbeddableSource().getExplicitTuplizerClassName() != null ) { + tuplizerClass = localBindingContext().getBuildingOptions().getServiceRegistry() .getService( ClassLoaderService.class ) - .classForName( attributeSource.getExplicitTuplizerClassName() ); - attributeBinding.setCustomComponentTuplizerClass( tuplizerClass ); + .classForName( attributeSource.getEmbeddableSource().getExplicitTuplizerClassName() ); } + final EmbeddedAttributeBinding attributeBinding = attributeBindingContainer.makeAggregatedCompositeAttributeBinding( + attribute, + referencingAttribute, + tuplizerClass, + propertyAccessorName( attributeSource ), + attributeSource.isIncludedInOptimisticLocking(), + attributeSource.isLazy(), + naturalIdMutability, + createMetaAttributeContext( attributeBindingContainer, attributeSource ), + attributeSource.getAttributeRole(), + attributeSource.getAttributePath() + ); + return attributeBinding; } @@ -1886,6 +1950,8 @@ public class Binder { attributeSource.isIgnoreNotFound(), attributeSource.getNaturalIdMutability(), createMetaAttributeContext( attributeBindingContainer, attributeSource ), + attributeSource.getAttributeRole(), + attributeSource.getAttributePath(), referencedEntityBinding, referencedAttributeBinding ); @@ -1924,9 +1990,9 @@ public class Binder { final SingularAttributeBinding idAttributeBinding = referencedEntityBinding.getHierarchyDetails().getEntityIdentifier().getAttributeBinding(); - final String uniqueKeyAttributeName = idAttributeBinding == referencedAttributeBinding ? - null : - getRelativePathFromEntityName( referencedAttributeBinding ); + final String uniqueKeyAttributeName = idAttributeBinding == referencedAttributeBinding + ? null + : referencedAttributeBinding.getAttributePath().getFullPath(); final Type resolvedType = rootBindingContext.getMetadataCollector().getTypeResolver().getTypeFactory().manyToOne( referencedEntityBinding.getEntityName(), @@ -1987,6 +2053,8 @@ public class Binder { attributeSource.isLazy(), attributeSource.getNaturalIdMutability(), createMetaAttributeContext( attributeBindingContainer, attributeSource ), + attributeSource.getAttributeRole(), + attributeSource.getAttributePath(), referencedEntityBinding, referencedAttributeBinding, attributeSource.getForeignKeyDirection() == ForeignKeyDirection.FROM_PARENT @@ -2028,7 +2096,7 @@ public class Binder { uniqueKeyAttributeName = null; } else { - uniqueKeyAttributeName = getRelativePathFromEntityName( referencedAttributeBinding ); + uniqueKeyAttributeName = referencedAttributeBinding.getAttributePath().getFullPath(); } final Type resolvedType; if ( attributeSource.isMappedBy() || attributeSource.relationalValueSources().isEmpty() ) { @@ -2090,7 +2158,7 @@ public class Binder { private AbstractPluralAttributeBinding bindPluralAttribute( final AttributeBindingContainer attributeBindingContainer, final PluralAttributeSource attributeSource) { - final PluralAttributeSource.Nature nature = attributeSource.getNature(); + final PluralAttributeNature nature = attributeSource.getNature(); final PluralAttribute attribute = attributeBindingContainer.getAttributeContainer().locatePluralAttribute( attributeSource.getName() ); final AbstractPluralAttributeBinding attributeBinding; @@ -2230,7 +2298,9 @@ public class Binder { determinePluralAttributeKeyReferencedBinding( attributeBindingContainer, attributeSource ), propertyAccessorName( attributeSource ), attributeSource.isIncludedInOptimisticLocking(), - createMetaAttributeContext( attributeBindingContainer, attributeSource ) + createMetaAttributeContext( attributeBindingContainer, attributeSource ), + attributeSource.getAttributeRole(), + attributeSource.getAttributePath() ); } @@ -2248,6 +2318,8 @@ public class Binder { propertyAccessorName( attributeSource ), attributeSource.isIncludedInOptimisticLocking(), createMetaAttributeContext( attributeBindingContainer, attributeSource ), + attributeSource.getAttributeRole(), + attributeSource.getAttributePath(), getSequentialPluralAttributeIndexBase( attributeSource ) ); } @@ -2266,22 +2338,24 @@ public class Binder { propertyAccessorName( attributeSource ), attributeSource.isIncludedInOptimisticLocking(), createMetaAttributeContext( attributeBindingContainer, attributeSource ), + attributeSource.getAttributeRole(), + attributeSource.getAttributePath(), getSequentialPluralAttributeIndexBase( attributeSource ) ); } private int getSequentialPluralAttributeIndexBase(IndexedPluralAttributeSource pluralAttributeSource) { final PluralAttributeIndexSource indexedPluralAttributeSource = pluralAttributeSource.getIndexSource(); - if ( ! SequentialPluralAttributeIndexSource.class.isInstance( indexedPluralAttributeSource ) ) { + if ( ! PluralAttributeSequentialIndexSource.class.isInstance( indexedPluralAttributeSource ) ) { throw new IllegalArgumentException( String.format( "Expected an argument of type: %s; instead, got %s", - SequentialPluralAttributeIndexSource.class.getName(), + PluralAttributeSequentialIndexSource.class.getName(), indexedPluralAttributeSource.getClass().getName() ) ); } - return ( (SequentialPluralAttributeIndexSource) indexedPluralAttributeSource ).base(); + return ( (PluralAttributeSequentialIndexSource) indexedPluralAttributeSource ).base(); } private AbstractPluralAttributeBinding bindMapAttribute( @@ -2298,8 +2372,9 @@ public class Binder { determinePluralAttributeKeyReferencedBinding( attributeBindingContainer, attributeSource ), propertyAccessorName( attributeSource ), attributeSource.isIncludedInOptimisticLocking(), - - createMetaAttributeContext( attributeBindingContainer, attributeSource ) + createMetaAttributeContext( attributeBindingContainer, attributeSource ), + attributeSource.getAttributeRole(), + attributeSource.getAttributePath() ); } @@ -2316,7 +2391,9 @@ public class Binder { determinePluralAttributeKeyReferencedBinding( attributeBindingContainer, attributeSource ), propertyAccessorName( attributeSource ), attributeSource.isIncludedInOptimisticLocking(), - createMetaAttributeContext( attributeBindingContainer, attributeSource ) + createMetaAttributeContext( attributeBindingContainer, attributeSource ), + attributeSource.getAttributeRole(), + attributeSource.getAttributePath() ); } @@ -2324,8 +2401,8 @@ public class Binder { //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ collection attributes binding private void bindBasicCollectionElement( - final BasicPluralAttributeElementBinding elementBinding, - final BasicPluralAttributeElementSource elementSource, + final PluralAttributeElementBindingBasic elementBinding, + final PluralAttributeElementSourceBasic elementSource, final JavaTypeDescriptor defaultElementJavaClassReference) { bindBasicPluralElementRelationalValues( elementSource, elementBinding ); typeHelper().bindBasicCollectionElementType( elementBinding, elementSource, defaultElementJavaClassReference ); @@ -2339,8 +2416,8 @@ public class Binder { private void bindNonAssociationCollectionKey( final AbstractPluralAttributeBinding attributeBinding, final PluralAttributeSource attributeSource) { - if ( attributeSource.getElementSource().getNature() != PluralAttributeElementSource.Nature.BASIC && - attributeSource.getElementSource().getNature() != PluralAttributeElementSource.Nature.AGGREGATE ) { + if ( attributeSource.getElementSource().getNature() != PluralAttributeElementNature.BASIC && + attributeSource.getElementSource().getNature() != PluralAttributeElementNature.AGGREGATE ) { throw new AssertionFailure( String.format( "Expected basic or aggregate attribute binding; instead got {%s}", @@ -2366,43 +2443,74 @@ public class Binder { ); } + private Aggregate findOrBuildAggregate(JavaTypeDescriptor embeddableDescriptor) { + org.hibernate.metamodel.spi.domain.Type domainType = domainModelTypes.get( embeddableDescriptor ); + if ( domainType == null ) { + domainType = new Aggregate( embeddableDescriptor, null ); + domainModelTypes.put( embeddableDescriptor, domainType ); + } + + if ( !Aggregate.class.isInstance( domainType ) ) { + throw new IllegalStateException( + String.format( + Locale.ENGLISH, + "Found previously built domain type for Aggregate JavaTypeDescriptor [%s] which was not Aggregate : %s", + embeddableDescriptor.getName(), + domainType.getName() + ) + ); + } + + return (Aggregate) domainType; + } + private void bindCompositeCollectionElement( - final CompositePluralAttributeElementBinding elementBinding, - final CompositePluralAttributeElementSource elementSource, + final PluralAttributeElementBindingEmbedded elementBinding, + final PluralAttributeElementSourceEmbedded elementSource, final JavaTypeDescriptor reflectedElementTypeDescriptor) { final PluralAttributeBinding pluralAttributeBinding = elementBinding.getPluralAttributeBinding(); // Create the aggregate type - // TODO: aggregateName should be set to elementSource.getPath() (which is currently not implemented) - // or Binder should define AttributeBindingContainer paths instead. final JavaTypeDescriptor elementTypeDescriptor; - if ( elementSource.getTypeDescriptor() != null ) { - elementTypeDescriptor = elementSource.getTypeDescriptor(); + if ( elementSource.getEmbeddableSource().getTypeDescriptor() != null ) { + elementTypeDescriptor = elementSource.getEmbeddableSource().getTypeDescriptor(); } else { elementTypeDescriptor = reflectedElementTypeDescriptor; } - final Aggregate aggregate = new Aggregate( - elementTypeDescriptor, - null - ); - final SingularAttribute parentAttribute = - StringHelper.isEmpty( elementSource.getParentReferenceAttributeName() ) - ? null - : aggregate.createSingularAttribute( elementSource.getParentReferenceAttributeName() ); - final CompositeAttributeBindingContainer compositeAttributeBindingContainer = - elementBinding.createCompositeAttributeBindingContainer( - aggregate, - createMetaAttributeContext( - pluralAttributeBinding.getContainer(), - elementSource.getToolingHintSources() - ), - parentAttribute - ); - bindAttributes( compositeAttributeBindingContainer, elementSource ); + final Aggregate aggregate = findOrBuildAggregate( elementTypeDescriptor ); + + final String parentReferenceAttributeName = StringHelper.nullIfEmpty( + elementSource.getEmbeddableSource().getParentReferenceAttributeName() + ); + final SingularAttribute parentAttribute = parentReferenceAttributeName == null + ? null + : aggregate.createSingularAttribute( parentReferenceAttributeName ); + + Class tuplizerClass = null; + final String tuplizerClassName = elementSource.getEmbeddableSource().getExplicitTuplizerClassName(); + if ( StringHelper.isNotEmpty( tuplizerClassName ) ) { + tuplizerClass = localBindingContext().getBuildingOptions() + .getServiceRegistry() + .getService( ClassLoaderService.class ) + .classForName( tuplizerClassName ); + } + + final EmbeddableBinding embeddableBinding = elementBinding.createBindingContainer( + aggregate, + createMetaAttributeContext( + pluralAttributeBinding.getContainer(), + elementSource.getToolingHintSources() + ), + parentAttribute, + tuplizerClass + ); + + bindAttributes( embeddableBinding, elementSource.getEmbeddableSource() ); + pluralAttributeBinding.getAttribute().setElementType( aggregate ); Type resolvedType = rootBindingContext.getMetadataCollector().getTypeResolver().getTypeFactory().component( - new ComponentMetamodel( rootBindingContext.getServiceRegistry(), compositeAttributeBindingContainer, false, false ) + new ComponentMetamodel( rootBindingContext.getServiceRegistry(), embeddableBinding, false, false ) ); // TODO: binding the HibernateTypeDescriptor should be simplified since we know the class name already typeHelper().bindHibernateTypeDescriptor( @@ -2418,7 +2526,7 @@ public class Binder { * * and not sure if this is the right place to apply this logic, apparently source level is not okay, so here it is, for now. */ - for ( AttributeBinding ab : compositeAttributeBindingContainer.attributeBindings() ) { + for ( AttributeBinding ab : embeddableBinding.attributeBindings() ) { if ( ab.isCascadeable() ) { final Cascadeable cascadeable; if ( ab.getAttribute().isSingular() ) { @@ -2438,16 +2546,71 @@ public class Binder { } } + private void bindListIndex( + IndexedPluralAttributeBinding attributeBinding, + PluralAttributeSequentialIndexSource indexSource, + JavaTypeDescriptor reflectedIndexTypeDescriptor) { + final BasicPluralAttributeIndexBinding indexBinding = + (BasicPluralAttributeIndexBinding) attributeBinding.getPluralAttributeIndexBinding(); + // TODO: need to resolve default column names. + indexBinding.setRelationalValueBindings( + relationalValueBindingHelper().createRelationalValueBindings( + attributeBinding.getContainer(), + indexSource, + attributeBinding.getPluralAttributeKeyBinding().getCollectionTable(), + indexSource.getDefaultNamingStrategies(), + true + ) + ); + + typeHelper().bindHibernateTypeDescriptor( + indexBinding.getHibernateTypeDescriptor(), + indexSource.getTypeInformation(), + Primitives.INTEGER.getPrimitiveType() + ); + typeHelper().bindJdbcDataType( + indexBinding.getHibernateTypeDescriptor().getResolvedTypeMapping(), + indexBinding.getRelationalValueBindings() + ); + + IndexedPluralAttribute indexedPluralAttribute = + (IndexedPluralAttribute) indexBinding.getIndexedPluralAttributeBinding().getAttribute(); + + // todo : we need to centralize this stuff somewhere... + final HibernateTypeDescriptor hibernateTypeDescriptor = indexBinding.getHibernateTypeDescriptor(); + final BasicType basicType; + if ( hibernateTypeDescriptor.getJavaTypeDescriptor() != null ) { + basicType = (BasicType) localBindingContext().makeDomainType( + hibernateTypeDescriptor.getJavaTypeDescriptor().getName() + ); + } + else if ( hibernateTypeDescriptor.getResolvedTypeMapping() != null ) { + basicType = (BasicType) localBindingContext().makeDomainType( + hibernateTypeDescriptor.getResolvedTypeMapping().getName() + ); + } + else if ( hibernateTypeDescriptor.getExplicitTypeName() != null ) { + basicType = (BasicType) localBindingContext().makeDomainType( + hibernateTypeDescriptor.getExplicitTypeName() + ); + } + else { + basicType = new BasicType( hibernateTypeDescriptor.getJavaTypeDescriptor() ); + } + + indexedPluralAttribute.setIndexType( basicType ); + } + private void bindEntityAttributePluralAttributeIndex( final IndexedPluralAttributeBinding attributeBinding, - final EntityAttributePluralAttributeIndexSource indexSource, + final PluralAttributeMapKeySourceEntityAttribute indexSource, final JavaTypeDescriptor defaultIndexTypeDescriptor) { throw new NotYetImplementedException( "Plural attribute index that is an attribute of the referenced entity is not supported yet." ); } private void bindBasicCollectionIndex( final IndexedPluralAttributeBinding attributeBinding, - final BasicPluralAttributeIndexSource indexSource, + final PluralAttributeMapKeySourceBasic indexSource, final JavaTypeDescriptor defaultIndexTypeDescriptor) { final BasicPluralAttributeIndexBinding indexBinding = (BasicPluralAttributeIndexBinding) attributeBinding.getPluralAttributeIndexBinding(); @@ -2459,7 +2622,7 @@ public class Binder { attributeBinding.getPluralAttributeKeyBinding().getCollectionTable(), indexSource.getDefaultNamingStrategies(), attributeBinding.getPluralAttributeElementBinding() - .getNature() != PluralAttributeElementBinding.Nature.ONE_TO_MANY + .getNature() != PluralAttributeElementNature.ONE_TO_MANY ) ); // TODO: create a foreign key if non-inverse and the index is an association @@ -2505,35 +2668,31 @@ public class Binder { final CompositePluralAttributeIndexBinding indexBinding, final IndexedPluralAttributeSource indexedPluralAttributeSource, final JavaTypeDescriptor reflectedIndexTypeDescriptor) { - final CompositePluralAttributeIndexSource indexSource = - (CompositePluralAttributeIndexSource) indexedPluralAttributeSource.getIndexSource(); + final PluralAttributeMapKeySourceEmbedded indexSource = + (PluralAttributeMapKeySourceEmbedded) indexedPluralAttributeSource.getIndexSource(); final JavaTypeDescriptor indexTypeDescriptor; - if ( indexSource.getTypeDescriptor() != null ) { - indexTypeDescriptor = indexSource.getTypeDescriptor(); + if ( indexSource.getEmbeddableSource().getTypeDescriptor() != null ) { + indexTypeDescriptor = indexSource.getEmbeddableSource().getTypeDescriptor(); } else { indexTypeDescriptor = reflectedIndexTypeDescriptor; } - // Create the aggregate type - // TODO: aggregateName should be set to elementSource.getPath() (which is currently not implemented) - // or Binder should define AttributeBindingContainer paths instead. - final Aggregate aggregate = new Aggregate( - indexTypeDescriptor, + + final Aggregate aggregate = findOrBuildAggregate( indexTypeDescriptor ); + + final EmbeddableBinding embeddableBinding = indexBinding.createCompositeAttributeBindingContainer( + aggregate, + null, + null, null ); - final CompositeAttributeBindingContainer compositeAttributeBindingContainer = - indexBinding.createCompositeAttributeBindingContainer( - aggregate, - null, - null - ); - bindAttributes( compositeAttributeBindingContainer, indexSource ); + bindAttributes( embeddableBinding, indexSource.getEmbeddableSource() ); Type resolvedType = rootBindingContext.getMetadataCollector().getTypeResolver().getTypeFactory().component( new ComponentMetamodel( rootBindingContext.getServiceRegistry(), - compositeAttributeBindingContainer, + embeddableBinding, false, false ) @@ -2552,8 +2711,8 @@ public class Binder { } private void bindOneToManyCollectionElement( - final OneToManyPluralAttributeElementBinding elementBinding, - final OneToManyPluralAttributeElementSource elementSource, + final PluralAttributeElementBindingOneToMany elementBinding, + final PluralAttributeElementSourceOneToMany elementSource, final EntityBinding referencedEntityBinding, final JavaTypeDescriptor defaultElementTypeDescriptor) { elementBinding.setElementEntityIdentifier( @@ -2590,8 +2749,8 @@ public class Binder { } private void bindManyToManyCollectionElement( - final ManyToManyPluralAttributeElementBinding elementBinding, - final ManyToManyPluralAttributeElementSource elementSource, + final PluralAttributeElementBindingManyToMany elementBinding, + final PluralAttributeElementSourceManyToMany elementSource, final EntityBinding referencedEntityBinding, final JavaTypeDescriptor defaultElementTypeDescriptor) { final TableSpecification collectionTable = @@ -2648,7 +2807,7 @@ public class Binder { final AbstractPluralAttributeBinding attributeBinding, final PluralAttributeSource attributeSource, final EntityBinding referencedEntityBinding) { - if ( attributeSource.getElementSource().getNature() != PluralAttributeElementSource.Nature.ONE_TO_MANY ) { + if ( attributeSource.getElementSource().getNature() != PluralAttributeElementNature.ONE_TO_MANY ) { throw new AssertionFailure( String.format( "Expected one-to-many attribute binding; instead got {%s}", @@ -2669,7 +2828,7 @@ public class Binder { final AbstractPluralAttributeBinding attributeBinding, final PluralAttributeSource attributeSource, final EntityBinding referencedEntityBinding) { - if ( attributeSource.getElementSource().getNature() != PluralAttributeElementSource.Nature.MANY_TO_MANY ) { + if ( attributeSource.getElementSource().getNature() != PluralAttributeElementNature.MANY_TO_MANY ) { throw new AssertionFailure( String.format( "Expected many-to-many attribute binding; instead got {%s}", @@ -2680,7 +2839,7 @@ public class Binder { final AssociationRelationalBindingResolver resolver = getAssociationRelationalBindingResolver( attributeSource ); final TableSpecification collectionTable = resolver.resolveManyToManyCollectionTable( attributeSource, - createAttributePath( attributeBinding ), + attributeSource.getAttributePath().getFullPath(), attributeBinding.getContainer().seekEntityBinding(), referencedEntityBinding ); @@ -2697,10 +2856,10 @@ public class Binder { reflectedCollectionJavaTypes ); final PluralAttributeIndexSource indexSource = attributeSource.getIndexSource(); - if ( indexSource.isReferencedEntityAttribute() ) { + if ( PluralAttributeMapKeySourceEntityAttribute.class.isInstance( indexSource ) ) { bindEntityAttributePluralAttributeIndex( attributeBinding, - (EntityAttributePluralAttributeIndexSource) indexSource, + (PluralAttributeMapKeySourceEntityAttribute) indexSource, reflectedIndexTypeDescriptor ); } @@ -2709,7 +2868,7 @@ public class Binder { case BASIC: { bindBasicCollectionIndex( attributeBinding, - (BasicPluralAttributeIndexSource) attributeSource.getIndexSource(), + (PluralAttributeMapKeySourceBasic) attributeSource.getIndexSource(), reflectedIndexTypeDescriptor ); break; @@ -2722,6 +2881,15 @@ public class Binder { ); break; } + case SEQUENTIAL: { + // easy peasy, we have an array/list index + bindListIndex( + attributeBinding, + (PluralAttributeSequentialIndexSource) attributeSource.getIndexSource(), + reflectedIndexTypeDescriptor + ); + break; + } default: { throw new NotYetImplementedException( String.format( @@ -2732,7 +2900,7 @@ public class Binder { } } if ( attributeBinding.getPluralAttributeElementBinding() - .getNature() == PluralAttributeElementBinding.Nature.ONE_TO_MANY ) { + .getNature() == PluralAttributeElementNature.ONE_TO_MANY ) { for ( RelationalValueBinding relationalValueBinding : attributeBinding.getPluralAttributeIndexBinding().getRelationalValueBindings() ) { if ( Column.class.isInstance( relationalValueBinding.getValue() ) ) { // TODO: fix this when column nullability is refactored @@ -2750,8 +2918,8 @@ public class Binder { final ReflectedCollectionJavaTypes reflectedCollectionJavaTypes) { bindNonAssociationCollectionKey( attributeBinding, attributeSource ); bindCompositeCollectionElement( - (CompositePluralAttributeElementBinding) attributeBinding.getPluralAttributeElementBinding(), - (CompositePluralAttributeElementSource) attributeSource.getElementSource(), + (PluralAttributeElementBindingEmbedded) attributeBinding.getPluralAttributeElementBinding(), + (PluralAttributeElementSourceEmbedded) attributeSource.getElementSource(), typeHelper().reflectedCollectionElementJavaType( reflectedCollectionJavaTypes ) ); } @@ -2760,8 +2928,8 @@ public class Binder { final PluralAttributeSource attributeSource, final AbstractPluralAttributeBinding attributeBinding, final ReflectedCollectionJavaTypes reflectedCollectionJavaTypes) { - final ManyToManyPluralAttributeElementSource elementSource = - (ManyToManyPluralAttributeElementSource) attributeSource.getElementSource(); + final PluralAttributeElementSourceManyToMany elementSource = + (PluralAttributeElementSourceManyToMany) attributeSource.getElementSource(); final JavaTypeDescriptor reflectedElementTypeDescriptor = typeHelper().reflectedCollectionElementJavaType( reflectedCollectionJavaTypes ); @@ -2769,7 +2937,7 @@ public class Binder { throw localBindingContext().makeMappingException( String.format( "The mapping for the entity associated with one-to-many attribute (%s) is undefined.", - createAttributePathQualifiedByEntityName( attributeBinding ) + attributeSource.getAttributeRole().getFullPath() ) ); } @@ -2777,7 +2945,7 @@ public class Binder { reflectedElementTypeDescriptor, elementSource.getReferencedEntityName() ); - ManyToManyPluralAttributeElementBinding manyToManyPluralAttributeElementBinding = (ManyToManyPluralAttributeElementBinding) attributeBinding + PluralAttributeElementBindingManyToMany manyToManyPluralAttributeElementBinding = (PluralAttributeElementBindingManyToMany) attributeBinding .getPluralAttributeElementBinding(); if ( elementSource.getFilterSources() != null ) { @@ -2793,7 +2961,7 @@ public class Binder { bindManyToManyCollectionKey( attributeBinding, attributeSource, referencedEntityBinding ); bindManyToManyCollectionElement( manyToManyPluralAttributeElementBinding, - (ManyToManyPluralAttributeElementSource) attributeSource.getElementSource(), + (PluralAttributeElementSourceManyToMany) attributeSource.getElementSource(), referencedEntityBinding, reflectedElementTypeDescriptor ); @@ -2803,8 +2971,8 @@ public class Binder { final PluralAttributeSource attributeSource, final AbstractPluralAttributeBinding attributeBinding, final ReflectedCollectionJavaTypes reflectedCollectionJavaTypes) { - final OneToManyPluralAttributeElementSource elementSource = - (OneToManyPluralAttributeElementSource) attributeSource.getElementSource(); + final PluralAttributeElementSourceOneToMany elementSource = + (PluralAttributeElementSourceOneToMany) attributeSource.getElementSource(); final JavaTypeDescriptor defaultElementTypeDescriptor = typeHelper().reflectedCollectionElementJavaType( reflectedCollectionJavaTypes ); @@ -2812,7 +2980,7 @@ public class Binder { throw localBindingContext().makeMappingException( String.format( "The mapping for the entity associated with one-to-many attribute (%s) is undefined.", - createAttributePathQualifiedByEntityName( attributeBinding ) + attributeSource.getAttributeRole().getFullPath() ) ); } @@ -2822,8 +2990,8 @@ public class Binder { ); bindOneToManyCollectionKey( attributeBinding, attributeSource, referencedEntityBinding ); bindOneToManyCollectionElement( - (OneToManyPluralAttributeElementBinding) attributeBinding.getPluralAttributeElementBinding(), - (OneToManyPluralAttributeElementSource) attributeSource.getElementSource(), + (PluralAttributeElementBindingOneToMany) attributeBinding.getPluralAttributeElementBinding(), + (PluralAttributeElementSourceOneToMany) attributeSource.getElementSource(), referencedEntityBinding, defaultElementTypeDescriptor ); @@ -2835,8 +3003,8 @@ public class Binder { final ReflectedCollectionJavaTypes reflectedCollectionJavaTypes) { bindNonAssociationCollectionKey( attributeBinding, attributeSource ); bindBasicCollectionElement( - (BasicPluralAttributeElementBinding) attributeBinding.getPluralAttributeElementBinding(), - (BasicPluralAttributeElementSource) attributeSource.getElementSource(), + (PluralAttributeElementBindingBasic) attributeBinding.getPluralAttributeElementBinding(), + (PluralAttributeElementSourceBasic) attributeSource.getElementSource(), typeHelper().reflectedCollectionElementJavaType( reflectedCollectionJavaTypes ) ); } @@ -2889,7 +3057,7 @@ public class Binder { //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ relational binding relates methods private void bindBasicPluralElementRelationalValues( final RelationalValueSourceContainer relationalValueSourceContainer, - final BasicPluralAttributeElementBinding elementBinding) { + final PluralAttributeElementBindingBasic elementBinding) { elementBinding.setRelationalValueBindings( relationalValueBindingHelper().createRelationalValueBindings( elementBinding.getPluralAttributeBinding().getContainer(), @@ -2903,7 +3071,7 @@ public class Binder { private void bindSetCollectionTablePrimaryKey(final SetBinding attributeBinding) { // only bind the primary key if there is a non-nullable element value. - if ( !attributeBinding.getPluralAttributeElementBinding().hasNonNullableValue() ) { + if ( !attributeBinding.getPluralAttributeElementBinding().getRelationalValueContainer().hasNonNullableRelationalValueBinding() ) { return; } @@ -2917,7 +3085,8 @@ public class Binder { for ( final RelationalValueBinding keyRelationalValueBinding : keyValueBindings ) { primaryKey.addColumn( (Column) keyRelationalValueBinding.getValue() ); } - for ( final RelationalValueBinding elementValueBinding : elementBinding.getRelationalValueBindings() ) { + for ( final RelationalValueBinding elementValueBinding + : elementBinding.getRelationalValueContainer().relationalValueBindings() ) { if ( !elementValueBinding.isDerived() && !elementValueBinding.isNullable() ) { primaryKey.addColumn( (Column) elementValueBinding.getValue() ); } @@ -2965,12 +3134,12 @@ public class Binder { private void bindCollectionTablePrimaryKey( final AbstractPluralAttributeBinding attributeBinding, final PluralAttributeSource attributeSource) { - final PluralAttributeSource.Nature pluralAttributeSourceNature = attributeSource.getNature(); - final PluralAttributeElementSource.Nature pluralElementSourceNature = attributeSource.getElementSource().getNature(); + final PluralAttributeNature pluralAttributeSourceNature = attributeSource.getNature(); + final PluralAttributeElementNature pluralElementSourceNature = attributeSource.getElementSource().getNature(); //TODO what is this case? it would be really good to add a comment - if ( pluralElementSourceNature == PluralAttributeElementSource.Nature.ONE_TO_MANY - || pluralAttributeSourceNature == PluralAttributeSource.Nature.BAG ) { + if ( pluralElementSourceNature == PluralAttributeElementNature.ONE_TO_MANY + || pluralAttributeSourceNature == PluralAttributeNature.BAG ) { return; } if ( !attributeBinding.getPluralAttributeKeyBinding().isInverse() ) { @@ -3073,17 +3242,17 @@ public class Binder { attributeBindingContainer.seekEntityBinding().locateTable( attributeSource.getContainingTableName() ); } - private static PluralAttributeElementBinding.Nature pluralAttributeElementNature( + private static PluralAttributeElementNature pluralAttributeElementNature( final PluralAttributeSource attributeSource) { - return PluralAttributeElementBinding.Nature.valueOf( attributeSource.getElementSource().getNature().name() ); + return attributeSource.getElementSource().getNature(); } - private static PluralAttributeIndexBinding.Nature pluralAttributeIndexNature( + private static PluralAttributeIndexNature pluralAttributeIndexNature( final PluralAttributeSource attributeSource) { if ( !IndexedPluralAttributeSource.class.isInstance( attributeSource ) ) { return null; } - return PluralAttributeIndexBinding.Nature.valueOf( + return PluralAttributeIndexNature.valueOf( ( (IndexedPluralAttributeSource) attributeSource ).getIndexSource().getNature().name() ); } @@ -3103,11 +3272,12 @@ public class Binder { // the index has as formula; // only create the primary key if there are non-nullable element columns final PluralAttributeElementBinding pluralAttributeElementBinding = attributeBinding.getPluralAttributeElementBinding(); - if ( pluralAttributeElementBinding.hasNonNullableValue() ) { + if ( pluralAttributeElementBinding.getRelationalValueContainer().hasNonNullableRelationalValueBinding() ) { for ( final RelationalValueBinding keyRelationalValueBinding : keyRelationalValueBindings ) { primaryKey.addColumn( (Column) keyRelationalValueBinding.getValue() ); } - for ( RelationalValueBinding relationalValueBinding : pluralAttributeElementBinding.getRelationalValueBindings() ) { + for ( RelationalValueBinding relationalValueBinding + : pluralAttributeElementBinding.getRelationalValueContainer().relationalValueBindings() ) { if ( !relationalValueBinding.isDerived() && !relationalValueBinding.isNullable() && relationalValueBinding.getTable().equals( collectionTable ) ){ @@ -3129,14 +3299,6 @@ public class Binder { } } - - private static String getRelativePathFromEntityName( - final AttributeBinding attributeBinding) { - return StringHelper.isEmpty( attributeBinding.getContainer().getPathBase() ) ? - attributeBinding.getAttribute().getName() : - attributeBinding.getContainer().getPathBase() + "." + attributeBinding.getAttribute().getName(); - } - // TODO: should this be moved to CascadeStyles as a static method? // TODO: sources already factor in default cascade; should that be done here instead? private static CascadeStyle determineCascadeStyle( @@ -3208,18 +3370,7 @@ public class Binder { attributeBindingContainer.getAttributeContainer().createSingularAttribute( attributeSource.getName() ); } - static String createAttributePathQualifiedByEntityName(final AttributeBinding attributeBinding) { - final String entityName = attributeBinding.getContainer().seekEntityBinding().getEntityName(); - return entityName + '.' + createAttributePath( attributeBinding ); - } - static String createAttributePath(final AttributeBinding attributeBinding) { - return StringHelper.isEmpty( attributeBinding.getContainer().getPathBase() ) ? - attributeBinding.getAttribute().getName() : - attributeBinding.getContainer().getPathBase() + '.' + attributeBinding.getAttribute().getName(); - } - public static interface DefaultNamingStrategy { - String defaultName(NamingStrategy namingStrategy); } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/binder/CollectionTableNamingStrategyHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/binder/CollectionTableNamingStrategyHelper.java index 6b07f50730..40e99f0481 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/binder/CollectionTableNamingStrategyHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/binder/CollectionTableNamingStrategyHelper.java @@ -35,7 +35,7 @@ public class CollectionTableNamingStrategyHelper extends TableNamingStrategyHelp public CollectionTableNamingStrategyHelper(final AbstractPluralAttributeBinding pluralAttributeBinding) { super( pluralAttributeBinding.getContainer().seekEntityBinding() ); - this.propertyName = Binder.createAttributePath( pluralAttributeBinding ); + this.propertyName = pluralAttributeBinding.getAttribute().getName(); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/binder/HibernateTypeHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/binder/HibernateTypeHelper.java index ef3f8221be..4afae81cc6 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/binder/HibernateTypeHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/binder/HibernateTypeHelper.java @@ -44,25 +44,26 @@ import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; import org.hibernate.metamodel.reflite.spi.MethodDescriptor; import org.hibernate.metamodel.reflite.spi.PrimitiveTypeDescriptor; import org.hibernate.metamodel.source.spi.AttributeSource; -import org.hibernate.metamodel.source.spi.BasicPluralAttributeElementSource; -import org.hibernate.metamodel.source.spi.ComponentAttributeSource; +import org.hibernate.metamodel.source.spi.EmbeddedAttributeSource; import org.hibernate.metamodel.source.spi.HibernateTypeSource; import org.hibernate.metamodel.source.spi.IdentifiableTypeSource; -import org.hibernate.metamodel.source.spi.ManyToManyPluralAttributeElementSource; +import org.hibernate.metamodel.source.spi.PluralAttributeElementSourceBasic; +import org.hibernate.metamodel.source.spi.PluralAttributeElementSourceManyToMany; import org.hibernate.metamodel.source.spi.PluralAttributeSource; import org.hibernate.metamodel.source.spi.SingularAttributeSource; import org.hibernate.metamodel.spi.InFlightMetadataCollector; +import org.hibernate.metamodel.spi.PluralAttributeElementNature; +import org.hibernate.metamodel.spi.PluralAttributeNature; import org.hibernate.metamodel.spi.binding.AttributeBinding; import org.hibernate.metamodel.spi.binding.BasicAttributeBinding; -import org.hibernate.metamodel.spi.binding.BasicPluralAttributeElementBinding; -import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding; +import org.hibernate.metamodel.spi.binding.EmbeddedAttributeBinding; import org.hibernate.metamodel.spi.binding.EntityBinding; import org.hibernate.metamodel.spi.binding.EntityDiscriminator; import org.hibernate.metamodel.spi.binding.EntityIdentifier; import org.hibernate.metamodel.spi.binding.HibernateTypeDescriptor; -import org.hibernate.metamodel.spi.binding.ManyToManyPluralAttributeElementBinding; import org.hibernate.metamodel.spi.binding.PluralAttributeBinding; -import org.hibernate.metamodel.spi.binding.PluralAttributeElementBinding; +import org.hibernate.metamodel.spi.binding.PluralAttributeElementBindingBasic; +import org.hibernate.metamodel.spi.binding.PluralAttributeElementBindingManyToMany; import org.hibernate.metamodel.spi.binding.RelationalValueBinding; import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; import org.hibernate.metamodel.spi.binding.TypeDefinition; @@ -381,11 +382,11 @@ class HibernateTypeHelper { final boolean isAttributeIdentifier, final Aggregate composite, final JavaTypeDescriptor defaultTypeDescriptor, - final CompositeAttributeBinding attributeBinding) { + final EmbeddedAttributeBinding attributeBinding) { Type resolvedType = typeFactory().component( new ComponentMetamodel( serviceRegistry, - attributeBinding, + attributeBinding.getEmbeddableBinding(), isAttributeIdentifier, false ) @@ -400,8 +401,8 @@ class HibernateTypeHelper { } void bindBasicCollectionElementType( - final BasicPluralAttributeElementBinding elementBinding, - final BasicPluralAttributeElementSource elementSource, + final PluralAttributeElementBindingBasic elementBinding, + final PluralAttributeElementSourceBasic elementSource, final JavaTypeDescriptor defaultElementTypeDescriptor) { bindHibernateTypeDescriptor( elementBinding.getHibernateTypeDescriptor(), @@ -415,10 +416,10 @@ class HibernateTypeHelper { } void bindNonAggregatedCompositeIdentifierType( final ServiceRegistry serviceRegistry, - final CompositeAttributeBinding syntheticAttributeBinding, + final EmbeddedAttributeBinding syntheticAttributeBinding, final SingularAttribute syntheticAttribute) { final Type resolvedType = typeFactory().embeddedComponent( - new ComponentMetamodel( serviceRegistry, syntheticAttributeBinding, true, false ) + new ComponentMetamodel( serviceRegistry, syntheticAttributeBinding.getEmbeddableBinding(), true, false ) ); final HibernateTypeDescriptor typeDescriptor = syntheticAttributeBinding.getHibernateTypeDescriptor(); final String className = syntheticAttribute.getSingularAttributeType().getDescriptor() == null ? @@ -433,8 +434,8 @@ class HibernateTypeHelper { ); } void bindManyToManyAttributeType( - final ManyToManyPluralAttributeElementBinding elementBinding, - final ManyToManyPluralAttributeElementSource elementSource, + final PluralAttributeElementBindingManyToMany elementBinding, + final PluralAttributeElementSourceManyToMany elementSource, final EntityBinding referencedEntityBinding, final JavaTypeDescriptor defaultElementTypeDescriptor) { final Type resolvedElementType = typeFactory().manyToOne( @@ -455,7 +456,7 @@ class HibernateTypeHelper { ); bindJdbcDataType( resolvedElementType, - elementBinding.getRelationalValueBindings() + elementBinding.getRelationalValueContainer().relationalValueBindings() ); } @@ -508,7 +509,7 @@ class HibernateTypeHelper { ClassLoaderService classLoaderService, final PluralAttributeBinding pluralAttributeBinding, final PluralAttributeSource pluralAttributeSource, - final PluralAttributeSource.Nature nature) { + final PluralAttributeNature nature) { if ( pluralAttributeBinding.getHibernateTypeDescriptor().getExplicitTypeName() != null ) { return resolveCustomCollectionType( pluralAttributeBinding ); } @@ -562,8 +563,8 @@ class HibernateTypeHelper { else if ( pluralAttributeBinding.getOrderBy() != null ) { return typeFactory().orderedSet( role, propertyRef ); } - else if ( pluralAttributeBinding.getPluralAttributeElementBinding().getNature() == PluralAttributeElementBinding.Nature.MANY_TO_MANY && - ( (ManyToManyPluralAttributeElementBinding) pluralAttributeBinding.getPluralAttributeElementBinding() ).getManyToManyOrderBy() != null ) { + else if ( pluralAttributeBinding.getPluralAttributeElementBinding().getNature() == PluralAttributeElementNature.MANY_TO_MANY && + ( (PluralAttributeElementBindingManyToMany) pluralAttributeBinding.getPluralAttributeElementBinding() ).getManyToManyOrderBy() != null ) { return typeFactory().orderedSet( role, propertyRef ); } else { @@ -736,10 +737,10 @@ class HibernateTypeHelper { resolvedHibernateType ); } - else if ( CompositeAttributeBinding.class.isInstance( attributeBinding ) ) { + else if ( EmbeddedAttributeBinding.class.isInstance( attributeBinding ) ) { pushHibernateTypeInformationDown( - (ComponentAttributeSource) attributeSource, - (CompositeAttributeBinding) attributeBinding, + (EmbeddedAttributeSource) attributeSource, + (EmbeddedAttributeBinding) attributeBinding, resolvedHibernateType ); } @@ -763,8 +764,8 @@ class HibernateTypeHelper { @SuppressWarnings({ "UnusedParameters" }) private void pushHibernateTypeInformationDown( - final ComponentAttributeSource attributeSource, - final CompositeAttributeBinding attributeBinding, + final EmbeddedAttributeSource attributeSource, + final EmbeddedAttributeBinding attributeBinding, final Type resolvedHibernateType) { final HibernateTypeDescriptor hibernateTypeDescriptor = attributeBinding.getHibernateTypeDescriptor(); @@ -773,8 +774,8 @@ class HibernateTypeHelper { singularAttribute.resolveType( makeDomainType( hibernateTypeDescriptor.getJavaTypeDescriptor().getName() ) ); } - Iterator subAttributeSourceIterator = attributeSource.attributeSources().iterator(); - for ( AttributeBinding subAttributeBinding : attributeBinding.attributeBindings() ) { + Iterator subAttributeSourceIterator = attributeSource.getEmbeddableSource().attributeSources().iterator(); + for ( AttributeBinding subAttributeBinding : attributeBinding.getEmbeddableBinding().attributeBindings() ) { AttributeSource subAttributeSource = subAttributeSourceIterator.next(); if ( SingularAttributeBinding.class.isInstance( subAttributeBinding ) ) { processSingularAttributeTypeInformation( @@ -834,11 +835,11 @@ class HibernateTypeHelper { } public JavaTypeDescriptor determineJavaType( - final ComponentAttributeSource attributeSource, + final EmbeddedAttributeSource attributeSource, final AttributeContainer attributeContainer, final EntityMode entityMode) { - if ( attributeSource.getTypeDescriptor() != null ) { - return attributeSource.getTypeDescriptor(); + if ( attributeSource.getEmbeddableSource().getTypeDescriptor() != null ) { + return attributeSource.getEmbeddableSource().getTypeDescriptor(); } else if ( entityMode == EntityMode.MAP ) { return bindingContext().typeDescriptor( Map.class.getName() ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/binder/RelationalValueBindingHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/binder/RelationalValueBindingHelper.java index 1266df7991..3b6f49f069 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/binder/RelationalValueBindingHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/binder/RelationalValueBindingHelper.java @@ -35,9 +35,9 @@ import org.hibernate.metamodel.source.spi.DerivedValueSource; import org.hibernate.metamodel.source.spi.RelationalValueSource; import org.hibernate.metamodel.source.spi.RelationalValueSourceContainer; import org.hibernate.metamodel.source.spi.SingularAttributeSource; +import org.hibernate.metamodel.spi.NaturalIdMutability; import org.hibernate.metamodel.spi.binding.AttributeBindingContainer; import org.hibernate.metamodel.spi.binding.RelationalValueBinding; -import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; import org.hibernate.metamodel.spi.domain.Attribute; import org.hibernate.metamodel.spi.relational.Column; import org.hibernate.metamodel.spi.relational.DerivedValue; @@ -92,15 +92,15 @@ public class RelationalValueBindingHelper { final List defaultNameStrategies, final boolean forceNonNullable) { final List valueBindings = new ArrayList(); - final SingularAttributeBinding.NaturalIdMutability naturalIdMutability; + final NaturalIdMutability naturalIdMutability; if ( SingularAttributeSource.class.isInstance( valueSourceContainer ) ) { naturalIdMutability = SingularAttributeSource.class.cast( valueSourceContainer ).getNaturalIdMutability(); } else { - naturalIdMutability = SingularAttributeBinding.NaturalIdMutability.NOT_NATURAL_ID; + naturalIdMutability = NaturalIdMutability.NOT_NATURAL_ID; } - final boolean isNaturalId = naturalIdMutability != SingularAttributeBinding.NaturalIdMutability.NOT_NATURAL_ID; - final boolean isImmutableNaturalId = isNaturalId && ( naturalIdMutability == SingularAttributeBinding.NaturalIdMutability.IMMUTABLE ); + final boolean isNaturalId = naturalIdMutability != NaturalIdMutability.NOT_NATURAL_ID; + final boolean isImmutableNaturalId = isNaturalId && ( naturalIdMutability == NaturalIdMutability.IMMUTABLE ); final boolean reallyForceNonNullable = forceNonNullable ; //|| isNaturalId; todo is a natural id column should be not nullable? if ( valueSourceContainer.relationalValueSources().isEmpty() ) { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/binder/SourceIndex.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/binder/SourceIndex.java index d9a6abecd4..6b0dd05a35 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/binder/SourceIndex.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/binder/SourceIndex.java @@ -26,28 +26,30 @@ package org.hibernate.metamodel.internal.binder; import java.util.Collections; import java.util.EnumMap; import java.util.HashMap; -import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import org.hibernate.AssertionFailure; import org.hibernate.internal.CoreLogging; -import org.hibernate.internal.util.StringHelper; import org.hibernate.metamodel.source.spi.AggregatedCompositeIdentifierSource; import org.hibernate.metamodel.source.spi.AttributeSource; import org.hibernate.metamodel.source.spi.AttributeSourceResolutionContext; -import org.hibernate.metamodel.source.spi.ComponentAttributeSource; +import org.hibernate.metamodel.source.spi.EmbeddedAttributeSource; import org.hibernate.metamodel.source.spi.EntityHierarchySource; import org.hibernate.metamodel.source.spi.EntitySource; import org.hibernate.metamodel.source.spi.IdentifiableTypeSource; import org.hibernate.metamodel.source.spi.IdentifierSource; import org.hibernate.metamodel.source.spi.IndexedPluralAttributeSource; import org.hibernate.metamodel.source.spi.NonAggregatedCompositeIdentifierSource; +import org.hibernate.metamodel.source.spi.PluralAttributeIndexSourceResolver; import org.hibernate.metamodel.source.spi.PluralAttributeSource; import org.hibernate.metamodel.source.spi.SimpleIdentifierSource; import org.hibernate.metamodel.source.spi.SingularAttributeSource; import org.hibernate.metamodel.source.spi.ToOneAttributeSource; +import org.hibernate.metamodel.spi.AttributeRole; +import org.hibernate.metamodel.spi.SingularAttributeNature; import org.hibernate.metamodel.spi.binding.AttributeBinding; import org.hibernate.metamodel.spi.binding.EntityBinding; import org.hibernate.metamodel.spi.relational.Column; @@ -64,12 +66,11 @@ import org.jboss.logging.Logger; public class SourceIndex { private static final Logger log = CoreLogging.logger( SourceIndex.class ); - private static final String EMPTY_STRING = ""; - private final Map entitySourceIndexByEntityName = new HashMap(); - private final Map attributeSourcesByKey = new HashMap(); - private final Map mappedByAttributeKeysByOwnerAttributeKeys = - new HashMap(); + private final Map attributeSourcesByKey = new HashMap(); + + private final Map mappedByAttributeKeysByOwnerAttributeKeys = + new HashMap(); public void indexHierarchy(EntityHierarchySource hierarchy) { @@ -105,21 +106,21 @@ public class SourceIndex { case SIMPLE: { final AttributeSource identifierAttributeSource = ( (SimpleIdentifierSource) identifierSource ).getIdentifierAttributeSource(); - indexAttributeSources( hierarchyInfo, EMPTY_STRING, identifierAttributeSource, true ); + indexAttributeSources( hierarchyInfo, identifierAttributeSource, true ); break; } case NON_AGGREGATED_COMPOSITE: { final List nonAggregatedAttributeSources = ( (NonAggregatedCompositeIdentifierSource) identifierSource ).getAttributeSourcesMakingUpIdentifier(); for ( SingularAttributeSource nonAggregatedAttributeSource : nonAggregatedAttributeSources ) { - indexAttributeSources( hierarchyInfo, EMPTY_STRING, nonAggregatedAttributeSource, true ); + indexAttributeSources( hierarchyInfo, nonAggregatedAttributeSource, true ); } break; } case AGGREGATED_COMPOSITE: { - final ComponentAttributeSource aggregatedAttributeSource = + final EmbeddedAttributeSource aggregatedAttributeSource = ( (AggregatedCompositeIdentifierSource) identifierSource ).getIdentifierAttributeSource(); - indexAttributeSources( hierarchyInfo, EMPTY_STRING, aggregatedAttributeSource, true ); + indexAttributeSources( hierarchyInfo, aggregatedAttributeSource, true ); break; } default: { @@ -132,29 +133,22 @@ public class SourceIndex { private void indexAttributeSources( AttributeIndexingTarget attributeIndexingTarget, - String pathBase, AttributeSource attributeSource, boolean isInIdentifier) { - final AttributeSourceKey key = new AttributeSourceKey( - attributeIndexingTarget.getAttributeSourceKeyBase(), - pathBase, - attributeSource.getName() - ); - attributeSourcesByKey.put( key, attributeSource ); - log.debugf( "Indexing attribute source [%s]", key ); + log.debugf( "Indexing attribute source [%s]", attributeSource.getAttributeRole() ); + attributeSourcesByKey.put( attributeSource.getAttributeRole(), attributeSource ); if ( attributeSource.isSingular() ) { - attributeIndexingTarget.indexSingularAttributeSource( pathBase, (SingularAttributeSource) attributeSource, isInIdentifier ); + attributeIndexingTarget.indexSingularAttributeSource( (SingularAttributeSource) attributeSource, isInIdentifier ); } else { - attributeIndexingTarget.indexPluralAttributeSource( pathBase, (PluralAttributeSource) attributeSource ); + attributeIndexingTarget.indexPluralAttributeSource( (PluralAttributeSource) attributeSource ); } - if ( attributeSource instanceof ComponentAttributeSource ) { - for ( AttributeSource subAttributeSource : ( (ComponentAttributeSource) attributeSource ).attributeSources() ) { + if ( attributeSource instanceof EmbeddedAttributeSource ) { + for ( AttributeSource subAttributeSource : ( (EmbeddedAttributeSource) attributeSource ).getEmbeddableSource().attributeSources() ) { indexAttributeSources( attributeIndexingTarget, - key.attributePath(), subAttributeSource, isInIdentifier ); @@ -163,9 +157,8 @@ public class SourceIndex { } private void indexAttributes(EntitySourceIndex entitySourceIndex) { - final String emptyString = ""; for ( final AttributeSource attributeSource : entitySourceIndex.entitySource.attributeSources() ) { - indexAttributeSources(entitySourceIndex, emptyString, attributeSource, false ); + indexAttributeSources( entitySourceIndex, attributeSource, false ); } } @@ -183,181 +176,77 @@ public class SourceIndex { entitySourceIndexByEntityName.get( binding.getEntityName() ).resolveAttributeSources( context ); } - public Map getSingularAttributeSources( + public Map getSingularAttributeSources( String entityName, boolean isMappedBy, - SingularAttributeSource.Nature nature) { + SingularAttributeNature singularAttributeNature) { final EntitySourceIndex entitySourceIndex = entitySourceIndexByEntityName.get( entityName ); - return entitySourceIndex.getSingularAttributeSources( isMappedBy, nature ); + return entitySourceIndex.getSingularAttributeSources( isMappedBy, singularAttributeNature ); } - public Map getPluralAttributeSources( + public Map getPluralAttributeSources( String entityName, boolean isInverse) { final EntitySourceIndex entitySourceIndex = entitySourceIndexByEntityName.get( entityName ); return entitySourceIndex.getPluralAttributeSources( isInverse ); } - public AttributeSource attributeSource(final String entityName, final String attributePath) { - return attributeSourcesByKey.get( new AttributeSourceKey( entityName, attributePath ) ); + public AttributeSource attributeSource(final AttributeRole attributeRole) { + return attributeSourcesByKey.get( attributeRole ); + } + + public AttributeSource attributeSource(String entityName, String attributePath) { + final AttributeRole base = new AttributeRole( entityName ); + + AttributeRole role; + if ( attributePath.contains( "." ) ) { + role = base; + for ( String part : attributePath.split( "\\." ) ) { + role = role.append( part ); + } + } + else { + role = base.append( attributePath ); + } + return attributeSourcesByKey.get( role ); } public AttributeSource attributeSource(EntityBinding entityBinding, AttributeBinding attributeBinding) { - return attributeSourcesByKey.get( - new AttributeSourceKey( - entityBinding.getEntityName(), - attributeBinding.getAttributePath() - ) - ); - } - - public AttributeSource locateAttributeSourceOwnedBy(final String entityName, final String attributePath) { - AttributeSourceKey ownerKey = new AttributeSourceKey( entityName, attributePath ); - AttributeSourceKey mappedByKey = mappedByAttributeKeysByOwnerAttributeKeys.get( ownerKey ); - return mappedByKey == null ? null : attributeSourcesByKey.get( mappedByKey ); - } - - public EntitySource entitySource(final String entityName) { - return entitySourceIndexByEntityName.get( entityName ).entitySource; - } - - private EntitySourceIndex entitySourceIndex(String entityName) { - return entitySourceIndexByEntityName.get( entityName ); - } - - void addMappedByAssociationByOwnerAssociation(AttributeSourceKey ownerKey, AttributeSourceKey ownedKey) { - mappedByAttributeKeysByOwnerAttributeKeys.put( - ownerKey, - ownedKey - ); - - } - - - /** - * Helper class for indexing attribute look ups. - */ - public static class AttributeSourceKey { - private final String entityName; - private final String containerPath; - private final String attributeName; - - private AttributeSourceKey(final String entityName, final String containerPath, final String attributeName) { - this.entityName = entityName; - this.containerPath = containerPath; - this.attributeName = attributeName; - } - - private AttributeSourceKey(final String entityName, final String attributePath) { - this.entityName = entityName; - int indexLastDot = attributePath.lastIndexOf( '.' ); - if ( indexLastDot == -1 ) { - this.containerPath = EMPTY_STRING; - this.attributeName = attributePath; - } - else { - this.containerPath = attributePath.substring( 0, indexLastDot ); - this.attributeName = attributePath.substring( indexLastDot + 1 ); - } - } - - public String entityName() { - return entityName; - } - - public String containerPath() { - return containerPath; - } - - public String attributeName() { - return attributeName; - } - - public String attributePath() { - return StringHelper.isEmpty( containerPath ) - ? attributeName - : containerPath + '.' + attributeName; - } - - public String getAttributePathQualifiedByEntityName() { - return entityName + '.' + attributePath(); - } - - @Override - public String toString() { - return getAttributePathQualifiedByEntityName(); - } - - @Override - public boolean equals(Object o) { - if ( this == o ) { - return true; - } - if ( o == null || getClass() != o.getClass() ) { - return false; - } - - final AttributeSourceKey that = (AttributeSourceKey) o; - return attributeName.equals( that.attributeName ) - && containerPath.equals( that.containerPath ) - && entityName.equals( that.entityName ); - } - - @Override - public int hashCode() { - int result = entityName.hashCode(); - result = 31 * result + containerPath.hashCode(); - result = 31 * result + attributeName.hashCode(); - return result; - } + return attributeSourcesByKey.get( attributeBinding.getAttributeRole() ); } private static interface AttributeIndexingTarget { - public String getAttributeSourceKeyBase(); - - public void indexSingularAttributeSource( - String pathBase, - SingularAttributeSource attributeSource, - boolean isInIdentifier); - - public void indexPluralAttributeSource(String pathBase, PluralAttributeSource attributeSource); + public void indexSingularAttributeSource(SingularAttributeSource attributeSource, boolean isInIdentifier); + public void indexPluralAttributeSource(PluralAttributeSource attributeSource); } private static abstract class AbstractAttributeIndexingTarget implements AttributeIndexingTarget { - private final Map unresolvedSingularAttributeSourcesByKey - = new HashMap(); + private final Map unresolvedSingularAttributeSourcesByKey + = new HashMap(); - private final Map> identifierAttributeSourcesByNature - = new EnumMap>( SingularAttributeSource.Nature.class ); - private final Map> nonMappedBySingularAttributeSourcesByNature - = new EnumMap>( SingularAttributeSource.Nature.class ); - private final Map> mappedBySingularAttributeSourcesByNature - = new EnumMap>( SingularAttributeSource.Nature.class ); + private final Map> identifierAttributeSourcesByNature + = new EnumMap>( SingularAttributeNature.class ); + private final Map> nonMappedBySingularAttributeSourcesByNature + = new EnumMap>( SingularAttributeNature.class ); + private final Map> mappedBySingularAttributeSourcesByNature + = new EnumMap>( SingularAttributeNature.class ); // TODO: the following should not need to be LinkedHashMap, but it appears that some unit tests // depend on the ordering // TODO: rework nonInversePluralAttributeSourcesByKey and inversePluralAttributeSourcesByKey - private final Map nonInversePluralAttributeSourcesByKey = - new LinkedHashMap(); - private final Map inversePluralAttributeSourcesByKey = - new LinkedHashMap(); - - protected AttributeSourceKey makeKey(String pathBase, AttributeSource attributeSource) { - return new AttributeSourceKey( getAttributeSourceKeyBase(), pathBase, attributeSource.getName() ); - } + private final Map nonInversePluralAttributeSourcesByKey = + new LinkedHashMap(); + private final Map inversePluralAttributeSourcesByKey = + new LinkedHashMap(); @Override - public void indexSingularAttributeSource( - String pathBase, - SingularAttributeSource attributeSource, - boolean isInIdentifier) { - final AttributeSourceKey attributeSourceKey = makeKey( pathBase, attributeSource ); - if ( attributeSource.getNature() == null ) { - unresolvedSingularAttributeSourcesByKey.put( attributeSourceKey, attributeSource ); + public void indexSingularAttributeSource(SingularAttributeSource attributeSource, boolean isInIdentifier) { + if ( attributeSource.getSingularAttributeNature() == null ) { + unresolvedSingularAttributeSourcesByKey.put( attributeSource.getAttributeRole(), attributeSource ); return; } - final Map> map; + final Map> map; if ( isInIdentifier ) { map = identifierAttributeSourcesByNature; } @@ -369,54 +258,65 @@ public class SourceIndex { map = nonMappedBySingularAttributeSourcesByNature; } - indexSingularAttributeSource( attributeSourceKey, attributeSource, map ); + indexSingularAttributeSource( attributeSource, map ); } private static void indexSingularAttributeSource( - AttributeSourceKey attributeSourceKey, SingularAttributeSource attributeSource, - Map> map) { - final Map singularAttributeSources; - if ( map.containsKey( attributeSource.getNature() ) ) { - singularAttributeSources = map.get( attributeSource.getNature() ); + Map> map) { + final Map singularAttributeSources; + if ( map.containsKey( attributeSource.getSingularAttributeNature() ) ) { + singularAttributeSources = map.get( attributeSource.getSingularAttributeNature() ); } else { - singularAttributeSources = new LinkedHashMap(); - map.put( attributeSource.getNature(), singularAttributeSources ); + singularAttributeSources = new LinkedHashMap(); + map.put( attributeSource.getSingularAttributeNature(), singularAttributeSources ); } - if ( singularAttributeSources.put( attributeSourceKey, attributeSource ) != null ) { + if ( singularAttributeSources.put( attributeSource.getAttributeRole(), attributeSource ) != null ) { throw new AssertionFailure( - String.format( "Attempt to reindex attribute source for: [%s]", attributeSourceKey ) + String.format( + Locale.ENGLISH, + "Attempt to reindex attribute source for: [%s]", + attributeSource.getAttributeRole() + ) ); } } @Override - public void indexPluralAttributeSource( - String pathBase, - PluralAttributeSource attributeSource) { - final AttributeSourceKey key = makeKey( pathBase, attributeSource ); - final Map map = attributeSource.isInverse() + public void indexPluralAttributeSource(PluralAttributeSource attributeSource) { + final Map map = attributeSource.isInverse() ? inversePluralAttributeSourcesByKey : nonInversePluralAttributeSourcesByKey; - if ( map.put( key, attributeSource ) != null ) { + if ( map.put( attributeSource.getAttributeRole(), attributeSource ) != null ) { throw new AssertionFailure( - String.format( "Attempt to reindex attribute source for: [%s]", key ) + String.format( + Locale.ENGLISH, + "Attempt to reindex attribute source for: [%s]", + attributeSource.getAttributeRole() ) ); } } - public Map getSingularAttributeSources( + public Map getSingularAttributeSources( boolean isMappedBy, - SingularAttributeSource.Nature nature) { - final Map entries; - if ( isMappedBy && mappedBySingularAttributeSourcesByNature.containsKey( nature ) ) { - entries = Collections.unmodifiableMap( mappedBySingularAttributeSourcesByNature.get( nature ) ); + SingularAttributeNature singularAttributeNature) { + final Map entries; + if ( isMappedBy && mappedBySingularAttributeSourcesByNature.containsKey( singularAttributeNature ) ) { + entries = Collections.unmodifiableMap( + mappedBySingularAttributeSourcesByNature.get( + singularAttributeNature + ) + ); } - else if ( !isMappedBy && nonMappedBySingularAttributeSourcesByNature.containsKey( nature ) ) { - entries = Collections.unmodifiableMap( nonMappedBySingularAttributeSourcesByNature.get( nature ) ); + else if ( !isMappedBy && nonMappedBySingularAttributeSourcesByNature.containsKey( singularAttributeNature ) ) { + entries = Collections.unmodifiableMap( + nonMappedBySingularAttributeSourcesByNature.get( + singularAttributeNature + ) + ); } else { entries = Collections.emptyMap(); @@ -424,8 +324,8 @@ public class SourceIndex { return entries; } - public Map getPluralAttributeSources(boolean isInverse) { - final Map map = isInverse + public Map getPluralAttributeSources(boolean isInverse) { + final Map map = isInverse ? inversePluralAttributeSourcesByKey : nonInversePluralAttributeSourcesByKey; return Collections.unmodifiableMap( map ); @@ -442,41 +342,52 @@ public class SourceIndex { // so it needs to be resolved. pluralAttributeSource.resolvePluralAttributeElementSource( sourceResolutionContext ); } + if ( IndexedPluralAttributeSource.class.isInstance( pluralAttributeSource ) ) { - IndexedPluralAttributeSource indexedPluralAttributeSource = - (IndexedPluralAttributeSource) pluralAttributeSource; - indexedPluralAttributeSource.resolvePluralAttributeIndexSource( sourceResolutionContext ); + final IndexedPluralAttributeSource indexedPluralAttributeSource = (IndexedPluralAttributeSource) pluralAttributeSource; + if ( PluralAttributeIndexSourceResolver.class.isInstance( indexedPluralAttributeSource.getIndexSource() ) ) { + ( (PluralAttributeIndexSourceResolver) indexedPluralAttributeSource.getIndexSource() ).resolvePluralAttributeIndexSource( + sourceResolutionContext + ); + } } } for ( PluralAttributeSource pluralAttributeSource : nonInversePluralAttributeSourcesByKey.values() ) { if ( IndexedPluralAttributeSource.class.isInstance( pluralAttributeSource ) ) { - IndexedPluralAttributeSource indexedPluralAttributeSource = - (IndexedPluralAttributeSource) pluralAttributeSource; - indexedPluralAttributeSource.resolvePluralAttributeIndexSource( sourceResolutionContext ); + final IndexedPluralAttributeSource indexedPluralAttributeSource = (IndexedPluralAttributeSource) pluralAttributeSource; + if ( PluralAttributeIndexSourceResolver.class.isInstance( indexedPluralAttributeSource.getIndexSource() ) ) { + ( (PluralAttributeIndexSourceResolver) indexedPluralAttributeSource.getIndexSource() ).resolvePluralAttributeIndexSource( + sourceResolutionContext + ); + } } } // cycle through unresolved SingularAttributeSource. // TODO: rework so approach is similar to one-to-many/many-to-many resolution. - for ( Iterator> it = unresolvedSingularAttributeSourcesByKey.entrySet().iterator(); it.hasNext(); ) { - final Map.Entry entry = it.next(); - final AttributeSourceKey attributeSourceKey = entry.getKey(); - final SingularAttributeSource attributeSource = entry.getValue(); + for ( final SingularAttributeSource attributeSource : unresolvedSingularAttributeSourcesByKey.values() ) { if ( !ToOneAttributeSource.class.isInstance( attributeSource ) ) { throw new AssertionFailure( - String.format( "Only a ToOneAttributeSource is expected to have a null nature; attribute: %s ", attributeSourceKey ) + String.format( + Locale.ENGLISH, + "Only a ToOneAttributeSource is expected to have a null nature; attribute: %s ", + attributeSource.getAttributeRole() + ) ); } ToOneAttributeSource toOneAttributeSource = (ToOneAttributeSource) attributeSource; toOneAttributeSource.resolveToOneAttributeSource( sourceResolutionContext ); - if ( toOneAttributeSource.getNature() == null ) { + if ( toOneAttributeSource.getSingularAttributeNature() == null ) { throw new AssertionFailure( - String.format( "Null nature should have been resolved: %s ", attributeSourceKey ) + String.format( + Locale.ENGLISH, + "Null nature should have been resolved: %s ", + attributeSource.getAttributeRole() + ) ); } indexSingularAttributeSource( - attributeSourceKey, attributeSource, toOneAttributeSource.isMappedBy() ? mappedBySingularAttributeSourcesByNature @@ -498,22 +409,17 @@ public class SourceIndex { } @Override - public String getAttributeSourceKeyBase() { - return hierarchyKey; - } - - @Override - public void indexPluralAttributeSource(String pathBase, PluralAttributeSource attributeSource) { + public void indexPluralAttributeSource(PluralAttributeSource attributeSource) { throw new AssertionFailure( String.format( "Identifiers should not contain plural attributes: [%s]", - makeKey( pathBase, attributeSource ) + attributeSource.getAttributeRole().getFullPath() ) ); } @Override - public Map getPluralAttributeSources(boolean isInverse) { + public Map getPluralAttributeSources(boolean isInverse) { return Collections.emptyMap(); } @@ -553,17 +459,15 @@ public class SourceIndex { } @Override - public String getAttributeSourceKeyBase() { - return entitySource.getEntityName(); - } - - @Override - public Map getSingularAttributeSources( + public Map getSingularAttributeSources( boolean isMappedBy, - SingularAttributeSource.Nature nature) { - Map values = hierarchyInfo.getSingularAttributeSources( isMappedBy, nature ); + SingularAttributeNature singularAttributeNature) { + Map values = hierarchyInfo.getSingularAttributeSources( + isMappedBy, + singularAttributeNature + ); if ( values == null || values.isEmpty() ) { - values = super.getSingularAttributeSources( isMappedBy, nature ); + values = super.getSingularAttributeSources( isMappedBy, singularAttributeNature ); } return values; @@ -591,9 +495,4 @@ public class SourceIndex { } } - - private static class DependencyTreeNode { - private String dependedOnHierarchyKey; - private List dependantHierarchyKeys; - } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/resolver/AssociationRelationalBindingResolver.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/resolver/AssociationRelationalBindingResolver.java index 10e695f534..dbf6071aad 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/resolver/AssociationRelationalBindingResolver.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/resolver/AssociationRelationalBindingResolver.java @@ -25,7 +25,7 @@ package org.hibernate.metamodel.internal.resolver; import java.util.List; -import org.hibernate.metamodel.source.spi.ManyToManyPluralAttributeElementSource; +import org.hibernate.metamodel.source.spi.PluralAttributeElementSourceManyToMany; import org.hibernate.metamodel.source.spi.PluralAttributeSource; import org.hibernate.metamodel.source.spi.ToOneAttributeSource; import org.hibernate.metamodel.spi.binding.AttributeBindingContainer; @@ -77,13 +77,13 @@ public interface AssociationRelationalBindingResolver { List resolveManyToManyElementRelationalValueBindings( final EntityBinding entityBinding, - final ManyToManyPluralAttributeElementSource elementSource, + final PluralAttributeElementSourceManyToMany elementSource, final TableSpecification collectionTable, final EntityBinding referencedEntityBinding); ForeignKey resolveManyToManyElementForeignKey( final EntityBinding entityBinding, - final ManyToManyPluralAttributeElementSource elementSource, + final PluralAttributeElementSourceManyToMany elementSource, final TableSpecification collectionTable, final List relationalValueBindings, final EntityBinding referencedEntityBinding); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/resolver/MappedByAssociationRelationalBindingResolverImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/resolver/MappedByAssociationRelationalBindingResolverImpl.java index 3487cfbd35..db48c0cf5e 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/resolver/MappedByAssociationRelationalBindingResolverImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/resolver/MappedByAssociationRelationalBindingResolverImpl.java @@ -32,17 +32,17 @@ import org.hibernate.metamodel.internal.binder.BinderRootContext; import org.hibernate.metamodel.internal.binder.ForeignKeyHelper; import org.hibernate.metamodel.internal.binder.RelationalValueBindingHelper; import org.hibernate.metamodel.source.spi.AssociationSource; -import org.hibernate.metamodel.source.spi.ManyToManyPluralAttributeElementSource; import org.hibernate.metamodel.source.spi.MappedByAssociationSource; +import org.hibernate.metamodel.source.spi.PluralAttributeElementSourceManyToMany; import org.hibernate.metamodel.source.spi.PluralAttributeSource; import org.hibernate.metamodel.source.spi.ToOneAttributeSource; import org.hibernate.metamodel.spi.LocalBindingContext; import org.hibernate.metamodel.spi.binding.AttributeBinding; import org.hibernate.metamodel.spi.binding.AttributeBindingContainer; import org.hibernate.metamodel.spi.binding.EntityBinding; -import org.hibernate.metamodel.spi.binding.ManyToManyPluralAttributeElementBinding; import org.hibernate.metamodel.spi.binding.ManyToOneAttributeBinding; import org.hibernate.metamodel.spi.binding.PluralAttributeBinding; +import org.hibernate.metamodel.spi.binding.PluralAttributeElementBindingManyToMany; import org.hibernate.metamodel.spi.binding.RelationalValueBinding; import org.hibernate.metamodel.spi.binding.SecondaryTable; import org.hibernate.metamodel.spi.binding.SingularAssociationAttributeBinding; @@ -166,7 +166,7 @@ public class MappedByAssociationRelationalBindingResolverImpl implements Associa @Override public List resolveManyToManyElementRelationalValueBindings( final EntityBinding entityBinding, - final ManyToManyPluralAttributeElementSource elementSource, + final PluralAttributeElementSourceManyToMany elementSource, final TableSpecification collectionTable, final EntityBinding referencedEntityBinding) { { @@ -198,7 +198,7 @@ public class MappedByAssociationRelationalBindingResolverImpl implements Associa @Override public ForeignKey resolveManyToManyElementForeignKey( final EntityBinding entityBinding, - final ManyToManyPluralAttributeElementSource elementSource, + final PluralAttributeElementSourceManyToMany elementSource, final TableSpecification collectionTable, final List relationalValueBindings, final EntityBinding referencedEntityBinding) { @@ -246,9 +246,9 @@ public class MappedByAssociationRelationalBindingResolverImpl implements Associa } else { final PluralAttributeBinding pluralOwnerAttributeBinding = (PluralAttributeBinding) ownerAttributeBinding; - final ManyToManyPluralAttributeElementBinding ownerElementBinding = - (ManyToManyPluralAttributeElementBinding) pluralOwnerAttributeBinding.getPluralAttributeElementBinding(); - return ownerElementBinding.getRelationalValueBindings(); + final PluralAttributeElementBindingManyToMany ownerElementBinding = + (PluralAttributeElementBindingManyToMany) pluralOwnerAttributeBinding.getPluralAttributeElementBinding(); + return ownerElementBinding.getRelationalValueContainer().relationalValueBindings(); } } @@ -268,8 +268,8 @@ public class MappedByAssociationRelationalBindingResolverImpl implements Associa } else { final PluralAttributeBinding pluralOwnerAttributeBinding = (PluralAttributeBinding) ownerAttributeBinding; - final ManyToManyPluralAttributeElementBinding ownerElementBinding = - (ManyToManyPluralAttributeElementBinding) pluralOwnerAttributeBinding.getPluralAttributeElementBinding(); + final PluralAttributeElementBindingManyToMany ownerElementBinding = + (PluralAttributeElementBindingManyToMany) pluralOwnerAttributeBinding.getPluralAttributeElementBinding(); foreignKey = ownerElementBinding.getForeignKey(); } if ( attributeSource.getKeySource().isCascadeDeleteEnabled() ) { @@ -293,8 +293,8 @@ public class MappedByAssociationRelationalBindingResolverImpl implements Associa } else { final PluralAttributeBinding ownerPluralAttributeBinding = (PluralAttributeBinding) ownerAttributeBinding; - final ManyToManyPluralAttributeElementBinding ownerElementBinding = - (ManyToManyPluralAttributeElementBinding) ownerPluralAttributeBinding + final PluralAttributeElementBindingManyToMany ownerElementBinding = + (PluralAttributeElementBindingManyToMany) ownerPluralAttributeBinding .getPluralAttributeElementBinding(); referencedAttributeBinding = attributeBindingContainer.seekEntityBinding().locateAttributeBinding( ownerElementBinding.getForeignKey().getTargetTable(), diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/resolver/StandardAssociationRelationalBindingResolverImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/resolver/StandardAssociationRelationalBindingResolverImpl.java index 4e9fe87e33..712c95d2e3 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/resolver/StandardAssociationRelationalBindingResolverImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/resolver/StandardAssociationRelationalBindingResolverImpl.java @@ -38,14 +38,14 @@ import org.hibernate.metamodel.internal.binder.RelationalValueBindingHelper; import org.hibernate.metamodel.internal.binder.TableHelper; import org.hibernate.metamodel.source.spi.AssociationSource; import org.hibernate.metamodel.source.spi.ForeignKeyContributingSource; -import org.hibernate.metamodel.source.spi.ManyToManyPluralAttributeElementSource; -import org.hibernate.metamodel.source.spi.PluralAttributeElementSource; +import org.hibernate.metamodel.source.spi.PluralAttributeElementSourceManyToMany; import org.hibernate.metamodel.source.spi.PluralAttributeKeySource; import org.hibernate.metamodel.source.spi.PluralAttributeSource; import org.hibernate.metamodel.source.spi.RelationalValueSourceContainer; import org.hibernate.metamodel.source.spi.SingularAttributeSource; import org.hibernate.metamodel.source.spi.TableSpecificationSource; import org.hibernate.metamodel.source.spi.ToOneAttributeSource; +import org.hibernate.metamodel.spi.PluralAttributeElementNature; import org.hibernate.metamodel.spi.binding.AttributeBindingContainer; import org.hibernate.metamodel.spi.binding.EntityBinding; import org.hibernate.metamodel.spi.binding.RelationalValueBinding; @@ -194,7 +194,7 @@ public class StandardAssociationRelationalBindingResolverImpl implements Associa @Override public List resolveManyToManyElementRelationalValueBindings( final EntityBinding entityBinding, - final ManyToManyPluralAttributeElementSource elementSource, + final PluralAttributeElementSourceManyToMany elementSource, final TableSpecification collectionTable, final EntityBinding referencedEntityBinding) { final List targetColumns = @@ -230,7 +230,7 @@ public class StandardAssociationRelationalBindingResolverImpl implements Associa @Override public ForeignKey resolveManyToManyElementForeignKey( final EntityBinding entityBinding, - final ManyToManyPluralAttributeElementSource elementSource, + final PluralAttributeElementSourceManyToMany elementSource, final TableSpecification collectionTable, final List relationalValueBindings, final EntityBinding referencedEntityBinding) { @@ -318,7 +318,7 @@ public class StandardAssociationRelationalBindingResolverImpl implements Associa keySource, entityBinding, collectionTable, - attributeSource.getElementSource().getNature() != PluralAttributeElementSource.Nature.ONE_TO_MANY, + attributeSource.getElementSource().getNature() != PluralAttributeElementNature.ONE_TO_MANY, namingStrategies ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/internal/Primitives.java b/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/internal/Primitives.java index 055ace361f..03f14f2c3a 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/internal/Primitives.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/internal/Primitives.java @@ -62,6 +62,18 @@ public class Primitives { this.primitiveType ); } + + public PrimitiveTypeDescriptor getPrimitiveType() { + return primitiveType; + } + + public PrimitiveWrapperTypeDescriptor getPrimitiveWrapperType() { + return primitiveWrapperType; + } + + public ArrayDescriptor getPrimitiveArrayType() { + return primitiveArrayType; + } } public static final PrimitiveGroup CHAR = new PrimitiveGroup( char.class, char[].class, Character.class ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/AbstractAttributeSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/AbstractAttributeSource.java deleted file mode 100644 index 0c2e531a63..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/AbstractAttributeSource.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2014, 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.metamodel.source.internal; - -import java.util.Collection; -import java.util.Collections; - -import org.hibernate.metamodel.source.internal.annotations.attribute.AbstractPersistentAttribute; -import org.hibernate.metamodel.source.spi.AttributeSource; -import org.hibernate.metamodel.source.spi.ToolingHintSource; - -/** - * Common contract for source of all persistent attributes. - * - * @author Steve Ebersole - * @author Hardy Ferentschik - */ -public abstract class AbstractAttributeSource implements AttributeSource { - private final AbstractManagedTypeSource container; - private final AbstractPersistentAttribute attribute; - - protected AbstractAttributeSource( - AbstractManagedTypeSource container, - AbstractPersistentAttribute attribute) { - this.container = container; - this.attribute = attribute; - } - - public AbstractManagedTypeSource getContainer() { - return container; - } - - public AbstractPersistentAttribute getPersistentAttribute() { - return attribute; - } - - @Override - public String getName() { - return attribute.getName(); - } - - @Override - public String getPropertyAccessorName() { - return attribute.getAccessorStrategy(); - } - - @Override - public boolean isIncludedInOptimisticLocking() { - return getPersistentAttribute().isIncludeInOptimisticLocking(); - } - - @Override - public Collection getToolingHintSources() { - // todo : when hooking in unified (Hibernate-specific) xml elements need to account for this - return Collections.emptyList(); - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/AbstractManagedTypeSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/AbstractManagedTypeSource.java deleted file mode 100644 index 7cc0f0059c..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/AbstractManagedTypeSource.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2014, 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.metamodel.source.internal; - -import org.hibernate.metamodel.source.internal.annotations.attribute.AssociationOverride; -import org.hibernate.metamodel.source.internal.annotations.attribute.AttributeOverride; -import org.hibernate.metamodel.source.internal.annotations.entity.ManagedTypeMetadata; -import org.hibernate.metamodel.source.spi.AttributeSourceContainer; -import org.hibernate.metamodel.spi.LocalBindingContext; - -/** - * Base class for sources of "managed type" (entity, mapped-superclass, - * embeddable) information. - * - * @author Steve Ebersole - * @author Hardy Ferentschik - */ -public abstract class AbstractManagedTypeSource implements AttributeSourceContainer { - private final ManagedTypeMetadata metadata; - - protected AbstractManagedTypeSource(ManagedTypeMetadata metadata) { - this.metadata = metadata; - } - - @Override - public LocalBindingContext getLocalBindingContext() { - return metadata.getLocalBindingContext(); - } - - abstract AttributeOverride locateAttributeOverride(String path); - - abstract AssociationOverride locateAssociationOverride(String path); - - abstract AttributeConversionInfo locateConversionInfo(String path); -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/AbstractSingularAssociationAttributeSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/AbstractSingularAssociationAttributeSource.java deleted file mode 100644 index 2240b45f20..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/AbstractSingularAssociationAttributeSource.java +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2014, 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.metamodel.source.internal; - -import java.util.HashSet; -import java.util.Set; - -import org.hibernate.engine.FetchStyle; -import org.hibernate.engine.FetchTiming; -import org.hibernate.engine.spi.CascadeStyle; -import org.hibernate.engine.spi.CascadeStyles; -import org.hibernate.metamodel.source.internal.annotations.attribute.SingularAssociationAttribute; -import org.hibernate.metamodel.source.internal.annotations.util.EnumConversionHelper; -import org.hibernate.metamodel.source.spi.AttributeSource; -import org.hibernate.metamodel.source.spi.MappedByAssociationSource; -import org.hibernate.metamodel.source.spi.SingularAttributeSource; -import org.hibernate.metamodel.source.spi.ToOneAttributeSource; -import org.hibernate.type.ForeignKeyDirection; - -/** - * Common support for singular association (*-to-one) persistent attributes. - * - * @author Steve Ebersole - * @author Gail Badner - */ -public abstract class AbstractSingularAssociationAttributeSource - extends AbstractSingularAttributeSource - implements ToOneAttributeSource { - - private final Set cascadeStyles; - private final Set ownedAssociationSources = new HashSet(); - - private Nature nature; - - public AbstractSingularAssociationAttributeSource( - AbstractManagedTypeSource container, - SingularAssociationAttribute attribute) { - super( container, attribute ); - this.cascadeStyles = determineCascadeStyles( attribute ); - } - - private static Set determineCascadeStyles(SingularAssociationAttribute associationAttribute) { - final Set cascadeStyles = EnumConversionHelper.cascadeTypeToCascadeStyleSet( - associationAttribute.getJpaCascadeTypes(), - associationAttribute.getHibernateCascadeTypes(), - associationAttribute.getContext() - ); - if ( associationAttribute.isOrphanRemoval() ) { - cascadeStyles.add( CascadeStyles.DELETE_ORPHAN ); - } - return cascadeStyles; - } - - @Override - protected void validateConversionInfo(AttributeConversionInfo conversionInfo) { - throw getContainer().getLocalBindingContext().makeMappingException( - "Illegal attempt to apply AttributeConverter to non-basic attribute : " - + getPersistentAttribute().getBackingMember().toString() - ); - } - - protected void setNature(Nature nature) { - assert this.nature == null; - this.nature = nature; - } - - @Override - public SingularAssociationAttribute getPersistentAttribute() { - return (SingularAssociationAttribute) super.getPersistentAttribute(); - } - - @Override - public SingularAttributeSource.Nature getNature() { - return nature; - } - - - @Override - public AttributeSource getAttributeSource() { - return this; - } - - @Override - public String getReferencedEntityName() { - return getPersistentAttribute().getTargetTypeName(); - } - - @Override - public boolean isUnique() { - return nature == Nature.ONE_TO_ONE; - } - - @Override - public boolean isIgnoreNotFound() { - return getPersistentAttribute().isIgnoreNotFound(); - } - - @Override - public Set getOwnedAssociationSources() { - return ownedAssociationSources; - } - - @Override - public void addMappedByAssociationSource(MappedByAssociationSource attributeSource) { - if ( attributeSource == null ) { - throw new IllegalArgumentException( "attributeSource must be non-null." ); - } - ownedAssociationSources.add( attributeSource ); - } - - @Override - public boolean isMappedBy() { - return false; - } - - @Override - public Set getCascadeStyles() { - return cascadeStyles; - } - - @Override - public FetchTiming getFetchTiming() { - return getPersistentAttribute().isLazy() - ? FetchTiming.DELAYED - : FetchTiming.IMMEDIATE; - } - - @Override - public FetchStyle getFetchStyle() { - if ( getPersistentAttribute().getFetchStyle() != null ) { - return getPersistentAttribute().getFetchStyle(); - } - else { - return getPersistentAttribute().isLazy() - ? FetchStyle.SELECT - : FetchStyle.JOIN; - } - } - - @Override - public boolean isUnWrapProxy() { - return getPersistentAttribute().isUnWrapProxy(); - } - - @Override - public String toString() { - return "ToOneAttributeSourceImpl{attribute=" + getPersistentAttribute() - + ", cascadeStyles=" + cascadeStyles + '}'; - } - - @Override - public ForeignKeyDirection getForeignKeyDirection() { - return nature == Nature.ONE_TO_ONE && !getPersistentAttribute().isOptional() - ? ForeignKeyDirection.FROM_PARENT - : ForeignKeyDirection.TO_PARENT; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/AbstractSingularAttributeSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/AbstractSingularAttributeSource.java deleted file mode 100644 index 8cac4474dd..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/AbstractSingularAttributeSource.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2014, 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.metamodel.source.internal; - -import org.hibernate.mapping.PropertyGeneration; -import org.hibernate.metamodel.source.internal.annotations.attribute.AbstractPersistentAttribute; -import org.hibernate.metamodel.source.spi.SingularAttributeSource; - -import static org.hibernate.metamodel.spi.binding.SingularAttributeBinding.NaturalIdMutability; - -/** - * Common support for singular, non-composite persistent attributes. - * - * @author Steve Ebersole - * @author Hardy Ferentschik - */ -public abstract class AbstractSingularAttributeSource - extends AbstractAttributeSource - implements SingularAttributeSource { - private final AttributeConversionInfo conversionInfo; - - protected AbstractSingularAttributeSource( - AbstractManagedTypeSource container, - AbstractPersistentAttribute attribute) { - super( container, attribute ); - - this.conversionInfo = container.locateConversionInfo( attribute.getName() ); - validateConversionInfo( conversionInfo ); - } - - protected abstract void validateConversionInfo(AttributeConversionInfo conversionInfo); - - public AttributeConversionInfo getConversionInfo() { - return conversionInfo; - } - - @Override - public boolean isSingular() { - return true; - } - - @Override - public boolean isVirtualAttribute() { - return false; - } - - @Override - public PropertyGeneration getGeneration() { - return getPersistentAttribute().getPropertyGeneration(); - } - - @Override - public boolean isLazy() { - return getPersistentAttribute().isLazy(); - } - - @Override - public NaturalIdMutability getNaturalIdMutability() { - return getPersistentAttribute().getNaturalIdMutability(); - } - - @Override - public boolean areValuesIncludedInInsertByDefault() { - return getPersistentAttribute().isInsertable(); - } - - @Override - public boolean areValuesIncludedInUpdateByDefault() { - return !getPersistentAttribute().isId() && getPersistentAttribute().isUpdatable(); - } - - @Override - public boolean areValuesNullableByDefault() { - return !getPersistentAttribute().isId() && getPersistentAttribute().isOptional(); - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/BasicAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/BasicAttributeSourceImpl.java deleted file mode 100644 index d5cfd4d70b..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/BasicAttributeSourceImpl.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2014, 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.metamodel.source.internal; - -import java.util.ArrayList; -import java.util.List; - -import org.hibernate.metamodel.source.internal.annotations.ColumnSourceImpl; -import org.hibernate.metamodel.source.internal.annotations.DerivedValueSourceImpl; -import org.hibernate.metamodel.source.internal.annotations.attribute.AttributeOverride; -import org.hibernate.metamodel.source.internal.annotations.attribute.BasicAttribute; -import org.hibernate.metamodel.source.internal.annotations.attribute.Column; -import org.hibernate.metamodel.source.spi.HibernateTypeSource; -import org.hibernate.metamodel.source.spi.RelationalValueSource; - -/** - * Represents source of a basic singular attribute information for binding - * - * @author Steve Ebersole - */ -public class BasicAttributeSourceImpl extends AbstractSingularAttributeSource { - private final List relationalValueSources; - - protected BasicAttributeSourceImpl(AbstractManagedTypeSource container, BasicAttribute attribute) { - super( container, attribute ); - - if ( container.locateAttributeOverride( attribute.getName() ) != null ) { - throw container.getLocalBindingContext().makeMappingException( - "Association-override not valid on basic attributes : " - + attribute.getBackingMember().toString() - ); - } - - - this.relationalValueSources = new ArrayList(); - if ( attribute.getFormulaValue() != null ) { - relationalValueSources.add( new DerivedValueSourceImpl( attribute.getFormulaValue() ) ); - } - else { - final AttributeOverride attributeOverride = container.locateAttributeOverride( attribute.getName() ); - final int explicitColumnCount = attribute.getColumnValues().size(); - - if ( explicitColumnCount == 0 ) { - Column overrideColumn = attributeOverride.getImpliedColumn(); - if ( overrideColumn != null - || attribute.getCustomReadFragment() != null - || attribute.getCustomWriteFragment() != null - || attribute.getCheckCondition() != null ) { - relationalValueSources.add( - new ColumnSourceImpl( - overrideColumn, - null, - attribute.getCustomReadFragment(), - attribute.getCustomWriteFragment(), - attribute.getCheckCondition() - ) - ); - } - } - else if ( explicitColumnCount == 1 ) { - Column column = attribute.getColumnValues().get( 0 ); - if ( attributeOverride != null ) { - column.applyColumnValues( attributeOverride.getOverriddenColumnInfo() ); - } - relationalValueSources.add( - new ColumnSourceImpl( - column, - null, - attribute.getCustomReadFragment(), - attribute.getCustomWriteFragment(), - attribute.getCheckCondition() - ) - ); - } - else { - if ( attributeOverride != null ) { - throw container.getLocalBindingContext().makeMappingException( - "Cannot apply AttributeOverride to attribute mapped to more than one column : " - + attribute.getBackingMember().toString() - ); - } - - for ( Column column : attribute.getColumnValues() ) { - relationalValueSources.add( new ColumnSourceImpl( column, null ) ); - } - } - } - } - - @Override - public BasicAttribute getPersistentAttribute() { - return (BasicAttribute) super.getPersistentAttribute(); - } - - @Override - protected void validateConversionInfo(AttributeConversionInfo conversionInfo) { - - } - - @Override - public Nature getNature() { - return Nature.BASIC; - } - - @Override - public String getContainingTableName() { - return null; - } - - @Override - public HibernateTypeSource getTypeInformation() { - return null; - } - - @Override - public List relationalValueSources() { - return relationalValueSources; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/AbstractManyToManyPluralAttributeElementSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/AbstractPluralAttributeElementSourceAssociationManyToManyImpl.java similarity index 79% rename from hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/AbstractManyToManyPluralAttributeElementSourceImpl.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/AbstractPluralAttributeElementSourceAssociationManyToManyImpl.java index 745c5324a6..0143d5615a 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/AbstractManyToManyPluralAttributeElementSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/AbstractPluralAttributeElementSourceAssociationManyToManyImpl.java @@ -27,17 +27,18 @@ import org.hibernate.engine.FetchTiming; import org.hibernate.internal.util.StringHelper; import org.hibernate.metamodel.source.internal.annotations.attribute.AbstractPersistentAttribute; import org.hibernate.metamodel.source.spi.FilterSource; -import org.hibernate.metamodel.source.spi.ManyToManyPluralAttributeElementSource; +import org.hibernate.metamodel.source.spi.PluralAttributeElementSourceManyToMany; +import org.hibernate.metamodel.spi.PluralAttributeElementNature; /** * @author Gail Badner */ -public abstract class AbstractManyToManyPluralAttributeElementSourceImpl - extends AbstractPluralAssociationElementSourceImpl - implements ManyToManyPluralAttributeElementSource { +public abstract class AbstractPluralAttributeElementSourceAssociationManyToManyImpl + extends AbstractPluralElementSourceAssociationImpl + implements PluralAttributeElementSourceManyToMany { - public AbstractManyToManyPluralAttributeElementSourceImpl(PluralAttributeSourceImpl pluralAttributeSource) { + public AbstractPluralAttributeElementSourceAssociationManyToManyImpl(PluralAttributeSourceImpl pluralAttributeSource) { super( pluralAttributeSource ); } @@ -68,8 +69,8 @@ public abstract class AbstractManyToManyPluralAttributeElementSourceImpl } @Override - public Nature getNature() { - return Nature.MANY_TO_MANY; + public PluralAttributeElementNature getNature() { + return PluralAttributeElementNature.MANY_TO_MANY; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/AbstractPluralAttributeIndexSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/AbstractPluralAttributeIndexSourceImpl.java index 4f5bb8c639..2842d18b5e 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/AbstractPluralAttributeIndexSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/AbstractPluralAttributeIndexSourceImpl.java @@ -59,11 +59,6 @@ public abstract class AbstractPluralAttributeIndexSourceImpl implements PluralAt }; } - @Override - public boolean isReferencedEntityAttribute() { - return false; - } - @Override public boolean areValuesIncludedInInsertByDefault() { return false; @@ -79,7 +74,7 @@ public abstract class AbstractPluralAttributeIndexSourceImpl implements PluralAt return false; } - protected PluralAttribute pluralAssociationAttribute() { + protected PluralAttribute pluralAttribute() { return attribute; } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/AbstractPluralAssociationElementSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/AbstractPluralElementSourceAssociationImpl.java similarity index 91% rename from hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/AbstractPluralAssociationElementSourceImpl.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/AbstractPluralElementSourceAssociationImpl.java index e3b4971962..1392822288 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/AbstractPluralAssociationElementSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/AbstractPluralElementSourceAssociationImpl.java @@ -28,20 +28,20 @@ import java.util.Set; import org.hibernate.engine.spi.CascadeStyle; import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttribute; -import org.hibernate.metamodel.source.spi.AssociationPluralAttributeElementSource; import org.hibernate.metamodel.source.spi.AttributeSource; import org.hibernate.metamodel.source.spi.MappedByAssociationSource; +import org.hibernate.metamodel.source.spi.PluralAttributeElementSourceAssociation; /** * @author Gail Badner */ -public abstract class AbstractPluralAssociationElementSourceImpl +public abstract class AbstractPluralElementSourceAssociationImpl extends AbstractPluralAttributeElementSourceImpl - implements AssociationPluralAttributeElementSource { + implements PluralAttributeElementSourceAssociation { private final Set ownedAssociationSources = new HashSet( ); - public AbstractPluralAssociationElementSourceImpl(PluralAttributeSourceImpl pluralAttributeSource) { + public AbstractPluralElementSourceAssociationImpl(PluralAttributeSourceImpl pluralAttributeSource) { super( pluralAttributeSource ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/AbstractToOneAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/AbstractToOneAttributeSourceImpl.java index 12add4b69c..57ad3b4cda 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/AbstractToOneAttributeSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/AbstractToOneAttributeSourceImpl.java @@ -12,15 +12,17 @@ import org.hibernate.metamodel.source.internal.annotations.attribute.SingularAss import org.hibernate.metamodel.source.internal.annotations.util.EnumConversionHelper; import org.hibernate.metamodel.source.spi.AttributeSource; import org.hibernate.metamodel.source.spi.MappedByAssociationSource; -import org.hibernate.metamodel.source.spi.SingularAttributeSource; import org.hibernate.metamodel.source.spi.ToOneAttributeSource; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; +import org.hibernate.metamodel.spi.SingularAttributeNature; import org.hibernate.type.ForeignKeyDirection; public abstract class AbstractToOneAttributeSourceImpl extends SingularAttributeSourceImpl implements ToOneAttributeSource{ private final SingularAssociationAttribute associationAttribute; private final Set unifiedCascadeStyles; - private SingularAttributeSource.Nature nature; + private SingularAttributeNature singularAttributeNature; private final Set ownedAssociationSources = new HashSet(); public AbstractToOneAttributeSourceImpl(SingularAssociationAttribute associationAttribute) { @@ -42,19 +44,19 @@ public abstract class AbstractToOneAttributeSourceImpl extends SingularAttribute } @Override - public SingularAttributeSource.Nature getNature() { - return nature; + public SingularAttributeNature getSingularAttributeNature() { + return singularAttributeNature; } protected SingularAssociationAttribute associationAttribute() { return associationAttribute; } - protected void setNature(SingularAttributeSource.Nature nature) { - if ( this.nature != null ) { + protected void setSingularAttributeNature(SingularAttributeNature singularAttributeNature) { + if ( this.singularAttributeNature != null ) { throw new IllegalStateException( "nature is already initialized." ); } - this.nature = nature; + this.singularAttributeNature = singularAttributeNature; } @Override @@ -122,7 +124,7 @@ public abstract class AbstractToOneAttributeSourceImpl extends SingularAttribute @Override public ForeignKeyDirection getForeignKeyDirection() { - return nature == Nature.ONE_TO_ONE && !associationAttribute.isOptional() + return singularAttributeNature == SingularAttributeNature.ONE_TO_ONE && !associationAttribute.isOptional() ? ForeignKeyDirection.FROM_PARENT : ForeignKeyDirection.TO_PARENT; } @@ -131,4 +133,15 @@ public abstract class AbstractToOneAttributeSourceImpl extends SingularAttribute public String toString() { return "ToOneAttributeSourceImpl{role=" + associationAttribute.getRole().getFullPath() + '}'; } + + + @Override + public AttributePath getAttributePath() { + return associationAttribute.getPath(); + } + + @Override + public AttributeRole getAttributeRole() { + return associationAttribute.getRole(); + } } \ No newline at end of file diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/AggregatedCompositeIdentifierSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/AggregatedCompositeIdentifierSourceImpl.java index 3e15f5766d..ca3b9e1e03 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/AggregatedCompositeIdentifierSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/AggregatedCompositeIdentifierSourceImpl.java @@ -28,7 +28,7 @@ import java.util.Collections; import org.hibernate.id.EntityIdentifierNature; import org.hibernate.metamodel.source.spi.AggregatedCompositeIdentifierSource; -import org.hibernate.metamodel.source.spi.ComponentAttributeSource; +import org.hibernate.metamodel.source.spi.EmbeddedAttributeSource; import org.hibernate.metamodel.source.spi.ToolingHintSource; import org.hibernate.metamodel.spi.binding.IdentifierGeneratorDefinition; @@ -51,7 +51,7 @@ class AggregatedCompositeIdentifierSourceImpl } @Override - public ComponentAttributeSource getIdentifierAttributeSource() { + public EmbeddedAttributeSource getIdentifierAttributeSource() { return componentAttributeSource; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/BasicAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/BasicAttributeSourceImpl.java index 3d9ee21d4f..815e913a6b 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/BasicAttributeSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/BasicAttributeSourceImpl.java @@ -31,6 +31,9 @@ import org.hibernate.metamodel.source.internal.annotations.attribute.BasicAttrib import org.hibernate.metamodel.source.internal.annotations.attribute.Column; import org.hibernate.metamodel.source.internal.annotations.attribute.OverrideAndConverterCollector; import org.hibernate.metamodel.source.spi.RelationalValueSource; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; +import org.hibernate.metamodel.spi.SingularAttributeNature; /** * @author Steve Ebersole @@ -61,8 +64,8 @@ public class BasicAttributeSourceImpl extends SingularAttributeSourceImpl { } @Override - public Nature getNature() { - return Nature.BASIC; + public SingularAttributeNature getSingularAttributeNature() { + return SingularAttributeNature.BASIC; } @Override @@ -128,4 +131,14 @@ public class BasicAttributeSourceImpl extends SingularAttributeSourceImpl { return relationalValueSources; } + + @Override + public AttributePath getAttributePath() { + return getAnnotatedAttribute().getPath(); + } + + @Override + public AttributeRole getAttributeRole() { + return getAnnotatedAttribute().getRole(); + } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/BasicPluralAttributeIndexSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/BasicPluralAttributeIndexSourceImpl.java deleted file mode 100644 index ab2282907e..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/BasicPluralAttributeIndexSourceImpl.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2012, 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.metamodel.source.internal.annotations; - -import java.util.Collections; -import java.util.List; - -import org.hibernate.metamodel.internal.binder.Binder; -import org.hibernate.metamodel.source.internal.annotations.attribute.Column; -import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttribute; -import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames; -import org.hibernate.metamodel.source.spi.BasicPluralAttributeIndexSource; -import org.hibernate.metamodel.source.spi.RelationalValueSource; -import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding; - -import org.jboss.jandex.AnnotationInstance; - -/** - * @author Strong Liu - */ -public class BasicPluralAttributeIndexSourceImpl extends AbstractPluralAttributeIndexSourceImpl implements BasicPluralAttributeIndexSource { - private final IndexedPluralAttributeSourceImpl indexedPluralAttributeSource; - private final List relationalValueSources; - private final Binder.DefaultNamingStrategy defaultNamingStrategy; - - public BasicPluralAttributeIndexSourceImpl( - IndexedPluralAttributeSourceImpl indexedPluralAttributeSource, - PluralAttribute attribute, - Binder.DefaultNamingStrategy defaultNamingStrategy) { - this( indexedPluralAttributeSource, attribute, defaultNamingStrategy, createRelationalValueSources( attribute ) ); - } - - public BasicPluralAttributeIndexSourceImpl( - IndexedPluralAttributeSourceImpl indexedPluralAttributeSource, - PluralAttribute attribute, - Binder.DefaultNamingStrategy defaultNamingStrategy, - List relationalValueSources) { - super( attribute ); - this.indexedPluralAttributeSource = indexedPluralAttributeSource; - this.relationalValueSources = relationalValueSources; - this.defaultNamingStrategy = defaultNamingStrategy; - } - - private static List createRelationalValueSources(PluralAttribute attribute) { - // ugh! - // i give up for now... - AnnotationInstance columnAnnotation = attribute.getBackingMember().getAnnotations().get( - JPADotNames.ORDER_COLUMN - ); - if ( columnAnnotation == null ) { - columnAnnotation = attribute.getBackingMember().getAnnotations().get( - JPADotNames.MAP_KEY_COLUMN - ); - } - Column indexColumn = new Column( columnAnnotation ); - return Collections.singletonList( (RelationalValueSource) new ColumnSourceImpl( indexColumn ) ); - } - @Override - public PluralAttributeIndexBinding.Nature getNature() { - return PluralAttributeIndexBinding.Nature.BASIC; - } - - @Override - public List getDefaultNamingStrategies() { - return Collections.singletonList( defaultNamingStrategy ); - } - - @Override - public List relationalValueSources() { - return relationalValueSources; - } - -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/CompositePluralAttributeElementSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/CompositePluralAttributeElementSourceImpl.java deleted file mode 100644 index ce7c9baacf..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/CompositePluralAttributeElementSourceImpl.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * JBoss, Home of Professional Open Source - * Copyright 2012 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. - */ -package org.hibernate.metamodel.source.internal.annotations; - -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Set; - -import org.hibernate.engine.spi.CascadeStyle; -import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; -import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttribute; -import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttributeElementDetailsEmbedded; -import org.hibernate.metamodel.source.internal.annotations.entity.EmbeddableTypeMetadata; -import org.hibernate.metamodel.source.spi.AttributeSource; -import org.hibernate.metamodel.source.spi.CompositePluralAttributeElementSource; -import org.hibernate.metamodel.source.spi.ToolingHintSource; -import org.hibernate.metamodel.spi.LocalBindingContext; - -/** - * @author Brett Meyer - */ -public class CompositePluralAttributeElementSourceImpl - implements CompositePluralAttributeElementSource { - private final PluralAttribute pluralAttribute; - private final Set unifiedCascadeStyles; - private final PluralAttributeElementDetailsEmbedded elementDescriptor; - - private final EmbeddableTypeMetadata embeddableTypeMetadata; - - private final List attributeSources; - - public CompositePluralAttributeElementSourceImpl(PluralAttributeSourceImpl pluralAttributeSource) { - this.pluralAttribute = pluralAttributeSource.getPluralAttribute(); - this.unifiedCascadeStyles = pluralAttributeSource.getUnifiedCascadeStyles(); - - this.elementDescriptor = (PluralAttributeElementDetailsEmbedded) pluralAttribute.getElementDetails(); - this.embeddableTypeMetadata = elementDescriptor.getEmbeddableTypeMetadata(); - - this.attributeSources = SourceHelper.buildAttributeSources( - embeddableTypeMetadata, - SourceHelper.PluralAttributesDisallowedAttributeBuilder.INSTANCE - ); - } - - @Override - public Nature getNature() { - return Nature.AGGREGATE; - } - - @Override - public String getPath() { - // TODO Auto-generated method stub - return null; - } - - @Override - public List attributeSources() { - return attributeSources; - } - - @Override - public LocalBindingContext getLocalBindingContext() { - return pluralAttribute.getContext(); - } - - @Override - public Set getCascadeStyles() { - return unifiedCascadeStyles; - } - - @Override - public Collection getToolingHintSources() { - // HBM only - return Collections.emptyList(); - } - - @Override - public JavaTypeDescriptor getTypeDescriptor() { - return elementDescriptor.getJavaType(); - } - - @Override - public String getParentReferenceAttributeName() { - return embeddableTypeMetadata.getParentReferencingAttributeName(); - } - - @Override - public String getExplicitTuplizerClassName() { - - // TODO ? - return null; - } - -// private void buildAttributeSources() { -// // TODO: Duplicates code in EmbeddedAttributeSourceImpl. -// for ( SimpleAttribute attribute : embeddableTypeMetadata.getSimpleAttributes().values() ) { -// attribute.setNaturalIdMutability( embeddableTypeMetadata.getNaturalIdMutability() ); -// attributeSources.add( new SingularAttributeSourceImpl( attribute ) ); -// } -// for ( EmbeddableTypeMetadata embeddable : embeddableTypeMetadata.getEmbeddedClasses().values() ) { -// embeddable.setNaturalIdMutability( embeddableTypeMetadata.getNaturalIdMutability() ); -// attributeSources.add( -// new EmbeddedAttributeSourceImpl( -// embeddable, -// getPath(), -// embeddableTypeMetadata.getClassLevelAccessType() -// ) -// ); -// } -// for ( AssociationAttribute associationAttribute : embeddableTypeMetadata.getAssociationAttributes().values() ) { -// associationAttribute.setNaturalIdMutability( embeddableTypeMetadata.getNaturalIdMutability() ); -// } -// SourceHelper.resolveAssociationAttributes( embeddableTypeMetadata, attributeSources ); -// } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/AbstractEmbeddableAdapter.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/EmbeddableSourceImpl.java similarity index 58% rename from hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/AbstractEmbeddableAdapter.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/EmbeddableSourceImpl.java index 4eba9c441c..bcf776eaae 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/AbstractEmbeddableAdapter.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/EmbeddableSourceImpl.java @@ -25,31 +25,65 @@ package org.hibernate.metamodel.source.internal.annotations; import java.util.List; +import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; import org.hibernate.metamodel.source.internal.annotations.entity.EmbeddableTypeMetadata; import org.hibernate.metamodel.source.spi.AttributeSource; -import org.hibernate.metamodel.source.spi.AttributeSourceContainer; +import org.hibernate.metamodel.source.spi.EmbeddableSource; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; +import org.hibernate.metamodel.spi.LocalBindingContext; /** * @author Steve Ebersole */ -public abstract class AbstractEmbeddableAdapter implements AttributeSourceContainer { +public class EmbeddableSourceImpl implements EmbeddableSource { private final EmbeddableTypeMetadata embeddableTypeMetadata; private final List attributeSources; - public AbstractEmbeddableAdapter(EmbeddableTypeMetadata embeddableTypeMetadata) { + public EmbeddableSourceImpl( + EmbeddableTypeMetadata embeddableTypeMetadata, + SourceHelper.AttributeBuilder attributeBuilder) { this.embeddableTypeMetadata = embeddableTypeMetadata; - this.attributeSources = SourceHelper.buildAttributeSources( embeddableTypeMetadata, getAttributeBuilder() ); + this.attributeSources = SourceHelper.buildAttributeSources( embeddableTypeMetadata, attributeBuilder ); } protected EmbeddableTypeMetadata getEmbeddableTypeMetadata() { return embeddableTypeMetadata; } + @Override + public AttributePath getAttributePathBase() { + return embeddableTypeMetadata.getAttributePathBase(); + } + + @Override + public AttributeRole getAttributeRoleBase() { + return embeddableTypeMetadata.getAttributeRoleBase(); + } + @Override public List attributeSources() { return attributeSources; } - protected abstract SourceHelper.AttributeBuilder getAttributeBuilder(); + @Override + public JavaTypeDescriptor getTypeDescriptor() { + return embeddableTypeMetadata.getJavaTypeDescriptor(); + } + + @Override + public String getParentReferenceAttributeName() { + return embeddableTypeMetadata.getParentReferencingAttributeName(); + } + + @Override + public String getExplicitTuplizerClassName() { + return embeddableTypeMetadata.getCustomTuplizerClassName(); + } + + @Override + public LocalBindingContext getLocalBindingContext() { + return embeddableTypeMetadata.getLocalBindingContext(); + } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/EmbeddedAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/EmbeddedAttributeSourceImpl.java index d4b7b5a6ee..9e0effa0be 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/EmbeddedAttributeSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/EmbeddedAttributeSourceImpl.java @@ -30,42 +30,57 @@ import java.util.Locale; import org.hibernate.internal.util.StringHelper; import org.hibernate.mapping.PropertyGeneration; -import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; import org.hibernate.metamodel.source.internal.annotations.attribute.EmbeddedAttribute; import org.hibernate.metamodel.source.internal.annotations.attribute.PersistentAttribute; -import org.hibernate.metamodel.source.spi.ComponentAttributeSource; +import org.hibernate.metamodel.source.spi.EmbeddableSource; +import org.hibernate.metamodel.source.spi.EmbeddedAttributeSource; import org.hibernate.metamodel.source.spi.HibernateTypeSource; import org.hibernate.metamodel.source.spi.RelationalValueSource; import org.hibernate.metamodel.source.spi.ToolingHintSource; -import org.hibernate.metamodel.spi.LocalBindingContext; -import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; +import org.hibernate.metamodel.spi.NaturalIdMutability; +import org.hibernate.metamodel.spi.SingularAttributeNature; /** - * Annotation backed implementation of {@code ComponentAttributeSource}. + * Annotation backed implementation of {@code EmbeddedAttributeSource}. * * @author Steve Ebersole * @author Hardy Ferentschik * @author Brett Meyer */ -public class EmbeddedAttributeSourceImpl - extends AbstractEmbeddableAdapter - implements ComponentAttributeSource, AnnotationAttributeSource { +public class EmbeddedAttributeSourceImpl implements EmbeddedAttributeSource, AnnotationAttributeSource { private final EmbeddedAttribute attribute; - private final JavaTypeDescriptor embeddableJavaTypeDescriptor; - private final boolean partOfIdentifier; - private final boolean partOfPersistentCollection; + private final EmbeddableSource embeddableSource; public EmbeddedAttributeSourceImpl( EmbeddedAttribute attribute, boolean partOfIdentifier, boolean partOfPersistentCollection) { - super( attribute.getEmbeddableTypeMetadata() ); + + final SourceHelper.AttributeBuilder attributeBuilder; + if ( partOfIdentifier ) { + attributeBuilder = SourceHelper.IdentifierPathAttributeBuilder.INSTANCE; + } + else if ( partOfPersistentCollection ) { + attributeBuilder = SourceHelper.PluralAttributesDisallowedAttributeBuilder.INSTANCE; + } + else { + attributeBuilder = SourceHelper.StandardAttributeBuilder.INSTANCE; + } + + this.embeddableSource = new EmbeddableSourceImpl( + attribute.getEmbeddableTypeMetadata(), + attributeBuilder + ); this.attribute = attribute; - this.embeddableJavaTypeDescriptor = attribute.getBackingMember().getType().getErasedType(); - this.partOfIdentifier = partOfIdentifier; - this.partOfPersistentCollection = partOfPersistentCollection; + } + + @Override + public EmbeddableSource getEmbeddableSource() { + return embeddableSource; } @Override @@ -79,8 +94,8 @@ public class EmbeddedAttributeSourceImpl } @Override - public Nature getNature() { - return Nature.COMPOSITE; + public SingularAttributeNature getSingularAttributeNature() { + return SingularAttributeNature.COMPOSITE; } @Override @@ -88,21 +103,22 @@ public class EmbeddedAttributeSourceImpl return true; } - @Override - public JavaTypeDescriptor getTypeDescriptor() { - return embeddableJavaTypeDescriptor; - } - @Override public String getName() { return attribute.getName(); } @Override - public String getExplicitTuplizerClassName() { - return attribute.getEmbeddableTypeMetadata().getCustomTuplizerClassName(); + public AttributePath getAttributePath() { + return attribute.getPath(); } + @Override + public AttributeRole getAttributeRole() { + return attribute.getRole(); + } + + @Override public String getPropertyAccessorName() { // todo : would really rather have binder decipher this... @@ -111,21 +127,6 @@ public class EmbeddedAttributeSourceImpl : attribute.getAccessorStrategy(); } - @Override - public LocalBindingContext getLocalBindingContext() { - return attribute.getEmbeddableTypeMetadata().getLocalBindingContext(); - } - - @Override - public String getPath() { - return attribute.getPath().getFullPath(); - } - - @Override - public String getParentReferenceAttributeName() { - return getEmbeddableTypeMetadata().getParentReferencingAttributeName(); - } - @Override public Collection getToolingHintSources() { // not relevant for annotations @@ -161,7 +162,7 @@ public class EmbeddedAttributeSourceImpl } @Override - public SingularAttributeBinding.NaturalIdMutability getNaturalIdMutability() { + public NaturalIdMutability getNaturalIdMutability() { return attribute.getNaturalIdMutability(); } @@ -188,19 +189,6 @@ public class EmbeddedAttributeSourceImpl @Override public String toString() { return "EmbeddedAttributeSourceImpl{role=" + attribute.getRole().getFullPath() - + ", embeddable=" + getTypeDescriptor().getName().toString() + "}"; - } - - @Override - protected SourceHelper.AttributeBuilder getAttributeBuilder() { - if ( partOfIdentifier ) { - return SourceHelper.IdentifierPathAttributeBuilder.INSTANCE; - } - - if ( partOfPersistentCollection ) { - return SourceHelper.PluralAttributesDisallowedAttributeBuilder.INSTANCE; - } - - return SourceHelper.StandardAttributeBuilder.INSTANCE; + + ", embeddable=" + embeddableSource.getTypeDescriptor().getName().toString() + "}"; } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/IdentifiableTypeSourceAdapter.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/IdentifiableTypeSourceAdapter.java index 0704a6c0b3..eb40606d6f 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/IdentifiableTypeSourceAdapter.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/IdentifiableTypeSourceAdapter.java @@ -37,6 +37,8 @@ import org.hibernate.metamodel.source.spi.AttributeSource; import org.hibernate.metamodel.source.spi.EntityHierarchySource; import org.hibernate.metamodel.source.spi.IdentifiableTypeSource; import org.hibernate.metamodel.source.spi.JpaCallbackSource; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; import org.hibernate.metamodel.spi.LocalBindingContext; import org.hibernate.metamodel.spi.binding.InheritanceType; import org.hibernate.xml.spi.Origin; @@ -204,8 +206,13 @@ public abstract class IdentifiableTypeSourceAdapter implements IdentifiableTypeS } @Override - public String getPath() { - return ""; + public AttributePath getAttributePathBase() { + return identifiableTypeMetadata.getAttributePathBase(); + } + + @Override + public AttributeRole getAttributeRoleBase() { + return identifiableTypeMetadata.getAttributeRoleBase(); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/IndexedPluralAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/IndexedPluralAttributeSourceImpl.java deleted file mode 100644 index 5c2f806b3e..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/IndexedPluralAttributeSourceImpl.java +++ /dev/null @@ -1,245 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2012, 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.metamodel.source.internal.annotations; - -import java.util.EnumSet; - -import org.hibernate.cfg.NamingStrategy; -import org.hibernate.cfg.NotYetImplementedException; -import org.hibernate.metamodel.internal.binder.Binder; -import org.hibernate.metamodel.source.internal.annotations.attribute.AbstractPersistentAttribute; -import org.hibernate.metamodel.source.internal.annotations.attribute.OverrideAndConverterCollector; -import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttribute; -import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames; -import org.hibernate.metamodel.source.spi.AttributeSource; -import org.hibernate.metamodel.source.spi.AttributeSourceResolutionContext; -import org.hibernate.metamodel.source.spi.ComponentAttributeSource; -import org.hibernate.metamodel.source.spi.IdentifierSource; -import org.hibernate.metamodel.source.spi.IndexedPluralAttributeSource; -import org.hibernate.metamodel.source.spi.MappingException; -import org.hibernate.metamodel.source.spi.PluralAttributeIndexSource; -import org.hibernate.metamodel.source.spi.PluralAttributeSource; -import org.hibernate.metamodel.source.spi.SimpleIdentifierSource; -import org.hibernate.metamodel.source.spi.SingularAttributeSource; - -import org.jboss.jandex.AnnotationInstance; - -/** - * @author Strong Liu - */ -public class IndexedPluralAttributeSourceImpl extends PluralAttributeSourceImpl - implements IndexedPluralAttributeSource { - - private final static EnumSet VALID_NATURES = EnumSet.of( - AbstractPersistentAttribute.Nature.MANY_TO_MANY, - AbstractPersistentAttribute.Nature.ONE_TO_MANY, - AbstractPersistentAttribute.Nature.ELEMENT_COLLECTION_BASIC, - AbstractPersistentAttribute.Nature.ELEMENT_COLLECTION_EMBEDDABLE - ); - - private PluralAttributeIndexSource indexSource; - - public IndexedPluralAttributeSourceImpl( - PluralAttribute attribute, - OverrideAndConverterCollector overrideAndConverterCollector) { - super( attribute, overrideAndConverterCollector ); - if ( !VALID_NATURES.contains( attribute.getNature() ) ) { - throw new MappingException( - "Indexed column could be only mapped on the MANY side", - attribute.getContext().getOrigin() - ); - } - - if ( attribute.getPluralAttributeNature() == PluralAttributeSource.Nature.ARRAY - && !attribute.getBackingMember().getAnnotations().containsKey( JPADotNames.ORDER_COLUMN ) ) { - throw attribute.getContext().makeMappingException( - "Persistent arrays must be annotated with @OrderColumn : " + attribute.getRole() - ); - } - - this.indexSource = determineIndexSourceInfo( attribute ); - } - - private PluralAttributeIndexSource determineIndexSourceInfo(final PluralAttribute attribute) { - // could be an array/list - if ( attribute.getPluralAttributeNature() == Nature.ARRAY - || attribute.getPluralAttributeNature() == Nature.LIST ) { - final Binder.DefaultNamingStrategy defaultNamingStrategy = new Binder.DefaultNamingStrategy() { - @Override - public String defaultName(NamingStrategy namingStrategy) { - return namingStrategy.propertyToColumnName( attribute.getName() ) + "_ORDER"; - } - }; - return new SequentialPluralAttributeIndexSourceImpl( this, attribute, defaultNamingStrategy ); - } - - // or a map - return determineMapKeyInfo( attribute ); - } - - private PluralAttributeIndexSource determineMapKeyInfo(final PluralAttribute attribute) { - final AnnotationInstance mapKey = attribute.getBackingMember().getAnnotations().get( JPADotNames.MAP_KEY ); - final AnnotationInstance mapKeyClass = attribute.getBackingMember().getAnnotations().get( JPADotNames.MAP_KEY_CLASS ); - - if ( mapKey != null && mapKeyClass != null ) { - // this is an error according to the spec... - throw attribute.getContext().makeMappingException( - "Map attribute [" + attribute.getName() + "] defined both " + - "@MapKey and @MapKeyClass; only one should be used" - ); - } - - if ( mapKey != null ) { - // need to wait until the ID or attribute source can be resolved. - return null; - } - - if ( mapKeyClass != null ) { - throw new NotYetImplementedException( "@MapKeyClass is not supported yet." ); - } - - - final AnnotationInstance mapKeyColumn = attribute.getBackingMember().getAnnotations().get( JPADotNames.MAP_KEY_COLUMN ); - if ( mapKeyColumn != null ) { - // todo : does this cover @MapKeyType??? - final Binder.DefaultNamingStrategy defaultNamingStrategy = new Binder.DefaultNamingStrategy() { - @Override - public String defaultName(NamingStrategy namingStrategy) { - return namingStrategy.propertyToColumnName( attribute.getName() ) + "_KEY"; - } - }; - return new BasicPluralAttributeIndexSourceImpl( this, attribute, defaultNamingStrategy ); - } - - - if ( attribute.getBackingMember().getAnnotations().containsKey( JPADotNames.MAP_KEY_ENUMERATED ) ) { - // basic - throw new NotYetImplementedException( "@MapKeyEnumerated is not supported yet." ); - } - else if ( attribute.getBackingMember().getAnnotations().containsKey( JPADotNames.MAP_KEY_TEMPORAL ) ) { - // basic - throw new NotYetImplementedException( "@MapKeyTemporal is not supported yet." ); - } - else if ( attribute.getBackingMember().getAnnotations().containsKey( JPADotNames.MAP_KEY_JOIN_COLUMN ) ) { - // association - throw new NotYetImplementedException( "@MapKeyJoinColumn is not supported yet." ); - } - else if ( attribute.getBackingMember().getAnnotations().containsKey( JPADotNames.MAP_KEY_JOIN_COLUMNS ) ) { - // association - throw new NotYetImplementedException( "@MapKeyJoinColumns is not supported yet." ); - } - - // todo : some of these in general ought to move to the attribute.getIndexDetails() - - - // default, just assume the key is a "basic" type - final Binder.DefaultNamingStrategy defaultNamingStrategy = new Binder.DefaultNamingStrategy() { - @Override - public String defaultName(NamingStrategy namingStrategy) { - return namingStrategy.propertyToColumnName( attribute.getName() ) + "_KEY"; - } - }; - return new BasicPluralAttributeIndexSourceImpl( this, attribute, defaultNamingStrategy ); - } - - @Override - public PluralAttributeIndexSource resolvePluralAttributeIndexSource(AttributeSourceResolutionContext attributeSourceResolutionContext) { - if ( indexSource == null ) { - final AnnotationInstance mapKey = pluralAssociationAttribute().getBackingMember().getAnnotations().get( JPADotNames.MAP_KEY ); - if ( mapKey != null ) { - indexSource = resolveMapKeyPluralAttributeIndexSource( attributeSourceResolutionContext, mapKey ); - } - else { - throw new NotYetImplementedException( "cannot resolve index source." ); - } - } - return indexSource; - } - - private PluralAttributeIndexSource resolveMapKeyPluralAttributeIndexSource( - AttributeSourceResolutionContext attributeSourceResolutionContext, - AnnotationInstance mapKey) { - final String attributeName = mapKey.value( "name" ).asString(); - final PluralAttributeIndexSource innerIndexSource; - if ( attributeName == null ) { - final IdentifierSource identifierSource = attributeSourceResolutionContext.resolveIdentifierSource( - pluralAssociationAttribute().getElementDetails().getJavaType().getName().toString() - ); - switch ( identifierSource.getNature() ) { - case SIMPLE: { - innerIndexSource = new BasicPluralAttributeIndexSourceImpl( - this, - pluralAssociationAttribute(), - null, - ( (SimpleIdentifierSource) identifierSource ).getIdentifierAttributeSource().relationalValueSources() ); - break; - } - default: { - throw new NotYetImplementedException( "Only simple IDs are supported for @MapKey" ); - } - } - } - else { - AttributeSource attributeSource = attributeSourceResolutionContext.resolveAttributeSource( - pluralAssociationAttribute().getElementDetails().getJavaType().getName().toString(), - attributeName - ); - if ( ! attributeSource.isSingular() ) { - throw new MappingException( - String.format( - "Plural attribute index [%s.%s] is not a singular attribute.", - pluralAssociationAttribute().getElementDetails().getJavaType().getName().toString(), - attributeName - ), - pluralAssociationAttribute().getContext().getOrigin() - ); - } - final SingularAttributeSource mapKeyAttributeSource = (SingularAttributeSource) attributeSource; - switch ( mapKeyAttributeSource.getNature() ) { - case BASIC: - innerIndexSource = new BasicPluralAttributeIndexSourceImpl( - this, - pluralAssociationAttribute(), - null, - mapKeyAttributeSource.relationalValueSources() ); - break; - case COMPOSITE: - innerIndexSource = new CompositePluralAttributeIndexSourceImpl( - pluralAssociationAttribute(), - ( (ComponentAttributeSource) attributeSource ).attributeSources(), - null - ); - break; - default: - throw new NotYetImplementedException( "Only basic plural attribute index sources are supported for @MapKey" ); - } - } - return new MapKeyPluralAttributeIndexSourceImpl( pluralAssociationAttribute(), innerIndexSource, attributeName ); - } - - @Override - public PluralAttributeIndexSource getIndexSource() { - return indexSource; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/ManyToAnyPluralAttributeElementSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/ManyToAnyPluralAttributeElementSourceImpl.java deleted file mode 100644 index 208fad12db..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/ManyToAnyPluralAttributeElementSourceImpl.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.hibernate.metamodel.source.internal.annotations; - -import org.hibernate.metamodel.source.spi.ManyToAnyPluralAttributeElementSource; - -/** - * @author Hardy Ferentschik - */ -public class ManyToAnyPluralAttributeElementSourceImpl - extends AbstractPluralAssociationElementSourceImpl - implements ManyToAnyPluralAttributeElementSource { - - public ManyToAnyPluralAttributeElementSourceImpl(PluralAttributeSourceImpl pluralAttributeSource) { - super( pluralAttributeSource ); - } - - @Override - public Nature getNature() { - return Nature.MANY_TO_ANY; - } -} - diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/ManyToManyMappedByPluralAttributeElementSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/MappedByPluralAttributeElementSourceAssociationManyToManyImpl.java similarity index 88% rename from hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/ManyToManyMappedByPluralAttributeElementSourceImpl.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/MappedByPluralAttributeElementSourceAssociationManyToManyImpl.java index 676961cdad..56f04a5353 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/ManyToManyMappedByPluralAttributeElementSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/MappedByPluralAttributeElementSourceAssociationManyToManyImpl.java @@ -9,11 +9,11 @@ import org.hibernate.metamodel.source.spi.RelationalValueSource; /** * @author Gail Badner */ -public class ManyToManyMappedByPluralAttributeElementSourceImpl - extends AbstractManyToManyPluralAttributeElementSourceImpl +public class MappedByPluralAttributeElementSourceAssociationManyToManyImpl + extends AbstractPluralAttributeElementSourceAssociationManyToManyImpl implements MappedByAssociationSource { - public ManyToManyMappedByPluralAttributeElementSourceImpl(PluralAttributeSourceImpl pluralAttributeSource) { + public MappedByPluralAttributeElementSourceAssociationManyToManyImpl(PluralAttributeSourceImpl pluralAttributeSource) { super( pluralAttributeSource ); if ( pluralAssociationAttribute().getMappedByAttributeName() == null ) { throw new AssertionFailure( "pluralAssociationAttribute().getMappedByAttributeName() must be non-null." ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/OneToManyMappedByPluralAttributeElementSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/MappedByPluralAttributeElementSourceAssociationOneToManyImpl.java similarity index 84% rename from hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/OneToManyMappedByPluralAttributeElementSourceImpl.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/MappedByPluralAttributeElementSourceAssociationOneToManyImpl.java index 3de312f81e..6b54205503 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/OneToManyMappedByPluralAttributeElementSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/MappedByPluralAttributeElementSourceAssociationOneToManyImpl.java @@ -29,10 +29,10 @@ import org.hibernate.metamodel.source.spi.MappedByAssociationSource; /** * @author Gail Badner */ -public class OneToManyMappedByPluralAttributeElementSourceImpl - extends OneToManyPluralAttributeElementSourceImpl implements MappedByAssociationSource { +public class MappedByPluralAttributeElementSourceAssociationOneToManyImpl + extends PluralAttributeElementSourceAssociationOneToManyImpl implements MappedByAssociationSource { - public OneToManyMappedByPluralAttributeElementSourceImpl(PluralAttributeSourceImpl pluralAttributeSource) { + public MappedByPluralAttributeElementSourceAssociationOneToManyImpl(PluralAttributeSourceImpl pluralAttributeSource) { super( pluralAttributeSource ); if ( pluralAttributeSource.pluralAssociationAttribute().getMappedByAttributeName() == null ) { throw new AssertionFailure( "pluralAssociationAttribute().getMappedByAttributeName() must be non-null." ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/PluralAttributeElementSourceAssociationManyToAnyImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/PluralAttributeElementSourceAssociationManyToAnyImpl.java new file mode 100644 index 0000000000..01467b3920 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/PluralAttributeElementSourceAssociationManyToAnyImpl.java @@ -0,0 +1,22 @@ +package org.hibernate.metamodel.source.internal.annotations; + +import org.hibernate.metamodel.source.spi.PluralAttributeElementSourceManyToAny; +import org.hibernate.metamodel.spi.PluralAttributeElementNature; + +/** + * @author Hardy Ferentschik + */ +public class PluralAttributeElementSourceAssociationManyToAnyImpl + extends AbstractPluralElementSourceAssociationImpl + implements PluralAttributeElementSourceManyToAny { + + public PluralAttributeElementSourceAssociationManyToAnyImpl(PluralAttributeSourceImpl pluralAttributeSource) { + super( pluralAttributeSource ); + } + + @Override + public PluralAttributeElementNature getNature() { + return PluralAttributeElementNature.MANY_TO_ANY; + } +} + diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/ManyToManyPluralAttributeElementSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/PluralAttributeElementSourceAssociationManyToManyImpl.java similarity index 92% rename from hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/ManyToManyPluralAttributeElementSourceImpl.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/PluralAttributeElementSourceAssociationManyToManyImpl.java index d63c009b35..a9de8f83f6 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/ManyToManyPluralAttributeElementSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/PluralAttributeElementSourceAssociationManyToManyImpl.java @@ -31,7 +31,7 @@ import org.hibernate.internal.util.StringHelper; import org.hibernate.metamodel.source.internal.annotations.attribute.Column; import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames; import org.hibernate.metamodel.source.spi.ForeignKeyContributingSource; -import org.hibernate.metamodel.source.spi.ManyToManyPluralAttributeElementSource; +import org.hibernate.metamodel.source.spi.PluralAttributeElementSourceManyToMany; import org.hibernate.metamodel.source.spi.RelationalValueSource; import org.hibernate.metamodel.spi.relational.TableSpecification; import org.hibernate.metamodel.spi.relational.Value; @@ -44,13 +44,13 @@ import org.jboss.jandex.AnnotationValue; * @author Brett Meyer * @author Gail Badner */ -public class ManyToManyPluralAttributeElementSourceImpl - extends AbstractManyToManyPluralAttributeElementSourceImpl - implements ManyToManyPluralAttributeElementSource { +public class PluralAttributeElementSourceAssociationManyToManyImpl + extends AbstractPluralAttributeElementSourceAssociationManyToManyImpl + implements PluralAttributeElementSourceManyToMany { private final List relationalValueSources = new ArrayList(); - public ManyToManyPluralAttributeElementSourceImpl(PluralAttributeSourceImpl pluralAttributeSource) { + public PluralAttributeElementSourceAssociationManyToManyImpl(PluralAttributeSourceImpl pluralAttributeSource) { super( pluralAttributeSource ); if ( pluralAttributeSource.getMappedBy() != null ) { throw new AssertionFailure( "pluralAttributeSource.getMappedByAttributeName() must be null." ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/OneToManyPluralAttributeElementSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/PluralAttributeElementSourceAssociationOneToManyImpl.java similarity index 69% rename from hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/OneToManyPluralAttributeElementSourceImpl.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/PluralAttributeElementSourceAssociationOneToManyImpl.java index 500e819fca..a8a56253df 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/OneToManyPluralAttributeElementSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/PluralAttributeElementSourceAssociationOneToManyImpl.java @@ -23,22 +23,23 @@ */ package org.hibernate.metamodel.source.internal.annotations; -import org.hibernate.metamodel.source.spi.OneToManyPluralAttributeElementSource; +import org.hibernate.metamodel.source.spi.PluralAttributeElementSourceOneToMany; +import org.hibernate.metamodel.spi.PluralAttributeElementNature; /** * @author Hardy Ferentschik */ -public class OneToManyPluralAttributeElementSourceImpl - extends AbstractPluralAssociationElementSourceImpl - implements OneToManyPluralAttributeElementSource { +public class PluralAttributeElementSourceAssociationOneToManyImpl + extends AbstractPluralElementSourceAssociationImpl + implements PluralAttributeElementSourceOneToMany { - public OneToManyPluralAttributeElementSourceImpl(PluralAttributeSourceImpl pluralAttributeSource) { + public PluralAttributeElementSourceAssociationOneToManyImpl(PluralAttributeSourceImpl pluralAttributeSource) { super( pluralAttributeSource ); } @Override - public Nature getNature() { - return Nature.ONE_TO_MANY; + public PluralAttributeElementNature getNature() { + return PluralAttributeElementNature.ONE_TO_MANY; } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/BasicPluralAttributeElementSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/PluralAttributeElementSourceBasicImpl.java similarity index 75% rename from hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/BasicPluralAttributeElementSourceImpl.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/PluralAttributeElementSourceBasicImpl.java index b35e026221..da9cc35083 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/BasicPluralAttributeElementSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/PluralAttributeElementSourceBasicImpl.java @@ -5,19 +5,20 @@ import java.util.List; import org.hibernate.metamodel.source.internal.annotations.attribute.Column; import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttribute; -import org.hibernate.metamodel.source.spi.BasicPluralAttributeElementSource; import org.hibernate.metamodel.source.spi.HibernateTypeSource; +import org.hibernate.metamodel.source.spi.PluralAttributeElementSourceBasic; import org.hibernate.metamodel.source.spi.RelationalValueSource; +import org.hibernate.metamodel.spi.PluralAttributeElementNature; /** * @author Hardy Ferentschik */ -public class BasicPluralAttributeElementSourceImpl +public class PluralAttributeElementSourceBasicImpl extends AbstractPluralAttributeElementSourceImpl - implements BasicPluralAttributeElementSource { - private final Nature nature; + implements PluralAttributeElementSourceBasic { + private final PluralAttributeElementNature nature; - public BasicPluralAttributeElementSourceImpl(PluralAttributeSourceImpl pluralAttributeSource) { + public PluralAttributeElementSourceBasicImpl(PluralAttributeSourceImpl pluralAttributeSource) { super( pluralAttributeSource ); this.nature = resolveNature( getPluralAttribute() ); } @@ -28,17 +29,17 @@ public class BasicPluralAttributeElementSourceImpl } @Override - public Nature getNature() { + public PluralAttributeElementNature getNature() { return nature; } - private static Nature resolveNature(PluralAttribute attribute){ + private static PluralAttributeElementNature resolveNature(PluralAttribute attribute){ switch ( attribute.getNature() ) { case ELEMENT_COLLECTION_BASIC: { - return Nature.BASIC; + return PluralAttributeElementNature.BASIC; } case ELEMENT_COLLECTION_EMBEDDABLE: { - return Nature.AGGREGATE; + return PluralAttributeElementNature.AGGREGATE; } default: { throw new AssertionError( diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/PluralAttributeElementSourceEmbeddedImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/PluralAttributeElementSourceEmbeddedImpl.java new file mode 100644 index 0000000000..4c858aa0f1 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/PluralAttributeElementSourceEmbeddedImpl.java @@ -0,0 +1,78 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * JBoss, Home of Professional Open Source + * Copyright 2012 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. + */ +package org.hibernate.metamodel.source.internal.annotations; + +import java.util.Collection; +import java.util.Collections; +import java.util.Set; + +import org.hibernate.engine.spi.CascadeStyle; +import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttribute; +import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttributeElementDetailsEmbedded; +import org.hibernate.metamodel.source.spi.EmbeddableSource; +import org.hibernate.metamodel.source.spi.PluralAttributeElementSourceEmbedded; +import org.hibernate.metamodel.source.spi.ToolingHintSource; +import org.hibernate.metamodel.spi.PluralAttributeElementNature; + +/** + * @author Brett Meyer + */ +public class PluralAttributeElementSourceEmbeddedImpl + implements PluralAttributeElementSourceEmbedded { + private final PluralAttribute pluralAttribute; + private final Set unifiedCascadeStyles; + private final PluralAttributeElementDetailsEmbedded elementDescriptor; + + private final EmbeddableSourceImpl embeddableSource; + + public PluralAttributeElementSourceEmbeddedImpl(PluralAttributeSourceImpl pluralAttributeSource) { + this.pluralAttribute = pluralAttributeSource.getPluralAttribute(); + this.unifiedCascadeStyles = pluralAttributeSource.getUnifiedCascadeStyles(); + + this.elementDescriptor = (PluralAttributeElementDetailsEmbedded) pluralAttribute.getElementDetails(); + this.embeddableSource = new EmbeddableSourceImpl( + elementDescriptor.getEmbeddableTypeMetadata(), + SourceHelper.PluralAttributesDisallowedAttributeBuilder.INSTANCE + ); + } + + @Override + public PluralAttributeElementNature getNature() { + return PluralAttributeElementNature.AGGREGATE; + } + + + @Override + public EmbeddableSource getEmbeddableSource() { + return embeddableSource; + } + + @Override + public Set getCascadeStyles() { + return unifiedCascadeStyles; + } + + @Override + public Collection getToolingHintSources() { + // HBM only + return Collections.emptyList(); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/PluralAttributeIdBagSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/PluralAttributeIdBagSourceImpl.java new file mode 100644 index 0000000000..783e5397a9 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/PluralAttributeIdBagSourceImpl.java @@ -0,0 +1,40 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2014, 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.metamodel.source.internal.annotations; + +import org.hibernate.metamodel.source.internal.annotations.attribute.OverrideAndConverterCollector; +import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttribute; + +/** + * @author Steve Ebersole + */ +public class PluralAttributeIdBagSourceImpl extends PluralAttributeSourceImpl { + public PluralAttributeIdBagSourceImpl( + PluralAttribute pluralAttribute, + OverrideAndConverterCollector overrideAndConverterCollector) { + super( pluralAttribute, overrideAndConverterCollector ); + } + + // todo : source contracts still need a notion of id-bag +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/PluralAttributeIndexedSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/PluralAttributeIndexedSourceImpl.java new file mode 100644 index 0000000000..b9dbf99c52 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/PluralAttributeIndexedSourceImpl.java @@ -0,0 +1,80 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2012, 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.metamodel.source.internal.annotations; + +import java.util.EnumSet; + +import org.hibernate.metamodel.source.internal.annotations.attribute.AbstractPersistentAttribute; +import org.hibernate.metamodel.source.internal.annotations.attribute.OverrideAndConverterCollector; +import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttribute; +import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames; +import org.hibernate.metamodel.source.spi.IndexedPluralAttributeSource; +import org.hibernate.metamodel.source.spi.MappingException; +import org.hibernate.metamodel.source.spi.PluralAttributeIndexSource; +import org.hibernate.metamodel.spi.PluralAttributeNature; + +/** + * @author Strong Liu + * @author Steve Ebersole + */ +public class PluralAttributeIndexedSourceImpl + extends PluralAttributeSourceImpl + implements IndexedPluralAttributeSource { + + private final static EnumSet VALID_NATURES = EnumSet.of( + AbstractPersistentAttribute.Nature.MANY_TO_MANY, + AbstractPersistentAttribute.Nature.ONE_TO_MANY, + AbstractPersistentAttribute.Nature.ELEMENT_COLLECTION_BASIC, + AbstractPersistentAttribute.Nature.ELEMENT_COLLECTION_EMBEDDABLE + ); + + private PluralAttributeIndexSource indexSource; + + public PluralAttributeIndexedSourceImpl( + PluralAttribute attribute, + OverrideAndConverterCollector overrideAndConverterCollector) { + super( attribute, overrideAndConverterCollector ); + if ( !VALID_NATURES.contains( attribute.getNature() ) ) { + throw new MappingException( + "Indexed column could be only mapped on the MANY side", + attribute.getContext().getOrigin() + ); + } + + if ( attribute.getPluralAttributeNature() == PluralAttributeNature.ARRAY + && !attribute.getBackingMember().getAnnotations().containsKey( JPADotNames.ORDER_COLUMN ) ) { + throw attribute.getContext().makeMappingException( + "Persistent arrays must be annotated with @OrderColumn : " + attribute.getRole() + ); + } + + this.indexSource = new PluralAttributeSequentialIndexSourceImpl( attribute ); + } + + + @Override + public PluralAttributeIndexSource getIndexSource() { + return indexSource; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/MapKeyPluralAttributeIndexSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/PluralAttributeMapKeySourceBasicImpl.java similarity index 53% rename from hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/MapKeyPluralAttributeIndexSourceImpl.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/PluralAttributeMapKeySourceBasicImpl.java index 2f1665c7c5..002683d21c 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/MapKeyPluralAttributeIndexSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/PluralAttributeMapKeySourceBasicImpl.java @@ -1,7 +1,7 @@ /* * Hibernate, Relational Persistence for Idiomatic Java * - * Copyright (c) 2013, Red Hat Inc. or third-party contributors as + * Copyright (c) 2012, 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. @@ -23,53 +23,50 @@ */ package org.hibernate.metamodel.source.internal.annotations; +import java.util.Collections; import java.util.List; import org.hibernate.metamodel.internal.binder.Binder; +import org.hibernate.metamodel.source.internal.annotations.attribute.Column; import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttribute; -import org.hibernate.metamodel.source.spi.EntityAttributePluralAttributeIndexSource; -import org.hibernate.metamodel.source.spi.PluralAttributeIndexSource; +import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttributeIndexDetailsMapKeyBasic; +import org.hibernate.metamodel.source.spi.PluralAttributeMapKeySourceBasic; import org.hibernate.metamodel.source.spi.RelationalValueSource; -import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding; +import org.hibernate.metamodel.spi.PluralAttributeIndexNature; /** - * @author Gail Badner + * @author Steve Ebersole + * @author Strong Liu */ -public class MapKeyPluralAttributeIndexSourceImpl extends AbstractPluralAttributeIndexSourceImpl implements EntityAttributePluralAttributeIndexSource { - private final PluralAttributeIndexSource pluralAttributeIndexSource; - private final String attributeName; +public class PluralAttributeMapKeySourceBasicImpl + extends AbstractPluralAttributeIndexSourceImpl + implements PluralAttributeMapKeySourceBasic { + private final List relationalValueSources; + private final Binder.DefaultNamingStrategy defaultNamingStrategy; - public MapKeyPluralAttributeIndexSourceImpl( + public PluralAttributeMapKeySourceBasicImpl( PluralAttribute attribute, - PluralAttributeIndexSource pluralAttributeIndexSource, - String attributeName) { + PluralAttributeIndexDetailsMapKeyBasic mapKeyDetails) { super( attribute ); - this.pluralAttributeIndexSource = pluralAttributeIndexSource; - this.attributeName = attributeName; + this.defaultNamingStrategy = new PluralAttributeMapSourceImpl.MapKeyColumnDefaultNaming( attribute ); + this.relationalValueSources = Collections.singletonList( + (RelationalValueSource) new ColumnSourceImpl( new Column( mapKeyDetails.getMapKeyColumnAnnotation() ) ) + ); } @Override - public String getAttributeName() { - return attributeName; - } - - @Override - public PluralAttributeIndexBinding.Nature getNature() { - return pluralAttributeIndexSource.getNature(); + public PluralAttributeIndexNature getNature() { + return PluralAttributeIndexNature.BASIC; } @Override public List getDefaultNamingStrategies() { - return pluralAttributeIndexSource.getDefaultNamingStrategies(); - } - - @Override - public boolean isReferencedEntityAttribute() { - return true; + return Collections.singletonList( defaultNamingStrategy ); } @Override public List relationalValueSources() { - return pluralAttributeIndexSource.relationalValueSources(); + return relationalValueSources; } + } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/CompositePluralAttributeIndexSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/PluralAttributeMapKeySourceEmbeddedImpl.java similarity index 59% rename from hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/CompositePluralAttributeIndexSourceImpl.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/PluralAttributeMapKeySourceEmbeddedImpl.java index 885a93f312..9595976428 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/CompositePluralAttributeIndexSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/PluralAttributeMapKeySourceEmbeddedImpl.java @@ -23,39 +23,48 @@ */ package org.hibernate.metamodel.source.internal.annotations; -import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.hibernate.metamodel.internal.binder.Binder; import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttribute; -import org.hibernate.metamodel.source.spi.AttributeSource; -import org.hibernate.metamodel.source.spi.CompositePluralAttributeIndexSource; +import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttributeIndexDetailsMapKeyEmbedded; +import org.hibernate.metamodel.source.spi.EmbeddableSource; +import org.hibernate.metamodel.source.spi.PluralAttributeMapKeySourceEmbedded; import org.hibernate.metamodel.source.spi.RelationalValueSource; -import org.hibernate.metamodel.spi.LocalBindingContext; -import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding; +import org.hibernate.metamodel.spi.PluralAttributeIndexNature; /** * @author Gail Badner */ -public class CompositePluralAttributeIndexSourceImpl extends AbstractPluralAttributeIndexSourceImpl implements CompositePluralAttributeIndexSource { - private final List relationalValueSources = new ArrayList( 1 ); - private final Binder.DefaultNamingStrategy defaultNamingStrategy; - private final List attributeSources; +public class PluralAttributeMapKeySourceEmbeddedImpl + extends AbstractPluralAttributeIndexSourceImpl + implements PluralAttributeMapKeySourceEmbedded { - public CompositePluralAttributeIndexSourceImpl( + private final EmbeddableSourceImpl embeddableSource; + private final Binder.DefaultNamingStrategy defaultNamingStrategy; + + public PluralAttributeMapKeySourceEmbeddedImpl( PluralAttribute attribute, - List attributeSources, - Binder.DefaultNamingStrategy defaultNamingStrategy) { + PluralAttributeIndexDetailsMapKeyEmbedded mapKeyDetails) { super( attribute ); - this.attributeSources = attributeSources; - this.defaultNamingStrategy = defaultNamingStrategy; + + this.embeddableSource = new EmbeddableSourceImpl( + mapKeyDetails.getEmbeddableTypeMetadata(), + SourceHelper.IdentifierPathAttributeBuilder.INSTANCE + ); + this.defaultNamingStrategy = new PluralAttributeMapSourceImpl.MapKeyColumnDefaultNaming( attribute ); } @Override - public PluralAttributeIndexBinding.Nature getNature() { - return PluralAttributeIndexBinding.Nature.AGGREGATE; + public PluralAttributeIndexNature getNature() { + return PluralAttributeIndexNature.AGGREGATE; + } + + @Override + public EmbeddableSource getEmbeddableSource() { + return embeddableSource; } @Override @@ -63,14 +72,9 @@ public class CompositePluralAttributeIndexSourceImpl extends AbstractPluralAttri return Collections.singletonList( defaultNamingStrategy ); } - @Override - public boolean isReferencedEntityAttribute() { - return false; - } - @Override public List relationalValueSources() { - return relationalValueSources; + return null; } @Override @@ -89,21 +93,6 @@ public class CompositePluralAttributeIndexSourceImpl extends AbstractPluralAttri } public JavaTypeDescriptor getTypeDescriptor() { - return pluralAssociationAttribute().getIndexDetails().getJavaType(); - } - - @Override - public String getPath() { - return null; //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public List attributeSources() { - return attributeSources; - } - - @Override - public LocalBindingContext getLocalBindingContext() { - return pluralAssociationAttribute().getContext(); + return embeddableSource.getTypeDescriptor(); } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/PluralAttributeMapKeySourceEntityAttributeImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/PluralAttributeMapKeySourceEntityAttributeImpl.java new file mode 100644 index 0000000000..b57a939da6 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/PluralAttributeMapKeySourceEntityAttributeImpl.java @@ -0,0 +1,150 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2014, 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.metamodel.source.internal.annotations; + +import java.util.List; + +import org.hibernate.metamodel.internal.binder.Binder; +import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttribute; +import org.hibernate.metamodel.source.spi.AggregatedCompositeIdentifierSource; +import org.hibernate.metamodel.source.spi.AttributeSource; +import org.hibernate.metamodel.source.spi.AttributeSourceResolutionContext; +import org.hibernate.metamodel.source.spi.IdentifierSource; +import org.hibernate.metamodel.source.spi.MappingException; +import org.hibernate.metamodel.source.spi.PluralAttributeIndexSource; +import org.hibernate.metamodel.source.spi.PluralAttributeIndexSourceResolver; +import org.hibernate.metamodel.source.spi.PluralAttributeMapKeySourceEntityAttribute; +import org.hibernate.metamodel.source.spi.RelationalValueSource; +import org.hibernate.metamodel.source.spi.SimpleIdentifierSource; +import org.hibernate.metamodel.source.spi.SingularAttributeSource; +import org.hibernate.metamodel.spi.PluralAttributeIndexNature; + +/** + * Modeling of the JPA {@link javax.persistence.MapKey} annotation + * + * @author Steve Ebersole + */ +public class PluralAttributeMapKeySourceEntityAttributeImpl + extends AbstractPluralAttributeIndexSourceImpl + implements PluralAttributeMapKeySourceEntityAttribute, PluralAttributeIndexSourceResolver { + + private final String mapKeyAttributeName; + private final Binder.DefaultNamingStrategy defaultNamingStrategy; + private SingularAttributeSource mapKeyAttributeSource; + + public PluralAttributeMapKeySourceEntityAttributeImpl( + PluralAttribute attribute, + String mapKeyAttributeName) { + super( attribute ); + this.mapKeyAttributeName = mapKeyAttributeName; + this.defaultNamingStrategy = new PluralAttributeMapSourceImpl.MapKeyColumnDefaultNaming( attribute ); + } + + @Override + public PluralAttributeIndexSource resolvePluralAttributeIndexSource(AttributeSourceResolutionContext context) { + if ( mapKeyAttributeName == null ) { + final IdentifierSource identifierSource = context.resolveIdentifierSource( + pluralAttribute().getElementDetails().getJavaType().getName().toString() + ); + switch ( identifierSource.getNature() ) { + case SIMPLE: { + mapKeyAttributeSource = ( (SimpleIdentifierSource) identifierSource ).getIdentifierAttributeSource(); + break; + } + case AGGREGATED_COMPOSITE: { + mapKeyAttributeSource = ( (AggregatedCompositeIdentifierSource) identifierSource ).getIdentifierAttributeSource(); + } + default: { + throw pluralAttribute().getContext().makeMappingException( + "Non-aggregated composite identifiers are not supported for @MapKey" + ); + } + } + } + else { + AttributeSource attributeSource = context.resolveAttributeSource( + pluralAttribute().getElementDetails().getJavaType().getName().toString(), + mapKeyAttributeName + ); + if ( ! attributeSource.isSingular() ) { + throw new MappingException( + String.format( + "Plural attribute index [%s.%s] is not a singular attribute.", + pluralAttribute().getElementDetails().getJavaType().getName().toString(), + mapKeyAttributeName + ), + pluralAttribute().getContext().getOrigin() + ); + } + mapKeyAttributeSource = (SingularAttributeSource) attributeSource; + } + + return this; + } + + @Override + public String getAttributeName() { + return mapKeyAttributeName; + } + + @Override + public PluralAttributeIndexNature getNature() { + if ( mapKeyAttributeSource == null ) { + return null; + } + + switch ( mapKeyAttributeSource.getSingularAttributeNature() ) { + case BASIC: { + return PluralAttributeIndexNature.BASIC; + } + case COMPOSITE: { + return PluralAttributeIndexNature.AGGREGATE; + } + case ANY: { + return PluralAttributeIndexNature.MANY_TO_ANY; + } + case MANY_TO_ONE: { + return PluralAttributeIndexNature.MANY_TO_MANY; + } + default: { + throw pluralAttribute().getContext().makeMappingException( + "Unexpected attribute nature : " + mapKeyAttributeSource.getSingularAttributeNature() + ); + } + } + } + + @Override + public List getDefaultNamingStrategies() { + return null; + } + + @Override + public List relationalValueSources() { + if ( mapKeyAttributeSource == null ) { + return null; + } + return mapKeyAttributeSource.relationalValueSources(); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/PluralAttributeMapSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/PluralAttributeMapSourceImpl.java new file mode 100644 index 0000000000..9c5280edf1 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/PluralAttributeMapSourceImpl.java @@ -0,0 +1,102 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2014, 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.metamodel.source.internal.annotations; + +import org.hibernate.cfg.NamingStrategy; +import org.hibernate.metamodel.internal.binder.Binder; +import org.hibernate.metamodel.source.internal.annotations.attribute.OverrideAndConverterCollector; +import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttribute; +import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttributeIndexDetails; +import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttributeIndexDetailsMapKeyBasic; +import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttributeIndexDetailsMapKeyEmbedded; +import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttributeIndexDetailsMapKeyEntityAttribute; +import org.hibernate.metamodel.source.spi.IndexedPluralAttributeSource; +import org.hibernate.metamodel.source.spi.PluralAttributeIndexSource; + +/** + * @author Steve Ebersole + */ +public class PluralAttributeMapSourceImpl + extends PluralAttributeSourceImpl + implements IndexedPluralAttributeSource { + private final PluralAttributeIndexSource mapKeySource; + + public PluralAttributeMapSourceImpl( + PluralAttribute attribute, + OverrideAndConverterCollector overrideAndConverterCollector) { + super( attribute, overrideAndConverterCollector ); + + this.mapKeySource = determineMapKeySourceInfo( attribute ); + } + + protected PluralAttributeIndexSource determineMapKeySourceInfo(final PluralAttribute attribute) { + final PluralAttributeIndexDetails mapKeyDetails = attribute.getIndexDetails(); + + if ( mapKeyDetails.getIndexNature() == null ) { + return new PluralAttributeMapKeySourceEntityAttributeImpl( + attribute, + ( (PluralAttributeIndexDetailsMapKeyEntityAttribute) mapKeyDetails ).getReferencedAttributeName() + ); + } + + switch ( mapKeyDetails.getIndexNature() ) { + case BASIC: { + return new PluralAttributeMapKeySourceBasicImpl( + attribute, + (PluralAttributeIndexDetailsMapKeyBasic) mapKeyDetails + ); + } + case AGGREGATE: { + return new PluralAttributeMapKeySourceEmbeddedImpl( + attribute, + (PluralAttributeIndexDetailsMapKeyEmbedded) mapKeyDetails + ); + } + default: { + throw attribute.getContext().makeMappingException( + "Support for entities as map keys is not yet implemented" + ); + } + } + } + + @Override + public PluralAttributeIndexSource getIndexSource() { + return mapKeySource; + } + + static class MapKeyColumnDefaultNaming implements Binder.DefaultNamingStrategy { + private final PluralAttribute pluralAttribute; + + MapKeyColumnDefaultNaming(PluralAttribute pluralAttribute) { + this.pluralAttribute = pluralAttribute; + } + + @Override + public String defaultName(NamingStrategy namingStrategy) { + return pluralAttribute.getName() + "_KEY"; + } + } + +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/SequentialPluralAttributeIndexSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/PluralAttributeSequentialIndexSourceImpl.java similarity index 59% rename from hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/SequentialPluralAttributeIndexSourceImpl.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/PluralAttributeSequentialIndexSourceImpl.java index 42ab9f6376..41fb821540 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/SequentialPluralAttributeIndexSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/PluralAttributeSequentialIndexSourceImpl.java @@ -24,26 +24,34 @@ package org.hibernate.metamodel.source.internal.annotations; import java.util.Collections; +import java.util.List; import java.util.Map; +import org.hibernate.cfg.NamingStrategy; import org.hibernate.metamodel.internal.binder.Binder; import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; +import org.hibernate.metamodel.source.internal.annotations.attribute.Column; import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttribute; import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames; import org.hibernate.metamodel.source.spi.HibernateTypeSource; -import org.hibernate.metamodel.source.spi.SequentialPluralAttributeIndexSource; +import org.hibernate.metamodel.source.spi.PluralAttributeSequentialIndexSource; +import org.hibernate.metamodel.source.spi.RelationalValueSource; +import org.hibernate.metamodel.spi.PluralAttributeIndexNature; import org.jboss.jandex.AnnotationInstance; /** * @author Gail Badner */ -public class SequentialPluralAttributeIndexSourceImpl - extends BasicPluralAttributeIndexSourceImpl - implements SequentialPluralAttributeIndexSource { - private final int base; +public class PluralAttributeSequentialIndexSourceImpl + extends AbstractPluralAttributeIndexSourceImpl + implements PluralAttributeSequentialIndexSource { - private final static HibernateTypeSource INTERGER_TYPE = new HibernateTypeSource() { + private final int base; + private final RelationalValueSource relationalValueSource; + private final Binder.DefaultNamingStrategy defaultNamingStrategy; + + private final static HibernateTypeSource INTEGER_TYPE = new HibernateTypeSource() { @Override public String getName() { return "integer"; @@ -59,24 +67,44 @@ public class SequentialPluralAttributeIndexSourceImpl } }; - public SequentialPluralAttributeIndexSourceImpl( - IndexedPluralAttributeSourceImpl indexedPluralAttributeSource, - PluralAttribute attribute, - Binder.DefaultNamingStrategy defaultNamingStrategy) { - super( indexedPluralAttributeSource, attribute, defaultNamingStrategy ); + public PluralAttributeSequentialIndexSourceImpl(final PluralAttribute attribute) { + super( attribute ); final AnnotationInstance columnAnnotation = attribute.getBackingMember().getAnnotations() .get( JPADotNames.ORDER_COLUMN ); this.base = columnAnnotation.value( "base" ) != null ? columnAnnotation.value( "base" ).asInt() : 0; + this.relationalValueSource = new ColumnSourceImpl( new Column( columnAnnotation ) ); + this.defaultNamingStrategy = new Binder.DefaultNamingStrategy() { + @Override + public String defaultName(NamingStrategy namingStrategy) { + return attribute.getName() + "_ORDER"; + } + }; } @Override public int base() { return base; } + + @Override + public PluralAttributeIndexNature getNature() { + return PluralAttributeIndexNature.SEQUENTIAL; + } + + @Override + public List getDefaultNamingStrategies() { + return Collections.singletonList( defaultNamingStrategy ); + } + @Override public HibernateTypeSource getTypeInformation() { - return INTERGER_TYPE; + return INTEGER_TYPE; + } + + @Override + public List relationalValueSources() { + return Collections.singletonList( relationalValueSource ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/PluralAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/PluralAttributeSourceImpl.java index d471f08cc6..6ee85c21e1 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/PluralAttributeSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/PluralAttributeSourceImpl.java @@ -27,6 +27,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.Set; import org.hibernate.AssertionFailure; @@ -37,14 +38,20 @@ import org.hibernate.engine.spi.CascadeStyles; import org.hibernate.internal.util.StringHelper; import org.hibernate.metamodel.reflite.spi.ArrayDescriptor; import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; +import org.hibernate.metamodel.source.internal.annotations.attribute.CollectionIdInformation; +import org.hibernate.metamodel.source.internal.annotations.attribute.Column; import org.hibernate.metamodel.source.internal.annotations.attribute.OverrideAndConverterCollector; import org.hibernate.metamodel.source.internal.annotations.attribute.PersistentAttribute; import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttribute; +import org.hibernate.metamodel.source.internal.annotations.attribute.type.AttributeTypeResolver; +import org.hibernate.metamodel.source.internal.annotations.entity.EntityBindingContext; import org.hibernate.metamodel.source.internal.annotations.util.EnumConversionHelper; import org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames; import org.hibernate.metamodel.source.spi.AssociationSource; import org.hibernate.metamodel.source.spi.AttributeSource; import org.hibernate.metamodel.source.spi.AttributeSourceResolutionContext; +import org.hibernate.metamodel.source.spi.CollectionIdSource; +import org.hibernate.metamodel.source.spi.ColumnSource; import org.hibernate.metamodel.source.spi.FilterSource; import org.hibernate.metamodel.source.spi.HibernateTypeSource; import org.hibernate.metamodel.source.spi.MappedByAssociationSource; @@ -56,6 +63,10 @@ import org.hibernate.metamodel.source.spi.Sortable; import org.hibernate.metamodel.source.spi.TableSpecificationSource; import org.hibernate.metamodel.source.spi.ToOneAttributeSource; import org.hibernate.metamodel.source.spi.ToolingHintSource; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; +import org.hibernate.metamodel.spi.PluralAttributeElementNature; +import org.hibernate.metamodel.spi.PluralAttributeNature; import org.hibernate.metamodel.spi.binding.Caching; import org.hibernate.metamodel.spi.binding.CustomSQL; @@ -67,7 +78,7 @@ import org.jboss.jandex.AnnotationInstance; public class PluralAttributeSourceImpl implements AnnotationAttributeSource, PluralAttributeSource, Orderable, Sortable { private final PluralAttribute pluralAttribute; - private final Nature nature; + private final PluralAttributeNature nature; private final Set unifiedCascadeStyles; @@ -75,6 +86,8 @@ public class PluralAttributeSourceImpl private final PluralAttributeKeySource keySource; private final FilterSource[] filterSources; + private final CollectionIdSource collectionIdSource; + // If it is not the owner side (i.e., mappedBy != null), then the AttributeSource // for the owner is required to determine elementSource. private PluralAttributeElementSource elementSource; @@ -97,6 +110,16 @@ public class PluralAttributeSourceImpl this.elementSource = determineElementSource( this, this ); } this.filterSources = determineFilterSources( pluralAttribute ); + + if ( pluralAttribute.getCollectionIdInformation() == null ) { + this.collectionIdSource = null; + } + else { + collectionIdSource = new CollectionIdSourceImpl( + pluralAttribute.getCollectionIdInformation(), + pluralAttribute.getContext() + ); + } } private static Set determineCascadeStyles(PluralAttribute pluralAttribute) { @@ -140,6 +163,21 @@ public class PluralAttributeSourceImpl } } + @Override + public AttributePath getAttributePath() { + return pluralAttribute.getPath(); + } + + @Override + public AttributeRole getAttributeRole() { + return pluralAttribute.getRole(); + } + + @Override + public CollectionIdSource getCollectionIdSource() { + return collectionIdSource; + } + @Override public PersistentAttribute getAnnotatedAttribute() { return getPluralAttribute(); @@ -154,7 +192,7 @@ public class PluralAttributeSourceImpl } @Override - public Nature getNature() { + public PluralAttributeNature getNature() { return nature; } @@ -210,17 +248,17 @@ public class PluralAttributeSourceImpl final PluralAttribute associationAttribute = pluralAttributeSource.pluralAssociationAttribute(); switch ( pluralAttributeSource.pluralAssociationAttribute().getNature() ) { case ELEMENT_COLLECTION_BASIC: { - return new BasicPluralAttributeElementSourceImpl( pluralAttributeSource ); + return new PluralAttributeElementSourceBasicImpl( pluralAttributeSource ); } case ELEMENT_COLLECTION_EMBEDDABLE: { - return new CompositePluralAttributeElementSourceImpl( pluralAttributeSource ); + return new PluralAttributeElementSourceEmbeddedImpl( pluralAttributeSource ); } case MANY_TO_MANY: { if ( associationAttribute.getMappedByAttributeName() == null ) { - return new ManyToManyPluralAttributeElementSourceImpl( pluralAttributeSource ); + return new PluralAttributeElementSourceAssociationManyToManyImpl( pluralAttributeSource ); } else { - return new ManyToManyMappedByPluralAttributeElementSourceImpl( pluralAttributeSource ); + return new MappedByPluralAttributeElementSourceAssociationManyToManyImpl( pluralAttributeSource ); } } case ONE_TO_MANY: { @@ -230,23 +268,23 @@ public class PluralAttributeSourceImpl if ( usesJoinTable ) { if ( associationAttribute.getMappedByAttributeName() == null ) { - return new ManyToManyPluralAttributeElementSourceImpl( pluralAttributeSource ); + return new PluralAttributeElementSourceAssociationManyToManyImpl( pluralAttributeSource ); } else { - return new ManyToManyMappedByPluralAttributeElementSourceImpl( pluralAttributeSource ); + return new MappedByPluralAttributeElementSourceAssociationManyToManyImpl( pluralAttributeSource ); } } else { if ( associationAttribute.getMappedByAttributeName() == null ) { - return new OneToManyPluralAttributeElementSourceImpl( pluralAttributeSource ); + return new PluralAttributeElementSourceAssociationOneToManyImpl( pluralAttributeSource ); } else { - return new OneToManyMappedByPluralAttributeElementSourceImpl( pluralAttributeSource ); + return new MappedByPluralAttributeElementSourceAssociationOneToManyImpl( pluralAttributeSource ); } } } case MANY_TO_ANY: { - return new ManyToAnyPluralAttributeElementSourceImpl( pluralAttributeSource ); + return new PluralAttributeElementSourceAssociationManyToAnyImpl( pluralAttributeSource ); } default: { throw new AssertionError( "Unexpected plural attribute nature :" + associationAttribute.getNature() ); @@ -375,7 +413,7 @@ public class PluralAttributeSourceImpl @Override public String getOrder() { - return elementSource.getNature() == PluralAttributeElementSource.Nature.MANY_TO_MANY ? + return elementSource.getNature() == PluralAttributeElementNature.MANY_TO_MANY ? null : pluralAttribute.getOrderBy(); } @@ -457,6 +495,96 @@ public class PluralAttributeSourceImpl protected PluralAttribute pluralAssociationAttribute() { return pluralAttribute; } + + + private static class CollectionIdSourceImpl implements CollectionIdSource { + private final ColumnSourceImpl columnSource; + private final HibernateTypeSource typeSource; + private final String generatorName; + + public CollectionIdSourceImpl(CollectionIdInformation collectionIdInformation, EntityBindingContext context) { + this.columnSource = interpretColumns( collectionIdInformation.getColumns(), context ); + this.typeSource = createTypeSource( collectionIdInformation.getTypeResolver() ); + this.generatorName = collectionIdInformation.getGeneratorDefinition().getName(); + } + + private static ColumnSourceImpl interpretColumns(List columns, EntityBindingContext context) { + if ( columns == null || columns.isEmpty() ) { + return null; + } + + if ( columns.size() > 1 ) { + throw context.makeMappingException( "Expecting just one column for collection id" ); + } + + return new ColumnSourceImpl( columns.get( 0 ) ); + } + + private HibernateTypeSource createTypeSource(AttributeTypeResolver typeResolver) { + if ( typeResolver == null ) { + return EmptyHibernateTypeSource.INSTANCE; + } + + final String resolvedTypeName = typeResolver.getExplicitHibernateTypeName(); + if ( StringHelper.isEmpty( resolvedTypeName ) ) { + return EmptyHibernateTypeSource.INSTANCE; + } + + return new HibernateTypeSource() { + @Override + public String getName() { + return resolvedTypeName; + } + + @Override + public Map getParameters() { + return Collections.emptyMap(); + } + + @Override + public JavaTypeDescriptor getJavaType() { + return null; + } + }; + } + + @Override + public ColumnSource getColumnSource() { + return null; + } + + @Override + public HibernateTypeSource getTypeInformation() { + return null; + } + + @Override + public String getGeneratorName() { + return null; + } + } + + private static class EmptyHibernateTypeSource implements HibernateTypeSource { + /** + * Singleton access + */ + public static final EmptyHibernateTypeSource INSTANCE = new EmptyHibernateTypeSource(); + + @Override + public String getName() { + return null; + } + + @Override + public Map getParameters() { + return null; + } + + @Override + public JavaTypeDescriptor getJavaType() { + return null; + } + } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/SingularAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/SingularAttributeSourceImpl.java index 54593fb9c4..8150e86dea 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/SingularAttributeSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/SingularAttributeSourceImpl.java @@ -32,8 +32,7 @@ import org.hibernate.metamodel.source.internal.annotations.attribute.SingularAtt import org.hibernate.metamodel.source.spi.HibernateTypeSource; import org.hibernate.metamodel.source.spi.SingularAttributeSource; import org.hibernate.metamodel.source.spi.ToolingHintSource; - -import static org.hibernate.metamodel.spi.binding.SingularAttributeBinding.NaturalIdMutability; +import org.hibernate.metamodel.spi.NaturalIdMutability; /** * @author Hardy Ferentschik diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/SourceHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/SourceHelper.java index df20372ddf..67c936af57 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/SourceHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/SourceHelper.java @@ -43,7 +43,7 @@ import org.hibernate.metamodel.source.internal.annotations.entity.ManagedTypeMet import org.hibernate.metamodel.source.internal.annotations.entity.MappedSuperclassTypeMetadata; import org.hibernate.metamodel.source.internal.annotations.entity.RootEntityTypeMetadata; import org.hibernate.metamodel.source.spi.AttributeSource; -import org.hibernate.metamodel.source.spi.ComponentAttributeSource; +import org.hibernate.metamodel.source.spi.EmbeddedAttributeSource; import org.hibernate.metamodel.source.spi.PluralAttributeSource; import org.hibernate.metamodel.source.spi.SingularAttributeSource; import org.hibernate.metamodel.source.spi.ToOneAttributeSource; @@ -57,7 +57,7 @@ import org.hibernate.metamodel.source.spi.ToOneAttributeSource; public class SourceHelper { private static final CoreMessageLogger LOG = CoreLogging.messageLogger( SourceHelper.class ); - // todo : the walking supers bits here is do to the total lack of understanding of MappedSuperclasses in Binder... + // todo : the walking supers bits here is due to the total lack of understanding of MappedSuperclasses in Binder... public static List buildAttributeSources( ManagedTypeMetadata managedTypeMetadata, @@ -241,7 +241,7 @@ public class SourceHelper { BasicAttribute attribute, OverrideAndConverterCollector overrideAndConverterCollector); - public ComponentAttributeSource buildEmbeddedAttribute( + public EmbeddedAttributeSource buildEmbeddedAttribute( EmbeddedAttribute attribute, OverrideAndConverterCollector overrideAndConverterCollector); @@ -277,7 +277,7 @@ public class SourceHelper { } @Override - public ComponentAttributeSource buildEmbeddedAttribute( + public EmbeddedAttributeSource buildEmbeddedAttribute( EmbeddedAttribute attribute, OverrideAndConverterCollector overrideAndConverterCollector) { return new EmbeddedAttributeSourceImpl( attribute, false, false ); @@ -304,10 +304,15 @@ public class SourceHelper { case SET: { return new PluralAttributeSourceImpl( attribute, overrideAndConverterCollector ); } + case ID_BAG: { + return new PluralAttributeIdBagSourceImpl( attribute, overrideAndConverterCollector ); + } + case MAP: { + return new PluralAttributeMapSourceImpl( attribute, overrideAndConverterCollector ); + } case ARRAY: - case MAP: case LIST: { - return new IndexedPluralAttributeSourceImpl( attribute, overrideAndConverterCollector ); + return new PluralAttributeIndexedSourceImpl( attribute, overrideAndConverterCollector ); } default: { throw new AssertionFailure( @@ -343,7 +348,7 @@ public class SourceHelper { public static final PluralAttributesDisallowedAttributeBuilder INSTANCE = new PluralAttributesDisallowedAttributeBuilder(); @Override - public ComponentAttributeSource buildEmbeddedAttribute( + public EmbeddedAttributeSource buildEmbeddedAttribute( EmbeddedAttribute attribute, OverrideAndConverterCollector overrideAndConverterCollector) { return new EmbeddedAttributeSourceImpl( attribute, false, true ); @@ -402,7 +407,7 @@ public class SourceHelper { } @Override - public ComponentAttributeSource buildEmbeddedAttribute( + public EmbeddedAttributeSource buildEmbeddedAttribute( EmbeddedAttribute attribute, OverrideAndConverterCollector overrideAndConverterCollector) { return new EmbeddedAttributeSourceImpl( attribute, true, false ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/ToOneAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/ToOneAttributeSourceImpl.java index bef835d353..b252ed9201 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/ToOneAttributeSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/ToOneAttributeSourceImpl.java @@ -46,10 +46,14 @@ import org.hibernate.metamodel.source.spi.AttributeSourceResolutionContext; import org.hibernate.metamodel.source.spi.ForeignKeyContributingSource; import org.hibernate.metamodel.source.spi.RelationalValueSource; import org.hibernate.metamodel.source.spi.ToOneAttributeSource; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; +import org.hibernate.metamodel.spi.SingularAttributeNature; import org.hibernate.metamodel.spi.binding.AttributeBinding; -import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding; +import org.hibernate.metamodel.spi.binding.EmbeddedAttributeBinding; import org.hibernate.metamodel.spi.relational.TableSpecification; import org.hibernate.metamodel.spi.relational.Value; + import org.jboss.jandex.AnnotationInstance; /** @@ -83,30 +87,30 @@ public class ToOneAttributeSourceImpl extends AbstractToOneAttributeSourceImpl i // Need to initialize logicalJoinTableName before determining nature. this.containingTableName = resolveContainingTableName( associationAttribute, relationalValueSources ); - setNature( determineNatureIfPossible( associationAttribute ) ); + setSingularAttributeNature( determineNatureIfPossible( associationAttribute ) ); this.foreignKeyDelegate = new ForeignKeyDelegate( associationAttribute().getBackingMember().getAnnotations(), cls); } - private Nature determineNatureIfPossible( + private SingularAttributeNature determineNatureIfPossible( SingularAssociationAttribute associationAttribute) { if ( AbstractPersistentAttribute.Nature.MANY_TO_ONE.equals( associationAttribute.getNature() ) ) { - return Nature.MANY_TO_ONE; + return SingularAttributeNature.MANY_TO_ONE; } else if ( AbstractPersistentAttribute.Nature.ONE_TO_ONE.equals( associationAttribute.getNature() ) ) { if ( getContainingTableName() != null ) { - return Nature.MANY_TO_ONE; + return SingularAttributeNature.MANY_TO_ONE; } else if ( associationAttribute.hasPrimaryKeyJoinColumn() ) { - return Nature.ONE_TO_ONE; + return SingularAttributeNature.ONE_TO_ONE; } else if ( associationAttribute.isId() ) { // if this association is part of the ID then this can't be a one-to-one - return Nature.MANY_TO_ONE; + return SingularAttributeNature.MANY_TO_ONE; } else if ( associationAttribute.getJoinColumnValues() == null || associationAttribute.getJoinColumnValues().isEmpty() ) { - return Nature.MANY_TO_ONE; + return SingularAttributeNature.MANY_TO_ONE; } else { return null; @@ -120,7 +124,7 @@ public class ToOneAttributeSourceImpl extends AbstractToOneAttributeSourceImpl i @Override public void resolveToOneAttributeSource(AttributeSourceResolutionContext context) { - if ( getNature() != null ) { + if ( getSingularAttributeNature() != null ) { return; } // It would be nice to have the following block in determineNatureIfPossible(), @@ -128,7 +132,7 @@ public class ToOneAttributeSourceImpl extends AbstractToOneAttributeSourceImpl i if ( AbstractPersistentAttribute.Nature.ONE_TO_ONE.equals( associationAttribute().getNature() ) ) { final List idColumns = context.resolveIdentifierColumns(); if ( associationAttribute().getJoinColumnValues().size() != idColumns.size() ) { - setNature( Nature.MANY_TO_ONE ); + setSingularAttributeNature( SingularAttributeNature.MANY_TO_ONE ); } else { Set joinColumnNames = new HashSet( associationAttribute().getJoinColumnValues().size() ); @@ -143,23 +147,29 @@ public class ToOneAttributeSourceImpl extends AbstractToOneAttributeSourceImpl i break; } } - setNature( areJoinColumnsSameAsIdColumns ? Nature.ONE_TO_ONE : Nature.MANY_TO_ONE ); + setSingularAttributeNature( + areJoinColumnsSameAsIdColumns ? + SingularAttributeNature.ONE_TO_ONE : + SingularAttributeNature.MANY_TO_ONE + ); } } - if ( getNature() == null ) { + if ( getSingularAttributeNature() == null ) { throw new NotYetImplementedException( "unknown type of to-one attribute." ); } } @Override public List getDefaultNamingStrategies( - final String entityName, final String tableName, final AttributeBinding referencedAttributeBinding) { - if ( CompositeAttributeBinding.class.isInstance( referencedAttributeBinding ) ) { - CompositeAttributeBinding compositeAttributeBinding = CompositeAttributeBinding.class.cast( + final String entityName, + final String tableName, + final AttributeBinding referencedAttributeBinding) { + if ( EmbeddedAttributeBinding.class.isInstance( referencedAttributeBinding ) ) { + EmbeddedAttributeBinding embeddedAttributeBinding = EmbeddedAttributeBinding.class.cast( referencedAttributeBinding ); List result = new ArrayList( ); - for ( final AttributeBinding attributeBinding : compositeAttributeBinding.attributeBindings() ) { + for ( final AttributeBinding attributeBinding : embeddedAttributeBinding.getEmbeddableBinding().attributeBindings() ) { result.addAll( getDefaultNamingStrategies( entityName, tableName, attributeBinding ) ); } return result; @@ -281,6 +291,16 @@ public class ToOneAttributeSourceImpl extends AbstractToOneAttributeSourceImpl i return false; } + @Override + public AttributePath getAttributePath() { + return getAnnotatedAttribute().getPath(); + } + + @Override + public AttributeRole getAttributeRole() { + return getAnnotatedAttribute().getRole(); + } + public class AnnotationJoinColumnResolutionDelegate implements ForeignKeyContributingSource.JoinColumnResolutionDelegate { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/ToOneMappedByAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/ToOneMappedByAttributeSourceImpl.java index 473c5d17f8..e0d07dc324 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/ToOneMappedByAttributeSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/ToOneMappedByAttributeSourceImpl.java @@ -34,6 +34,7 @@ import org.hibernate.metamodel.source.spi.AttributeSourceResolutionContext; import org.hibernate.metamodel.source.spi.MappedByAssociationSource; import org.hibernate.metamodel.source.spi.RelationalValueSource; import org.hibernate.metamodel.source.spi.ToOneAttributeSource; +import org.hibernate.metamodel.spi.SingularAttributeNature; import org.hibernate.metamodel.spi.binding.AttributeBinding; /** @@ -62,7 +63,7 @@ public class ToOneMappedByAttributeSourceImpl @Override public void resolveToOneAttributeSource(AttributeSourceResolutionContext context) { - if ( getNature() != null && owner != null) { + if ( getSingularAttributeNature() != null && owner != null) { return; } if ( owner == null ) { @@ -72,17 +73,17 @@ public class ToOneMappedByAttributeSourceImpl ); owner.addMappedByAssociationSource( this ); } - if ( getNature() == null ) { - final Nature nature; + if ( getSingularAttributeNature() == null ) { + final SingularAttributeNature singularAttributeNature; if ( AbstractPersistentAttribute.Nature.MANY_TO_ONE.equals( associationAttribute().getNature() ) ) { - nature = Nature.MANY_TO_ONE; + singularAttributeNature = SingularAttributeNature.MANY_TO_ONE; } else if ( AbstractPersistentAttribute.Nature.ONE_TO_ONE.equals( associationAttribute().getNature() ) ) { if ( owner.getContainingTableName() != null ) { - nature = Nature.MANY_TO_ONE; + singularAttributeNature = SingularAttributeNature.MANY_TO_ONE; } else { - nature = Nature.ONE_TO_ONE; + singularAttributeNature = SingularAttributeNature.ONE_TO_ONE; } } else { @@ -91,7 +92,7 @@ public class ToOneMappedByAttributeSourceImpl associationAttribute().getNature(), associationAttribute().getRole() )); } - setNature( nature ); + setSingularAttributeNature( singularAttributeNature ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/VersionAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/VersionAttributeSourceImpl.java index 869ef94192..27f5e8ac37 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/VersionAttributeSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/VersionAttributeSourceImpl.java @@ -26,8 +26,7 @@ package org.hibernate.metamodel.source.internal.annotations; import org.hibernate.metamodel.source.internal.annotations.attribute.BasicAttribute; import org.hibernate.metamodel.source.internal.annotations.attribute.OverrideAndConverterCollector; import org.hibernate.metamodel.source.spi.VersionAttributeSource; - -import static org.hibernate.metamodel.spi.binding.SingularAttributeBinding.NaturalIdMutability; +import org.hibernate.metamodel.spi.NaturalIdMutability; /** * @author Steve Ebersole diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/AbstractPersistentAttribute.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/AbstractPersistentAttribute.java index 1f58c1556f..dd2b366276 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/AbstractPersistentAttribute.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/AbstractPersistentAttribute.java @@ -38,14 +38,13 @@ import org.hibernate.metamodel.source.internal.annotations.util.AnnotationParser import org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames; import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames; import org.hibernate.metamodel.source.internal.annotations.util.JandexHelper; -import org.hibernate.metamodel.source.spi.AttributePath; -import org.hibernate.metamodel.source.spi.AttributeRole; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; +import org.hibernate.metamodel.spi.NaturalIdMutability; import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationValue; -import static org.hibernate.metamodel.spi.binding.SingularAttributeBinding.NaturalIdMutability; - /** * Base class for the different types of persistent attributes * diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/AbstractPluralAttributeIndexDetailsMapKey.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/AbstractPluralAttributeIndexDetailsMapKey.java new file mode 100644 index 0000000000..05fca5c5bb --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/AbstractPluralAttributeIndexDetailsMapKey.java @@ -0,0 +1,70 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2014, 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.metamodel.source.internal.annotations.attribute; + +import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; +import org.hibernate.metamodel.reflite.spi.MemberDescriptor; +import org.hibernate.metamodel.source.internal.annotations.attribute.type.AttributeTypeResolver; +import org.hibernate.metamodel.source.internal.annotations.attribute.type.AttributeTypeResolverComposition; +import org.hibernate.metamodel.source.internal.annotations.attribute.type.EnumeratedTypeResolver; +import org.hibernate.metamodel.source.internal.annotations.attribute.type.HibernateTypeResolver; +import org.hibernate.metamodel.source.internal.annotations.attribute.type.TemporalTypeResolver; + + +/** + * PluralAttributeIndexDetails implementation for describing the key of a Map + * + * @author Steve Ebersole + */ +public abstract class AbstractPluralAttributeIndexDetailsMapKey implements PluralAttributeIndexDetails { + private final PluralAttribute pluralAttribute; + private final JavaTypeDescriptor resolvedMapKeyType; + private final AttributeTypeResolver typeResolver; + + public AbstractPluralAttributeIndexDetailsMapKey( + PluralAttribute pluralAttribute, + MemberDescriptor backingMember, + JavaTypeDescriptor resolvedMapKeyType) { + this.pluralAttribute = pluralAttribute; + this.resolvedMapKeyType = resolvedMapKeyType; + + this.typeResolver = new AttributeTypeResolverComposition( + resolvedMapKeyType, + pluralAttribute.getContext(), + HibernateTypeResolver.createCollectionIndexTypeResolver( pluralAttribute, resolvedMapKeyType ), + EnumeratedTypeResolver.createCollectionIndexTypeResolver( pluralAttribute, resolvedMapKeyType ), + TemporalTypeResolver.createCollectionIndexTypeResolver( pluralAttribute, resolvedMapKeyType ) + ); + } + + @Override + public JavaTypeDescriptor getJavaType() { + return resolvedMapKeyType; + } + + @Override + public AttributeTypeResolver getTypeResolver() { + return typeResolver; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/AbstractSingularAttribute.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/AbstractSingularAttribute.java index 6d5a37acf1..900711574e 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/AbstractSingularAttribute.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/AbstractSingularAttribute.java @@ -32,9 +32,10 @@ import org.hibernate.metamodel.source.internal.annotations.entity.ManagedTypeMet import org.hibernate.metamodel.source.internal.annotations.util.ConverterAndOverridesHelper; import org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames; import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames; -import org.hibernate.metamodel.source.spi.AttributePath; -import org.hibernate.metamodel.source.spi.AttributeRole; -import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; +import org.hibernate.metamodel.spi.NaturalIdMutability; + import org.jboss.logging.Logger; /** @@ -176,7 +177,7 @@ public abstract class AbstractSingularAttribute } @Override - public SingularAttributeBinding.NaturalIdMutability getNaturalIdMutability() { + public NaturalIdMutability getNaturalIdMutability() { return super.getNaturalIdMutability(); } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/BasicAttribute.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/BasicAttribute.java index 69dec2229a..5e7d786e29 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/BasicAttribute.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/BasicAttribute.java @@ -48,10 +48,10 @@ import org.hibernate.metamodel.source.internal.annotations.util.EnumConversionHe import org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames; import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames; import org.hibernate.metamodel.source.internal.annotations.util.JandexHelper; -import org.hibernate.metamodel.source.spi.AttributePath; -import org.hibernate.metamodel.source.spi.AttributeRole; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; +import org.hibernate.metamodel.spi.NaturalIdMutability; import org.hibernate.metamodel.spi.binding.IdentifierGeneratorDefinition; -import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationValue; @@ -164,7 +164,7 @@ public class BasicAttribute extends AbstractSingularAttribute { this.propertyGeneration = propertyGeneration; } - if ( getNaturalIdMutability() == SingularAttributeBinding.NaturalIdMutability.IMMUTABLE ) { + if ( getNaturalIdMutability() == NaturalIdMutability.IMMUTABLE ) { this.updateability.disable(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/EmbeddedAttribute.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/EmbeddedAttribute.java index a8067189d4..e025e5e463 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/EmbeddedAttribute.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/EmbeddedAttribute.java @@ -34,9 +34,9 @@ import org.hibernate.metamodel.source.internal.annotations.attribute.type.Hibern import org.hibernate.metamodel.source.internal.annotations.entity.EmbeddableTypeMetadata; import org.hibernate.metamodel.source.internal.annotations.entity.ManagedTypeMetadata; import org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames; -import org.hibernate.metamodel.source.spi.AttributePath; -import org.hibernate.metamodel.source.spi.AttributeRole; -import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; +import org.hibernate.metamodel.spi.NaturalIdMutability; import org.jboss.jandex.AnnotationInstance; @@ -101,7 +101,7 @@ public class EmbeddedAttribute extends AbstractSingularAttribute implements Embe updateability.disable(); } - if ( getNaturalIdMutability() == SingularAttributeBinding.NaturalIdMutability.IMMUTABLE ) { + if ( getNaturalIdMutability() == NaturalIdMutability.IMMUTABLE ) { updateability.disable(); } } @@ -144,7 +144,7 @@ public class EmbeddedAttribute extends AbstractSingularAttribute implements Embe } @Override - public SingularAttributeBinding.NaturalIdMutability getContainerNaturalIdMutability() { + public NaturalIdMutability getContainerNaturalIdMutability() { return super.getNaturalIdMutability(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/EmbeddedContainer.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/EmbeddedContainer.java index 1e42372925..cc35a50f0a 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/EmbeddedContainer.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/EmbeddedContainer.java @@ -25,8 +25,8 @@ package org.hibernate.metamodel.source.internal.annotations.attribute; import org.hibernate.metamodel.reflite.spi.MemberDescriptor; import org.hibernate.metamodel.source.internal.AttributeConversionInfo; -import org.hibernate.metamodel.source.spi.AttributePath; -import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.NaturalIdMutability; /** * Defines the container of an embedded value. Acts as the container for @@ -43,7 +43,7 @@ public interface EmbeddedContainer extends OverrideAndConverterCollector { public AssociationOverride locateAssociationOverride(AttributePath attributePath); - public SingularAttributeBinding.NaturalIdMutability getContainerNaturalIdMutability(); + public NaturalIdMutability getContainerNaturalIdMutability(); boolean getContainerOptionality(); boolean getContainerUpdatability(); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/OverrideAndConverterCollector.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/OverrideAndConverterCollector.java index 0762881c71..2dccad7915 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/OverrideAndConverterCollector.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/OverrideAndConverterCollector.java @@ -24,7 +24,7 @@ package org.hibernate.metamodel.source.internal.annotations.attribute; import org.hibernate.metamodel.source.internal.AttributeConversionInfo; -import org.hibernate.metamodel.source.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributePath; /** * Contract used in normalizing AttributeConverters, AttributeOverrides and diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PersistentAttribute.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PersistentAttribute.java index 30b9569f88..90aa7b70b4 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PersistentAttribute.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PersistentAttribute.java @@ -32,8 +32,8 @@ import org.hibernate.metamodel.source.internal.annotations.entity.EntityBindingC import org.hibernate.metamodel.source.internal.annotations.entity.ManagedTypeMetadata; import org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames; import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames; -import org.hibernate.metamodel.source.spi.AttributePath; -import org.hibernate.metamodel.source.spi.AttributeRole; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; import org.jboss.jandex.DotName; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PluralAttribute.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PluralAttribute.java index e6b8d70b4f..ecbce5105f 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PluralAttribute.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PluralAttribute.java @@ -24,6 +24,7 @@ package org.hibernate.metamodel.source.internal.annotations.attribute; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.EnumSet; import java.util.List; @@ -31,7 +32,6 @@ import java.util.Map; import java.util.Set; import java.util.SortedMap; import java.util.SortedSet; - import javax.persistence.AccessType; import javax.persistence.CascadeType; @@ -59,17 +59,32 @@ import org.hibernate.metamodel.source.internal.annotations.util.ConverterAndOver import org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames; import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames; import org.hibernate.metamodel.source.internal.annotations.util.JandexHelper; -import org.hibernate.metamodel.source.spi.AttributePath; -import org.hibernate.metamodel.source.spi.AttributeRole; import org.hibernate.metamodel.source.spi.MappingException; -import org.hibernate.metamodel.source.spi.PluralAttributeSource; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; +import org.hibernate.metamodel.spi.PluralAttributeNature; import org.hibernate.metamodel.spi.binding.Caching; import org.hibernate.metamodel.spi.binding.CustomSQL; import org.hibernate.metamodel.spi.binding.IdentifierGeneratorDefinition; + import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationValue; import org.jboss.jandex.DotName; +import static org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames.LOADER; +import static org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames.ON_DELETE; +import static org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames.PERSISTER; +import static org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames.WHERE; +import static org.hibernate.metamodel.source.internal.annotations.util.JPADotNames.EMBEDDABLE; +import static org.hibernate.metamodel.source.internal.annotations.util.JPADotNames.ENTITY; +import static org.hibernate.metamodel.source.internal.annotations.util.JPADotNames.MAP_KEY; +import static org.hibernate.metamodel.source.internal.annotations.util.JPADotNames.MAP_KEY_CLASS; +import static org.hibernate.metamodel.source.internal.annotations.util.JPADotNames.MAP_KEY_COLUMN; +import static org.hibernate.metamodel.source.internal.annotations.util.JPADotNames.MAP_KEY_ENUMERATED; +import static org.hibernate.metamodel.source.internal.annotations.util.JPADotNames.MAP_KEY_TEMPORAL; +import static org.hibernate.metamodel.source.internal.annotations.util.JPADotNames.ORDER_BY; +import static org.hibernate.metamodel.source.internal.annotations.util.JPADotNames.ORDER_COLUMN; + /** * Represents a plural persistent attribute. * @@ -80,11 +95,11 @@ import org.jboss.jandex.DotName; public class PluralAttribute extends AbstractPersistentAttribute implements FetchableAttribute, AssociationAttribute { - private static final EnumSet CANNOT_HAVE_COLLECTION_ID = EnumSet.of( - PluralAttributeSource.Nature.SET, - PluralAttributeSource.Nature.MAP, - PluralAttributeSource.Nature.LIST, - PluralAttributeSource.Nature.ARRAY + private static final EnumSet CANNOT_HAVE_COLLECTION_ID = EnumSet.of( + PluralAttributeNature.SET, + PluralAttributeNature.MAP, + PluralAttributeNature.LIST, + PluralAttributeNature.ARRAY ); private final String mappedByAttributeName; @@ -100,7 +115,7 @@ public class PluralAttribute // information about the collection private final CollectionIdInformation collectionIdInformation; - private final PluralAttributeSource.Nature pluralAttributeNature; + private final PluralAttributeNature pluralAttributeNature; private final String customPersister; private final Caching caching; private final String comparatorName; @@ -357,7 +372,7 @@ public class PluralAttribute } - private PluralAttributeSource.Nature resolvePluralAttributeNature( + private PluralAttributeNature resolvePluralAttributeNature( MemberDescriptor backingMember, CollectionIdInformation collectionIdInformation) { //TODO org.hibernate.cfg.annotations.CollectionBinder#hasToBeSorted @@ -365,21 +380,21 @@ public class PluralAttribute final JavaTypeDescriptor pluralType = backingMember.getType().getErasedType(); if ( ArrayDescriptor.class.isInstance( pluralType ) ) { - return PluralAttributeSource.Nature.ARRAY; + return PluralAttributeNature.ARRAY; } if ( getContext().getJavaTypeDescriptorRepository().jdkMapDescriptor().isAssignableFrom( pluralType ) ) { - return PluralAttributeSource.Nature.MAP; + return PluralAttributeNature.MAP; } if ( getContext().getJavaTypeDescriptorRepository().jdkSetDescriptor().isAssignableFrom( pluralType ) ) { - return PluralAttributeSource.Nature.SET; + return PluralAttributeNature.SET; } if ( getContext().getJavaTypeDescriptorRepository().jdkListDescriptor().isAssignableFrom( pluralType ) ) { // we have a LIST nature as long as there is an @OrderColumn annotation - if ( backingMember.getAnnotations().containsKey( JPADotNames.ORDER_COLUMN ) ) { - return PluralAttributeSource.Nature.LIST; + if ( backingMember.getAnnotations().containsKey( ORDER_COLUMN ) ) { + return PluralAttributeNature.LIST; } } @@ -395,8 +410,8 @@ public class PluralAttribute // todo : does ID_BAG really need a separate nature? return collectionIdInformation != null - ? PluralAttributeSource.Nature.ID_BAG - : PluralAttributeSource.Nature.BAG; + ? PluralAttributeNature.ID_BAG + : PluralAttributeNature.BAG; } private PluralAttributeElementDetails resolveElementDetails( @@ -427,28 +442,129 @@ public class PluralAttribute private PluralAttributeIndexDetails resolveIndexDetails( MemberDescriptor backingMember, - PluralAttributeSource.Nature pluralAttributeNature, + PluralAttributeNature pluralAttributeNature, JavaTypeDescriptor indexType) { // could be an array/list - if ( pluralAttributeNature == PluralAttributeSource.Nature.ARRAY - || pluralAttributeNature == PluralAttributeSource.Nature.LIST ) { - return new PluralAttributeSequentialIndexDetails( this, backingMember ); + if ( pluralAttributeNature == PluralAttributeNature.ARRAY + || pluralAttributeNature == PluralAttributeNature.LIST ) { + return new PluralAttributeIndexDetailsSequential( this, backingMember ); } // or a map - if ( pluralAttributeNature != PluralAttributeSource.Nature.MAP ) { + if ( pluralAttributeNature != PluralAttributeNature.MAP ) { return null; } - return new PluralAttributeMapKeyDetails( this, backingMember, indexType ); + final AnnotationInstance mapKeyAnnotation = backingMember.getAnnotations().get( MAP_KEY ); + final AnnotationInstance mapKeyClassAnnotation = backingMember.getAnnotations().get( MAP_KEY_CLASS ); + final AnnotationInstance mapKeyColumnAnnotation = backingMember.getAnnotations().get( MAP_KEY_COLUMN ); + final AnnotationInstance mapKeyEnumeratedAnnotation = backingMember.getAnnotations().get( MAP_KEY_ENUMERATED ); + final AnnotationInstance mapKeyTemporalAnnotation = backingMember.getAnnotations().get( MAP_KEY_TEMPORAL ); + + final List mapKeyJoinColumnAnnotations = collectMapKeyJoinColumnAnnotations( backingMember ); + + if ( mapKeyAnnotation != null && mapKeyClassAnnotation != null ) { + // this is an error according to the spec... + throw getContext().makeMappingException( + "Map attribute defined both @MapKey and @MapKeyClass; only one should be used : " + + backingMember.toLoggableForm() + ); + } + + + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // Level 1 : @MapKey + + if ( mapKeyAnnotation != null ) { + final AnnotationValue value = mapKeyAnnotation.value( "name" ); + String mapKeyAttributeName = null; + if ( value != null ) { + mapKeyAttributeName = StringHelper.nullIfEmpty( value.asString() ); + } + return new PluralAttributeIndexDetailsMapKeyEntityAttribute( this, backingMember, indexType, mapKeyAttributeName ); + } + + + + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // Level 2 : @MapKeyEnumerated / @MapKeyTemporal imply basic key + + if ( mapKeyEnumeratedAnnotation != null || mapKeyTemporalAnnotation != null ) { + return new PluralAttributeIndexDetailsMapKeyBasic( this, backingMember, indexType, mapKeyColumnAnnotation ); + } + + + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // Level 3 : if we could not decode a specific key type, we assume basic + + JavaTypeDescriptor mapKeyType = indexType; + if ( mapKeyClassAnnotation != null ) { + final DotName name = mapKeyClassAnnotation.value().asClass().name(); + mapKeyType = getContext().getJavaTypeDescriptorRepository().getType( name ); + } + if ( mapKeyType == null ) { + if ( !mapKeyJoinColumnAnnotations.isEmpty() ) { + throw getContext().makeMappingException( + "Map key type could not be resolved (to determine entity name to use as key), " + + "but @MapKeyJoinColumn(s) was present. Map should either use generics or " + + "use @MapKeyClass to specify entity class" + ); + } + return new PluralAttributeIndexDetailsMapKeyBasic( this, backingMember, indexType, mapKeyColumnAnnotation ); + } + + + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // Level 4 : if @MapKeyJoinColumn(s) were specified, we have an entity + + if ( !mapKeyJoinColumnAnnotations.isEmpty() ) { + throw new NotYetImplementedException( "Entities as map keys not yet implemented" ); + } + + + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // Level 5 : if decode the nature of the map key type + + if ( mapKeyType.findTypeAnnotation( EMBEDDABLE ) != null ) { + return new PluralAttributeIndexDetailsMapKeyEmbedded( this, backingMember, indexType ); + } + + if ( mapKeyType.findTypeAnnotation( ENTITY ) != null ) { + throw new NotYetImplementedException( "Entities as map keys not yet implemented" ); + } + + return new PluralAttributeIndexDetailsMapKeyBasic( this, backingMember, indexType, mapKeyColumnAnnotation ); } - private JavaTypeDescriptor resolveIndicatedMapKeyClass(AnnotationInstance mapKeyClass) { - final AnnotationValue value = mapKeyClass.value(); - if ( value == null ) { - throw new IllegalStateException( "Unexpected null value for @MapKeyClass#value" ); + private List collectMapKeyJoinColumnAnnotations(MemberDescriptor backingMember) { + final AnnotationInstance singular = backingMember.getAnnotations().get( JPADotNames.MAP_KEY_JOIN_COLUMN ); + final AnnotationInstance plural = backingMember.getAnnotations().get( JPADotNames.MAP_KEY_JOIN_COLUMNS ); + + if ( singular != null && plural != null ) { + throw getContext().makeMappingException( + "Attribute [" + backingMember.toLoggableForm() + + "] declared both @MapKeyJoinColumn and " + + "@MapKeyJoinColumns; should only use one or the other" + ); } - return getContext().getJavaTypeDescriptorRepository().getType( value.asClass().name() ); + + if ( singular == null && plural == null ) { + return Collections.emptyList(); + } + + if ( singular != null ) { + return Collections.singletonList( singular ); + } + + final AnnotationInstance[] annotations = JandexHelper.extractAnnotationsValue( + plural, + "value" + ); + if ( annotations == null || annotations.length == 0 ) { + return null; + } + + return Arrays.asList( annotations ); } private Caching determineCachingSettings(MemberDescriptor backingMember) { @@ -487,14 +603,14 @@ public class PluralAttribute } private String determineCustomLoaderName(MemberDescriptor backingMember) { - final AnnotationInstance loaderAnnotation = backingMember.getAnnotations().get( HibernateDotNames.LOADER ); + final AnnotationInstance loaderAnnotation = backingMember.getAnnotations().get( LOADER ); return loaderAnnotation == null ? null : StringHelper.nullIfEmpty( loaderAnnotation.value( "namedQuery" ).asString() ); } private String determineCustomPersister(MemberDescriptor backingMember) { - final AnnotationInstance persisterAnnotation = backingMember.getAnnotations().get( HibernateDotNames.PERSISTER ); + final AnnotationInstance persisterAnnotation = backingMember.getAnnotations().get( PERSISTER ); return persisterAnnotation == null ? null : StringHelper.nullIfEmpty( persisterAnnotation.value( "impl" ).asString() ); @@ -502,7 +618,7 @@ public class PluralAttribute private OnDeleteAction determineOnDeleteAction(MemberDescriptor backingMember) { final AnnotationInstance onDeleteAnnotation = backingMember.getAnnotations().get( - HibernateDotNames.ON_DELETE + ON_DELETE ); return onDeleteAnnotation == null ? null @@ -510,7 +626,7 @@ public class PluralAttribute } private String determineWereClause(MemberDescriptor backingMember) { - final AnnotationInstance whereAnnotation = backingMember.getAnnotations().get( HibernateDotNames.WHERE ); + final AnnotationInstance whereAnnotation = backingMember.getAnnotations().get( WHERE ); return whereAnnotation == null ? null : StringHelper.nullIfEmpty( whereAnnotation.value( "clause" ).asString() ); @@ -518,7 +634,7 @@ public class PluralAttribute private String determineOrderBy(MemberDescriptor backingMember) { final AnnotationInstance hbmOrderBy = backingMember.getAnnotations().get( HibernateDotNames.ORDER_BY ); - final AnnotationInstance jpaOrderBy = backingMember.getAnnotations().get( JPADotNames.ORDER_BY ); + final AnnotationInstance jpaOrderBy = backingMember.getAnnotations().get( ORDER_BY ); if ( hbmOrderBy != null && jpaOrderBy != null ) { throw getContext().makeMappingException( @@ -569,8 +685,8 @@ public class PluralAttribute } private void checkSortedTypeIsSortable() { - if ( pluralAttributeNature != PluralAttributeSource.Nature.MAP - && pluralAttributeNature != PluralAttributeSource.Nature.SET ) { + if ( pluralAttributeNature != PluralAttributeNature.MAP + && pluralAttributeNature != PluralAttributeNature.SET ) { return; } @@ -677,7 +793,7 @@ public class PluralAttribute return indexDetails; } - public PluralAttributeSource.Nature getPluralAttributeNature() { + public PluralAttributeNature getPluralAttributeNature() { return pluralAttributeNature; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PluralAttributeElementDetails.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PluralAttributeElementDetails.java index 15f32ca9cf..f22c1f0f24 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PluralAttributeElementDetails.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PluralAttributeElementDetails.java @@ -25,6 +25,7 @@ package org.hibernate.metamodel.source.internal.annotations.attribute; import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; import org.hibernate.metamodel.source.internal.annotations.attribute.type.AttributeTypeResolver; +import org.hibernate.metamodel.spi.PluralAttributeElementNature; /** * Presents metadata about the elements of a plural attribute @@ -39,6 +40,13 @@ public interface PluralAttributeElementDetails { */ public JavaTypeDescriptor getJavaType(); + /** + * Get the nature of the element values. + * + * @return The element nature + */ + public PluralAttributeElementNature getElementNature(); + /** * Get the type resolver for the collection elements. * diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PluralAttributeElementDetailsBasic.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PluralAttributeElementDetailsBasic.java index d2fc2597cf..3f43832940 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PluralAttributeElementDetailsBasic.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PluralAttributeElementDetailsBasic.java @@ -31,6 +31,7 @@ import org.hibernate.metamodel.source.internal.annotations.attribute.type.Hibern import org.hibernate.metamodel.source.internal.annotations.attribute.type.LobTypeResolver; import org.hibernate.metamodel.source.internal.annotations.attribute.type.TemporalTypeResolver; import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames; +import org.hibernate.metamodel.spi.PluralAttributeElementNature; import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationValue; @@ -93,6 +94,11 @@ public class PluralAttributeElementDetailsBasic implements PluralAttributeElemen return javaType; } + @Override + public PluralAttributeElementNature getElementNature() { + return PluralAttributeElementNature.BASIC; + } + @Override public AttributeTypeResolver getTypeResolver() { return typeResolver; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PluralAttributeElementDetailsEmbedded.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PluralAttributeElementDetailsEmbedded.java index 9013183508..938b76e478 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PluralAttributeElementDetailsEmbedded.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PluralAttributeElementDetailsEmbedded.java @@ -32,8 +32,11 @@ import org.hibernate.metamodel.source.internal.annotations.attribute.type.Attrib import org.hibernate.metamodel.source.internal.annotations.entity.EmbeddableTypeMetadata; import org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames; import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames; -import org.hibernate.metamodel.source.spi.AttributePath; -import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; +import org.hibernate.metamodel.spi.NaturalIdMutability; +import org.hibernate.metamodel.spi.PluralAttributeElementNature; +import org.hibernate.metamodel.spi.PluralAttributeNature; import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationValue; @@ -99,12 +102,20 @@ public class PluralAttributeElementDetailsEmbedded implements PluralAttributeEle } private EmbeddableTypeMetadata buildEmbeddedMetadata(PluralAttribute pluralAttribute, ClassDescriptor javaType) { + final boolean isMap = pluralAttribute.getPluralAttributeNature() == PluralAttributeNature.MAP; + final AttributeRole role = isMap + ? pluralAttribute.getRole().append( "value" ) + : pluralAttribute.getRole().append( "element" ); + final AttributePath path = isMap + ? pluralAttribute.getPath().append( "value" ) + : pluralAttribute.getPath(); + // we pass `this` (as EmbeddedContainer) in order to route calls back properly. return new EmbeddableTypeMetadata( javaType, this, - pluralAttribute.getRole().append( "element" ), - pluralAttribute.getPath(), + role, + path, pluralAttribute.getAccessType(), pluralAttribute.getAccessorStrategy(), pluralAttribute.getContext() @@ -116,6 +127,11 @@ public class PluralAttributeElementDetailsEmbedded implements PluralAttributeEle return javaType; } + @Override + public PluralAttributeElementNature getElementNature() { + return PluralAttributeElementNature.AGGREGATE; + } + @Override public AttributeTypeResolver getTypeResolver() { return typeResolver; @@ -149,7 +165,7 @@ public class PluralAttributeElementDetailsEmbedded implements PluralAttributeEle } @Override - public SingularAttributeBinding.NaturalIdMutability getContainerNaturalIdMutability() { + public NaturalIdMutability getContainerNaturalIdMutability() { return null; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PluralAttributeElementDetailsEntity.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PluralAttributeElementDetailsEntity.java index 1ef7b4a192..7a683a304e 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PluralAttributeElementDetailsEntity.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PluralAttributeElementDetailsEntity.java @@ -28,6 +28,7 @@ import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; import org.hibernate.metamodel.source.internal.annotations.attribute.type.AttributeTypeResolver; import org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames; import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames; +import org.hibernate.metamodel.spi.PluralAttributeElementNature; import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationValue; @@ -37,6 +38,7 @@ import org.jboss.jandex.AnnotationValue; */ public class PluralAttributeElementDetailsEntity implements PluralAttributeElementDetails { private final ClassDescriptor javaType; + private final PluralAttributeElementNature elementNature; private final AttributeTypeResolver typeResolver; public PluralAttributeElementDetailsEntity( @@ -51,6 +53,7 @@ public class PluralAttributeElementDetailsEntity implements PluralAttributeEleme ); } + this.elementNature = decodeElementNature( pluralAttribute ); this.typeResolver = buildTypeResolver( pluralAttribute, javaType ); } @@ -99,6 +102,25 @@ public class PluralAttributeElementDetailsEntity implements PluralAttributeEleme return (ClassDescriptor) inferredElementType; } + private PluralAttributeElementNature decodeElementNature(PluralAttribute pluralAttribute) { + switch ( pluralAttribute.getNature() ) { + case MANY_TO_ANY: { + return PluralAttributeElementNature.MANY_TO_ANY; + } + case MANY_TO_MANY: { + return PluralAttributeElementNature.MANY_TO_MANY; + } + case ONE_TO_MANY: { + return PluralAttributeElementNature.ONE_TO_MANY; + } + default: { + throw pluralAttribute.getContext().makeMappingException( + "Unexpected plural attribute nature : " + pluralAttribute.getNature() + ); + } + } + } + private AttributeTypeResolver buildTypeResolver(PluralAttribute pluralAttribute, ClassDescriptor javaType) { // todo : No idea what this should be for entities : return the entity name as type name? return no type name? return null; @@ -109,6 +131,11 @@ public class PluralAttributeElementDetailsEntity implements PluralAttributeEleme return javaType; } + @Override + public PluralAttributeElementNature getElementNature() { + return elementNature; + } + @Override public AttributeTypeResolver getTypeResolver() { return typeResolver; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PluralAttributeIndexDetails.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PluralAttributeIndexDetails.java index 482fbe5d9d..0950428da2 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PluralAttributeIndexDetails.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PluralAttributeIndexDetails.java @@ -25,6 +25,7 @@ package org.hibernate.metamodel.source.internal.annotations.attribute; import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; import org.hibernate.metamodel.source.internal.annotations.attribute.type.AttributeTypeResolver; +import org.hibernate.metamodel.spi.PluralAttributeIndexNature; /** * Presents metadata about the elements of a plural attribute. @@ -42,6 +43,14 @@ public interface PluralAttributeIndexDetails { */ public JavaTypeDescriptor getJavaType(); + /** + * Get the nature of the collection index. To a large degree, this is + * used to know what further, more specific type-casts can be performed. + * + * @return The nature of the collection index + */ + public PluralAttributeIndexNature getIndexNature(); + /** * Get the type resolver for the collection index. * diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PluralAttributeIndexDetailsMapKeyBasic.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PluralAttributeIndexDetailsMapKeyBasic.java new file mode 100644 index 0000000000..08ad2fa455 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PluralAttributeIndexDetailsMapKeyBasic.java @@ -0,0 +1,55 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2014, 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.metamodel.source.internal.annotations.attribute; + +import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; +import org.hibernate.metamodel.reflite.spi.MemberDescriptor; +import org.hibernate.metamodel.spi.PluralAttributeIndexNature; + +import org.jboss.jandex.AnnotationInstance; + +/** + * @author Steve Ebersole + */ +public class PluralAttributeIndexDetailsMapKeyBasic extends AbstractPluralAttributeIndexDetailsMapKey { + private final AnnotationInstance mapKeyColumnAnnotation; + + public PluralAttributeIndexDetailsMapKeyBasic( + PluralAttribute pluralAttribute, + MemberDescriptor backingMember, + JavaTypeDescriptor resolvedMapKeyType, + AnnotationInstance mapKeyColumnAnnotation) { + super( pluralAttribute, backingMember, resolvedMapKeyType ); + this.mapKeyColumnAnnotation = mapKeyColumnAnnotation; + } + + public AnnotationInstance getMapKeyColumnAnnotation() { + return mapKeyColumnAnnotation; + } + + @Override + public PluralAttributeIndexNature getIndexNature() { + return PluralAttributeIndexNature.BASIC; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PluralAttributeIndexDetailsMapKeyEmbedded.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PluralAttributeIndexDetailsMapKeyEmbedded.java new file mode 100644 index 0000000000..3e59469164 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PluralAttributeIndexDetailsMapKeyEmbedded.java @@ -0,0 +1,129 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2014, 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.metamodel.source.internal.annotations.attribute; + +import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; +import org.hibernate.metamodel.reflite.spi.MemberDescriptor; +import org.hibernate.metamodel.source.internal.AttributeConversionInfo; +import org.hibernate.metamodel.source.internal.annotations.entity.EmbeddableTypeMetadata; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.NaturalIdMutability; +import org.hibernate.metamodel.spi.PluralAttributeIndexNature; + +/** + * @author Steve Ebersole + */ +public class PluralAttributeIndexDetailsMapKeyEmbedded + extends AbstractPluralAttributeIndexDetailsMapKey + implements EmbeddedContainer { + + private final PluralAttribute pluralAttribute; + private final EmbeddableTypeMetadata embeddableTypeMetadata; + + public PluralAttributeIndexDetailsMapKeyEmbedded( + PluralAttribute pluralAttribute, + MemberDescriptor backingMember, + JavaTypeDescriptor resolvedMapKeyType) { + super( pluralAttribute, backingMember, resolvedMapKeyType ); + this.pluralAttribute = pluralAttribute; + + // we pass `this` (as EmbeddedContainer) in order to route calls back properly. + this.embeddableTypeMetadata = new EmbeddableTypeMetadata( + resolvedMapKeyType, + this, + pluralAttribute.getRole().append( "key" ), + pluralAttribute.getPath().append( "key" ), + pluralAttribute.getAccessType(), + pluralAttribute.getAccessorStrategy(), + pluralAttribute.getContext() + ); + } + + public EmbeddableTypeMetadata getEmbeddableTypeMetadata() { + return embeddableTypeMetadata; + } + + @Override + public PluralAttributeIndexNature getIndexNature() { + return PluralAttributeIndexNature.AGGREGATE; + } + + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // EmbeddedContainer impl + + @Override + public MemberDescriptor getBackingMember() { + return pluralAttribute.getBackingMember(); + } + + @Override + public AttributeConversionInfo locateConversionInfo(AttributePath attributePath) { + return pluralAttribute.getContainer().locateConversionInfo( attributePath ); + } + + @Override + public AttributeOverride locateAttributeOverride(AttributePath attributePath) { + return pluralAttribute.getContainer().locateAttributeOverride( attributePath ); + } + + @Override + public AssociationOverride locateAssociationOverride(AttributePath attributePath) { + return pluralAttribute.getContainer().locateAssociationOverride( attributePath ); + } + + @Override + public NaturalIdMutability getContainerNaturalIdMutability() { + return null; + } + + @Override + public boolean getContainerOptionality() { + return false; + } + + @Override + public boolean getContainerUpdatability() { + return false; + } + + @Override + public boolean getContainerInsertability() { + return false; + } + + @Override + public void registerConverter(AttributePath attributePath, AttributeConversionInfo conversionInfo) { + pluralAttribute.getContainer().registerConverter( attributePath, conversionInfo ); + } + + @Override + public void registerAttributeOverride(AttributePath attributePath, AttributeOverride override) { + pluralAttribute.getContainer().registerAttributeOverride( attributePath, override ); + } + + @Override + public void registerAssociationOverride(AttributePath attributePath, AssociationOverride override) { + pluralAttribute.getContainer().registerAssociationOverride( attributePath, override ); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PluralAttributeIndexDetailsMapKeyEntityAttribute.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PluralAttributeIndexDetailsMapKeyEntityAttribute.java new file mode 100644 index 0000000000..779a6d35b5 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PluralAttributeIndexDetailsMapKeyEntityAttribute.java @@ -0,0 +1,54 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2014, 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.metamodel.source.internal.annotations.attribute; + +import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; +import org.hibernate.metamodel.reflite.spi.MemberDescriptor; +import org.hibernate.metamodel.spi.PluralAttributeIndexNature; + +/** + * @author Steve Ebersole + */ +public class PluralAttributeIndexDetailsMapKeyEntityAttribute extends AbstractPluralAttributeIndexDetailsMapKey { + private final String referencedAttributeName; + + public PluralAttributeIndexDetailsMapKeyEntityAttribute( + PluralAttribute pluralAttribute, + MemberDescriptor backingMember, + JavaTypeDescriptor resolvedMapKeyType, + String referencedAttributeName) { + super( pluralAttribute, backingMember, resolvedMapKeyType ); + this.referencedAttributeName = referencedAttributeName; + } + + public String getReferencedAttributeName() { + return referencedAttributeName; + } + + @Override + public PluralAttributeIndexNature getIndexNature() { + // we don't know until we can resolve the referenced entity attribute + return null; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PluralAttributeSequentialIndexDetails.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PluralAttributeIndexDetailsSequential.java similarity index 90% rename from hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PluralAttributeSequentialIndexDetails.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PluralAttributeIndexDetailsSequential.java index 540f3a9222..aba77a4643 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PluralAttributeSequentialIndexDetails.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PluralAttributeIndexDetailsSequential.java @@ -26,6 +26,7 @@ package org.hibernate.metamodel.source.internal.annotations.attribute; import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; import org.hibernate.metamodel.reflite.spi.MemberDescriptor; import org.hibernate.metamodel.source.internal.annotations.attribute.type.AttributeTypeResolver; +import org.hibernate.metamodel.spi.PluralAttributeIndexNature; import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationValue; @@ -36,13 +37,13 @@ import static org.hibernate.metamodel.source.internal.annotations.util.JPADotNam /** * @author Steve Ebersole */ -public class PluralAttributeSequentialIndexDetails implements PluralAttributeIndexDetails { +public class PluralAttributeIndexDetailsSequential implements PluralAttributeIndexDetails { private final PluralAttribute pluralAttribute; private final Column orderColumn; private final int base; - public PluralAttributeSequentialIndexDetails(PluralAttribute pluralAttribute, MemberDescriptor backingMember) { + public PluralAttributeIndexDetailsSequential(PluralAttribute pluralAttribute, MemberDescriptor backingMember) { this.pluralAttribute = pluralAttribute; this.orderColumn = determineOrderColumn( backingMember ); @@ -84,6 +85,11 @@ public class PluralAttributeSequentialIndexDetails implements PluralAttributeInd return null; } + @Override + public PluralAttributeIndexNature getIndexNature() { + return PluralAttributeIndexNature.SEQUENTIAL; + } + @Override public AttributeTypeResolver getTypeResolver() { return null; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PluralAttributeMapKeyDetails.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PluralAttributeMapKeyDetails.java deleted file mode 100644 index 0abc0e485a..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/PluralAttributeMapKeyDetails.java +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2014, 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.metamodel.source.internal.annotations.attribute; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; -import org.hibernate.metamodel.reflite.spi.MemberDescriptor; -import org.hibernate.metamodel.source.internal.annotations.attribute.type.AttributeTypeResolver; -import org.hibernate.metamodel.source.internal.annotations.attribute.type.AttributeTypeResolverComposition; -import org.hibernate.metamodel.source.internal.annotations.attribute.type.EnumeratedTypeResolver; -import org.hibernate.metamodel.source.internal.annotations.attribute.type.HibernateTypeResolver; -import org.hibernate.metamodel.source.internal.annotations.attribute.type.TemporalTypeResolver; -import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames; -import org.hibernate.metamodel.source.internal.annotations.util.JandexHelper; - -import org.jboss.jandex.AnnotationInstance; -import org.jboss.jandex.AnnotationValue; - - -/** - * PluralAttributeIndexDetails implementation for describing the key of a Map - * - * @author Steve Ebersole - */ -public class PluralAttributeMapKeyDetails implements PluralAttributeIndexDetails { - private final PluralAttribute pluralAttribute; - - private final AnnotationInstance mapKeyAnnotation; - private final AnnotationInstance mapKeyClassAnnotation; - - private final AnnotationInstance mapKeyColumnAnnotation; - private final List mapKeyJoinColumnAnnotations; - - private final JavaTypeDescriptor resolvedMapKeyType; - private final AttributeTypeResolver typeResolver; - - public PluralAttributeMapKeyDetails( - PluralAttribute pluralAttribute, - MemberDescriptor backingMember, - JavaTypeDescriptor resolvedMapKeyType) { - this.pluralAttribute = pluralAttribute; - - this.mapKeyAnnotation = backingMember.getAnnotations().get( JPADotNames.MAP_KEY ); - this.mapKeyClassAnnotation = backingMember.getAnnotations().get( JPADotNames.MAP_KEY_CLASS ); - - if ( mapKeyAnnotation != null && mapKeyClassAnnotation != null ) { - // this is an error according to the spec... - throw pluralAttribute.getContext().makeMappingException( - "Map attribute defined both @MapKey and @MapKeyClass; only one should be used : " + - backingMember.toLoggableForm() - ); - } - - this.mapKeyColumnAnnotation = backingMember.getAnnotations().get( JPADotNames.MAP_KEY_COLUMN ); - this.mapKeyJoinColumnAnnotations = collectMapKeyJoinColumnAnnotations( backingMember ); - - this.resolvedMapKeyType = determineMapKeyJavaType( backingMember, resolvedMapKeyType, mapKeyClassAnnotation ); - - this.typeResolver = new AttributeTypeResolverComposition( - resolvedMapKeyType, - pluralAttribute.getContext(), - HibernateTypeResolver.createCollectionIndexTypeResolver( pluralAttribute, resolvedMapKeyType ), - EnumeratedTypeResolver.createCollectionIndexTypeResolver( pluralAttribute, resolvedMapKeyType ), - TemporalTypeResolver.createCollectionIndexTypeResolver( pluralAttribute, resolvedMapKeyType ) - ); - } - - private JavaTypeDescriptor determineMapKeyJavaType( - MemberDescriptor backingMember, - JavaTypeDescriptor resolvedMapKeyType, - AnnotationInstance mapKeyClassAnnotation) { - if ( mapKeyClassAnnotation != null ) { - final AnnotationValue value = mapKeyClassAnnotation.value(); - assert value != null : "Unexpected null from @MapKeyClass.value : " + backingMember.toLoggableForm(); - return pluralAttribute.getContext().getJavaTypeDescriptorRepository().getType( value.asClass().name() ); - } - - return resolvedMapKeyType; - } - - private List collectMapKeyJoinColumnAnnotations(MemberDescriptor backingMember) { - final AnnotationInstance singular = backingMember.getAnnotations().get( JPADotNames.MAP_KEY_JOIN_COLUMN ); - final AnnotationInstance plural = backingMember.getAnnotations().get( JPADotNames.MAP_KEY_JOIN_COLUMNS ); - - if ( singular != null && plural != null ) { - throw pluralAttribute.getContext().makeMappingException( - "Attribute [" + backingMember.toLoggableForm() + - "] declared both @MapKeyJoinColumn and " + - "@MapKeyJoinColumns; should only use one or the other" - ); - } - - if ( singular == null && plural == null ) { - return null; - } - - if ( singular != null ) { - return Collections.singletonList( singular ); - } - - final AnnotationInstance[] annotations = JandexHelper.extractAnnotationsValue( - plural, - "value" - ); - if ( annotations == null || annotations.length == 0 ) { - return null; - } - - return Arrays.asList( annotations ); - } - - /** - * Get the {@link javax.persistence.MapKey} annotation descriptor, if one. - * - * @return The @MapKey annotation, or {@code null} - */ - public AnnotationInstance getMapKeyAnnotation() { - return mapKeyAnnotation; - } - - /** - * Get the {@link javax.persistence.MapKeyClass} annotation descriptor, if one. - * - * @return The @MapKeyClass annotation, or {@code null} - */ - public AnnotationInstance getMapKeyClassAnnotation() { - return mapKeyClassAnnotation; - } - - public AnnotationInstance getMapKeyColumnAnnotation() { - return mapKeyColumnAnnotation; - } - - public List getMapKeyJoinColumnAnnotations() { - return mapKeyJoinColumnAnnotations; - } - - @Override - public JavaTypeDescriptor getJavaType() { - return resolvedMapKeyType; - } - - @Override - public AttributeTypeResolver getTypeResolver() { - return typeResolver; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/SingularAssociationAttribute.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/SingularAssociationAttribute.java index 2c92ec1929..bfbcbcd50e 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/SingularAssociationAttribute.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/SingularAssociationAttribute.java @@ -25,7 +25,6 @@ package org.hibernate.metamodel.source.internal.annotations.attribute; import java.util.ArrayList; import java.util.Set; - import javax.persistence.AccessType; import javax.persistence.CascadeType; @@ -39,8 +38,9 @@ import org.hibernate.metamodel.source.internal.annotations.entity.ManagedTypeMet import org.hibernate.metamodel.source.internal.annotations.util.AssociationHelper; import org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames; import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames; -import org.hibernate.metamodel.source.spi.AttributePath; -import org.hibernate.metamodel.source.spi.AttributeRole; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; + import org.jboss.jandex.AnnotationInstance; /** diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/SingularAttribute.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/SingularAttribute.java index f4868e653e..c1477f9e90 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/SingularAttribute.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/SingularAttribute.java @@ -26,7 +26,7 @@ package org.hibernate.metamodel.source.internal.annotations.attribute; import java.util.List; import org.hibernate.metamodel.source.internal.AttributeConversionInfo; -import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; +import org.hibernate.metamodel.spi.NaturalIdMutability; /** * Represents a singular persistent attribute. @@ -38,7 +38,7 @@ public interface SingularAttribute extends PersistentAttribute { boolean isVersion(); - SingularAttributeBinding.NaturalIdMutability getNaturalIdMutability(); + NaturalIdMutability getNaturalIdMutability(); AttributeConversionInfo getConversionInfo(); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/entity/EmbeddableTypeMetadata.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/entity/EmbeddableTypeMetadata.java index ecde044026..e82c503f85 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/entity/EmbeddableTypeMetadata.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/entity/EmbeddableTypeMetadata.java @@ -35,9 +35,9 @@ import org.hibernate.metamodel.source.internal.annotations.attribute.EmbeddedCon import org.hibernate.metamodel.source.internal.annotations.util.ConverterAndOverridesHelper; import org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames; import org.hibernate.metamodel.source.internal.annotations.util.JandexHelper; -import org.hibernate.metamodel.source.spi.AttributePath; -import org.hibernate.metamodel.source.spi.AttributeRole; -import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; +import org.hibernate.metamodel.spi.NaturalIdMutability; import org.jboss.jandex.AnnotationInstance; @@ -54,7 +54,7 @@ import static org.hibernate.metamodel.source.internal.annotations.util.Hibernate */ public class EmbeddableTypeMetadata extends ManagedTypeMetadata { private final EmbeddedContainer container; - private final SingularAttributeBinding.NaturalIdMutability naturalIdMutability; + private final NaturalIdMutability naturalIdMutability; private final String parentReferencingAttributeName; private final String customTuplizerClassName; @@ -132,7 +132,7 @@ public class EmbeddableTypeMetadata extends ManagedTypeMetadata { return parentReferencingAttributeName; } - public SingularAttributeBinding.NaturalIdMutability getNaturalIdMutability() { + public NaturalIdMutability getNaturalIdMutability() { return naturalIdMutability; } @@ -179,14 +179,14 @@ public class EmbeddableTypeMetadata extends ManagedTypeMetadata { @Override @SuppressWarnings("SimplifiableIfStatement") public boolean canAttributesBeUpdatable() { - if ( naturalIdMutability == SingularAttributeBinding.NaturalIdMutability.IMMUTABLE ) { + if ( naturalIdMutability == NaturalIdMutability.IMMUTABLE ) { return false; } return container.getContainerUpdatability(); } @Override - public SingularAttributeBinding.NaturalIdMutability getContainerNaturalIdMutability() { + public NaturalIdMutability getContainerNaturalIdMutability() { return naturalIdMutability; } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/entity/IdentifiableTypeMetadata.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/entity/IdentifiableTypeMetadata.java index 4e89331dd1..7955cf9ca0 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/entity/IdentifiableTypeMetadata.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/entity/IdentifiableTypeMetadata.java @@ -46,8 +46,8 @@ import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames; import org.hibernate.metamodel.source.internal.annotations.util.JPAListenerHelper; import org.hibernate.metamodel.source.internal.annotations.util.JandexHelper; import org.hibernate.metamodel.source.internal.jandex.PseudoJpaDotNames; -import org.hibernate.metamodel.source.spi.AttributePath; import org.hibernate.metamodel.source.spi.JpaCallbackSource; +import org.hibernate.metamodel.spi.AttributePath; import org.hibernate.metamodel.spi.binding.InheritanceType; import org.jboss.jandex.AnnotationInstance; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/entity/ManagedTypeMetadata.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/entity/ManagedTypeMetadata.java index 4019ad3f8d..57e1fc5185 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/entity/ManagedTypeMetadata.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/entity/ManagedTypeMetadata.java @@ -64,10 +64,10 @@ import org.hibernate.metamodel.source.internal.annotations.util.AnnotationParser import org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames; import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames; import org.hibernate.metamodel.source.internal.annotations.util.JandexHelper; -import org.hibernate.metamodel.source.spi.AttributePath; -import org.hibernate.metamodel.source.spi.AttributeRole; import org.hibernate.metamodel.source.spi.MappingException; -import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; +import org.hibernate.metamodel.spi.NaturalIdMutability; import org.hibernate.xml.spi.Origin; import org.hibernate.xml.spi.SourceType; @@ -388,6 +388,10 @@ public abstract class ManagedTypeMetadata implements OverrideAndConverterCollect return attributeRoleBase; } + public AttributePath getAttributePathBase() { + return attributePathBase; + } + public JavaTypeDescriptor getJavaTypeDescriptor() { return javaTypeDescriptor; } @@ -1071,7 +1075,7 @@ public abstract class ManagedTypeMetadata implements OverrideAndConverterCollect return true; } - public SingularAttributeBinding.NaturalIdMutability getContainerNaturalIdMutability() { - return SingularAttributeBinding.NaturalIdMutability.NOT_NATURAL_ID; + public NaturalIdMutability getContainerNaturalIdMutability() { + return NaturalIdMutability.NOT_NATURAL_ID; } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/entity/RootEntityTypeMetadata.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/entity/RootEntityTypeMetadata.java index 2ed163fa50..9c746205f3 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/entity/RootEntityTypeMetadata.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/entity/RootEntityTypeMetadata.java @@ -33,7 +33,7 @@ import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; import org.hibernate.metamodel.source.internal.annotations.AnnotationBindingContext; import org.hibernate.metamodel.source.internal.annotations.attribute.PrimaryKeyJoinColumn; import org.hibernate.metamodel.source.internal.annotations.util.ConverterAndOverridesHelper; -import org.hibernate.metamodel.source.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributePath; import org.jboss.jandex.AnnotationInstance; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/global/SqlResultSetProcessor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/global/SqlResultSetProcessor.java index a337bf219a..321e743a22 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/global/SqlResultSetProcessor.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/global/SqlResultSetProcessor.java @@ -46,7 +46,7 @@ import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.metamodel.source.internal.annotations.AnnotationBindingContext; import org.hibernate.metamodel.source.internal.annotations.util.JandexHelper; import org.hibernate.metamodel.spi.binding.AttributeBinding; -import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding; +import org.hibernate.metamodel.spi.binding.EmbeddedAttributeBinding; import org.hibernate.metamodel.spi.binding.EntityBinding; import org.hibernate.metamodel.spi.binding.ManyToOneAttributeBinding; import org.hibernate.metamodel.spi.binding.SingularAssociationAttributeBinding; @@ -255,11 +255,11 @@ public class SqlResultSetProcessor { String reducedName = name.substring( 0, dotIndex ); AttributeBinding attributeBinding = entityBinding.locateAttributeBinding( reducedName ); Iterable attributeBindings = null; - if ( CompositeAttributeBinding.class.isInstance( attributeBinding ) ) { - CompositeAttributeBinding compositeAttributeBinding = CompositeAttributeBinding.class.cast( + if ( EmbeddedAttributeBinding.class.isInstance( attributeBinding ) ) { + EmbeddedAttributeBinding embeddedAttributeBinding = EmbeddedAttributeBinding.class.cast( attributeBinding ); - attributeBindings = compositeAttributeBinding.attributeBindings(); + attributeBindings = embeddedAttributeBinding.getEmbeddableBinding().attributeBindings(); } else if ( ManyToOneAttributeBinding.class.isInstance( attributeBinding ) ) { @@ -287,8 +287,9 @@ public class SqlResultSetProcessor { SingularAttributeBinding identifierAttributeBinding = referencedEntityBinding.getHierarchyDetails() .getEntityIdentifier() .getAttributeBinding(); - if ( CompositeAttributeBinding.class.isInstance( identifierAttributeBinding ) ) { - attributeBindings = CompositeAttributeBinding.class.cast( identifierAttributeBinding ) + if ( EmbeddedAttributeBinding.class.isInstance( identifierAttributeBinding ) ) { + attributeBindings = EmbeddedAttributeBinding.class.cast( identifierAttributeBinding ) + .getEmbeddableBinding() .attributeBindings(); } else { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/util/AnnotationParserHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/util/AnnotationParserHelper.java index 6492879117..dd68b48793 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/util/AnnotationParserHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/util/AnnotationParserHelper.java @@ -33,8 +33,8 @@ import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; import org.hibernate.metamodel.reflite.spi.MemberDescriptor; import org.hibernate.metamodel.source.internal.annotations.entity.EntityBindingContext; import org.hibernate.metamodel.source.internal.annotations.entity.ManagedTypeMetadata; +import org.hibernate.metamodel.spi.NaturalIdMutability; import org.hibernate.metamodel.spi.binding.CustomSQL; -import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.ClassInfo; @@ -180,7 +180,7 @@ public class AnnotationParserHelper { return mapKeyType; } - public static SingularAttributeBinding.NaturalIdMutability determineNaturalIdMutability( + public static NaturalIdMutability determineNaturalIdMutability( ManagedTypeMetadata container, MemberDescriptor member) { final AnnotationInstance naturalIdAnnotation = member.getAnnotations().get( HibernateDotNames.NATURAL_ID ); @@ -191,8 +191,8 @@ public class AnnotationParserHelper { final boolean mutable = naturalIdAnnotation.value( "mutable" ) != null && naturalIdAnnotation.value( "mutable" ).asBoolean(); return mutable - ? SingularAttributeBinding.NaturalIdMutability.MUTABLE - : SingularAttributeBinding.NaturalIdMutability.IMMUTABLE; + ? NaturalIdMutability.MUTABLE + : NaturalIdMutability.IMMUTABLE; } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/util/ConverterAndOverridesHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/util/ConverterAndOverridesHelper.java index ef42cdc7b5..afead838af 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/util/ConverterAndOverridesHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/util/ConverterAndOverridesHelper.java @@ -35,7 +35,7 @@ import org.hibernate.metamodel.source.internal.annotations.attribute.OverrideAnd import org.hibernate.metamodel.source.internal.annotations.attribute.PersistentAttribute; import org.hibernate.metamodel.source.internal.annotations.entity.EntityBindingContext; import org.hibernate.metamodel.source.internal.annotations.entity.ManagedTypeMetadata; -import org.hibernate.metamodel.source.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributePath; import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationValue; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractEmbeddableJaxbSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractEmbeddableJaxbSource.java new file mode 100644 index 0000000000..3ec044ff3c --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractEmbeddableJaxbSource.java @@ -0,0 +1,129 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2014, 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.metamodel.source.internal.hbm; + +import java.util.Collections; +import java.util.List; + +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbAnyElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbArrayElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbBagElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbComponentElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbDynamicComponentElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbKeyManyToOneElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbKeyPropertyElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbListElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbManyToOneElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbMapElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbNestedCompositeElementElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbOneToOneElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPrimitiveArrayElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPropertiesElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPropertyElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbSetElement; + +/** + * @author Steve Ebersole + */ +public abstract class AbstractEmbeddableJaxbSource implements EmbeddableJaxbSource { + @Override + public List getKeyPropertyElementList() { + return Collections.emptyList(); + } + + @Override + public List getKeyManyToOneElementList() { + return Collections.emptyList(); + } + + @Override + public List getPropertyElementList() { + return Collections.emptyList(); + } + + @Override + public List getManyToOneElementList() { + return Collections.emptyList(); + } + + @Override + public List getOneToOneElementList() { + return Collections.emptyList(); + } + + @Override + public List getComponentElementList() { + return Collections.emptyList(); + } + + @Override + public List getNestedCompositeElementList() { + return Collections.emptyList(); + } + + @Override + public List getDynamicComponentElementList() { + return Collections.emptyList(); + } + + @Override + public List getPropertiesElementList() { + return Collections.emptyList(); + } + + @Override + public List getAnyElementList() { + return Collections.emptyList(); + } + + @Override + public List getMapElementList() { + return Collections.emptyList(); + } + + @Override + public List getSetElementList() { + return Collections.emptyList(); + } + + @Override + public List getListElementList() { + return Collections.emptyList(); + } + + @Override + public List getBagElementList() { + return Collections.emptyList(); + } + + @Override + public List getArrayElementList() { + return Collections.emptyList(); + } + + @Override + public List getPrimitiveArrayElementList() { + return Collections.emptyList(); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractEmbeddedAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractEmbeddedAttributeSourceImpl.java new file mode 100644 index 0000000000..5debfa0644 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractEmbeddedAttributeSourceImpl.java @@ -0,0 +1,150 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2012, 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.metamodel.source.internal.hbm; + +import java.util.Collection; +import java.util.List; + +import org.hibernate.mapping.PropertyGeneration; +import org.hibernate.metamodel.source.internal.jaxb.hbm.ComponentSourceElement; +import org.hibernate.metamodel.source.spi.AttributeSourceContainer; +import org.hibernate.metamodel.source.spi.EmbeddableSource; +import org.hibernate.metamodel.source.spi.EmbeddedAttributeSource; +import org.hibernate.metamodel.source.spi.HibernateTypeSource; +import org.hibernate.metamodel.source.spi.RelationalValueSource; +import org.hibernate.metamodel.source.spi.ToolingHintSource; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; +import org.hibernate.metamodel.spi.NaturalIdMutability; +import org.hibernate.metamodel.spi.SingularAttributeNature; + +/** + * Common bas class for and mappings. + * + * @author Steve Ebersole + */ +public abstract class AbstractEmbeddedAttributeSourceImpl + extends AbstractHbmSourceNode + implements EmbeddedAttributeSource { + + private final ComponentSourceElement jaxbComponentSourceElement; + private final EmbeddableSourceImpl embeddableSource; + + protected AbstractEmbeddedAttributeSourceImpl( + MappingDocument sourceMappingDocument, + AttributeSourceContainer parentContainer, + AttributeRole attributeRoleBase, + AttributePath attributePathBase, + ComponentSourceElement jaxbComponentSourceElement, + EmbeddableJaxbSource embeddableJaxbSource, + NaturalIdMutability naturalIdMutability, + String logicalTableName) { + super( sourceMappingDocument ); + this.jaxbComponentSourceElement = jaxbComponentSourceElement; + this.embeddableSource = new EmbeddableSourceImpl( + sourceMappingDocument, + attributeRoleBase, + attributePathBase, + embeddableJaxbSource, + logicalTableName, + naturalIdMutability + ); + } + + protected ComponentSourceElement jaxbComponentSourceElement() { + return jaxbComponentSourceElement; + } + + @Override + public EmbeddableSource getEmbeddableSource() { + return embeddableSource; + } + + @Override + public String getName() { + return jaxbComponentSourceElement.getName(); + } + + @Override + public boolean isSingular() { + return true; + } + + @Override + public boolean isVirtualAttribute() { + return false; + } + + @Override + public SingularAttributeNature getSingularAttributeNature() { + return SingularAttributeNature.COMPOSITE; + } + + @Override + public HibernateTypeSource getTypeInformation() { + // does not support type information. + return null; + } + + @Override + public String getPropertyAccessorName() { + return jaxbComponentSourceElement.getAccess(); + } + + @Override + public NaturalIdMutability getNaturalIdMutability() { + return null; + } + + @Override + public Collection getToolingHintSources() { + return jaxbComponentSourceElement.getMeta(); + } + + @Override + public PropertyGeneration getGeneration() { + // todo : is this correct here? + return null; + } + + @Override + public boolean areValuesNullableByDefault() { + return true; + } + + + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // relational value source info comes from the individual sub-attributes + + @Override + public String getContainingTableName() { + return null; + } + + @Override + public List relationalValueSources() { + // none, they are defined on the simple sub-attributes + return null; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractEntitySourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractEntitySourceImpl.java index 85c274a5b8..f0a6fd4597 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractEntitySourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractEntitySourceImpl.java @@ -34,7 +34,6 @@ import java.util.Set; import org.hibernate.EntityMode; import org.hibernate.TruthValue; -import org.hibernate.cfg.NotYetImplementedException; import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.metamodel.source.internal.jaxb.hbm.EntityElement; @@ -66,9 +65,11 @@ import org.hibernate.metamodel.source.spi.JpaCallbackSource; import org.hibernate.metamodel.source.spi.SecondaryTableSource; import org.hibernate.metamodel.source.spi.SubclassEntitySource; import org.hibernate.metamodel.source.spi.ToolingHintSource; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; import org.hibernate.metamodel.spi.LocalBindingContext; +import org.hibernate.metamodel.spi.NaturalIdMutability; import org.hibernate.metamodel.spi.binding.CustomSQL; -import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; import org.hibernate.xml.spi.Origin; /** @@ -85,6 +86,9 @@ public abstract class AbstractEntitySourceImpl private final String entityName; private final String jpaEntityName; + private final AttributeRole attributeRoleBase; + private final AttributePath attributePathBase; + private List subclassEntitySources = new ArrayList(); private int inLineViewCount = 0; @@ -109,6 +113,10 @@ public abstract class AbstractEntitySourceImpl this.entityName = className; this.jpaEntityName = StringHelper.unqualify( className ); } + + this.attributePathBase = new AttributePath(); + this.attributeRoleBase = new AttributeRole( entityName ); + this.filterSources = buildFilterSources(); } @@ -117,6 +125,16 @@ public abstract class AbstractEntitySourceImpl return StringHelper.isNotEmpty( className ) ? className : entityName; } + @Override + public AttributePath getAttributePathBase() { + return attributePathBase; + } + + @Override + public AttributeRole getAttributeRoleBase() { + return attributeRoleBase; + } + @Override public Collection getSubTypes() { return subclassEntitySources; @@ -166,14 +184,14 @@ public abstract class AbstractEntitySourceImpl } protected List buildAttributeSources(List attributeSources) { - return buildAttributeSources( entityElement, attributeSources, null, SingularAttributeBinding.NaturalIdMutability.NOT_NATURAL_ID ); + return buildAttributeSources( entityElement, attributeSources, null, NaturalIdMutability.NOT_NATURAL_ID ); } protected List buildAttributeSources( EntityElement element, List attributeSources, String logicTalbeName, - SingularAttributeBinding.NaturalIdMutability naturalIdMutability){ + NaturalIdMutability naturalIdMutability){ processPropertyAttributes( attributeSources, element.getProperty(), logicTalbeName, naturalIdMutability ); processComponentAttributes( attributeSources, @@ -218,11 +236,12 @@ public abstract class AbstractEntitySourceImpl List results, List propertyElements, String logicalTableName, - SingularAttributeBinding.NaturalIdMutability naturalIdMutability) { + NaturalIdMutability naturalIdMutability) { for ( JaxbPropertyElement element : propertyElements ) { results.add( new PropertyAttributeSourceImpl( sourceMappingDocument(), + this, element, logicalTableName, naturalIdMutability @@ -253,15 +272,15 @@ public abstract class AbstractEntitySourceImpl protected void processComponentAttributes(List results, List elements, String logicalTableName, - SingularAttributeBinding.NaturalIdMutability naturalIdMutability) { + NaturalIdMutability naturalIdMutability) { for ( JaxbComponentElement element : elements ) { results.add( - new ComponentAttributeSourceImpl( + new EmbeddedAttributeSourceImpl( sourceMappingDocument(), - element, this, - logicalTableName, - naturalIdMutability + element, + naturalIdMutability, + logicalTableName ) ); } @@ -270,18 +289,19 @@ public abstract class AbstractEntitySourceImpl protected void processDynamicComponentAttributes(List results, List elements, String logicalTableName, - SingularAttributeBinding.NaturalIdMutability naturalIdMutability) { + NaturalIdMutability naturalIdMutability) { // todo : implement } protected void processManyToOneAttributes(List results, List elements, String logicalTableName, - SingularAttributeBinding.NaturalIdMutability naturalIdMutability) { + NaturalIdMutability naturalIdMutability) { for ( JaxbManyToOneElement element : elements ) { results.add( new ManyToOneAttributeSourceImpl( sourceMappingDocument(), + this, element, logicalTableName, naturalIdMutability @@ -292,11 +312,12 @@ public abstract class AbstractEntitySourceImpl protected void processOneToOneAttributes(List results, List elements, String logicalTableName, - SingularAttributeBinding.NaturalIdMutability naturalIdMutability) { + NaturalIdMutability naturalIdMutability) { for ( JaxbOneToOneElement element : elements ) { results.add( new OneToOneAttributeSourceImpl( sourceMappingDocument(), + this, element, logicalTableName, naturalIdMutability @@ -308,7 +329,7 @@ public abstract class AbstractEntitySourceImpl protected void processAnyAttributes(List results, List elements, String logicalTableName, - SingularAttributeBinding.NaturalIdMutability naturalIdMutability) { + NaturalIdMutability naturalIdMutability) { // todo : implement } @@ -357,15 +378,24 @@ public abstract class AbstractEntitySourceImpl ); } } - protected void processIdBagAttributes(List results, - List propertyElements){ - if ( !propertyElements.isEmpty() ) { - throw new NotYetImplementedException( " is not supported yet" ); + protected void processIdBagAttributes( + List results, + List elements){ + for ( JaxbIdbagElement element : elements ) { + results.add( + new IdBagSourceImpl( + sourceMappingDocument(), + element, + this + ) + ); } } - protected void processBagAttributes(List results, - List propertyElements) { + + protected void processBagAttributes( + List results, + List propertyElements) { for ( JaxbBagElement element : propertyElements ) { results.add( new BagSourceImpl( @@ -393,7 +423,7 @@ public abstract class AbstractEntitySourceImpl secondaryTableSources.add( secondaryTableSource ); final String logicalTableName = secondaryTableSource.getLogicalTableNameForContainedColumns(); - final SingularAttributeBinding.NaturalIdMutability naturalIdMutability = SingularAttributeBinding.NaturalIdMutability.NOT_NATURAL_ID; + final NaturalIdMutability naturalIdMutability = NaturalIdMutability.NOT_NATURAL_ID; processAnyAttributes( attributeSources, joinElement.getAny(), @@ -558,11 +588,6 @@ public abstract class AbstractEntitySourceImpl return entityElement.getMeta(); } - @Override - public String getPath() { - return ""; - } - @Override public List attributeSources() { return attributeSources; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractPluralAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractPluralAttributeSourceImpl.java index 48001af54a..a13f1e55fe 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractPluralAttributeSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractPluralAttributeSourceImpl.java @@ -31,12 +31,12 @@ import org.hibernate.AssertionFailure; import org.hibernate.cfg.NotYetImplementedException; import org.hibernate.engine.FetchStyle; import org.hibernate.engine.FetchTiming; -import org.hibernate.internal.util.StringHelper; import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbFilterElement; import org.hibernate.metamodel.source.internal.jaxb.hbm.PluralAttributeElement; import org.hibernate.metamodel.source.spi.AttributeSourceContainer; import org.hibernate.metamodel.source.spi.AttributeSourceResolutionContext; +import org.hibernate.metamodel.source.spi.CollectionIdSource; import org.hibernate.metamodel.source.spi.FilterSource; import org.hibernate.metamodel.source.spi.HibernateTypeSource; import org.hibernate.metamodel.source.spi.MappingException; @@ -45,6 +45,8 @@ import org.hibernate.metamodel.source.spi.PluralAttributeKeySource; import org.hibernate.metamodel.source.spi.PluralAttributeSource; import org.hibernate.metamodel.source.spi.TableSpecificationSource; import org.hibernate.metamodel.source.spi.ToolingHintSource; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; import org.hibernate.metamodel.spi.binding.Caching; import org.hibernate.metamodel.spi.binding.CustomSQL; @@ -58,6 +60,9 @@ public abstract class AbstractPluralAttributeSourceImpl private final PluralAttributeElement pluralAttributeElement; private final AttributeSourceContainer container; + private final AttributeRole attributeRole; + private final AttributePath attributePath; + private final HibernateTypeSource typeInformation; private final PluralAttributeKeySource keySource; @@ -75,6 +80,9 @@ public abstract class AbstractPluralAttributeSourceImpl this.pluralAttributeElement = pluralAttributeElement; this.container = container; + this.attributeRole = container.getAttributeRoleBase().append( pluralAttributeElement.getName() ); + this.attributePath = container.getAttributePathBase().append( pluralAttributeElement.getName() ); + this.keySource = new PluralAttributeKeySourceImpl( sourceMappingDocument(), pluralAttributeElement.getKey(), @@ -82,10 +90,7 @@ public abstract class AbstractPluralAttributeSourceImpl ); this.elementSource = interpretElementType(); - this.caching = Helper.createCaching( - pluralAttributeElement.getCache(), - StringHelper.qualify( container().getPath(), getName() ) - ); + this.caching = Helper.createCaching( pluralAttributeElement.getCache() ); this.typeInformation = new HibernateTypeSource() { @Override @@ -126,7 +131,7 @@ public abstract class AbstractPluralAttributeSourceImpl // If so, getType is currently null. // elementClassReference = makeClassReference(pluralAttributeElement // .getElement().getType().getName()); - return new BasicPluralAttributeElementSourceImpl( + return new PluralAttributeElementSourceBasicImpl( sourceMappingDocument(), pluralAttributeElement.getElement() ); @@ -136,8 +141,9 @@ public abstract class AbstractPluralAttributeSourceImpl pluralAttributeElement .getCompositeElement().getClazz() ); - return new CompositePluralAttributeElementSourceImpl( + return new PluralAttributeElementSourceEmbeddedImpl( sourceMappingDocument(), + this, pluralAttributeElement.getCompositeElement(), pluralAttributeElement.getCascade() ); @@ -147,7 +153,7 @@ public abstract class AbstractPluralAttributeSourceImpl pluralAttributeElement .getOneToMany().getClazz() ); - return new OneToManyPluralAttributeElementSourceImpl( + return new PluralAttributeElementSourceOneToManyImpl( sourceMappingDocument(), this, pluralAttributeElement.getOneToMany(), @@ -159,7 +165,7 @@ public abstract class AbstractPluralAttributeSourceImpl pluralAttributeElement .getManyToMany().getClazz() ); - return new ManyToManyPluralAttributeElementSourceImpl( + return new PluralAttributeElementSourceManyToManyImpl( sourceMappingDocument(), this, pluralAttributeElement.getManyToMany(), @@ -178,6 +184,16 @@ public abstract class AbstractPluralAttributeSourceImpl } } + @Override + public AttributePath getAttributePath() { + return attributePath; + } + + @Override + public AttributeRole getAttributeRole() { + return attributeRole; + } + @Override public PluralAttributeElementSource resolvePluralAttributeElementSource(AttributeSourceResolutionContext context) { // elementSource is already resolved; nothing to do. @@ -252,7 +268,12 @@ public abstract class AbstractPluralAttributeSourceImpl @Override public String inferInLineViewName() { - return container().getPath() + "." + pluralAttributeElement.getName(); + return getAttributeRole().getFullPath(); + } + + @Override + public CollectionIdSource getCollectionIdSource() { + return null; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractToOneAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractToOneAttributeSourceImpl.java index 9af4f64521..8589f04f75 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractToOneAttributeSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractToOneAttributeSourceImpl.java @@ -39,9 +39,9 @@ import org.hibernate.metamodel.source.spi.HibernateTypeSource; import org.hibernate.metamodel.source.spi.MappedByAssociationSource; import org.hibernate.metamodel.source.spi.MappingException; import org.hibernate.metamodel.source.spi.ToOneAttributeSource; +import org.hibernate.metamodel.spi.NaturalIdMutability; import org.hibernate.metamodel.spi.binding.AttributeBinding; -import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding; -import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; +import org.hibernate.metamodel.spi.binding.EmbeddedAttributeBinding; import org.hibernate.metamodel.spi.relational.TableSpecification; import org.hibernate.metamodel.spi.relational.Value; @@ -49,13 +49,13 @@ import org.hibernate.metamodel.spi.relational.Value; * @author Gail Badner */ public abstract class AbstractToOneAttributeSourceImpl extends AbstractHbmSourceNode implements ToOneAttributeSource{ - private final SingularAttributeBinding.NaturalIdMutability naturalIdMutability; + private final NaturalIdMutability naturalIdMutability; private final String propertyRef; private final Set ownedAssociationSources = new HashSet( ); AbstractToOneAttributeSourceImpl( MappingDocument sourceMappingDocument, - SingularAttributeBinding.NaturalIdMutability naturalIdMutability, + NaturalIdMutability naturalIdMutability, String propertyRef) { super( sourceMappingDocument ); this.naturalIdMutability = naturalIdMutability; @@ -68,7 +68,7 @@ public abstract class AbstractToOneAttributeSourceImpl extends AbstractHbmSource } @Override - public SingularAttributeBinding.NaturalIdMutability getNaturalIdMutability() { + public NaturalIdMutability getNaturalIdMutability() { return naturalIdMutability; } @@ -182,12 +182,12 @@ public abstract class AbstractToOneAttributeSourceImpl extends AbstractHbmSource final String entityName, final String tableName, final AttributeBinding referencedAttributeBinding) { - if ( CompositeAttributeBinding.class.isInstance( referencedAttributeBinding ) ) { - CompositeAttributeBinding compositeAttributeBinding = CompositeAttributeBinding.class.cast( + if ( EmbeddedAttributeBinding.class.isInstance( referencedAttributeBinding ) ) { + EmbeddedAttributeBinding embeddedAttributeBinding = EmbeddedAttributeBinding.class.cast( referencedAttributeBinding ); List result = new ArrayList(); - for ( final AttributeBinding attributeBinding : compositeAttributeBinding.attributeBindings() ) { + for ( final AttributeBinding attributeBinding : embeddedAttributeBinding.getEmbeddableBinding().attributeBindings() ) { result.addAll( getDefaultNamingStrategies( entityName, tableName, attributeBinding ) ); } return result; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ArraySourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ArraySourceImpl.java index 7b7ac32199..5eb00196b7 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ArraySourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ArraySourceImpl.java @@ -23,21 +23,20 @@ */ package org.hibernate.metamodel.source.internal.hbm; -import org.hibernate.AssertionFailure; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbArrayElement; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbListIndexElement; import org.hibernate.metamodel.source.spi.AttributeSourceContainer; -import org.hibernate.metamodel.source.spi.AttributeSourceResolutionContext; import org.hibernate.metamodel.source.spi.IndexedPluralAttributeSource; import org.hibernate.metamodel.source.spi.PluralAttributeIndexSource; -import org.hibernate.metamodel.source.spi.SequentialPluralAttributeIndexSource; +import org.hibernate.metamodel.source.spi.PluralAttributeSequentialIndexSource; +import org.hibernate.metamodel.spi.PluralAttributeNature; /** * @author Brett Meyer */ public class ArraySourceImpl extends AbstractPluralAttributeSourceImpl implements IndexedPluralAttributeSource { - private final SequentialPluralAttributeIndexSource indexSource; + private final PluralAttributeSequentialIndexSource indexSource; public ArraySourceImpl( MappingDocument sourceMappingDocument, @@ -46,20 +45,12 @@ public class ArraySourceImpl extends AbstractPluralAttributeSourceImpl implement super( sourceMappingDocument, arrayElement, container ); JaxbListIndexElement listIndexElement = arrayElement.getListIndex(); if ( listIndexElement == null ) { - this.indexSource = new SequentialPluralAttributeIndexSourceImpl( sourceMappingDocument(), arrayElement.getIndex() ); + this.indexSource = new PluralAttributeSequentialIndexSourceImpl( sourceMappingDocument(), arrayElement.getIndex() ); } else { - this.indexSource = new SequentialPluralAttributeIndexSourceImpl( sourceMappingDocument(), listIndexElement ); + this.indexSource = new PluralAttributeSequentialIndexSourceImpl( sourceMappingDocument(), listIndexElement ); } } - @Override - public PluralAttributeIndexSource resolvePluralAttributeIndexSource(AttributeSourceResolutionContext context) { - if ( indexSource == null ) { - throw new AssertionFailure( "Array index source should have been resolved already." ); - } - return indexSource; - } - @Override public PluralAttributeIndexSource getIndexSource() { return indexSource; @@ -76,7 +67,7 @@ public class ArraySourceImpl extends AbstractPluralAttributeSourceImpl implement * @see org.hibernate.metamodel.source.spi.PluralAttributeSource#getNature() */ @Override - public Nature getNature() { - return Nature.ARRAY; + public PluralAttributeNature getNature() { + return PluralAttributeNature.ARRAY; } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/BagSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/BagSourceImpl.java index e2ec36b65f..091670e194 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/BagSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/BagSourceImpl.java @@ -27,6 +27,7 @@ import org.hibernate.internal.util.StringHelper; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbBagElement; import org.hibernate.metamodel.source.spi.AttributeSourceContainer; import org.hibernate.metamodel.source.spi.Orderable; +import org.hibernate.metamodel.spi.PluralAttributeNature; /** * @author Steve Ebersole @@ -40,8 +41,8 @@ public class BagSourceImpl extends AbstractPluralAttributeSourceImpl implements } @Override - public Nature getNature() { - return Nature.BAG; + public PluralAttributeNature getNature() { + return PluralAttributeNature.BAG; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ComponentAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ComponentAttributeSourceImpl.java deleted file mode 100644 index ec14b3f4b4..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ComponentAttributeSourceImpl.java +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2012, 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.metamodel.source.internal.hbm; - -import java.util.ArrayList; -import java.util.List; - -import org.hibernate.EntityMode; -import org.hibernate.internal.util.StringHelper; -import org.hibernate.mapping.PropertyGeneration; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbAnyElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbArrayElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbBagElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbComponentElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbDynamicComponentElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbListElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbManyToOneElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbMapElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbOneToOneElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPrimitiveArrayElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPropertyElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbSetElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbTuplizerElement; -import org.hibernate.metamodel.source.spi.AttributeSource; -import org.hibernate.metamodel.source.spi.AttributeSourceContainer; -import org.hibernate.metamodel.source.spi.RelationalValueSource; -import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; - -/** - * @author Steve Ebersole - */ -class ComponentAttributeSourceImpl extends AbstractComponentAttributeSourceImpl { - public ComponentAttributeSourceImpl( - MappingDocument sourceMappingDocument, - JaxbComponentElement componentElement, - AttributeSourceContainer parentContainer, - String logicalTableName, - SingularAttributeBinding.NaturalIdMutability naturalIdMutability) { - super( sourceMappingDocument, componentElement, parentContainer, logicalTableName, naturalIdMutability ); - } - - protected JaxbComponentElement componentElement() { - return (JaxbComponentElement) super.componentSourceElement(); - } - - @Override - protected List buildAttributeSources() { - List attributeSources = new ArrayList(); - for(final JaxbPropertyElement element : componentElement().getProperty()){ - attributeSources.add( buildAttributeSource( element ) ); - } - for(final JaxbManyToOneElement element : componentElement().getManyToOne()){ - attributeSources.add( buildAttributeSource( element ) ); - } - for(final JaxbOneToOneElement element: componentElement().getOneToOne()){ - attributeSources.add( buildAttributeSource( element ) ); - } - for(final JaxbComponentElement element: componentElement().getComponent()){ - attributeSources.add( buildAttributeSource( element ) ); - } - for(final JaxbDynamicComponentElement element: componentElement().getDynamicComponent()){ - attributeSources.add( buildAttributeSource(element) ); - } - for(final JaxbAnyElement element: componentElement().getAny()){ - attributeSources.add( buildAttributeSource( element ) ); - } - for(final JaxbMapElement element: componentElement().getMap()){ - attributeSources.add( buildAttributeSource( element ) ); - } - for(final JaxbSetElement element: componentElement().getSet()){ - attributeSources.add( buildAttributeSource( element ) ); - } - for(final JaxbListElement element: componentElement().getList()){ - attributeSources.add( buildAttributeSource( element ) ); - } - for(final JaxbBagElement element: componentElement().getBag()){ - attributeSources.add( buildAttributeSource( element ) ); - } - for(final JaxbArrayElement element: componentElement().getArray()){ - attributeSources.add( buildAttributeSource( element ) ); - } - for(final JaxbPrimitiveArrayElement element: componentElement().getPrimitiveArray()){ - attributeSources.add( buildAttributeSource( element ) ); - } - return attributeSources; - } - - @Override - public String getParentReferenceAttributeName() { - return componentElement().getParent() == null ? null : componentElement().getParent().getName(); - } - - @Override - public String getExplicitTuplizerClassName() { - if ( componentElement().getTuplizer() == null ) { - return null; - } - final EntityMode entityMode = StringHelper.isEmpty( componentElement().getClazz() ) ? EntityMode.MAP : EntityMode.POJO; - for ( JaxbTuplizerElement tuplizerElement : componentElement().getTuplizer() ) { - if ( entityMode == EntityMode.parse( tuplizerElement.getEntityMode().value() ) ) { - return tuplizerElement.getClazz(); - } - } - return null; - } - - @Override - public PropertyGeneration getGeneration() { - // todo : is this correct here? - return null; - } - - @Override - public boolean isLazy() { - return componentElement().isLazy(); - } - - @Override - public boolean isIncludedInOptimisticLocking() { - return componentElement().isOptimisticLock(); - } - - @Override - public boolean areValuesIncludedInInsertByDefault() { - return componentElement().isInsert(); - } - - @Override - public boolean areValuesIncludedInUpdateByDefault() { - return componentElement().isUpdate(); - } - - @Override - public boolean areValuesNullableByDefault() { - return true; - } - - @Override - public List relationalValueSources() { - // none, they are defined on the simple sub-attributes - return null; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/CompositePluralAttributeElementSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/CompositePluralAttributeElementSourceImpl.java deleted file mode 100644 index e9363b8765..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/CompositePluralAttributeElementSourceImpl.java +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2011, 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.metamodel.source.internal.hbm; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Set; - -import org.hibernate.EntityMode; -import org.hibernate.cfg.NotYetImplementedException; -import org.hibernate.engine.spi.CascadeStyle; -import org.hibernate.internal.util.StringHelper; -import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbAnyElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbCompositeElementElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbManyToOneElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbNestedCompositeElementElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPropertyElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbTuplizerElement; -import org.hibernate.metamodel.source.spi.AttributeSource; -import org.hibernate.metamodel.source.spi.CompositePluralAttributeElementSource; -import org.hibernate.metamodel.source.spi.SingularAttributeSource; -import org.hibernate.metamodel.source.spi.ToolingHintSource; -import org.hibernate.metamodel.spi.LocalBindingContext; -import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; - -/** - * @author Steve Ebersole - * @author Gail Badner - */ -public class CompositePluralAttributeElementSourceImpl - extends AbstractHbmSourceNode - implements CompositePluralAttributeElementSource { - - private final JaxbCompositeElementElement compositeElement; - private final Set cascadeStyles; - private final List attributeSources; - - public CompositePluralAttributeElementSourceImpl( - MappingDocument mappingDocument, - JaxbCompositeElementElement compositeElement, - String cascadeString) { - super( mappingDocument ); - this.compositeElement = compositeElement; - this.cascadeStyles = Helper.interpretCascadeStyles( cascadeString, bindingContext() ); - this.attributeSources = buildAttributeSources( mappingDocument, compositeElement ); - } - - @Override - public Nature getNature() { - return Nature.AGGREGATE; - } - - @Override - public JavaTypeDescriptor getTypeDescriptor() { - return bindingContext().typeDescriptor( compositeElement.getClazz() ); - } - - @Override - public String getParentReferenceAttributeName() { - return compositeElement.getParent() != null - ? compositeElement.getParent().getName() - : null; - } - - @Override - public String getExplicitTuplizerClassName() { - if ( compositeElement.getTuplizer() == null ) { - return null; - } - final EntityMode entityMode = StringHelper.isEmpty( compositeElement.getClazz() ) ? EntityMode.MAP : EntityMode.POJO; - for ( JaxbTuplizerElement tuplizerElement : compositeElement.getTuplizer() ) { - if ( entityMode == EntityMode.parse( tuplizerElement.getEntityMode().value() ) ) { - return tuplizerElement.getClazz(); - } - } - return null; - } - - @Override - public String getPath() { - // todo : implementing this requires passing in the collection source and being able to resolve the collection's role - return null; - } - - @Override - public List attributeSources() { - return attributeSources; - } - - private static List buildAttributeSources( - MappingDocument mappingDocument, - JaxbCompositeElementElement compositeElement) { - List attributeSources = new ArrayList(); - for( final JaxbAnyElement element : compositeElement.getAny() ) { - attributeSources.add( buildAttributeSource( mappingDocument, element ) ); - } - for( final JaxbManyToOneElement element : compositeElement.getManyToOne() ) { - attributeSources.add( buildAttributeSource( mappingDocument, element ) ); - } - for( final JaxbNestedCompositeElementElement element : compositeElement.getNestedCompositeElement() ) { - attributeSources.add( buildAttributeSource( mappingDocument, element ) ); - } - for( final JaxbPropertyElement element : compositeElement.getProperty() ) { - attributeSources.add( buildAttributeSource( mappingDocument, element ) ); - } - return attributeSources; - } - - @Override - public LocalBindingContext getLocalBindingContext() { - return bindingContext(); - } - - @Override - public Set getCascadeStyles() { - return cascadeStyles; - } - - private static AttributeSource buildAttributeSource( - MappingDocument sourceMappingDocument, - JaxbAnyElement attributeElement) { - // todo : implement - throw new NotYetImplementedException(); - } - - private static SingularAttributeSource buildAttributeSource( - MappingDocument sourceMappingDocument, - JaxbPropertyElement attributeElement) { - return new PropertyAttributeSourceImpl( - sourceMappingDocument, - attributeElement, - null, - SingularAttributeBinding.NaturalIdMutability.NOT_NATURAL_ID - ); - } - - private static AttributeSource buildAttributeSource( - MappingDocument sourceMappingDocument, - JaxbManyToOneElement attributeElement) { - return new ManyToOneAttributeSourceImpl( - sourceMappingDocument, - JaxbManyToOneElement.class.cast( attributeElement ), - null, - SingularAttributeBinding.NaturalIdMutability.NOT_NATURAL_ID - ); - } - - private static AttributeSource buildAttributeSource( - MappingDocument sourceMappingDocument, - JaxbNestedCompositeElementElement attributeElement) { - // todo : implement - throw new NotYetImplementedException( "Nested composite element is not supported yet."); - } - - @Override - public Collection getToolingHintSources() { - return compositeElement.getMeta(); - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/CompositePluralAttributeIndexSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/CompositePluralAttributeIndexSourceImpl.java deleted file mode 100644 index d5781ed426..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/CompositePluralAttributeIndexSourceImpl.java +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2013, Red Hat Inc. or third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Inc. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License, as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package org.hibernate.metamodel.source.internal.hbm; - -import java.util.ArrayList; -import java.util.List; - -import org.hibernate.metamodel.internal.binder.Binder; -import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbCompositeIndexElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbCompositeMapKeyElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbKeyManyToOneElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbKeyPropertyElement; -import org.hibernate.metamodel.source.spi.AttributeSource; -import org.hibernate.metamodel.source.spi.CompositePluralAttributeIndexSource; -import org.hibernate.metamodel.source.spi.HibernateTypeSource; -import org.hibernate.metamodel.source.spi.RelationalValueSource; -import org.hibernate.metamodel.spi.LocalBindingContext; -import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding; -import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; - -/** - * @author Gail Badner - */ -public class CompositePluralAttributeIndexSourceImpl - extends AbstractHbmSourceNode - implements CompositePluralAttributeIndexSource { - - private final String className; - private final List attributeSources; - - public CompositePluralAttributeIndexSourceImpl( - MappingDocument mappingDocument, - JaxbCompositeIndexElement compositeIndexElement) { - this( - mappingDocument, - compositeIndexElement.getClazz(), - compositeIndexElement.getKeyProperty(), - compositeIndexElement.getKeyManyToOne() - ); - } - - public CompositePluralAttributeIndexSourceImpl( - MappingDocument mappingDocument, - JaxbCompositeMapKeyElement compositeMapKeyElement) { - this( - mappingDocument, - compositeMapKeyElement.getClazz(), - compositeMapKeyElement.getKeyProperty(), - compositeMapKeyElement.getKeyManyToOne() - ); - } - - private CompositePluralAttributeIndexSourceImpl( - MappingDocument mappingDocument, - String className, - List keyPropertyElements, - List keyManyToOneElements) { - super( mappingDocument ); - this.className = bindingContext().qualifyClassName( className ); - this.attributeSources = buildAttributeSources( - mappingDocument, - keyPropertyElements, - keyManyToOneElements - ); - } - - @Override - public PluralAttributeIndexBinding.Nature getNature() { - return PluralAttributeIndexBinding.Nature.AGGREGATE; - } - - @Override - public List getDefaultNamingStrategies() { - return null; //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public HibernateTypeSource getTypeInformation() { - return null; //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public boolean isReferencedEntityAttribute() { - return false; //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public JavaTypeDescriptor getTypeDescriptor() { - return bindingContext().typeDescriptor( className ); - } - - @Override - public String getPath() { - // todo : implementing this requires passing in the collection source and being able to resolve the collection's role - return null; - } - - @Override - public List attributeSources() { - return attributeSources; - } - - private static List buildAttributeSources( - MappingDocument mappingDocument, - List keyPropertyElements, - List keyManyToOneElements) { - List attributeSources = new ArrayList(); - for ( JaxbKeyPropertyElement keyProperty : keyPropertyElements ){ - attributeSources.add( - new KeyAttributeSourceImpl( - mappingDocument, - keyProperty, - SingularAttributeBinding.NaturalIdMutability.NOT_NATURAL_ID - ) - ); - } - for (JaxbKeyManyToOneElement keyManyToOne :keyManyToOneElements ){ - attributeSources.add( - new KeyManyToOneSourceImpl( - mappingDocument, - keyManyToOne, - SingularAttributeBinding.NaturalIdMutability.NOT_NATURAL_ID - ) - ); - } - return attributeSources; - } - - @Override - public LocalBindingContext getLocalBindingContext() { - return bindingContext(); - } - - @Override - public List relationalValueSources() { - return null; - } - - @Override - public boolean areValuesIncludedInInsertByDefault() { - return true; - } - - @Override - public boolean areValuesIncludedInUpdateByDefault() { - return false; - } - - @Override - public boolean areValuesNullableByDefault() { - return true; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/EmbeddableJaxbSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/EmbeddableJaxbSource.java new file mode 100644 index 0000000000..a8e8c6a0b4 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/EmbeddableJaxbSource.java @@ -0,0 +1,95 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2014, 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.metamodel.source.internal.hbm; + +import java.util.List; + +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbAnyElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbArrayElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbBagElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbComponentElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbDynamicComponentElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbKeyManyToOneElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbKeyPropertyElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbListElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbManyToOneElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbMapElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbNestedCompositeElementElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbOneToOneElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPrimitiveArrayElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPropertiesElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPropertyElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbSetElement; + +/** + * Describes the JAXB source (HBM) for embeddable (composite) information. The + * HBM XML schema unfortunately did not define these consistently between + * {@code } and {@code }, so this contract unifies + * access to this information. + * + * @author Steve Ebersole + */ +public interface EmbeddableJaxbSource { + public String getClazz(); + + public String findParent(); + public String findTuplizer(); + + // todo : ultimately would be nice to remove the distinction between: + // * getKeyPropertyElementList() / getPropertyElementList() + // * getKeyManyToOneElementList() / getManyToOneElementList() + // the difference is really a matter of the "container", not the attribute + + public List getKeyPropertyElementList(); + + public List getKeyManyToOneElementList(); + + public List getPropertyElementList(); + + public List getManyToOneElementList(); + + public List getOneToOneElementList(); + + public List getComponentElementList(); + + public List getNestedCompositeElementList(); + + public List getDynamicComponentElementList(); + + public List getPropertiesElementList(); + + public List getAnyElementList(); + + public List getMapElementList(); + + public List getSetElementList(); + + public List getListElementList(); + + public List getBagElementList(); + + public List getArrayElementList(); + + public List getPrimitiveArrayElementList(); +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractComponentAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/EmbeddableSourceImpl.java similarity index 50% rename from hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractComponentAttributeSourceImpl.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/EmbeddableSourceImpl.java index cbaf28ded1..bdc6b11538 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractComponentAttributeSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/EmbeddableSourceImpl.java @@ -1,7 +1,7 @@ /* * Hibernate, Relational Persistence for Idiomatic Java * - * Copyright (c) 2012, Red Hat Inc. or third-party contributors as + * Copyright (c) 2014, 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. @@ -23,73 +23,188 @@ */ package org.hibernate.metamodel.source.internal.hbm; -import java.util.Collection; +import java.util.ArrayList; import java.util.List; import org.hibernate.cfg.NotYetImplementedException; import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; -import org.hibernate.metamodel.source.internal.jaxb.hbm.ComponentSourceElement; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbAnyElement; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbArrayElement; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbBagElement; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbComponentElement; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbDynamicComponentElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbKeyManyToOneElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbKeyPropertyElement; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbListElement; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbManyToManyElement; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbManyToOneElement; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbMapElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbNestedCompositeElementElement; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbOneToManyElement; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbOneToOneElement; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPrimitiveArrayElement; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPropertyElement; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbSetElement; import org.hibernate.metamodel.source.spi.AttributeSource; -import org.hibernate.metamodel.source.spi.AttributeSourceContainer; -import org.hibernate.metamodel.source.spi.ComponentAttributeSource; -import org.hibernate.metamodel.source.spi.HibernateTypeSource; +import org.hibernate.metamodel.source.spi.EmbeddableSource; import org.hibernate.metamodel.source.spi.SingularAttributeSource; -import org.hibernate.metamodel.source.spi.ToolingHintSource; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; import org.hibernate.metamodel.spi.LocalBindingContext; -import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; +import org.hibernate.metamodel.spi.NaturalIdMutability; /** * @author Steve Ebersole */ -public abstract class AbstractComponentAttributeSourceImpl extends AbstractHbmSourceNode implements ComponentAttributeSource { - private final ComponentSourceElement componentSourceElement; - private final AttributeSourceContainer parentContainer; - private final List subAttributeSources; - private final SingularAttributeBinding.NaturalIdMutability naturalIdMutability; - private final JavaTypeDescriptor componentTypeDescriptor; - private final String logicalTableName; - private final String path; +public class EmbeddableSourceImpl extends AbstractHbmSourceNode implements EmbeddableSource { + private final EmbeddableJaxbSource embeddableSource; + private final JavaTypeDescriptor typeDescriptor; - protected AbstractComponentAttributeSourceImpl( - MappingDocument sourceMappingDocument, - ComponentSourceElement componentSourceElement, - AttributeSourceContainer parentContainer, + private final AttributeRole attributeRoleBase; + private final AttributePath attributePathBase; + + private final String logicalTableName; + private final NaturalIdMutability naturalIdMutability; + + private final List attributeSources; + + public EmbeddableSourceImpl( + MappingDocument mappingDocument, + AttributeRole attributeRoleBase, + AttributePath attributePathBase, + EmbeddableJaxbSource embeddableJaxbSource, String logicalTableName, - SingularAttributeBinding.NaturalIdMutability naturalIdMutability) { - super( sourceMappingDocument ); - this.componentSourceElement = componentSourceElement; - this.parentContainer = parentContainer; - this.naturalIdMutability = naturalIdMutability; - this.componentTypeDescriptor = typeDescriptor( componentSourceElement.getClazz() ); + NaturalIdMutability naturalIdMutability) { + super( mappingDocument ); + this.attributeRoleBase = attributeRoleBase; + this.attributePathBase = attributePathBase; + this.embeddableSource = embeddableJaxbSource; this.logicalTableName = logicalTableName; - this.path = parentContainer.getPath() + '.' + componentSourceElement.getName(); - - this.subAttributeSources = buildAttributeSources(); + this.naturalIdMutability = naturalIdMutability; + + this.typeDescriptor = typeDescriptor( embeddableJaxbSource.getClazz() ); + + this.attributeSources = buildAttributeSources( embeddableJaxbSource, this ); } @Override - public String getContainingTableName() { - return logicalTableName; + public JavaTypeDescriptor getTypeDescriptor() { + return typeDescriptor; + } + + @Override + public String getParentReferenceAttributeName() { + return embeddableSource.findParent(); + } + + @Override + public String getExplicitTuplizerClassName() { + return embeddableSource.findTuplizer(); + } + + @Override + public AttributePath getAttributePathBase() { + return attributePathBase; + } + + @Override + public AttributeRole getAttributeRoleBase() { + return attributeRoleBase; + } + + @Override + public List attributeSources() { + return attributeSources; + } + + @Override + public LocalBindingContext getLocalBindingContext() { + return bindingContext(); + } + + + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // Attribute building + + protected static List buildAttributeSources( + EmbeddableJaxbSource container, + EmbeddableSourceImpl embeddableSource) { + final List attributeSources = new ArrayList(); + + for ( JaxbPropertyElement element : container.getPropertyElementList() ) { + attributeSources.add( embeddableSource.buildAttributeSource( element ) ); + } + + for ( JaxbManyToOneElement element : container.getManyToOneElementList() ) { + attributeSources.add( embeddableSource.buildAttributeSource( element ) ); + } + + for ( JaxbOneToOneElement element: container.getOneToOneElementList() ) { + attributeSources.add( embeddableSource.buildAttributeSource( element ) ); + } + + for ( JaxbComponentElement element: container.getComponentElementList() ) { + attributeSources.add( embeddableSource.buildAttributeSource( element ) ); + } + + for ( JaxbNestedCompositeElementElement element: container.getNestedCompositeElementList() ) { + attributeSources.add( embeddableSource.buildAttributeSource( element ) ); + } + + for ( JaxbDynamicComponentElement element: container.getDynamicComponentElementList() ) { + attributeSources.add( embeddableSource.buildAttributeSource(element) ); + } + + for ( JaxbAnyElement element: container.getAnyElementList() ) { + attributeSources.add( embeddableSource.buildAttributeSource( element ) ); + } + + for ( JaxbMapElement element: container.getMapElementList() ) { + attributeSources.add( embeddableSource.buildAttributeSource( element ) ); + } + + for ( JaxbSetElement element: container.getSetElementList() ) { + attributeSources.add( embeddableSource.buildAttributeSource( element ) ); + } + for ( JaxbListElement element: container.getListElementList() ) { + attributeSources.add( embeddableSource.buildAttributeSource( element ) ); + } + + for ( JaxbBagElement element: container.getBagElementList() ) { + attributeSources.add( embeddableSource.buildAttributeSource( element ) ); + } + + for ( JaxbArrayElement element: container.getArrayElementList() ) { + attributeSources.add( embeddableSource.buildAttributeSource( element ) ); + } + + for ( JaxbPrimitiveArrayElement element: container.getPrimitiveArrayElementList() ) { + attributeSources.add( embeddableSource.buildAttributeSource( element ) ); + } + + for ( JaxbKeyPropertyElement element : container.getKeyPropertyElementList() ) { + attributeSources.add( embeddableSource.buildAttributeSource( element ) ); + } + + for ( JaxbKeyManyToOneElement element : container.getKeyManyToOneElementList() ) { + attributeSources.add( embeddableSource.buildAttributeSource( element ) ); + } + + return attributeSources; + } + + private AttributeSource buildAttributeSource(JaxbKeyPropertyElement element) { + return new IdentifierKeyAttributeSourceImpl( sourceMappingDocument(), this, element ); + } + + private AttributeSource buildAttributeSource(JaxbKeyManyToOneElement element) { + return new IdentifierKeyManyToOneSourceImpl( sourceMappingDocument(), this, element ); } - protected abstract List buildAttributeSources(); protected SingularAttributeSource buildAttributeSource(JaxbPropertyElement attributeElement) { return new PropertyAttributeSourceImpl( sourceMappingDocument(), + this, attributeElement, logicalTableName, naturalIdMutability @@ -97,21 +212,29 @@ public abstract class AbstractComponentAttributeSourceImpl extends AbstractHbmSo } protected AttributeSource buildAttributeSource(JaxbComponentElement attributeElement) { - return new ComponentAttributeSourceImpl( + return new EmbeddedAttributeSourceImpl( sourceMappingDocument(), - attributeElement, this, - logicalTableName, - naturalIdMutability + attributeElement, + naturalIdMutability, + logicalTableName ); } - protected AttributeSource buildAttributeSource(JaxbDynamicComponentElement attributeElement){ + + private AttributeSource buildAttributeSource(JaxbNestedCompositeElementElement element) { // todo : implement throw new NotYetImplementedException(); } + + protected AttributeSource buildAttributeSource(JaxbDynamicComponentElement attributeElement) { + // todo : implement + throw new NotYetImplementedException(); + } + protected AttributeSource buildAttributeSource(JaxbManyToOneElement attributeElement) { return new ManyToOneAttributeSourceImpl( sourceMappingDocument(), + this, attributeElement, logicalTableName, naturalIdMutability @@ -121,6 +244,7 @@ public abstract class AbstractComponentAttributeSourceImpl extends AbstractHbmSo protected AttributeSource buildAttributeSource(JaxbOneToOneElement attributeElement) { return new OneToOneAttributeSourceImpl( sourceMappingDocument(), + this, attributeElement, logicalTableName, naturalIdMutability @@ -141,110 +265,44 @@ public abstract class AbstractComponentAttributeSourceImpl extends AbstractHbmSo // todo : implement throw new NotYetImplementedException(); } - // todo duplicated with org.hibernate.metamodel.internal.source.hbm.AbstractEntitySourceImpl - protected AttributeSource buildAttributeSource(JaxbMapElement attributeElement){ + + protected AttributeSource buildAttributeSource(JaxbMapElement attributeElement) { return new MapSourceImpl( sourceMappingDocument(), attributeElement, - parentContainer + this ); } protected AttributeSource buildAttributeSource(JaxbSetElement attributeElement) { return new SetSourceImpl( sourceMappingDocument(), attributeElement, - parentContainer + this ); } protected AttributeSource buildAttributeSource(JaxbListElement attributeElement) { return new ListSourceImpl( sourceMappingDocument(), attributeElement, - parentContainer + this ); } protected AttributeSource buildAttributeSource(JaxbBagElement attributeElement) { return new BagSourceImpl( sourceMappingDocument(), attributeElement, - parentContainer + this ); } protected AttributeSource buildAttributeSource(JaxbArrayElement attributeElement) { return new ArraySourceImpl( sourceMappingDocument(), attributeElement, - parentContainer + this ); } protected AttributeSource buildAttributeSource(JaxbPrimitiveArrayElement attributeElement) { // todo : implement throw new NotYetImplementedException(); } - - - protected ComponentSourceElement componentSourceElement() { - return componentSourceElement; - } - - @Override - public JavaTypeDescriptor getTypeDescriptor() { - return componentTypeDescriptor; - } - - @Override - public String getPath() { - return path; - } - - @Override - public LocalBindingContext getLocalBindingContext() { - return parentContainer.getLocalBindingContext(); - } - - @Override - public List attributeSources() { - return subAttributeSources; - } - - @Override - public boolean isVirtualAttribute() { - return false; - } - - @Override - public Nature getNature() { - return Nature.COMPOSITE; - } - - @Override - public HibernateTypeSource getTypeInformation() { - // does not support type information. - return null; - } - - @Override - public String getName() { - return componentSourceElement.getName(); - } - - @Override - public boolean isSingular() { - return true; - } - - @Override - public String getPropertyAccessorName() { - return componentSourceElement.getAccess(); - } - - @Override - public SingularAttributeBinding.NaturalIdMutability getNaturalIdMutability() { - return naturalIdMutability; - } - - @Override - public Collection getToolingHintSources() { - return componentSourceElement.getMeta(); - } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/EmbeddedAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/EmbeddedAttributeSourceImpl.java new file mode 100644 index 0000000000..eeb7b2b436 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/EmbeddedAttributeSourceImpl.java @@ -0,0 +1,211 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2012, 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.metamodel.source.internal.hbm; + +import java.util.List; + +import org.hibernate.EntityMode; +import org.hibernate.internal.util.StringHelper; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbAnyElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbArrayElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbBagElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbComponentElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbDynamicComponentElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbListElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbManyToOneElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbMapElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbOneToOneElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPrimitiveArrayElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPropertiesElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPropertyElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbSetElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbTuplizerElement; +import org.hibernate.metamodel.source.spi.AttributeSourceContainer; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; +import org.hibernate.metamodel.spi.NaturalIdMutability; + +/** + * The source information for a singular attribute whose type is composite + * (embedded in JPA terms). + * + * @author Steve Ebersole + */ +class EmbeddedAttributeSourceImpl extends AbstractEmbeddedAttributeSourceImpl { + public EmbeddedAttributeSourceImpl( + MappingDocument sourceMappingDocument, + AttributeSourceContainer parentContainer, + JaxbComponentElement jaxbComponentElement, + NaturalIdMutability naturalIdMutability, + String logicalTableName) { + super( + sourceMappingDocument, + parentContainer, + parentContainer.getAttributeRoleBase().append( jaxbComponentElement.getName() ), + parentContainer.getAttributePathBase().append( jaxbComponentElement.getName() ), + jaxbComponentElement, + new EmbeddableJaxbSourceImpl( jaxbComponentElement ), + naturalIdMutability, + logicalTableName + ); + } + + @Override + protected JaxbComponentElement jaxbComponentSourceElement() { + return (JaxbComponentElement) super.jaxbComponentSourceElement(); + } + + @Override + public boolean isLazy() { + return jaxbComponentSourceElement().isLazy(); + } + + @Override + public AttributePath getAttributePath() { + return getEmbeddableSource().getAttributePathBase(); + } + + @Override + public AttributeRole getAttributeRole() { + return getEmbeddableSource().getAttributeRoleBase(); + } + + @Override + public boolean isIncludedInOptimisticLocking() { + return jaxbComponentSourceElement().isOptimisticLock(); + } + + @Override + public boolean areValuesIncludedInInsertByDefault() { + return jaxbComponentSourceElement().isInsert(); + } + + @Override + public boolean areValuesIncludedInUpdateByDefault() { + return jaxbComponentSourceElement().isUpdate(); + } + + public static class EmbeddableJaxbSourceImpl extends AbstractEmbeddableJaxbSource { + private final JaxbComponentElement jaxbComponentElement; + + public EmbeddableJaxbSourceImpl(JaxbComponentElement jaxbComponentElement) { + this.jaxbComponentElement = jaxbComponentElement; + } + + @Override + public String getClazz() { + return jaxbComponentElement.getClazz(); + } + + @Override + public String findParent() { + return jaxbComponentElement.getParent() == null + ? null + : jaxbComponentElement.getParent().getName(); + } + + @Override + public String findTuplizer() { + if ( jaxbComponentElement.getTuplizer() == null ) { + return null; + } + + final EntityMode entityMode = StringHelper.isEmpty( jaxbComponentElement.getClazz() ) + ? EntityMode.MAP + : EntityMode.POJO; + + for ( JaxbTuplizerElement tuplizerElement : jaxbComponentElement.getTuplizer() ) { + if ( entityMode == EntityMode.parse( tuplizerElement.getEntityMode().value() ) ) { + return tuplizerElement.getClazz(); + } + } + return null; + } + + @Override + public List getPropertyElementList() { + return jaxbComponentElement.getProperty(); + } + + @Override + public List getManyToOneElementList() { + return jaxbComponentElement.getManyToOne(); + } + + @Override + public List getOneToOneElementList() { + return jaxbComponentElement.getOneToOne(); + } + + @Override + public List getComponentElementList() { + return jaxbComponentElement.getComponent(); + } + + @Override + public List getDynamicComponentElementList() { + return jaxbComponentElement.getDynamicComponent(); + } + + @Override + public List getPropertiesElementList() { + return jaxbComponentElement.getProperties(); + } + + @Override + public List getAnyElementList() { + return jaxbComponentElement.getAny(); + } + + @Override + public List getMapElementList() { + return jaxbComponentElement.getMap(); + } + + @Override + public List getSetElementList() { + return jaxbComponentElement.getSet(); + } + + @Override + public List getListElementList() { + return jaxbComponentElement.getList(); + } + + @Override + public List getBagElementList() { + return jaxbComponentElement.getBag(); + } + + @Override + public List getArrayElementList() { + return jaxbComponentElement.getArray(); + } + + @Override + public List getPrimitiveArrayElementList() { + return jaxbComponentElement.getPrimitiveArray(); + } + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/EntityHierarchySourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/EntityHierarchySourceImpl.java index ec7c3e93d9..9c6976bec1 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/EntityHierarchySourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/EntityHierarchySourceImpl.java @@ -32,7 +32,6 @@ import org.hibernate.TruthValue; import org.hibernate.engine.OptimisticLockStyle; import org.hibernate.id.EntityIdentifierNature; import org.hibernate.internal.util.StringHelper; -import org.hibernate.mapping.PropertyGeneration; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbClassElement; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbCompositeIdElement; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbDiscriminatorElement; @@ -41,9 +40,8 @@ import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbKeyPropertyElement; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbMultiTenancyElement; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPolymorphismAttribute; import org.hibernate.metamodel.source.spi.AggregatedCompositeIdentifierSource; -import org.hibernate.metamodel.source.spi.AttributeSource; -import org.hibernate.metamodel.source.spi.ComponentAttributeSource; import org.hibernate.metamodel.source.spi.DiscriminatorSource; +import org.hibernate.metamodel.source.spi.EmbeddedAttributeSource; import org.hibernate.metamodel.source.spi.EntityHierarchySource; import org.hibernate.metamodel.source.spi.EntitySource; import org.hibernate.metamodel.source.spi.IdentifierSource; @@ -56,10 +54,12 @@ import org.hibernate.metamodel.source.spi.SingularAttributeSource; import org.hibernate.metamodel.source.spi.SizeSource; import org.hibernate.metamodel.source.spi.ToolingHintSource; import org.hibernate.metamodel.source.spi.VersionAttributeSource; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; +import org.hibernate.metamodel.spi.NaturalIdMutability; import org.hibernate.metamodel.spi.binding.Caching; import org.hibernate.metamodel.spi.binding.IdentifierGeneratorDefinition; import org.hibernate.metamodel.spi.binding.InheritanceType; -import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; /** * @author Steve Ebersole @@ -74,7 +74,7 @@ public class EntityHierarchySourceImpl implements EntityHierarchySource { this.rootEntitySource = rootEntitySource; this.rootEntitySource.injectHierarchy( this ); - this.caching = Helper.createCaching( entityElement().getCache(), getEntityName() ); + this.caching = Helper.createCaching( entityElement().getCache() ); this.naturalIdCaching = Helper.createNaturalIdCaching( rootEntitySource.entityElement().getNaturalIdCache() ); @@ -147,12 +147,14 @@ public class EntityHierarchySourceImpl implements EntityHierarchySource { if ( entityElement().getVersion() != null ) { return new VersionAttributeSourceImpl( rootEntitySource.sourceMappingDocument(), + rootEntitySource, entityElement().getVersion() ); } else if ( entityElement().getTimestamp() != null ) { return new TimestampAttributeSourceImpl( rootEntitySource.sourceMappingDocument(), + rootEntitySource, entityElement().getTimestamp() ); } @@ -339,7 +341,7 @@ public class EntityHierarchySourceImpl implements EntityHierarchySource { private class SimpleIdentifierSourceImpl implements SimpleIdentifierSource { @Override public SingularAttributeSource getIdentifierAttributeSource() { - return new SingularIdentifierAttributeSourceImpl( sourceMappingDocument(), entityElement().getId() ); + return new SingularIdentifierAttributeSourceImpl( sourceMappingDocument(), rootEntitySource, entityElement().getId() ); } @Override @@ -388,11 +390,11 @@ public class EntityHierarchySourceImpl implements EntityHierarchySource { } private class AggregatedCompositeIdentifierSourceImpl implements AggregatedCompositeIdentifierSource { - private final CompositeIdentifierComponentAttributeSourceImpl componentAttributeSource - = new CompositeIdentifierComponentAttributeSourceImpl(); + private final CompositeIdentifierEmbeddedAttributeSourceImpl componentAttributeSource + = new CompositeIdentifierEmbeddedAttributeSourceImpl(); @Override - public ComponentAttributeSource getIdentifierAttributeSource() { + public EmbeddedAttributeSource getIdentifierAttributeSource() { return componentAttributeSource; } @@ -447,56 +449,34 @@ public class EntityHierarchySourceImpl implements EntityHierarchySource { } } - private class CompositeIdentifierComponentAttributeSourceImpl extends AbstractComponentAttributeSourceImpl { - protected CompositeIdentifierComponentAttributeSourceImpl() { + private class CompositeIdentifierEmbeddedAttributeSourceImpl extends AbstractEmbeddedAttributeSourceImpl { + private final List keyPropertyElementList; + private final List keyManyToOneElementList; + + protected CompositeIdentifierEmbeddedAttributeSourceImpl() { super( EntityHierarchySourceImpl.this.sourceMappingDocument(), - entityElement().getCompositeId(), rootEntitySource, - null, - SingularAttributeBinding.NaturalIdMutability.NOT_NATURAL_ID + rootEntitySource.getAttributeRoleBase().append( "id" ), + rootEntitySource.getAttributePathBase().append( "id" ), + entityElement().getCompositeId(), + new EmbeddableJaxbSourceImpl( entityElement().getCompositeId() ), + NaturalIdMutability.NOT_NATURAL_ID, + null ); - } - protected JaxbCompositeIdElement compositeIdElement() { - return (JaxbCompositeIdElement) componentSourceElement(); - } + this.keyPropertyElementList = new ArrayList(); + this.keyManyToOneElementList = new ArrayList(); - @Override - protected List buildAttributeSources() { - List attributeSources = new ArrayList(); - final JaxbCompositeIdElement compositeId = entityElement().getCompositeId(); - final List list = compositeId.getKeyPropertyOrKeyManyToOne(); - for ( final Object obj : list ) { + final JaxbCompositeIdElement compositeIdElement = entityElement().getCompositeId(); + for ( final Object obj : compositeIdElement.getKeyPropertyOrKeyManyToOne() ) { if ( JaxbKeyPropertyElement.class.isInstance( obj ) ) { - JaxbKeyPropertyElement key = JaxbKeyPropertyElement.class.cast( obj ); - attributeSources.add( new IdentifierKeyAttributeSourceImpl( sourceMappingDocument(), key ) ); + keyPropertyElementList.add( JaxbKeyPropertyElement.class.cast( obj ) ); } - if ( JaxbKeyManyToOneElement.class.isInstance( obj ) ) { - JaxbKeyManyToOneElement key = JaxbKeyManyToOneElement.class.cast( obj ); - attributeSources.add( new IdentifierKeyManyToOneSourceImpl( sourceMappingDocument(), key ) ); + else if ( JaxbKeyManyToOneElement.class.isInstance( obj ) ) { + keyManyToOneElementList.add( JaxbKeyManyToOneElement.class.cast( obj ) ); } } - return attributeSources; - } - - - @Override - public String getParentReferenceAttributeName() { - // composite-id cannot name parent - return null; - } - - @Override - public String getExplicitTuplizerClassName() { - // composite-id cannot name tuplizer - return null; - } - - @Override - public PropertyGeneration getGeneration() { - // identifiers have implicit generation - return null; } @Override @@ -505,13 +485,18 @@ public class EntityHierarchySourceImpl implements EntityHierarchySource { } @Override - public boolean isIncludedInOptimisticLocking() { - return false; + public AttributePath getAttributePath() { + return getEmbeddableSource().getAttributePathBase(); } @Override - public List relationalValueSources() { - return null; + public AttributeRole getAttributeRole() { + return getEmbeddableSource().getAttributeRoleBase(); + } + + @Override + public boolean isIncludedInOptimisticLocking() { + return false; } @Override @@ -530,6 +515,7 @@ public class EntityHierarchySourceImpl implements EntityHierarchySource { } } + private class NonAggregatedCompositeIdentifierSourceImpl implements NonAggregatedCompositeIdentifierSource { @Override public Class getLookupIdClass() { @@ -549,11 +535,23 @@ public class EntityHierarchySourceImpl implements EntityHierarchySource { for ( final Object obj : list ) { if ( JaxbKeyPropertyElement.class.isInstance( obj ) ) { JaxbKeyPropertyElement key = JaxbKeyPropertyElement.class.cast( obj ); - attributeSources.add( new IdentifierKeyAttributeSourceImpl( sourceMappingDocument(), key ) ); + attributeSources.add( + new IdentifierKeyAttributeSourceImpl( + sourceMappingDocument(), + rootEntitySource, + key + ) + ); } if ( JaxbKeyManyToOneElement.class.isInstance( obj ) ) { JaxbKeyManyToOneElement key = JaxbKeyManyToOneElement.class.cast( obj ); - attributeSources.add( new IdentifierKeyManyToOneSourceImpl( sourceMappingDocument(), key ) ); + attributeSources.add( + new IdentifierKeyManyToOneSourceImpl( + sourceMappingDocument(), + rootEntitySource, + key + ) + ); } } @@ -601,6 +599,55 @@ public class EntityHierarchySourceImpl implements EntityHierarchySource { } } + public static class EmbeddableJaxbSourceImpl extends AbstractEmbeddableJaxbSource { + private final JaxbCompositeIdElement compositeIdElement; + + private final List keyPropertyElementList; + private final List keyManyToOneElementList; + + public EmbeddableJaxbSourceImpl(JaxbCompositeIdElement compositeIdElement) { + this.compositeIdElement = compositeIdElement; + + this.keyPropertyElementList = new ArrayList(); + this.keyManyToOneElementList = new ArrayList(); + + for ( final Object obj : compositeIdElement.getKeyPropertyOrKeyManyToOne() ) { + if ( JaxbKeyPropertyElement.class.isInstance( obj ) ) { + keyPropertyElementList.add( JaxbKeyPropertyElement.class.cast( obj ) ); + } + else if ( JaxbKeyManyToOneElement.class.isInstance( obj ) ) { + keyManyToOneElementList.add( JaxbKeyManyToOneElement.class.cast( obj ) ); + } + } + } + + @Override + public String getClazz() { + return compositeIdElement.getClazz(); + } + + @Override + public String findParent() { + return null; + } + + @Override + public String findTuplizer() { + return null; + } + + @Override + public List getKeyPropertyElementList() { + return keyPropertyElementList; + } + + @Override + public List getKeyManyToOneElementList() { + return keyManyToOneElementList; + } + + } + private Class determineJpaIdClass() { // this would be a defined with mapped="false" final JaxbCompositeIdElement compositeId = entityElement().getCompositeId(); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/Helper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/Helper.java index b3329894c1..9b8e3570c9 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/Helper.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/Helper.java @@ -62,16 +62,12 @@ import org.hibernate.metamodel.spi.binding.Caching; import org.hibernate.metamodel.spi.binding.CustomSQL; import org.hibernate.metamodel.spi.binding.InheritanceType; import org.hibernate.metamodel.spi.binding.MetaAttribute; -import org.hibernate.metamodel.spi.relational.Identifier; -import org.hibernate.metamodel.spi.relational.Schema; /** - * A helper for dealing with * @author Steve Ebersole * @author Gail Badner */ public class Helper { - private static final String NATURAL_ID_CACHE_SUFFIX = "##NaturalId"; public static final HibernateTypeSource TO_ONE_ATTRIBUTE_TYPE_SOURCE = new HibernateTypeSource() { @Override public String getName() { @@ -168,16 +164,22 @@ public class Helper { : qualifyIfNeeded( entityElement.getName(), unqualifiedClassPackage ); } - public static Caching createCaching(final JaxbCacheElement cacheElement, final String defaultRegionName) { + public static Caching createCaching(JaxbCacheElement cacheElement) { if ( cacheElement == null ) { // I'd really rather this be UNKNOWN, but the annotation version resolves this to TRUE/FALSE return new Caching( TruthValue.FALSE ); } - final String region = cacheElement.getRegion() != null ? cacheElement.getRegion() : defaultRegionName; + final AccessType accessType = AccessType.fromExternalName( cacheElement.getUsage().value() ); final boolean cacheLazyProps = cacheElement.getInclude() == null || !"non-lazy".equals( cacheElement.getInclude().value() ); - return new Caching( region, accessType, cacheLazyProps, TruthValue.TRUE ); + + return new Caching( + cacheElement.getRegion(), + accessType, + cacheLazyProps, + TruthValue.TRUE + ); } public static Caching createNaturalIdCaching(JaxbNaturalIdCacheElement cacheElement) { @@ -272,36 +274,11 @@ public class Helper { return null; } - public static Schema.Name determineDatabaseSchemaName( - String explicitSchemaName, - String explicitCatalogName, - LocalBindingContext bindingContext) { - return new Schema.Name( - resolveIdentifier( - explicitCatalogName, - bindingContext.getMappingDefaults().getCatalogName(), - bindingContext.quoteIdentifiersInContext() - ), resolveIdentifier( - explicitSchemaName, - bindingContext.getMappingDefaults().getSchemaName(), - bindingContext.quoteIdentifiersInContext() - ) - ); - } - - public static Identifier resolveIdentifier(String explicitName, String defaultName, boolean globalQuoting) { - String name = StringHelper.isNotEmpty( explicitName ) ? explicitName : defaultName; - if ( globalQuoting ) { - name = StringHelper.quote( name ); - } - return Identifier.toIdentifier( name ); - } - /** * Operates like SQL coalesce expression, except empty strings are treated as null. Return the first non-empty value * * @param values The list of values. - * @param + * @param Generic type of values to coalesce * * @return The first non-empty value, or null if all values were empty */ diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/IdBagSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/IdBagSourceImpl.java new file mode 100644 index 0000000000..4c22365ba1 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/IdBagSourceImpl.java @@ -0,0 +1,178 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2014, 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.metamodel.source.internal.hbm; + +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import org.hibernate.internal.util.StringHelper; +import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbBagElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbColumnElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbIdbagElement; +import org.hibernate.metamodel.source.spi.CollectionIdSource; +import org.hibernate.metamodel.source.spi.ColumnSource; +import org.hibernate.metamodel.source.spi.HibernateTypeSource; +import org.hibernate.metamodel.source.spi.Orderable; +import org.hibernate.metamodel.source.spi.RelationalValueSource; +import org.hibernate.metamodel.source.spi.SizeSource; +import org.hibernate.metamodel.spi.PluralAttributeNature; + +/** + * @author Steve Ebersole + */ +public class IdBagSourceImpl extends AbstractPluralAttributeSourceImpl implements Orderable { + public final CollectionIdSource collectionIdSource; + + public IdBagSourceImpl( + MappingDocument mappingDocument, + final JaxbIdbagElement element, + AbstractEntitySourceImpl abstractEntitySource) { + super( mappingDocument, element, abstractEntitySource ); + + final List relationalValueSources = Helper.buildValueSources( + sourceMappingDocument(), + new Helper.ValueSourcesAdapter() { + @Override + public String getColumnAttribute() { + return element.getCollectionId().getColumnAttribute(); + } + + @Override + public SizeSource getSizeSource() { + return Helper.createSizeSourceIfMapped( + element.getCollectionId().getLength(), + null, + null + ); + } + + @Override + public List getColumn() { + return element.getCollectionId().getColumn(); + } + + @Override + public boolean isIncludedInInsertByDefault() { + return true; + } + + @Override + public boolean isForceNotNull() { + return true; + } + } + ); + + ColumnSource collectionIdColumnSource = null; + if ( relationalValueSources != null && relationalValueSources.isEmpty() ) { + if ( relationalValueSources.size() > 1 ) { + throw makeMappingException( "Expecting just a single column for collection id (idbag)" ); + } + + final RelationalValueSource relationalValueSource = relationalValueSources.get( 0 ); + if ( !ColumnSource.class.isInstance( relationalValueSource ) ) { + throw makeMappingException( "Expecting column for collection id (idbag), but found formula" ); + } + + collectionIdColumnSource = (ColumnSource) relationalValueSource; + } + + final HibernateTypeSource typeSource = new HibernateTypeSource() { + private final String name = element.getCollectionId().getType(); + + @Override + public String getName() { + return name; + } + + @Override + public Map getParameters() { + return Collections.emptyMap(); + } + + @Override + public JavaTypeDescriptor getJavaType() { + return null; + } + }; + + this.collectionIdSource = new CollectionIdSourceImpl( + collectionIdColumnSource, + typeSource, + element.getCollectionId().getGenerator().getClazz() + ); + } + + @Override + public PluralAttributeNature getNature() { + return PluralAttributeNature.ID_BAG; + } + + @Override + public JaxbBagElement getPluralAttributeElement() { + return (JaxbBagElement) super.getPluralAttributeElement(); + } + + @Override + public boolean isOrdered() { + return StringHelper.isNotEmpty( getOrder() ); + } + + @Override + public String getOrder() { + return getPluralAttributeElement().getOrderBy(); + } + + private static class CollectionIdSourceImpl implements CollectionIdSource { + private final ColumnSource columnSource; + private final HibernateTypeSource typeSource; + private final String generator; + + public CollectionIdSourceImpl( + ColumnSource columnSource, + HibernateTypeSource typeSource, + String generator) { + this.columnSource = columnSource; + this.typeSource = typeSource; + this.generator = generator; + } + + @Override + public ColumnSource getColumnSource() { + return columnSource; + } + + @Override + public HibernateTypeSource getTypeInformation() { + return typeSource; + } + + @Override + public String getGeneratorName() { + return generator; + } + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/IdentifierKeyAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/IdentifierKeyAttributeSourceImpl.java index 147fc4194c..d8393a75ff 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/IdentifierKeyAttributeSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/IdentifierKeyAttributeSourceImpl.java @@ -24,17 +24,18 @@ package org.hibernate.metamodel.source.internal.hbm; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbKeyPropertyElement; -import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; +import org.hibernate.metamodel.source.spi.AttributeSourceContainer; +import org.hibernate.metamodel.spi.NaturalIdMutability; /** * @author Gail Badner */ public class IdentifierKeyAttributeSourceImpl extends KeyAttributeSourceImpl { - public IdentifierKeyAttributeSourceImpl( MappingDocument mappingDocument, - final JaxbKeyPropertyElement keyPropertyElement) { - super( mappingDocument, keyPropertyElement, SingularAttributeBinding.NaturalIdMutability.NOT_NATURAL_ID ); + AttributeSourceContainer container, + JaxbKeyPropertyElement keyPropertyElement) { + super( mappingDocument, keyPropertyElement, container, NaturalIdMutability.NOT_NATURAL_ID ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/IdentifierKeyManyToOneSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/IdentifierKeyManyToOneSourceImpl.java index ec8f79f000..30b1fea7b5 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/IdentifierKeyManyToOneSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/IdentifierKeyManyToOneSourceImpl.java @@ -24,7 +24,8 @@ package org.hibernate.metamodel.source.internal.hbm; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbKeyManyToOneElement; -import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; +import org.hibernate.metamodel.source.spi.AttributeSourceContainer; +import org.hibernate.metamodel.spi.NaturalIdMutability; /** * @author Gail Badner @@ -33,8 +34,9 @@ public class IdentifierKeyManyToOneSourceImpl extends KeyManyToOneSourceImpl { public IdentifierKeyManyToOneSourceImpl( MappingDocument mappingDocument, - final JaxbKeyManyToOneElement keyManyToOneElement) { - super( mappingDocument, keyManyToOneElement, SingularAttributeBinding.NaturalIdMutability.NOT_NATURAL_ID ); + AttributeSourceContainer container, + JaxbKeyManyToOneElement keyManyToOneElement) { + super( mappingDocument, container, keyManyToOneElement, NaturalIdMutability.NOT_NATURAL_ID ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/KeyAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/KeyAttributeSourceImpl.java index 1928e006a6..21b27fd2d2 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/KeyAttributeSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/KeyAttributeSourceImpl.java @@ -31,12 +31,16 @@ import org.hibernate.mapping.PropertyGeneration; import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbColumnElement; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbKeyPropertyElement; +import org.hibernate.metamodel.source.spi.AttributeSourceContainer; import org.hibernate.metamodel.source.spi.HibernateTypeSource; import org.hibernate.metamodel.source.spi.RelationalValueSource; import org.hibernate.metamodel.source.spi.SingularAttributeSource; import org.hibernate.metamodel.source.spi.SizeSource; import org.hibernate.metamodel.source.spi.ToolingHintSource; -import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; +import org.hibernate.metamodel.spi.NaturalIdMutability; +import org.hibernate.metamodel.spi.SingularAttributeNature; /** * Implementation for {@code } mappings @@ -47,14 +51,17 @@ class KeyAttributeSourceImpl extends AbstractHbmSourceNode implements SingularAttributeSource { private final JaxbKeyPropertyElement keyPropertyElement; - private final SingularAttributeBinding.NaturalIdMutability naturalIdMutability; + private final NaturalIdMutability naturalIdMutability; private final HibernateTypeSource typeSource; private final List valueSources; + private final AttributePath attributePath; + private final AttributeRole attributeRole; + public KeyAttributeSourceImpl( MappingDocument mappingDocument, final JaxbKeyPropertyElement keyPropertyElement, - final SingularAttributeBinding.NaturalIdMutability naturalIdMutability) { + AttributeSourceContainer container, final NaturalIdMutability naturalIdMutability) { super( mappingDocument ); this.keyPropertyElement = keyPropertyElement; this.naturalIdMutability = naturalIdMutability; @@ -116,6 +123,9 @@ class KeyAttributeSourceImpl } } ); + + this.attributePath = container.getAttributePathBase().append( getName() ); + this.attributeRole = container.getAttributeRoleBase().append( getName() ); } @Override @@ -123,6 +133,16 @@ class KeyAttributeSourceImpl return keyPropertyElement.getName(); } + @Override + public AttributePath getAttributePath() { + return attributePath; + } + + @Override + public AttributeRole getAttributeRole() { + return attributeRole; + } + @Override public HibernateTypeSource getTypeInformation() { return typeSource; @@ -144,7 +164,7 @@ class KeyAttributeSourceImpl } @Override - public SingularAttributeBinding.NaturalIdMutability getNaturalIdMutability() { + public NaturalIdMutability getNaturalIdMutability() { return naturalIdMutability; } @@ -154,8 +174,8 @@ class KeyAttributeSourceImpl } @Override - public Nature getNature() { - return Nature.BASIC; + public SingularAttributeNature getSingularAttributeNature() { + return SingularAttributeNature.BASIC; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/KeyManyToOneSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/KeyManyToOneSourceImpl.java index 1e8f137bea..2008fe4508 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/KeyManyToOneSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/KeyManyToOneSourceImpl.java @@ -32,10 +32,14 @@ import org.hibernate.engine.spi.CascadeStyle; import org.hibernate.engine.spi.CascadeStyles; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbColumnElement; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbKeyManyToOneElement; +import org.hibernate.metamodel.source.spi.AttributeSourceContainer; import org.hibernate.metamodel.source.spi.RelationalValueSource; import org.hibernate.metamodel.source.spi.SingularAttributeSource; import org.hibernate.metamodel.source.spi.ToolingHintSource; -import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; +import org.hibernate.metamodel.spi.NaturalIdMutability; +import org.hibernate.metamodel.spi.SingularAttributeNature; import org.hibernate.type.ForeignKeyDirection; /** @@ -49,10 +53,14 @@ class KeyManyToOneSourceImpl private final JaxbKeyManyToOneElement keyManyToOneElement; private final List valueSources; + private final AttributePath attributePath; + private final AttributeRole attributeRole; + public KeyManyToOneSourceImpl( MappingDocument mappingDocument, + AttributeSourceContainer container, final JaxbKeyManyToOneElement keyManyToOneElement, - final SingularAttributeBinding.NaturalIdMutability naturalIdMutability) { + final NaturalIdMutability naturalIdMutability) { super( mappingDocument, naturalIdMutability, null ); this.keyManyToOneElement = keyManyToOneElement; this.valueSources = Helper.buildValueSources( @@ -94,6 +102,9 @@ class KeyManyToOneSourceImpl } } ); + + this.attributePath = container.getAttributePathBase().append( getName() ); + this.attributeRole = container.getAttributeRoleBase().append( getName() ); } @Override @@ -101,6 +112,16 @@ class KeyManyToOneSourceImpl return keyManyToOneElement.getName(); } + @Override + public AttributePath getAttributePath() { + return attributePath; + } + + @Override + public AttributeRole getAttributeRole() { + return attributeRole; + } + @Override public String getPropertyAccessorName() { return keyManyToOneElement.getAccess(); @@ -112,8 +133,8 @@ class KeyManyToOneSourceImpl } @Override - public Nature getNature() { - return Nature.MANY_TO_ONE; + public SingularAttributeNature getSingularAttributeNature() { + return SingularAttributeNature.MANY_TO_ONE; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ListSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ListSourceImpl.java index 5d573ca4bd..ba3f447d52 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ListSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ListSourceImpl.java @@ -23,27 +23,17 @@ */ package org.hibernate.metamodel.source.internal.hbm; -import org.hibernate.AssertionFailure; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbListElement; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbListIndexElement; import org.hibernate.metamodel.source.spi.AttributeSourceContainer; -import org.hibernate.metamodel.source.spi.AttributeSourceResolutionContext; import org.hibernate.metamodel.source.spi.IndexedPluralAttributeSource; import org.hibernate.metamodel.source.spi.PluralAttributeIndexSource; -import org.hibernate.metamodel.source.spi.SequentialPluralAttributeIndexSource; +import org.hibernate.metamodel.source.spi.PluralAttributeSequentialIndexSource; +import org.hibernate.metamodel.spi.PluralAttributeNature; -/** - * - */ public class ListSourceImpl extends AbstractPluralAttributeSourceImpl implements IndexedPluralAttributeSource { + private final PluralAttributeSequentialIndexSource indexSource; - private final SequentialPluralAttributeIndexSource indexSource; - - /** - * @param sourceMappingDocument - * @param listElement - * @param container - */ public ListSourceImpl( MappingDocument sourceMappingDocument, JaxbListElement listElement, @@ -51,9 +41,10 @@ public class ListSourceImpl extends AbstractPluralAttributeSourceImpl implements super( sourceMappingDocument, listElement, container ); JaxbListIndexElement listIndexElement = listElement.getListIndex(); if ( listIndexElement == null ) { - this.indexSource = new SequentialPluralAttributeIndexSourceImpl( sourceMappingDocument(), listElement.getIndex() ); - } else { - this.indexSource = new SequentialPluralAttributeIndexSourceImpl( sourceMappingDocument(), listIndexElement ); + this.indexSource = new PluralAttributeSequentialIndexSourceImpl( sourceMappingDocument(), listElement.getIndex() ); + } + else { + this.indexSource = new PluralAttributeSequentialIndexSourceImpl( sourceMappingDocument(), listIndexElement ); } } @@ -67,21 +58,9 @@ public class ListSourceImpl extends AbstractPluralAttributeSourceImpl implements return ( JaxbListElement ) super.getPluralAttributeElement(); } - /** - * {@inheritDoc} - * - * @see org.hibernate.metamodel.source.spi.PluralAttributeSource#getNature() - */ @Override - public Nature getNature() { - return Nature.LIST; + public PluralAttributeNature getNature() { + return PluralAttributeNature.LIST; } - @Override - public PluralAttributeIndexSource resolvePluralAttributeIndexSource(AttributeSourceResolutionContext context) { - if ( indexSource == null ) { - throw new AssertionFailure( "Array index source should have been resolved already." ); - } - return indexSource; - } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ManyToOneAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ManyToOneAttributeSourceImpl.java index e25620b244..2339574c92 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ManyToOneAttributeSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ManyToOneAttributeSourceImpl.java @@ -30,9 +30,13 @@ import java.util.Set; import org.hibernate.engine.spi.CascadeStyle; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbColumnElement; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbManyToOneElement; +import org.hibernate.metamodel.source.spi.AttributeSourceContainer; import org.hibernate.metamodel.source.spi.RelationalValueSource; import org.hibernate.metamodel.source.spi.ToolingHintSource; -import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; +import org.hibernate.metamodel.spi.NaturalIdMutability; +import org.hibernate.metamodel.spi.SingularAttributeNature; import org.hibernate.type.ForeignKeyDirection; /** @@ -45,11 +49,15 @@ class ManyToOneAttributeSourceImpl extends AbstractToOneAttributeSourceImpl { private final String containingTableName; private final List valueSources; + private final AttributeRole attributeRole; + private final AttributePath attributePath; + ManyToOneAttributeSourceImpl( MappingDocument sourceMappingDocument, + AttributeSourceContainer container, final JaxbManyToOneElement manyToOneElement, final String logicalTableName, - SingularAttributeBinding.NaturalIdMutability naturalIdMutability) { + NaturalIdMutability naturalIdMutability) { super( sourceMappingDocument, naturalIdMutability, manyToOneElement.getPropertyRef() ); this.manyToOneElement = manyToOneElement; this.containingTableName = logicalTableName; @@ -92,6 +100,9 @@ class ManyToOneAttributeSourceImpl extends AbstractToOneAttributeSourceImpl { } } ); + + this.attributeRole = container.getAttributeRoleBase().append( manyToOneElement.getName() ); + this.attributePath = container.getAttributePathBase().append( manyToOneElement.getName() ); } @Override @@ -99,6 +110,16 @@ class ManyToOneAttributeSourceImpl extends AbstractToOneAttributeSourceImpl { return manyToOneElement.getName(); } + @Override + public AttributePath getAttributePath() { + return attributePath; + } + + @Override + public AttributeRole getAttributeRole() { + return attributeRole; + } + @Override public String getPropertyAccessorName() { return manyToOneElement.getAccess(); @@ -146,8 +167,8 @@ class ManyToOneAttributeSourceImpl extends AbstractToOneAttributeSourceImpl { } @Override - public Nature getNature() { - return Nature.MANY_TO_ONE; + public SingularAttributeNature getSingularAttributeNature() { + return SingularAttributeNature.MANY_TO_ONE; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/MapKeySourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/MapKeySourceBasicImpl.java similarity index 86% rename from hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/MapKeySourceImpl.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/MapKeySourceBasicImpl.java index 27492fb4da..d71d59d693 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/MapKeySourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/MapKeySourceBasicImpl.java @@ -33,21 +33,21 @@ import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbColumnElement; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbIndexElement; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbMapKeyElement; -import org.hibernate.metamodel.source.spi.BasicPluralAttributeIndexSource; import org.hibernate.metamodel.source.spi.HibernateTypeSource; +import org.hibernate.metamodel.source.spi.PluralAttributeMapKeySourceBasic; import org.hibernate.metamodel.source.spi.RelationalValueSource; import org.hibernate.metamodel.source.spi.SizeSource; -import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding; +import org.hibernate.metamodel.spi.PluralAttributeIndexNature; /** * */ -public class MapKeySourceImpl extends AbstractHbmSourceNode implements BasicPluralAttributeIndexSource { - private final PluralAttributeIndexBinding.Nature nature; +public class MapKeySourceBasicImpl extends AbstractHbmSourceNode implements PluralAttributeMapKeySourceBasic { + private final PluralAttributeIndexNature nature; private final List valueSources; private final HibernateTypeSource typeSource; - public MapKeySourceImpl(MappingDocument sourceMappingDocument, final JaxbMapKeyElement mapKey) { + public MapKeySourceBasicImpl(MappingDocument sourceMappingDocument, final JaxbMapKeyElement mapKey) { super( sourceMappingDocument ); valueSources = Helper.buildValueSources( sourceMappingDocument(), @@ -117,10 +117,10 @@ public class MapKeySourceImpl extends AbstractHbmSourceNode implements BasicPlur return null; } }; - this.nature = PluralAttributeIndexBinding.Nature.BASIC; + this.nature = PluralAttributeIndexNature.BASIC; } - public MapKeySourceImpl(MappingDocument sourceMappingDocument, final JaxbIndexElement indexElement) { + public MapKeySourceBasicImpl(MappingDocument sourceMappingDocument, final JaxbIndexElement indexElement) { super( sourceMappingDocument ); valueSources = Helper.buildValueSources( sourceMappingDocument, @@ -174,7 +174,7 @@ public class MapKeySourceImpl extends AbstractHbmSourceNode implements BasicPlur } }; - this.nature = PluralAttributeIndexBinding.Nature.BASIC; + this.nature = PluralAttributeIndexNature.BASIC; } @Override @@ -193,7 +193,7 @@ public class MapKeySourceImpl extends AbstractHbmSourceNode implements BasicPlur } @Override - public PluralAttributeIndexBinding.Nature getNature() { + public PluralAttributeIndexNature getNature() { return nature; } @@ -214,11 +214,6 @@ public class MapKeySourceImpl extends AbstractHbmSourceNode implements BasicPlur return typeSource; } - @Override - public boolean isReferencedEntityAttribute() { - return false; //To change body of implemented methods use File | Settings | File Templates. - } - @Override public List relationalValueSources() { return valueSources; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/MapSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/MapSourceImpl.java index 2803fc4dbc..2e9a38bc75 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/MapSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/MapSourceImpl.java @@ -27,38 +27,37 @@ import org.hibernate.AssertionFailure; import org.hibernate.cfg.NotYetImplementedException; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbMapElement; import org.hibernate.metamodel.source.spi.AttributeSourceContainer; -import org.hibernate.metamodel.source.spi.AttributeSourceResolutionContext; import org.hibernate.metamodel.source.spi.IndexedPluralAttributeSource; import org.hibernate.metamodel.source.spi.PluralAttributeIndexSource; +import org.hibernate.metamodel.spi.PluralAttributeNature; -/** - * - */ public class MapSourceImpl extends AbstractPluralAttributeSourceImpl implements IndexedPluralAttributeSource { - private final PluralAttributeIndexSource indexSource; - /** - * @param sourceMappingDocument - * @param mapElement - * @param container - */ public MapSourceImpl( MappingDocument sourceMappingDocument, JaxbMapElement mapElement, AttributeSourceContainer container) { super( sourceMappingDocument, mapElement, container ); if ( mapElement.getMapKey() != null ) { - this.indexSource = new MapKeySourceImpl( sourceMappingDocument, mapElement.getMapKey() ); + this.indexSource = new MapKeySourceBasicImpl( sourceMappingDocument, mapElement.getMapKey() ); } else if ( mapElement.getIndex() != null ) { - this.indexSource = new MapKeySourceImpl( sourceMappingDocument, mapElement.getIndex() ); + this.indexSource = new MapKeySourceBasicImpl( sourceMappingDocument, mapElement.getIndex() ); } else if ( mapElement.getCompositeMapKey() != null ) { - this.indexSource = new CompositePluralAttributeIndexSourceImpl( sourceMappingDocument, mapElement.getCompositeMapKey() ); + this.indexSource = new PluralAttributeMapKeySourceEmbeddedImpl( + sourceMappingDocument, + this, + mapElement.getCompositeMapKey() + ); } else if ( mapElement.getCompositeIndex() != null ) { - this.indexSource = new CompositePluralAttributeIndexSourceImpl( sourceMappingDocument, mapElement.getCompositeIndex() ); + this.indexSource = new PluralAttributeMapKeySourceEmbeddedImpl( + sourceMappingDocument, + this, + mapElement.getCompositeIndex() + ); } else if ( mapElement.getMapKeyManyToMany() != null ) { throw new NotYetImplementedException( " is not supported yet" ); @@ -74,15 +73,6 @@ public class MapSourceImpl extends AbstractPluralAttributeSourceImpl implements } } - @Override - public PluralAttributeIndexSource resolvePluralAttributeIndexSource(AttributeSourceResolutionContext context) { - if ( indexSource == null ) { - throw new NotYetImplementedException( "Plural attribute index source resolution not implemented yet." ); - - } - return indexSource; - } - @Override public PluralAttributeIndexSource getIndexSource() { return indexSource; @@ -93,13 +83,8 @@ public class MapSourceImpl extends AbstractPluralAttributeSourceImpl implements return ( JaxbMapElement ) super.getPluralAttributeElement(); } - /** - * {@inheritDoc} - * - * @see org.hibernate.metamodel.source.spi.PluralAttributeSource#getNature() - */ @Override - public Nature getNature() { - return Nature.MAP; + public PluralAttributeNature getNature() { + return PluralAttributeNature.MAP; } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/NamedQueryBindingHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/NamedQueryBindingHelper.java index 3dfdc8f1c6..48582cee8b 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/NamedQueryBindingHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/NamedQueryBindingHelper.java @@ -38,7 +38,7 @@ import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbSqlQueryElement; import org.hibernate.metamodel.spi.InFlightMetadataCollector; import org.hibernate.metamodel.spi.LocalBindingContext; import org.hibernate.metamodel.spi.binding.AttributeBinding; -import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding; +import org.hibernate.metamodel.spi.binding.EmbeddedAttributeBinding; import org.hibernate.metamodel.spi.binding.EntityBinding; import org.hibernate.metamodel.spi.binding.SingularAssociationAttributeBinding; import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; @@ -124,14 +124,12 @@ public class NamedQueryBindingHelper { String reducedName = name.substring( 0, dotIndex ); AttributeBinding value = null;// getRecursiveAttributeBinding(entityBinding, reducedName ); Iterable parentPropIter; - if ( CompositeAttributeBinding.class.isInstance( value ) ) { - CompositeAttributeBinding comp - = (CompositeAttributeBinding) value; - parentPropIter = comp.attributeBindings(); + if ( EmbeddedAttributeBinding.class.isInstance( value ) ) { + EmbeddedAttributeBinding comp + = (EmbeddedAttributeBinding) value; + parentPropIter = comp.getEmbeddableBinding().attributeBindings(); } - else if ( SingularAssociationAttributeBinding.class.isInstance( - value - ) ) { + else if ( SingularAssociationAttributeBinding.class.isInstance( value ) ) { SingularAssociationAttributeBinding toOne = SingularAssociationAttributeBinding.class.cast( value @@ -141,9 +139,9 @@ public class NamedQueryBindingHelper { SingularAttributeBinding referencedAttributeBinding = toOne.getReferencedAttributeBinding(); try { - parentPropIter = CompositeAttributeBinding.class.cast( + parentPropIter = EmbeddedAttributeBinding.class.cast( referencedAttributeBinding - ).attributeBindings(); + ).getEmbeddableBinding().attributeBindings(); } catch ( ClassCastException e ) { throw new org.hibernate.MappingException( diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/OneToOneAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/OneToOneAttributeSourceImpl.java index 1d2194eb13..756e69c23c 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/OneToOneAttributeSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/OneToOneAttributeSourceImpl.java @@ -30,9 +30,13 @@ import java.util.Set; import org.hibernate.engine.spi.CascadeStyle; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbColumnElement; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbOneToOneElement; +import org.hibernate.metamodel.source.spi.AttributeSourceContainer; import org.hibernate.metamodel.source.spi.RelationalValueSource; import org.hibernate.metamodel.source.spi.ToolingHintSource; -import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; +import org.hibernate.metamodel.spi.NaturalIdMutability; +import org.hibernate.metamodel.spi.SingularAttributeNature; import org.hibernate.type.ForeignKeyDirection; /** @@ -45,11 +49,15 @@ class OneToOneAttributeSourceImpl extends AbstractToOneAttributeSourceImpl { private final List valueSources; private final String containingTableName; + private final AttributeRole attributeRole; + private final AttributePath attributePath; + OneToOneAttributeSourceImpl( MappingDocument sourceMappingDocument, + AttributeSourceContainer container, final JaxbOneToOneElement oneToOneElement, final String logicalTableName, - SingularAttributeBinding.NaturalIdMutability naturalIdMutability) { + NaturalIdMutability naturalIdMutability) { super( sourceMappingDocument, naturalIdMutability, oneToOneElement.getPropertyRef() ); this.oneToOneElement = oneToOneElement; this.containingTableName = logicalTableName; @@ -94,6 +102,9 @@ class OneToOneAttributeSourceImpl extends AbstractToOneAttributeSourceImpl { } } ); + + this.attributeRole = container.getAttributeRoleBase().append( oneToOneElement.getName() ); + this.attributePath = container.getAttributePathBase().append( oneToOneElement.getName() ); } @Override @@ -101,6 +112,16 @@ class OneToOneAttributeSourceImpl extends AbstractToOneAttributeSourceImpl { return oneToOneElement.getName(); } + @Override + public AttributePath getAttributePath() { + return attributePath; + } + + @Override + public AttributeRole getAttributeRole() { + return attributeRole; + } + @Override public String getPropertyAccessorName() { return oneToOneElement.getAccess(); @@ -132,8 +153,8 @@ class OneToOneAttributeSourceImpl extends AbstractToOneAttributeSourceImpl { } @Override - public Nature getNature() { - return Nature.ONE_TO_ONE; + public SingularAttributeNature getSingularAttributeNature() { + return SingularAttributeNature.ONE_TO_ONE; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/BasicPluralAttributeElementSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PluralAttributeElementSourceBasicImpl.java similarity index 88% rename from hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/BasicPluralAttributeElementSourceImpl.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PluralAttributeElementSourceBasicImpl.java index abb47c329c..3d39509534 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/BasicPluralAttributeElementSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PluralAttributeElementSourceBasicImpl.java @@ -29,21 +29,22 @@ import java.util.Map; import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbColumnElement; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbElementElement; -import org.hibernate.metamodel.source.spi.BasicPluralAttributeElementSource; import org.hibernate.metamodel.source.spi.HibernateTypeSource; +import org.hibernate.metamodel.source.spi.PluralAttributeElementSourceBasic; import org.hibernate.metamodel.source.spi.RelationalValueSource; import org.hibernate.metamodel.source.spi.SizeSource; +import org.hibernate.metamodel.spi.PluralAttributeElementNature; /** * @author Steve Ebersole */ -public class BasicPluralAttributeElementSourceImpl +public class PluralAttributeElementSourceBasicImpl extends AbstractHbmSourceNode - implements BasicPluralAttributeElementSource { + implements PluralAttributeElementSourceBasic { private final List valueSources; private final HibernateTypeSource typeSource; - public BasicPluralAttributeElementSourceImpl( + public PluralAttributeElementSourceBasicImpl( MappingDocument sourceMappingDocument, final JaxbElementElement elementElement) { super( sourceMappingDocument ); @@ -52,12 +53,12 @@ public class BasicPluralAttributeElementSourceImpl new Helper.ValueSourcesAdapter() { @Override public boolean isIncludedInInsertByDefault() { - return BasicPluralAttributeElementSourceImpl.this.areValuesIncludedInInsertByDefault(); + return PluralAttributeElementSourceBasicImpl.this.areValuesIncludedInInsertByDefault(); } @Override public boolean isIncludedInUpdateByDefault() { - return BasicPluralAttributeElementSourceImpl.this.areValuesIncludedInUpdateByDefault(); + return PluralAttributeElementSourceBasicImpl.this.areValuesIncludedInUpdateByDefault(); } @Override @@ -124,8 +125,8 @@ public class BasicPluralAttributeElementSourceImpl } @Override - public Nature getNature() { - return Nature.BASIC; + public PluralAttributeElementNature getNature() { + return PluralAttributeElementNature.BASIC; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PluralAttributeElementSourceEmbeddedImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PluralAttributeElementSourceEmbeddedImpl.java new file mode 100644 index 0000000000..43d8d64fff --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PluralAttributeElementSourceEmbeddedImpl.java @@ -0,0 +1,150 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.metamodel.source.internal.hbm; + +import java.util.Collection; +import java.util.List; +import java.util.Set; + +import org.hibernate.EntityMode; +import org.hibernate.engine.spi.CascadeStyle; +import org.hibernate.internal.util.StringHelper; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbAnyElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbCompositeElementElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbManyToOneElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbNestedCompositeElementElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPropertyElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbTuplizerElement; +import org.hibernate.metamodel.source.spi.EmbeddableSource; +import org.hibernate.metamodel.source.spi.PluralAttributeElementSourceEmbedded; +import org.hibernate.metamodel.source.spi.ToolingHintSource; +import org.hibernate.metamodel.spi.NaturalIdMutability; +import org.hibernate.metamodel.spi.PluralAttributeElementNature; + +/** + * @author Steve Ebersole + * @author Gail Badner + */ +public class PluralAttributeElementSourceEmbeddedImpl + extends AbstractHbmSourceNode + implements PluralAttributeElementSourceEmbedded { + + private final JaxbCompositeElementElement compositeElement; + private final EmbeddableSourceImpl embeddableSource; + private final Set cascadeStyles; + + public PluralAttributeElementSourceEmbeddedImpl( + MappingDocument mappingDocument, + AbstractPluralAttributeSourceImpl pluralAttributeSource, + JaxbCompositeElementElement compositeElement, + String cascadeString) { + super( mappingDocument ); + this.compositeElement = compositeElement; + + this.embeddableSource = new EmbeddableSourceImpl( + mappingDocument, + pluralAttributeSource.getAttributeRole(), + pluralAttributeSource.getAttributePath(), + new EmbeddableJaxbSourceImpl( compositeElement ), + null, + NaturalIdMutability.NOT_NATURAL_ID + ); + + this.cascadeStyles = Helper.interpretCascadeStyles( cascadeString, bindingContext() ); + } + + @Override + public PluralAttributeElementNature getNature() { + return PluralAttributeElementNature.AGGREGATE; + } + + @Override + public EmbeddableSource getEmbeddableSource() { + return embeddableSource; + } + + @Override + public Collection getToolingHintSources() { + return compositeElement.getMeta(); + } + + public static class EmbeddableJaxbSourceImpl extends AbstractEmbeddableJaxbSource { + private final JaxbCompositeElementElement compositeElement; + + public EmbeddableJaxbSourceImpl(JaxbCompositeElementElement compositeElement) { + this.compositeElement = compositeElement; + } + + @Override + public String getClazz() { + return compositeElement.getClazz(); + } + + @Override + public String findParent() { + return compositeElement.getParent() != null + ? compositeElement.getParent().getName() + : null; + } + + @Override + public String findTuplizer() { + if ( compositeElement.getTuplizer() == null ) { + return null; + } + final EntityMode entityMode = StringHelper.isEmpty( compositeElement.getClazz() ) ? EntityMode.MAP : EntityMode.POJO; + for ( JaxbTuplizerElement tuplizerElement : compositeElement.getTuplizer() ) { + if ( entityMode == EntityMode.parse( tuplizerElement.getEntityMode().value() ) ) { + return tuplizerElement.getClazz(); + } + } + return null; + } + + @Override + public List getPropertyElementList() { + return compositeElement.getProperty(); + } + + @Override + public List getAnyElementList() { + return compositeElement.getAny(); + } + + @Override + public List getNestedCompositeElementList() { + return compositeElement.getNestedCompositeElement(); + } + + @Override + public List getManyToOneElementList() { + return compositeElement.getManyToOne(); + } + } + + @Override + public Set getCascadeStyles() { + return cascadeStyles; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ManyToManyPluralAttributeElementSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PluralAttributeElementSourceManyToManyImpl.java similarity index 94% rename from hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ManyToManyPluralAttributeElementSourceImpl.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PluralAttributeElementSourceManyToManyImpl.java index a31117b24a..bd069566d6 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ManyToManyPluralAttributeElementSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PluralAttributeElementSourceManyToManyImpl.java @@ -33,10 +33,11 @@ import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbColumnElement; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbFilterElement; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbManyToManyElement; import org.hibernate.metamodel.source.spi.FilterSource; -import org.hibernate.metamodel.source.spi.ManyToManyPluralAttributeElementSource; import org.hibernate.metamodel.source.spi.MappingException; +import org.hibernate.metamodel.source.spi.PluralAttributeElementSourceManyToMany; import org.hibernate.metamodel.source.spi.PluralAttributeSource; import org.hibernate.metamodel.source.spi.RelationalValueSource; +import org.hibernate.metamodel.spi.PluralAttributeElementNature; import org.hibernate.metamodel.spi.relational.TableSpecification; import org.hibernate.metamodel.spi.relational.Value; @@ -44,15 +45,15 @@ import org.hibernate.metamodel.spi.relational.Value; * @author Steve Ebersole * @author Gail Badner */ -public class ManyToManyPluralAttributeElementSourceImpl +public class PluralAttributeElementSourceManyToManyImpl extends AbstractPluralAssociationElementSourceImpl - implements ManyToManyPluralAttributeElementSource { + implements PluralAttributeElementSourceManyToMany { private final JaxbManyToManyElement manyToManyElement; private final Set cascadeStyles; private final List valueSources; private final FilterSource[] filterSources; - public ManyToManyPluralAttributeElementSourceImpl( + public PluralAttributeElementSourceManyToManyImpl( MappingDocument mappingDocument, final PluralAttributeSource pluralAttributeSource, final JaxbManyToManyElement manyToManyElement, @@ -113,8 +114,8 @@ public class ManyToManyPluralAttributeElementSourceImpl } @Override - public Nature getNature() { - return Nature.MANY_TO_MANY; + public PluralAttributeElementNature getNature() { + return PluralAttributeElementNature.MANY_TO_MANY; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/OneToManyPluralAttributeElementSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PluralAttributeElementSourceOneToManyImpl.java similarity index 85% rename from hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/OneToManyPluralAttributeElementSourceImpl.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PluralAttributeElementSourceOneToManyImpl.java index 1b2bffb448..b3d98c3d7b 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/OneToManyPluralAttributeElementSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PluralAttributeElementSourceOneToManyImpl.java @@ -28,19 +28,20 @@ import java.util.Set; import org.hibernate.engine.spi.CascadeStyle; import org.hibernate.internal.util.StringHelper; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbOneToManyElement; -import org.hibernate.metamodel.source.spi.OneToManyPluralAttributeElementSource; +import org.hibernate.metamodel.source.spi.PluralAttributeElementSourceOneToMany; import org.hibernate.metamodel.source.spi.PluralAttributeSource; +import org.hibernate.metamodel.spi.PluralAttributeElementNature; /** * @author Steve Ebersole */ -public class OneToManyPluralAttributeElementSourceImpl +public class PluralAttributeElementSourceOneToManyImpl extends AbstractPluralAssociationElementSourceImpl - implements OneToManyPluralAttributeElementSource { + implements PluralAttributeElementSourceOneToMany { private final JaxbOneToManyElement oneToManyElement; private final Set cascadeStyles; - public OneToManyPluralAttributeElementSourceImpl( + public PluralAttributeElementSourceOneToManyImpl( MappingDocument mappingDocument, final PluralAttributeSource pluralAttributeSource, final JaxbOneToManyElement oneToManyElement, @@ -51,8 +52,8 @@ public class OneToManyPluralAttributeElementSourceImpl } @Override - public Nature getNature() { - return Nature.ONE_TO_MANY; + public PluralAttributeElementNature getNature() { + return PluralAttributeElementNature.ONE_TO_MANY; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PluralAttributeMapKeySourceEmbeddedImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PluralAttributeMapKeySourceEmbeddedImpl.java new file mode 100644 index 0000000000..3ca71a0be9 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PluralAttributeMapKeySourceEmbeddedImpl.java @@ -0,0 +1,182 @@ +/* + * 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.metamodel.source.internal.hbm; + +import java.util.List; + +import org.hibernate.metamodel.internal.binder.Binder; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbCompositeIndexElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbCompositeMapKeyElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbKeyManyToOneElement; +import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbKeyPropertyElement; +import org.hibernate.metamodel.source.spi.EmbeddableSource; +import org.hibernate.metamodel.source.spi.HibernateTypeSource; +import org.hibernate.metamodel.source.spi.PluralAttributeMapKeySourceEmbedded; +import org.hibernate.metamodel.source.spi.RelationalValueSource; +import org.hibernate.metamodel.spi.NaturalIdMutability; +import org.hibernate.metamodel.spi.PluralAttributeIndexNature; + +/** + * @author Gail Badner + */ +public class PluralAttributeMapKeySourceEmbeddedImpl + extends AbstractHbmSourceNode + implements PluralAttributeMapKeySourceEmbedded { + + private final AbstractPluralAttributeSourceImpl pluralAttributeSource; + private final EmbeddableSourceImpl embeddableSource; + + + public PluralAttributeMapKeySourceEmbeddedImpl( + MappingDocument mappingDocument, + AbstractPluralAttributeSourceImpl pluralAttributeSource, + final JaxbCompositeIndexElement compositeIndexElement) { + this( + mappingDocument, + pluralAttributeSource, + new AbstractEmbeddableJaxbSource() { + + @Override + public String getClazz() { + return compositeIndexElement.getClazz(); + } + + @Override + public String findParent() { + return null; + } + + @Override + public String findTuplizer() { + return null; + } + + @Override + public List getKeyPropertyElementList() { + return compositeIndexElement.getKeyProperty(); + } + + @Override + public List getKeyManyToOneElementList() { + return compositeIndexElement.getKeyManyToOne(); + } + } + ); + } + + public PluralAttributeMapKeySourceEmbeddedImpl( + MappingDocument mappingDocument, + AbstractPluralAttributeSourceImpl pluralAttributeSource, + final JaxbCompositeMapKeyElement compositeMapKeyElement) { + this( + mappingDocument, + pluralAttributeSource, + + new AbstractEmbeddableJaxbSource() { + + @Override + public String getClazz() { + return compositeMapKeyElement.getClazz(); + } + + @Override + public String findParent() { + return null; + } + + @Override + public String findTuplizer() { + return null; + } + + @Override + public List getKeyPropertyElementList() { + return compositeMapKeyElement.getKeyProperty(); + } + + @Override + public List getKeyManyToOneElementList() { + return compositeMapKeyElement.getKeyManyToOne(); + } + } + ); + } + + private PluralAttributeMapKeySourceEmbeddedImpl( + MappingDocument mappingDocument, + AbstractPluralAttributeSourceImpl pluralAttributeSource, + EmbeddableJaxbSource embeddableJaxbSource) { + super( mappingDocument ); + + this.pluralAttributeSource = pluralAttributeSource; + this.embeddableSource = new EmbeddableSourceImpl( + mappingDocument, + pluralAttributeSource.getAttributeRole().append( "key" ), + pluralAttributeSource.getAttributePath().append( "key" ), + embeddableJaxbSource, + null, + NaturalIdMutability.NOT_NATURAL_ID + ); + } + + @Override + public PluralAttributeIndexNature getNature() { + return PluralAttributeIndexNature.AGGREGATE; + } + + @Override + public EmbeddableSource getEmbeddableSource() { + return embeddableSource; + } + + @Override + public List getDefaultNamingStrategies() { + return null; //To change body of implemented methods use File | Settings | File Templates. + } + + @Override + public HibernateTypeSource getTypeInformation() { + return null; //To change body of implemented methods use File | Settings | File Templates. + } + + @Override + public List relationalValueSources() { + return null; + } + + @Override + public boolean areValuesIncludedInInsertByDefault() { + return true; + } + + @Override + public boolean areValuesIncludedInUpdateByDefault() { + return false; + } + + @Override + public boolean areValuesNullableByDefault() { + return true; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/SequentialPluralAttributeIndexSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PluralAttributeSequentialIndexSourceImpl.java similarity index 87% rename from hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/SequentialPluralAttributeIndexSourceImpl.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PluralAttributeSequentialIndexSourceImpl.java index afe306d617..c2dc88d14a 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/SequentialPluralAttributeIndexSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PluralAttributeSequentialIndexSourceImpl.java @@ -35,20 +35,23 @@ import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbColumnElement; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbIndexElement; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbListIndexElement; import org.hibernate.metamodel.source.spi.HibernateTypeSource; +import org.hibernate.metamodel.source.spi.PluralAttributeSequentialIndexSource; import org.hibernate.metamodel.source.spi.RelationalValueSource; -import org.hibernate.metamodel.source.spi.SequentialPluralAttributeIndexSource; import org.hibernate.metamodel.source.spi.SizeSource; -import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding; +import org.hibernate.metamodel.spi.PluralAttributeIndexNature; /** * */ -public class SequentialPluralAttributeIndexSourceImpl extends AbstractHbmSourceNode implements SequentialPluralAttributeIndexSource { +public class PluralAttributeSequentialIndexSourceImpl extends AbstractHbmSourceNode implements + PluralAttributeSequentialIndexSource { private final List< RelationalValueSource > valueSources; private final HibernateTypeSource typeSource; private final int base; - public SequentialPluralAttributeIndexSourceImpl(MappingDocument sourceMappingDocument, final JaxbListIndexElement indexElement) { + public PluralAttributeSequentialIndexSourceImpl( + MappingDocument sourceMappingDocument, + final JaxbListIndexElement indexElement) { super( sourceMappingDocument ); valueSources = Helper.buildValueSources( sourceMappingDocument, new Helper.ValueSourcesAdapter() { @@ -93,7 +96,9 @@ public class SequentialPluralAttributeIndexSourceImpl extends AbstractHbmSourceN base = Integer.parseInt( indexElement.getBase() ); } - public SequentialPluralAttributeIndexSourceImpl(MappingDocument sourceMappingDocument, final JaxbIndexElement indexElement) { + public PluralAttributeSequentialIndexSourceImpl( + MappingDocument sourceMappingDocument, + final JaxbIndexElement indexElement) { super( sourceMappingDocument ); valueSources = Helper.buildValueSources( sourceMappingDocument, new Helper.ValueSourcesAdapter() { @@ -164,8 +169,8 @@ public class SequentialPluralAttributeIndexSourceImpl extends AbstractHbmSourceN } @Override - public PluralAttributeIndexBinding.Nature getNature() { - return PluralAttributeIndexBinding.Nature.BASIC; + public PluralAttributeIndexNature getNature() { + return PluralAttributeIndexNature.SEQUENTIAL; } @Override @@ -184,11 +189,6 @@ public class SequentialPluralAttributeIndexSourceImpl extends AbstractHbmSourceN return typeSource; } - @Override - public boolean isReferencedEntityAttribute() { - return false; - } - @Override public List< RelationalValueSource > relationalValueSources() { return valueSources; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PropertyAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PropertyAttributeSourceImpl.java index bbcb896da8..8e8845e233 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PropertyAttributeSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PropertyAttributeSourceImpl.java @@ -31,12 +31,16 @@ import org.hibernate.mapping.PropertyGeneration; import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbColumnElement; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPropertyElement; +import org.hibernate.metamodel.source.spi.AttributeSourceContainer; import org.hibernate.metamodel.source.spi.HibernateTypeSource; import org.hibernate.metamodel.source.spi.RelationalValueSource; import org.hibernate.metamodel.source.spi.SingularAttributeSource; import org.hibernate.metamodel.source.spi.SizeSource; import org.hibernate.metamodel.source.spi.ToolingHintSource; -import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; +import org.hibernate.metamodel.spi.NaturalIdMutability; +import org.hibernate.metamodel.spi.SingularAttributeNature; /** * Implementation for {@code } mappings @@ -47,14 +51,18 @@ class PropertyAttributeSourceImpl extends AbstractHbmSourceNode implements Singu private final JaxbPropertyElement propertyElement; private final HibernateTypeSource typeSource; private final List valueSources; - private final SingularAttributeBinding.NaturalIdMutability naturalIdMutability; + private final NaturalIdMutability naturalIdMutability; private final String containingTableName; + private final AttributeRole attributeRole; + private final AttributePath attributePath; + PropertyAttributeSourceImpl( MappingDocument sourceMappingDocument, + AttributeSourceContainer container, final JaxbPropertyElement propertyElement, final String logicalTableName, - SingularAttributeBinding.NaturalIdMutability naturalIdMutability) { + NaturalIdMutability naturalIdMutability) { super( sourceMappingDocument ); this.propertyElement = propertyElement; this.typeSource = new HibernateTypeSource() { @@ -133,6 +141,9 @@ class PropertyAttributeSourceImpl extends AbstractHbmSourceNode implements Singu } ); this.naturalIdMutability = naturalIdMutability; + + this.attributeRole = container.getAttributeRoleBase().append( getName() ); + this.attributePath = container.getAttributePathBase().append( getName() ); } @Override @@ -140,6 +151,16 @@ class PropertyAttributeSourceImpl extends AbstractHbmSourceNode implements Singu return propertyElement.getName(); } + @Override + public AttributePath getAttributePath() { + return attributePath; + } + + @Override + public AttributeRole getAttributeRole() { + return attributeRole; + } + @Override public HibernateTypeSource getTypeInformation() { return typeSource; @@ -161,7 +182,7 @@ class PropertyAttributeSourceImpl extends AbstractHbmSourceNode implements Singu } @Override - public SingularAttributeBinding.NaturalIdMutability getNaturalIdMutability() { + public NaturalIdMutability getNaturalIdMutability() { return naturalIdMutability; } @@ -171,8 +192,8 @@ class PropertyAttributeSourceImpl extends AbstractHbmSourceNode implements Singu } @Override - public Nature getNature() { - return Nature.BASIC; + public SingularAttributeNature getSingularAttributeNature() { + return SingularAttributeNature.BASIC; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/RootEntitySourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/RootEntitySourceImpl.java index 709268a450..b39f699a73 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/RootEntitySourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/RootEntitySourceImpl.java @@ -30,7 +30,7 @@ import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbNaturalIdElement; import org.hibernate.metamodel.source.spi.AttributeSource; import org.hibernate.metamodel.source.spi.IdentifiableTypeSource; import org.hibernate.metamodel.source.spi.TableSpecificationSource; -import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; +import org.hibernate.metamodel.spi.NaturalIdMutability; /** * @author Steve Ebersole @@ -51,9 +51,9 @@ public class RootEntitySourceImpl extends AbstractEntitySourceImpl { protected List buildAttributeSources(List attributeSources) { final JaxbNaturalIdElement naturalId = entityElement().getNaturalId(); if ( naturalId != null ) { - final SingularAttributeBinding.NaturalIdMutability naturalIdMutability = naturalId.isMutable() - ? SingularAttributeBinding.NaturalIdMutability.MUTABLE - : SingularAttributeBinding.NaturalIdMutability.IMMUTABLE; + final NaturalIdMutability naturalIdMutability = naturalId.isMutable() + ? NaturalIdMutability.MUTABLE + : NaturalIdMutability.IMMUTABLE; processPropertyAttributes( attributeSources, naturalId.getProperty(), null, naturalIdMutability ); processManyToOneAttributes( attributeSources, naturalId.getManyToOne(), null, naturalIdMutability ); processComponentAttributes( attributeSources, naturalId.getComponent(), null, naturalIdMutability ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/SetSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/SetSourceImpl.java index 77a0a51239..ac33fcfd20 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/SetSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/SetSourceImpl.java @@ -28,6 +28,7 @@ import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbSetElement; import org.hibernate.metamodel.source.spi.AttributeSourceContainer; import org.hibernate.metamodel.source.spi.Orderable; import org.hibernate.metamodel.source.spi.Sortable; +import org.hibernate.metamodel.spi.PluralAttributeNature; /** * @author Steve Ebersole @@ -46,8 +47,8 @@ public class SetSourceImpl extends AbstractPluralAttributeSourceImpl implements } @Override - public Nature getNature() { - return Nature.SET; + public PluralAttributeNature getNature() { + return PluralAttributeNature.SET; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/SingularIdentifierAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/SingularIdentifierAttributeSourceImpl.java index 0e2b04b614..b6db4cf4f0 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/SingularIdentifierAttributeSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/SingularIdentifierAttributeSourceImpl.java @@ -31,12 +31,16 @@ import org.hibernate.mapping.PropertyGeneration; import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbColumnElement; import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbIdElement; +import org.hibernate.metamodel.source.spi.AttributeSourceContainer; import org.hibernate.metamodel.source.spi.HibernateTypeSource; import org.hibernate.metamodel.source.spi.RelationalValueSource; import org.hibernate.metamodel.source.spi.SingularAttributeSource; import org.hibernate.metamodel.source.spi.SizeSource; import org.hibernate.metamodel.source.spi.ToolingHintSource; -import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; +import org.hibernate.metamodel.spi.NaturalIdMutability; +import org.hibernate.metamodel.spi.SingularAttributeNature; /** * Implementation for {@code } mappings @@ -46,12 +50,17 @@ import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; class SingularIdentifierAttributeSourceImpl extends AbstractHbmSourceNode implements SingularAttributeSource { + private final JaxbIdElement idElement; private final HibernateTypeSource typeSource; private final List valueSources; + private final AttributeRole attributeRole; + private final AttributePath attributePath; + public SingularIdentifierAttributeSourceImpl( MappingDocument mappingDocument, + AttributeSourceContainer container, final JaxbIdElement idElement) { super( mappingDocument ); this.idElement = idElement; @@ -113,6 +122,9 @@ class SingularIdentifierAttributeSourceImpl } } ); + + this.attributeRole = container.getAttributeRoleBase().append( getName() ); + this.attributePath = container.getAttributePathBase().append( getName() ); } @Override @@ -122,6 +134,16 @@ class SingularIdentifierAttributeSourceImpl : idElement.getName(); } + @Override + public AttributePath getAttributePath() { + return attributePath; + } + + @Override + public AttributeRole getAttributeRole() { + return attributeRole; + } + @Override public HibernateTypeSource getTypeInformation() { return typeSource; @@ -143,8 +165,8 @@ class SingularIdentifierAttributeSourceImpl } @Override - public SingularAttributeBinding.NaturalIdMutability getNaturalIdMutability() { - return SingularAttributeBinding.NaturalIdMutability.NOT_NATURAL_ID; + public NaturalIdMutability getNaturalIdMutability() { + return NaturalIdMutability.NOT_NATURAL_ID; } @Override @@ -153,8 +175,8 @@ class SingularIdentifierAttributeSourceImpl } @Override - public Nature getNature() { - return Nature.BASIC; + public SingularAttributeNature getSingularAttributeNature() { + return SingularAttributeNature.BASIC; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/TimestampAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/TimestampAttributeSourceImpl.java index c1de3a7e2c..fbdbd0ed9d 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/TimestampAttributeSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/TimestampAttributeSourceImpl.java @@ -35,7 +35,10 @@ import org.hibernate.metamodel.source.spi.HibernateTypeSource; import org.hibernate.metamodel.source.spi.RelationalValueSource; import org.hibernate.metamodel.source.spi.ToolingHintSource; import org.hibernate.metamodel.source.spi.VersionAttributeSource; -import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; +import org.hibernate.metamodel.spi.NaturalIdMutability; +import org.hibernate.metamodel.spi.SingularAttributeNature; /** * Implementation for {@code } mappings @@ -48,8 +51,12 @@ class TimestampAttributeSourceImpl private final JaxbTimestampElement timestampElement; private final List valueSources; + private final AttributePath attributePath; + private final AttributeRole attributeRole; + TimestampAttributeSourceImpl( MappingDocument mappingDocument, + RootEntitySourceImpl rootEntitySource, final JaxbTimestampElement timestampElement) { super( mappingDocument ); this.timestampElement = timestampElement; @@ -71,6 +78,9 @@ class TimestampAttributeSourceImpl } } ); + + this.attributePath = rootEntitySource.getAttributePathBase().append( getName() ); + this.attributeRole = rootEntitySource.getAttributeRoleBase().append( getName() ); } private final HibernateTypeSource typeSource = new HibernateTypeSource() { @@ -94,6 +104,16 @@ class TimestampAttributeSourceImpl return timestampElement.getName(); } + @Override + public AttributePath getAttributePath() { + return attributePath; + } + + @Override + public AttributeRole getAttributeRole() { + return attributeRole; + } + @Override public HibernateTypeSource getTypeInformation() { return typeSource; @@ -130,8 +150,8 @@ class TimestampAttributeSourceImpl } @Override - public SingularAttributeBinding.NaturalIdMutability getNaturalIdMutability() { - return SingularAttributeBinding.NaturalIdMutability.NOT_NATURAL_ID; + public NaturalIdMutability getNaturalIdMutability() { + return NaturalIdMutability.NOT_NATURAL_ID; } @Override @@ -140,8 +160,8 @@ class TimestampAttributeSourceImpl } @Override - public Nature getNature() { - return Nature.BASIC; + public SingularAttributeNature getSingularAttributeNature() { + return SingularAttributeNature.BASIC; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/VersionAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/VersionAttributeSourceImpl.java index af7c03a95d..1223d686bb 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/VersionAttributeSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/VersionAttributeSourceImpl.java @@ -36,7 +36,10 @@ import org.hibernate.metamodel.source.spi.HibernateTypeSource; import org.hibernate.metamodel.source.spi.RelationalValueSource; import org.hibernate.metamodel.source.spi.ToolingHintSource; import org.hibernate.metamodel.source.spi.VersionAttributeSource; -import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; +import org.hibernate.metamodel.spi.NaturalIdMutability; +import org.hibernate.metamodel.spi.SingularAttributeNature; /** @@ -50,8 +53,12 @@ class VersionAttributeSourceImpl private final JaxbVersionElement versionElement; private final List valueSources; + private final AttributePath attributePath; + private final AttributeRole attributeRole; + VersionAttributeSourceImpl( MappingDocument mappingDocument, + RootEntitySourceImpl rootEntitySource, final JaxbVersionElement versionElement) { super( mappingDocument ); this.versionElement = versionElement; @@ -78,6 +85,9 @@ class VersionAttributeSourceImpl } } ); + + this.attributePath = rootEntitySource.getAttributePathBase().append( getName() ); + this.attributeRole = rootEntitySource.getAttributeRoleBase().append( getName() ); } private final HibernateTypeSource typeSource = new HibernateTypeSource() { @@ -106,6 +116,16 @@ class VersionAttributeSourceImpl return versionElement.getName(); } + @Override + public AttributePath getAttributePath() { + return attributePath; + } + + @Override + public AttributeRole getAttributeRole() { + return attributeRole; + } + @Override public HibernateTypeSource getTypeInformation() { return typeSource; @@ -141,8 +161,8 @@ class VersionAttributeSourceImpl } @Override - public SingularAttributeBinding.NaturalIdMutability getNaturalIdMutability() { - return SingularAttributeBinding.NaturalIdMutability.NOT_NATURAL_ID; + public NaturalIdMutability getNaturalIdMutability() { + return NaturalIdMutability.NOT_NATURAL_ID; } @Override @@ -151,8 +171,8 @@ class VersionAttributeSourceImpl } @Override - public Nature getNature() { - return Nature.BASIC; + public SingularAttributeNature getSingularAttributeNature() { + return SingularAttributeNature.BASIC; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/AggregatedCompositeIdentifierSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/AggregatedCompositeIdentifierSource.java index 521d4893cc..bbe2709bb9 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/AggregatedCompositeIdentifierSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/AggregatedCompositeIdentifierSource.java @@ -37,5 +37,5 @@ public interface AggregatedCompositeIdentifierSource extends CompositeIdentifier * * @return The identifier attribute source. */ - public ComponentAttributeSource getIdentifierAttributeSource(); + public EmbeddedAttributeSource getIdentifierAttributeSource(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/AttributeSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/AttributeSource.java index fdccefc57e..0b9d38984f 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/AttributeSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/AttributeSource.java @@ -23,6 +23,9 @@ */ package org.hibernate.metamodel.source.spi; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; + /** * Contract for sources of persistent attribute descriptions. * @@ -36,10 +39,17 @@ public interface AttributeSource extends ToolingHintSourceContainer { */ public String getName(); + public AttributePath getAttributePath(); + public AttributeRole getAttributeRole(); + /** - * Is this a singular attribute? Specifically, can it be cast to {@link SingularAttributeSource}? - * - * @return {@code true} indicates this is castable to {@link SingularAttributeSource}; {@code false} otherwise. + * Attributes are coarsely speaking either singular or plural. This method + * reports whether this attribute is singular (false indicates it is plural + * instead). Singular attributes are castable to + * {@link org.hibernate.metamodel.source.spi.SingularAttributeSource} for + * further processing, whereas plural attributes are castable to + * {@link org.hibernate.metamodel.source.spi.PluralAttributeSource} for + * further processing. */ public boolean isSingular(); @@ -60,9 +70,10 @@ public interface AttributeSource extends ToolingHintSourceContainer { public String getPropertyAccessorName(); /** - * If the containing entity is using {@link org.hibernate.engine.OptimisticLockStyle#ALL} or - * {@link org.hibernate.engine.OptimisticLockStyle#DIRTY} style optimistic locking, should this attribute - * be used? + * If the containing entity is using optimistic locking, should this + * attribute participate in that locking? Meaning, should changes in the + * value of this attribute at runtime indicate that the entity is now dirty + * in terms of optimistic locking? * * @return {@code true} indicates it should be included; {@code false}, it should not. */ diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/AttributeSourceContainer.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/AttributeSourceContainer.java index 41fcf4238c..d05767100f 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/AttributeSourceContainer.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/AttributeSourceContainer.java @@ -25,21 +25,22 @@ package org.hibernate.metamodel.source.spi; import java.util.List; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; import org.hibernate.metamodel.spi.LocalBindingContext; /** * Contract for a container of {@link AttributeSource} references. Entities, * MappedSuperclasses and composites (Embeddables) all contain attributes. + *

+ * Think of this as the corollary to what JPA calls a ManagedType on the + * source side of things. * * @author Steve Ebersole */ public interface AttributeSourceContainer { - /** - * Obtain the path used to uniquely identify this container. - * - * @return The unique identifier path - */ - public String getPath(); + public AttributePath getAttributePathBase(); + public AttributeRole getAttributeRoleBase(); /** * Obtain this container's attribute sources. diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/CompositePluralAttributeElementSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/CollectionIdSource.java similarity index 62% rename from hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/CompositePluralAttributeElementSource.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/CollectionIdSource.java index 2615eec4a5..a73e7c6bf5 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/CompositePluralAttributeElementSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/CollectionIdSource.java @@ -1,7 +1,7 @@ /* * Hibernate, Relational Persistence for Idiomatic Java * - * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * Copyright (c) 2014, 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. @@ -23,17 +23,28 @@ */ package org.hibernate.metamodel.source.spi; -import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; - /** * @author Steve Ebersole */ -public interface CompositePluralAttributeElementSource - extends PluralAttributeElementSource, AttributeSourceContainer, CascadeStyleSource, ToolingHintSourceContainer { +public interface CollectionIdSource { + /** + * Obtain source information about the column for the collection id. + * + * @return The collection id column info. + */ + public ColumnSource getColumnSource(); - public JavaTypeDescriptor getTypeDescriptor(); + /** + * Obtain information about the Hibernate type ({@link org.hibernate.type.Type}) for the collection id + * + * @return The Hibernate type information + */ + public HibernateTypeSource getTypeInformation(); - public String getParentReferenceAttributeName(); - - public String getExplicitTuplizerClassName(); + /** + * Obtain the name of the identifier value generator. + * + * @return The identifier value generator name + */ + public String getGeneratorName(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/ComponentAttributeSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/EmbeddableSource.java similarity index 78% rename from hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/ComponentAttributeSource.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/EmbeddableSource.java index 0305723c43..1926dc60c9 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/ComponentAttributeSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/EmbeddableSource.java @@ -1,7 +1,7 @@ /* * Hibernate, Relational Persistence for Idiomatic Java * - * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * Copyright (c) 2014, 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. @@ -26,9 +26,15 @@ package org.hibernate.metamodel.source.spi; import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; /** + * Represents the binding source for an "embeddable" (in JPA terms) + * or "composite" (in legacy Hibernate terms). + *

+ * Note that this really models the JPA concept of an Embedded, more + * than the Embeddable. + * * @author Steve Ebersole */ -public interface ComponentAttributeSource extends SingularAttributeSource, AttributeSourceContainer { +public interface EmbeddableSource extends AttributeSourceContainer { public JavaTypeDescriptor getTypeDescriptor(); public String getParentReferenceAttributeName(); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/EmbeddableSourceContributor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/EmbeddableSourceContributor.java new file mode 100644 index 0000000000..fdf12e874e --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/EmbeddableSourceContributor.java @@ -0,0 +1,38 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2014, 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.metamodel.source.spi; + +/** + * Contract for things that can contain EmbeddableSource definitions. + * + * @author Steve Ebersole + */ +public interface EmbeddableSourceContributor { + /** + * Gets the source information about the embeddable/composition. + * + * @return The EmbeddableSource + */ + public EmbeddableSource getEmbeddableSource(); +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/EmbeddedAttributeSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/EmbeddedAttributeSource.java new file mode 100644 index 0000000000..9405a7a620 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/EmbeddedAttributeSource.java @@ -0,0 +1,33 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.metamodel.source.spi; + +/** + * Represents the binding source for a singular attribute that is "embedded" + * or "composite". + * + * @author Steve Ebersole + */ +public interface EmbeddedAttributeSource extends SingularAttributeSource, EmbeddableSourceContributor { +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/IndexedPluralAttributeSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/IndexedPluralAttributeSource.java index 9e9f602dc6..930985debd 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/IndexedPluralAttributeSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/IndexedPluralAttributeSource.java @@ -26,9 +26,6 @@ package org.hibernate.metamodel.source.spi; /** * */ -public interface IndexedPluralAttributeSource extends PluralAttributeSource, PluralAttributeIndexSourceResolver { - - PluralAttributeIndexSource resolvePluralAttributeIndexSource(AttributeSourceResolutionContext context); - +public interface IndexedPluralAttributeSource extends PluralAttributeSource { PluralAttributeIndexSource getIndexSource(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeElementSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeElementSource.java index f1eec01cc1..dd4b4d39a9 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeElementSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeElementSource.java @@ -23,33 +23,12 @@ */ package org.hibernate.metamodel.source.spi; +import org.hibernate.metamodel.spi.PluralAttributeElementNature; + /** * @author Steve Ebersole * @author Gail Badner */ public interface PluralAttributeElementSource { - public Nature getNature(); - - /** - * Describes the nature of the collection elements as declared by the metadata. - * - * @author Steve Ebersole - */ - enum Nature { - BASIC( false ), - AGGREGATE( false ), - ONE_TO_MANY( true ), - MANY_TO_MANY( true ), - MANY_TO_ANY( true ); - - private final boolean isAssociation; - - private Nature(boolean isAssociation) { - this.isAssociation = isAssociation; - } - - public boolean isAssociation() { - return isAssociation; - } - } + public PluralAttributeElementNature getNature(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/AssociationPluralAttributeElementSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeElementSourceAssociation.java similarity index 92% rename from hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/AssociationPluralAttributeElementSource.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeElementSourceAssociation.java index 07b40eef67..fc729c0579 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/AssociationPluralAttributeElementSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeElementSourceAssociation.java @@ -24,7 +24,7 @@ package org.hibernate.metamodel.source.spi; /** - + * @author Gail Badner - + */ -public interface AssociationPluralAttributeElementSource extends PluralAttributeElementSource, AssociationSource { + * @author Gail Badner + */ +public interface PluralAttributeElementSourceAssociation extends PluralAttributeElementSource, AssociationSource { } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/BasicPluralAttributeElementSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeElementSourceBasic.java similarity index 86% rename from hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/BasicPluralAttributeElementSource.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeElementSourceBasic.java index 3dca3238bf..984785501c 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/BasicPluralAttributeElementSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeElementSourceBasic.java @@ -24,9 +24,11 @@ package org.hibernate.metamodel.source.spi; /** + * Describes the source for the elements of persistent collections (plural + * attributes) where the elements are basic types + * * @author Steve Ebersole */ -public interface BasicPluralAttributeElementSource extends PluralAttributeElementSource, RelationalValueSourceContainer { - +public interface PluralAttributeElementSourceBasic extends PluralAttributeElementSource, RelationalValueSourceContainer { public HibernateTypeSource getExplicitHibernateTypeSource(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeElementSourceEmbedded.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeElementSourceEmbedded.java new file mode 100644 index 0000000000..4cce967a72 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeElementSourceEmbedded.java @@ -0,0 +1,35 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.metamodel.source.spi; + +/** + * Describes the source for the elements of persistent collections (plural + * attributes) where the elements are composites/embeddables. + * + * @author Steve Ebersole + */ +public interface PluralAttributeElementSourceEmbedded + extends PluralAttributeElementSource, + EmbeddableSourceContributor, CascadeStyleSource, ToolingHintSourceContainer { +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeElementSourceManyToAny.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeElementSourceManyToAny.java new file mode 100644 index 0000000000..609ea26adf --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeElementSourceManyToAny.java @@ -0,0 +1,34 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.metamodel.source.spi; + +/** + * Describes the source for the elements of persistent collections (plural + * attributes) where the elements are defined by Hibernate's any mapping + * + * @author Steve Ebersole + */ +public interface PluralAttributeElementSourceManyToAny + extends PluralAttributeElementSource, AssociationSource { +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/ManyToManyPluralAttributeElementSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeElementSourceManyToMany.java similarity index 89% rename from hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/ManyToManyPluralAttributeElementSource.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeElementSourceManyToMany.java index ca5937f680..d299d674ae 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/ManyToManyPluralAttributeElementSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeElementSourceManyToMany.java @@ -26,9 +26,12 @@ package org.hibernate.metamodel.source.spi; import org.hibernate.engine.FetchTiming; /** + * Describes the source for the elements of persistent collections (plural + * attributes) where the elements are many-to-many association + * * @author Steve Ebersole */ -public interface ManyToManyPluralAttributeElementSource +public interface PluralAttributeElementSourceManyToMany extends PluralAttributeElementSource, AssociationSource, RelationalValueSourceContainer, ForeignKeyContributingSource, Orderable { public String getReferencedEntityName(); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/OneToManyPluralAttributeElementSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeElementSourceOneToMany.java similarity index 85% rename from hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/OneToManyPluralAttributeElementSource.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeElementSourceOneToMany.java index 3e770bde7a..ed74ef81bd 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/OneToManyPluralAttributeElementSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeElementSourceOneToMany.java @@ -24,9 +24,12 @@ package org.hibernate.metamodel.source.spi; /** + * Describes the source for the elements of persistent collections (plural + * attributes) where the elements are a one-to-many association + * * @author Steve Ebersole */ -public interface OneToManyPluralAttributeElementSource extends PluralAttributeElementSource, AssociationSource { +public interface PluralAttributeElementSourceOneToMany extends PluralAttributeElementSource, AssociationSource { public String getReferencedEntityName(); public boolean isIgnoreNotFound(); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeIndexSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeIndexSource.java index df6487cb62..367044fc27 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeIndexSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeIndexSource.java @@ -26,13 +26,18 @@ package org.hibernate.metamodel.source.spi; import java.util.List; import org.hibernate.metamodel.internal.binder.Binder; -import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding; +import org.hibernate.metamodel.spi.PluralAttributeIndexNature; /** + * Highly abstract concept of the index of an "indexed persistent collection". + * More concretely (and generally more usefully) categorized as either:

    + *
  • {@link PluralAttributeSequentialIndexSource} - for list/array indexes
  • + *
  • {@link PluralAttributeMapKeySource} - for map keys
  • + *
* */ public interface PluralAttributeIndexSource extends RelationalValueSourceContainer { - PluralAttributeIndexBinding.Nature getNature(); + PluralAttributeIndexNature getNature(); List getDefaultNamingStrategies(); /** * Obtain information about the Hibernate index type ({@link org.hibernate.type.Type}) @@ -42,15 +47,4 @@ public interface PluralAttributeIndexSource extends RelationalValueSourceContain */ public HibernateTypeSource getTypeInformation(); - /** - * Is this plural attribute index source for an attribute of the referenced entity - * (relevant only for one-to-many and many-to-many associations)? - * - * If this method returns {@code true}, then this object can safely - * be cast to EntityAttributePluralAttributeIndexSource. - * - * @return true, if this plural attribute index source for an attribute of the referenced - * entity; false, otherwise. - */ - public boolean isReferencedEntityAttribute(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeIndexSourceResolver.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeIndexSourceResolver.java index 037250574e..06fae6b0b1 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeIndexSourceResolver.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeIndexSourceResolver.java @@ -27,5 +27,5 @@ package org.hibernate.metamodel.source.spi; * @author Gail Badner */ public interface PluralAttributeIndexSourceResolver { - PluralAttributeElementSource resolvePluralAttributeElementSource(AttributeSourceResolutionContext context); + PluralAttributeIndexSource resolvePluralAttributeIndexSource(AttributeSourceResolutionContext context); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeMapKeySource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeMapKeySource.java new file mode 100644 index 0000000000..b08af902ef --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeMapKeySource.java @@ -0,0 +1,64 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2014, 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.metamodel.source.spi; + +/** + * Describes source information about the key of a persistent map. At high + * level this broken down further into 2 categories:
    + *
  • {@link PluralAttributeMapKeySourceEntityAttribute}
  • + *
  • + *
      + *
    • {@link PluralAttributeMapKeySourceBasic}
    • + *
    • {@link PluralAttributeMapKeySourceEmbedded}
    • + *
    • {@link PluralAttributeMapKeySourceToOne}
    • + *
    + *
  • + *
+ *

+ * {@link PluralAttributeMapKeySourceEntityAttribute} is only relevant from + * annotations when using {@link javax.persistence.MapKey}. + * + * @author Steve Ebersole + */ +public interface PluralAttributeMapKeySource extends PluralAttributeIndexSource { + public static enum Nature { + BASIC, + EMBEDDED, + TO_ONE + } + + public Nature getMapKeyNature(); + + /** + * Is this plural attribute index source for an attribute of the referenced entity + * (relevant only for one-to-many and many-to-many associations)? + * + * If this method returns {@code true}, then this object can safely + * be cast to {@link PluralAttributeMapKeySourceEntityAttribute}. + * + * @return true, if this plural attribute index source for an attribute of the referenced + * entity; false, otherwise. + */ + public boolean isReferencedEntityAttribute(); +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/BasicPluralAttributeIndexSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeMapKeySourceBasic.java similarity index 92% rename from hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/BasicPluralAttributeIndexSource.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeMapKeySourceBasic.java index 7d4a9a647b..f9bc9ed7fe 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/BasicPluralAttributeIndexSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeMapKeySourceBasic.java @@ -26,5 +26,5 @@ package org.hibernate.metamodel.source.spi; /** * @author Gail Badner */ -public interface BasicPluralAttributeIndexSource extends PluralAttributeIndexSource { +public interface PluralAttributeMapKeySourceBasic extends PluralAttributeIndexSource { } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/SequentialPluralAttributeIndexSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeMapKeySourceEmbedded.java similarity index 90% rename from hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/SequentialPluralAttributeIndexSource.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeMapKeySourceEmbedded.java index 241df0c127..9d1cb9a88f 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/SequentialPluralAttributeIndexSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeMapKeySourceEmbedded.java @@ -26,6 +26,6 @@ package org.hibernate.metamodel.source.spi; /** * @author Gail Badner */ -public interface SequentialPluralAttributeIndexSource extends BasicPluralAttributeIndexSource { - int base(); +public interface PluralAttributeMapKeySourceEmbedded + extends PluralAttributeIndexSource, EmbeddableSourceContributor { } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/CompositePluralAttributeIndexSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeMapKeySourceEntityAttribute.java similarity index 64% rename from hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/CompositePluralAttributeIndexSource.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeMapKeySourceEntityAttribute.java index 51320b9604..dbd0a1fece 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/CompositePluralAttributeIndexSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeMapKeySourceEntityAttribute.java @@ -23,13 +23,22 @@ */ package org.hibernate.metamodel.source.spi; -import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; - /** + * Represents a map key where the map key value is actually the attribute value + * from the referenced entity. + * + * Only relevant to one-to-many and many-to-many associations mapped using + * the JPA {@link javax.persistence.MapKey} annotation. + * * @author Gail Badner + * @author Steve Ebersole */ -public interface CompositePluralAttributeIndexSource - extends PluralAttributeIndexSource, AttributeSourceContainer { - - public JavaTypeDescriptor getTypeDescriptor(); +public interface PluralAttributeMapKeySourceEntityAttribute extends PluralAttributeIndexSource { + /** + * The attribute name as reported by {@link javax.persistence.MapKey#name()} + * + * @return The attribute name; {@code null} indicates that the associated entity's + * id attribute should be used. + */ + public String getAttributeName(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/ManyToAnyPluralAttributeElementSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeMapKeySourceToOne.java similarity index 85% rename from hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/ManyToAnyPluralAttributeElementSource.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeMapKeySourceToOne.java index ee5da01d04..82625a82b3 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/ManyToAnyPluralAttributeElementSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeMapKeySourceToOne.java @@ -1,7 +1,7 @@ /* * Hibernate, Relational Persistence for Idiomatic Java * - * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * Copyright (c) 2014, 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. @@ -26,6 +26,5 @@ package org.hibernate.metamodel.source.spi; /** * @author Steve Ebersole */ -public interface ManyToAnyPluralAttributeElementSource - extends PluralAttributeElementSource, AssociationSource { +public interface PluralAttributeMapKeySourceToOne extends PluralAttributeMapKeySource { } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/EntityAttributePluralAttributeIndexSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeSequentialIndexSource.java similarity index 75% rename from hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/EntityAttributePluralAttributeIndexSource.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeSequentialIndexSource.java index c842bd034f..0c9e156a46 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/EntityAttributePluralAttributeIndexSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeSequentialIndexSource.java @@ -24,12 +24,17 @@ package org.hibernate.metamodel.source.spi; /** - * Represents a plural attribute index source that is an attribute - * of the referenced entity (relevant only to one-to-many and many-to-many - * associations). + * Defines the index of a persistent list/array * * @author Gail Badner + * @author Steve Ebersole */ -public interface EntityAttributePluralAttributeIndexSource extends PluralAttributeIndexSource { - public String getAttributeName(); +public interface PluralAttributeSequentialIndexSource extends PluralAttributeIndexSource { + /** + * Hibernate allows specifying the base value to use when storing the index + * to the database. This reports that "offset" value. + * + * @return The index base value. + */ + int base(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeSource.java index fce5f61fbe..cd2e8c6ee2 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/PluralAttributeSource.java @@ -23,12 +23,8 @@ */ package org.hibernate.metamodel.source.spi; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Set; - import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; +import org.hibernate.metamodel.spi.PluralAttributeNature; import org.hibernate.metamodel.spi.binding.Caching; import org.hibernate.metamodel.spi.binding.CustomSQL; @@ -37,7 +33,9 @@ import org.hibernate.metamodel.spi.binding.CustomSQL; */ public interface PluralAttributeSource extends AttributeSource, FetchableAttributeSource, PluralAttributeElementSourceResolver { - public Nature getNature(); + public PluralAttributeNature getNature(); + + public CollectionIdSource getCollectionIdSource(); public PluralAttributeKeySource getKeySource(); @@ -79,27 +77,4 @@ public interface PluralAttributeSource public boolean usesJoinTable(); - /** - * Describes the nature of the collection itself as declared by the metadata. - * - * @author Steve Ebersole - */ - enum Nature { - BAG( Collection.class ), - ID_BAG( Collection.class ), - SET( Set.class ), - LIST( List.class ), - MAP( Map.class ), - ARRAY( Object[].class ); - - private final Class reportedJavaType; - - Nature(Class reportedJavaType) { - this.reportedJavaType = reportedJavaType; - } - - public Class reportedJavaType() { - return reportedJavaType; - } - } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/SingularAttributeSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/SingularAttributeSource.java index 86a400c6d1..ece7413687 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/SingularAttributeSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/SingularAttributeSource.java @@ -24,7 +24,8 @@ package org.hibernate.metamodel.source.spi; import org.hibernate.mapping.PropertyGeneration; -import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; +import org.hibernate.metamodel.spi.NaturalIdMutability; +import org.hibernate.metamodel.spi.SingularAttributeNature; /** * Source-agnostic description of information needed to bind a singular attribute. @@ -45,7 +46,7 @@ public interface SingularAttributeSource extends AttributeSource, AttributeRelat * * @return The attribute type nature */ - public Nature getNature(); + public SingularAttributeNature getSingularAttributeNature(); /** * Obtain a description of if/when the attribute value is generated by the database. @@ -66,21 +67,6 @@ public interface SingularAttributeSource extends AttributeSource, AttributeRelat * * @return The mutability, see enum for meanings */ - public SingularAttributeBinding.NaturalIdMutability getNaturalIdMutability(); + public NaturalIdMutability getNaturalIdMutability(); - /** - * Describes the understood natures of a singular attribute. - * - * @author Steve Ebersole - */ - enum Nature { - BASIC, - // TODO: COMPOSITE should be changed to AGGREGATE - // when non-aggregated composite IDs are no longer - // modelled as an AttributeBinding - COMPOSITE, - MANY_TO_ONE, - ONE_TO_ONE, - ANY - } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/AbstractAttributeKey.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/AbstractAttributeKey.java similarity index 98% rename from hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/AbstractAttributeKey.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/spi/AbstractAttributeKey.java index 9b61e1ac81..7f2eda3d70 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/AbstractAttributeKey.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/AbstractAttributeKey.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.source.spi; +package org.hibernate.metamodel.spi; import org.hibernate.internal.util.StringHelper; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/AttributePath.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/AttributePath.java similarity index 81% rename from hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/AttributePath.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/spi/AttributePath.java index 6a6bf3c9c3..b3538d4368 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/AttributePath.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/AttributePath.java @@ -21,9 +21,13 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.source.spi; +package org.hibernate.metamodel.spi; /** + * An attribute path is, generally speaking, the path of attribute names back + * to a "root" (which is either an entity or a persistent collection). The + * name of this root typically is not included in the path. + * * @author Steve Ebersole */ public class AttributePath extends AbstractAttributeKey { @@ -43,6 +47,11 @@ public class AttributePath extends AbstractAttributeKey { return new AttributePath( this, property ); } + @Override + public AttributePath getParent() { + return (AttributePath) super.getParent(); + } + public AttributePath(AttributePath parent, String property) { super( parent, property ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/AttributeRole.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/AttributeRole.java similarity index 81% rename from hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/AttributeRole.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/spi/AttributeRole.java index e87d17dfae..e0c9e39b6e 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/AttributeRole.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/AttributeRole.java @@ -21,9 +21,13 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.source.spi; +package org.hibernate.metamodel.spi; /** + * An attribute role is, generally speaking, the path of attribute names back + * to a "root" (which is either an entity or a persistent collection). The + * name of this root typically is included in the path. + * * @author Steve Ebersole */ public class AttributeRole extends AbstractAttributeKey { @@ -43,6 +47,11 @@ public class AttributeRole extends AbstractAttributeKey { return new AttributeRole( this, property ); } + @Override + public AttributeRole getParent() { + return (AttributeRole) super.getParent(); + } + private AttributeRole(AttributeRole parent, String property) { super( parent, property ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/NaturalIdMutability.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/NaturalIdMutability.java new file mode 100644 index 0000000000..d6a86d5ca6 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/NaturalIdMutability.java @@ -0,0 +1,45 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2014, 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.metamodel.spi; + +/** + * A ternary boolean enum for describing the mutability aspects of an + * attribute as a natural id. + * + * @author Steve Ebersole + */ +public enum NaturalIdMutability { + /** + * The attribute is part of a mutable natural id + */ + MUTABLE, + /** + * The attribute is part of a immutable natural id + */ + IMMUTABLE, + /** + * The attribute is not part of any kind of natural id. + */ + NOT_NATURAL_ID +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/PluralAttributeElementNature.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/PluralAttributeElementNature.java new file mode 100644 index 0000000000..786a67f04e --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/PluralAttributeElementNature.java @@ -0,0 +1,73 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2014, 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.metamodel.spi; + +/** + * Describes the nature of plural attribute elements in terms of relational implications. + * + * @author Steve Ebersole + * @author Gail Badner + */ +public enum PluralAttributeElementNature { + /** + * The collection elements are basic, simple values. + */ + BASIC( false, false ), + /** + * The collection elements are compositions. + */ + AGGREGATE( false, true ), + /** + * The collection elements represent entity's in a one-to-many association. + */ + ONE_TO_MANY, + /** + * The collection elements represent entity's in a many-to-many association. + */ + MANY_TO_MANY, + /** + * The collection elements represent entity's in a multi-valued ANY mapping. + */ + MANY_TO_ANY; + + private final boolean isAssociation; + private final boolean isCascadeable; + + PluralAttributeElementNature() { + this( true, true ); + } + + PluralAttributeElementNature(boolean association, boolean cascadeable) { + this.isAssociation = association; + this.isCascadeable = cascadeable; + } + + public boolean isAssociation() { + return isAssociation; + } + + public boolean isCascadeable() { + return isCascadeable; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/PluralAttributeIndexNature.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/PluralAttributeIndexNature.java new file mode 100644 index 0000000000..3206beabe1 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/PluralAttributeIndexNature.java @@ -0,0 +1,52 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2014, 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.metamodel.spi; + +/** + * Describes the nature of plural attribute indexes in terms of relational implications. + * + * @author Steve Ebersole + */ +public enum PluralAttributeIndexNature { + /** + * A sequential array/list index + */ + SEQUENTIAL, + /** + * The collection indexes are basic, simple values. + */ + BASIC, + /** + * The map key is an aggregated composite + */ + AGGREGATE, + /** + * The map key is an association identified by a column(s) on the collection table. + */ + MANY_TO_MANY, + /** + * The map key is represented by a Hibernate ANY mapping + */ + MANY_TO_ANY +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/VersionAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/PluralAttributeNature.java similarity index 55% rename from hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/VersionAttributeSourceImpl.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/spi/PluralAttributeNature.java index ae563b6956..af659e8ce1 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/VersionAttributeSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/PluralAttributeNature.java @@ -21,34 +21,39 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.source.internal; +package org.hibernate.metamodel.spi; -import org.hibernate.metamodel.source.internal.annotations.attribute.BasicAttribute; -import org.hibernate.metamodel.source.spi.VersionAttributeSource; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Set; /** - * Represents source of version attribute information for binding + * Describes the nature of the collection itself as declared by the metadata. * * @author Steve Ebersole */ -public class VersionAttributeSourceImpl - extends BasicAttributeSourceImpl - implements VersionAttributeSource { +public enum PluralAttributeNature { + BAG( Collection.class, false ), + ID_BAG( Collection.class, false ), + SET( Set.class, false ), + LIST( List.class, true ), + ARRAY( Object[].class, true ), + MAP( Map.class, true ); - protected VersionAttributeSourceImpl(AbstractManagedTypeSource container, BasicAttribute attribute) { - super( container, attribute ); + private final boolean indexed; + private final Class reportedJavaType; + + PluralAttributeNature(Class reportedJavaType, boolean indexed) { + this.reportedJavaType = reportedJavaType; + this.indexed = indexed; } - @Override - protected void validateConversionInfo(AttributeConversionInfo conversionInfo) { - throw getContainer().getLocalBindingContext().makeMappingException( - "Illegal attempt to specify AttributeConverter for version attribute : " - + getPersistentAttribute().getBackingMember().toString() - ); + public Class reportedJavaType() { + return reportedJavaType; } - @Override - public String getUnsavedValue() { - return null; + public boolean isIndexed() { + return indexed; } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/SingularAttributeNature.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/SingularAttributeNature.java new file mode 100644 index 0000000000..909fd58e65 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/SingularAttributeNature.java @@ -0,0 +1,40 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2014, 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.metamodel.spi; + +/** + * Describes the understood natures of a singular attribute. + * + * @author Steve Ebersole + */ +public enum SingularAttributeNature { + BASIC, + // TODO: COMPOSITE should be changed to AGGREGATE + // when non-aggregated composite IDs are no longer + // modelled as an AttributeBinding + COMPOSITE, + MANY_TO_ONE, + ONE_TO_ONE, + ANY +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractAttributeBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractAttributeBinding.java index 3ad8dc6c77..553c207f04 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractAttributeBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractAttributeBinding.java @@ -28,6 +28,8 @@ import java.util.HashSet; import java.util.Set; import org.hibernate.metamodel.source.spi.MetaAttributeContext; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; import org.hibernate.metamodel.spi.domain.Attribute; /** @@ -47,21 +49,27 @@ public abstract class AbstractAttributeBinding implements AttributeBinding { private boolean isAlternateUniqueKey; + private final AttributeRole attributeRole; + private final AttributePath attributePath; + private final MetaAttributeContext metaAttributeContext; - private final String attributePath; protected AbstractAttributeBinding( AttributeBindingContainer container, Attribute attribute, String propertyAccessorName, boolean includedInOptimisticLocking, - MetaAttributeContext metaAttributeContext) { + MetaAttributeContext metaAttributeContext, + AttributeRole attributeRole, + AttributePath attributePath) { this.container = container; this.attribute = attribute; this.propertyAccessorName = propertyAccessorName; this.includedInOptimisticLocking = includedInOptimisticLocking; this.metaAttributeContext = metaAttributeContext; - this.attributePath = getContainer().getPathBase() + '.' + getAttribute().getName(); + + this.attributeRole = attributeRole; + this.attributePath = attributePath; } @Override @@ -75,10 +83,15 @@ public abstract class AbstractAttributeBinding implements AttributeBinding { } @Override - public String getAttributePath() { + public AttributePath getAttributePath() { return attributePath; } + @Override + public AttributeRole getAttributeRole() { + return attributeRole; + } + @Override public HibernateTypeDescriptor getHibernateTypeDescriptor() { return hibernateTypeDescriptor; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractAttributeBindingContainer.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractAttributeBindingContainer.java index 19c3b12fe5..3848e15458 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractAttributeBindingContainer.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractAttributeBindingContainer.java @@ -28,10 +28,17 @@ import java.util.Map; import org.hibernate.mapping.PropertyGeneration; import org.hibernate.metamodel.source.spi.MetaAttributeContext; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; +import org.hibernate.metamodel.spi.NaturalIdMutability; +import org.hibernate.metamodel.spi.PluralAttributeElementNature; +import org.hibernate.metamodel.spi.PluralAttributeIndexNature; +import org.hibernate.metamodel.spi.PluralAttributeNature; import org.hibernate.metamodel.spi.domain.PluralAttribute; import org.hibernate.metamodel.spi.domain.SingularAttribute; import org.hibernate.metamodel.spi.relational.TableSpecification; import org.hibernate.metamodel.spi.relational.Value; +import org.hibernate.tuple.component.ComponentTuplizer; /** * @author Gail Badner @@ -101,8 +108,10 @@ public abstract class AbstractAttributeBindingContainer implements AttributeBind String propertyAccessorName, boolean includedInOptimisticLocking, boolean lazy, - SingularAttributeBinding.NaturalIdMutability naturalIdMutability, + NaturalIdMutability naturalIdMutability, MetaAttributeContext metaAttributeContext, + AttributeRole attributeRole, + AttributePath attributePath, PropertyGeneration generation) { final BasicAttributeBinding binding = new BasicAttributeBinding( this, @@ -113,6 +122,8 @@ public abstract class AbstractAttributeBindingContainer implements AttributeBind lazy, naturalIdMutability, metaAttributeContext, + attributeRole, + attributePath, generation ); registerAttributeBinding( binding ); @@ -125,25 +136,30 @@ public abstract class AbstractAttributeBindingContainer implements AttributeBind } @Override - public CompositeAttributeBinding makeAggregatedCompositeAttributeBinding( + public EmbeddedAttributeBinding makeAggregatedCompositeAttributeBinding( SingularAttribute attribute, SingularAttribute parentReferenceAttribute, + Class tuplizerClass, String propertyAccessorName, boolean includedInOptimisticLocking, boolean lazy, - SingularAttributeBinding.NaturalIdMutability naturalIdMutability, - MetaAttributeContext metaAttributeContext) { - final CompositeAttributeBinding binding = - CompositeAttributeBinding.createAggregatedCompositeAttributeBinding( - this, - attribute, - propertyAccessorName, - includedInOptimisticLocking, - lazy, - naturalIdMutability, - metaAttributeContext, - parentReferenceAttribute - ); + NaturalIdMutability naturalIdMutability, + MetaAttributeContext metaAttributeContext, + AttributeRole attributeRole, + AttributePath attributePath) { + final EmbeddedAttributeBinding binding = EmbeddedAttributeBinding.createEmbeddedAttributeBinding( + this, + attribute, + propertyAccessorName, + includedInOptimisticLocking, + lazy, + naturalIdMutability, + metaAttributeContext, + attributeRole, + attributePath, + parentReferenceAttribute, + tuplizerClass + ); registerAttributeBinding( binding ); return binding; } @@ -154,8 +170,10 @@ public abstract class AbstractAttributeBindingContainer implements AttributeBind String propertyAccessorName, boolean includedInOptimisticLocking, boolean lazy, - SingularAttributeBinding.NaturalIdMutability naturalIdMutability, + NaturalIdMutability naturalIdMutability, MetaAttributeContext metaAttributeContext, + AttributeRole attributeRole, + AttributePath attributePath, EntityBinding referencedEntityBinding, SingularAttributeBinding referencedAttributeBinding, boolean isConstrained) { @@ -167,6 +185,8 @@ public abstract class AbstractAttributeBindingContainer implements AttributeBind lazy, naturalIdMutability, metaAttributeContext, + attributeRole, + attributePath, referencedEntityBinding, referencedAttributeBinding, isConstrained @@ -182,8 +202,10 @@ public abstract class AbstractAttributeBindingContainer implements AttributeBind boolean includedInOptimisticLocking, boolean lazy, boolean isIgnoreNotFound, - SingularAttributeBinding.NaturalIdMutability naturalIdMutability, + NaturalIdMutability naturalIdMutability, MetaAttributeContext metaAttributeContext, + AttributeRole attributeRole, + AttributePath attributePath, EntityBinding referencedEntityBinding, SingularAttributeBinding referencedAttributeBinding) { final ManyToOneAttributeBinding binding = new ManyToOneAttributeBinding( @@ -195,6 +217,8 @@ public abstract class AbstractAttributeBindingContainer implements AttributeBind isIgnoreNotFound, naturalIdMutability, metaAttributeContext, + attributeRole, + attributePath, referencedEntityBinding, referencedAttributeBinding ); @@ -205,12 +229,14 @@ public abstract class AbstractAttributeBindingContainer implements AttributeBind @Override public BagBinding makeBagAttributeBinding( PluralAttribute attribute, - PluralAttributeElementBinding.Nature nature, + PluralAttributeElementNature nature, SingularAttributeBinding referencedAttributeBinding, String propertyAccessorName, boolean includedInOptimisticLocking, - MetaAttributeContext metaAttributeContext) { - Helper.checkPluralAttributeNature( attribute, PluralAttribute.Nature.BAG ); + MetaAttributeContext metaAttributeContext, + AttributeRole attributeRole, + AttributePath attributePath) { + Helper.checkPluralAttributeNature( attribute, PluralAttributeNature.BAG ); final BagBinding binding = new BagBinding( this, attribute, @@ -218,7 +244,9 @@ public abstract class AbstractAttributeBindingContainer implements AttributeBind referencedAttributeBinding, propertyAccessorName, includedInOptimisticLocking, - metaAttributeContext + metaAttributeContext, + attributeRole, + attributePath ); registerAttributeBinding( binding ); return binding; @@ -227,13 +255,15 @@ public abstract class AbstractAttributeBindingContainer implements AttributeBind @Override public ListBinding makeListAttributeBinding( PluralAttribute attribute, - PluralAttributeElementBinding.Nature nature, + PluralAttributeElementNature nature, SingularAttributeBinding referencedAttributeBinding, String propertyAccessorName, boolean includedInOptimisticLocking, MetaAttributeContext metaAttributeContext, + AttributeRole attributeRole, + AttributePath attributePath, int base) { - Helper.checkPluralAttributeNature( attribute, PluralAttribute.Nature.LIST ); + Helper.checkPluralAttributeNature( attribute, PluralAttributeNature.LIST ); final ListBinding binding = new ListBinding( this, attribute, @@ -242,7 +272,10 @@ public abstract class AbstractAttributeBindingContainer implements AttributeBind propertyAccessorName, includedInOptimisticLocking, metaAttributeContext, - base ); + attributeRole, + attributePath, + base + ); registerAttributeBinding( binding ); return binding; } @@ -250,13 +283,15 @@ public abstract class AbstractAttributeBindingContainer implements AttributeBind @Override public ArrayBinding makeArrayAttributeBinding( PluralAttribute attribute, - PluralAttributeElementBinding.Nature nature, + PluralAttributeElementNature nature, SingularAttributeBinding referencedAttributeBinding, String propertyAccessorName, boolean includedInOptimisticLocking, MetaAttributeContext metaAttributeContext, + AttributeRole attributeRole, + AttributePath attributePath, int base) { - Helper.checkPluralAttributeNature( attribute, PluralAttribute.Nature.ARRAY ); + Helper.checkPluralAttributeNature( attribute, PluralAttributeNature.ARRAY ); final ArrayBinding binding = new ArrayBinding( this, attribute, @@ -265,7 +300,10 @@ public abstract class AbstractAttributeBindingContainer implements AttributeBind propertyAccessorName, includedInOptimisticLocking, metaAttributeContext, - base ); + attributeRole, + attributePath, + base + ); registerAttributeBinding( binding ); return binding; } @@ -273,13 +311,15 @@ public abstract class AbstractAttributeBindingContainer implements AttributeBind @Override public MapBinding makeMapAttributeBinding( PluralAttribute attribute, - PluralAttributeElementBinding.Nature elementNature, - PluralAttributeIndexBinding.Nature indexNature, + PluralAttributeElementNature elementNature, + PluralAttributeIndexNature indexNature, SingularAttributeBinding referencedAttributeBinding, String propertyAccessorName, boolean includedInOptimisticLocking, - MetaAttributeContext metaAttributeContext) { - Helper.checkPluralAttributeNature( attribute, PluralAttribute.Nature.MAP ); + MetaAttributeContext metaAttributeContext, + AttributeRole attributeRole, + AttributePath attributePath) { + Helper.checkPluralAttributeNature( attribute, PluralAttributeNature.MAP ); final MapBinding binding = new MapBinding( this, attribute, @@ -288,7 +328,10 @@ public abstract class AbstractAttributeBindingContainer implements AttributeBind referencedAttributeBinding, propertyAccessorName, includedInOptimisticLocking, - metaAttributeContext ); + metaAttributeContext, + attributeRole, + attributePath + ); registerAttributeBinding( binding ); return binding; } @@ -296,12 +339,14 @@ public abstract class AbstractAttributeBindingContainer implements AttributeBind @Override public SetBinding makeSetAttributeBinding( PluralAttribute attribute, - PluralAttributeElementBinding.Nature nature, + PluralAttributeElementNature nature, SingularAttributeBinding referencedAttributeBinding, String propertyAccessorName, boolean includedInOptimisticLocking, - MetaAttributeContext metaAttributeContext) { - Helper.checkPluralAttributeNature( attribute, PluralAttribute.Nature.SET ); + MetaAttributeContext metaAttributeContext, + AttributeRole attributeRole, + AttributePath attributePath) { + Helper.checkPluralAttributeNature( attribute, PluralAttributeNature.SET ); final SetBinding binding = new SetBinding( this, attribute, @@ -309,7 +354,9 @@ public abstract class AbstractAttributeBindingContainer implements AttributeBind referencedAttributeBinding, propertyAccessorName, includedInOptimisticLocking, - metaAttributeContext + metaAttributeContext, + attributeRole, + attributePath ); registerAttributeBinding( binding ); return binding; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractCompositeAttributeBindingContainer.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractEmbeddableBinding.java similarity index 75% rename from hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractCompositeAttributeBindingContainer.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractEmbeddableBinding.java index f901f0eb59..18f752b13e 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractCompositeAttributeBindingContainer.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractEmbeddableBinding.java @@ -27,6 +27,11 @@ import java.util.List; import org.hibernate.mapping.PropertyGeneration; import org.hibernate.metamodel.source.spi.MetaAttributeContext; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; +import org.hibernate.metamodel.spi.NaturalIdMutability; +import org.hibernate.metamodel.spi.PluralAttributeElementNature; +import org.hibernate.metamodel.spi.PluralAttributeIndexNature; import org.hibernate.metamodel.spi.domain.AttributeContainer; import org.hibernate.metamodel.spi.domain.PluralAttribute; import org.hibernate.metamodel.spi.domain.SingularAttribute; @@ -37,30 +42,37 @@ import org.hibernate.tuple.component.ComponentTuplizer; * A container for attribute bindings that make up composite grouping * * @author Gail Badner + * @author Steve Ebersole */ -public abstract class AbstractCompositeAttributeBindingContainer +public abstract class AbstractEmbeddableBinding extends AbstractAttributeBindingContainer - implements CompositeAttributeBindingContainer { + implements EmbeddableBinding { private final EntityBinding entityBinding; private final AttributeContainer attributeContainer; private final TableSpecification primaryTable; - private final String path; + private final AttributeRole roleBase; + private final AttributePath pathBase; private final MetaAttributeContext metaAttributeContext; private final SingularAttribute parentReference; + private final Class tuplizerClass; - protected AbstractCompositeAttributeBindingContainer( + protected AbstractEmbeddableBinding( EntityBinding entityBinding, AttributeContainer attributeContainer, TableSpecification primaryTable, - String path, + AttributeRole roleBase, + AttributePath pathBase, MetaAttributeContext metaAttributeContext, - SingularAttribute parentReference) { + SingularAttribute parentReference, + Class tuplizerClass) { this.entityBinding = entityBinding; this.attributeContainer = attributeContainer; this.primaryTable = primaryTable; - this.path = path; + this.roleBase = roleBase; + this.pathBase = pathBase; this.metaAttributeContext = metaAttributeContext; this.parentReference = parentReference; + this.tuplizerClass = tuplizerClass; } public SingularAttribute getParentReference() { @@ -68,8 +80,13 @@ public abstract class AbstractCompositeAttributeBindingContainer } @Override - public String getPathBase() { - return path; + public AttributePath getPathBase() { + return pathBase; + } + + @Override + public AttributeRole getRoleBase() { + return roleBase; } @Override @@ -94,7 +111,7 @@ public abstract class AbstractCompositeAttributeBindingContainer @Override public Class getCustomTuplizerClass() { - return null; + return tuplizerClass; } protected abstract boolean isModifiable(); @@ -112,8 +129,10 @@ public abstract class AbstractCompositeAttributeBindingContainer String propertyAccessorName, boolean includedInOptimisticLocking, boolean lazy, - SingularAttributeBinding.NaturalIdMutability naturalIdMutability, + NaturalIdMutability naturalIdMutability, MetaAttributeContext metaAttributeContext, + AttributeRole attributeRole, + AttributePath attributePath, PropertyGeneration generation) { if ( !isModifiable() ) { throw new UnsupportedOperationException( "Attribute bindings are read-only and cannot be modified." ); @@ -126,30 +145,37 @@ public abstract class AbstractCompositeAttributeBindingContainer lazy, naturalIdMutability, metaAttributeContext, + attributeRole, + attributePath, generation ); } @Override - public CompositeAttributeBinding makeAggregatedCompositeAttributeBinding( + public EmbeddedAttributeBinding makeAggregatedCompositeAttributeBinding( SingularAttribute attribute, SingularAttribute parentReferenceAttribute, - String propertyAccessorName, + Class tuplizerClass, String propertyAccessorName, boolean includedInOptimisticLocking, boolean lazy, - SingularAttributeBinding.NaturalIdMutability naturalIdMutability, - MetaAttributeContext metaAttributeContext) { + NaturalIdMutability naturalIdMutability, + MetaAttributeContext metaAttributeContext, + AttributeRole attributeRole, + AttributePath attributePath) { if ( !isModifiable() ) { throw new UnsupportedOperationException( "Attribute bindings are read-only and cannot be modified." ); } return super.makeAggregatedCompositeAttributeBinding( attribute, parentReferenceAttribute, + tuplizerClass, propertyAccessorName, includedInOptimisticLocking, lazy, naturalIdMutability, - metaAttributeContext + metaAttributeContext, + attributeRole, + attributePath ); } @@ -159,8 +185,10 @@ public abstract class AbstractCompositeAttributeBindingContainer String propertyAccessorName, boolean includedInOptimisticLocking, boolean lazy, - SingularAttributeBinding.NaturalIdMutability naturalIdMutability, + NaturalIdMutability naturalIdMutability, MetaAttributeContext metaAttributeContext, + AttributeRole attributeRole, + AttributePath attributePath, EntityBinding referencedEntityBinding, SingularAttributeBinding referencedAttributeBinding, boolean isConstrained) { @@ -174,6 +202,8 @@ public abstract class AbstractCompositeAttributeBindingContainer lazy, naturalIdMutability, metaAttributeContext, + attributeRole, + attributePath, referencedEntityBinding, referencedAttributeBinding, isConstrained @@ -187,8 +217,10 @@ public abstract class AbstractCompositeAttributeBindingContainer boolean includedInOptimisticLocking, boolean lazy, boolean isIgnoreNotFound, - SingularAttributeBinding.NaturalIdMutability naturalIdMutability, + NaturalIdMutability naturalIdMutability, MetaAttributeContext metaAttributeContext, + AttributeRole attributeRole, + AttributePath attributePath, EntityBinding referencedEntityBinding, SingularAttributeBinding referencedAttributeBinding) { if ( !isModifiable() ) { @@ -202,6 +234,8 @@ public abstract class AbstractCompositeAttributeBindingContainer isIgnoreNotFound, naturalIdMutability, metaAttributeContext, + attributeRole, + attributePath, referencedEntityBinding, referencedAttributeBinding ); @@ -210,11 +244,13 @@ public abstract class AbstractCompositeAttributeBindingContainer @Override public BagBinding makeBagAttributeBinding( PluralAttribute attribute, - PluralAttributeElementBinding.Nature nature, + PluralAttributeElementNature nature, SingularAttributeBinding referencedAttributeBinding, String propertyAccessorName, boolean includedInOptimisticLocking, - MetaAttributeContext metaAttributeContext) { + MetaAttributeContext metaAttributeContext, + AttributeRole attributeRole, + AttributePath attributePath) { if ( !isModifiable() ) { throw new UnsupportedOperationException( "Attribute bindings are read-only and cannot be modified." ); } @@ -224,18 +260,22 @@ public abstract class AbstractCompositeAttributeBindingContainer referencedAttributeBinding, propertyAccessorName, includedInOptimisticLocking, - metaAttributeContext + metaAttributeContext, + attributeRole, + attributePath ); } @Override public ListBinding makeListAttributeBinding( PluralAttribute attribute, - PluralAttributeElementBinding.Nature nature, + PluralAttributeElementNature nature, SingularAttributeBinding referencedAttributeBinding, String propertyAccessorName, boolean includedInOptimisticLocking, MetaAttributeContext metaAttributeContext, + AttributeRole attributeRole, + AttributePath attributePath, int base) { if ( !isModifiable() ) { throw new UnsupportedOperationException( "Attribute bindings are read-only and cannot be modified." ); @@ -247,6 +287,8 @@ public abstract class AbstractCompositeAttributeBindingContainer propertyAccessorName, includedInOptimisticLocking, metaAttributeContext, + attributeRole, + attributePath, base ); } @@ -254,11 +296,13 @@ public abstract class AbstractCompositeAttributeBindingContainer @Override public ArrayBinding makeArrayAttributeBinding( PluralAttribute attribute, - PluralAttributeElementBinding.Nature nature, + PluralAttributeElementNature nature, SingularAttributeBinding referencedAttributeBinding, String propertyAccessorName, boolean includedInOptimisticLocking, MetaAttributeContext metaAttributeContext, + AttributeRole attributeRole, + AttributePath attributePath, int base) { if ( !isModifiable() ) { throw new UnsupportedOperationException( "Attribute bindings are read-only and cannot be modified." ); @@ -270,6 +314,8 @@ public abstract class AbstractCompositeAttributeBindingContainer propertyAccessorName, includedInOptimisticLocking, metaAttributeContext, + attributeRole, + attributePath, base ); } @@ -277,12 +323,14 @@ public abstract class AbstractCompositeAttributeBindingContainer @Override public MapBinding makeMapAttributeBinding( PluralAttribute attribute, - PluralAttributeElementBinding.Nature elementNature, - PluralAttributeIndexBinding.Nature indexNature, + PluralAttributeElementNature elementNature, + PluralAttributeIndexNature indexNature, SingularAttributeBinding referencedAttributeBinding, String propertyAccessorName, boolean includedInOptimisticLocking, - MetaAttributeContext metaAttributeContext) { + MetaAttributeContext metaAttributeContext, + AttributeRole attributeRole, + AttributePath attributePath) { if ( !isModifiable() ) { throw new UnsupportedOperationException( "Attribute bindings are read-only and cannot be modified." ); } @@ -293,18 +341,22 @@ public abstract class AbstractCompositeAttributeBindingContainer referencedAttributeBinding, propertyAccessorName, includedInOptimisticLocking, - metaAttributeContext + metaAttributeContext, + attributeRole, + attributePath ); } @Override public SetBinding makeSetAttributeBinding( PluralAttribute attribute, - PluralAttributeElementBinding.Nature nature, + PluralAttributeElementNature nature, SingularAttributeBinding referencedAttributeBinding, String propertyAccessorName, boolean includedInOptimisticLocking, - MetaAttributeContext metaAttributeContext) { + MetaAttributeContext metaAttributeContext, + AttributeRole attributeRole, + AttributePath attributePath) { if ( !isModifiable() ) { throw new UnsupportedOperationException( "Attribute bindings are read-only and cannot be modified." ); } @@ -314,7 +366,9 @@ public abstract class AbstractCompositeAttributeBindingContainer referencedAttributeBinding, propertyAccessorName, includedInOptimisticLocking, - metaAttributeContext + metaAttributeContext, + attributeRole, + attributePath ); } } \ No newline at end of file diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractPluralAttributeAssociationElementBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractPluralAttributeAssociationElementBinding.java index 0cca131bdf..a0f7a312e3 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractPluralAttributeAssociationElementBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractPluralAttributeAssociationElementBinding.java @@ -23,7 +23,6 @@ */ package org.hibernate.metamodel.spi.binding; -import org.hibernate.FetchMode; import org.hibernate.engine.spi.CascadeStyle; /** @@ -48,9 +47,4 @@ public abstract class AbstractPluralAttributeAssociationElementBinding public void setCascadeStyle(CascadeStyle cascadeStyle) { this.cascadeStyle = cascadeStyle; } - - @Override - public FetchMode getFetchMode() { - return getPluralAttributeBinding().getFetchMode(); - } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractPluralAttributeBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractPluralAttributeBinding.java index 1143c6d627..7de28b0bc8 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractPluralAttributeBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractPluralAttributeBinding.java @@ -34,6 +34,9 @@ import org.hibernate.engine.FetchStyle; import org.hibernate.engine.FetchTiming; import org.hibernate.internal.FilterConfiguration; import org.hibernate.metamodel.source.spi.MetaAttributeContext; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; +import org.hibernate.metamodel.spi.PluralAttributeElementNature; import org.hibernate.metamodel.spi.domain.PluralAttribute; import org.hibernate.persister.collection.CollectionPersister; @@ -77,39 +80,43 @@ public abstract class AbstractPluralAttributeBinding extends AbstractAttributeBi protected AbstractPluralAttributeBinding( AttributeBindingContainer container, PluralAttribute attribute, - PluralAttributeElementBinding.Nature pluralAttributeElementNature, + PluralAttributeElementNature pluralAttributeElementNature, SingularAttributeBinding referencedAttributeBinding, String propertyAccessorName, boolean includedInOptimisticLocking, - MetaAttributeContext metaAttributeContext) { + MetaAttributeContext metaAttributeContext, + AttributeRole attributeRole, + AttributePath attributePath) { super( container, attribute, propertyAccessorName, includedInOptimisticLocking, - metaAttributeContext + metaAttributeContext, + attributeRole, + attributePath ); this.pluralAttributeKeyBinding = new PluralAttributeKeyBinding( this, referencedAttributeBinding ); this.pluralAttributeElementBinding = interpretNature( pluralAttributeElementNature ); this.referencedPropertyName = referencedAttributeBinding.getAttribute().getName(); } - private AbstractPluralAttributeElementBinding interpretNature(PluralAttributeElementBinding.Nature nature) { + private AbstractPluralAttributeElementBinding interpretNature(PluralAttributeElementNature nature) { switch ( nature ) { case BASIC: { - return new BasicPluralAttributeElementBinding( this ); + return new PluralAttributeElementBindingBasic( this ); } case AGGREGATE: { - return new CompositePluralAttributeElementBinding( this ); + return new PluralAttributeElementBindingEmbedded( this ); } case ONE_TO_MANY: { - return new OneToManyPluralAttributeElementBinding( this ); + return new PluralAttributeElementBindingOneToMany( this ); } case MANY_TO_MANY: { - return new ManyToManyPluralAttributeElementBinding( this ); + return new PluralAttributeElementBindingManyToMany( this ); } case MANY_TO_ANY: { - return new ManyToAnyPluralAttributeElementBinding( this ); + return new PluralAttributeElementBindingManyToAny( this ); } default: { throw new AssertionFailure( "Unknown collection element nature : " + nature ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractPluralAttributeElementBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractPluralAttributeElementBinding.java index 11d0645d06..3f2ddf5fcd 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractPluralAttributeElementBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractPluralAttributeElementBinding.java @@ -23,11 +23,6 @@ */ package org.hibernate.metamodel.spi.binding; -import java.util.List; - -import org.hibernate.FetchMode; -import org.hibernate.metamodel.spi.relational.Value; - /** * Basic contract describing the commonality between the various types of collection element mappings. * @@ -50,36 +45,4 @@ public abstract class AbstractPluralAttributeElementBinding implements PluralAtt public HibernateTypeDescriptor getHibernateTypeDescriptor() { return hibernateTypeDescriptor; } - - protected abstract RelationalValueBindingContainer getRelationalValueContainer(); - - @Override - public List getValues() { - return getRelationalValueContainer().values(); - } - - @Override - public List getRelationalValueBindings() { - return getRelationalValueContainer().relationalValueBindings(); - } - - @Override - public boolean isNullable() { - return getRelationalValueContainer().hasNullableRelationalValueBinding(); - } - - @Override - public boolean hasDerivedValue() { - return getRelationalValueContainer().hasDerivedValue(); - } - - @Override - public boolean hasNonNullableValue() { - return getRelationalValueContainer().hasNonNullableRelationalValueBinding(); - } - - @Override - public FetchMode getFetchMode() { - return getPluralAttributeBinding().getFetchMode(); - } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractSingularAssociationAttributeBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractSingularAssociationAttributeBinding.java index 70a3f0ba76..b3d2341257 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractSingularAssociationAttributeBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractSingularAssociationAttributeBinding.java @@ -31,6 +31,9 @@ import org.hibernate.engine.FetchStyle; import org.hibernate.engine.FetchTiming; import org.hibernate.engine.spi.CascadeStyle; import org.hibernate.metamodel.source.spi.MetaAttributeContext; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; +import org.hibernate.metamodel.spi.NaturalIdMutability; import org.hibernate.metamodel.spi.domain.SingularAttribute; import org.hibernate.metamodel.spi.relational.ForeignKey; import org.hibernate.metamodel.spi.relational.TableSpecification; @@ -59,6 +62,8 @@ public abstract class AbstractSingularAssociationAttributeBinding extends Abstra boolean isIgnoreNotFound, NaturalIdMutability naturalIdMutability, MetaAttributeContext metaAttributeContext, + AttributeRole attributeRole, + AttributePath attributePath, EntityBinding referencedEntityBinding, SingularAttributeBinding referencedAttributeBinding) { super( @@ -68,7 +73,9 @@ public abstract class AbstractSingularAssociationAttributeBinding extends Abstra includedInOptimisticLocking, isLazy, naturalIdMutability, - metaAttributeContext + metaAttributeContext, + attributeRole, + attributePath ); if ( referencedEntityBinding == null ) { throw new IllegalArgumentException( "referencedEntityBinding must be non-null." ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractSingularAttributeBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractSingularAttributeBinding.java index 8ae8e98e77..f6775a3555 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractSingularAttributeBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractSingularAttributeBinding.java @@ -26,6 +26,9 @@ package org.hibernate.metamodel.spi.binding; import java.util.List; import org.hibernate.metamodel.source.spi.MetaAttributeContext; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; +import org.hibernate.metamodel.spi.NaturalIdMutability; import org.hibernate.metamodel.spi.domain.SingularAttribute; import org.hibernate.metamodel.spi.relational.TableSpecification; import org.hibernate.metamodel.spi.relational.Value; @@ -47,8 +50,18 @@ public abstract class AbstractSingularAttributeBinding boolean includedInOptimisticLocking, boolean isLazy, NaturalIdMutability naturalIdMutability, - MetaAttributeContext metaAttributeContext) { - super( container, attribute, propertyAccessorName, includedInOptimisticLocking, metaAttributeContext ); + MetaAttributeContext metaAttributeContext, + AttributeRole attributeRole, + AttributePath attributePath) { + super( + container, + attribute, + propertyAccessorName, + includedInOptimisticLocking, + metaAttributeContext , + attributeRole, + attributePath + ); this.isLazy = isLazy; this.naturalIdMutability = naturalIdMutability; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/ArrayBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/ArrayBinding.java index fb990135e6..d570c231ff 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/ArrayBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/ArrayBinding.java @@ -24,6 +24,9 @@ package org.hibernate.metamodel.spi.binding; import org.hibernate.metamodel.source.spi.MetaAttributeContext; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; +import org.hibernate.metamodel.spi.PluralAttributeElementNature; import org.hibernate.metamodel.spi.domain.PluralAttribute; /** @@ -36,13 +39,25 @@ public class ArrayBinding extends AbstractPluralAttributeBinding implements Inde public ArrayBinding(AttributeBindingContainer container, PluralAttribute attribute, - PluralAttributeElementBinding.Nature pluralAttributeElementNature, + PluralAttributeElementNature pluralAttributeElementNature, SingularAttributeBinding referencedAttributeBinding, - String propertyAccessorName, boolean includedInOptimisticLocking, - MetaAttributeContext metaAttributeContext, int base) { - super( container, attribute, pluralAttributeElementNature, - referencedAttributeBinding, propertyAccessorName, - includedInOptimisticLocking, metaAttributeContext ); + String propertyAccessorName, + boolean includedInOptimisticLocking, + MetaAttributeContext metaAttributeContext, + AttributeRole attributeRole, + AttributePath attributePath, + int base) { + super( + container, + attribute, + pluralAttributeElementNature, + referencedAttributeBinding, + propertyAccessorName, + includedInOptimisticLocking, + metaAttributeContext, + attributeRole, + attributePath + ); pluralAttributeIndexBinding = new BasicPluralAttributeIndexBinding( this ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AttributeBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AttributeBinding.java index d7fc67b779..fe5e03659b 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AttributeBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AttributeBinding.java @@ -24,6 +24,8 @@ package org.hibernate.metamodel.spi.binding; import org.hibernate.metamodel.source.spi.MetaAttributeContext; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; import org.hibernate.metamodel.spi.domain.Attribute; /** @@ -79,5 +81,6 @@ public interface AttributeBinding { public boolean isLazy(); - public String getAttributePath(); + public AttributePath getAttributePath(); + public AttributeRole getAttributeRole(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AttributeBindingContainer.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AttributeBindingContainer.java index a605c45ca3..1080aaaf82 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AttributeBindingContainer.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AttributeBindingContainer.java @@ -27,26 +27,28 @@ import java.util.List; import org.hibernate.mapping.PropertyGeneration; import org.hibernate.metamodel.source.spi.MetaAttributeContext; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; +import org.hibernate.metamodel.spi.NaturalIdMutability; +import org.hibernate.metamodel.spi.PluralAttributeElementNature; +import org.hibernate.metamodel.spi.PluralAttributeIndexNature; import org.hibernate.metamodel.spi.domain.AttributeContainer; import org.hibernate.metamodel.spi.domain.PluralAttribute; import org.hibernate.metamodel.spi.domain.SingularAttribute; import org.hibernate.metamodel.spi.relational.TableSpecification; import org.hibernate.metamodel.spi.relational.Value; import org.hibernate.tuple.Tuplizer; +import org.hibernate.tuple.component.ComponentTuplizer; /** - * Common contract for {@link EntityBinding} and {@link CompositeAttributeBinding} in so far as they are both + * Common contract for {@link EntityBinding} and {@link EmbeddedAttributeBinding} in so far as they are both * containers for {@link AttributeBinding} descriptors * * @author Steve Ebersole */ public interface AttributeBindingContainer { - /** - * Obtain the path base of this container. Intended to help uniquely identify each attribute binding. - * - * @return The path base for this container. - */ - String getPathBase(); + public AttributePath getPathBase(); + public AttributeRole getRoleBase(); /** * Obtain the underlying domain attribute container. @@ -138,8 +140,10 @@ public interface AttributeBindingContainer { String propertyAccessorName, boolean includedInOptimisticLocking, boolean lazy, - SingularAttributeBinding.NaturalIdMutability naturalIdMutability, + NaturalIdMutability naturalIdMutability, MetaAttributeContext metaAttributeContext, + AttributeRole attributeRole, + AttributePath attributePath, PropertyGeneration generation); /** @@ -147,6 +151,7 @@ public interface AttributeBindingContainer { * * @param attribute The attribute for which to make a binding. * @param parentReferenceAttribute + * @param tuplizerClass * @param propertyAccessorName * @param includedInOptimisticLocking * @param lazy @@ -154,14 +159,17 @@ public interface AttributeBindingContainer { * * @return The attribute binding instance. */ - CompositeAttributeBinding makeAggregatedCompositeAttributeBinding( + EmbeddedAttributeBinding makeAggregatedCompositeAttributeBinding( SingularAttribute attribute, SingularAttribute parentReferenceAttribute, + Class tuplizerClass, String propertyAccessorName, boolean includedInOptimisticLocking, boolean lazy, - SingularAttributeBinding.NaturalIdMutability naturalIdMutability, - MetaAttributeContext metaAttributeContext); + NaturalIdMutability naturalIdMutability, + MetaAttributeContext metaAttributeContext, + AttributeRole attributeRole, + AttributePath attributePath); /** * Factory method for one-to-one attribute bindings. @@ -181,8 +189,10 @@ public interface AttributeBindingContainer { String propertyAccessorName, boolean includedInOptimisticLocking, boolean lazy, - SingularAttributeBinding.NaturalIdMutability naturalIdMutability, + NaturalIdMutability naturalIdMutability, MetaAttributeContext metaAttributeContext, + AttributeRole attributeRole, + AttributePath attributePath, EntityBinding referencedEntityBinding, SingularAttributeBinding referencedAttributeBinding, boolean isConstrained); @@ -208,8 +218,10 @@ public interface AttributeBindingContainer { boolean includedInOptimisticLocking, boolean lazy, boolean isIgnoreNotFound, - SingularAttributeBinding.NaturalIdMutability naturalIdMutability, + NaturalIdMutability naturalIdMutability, MetaAttributeContext metaAttributeContext, + AttributeRole attributeRole, + AttributePath attributePath, EntityBinding referencedEntityBinding, SingularAttributeBinding referencedAttributeBinding); @@ -228,11 +240,13 @@ public interface AttributeBindingContainer { */ BagBinding makeBagAttributeBinding( PluralAttribute attribute, - PluralAttributeElementBinding.Nature nature, + PluralAttributeElementNature nature, SingularAttributeBinding referencedAttributeBinding, String propertyAccessorName, boolean includedInOptimisticLocking, - MetaAttributeContext metaAttributeContext); + MetaAttributeContext metaAttributeContext, + AttributeRole attributeRole, + AttributePath attributePath); /** * Factory method for list attribute bindings. @@ -250,11 +264,13 @@ public interface AttributeBindingContainer { */ ListBinding makeListAttributeBinding( PluralAttribute attribute, - PluralAttributeElementBinding.Nature nature, + PluralAttributeElementNature nature, SingularAttributeBinding referencedAttributeBinding, String propertyAccessorName, boolean includedInOptimisticLocking, MetaAttributeContext metaAttributeContext, + AttributeRole attributeRole, + AttributePath attributePath, int base); /** @@ -273,11 +289,13 @@ public interface AttributeBindingContainer { */ ArrayBinding makeArrayAttributeBinding( PluralAttribute attribute, - PluralAttributeElementBinding.Nature nature, + PluralAttributeElementNature nature, SingularAttributeBinding referencedAttributeBinding, String propertyAccessorName, boolean includedInOptimisticLocking, MetaAttributeContext metaAttributeContext, + AttributeRole attributeRole, + AttributePath attributePath, int base); /** @@ -296,12 +314,14 @@ public interface AttributeBindingContainer { */ MapBinding makeMapAttributeBinding( PluralAttribute attribute, - PluralAttributeElementBinding.Nature elementNature, - PluralAttributeIndexBinding.Nature indexNature, + PluralAttributeElementNature elementNature, + PluralAttributeIndexNature indexNature, SingularAttributeBinding referencedAttributeBinding, String propertyAccessorName, boolean includedInOptimisticLocking, - MetaAttributeContext metaAttributeContext); + MetaAttributeContext metaAttributeContext, + AttributeRole attributeRole, + AttributePath attributePath); /** * Factory method for set attribute bindings. @@ -318,9 +338,11 @@ public interface AttributeBindingContainer { */ SetBinding makeSetAttributeBinding( PluralAttribute attribute, - PluralAttributeElementBinding.Nature nature, + PluralAttributeElementNature nature, SingularAttributeBinding referencedAttributeBinding, String propertyAccessorName, boolean includedInOptimisticLocking, - MetaAttributeContext metaAttributeContext); + MetaAttributeContext metaAttributeContext, + AttributeRole attributeRole, + AttributePath attributePath); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/BackRefAttributeBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/BackRefAttributeBinding.java index d8b1b2e778..529a691f08 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/BackRefAttributeBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/BackRefAttributeBinding.java @@ -27,6 +27,7 @@ import java.util.ArrayList; import java.util.List; import org.hibernate.mapping.PropertyGeneration; +import org.hibernate.metamodel.spi.NaturalIdMutability; import org.hibernate.metamodel.spi.domain.SingularAttribute; import org.hibernate.metamodel.spi.relational.Column; @@ -52,6 +53,8 @@ public class BackRefAttributeBinding extends BasicAttributeBinding { false, NaturalIdMutability.NOT_NATURAL_ID, null, + pluralAttributeBinding.getAttributeRole().append( "backRef" ), + pluralAttributeBinding.getAttributePath().append( "backRef" ), PropertyGeneration.NEVER ); this.pluralAttributeBinding = pluralAttributeBinding; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/BagBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/BagBinding.java index abd7816b00..54ca413a05 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/BagBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/BagBinding.java @@ -24,6 +24,9 @@ package org.hibernate.metamodel.spi.binding; import org.hibernate.metamodel.source.spi.MetaAttributeContext; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; +import org.hibernate.metamodel.spi.PluralAttributeElementNature; import org.hibernate.metamodel.spi.domain.PluralAttribute; /** @@ -35,11 +38,13 @@ public class BagBinding extends AbstractPluralAttributeBinding { protected BagBinding( AttributeBindingContainer container, PluralAttribute attribute, - PluralAttributeElementBinding.Nature pluralAttributeElementNature, + PluralAttributeElementNature pluralAttributeElementNature, SingularAttributeBinding referencedAttributeBinding, String propertyAccessorName, boolean includedInOptimisticLocking, - MetaAttributeContext metaAttributeContext) { + MetaAttributeContext metaAttributeContext, + AttributeRole attributeRole, + AttributePath attributePath) { super( container, attribute, @@ -47,7 +52,9 @@ public class BagBinding extends AbstractPluralAttributeBinding { referencedAttributeBinding, propertyAccessorName, includedInOptimisticLocking, - metaAttributeContext + metaAttributeContext, + attributeRole, + attributePath ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/BasicAttributeBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/BasicAttributeBinding.java index bd3623faf0..58695cbe13 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/BasicAttributeBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/BasicAttributeBinding.java @@ -27,6 +27,9 @@ import java.util.List; import org.hibernate.mapping.PropertyGeneration; import org.hibernate.metamodel.source.spi.MetaAttributeContext; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; +import org.hibernate.metamodel.spi.NaturalIdMutability; import org.hibernate.metamodel.spi.domain.SingularAttribute; /** @@ -48,6 +51,8 @@ public class BasicAttributeBinding boolean lazy, NaturalIdMutability naturalIdMutability, MetaAttributeContext metaAttributeContext, + AttributeRole attributeRole, + AttributePath attributePath, PropertyGeneration generation) { super( container, @@ -56,7 +61,9 @@ public class BasicAttributeBinding includedInOptimisticLocking, lazy, naturalIdMutability, - metaAttributeContext + metaAttributeContext, + attributeRole, + attributePath ); this.relationalValueBindingContainer = new RelationalValueBindingContainer( relationalValueBindings ); this.generation = generation; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/BasicPluralAttributeIndexBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/BasicPluralAttributeIndexBinding.java index 57571f42ce..00e3ddd9ba 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/BasicPluralAttributeIndexBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/BasicPluralAttributeIndexBinding.java @@ -26,6 +26,7 @@ package org.hibernate.metamodel.spi.binding; import java.util.List; import org.hibernate.AssertionFailure; +import org.hibernate.metamodel.spi.PluralAttributeIndexNature; import org.hibernate.metamodel.spi.relational.Value; /** @@ -62,7 +63,7 @@ public class BasicPluralAttributeIndexBinding extends AbstractPluralAttributeInd } @Override - public Nature getNature() { - return Nature.BASIC; + public PluralAttributeIndexNature getNature() { + return PluralAttributeIndexNature.BASIC; } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/CompositeAttributeBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/CompositeAttributeBinding.java deleted file mode 100644 index 2ab2031a30..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/CompositeAttributeBinding.java +++ /dev/null @@ -1,554 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2012, 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.metamodel.spi.binding; - -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import org.hibernate.engine.spi.CascadeStyle; -import org.hibernate.engine.spi.CascadeStyles; -import org.hibernate.internal.util.StringHelper; -import org.hibernate.mapping.PropertyGeneration; -import org.hibernate.metamodel.source.spi.MetaAttributeContext; -import org.hibernate.metamodel.spi.domain.AttributeContainer; -import org.hibernate.metamodel.spi.domain.PluralAttribute; -import org.hibernate.metamodel.spi.domain.SingularAttribute; -import org.hibernate.metamodel.spi.relational.TableSpecification; -import org.hibernate.metamodel.spi.relational.Value; -import org.hibernate.tuple.component.ComponentTuplizer; - -/** - * A specialized binding contract for a singular attribute binding that - * contains other attribute bindings. - * - * @author Gail Badner - */ -public class CompositeAttributeBinding - extends AbstractSingularAttributeBinding - implements SingularNonAssociationAttributeBinding, CompositeAttributeBindingContainer, Cascadeable { - - private final String pathBase; - private final AbstractCompositeAttributeBindingContainer compositeAttributeBindingContainer; - private Class customComponentTuplizerClass = null; - - private CompositeAttributeBinding( - AttributeBindingContainer container, - SingularAttribute attribute, - String propertyAccessorName, - boolean includedInOptimisticLocking, - boolean lazy, - NaturalIdMutability naturalIdMutability, - MetaAttributeContext metaAttributeContext, - AbstractCompositeAttributeBindingContainer compositeAttributeBindingContainer) { - super( - container, - attribute, - propertyAccessorName, - includedInOptimisticLocking, - lazy, - naturalIdMutability, - metaAttributeContext - ); - this.pathBase = attribute.getName(); - this.compositeAttributeBindingContainer = compositeAttributeBindingContainer; - } - - public static CompositeAttributeBinding createAggregatedCompositeAttributeBinding( - AttributeBindingContainer container, - SingularAttribute attribute, - String propertyAccessorName, - boolean includedInOptimisticLocking, - boolean lazy, - NaturalIdMutability naturalIdMutability, - MetaAttributeContext metaAttributeContext, - SingularAttribute parentReference) { - AbstractCompositeAttributeBindingContainer compositeAttributeBindingContainer = - new AbstractCompositeAttributeBindingContainer( - container.seekEntityBinding(), - (AttributeContainer) attribute.getSingularAttributeType(), - container.getPrimaryTable(), - createContainerPath( container, attribute ), - metaAttributeContext, - parentReference) { - private final Map attributeBindingMap = - new LinkedHashMap(); - - @Override - protected boolean isModifiable() { - return true; - } - - @Override - protected Map attributeBindingMapInternal() { - return attributeBindingMap; - } - - @Override - public boolean isAggregated() { - return true; - } - }; - if ( ! attribute.getSingularAttributeType().isAggregate() ) { - throw new IllegalArgumentException( - "Cannot create an aggregated CompositeAttributeBindingContainer with a non-aggregate attribute type" - ); - } - return new CompositeAttributeBinding( - container, - attribute, - propertyAccessorName, - includedInOptimisticLocking, - lazy, - naturalIdMutability, - metaAttributeContext, - compositeAttributeBindingContainer - ); - } - - // TODO: Get rid of this when non-aggregated composite IDs is no longer modelled as a CompositeAttributeBinding. - public static CompositeAttributeBinding createNonAggregatedCompositeAttributeBinding( - AttributeBindingContainer container, - SingularAttribute syntheticAttribute, - NaturalIdMutability naturalIdMutability, - MetaAttributeContext metaAttributeContext, - final List subAttributeBindings) { - AbstractCompositeAttributeBindingContainer compositeAttributeBindingContainer = - new AbstractCompositeAttributeBindingContainer( - container.seekEntityBinding(), - (AttributeContainer) syntheticAttribute.getSingularAttributeType(), - container.getPrimaryTable(), - createContainerPath( container, syntheticAttribute ), - metaAttributeContext, - null) { - private final Map attributeBindingMap = createUnmodifiableAttributeBindingMap( subAttributeBindings ); - - @Override - protected boolean isModifiable() { - return false; - } - - @Override - protected Map attributeBindingMapInternal() { - return this.attributeBindingMap; - } - - @Override - public boolean isAggregated() { - return false; - } - }; - if ( syntheticAttribute.getSingularAttributeType().isAggregate() ) { - throw new IllegalArgumentException( - "Cannot create a non-aggregated CompositeAttributeBindingContainer with an aggregate attribute type" - ); - } - return new CompositeAttributeBinding( - container, - syntheticAttribute, - "embedded", // TODO: get rid of "magic" string. - false, - false, - naturalIdMutability, - metaAttributeContext, - compositeAttributeBindingContainer - ); - } - - private static Map createUnmodifiableAttributeBindingMap( - List subAttributeBindings) { - Map map = new LinkedHashMap( subAttributeBindings.size() ); - for ( AttributeBinding subAttributeBinding : subAttributeBindings ) { - map.put( subAttributeBinding.getAttribute().getName(), subAttributeBinding ); - } - return Collections.unmodifiableMap( map ); - } - - private static String createContainerPath(AttributeBindingContainer container, SingularAttribute attribute) { - return StringHelper.isEmpty( container.getPathBase() ) - ? attribute.getName() - : container.getPathBase() + '.' + attribute.getName(); - - } - - /** - * Can the composite attribute be mapped to a single entity - * attribute by means of an actual component class that aggregates - * the tuple values? - * - * @return true, if the attribute can be mapped to a single entity - * attribute by means of an actual component class that aggregates - * the tuple values; false, otherwise. - */ - public boolean isAggregated() { - return compositeAttributeBindingContainer.isAggregated(); - } - - public SingularAttribute getParentReference() { - return compositeAttributeBindingContainer.getParentReference(); - } - - @Override - public Class getCustomTuplizerClass() { - return customComponentTuplizerClass; - } - - public void setCustomComponentTuplizerClass(Class customComponentTuplizerClass) { - this.customComponentTuplizerClass = customComponentTuplizerClass; - } - - @Override - protected RelationalValueBindingContainer getRelationalValueBindingContainer() { - return compositeAttributeBindingContainer.getRelationalValueBindingContainer(); - } - - @Override - public boolean isAssociation() { - return false; - } - - @Override - public boolean hasDerivedValue() { - // todo : not sure this is even relevant for components - return false; - } - - @Override - public boolean isCascadeable() { - for ( AttributeBinding attributeBinding : attributeBindings() ) { - if ( attributeBinding.isCascadeable() ) { - return true; - } - } - return false; - } - - @Override - public CascadeStyle getCascadeStyle() { - for ( AttributeBinding attributeBinding : attributeBindings() ) { - if ( attributeBinding.isCascadeable() ) { - final Cascadeable cascadeable; - if ( attributeBinding.getAttribute().isSingular() ) { - cascadeable = Cascadeable.class.cast( attributeBinding ); - } - else { - cascadeable = Cascadeable.class.cast( ( (PluralAttributeBinding) attributeBinding ).getPluralAttributeElementBinding() ); - } - CascadeStyle cascadeStyle = cascadeable.getCascadeStyle(); - if ( cascadeStyle != CascadeStyles.NONE ) { - return CascadeStyles.ALL; - } - } - } - return CascadeStyles.NONE; - } - - @Override - public void setCascadeStyle(CascadeStyle cascadeStyle) { - throw new IllegalAccessError( "Composite attribute is not supposed to have cascade" ); - } - - @Override - public boolean isNullable() { - // return false if there are any singular attributes are non-nullable - for ( AttributeBinding attributeBinding : attributeBindings() ) { - // only check singular attributes - if ( attributeBinding.getAttribute().isSingular() && - ! ( (SingularAttributeBinding) attributeBinding ).isNullable() ) { - return false; - } - } - return true; - } - - @Override - public boolean isIncludedInInsert() { - // if the attribute is synthetic, this attribute binding (as a whole) is not insertable; - if ( getAttribute().isSynthetic() ) { - return false; - } - // otherwise, return true if there are any singular attributes that are included in the insert. - for ( AttributeBinding attributeBinding : attributeBindings() ) { - // only check singular attributes - if ( attributeBinding.getAttribute().isSingular() && - ( (SingularAttributeBinding) attributeBinding ).isIncludedInInsert() ) { - return true; - } - } - return false; - } - - @Override - public boolean isIncludedInUpdate() { - // if the attribute is synthetic, this attribute binding (as a whole) is not updateable; - if ( getAttribute().isSynthetic() ) { - return false; - } - // otherwise, return true if there are any singular attributes that are updatable; - for ( AttributeBinding attributeBinding : attributeBindings() ) { - // only check singular attributes - if ( attributeBinding.getAttribute().isSingular() && - ( (SingularAttributeBinding) attributeBinding ).isIncludedInUpdate() ) { - return true; - } - } - return false; - } - - @Override - protected void collectRelationalValueBindings(RelationalValueBindingContainer relationalValueBindingContainer) { - compositeAttributeBindingContainer.collectRelationalValueBindings( relationalValueBindingContainer ); - } - - @Override - public String getPathBase() { - return pathBase; - } - - @Override - public AttributeContainer getAttributeContainer() { - return compositeAttributeBindingContainer.getAttributeContainer(); - } - - @Override - public Iterable attributeBindings() { - return compositeAttributeBindingContainer.attributeBindings(); - } - - @Override - public int attributeBindingSpan() { - return compositeAttributeBindingContainer.attributeBindingSpan(); - } - - @Override - public AttributeBinding locateAttributeBinding(String name) { - return compositeAttributeBindingContainer.locateAttributeBinding( name ); - } - - @Override - public SingularAttributeBinding locateAttributeBinding( - TableSpecification table, - List values) { - return compositeAttributeBindingContainer.locateAttributeBinding( table, values ); - } - - @Override - public EntityBinding seekEntityBinding() { - return compositeAttributeBindingContainer.seekEntityBinding(); - } - - @Override - public TableSpecification getPrimaryTable() { - return compositeAttributeBindingContainer.getPrimaryTable(); - } - - - - @Override - public BasicAttributeBinding makeBasicAttributeBinding( - SingularAttribute attribute, - List relationalValueBindings, - String propertyAccessorName, - boolean includedInOptimisticLocking, - boolean lazy, - NaturalIdMutability naturalIdMutability, - MetaAttributeContext metaAttributeContext, - PropertyGeneration generation) { - return compositeAttributeBindingContainer.makeBasicAttributeBinding( - attribute, - relationalValueBindings, - propertyAccessorName, - includedInOptimisticLocking, - lazy, - naturalIdMutability, - metaAttributeContext, - generation - ); - } - - @Override - public CompositeAttributeBinding makeAggregatedCompositeAttributeBinding( - SingularAttribute attribute, - SingularAttribute parentReferenceAttribute, - String propertyAccessorName, - boolean includedInOptimisticLocking, - boolean lazy, - NaturalIdMutability naturalIdMutability, - MetaAttributeContext metaAttributeContext) { - return compositeAttributeBindingContainer.makeAggregatedCompositeAttributeBinding( - attribute, - parentReferenceAttribute, - propertyAccessorName, - includedInOptimisticLocking, - lazy, - naturalIdMutability, - metaAttributeContext - ); - } - - @Override - public OneToOneAttributeBinding makeOneToOneAttributeBinding( - SingularAttribute attribute, - String propertyAccessorName, - boolean includedInOptimisticLocking, - boolean lazy, - NaturalIdMutability naturalIdMutability, - MetaAttributeContext metaAttributeContext, - EntityBinding referencedEntityBinding, - SingularAttributeBinding referencedAttributeBinding, - boolean isConstrained) { - return compositeAttributeBindingContainer.makeOneToOneAttributeBinding( - attribute, - propertyAccessorName, - includedInOptimisticLocking, - lazy, - naturalIdMutability, - metaAttributeContext, - referencedEntityBinding, - referencedAttributeBinding, - isConstrained - ); - } - - @Override - public ManyToOneAttributeBinding makeManyToOneAttributeBinding( - SingularAttribute attribute, - String propertyAccessorName, - boolean includedInOptimisticLocking, - boolean lazy, - boolean isIgnoreNotFound, - NaturalIdMutability naturalIdMutability, - MetaAttributeContext metaAttributeContext, - EntityBinding referencedEntityBinding, - SingularAttributeBinding referencedAttributeBinding) { - return compositeAttributeBindingContainer.makeManyToOneAttributeBinding( - attribute, - propertyAccessorName, - includedInOptimisticLocking, - lazy, - isIgnoreNotFound, - naturalIdMutability, - metaAttributeContext, - referencedEntityBinding, - referencedAttributeBinding - ); - } - - @Override - public BagBinding makeBagAttributeBinding( - PluralAttribute attribute, - PluralAttributeElementBinding.Nature nature, - SingularAttributeBinding referencedAttributeBinding, - String propertyAccessorName, - boolean includedInOptimisticLocking, - MetaAttributeContext metaAttributeContext) { - return compositeAttributeBindingContainer.makeBagAttributeBinding( - attribute, - nature, - referencedAttributeBinding, - propertyAccessorName, - includedInOptimisticLocking, - metaAttributeContext - ); - } - - @Override - public ListBinding makeListAttributeBinding( - PluralAttribute attribute, - PluralAttributeElementBinding.Nature nature, - SingularAttributeBinding referencedAttributeBinding, - String propertyAccessorName, - boolean includedInOptimisticLocking, - MetaAttributeContext metaAttributeContext, - int base) { - return compositeAttributeBindingContainer.makeListAttributeBinding( - attribute, - nature, - referencedAttributeBinding, - propertyAccessorName, - includedInOptimisticLocking, - metaAttributeContext, - base - ); - } - - @Override - public ArrayBinding makeArrayAttributeBinding( - PluralAttribute attribute, - PluralAttributeElementBinding.Nature nature, - SingularAttributeBinding referencedAttributeBinding, - String propertyAccessorName, - boolean includedInOptimisticLocking, - MetaAttributeContext metaAttributeContext, - int base) { - return compositeAttributeBindingContainer.makeArrayAttributeBinding( - attribute, - nature, - referencedAttributeBinding, - propertyAccessorName, - includedInOptimisticLocking, - metaAttributeContext, - base - ); - } - - @Override - public MapBinding makeMapAttributeBinding( - PluralAttribute attribute, - PluralAttributeElementBinding.Nature elementNature, - PluralAttributeIndexBinding.Nature indexNature, - SingularAttributeBinding referencedAttributeBinding, - String propertyAccessorName, - boolean includedInOptimisticLocking, - MetaAttributeContext metaAttributeContext) { - return compositeAttributeBindingContainer.makeMapAttributeBinding( - attribute, - elementNature, - indexNature, - referencedAttributeBinding, - propertyAccessorName, - includedInOptimisticLocking, - metaAttributeContext - ); - } - - @Override - public SetBinding makeSetAttributeBinding( - PluralAttribute attribute, - PluralAttributeElementBinding.Nature nature, - SingularAttributeBinding referencedAttributeBinding, - String propertyAccessorName, - boolean includedInOptimisticLocking, - MetaAttributeContext metaAttributeContext) { - return compositeAttributeBindingContainer.makeSetAttributeBinding( - attribute, - nature, - referencedAttributeBinding, - propertyAccessorName, - includedInOptimisticLocking, - metaAttributeContext - ); - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/CompositePluralAttributeElementBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/CompositePluralAttributeElementBinding.java deleted file mode 100644 index 4f4458b22e..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/CompositePluralAttributeElementBinding.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2011, 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.metamodel.spi.binding; - -import java.util.LinkedHashMap; -import java.util.Map; - -import org.hibernate.engine.spi.CascadeStyle; -import org.hibernate.metamodel.source.spi.MetaAttributeContext; -import org.hibernate.metamodel.spi.domain.Aggregate; -import org.hibernate.metamodel.spi.domain.SingularAttribute; - -/** - * Describes plural attributes of {@link org.hibernate.metamodel.spi.binding.PluralAttributeElementBinding.Nature#AGGREGATE} elements - * - * @author Steve Ebersole - * @author Gail Badner - */ -public class CompositePluralAttributeElementBinding - extends AbstractPluralAttributeElementBinding - implements Cascadeable { - - // TODO: Come up with a more descriptive name for compositeAttributeBindingContainer. - private AbstractCompositeAttributeBindingContainer compositeAttributeBindingContainer; - private CascadeStyle cascadeStyle; - - - - public CompositePluralAttributeElementBinding(AbstractPluralAttributeBinding binding) { - super( binding ); - } - - @Override - protected RelationalValueBindingContainer getRelationalValueContainer() { - return compositeAttributeBindingContainer.getRelationalValueBindingContainer(); - } - - @Override - public Nature getNature() { - return Nature.AGGREGATE; - } - - public CompositeAttributeBindingContainer createCompositeAttributeBindingContainer( - Aggregate aggregate, - MetaAttributeContext metaAttributeContext, - SingularAttribute parentReference) { - compositeAttributeBindingContainer = - new AbstractCompositeAttributeBindingContainer( - getPluralAttributeBinding().getContainer().seekEntityBinding(), - aggregate, - getPluralAttributeBinding().getPluralAttributeKeyBinding().getCollectionTable(), - getPluralAttributeBinding().getAttribute().getRole() + ".element", - metaAttributeContext, - parentReference) { - final Map attributeBindingMap = new LinkedHashMap(); - - @Override - protected boolean isModifiable() { - return true; - } - - @Override - protected Map attributeBindingMapInternal() { - return attributeBindingMap; - } - - @Override - public boolean isAggregated() { - return true; - } - }; - return compositeAttributeBindingContainer; - } - - public CompositeAttributeBindingContainer getCompositeAttributeBindingContainer() { - return compositeAttributeBindingContainer; - } - - @Override - public CascadeStyle getCascadeStyle() { - return cascadeStyle; - } - - @Override - public void setCascadeStyle(CascadeStyle cascadeStyle) { - this.cascadeStyle = cascadeStyle; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/CompositePluralAttributeIndexBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/CompositePluralAttributeIndexBinding.java index bf5451ada8..adf3680405 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/CompositePluralAttributeIndexBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/CompositePluralAttributeIndexBinding.java @@ -28,62 +28,66 @@ import java.util.List; import java.util.Map; import org.hibernate.metamodel.source.spi.MetaAttributeContext; +import org.hibernate.metamodel.spi.PluralAttributeIndexNature; import org.hibernate.metamodel.spi.domain.Aggregate; import org.hibernate.metamodel.spi.domain.SingularAttribute; import org.hibernate.metamodel.spi.relational.Value; +import org.hibernate.tuple.component.ComponentTuplizer; /** - * Describes plural attributes of {@link org.hibernate.metamodel.spi.binding.PluralAttributeElementBinding.Nature#AGGREGATE} elements + * Describes plural attributes of {@link org.hibernate.metamodel.spi.PluralAttributeElementNature#AGGREGATE} elements * * @author Gail Badner */ public class CompositePluralAttributeIndexBinding extends AbstractPluralAttributeIndexBinding { // TODO: Come up with a more descriptive name for compositeAttributeBindingContainer. - private AbstractCompositeAttributeBindingContainer compositeAttributeBindingContainer; + private AbstractEmbeddableBinding compositeAttributeBindingContainer; public CompositePluralAttributeIndexBinding(IndexedPluralAttributeBinding binding) { super( binding ); } @Override - public Nature getNature() { - return Nature.AGGREGATE; + public PluralAttributeIndexNature getNature() { + return PluralAttributeIndexNature.AGGREGATE; } - public CompositeAttributeBindingContainer createCompositeAttributeBindingContainer( + public EmbeddableBinding createCompositeAttributeBindingContainer( Aggregate aggregate, MetaAttributeContext metaAttributeContext, - SingularAttribute parentReference) { - compositeAttributeBindingContainer = - new AbstractCompositeAttributeBindingContainer( - getIndexedPluralAttributeBinding().getContainer().seekEntityBinding(), - aggregate, - getIndexedPluralAttributeBinding().getPluralAttributeKeyBinding().getCollectionTable(), - getIndexedPluralAttributeBinding().getAttribute().getRole() + ".key", - metaAttributeContext, - parentReference) { - final Map attributeBindingMap = new LinkedHashMap(); + SingularAttribute parentReference, + Class tuplizerClass) { + compositeAttributeBindingContainer = new AbstractEmbeddableBinding( + getIndexedPluralAttributeBinding().getContainer().seekEntityBinding(), + aggregate, + getIndexedPluralAttributeBinding().getPluralAttributeKeyBinding().getCollectionTable(), + getIndexedPluralAttributeBinding().getAttributeRole().append( "key" ), + getIndexedPluralAttributeBinding().getAttributePath().append( "key" ), + metaAttributeContext, + parentReference, + tuplizerClass) { + final Map attributeBindingMap = new LinkedHashMap(); - @Override - protected boolean isModifiable() { - return true; - } + @Override + protected boolean isModifiable() { + return true; + } - @Override - protected Map attributeBindingMapInternal() { - return attributeBindingMap; - } + @Override + protected Map attributeBindingMapInternal() { + return attributeBindingMap; + } - @Override - public boolean isAggregated() { - return true; - } - }; + @Override + public boolean isAggregated() { + return true; + } + }; return compositeAttributeBindingContainer; } - public CompositeAttributeBindingContainer getCompositeAttributeBindingContainer() { + public EmbeddableBinding getCompositeAttributeBindingContainer() { return compositeAttributeBindingContainer; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/CompositeAttributeBindingContainer.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/EmbeddableBinding.java similarity index 94% rename from hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/CompositeAttributeBindingContainer.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/EmbeddableBinding.java index 2b77fe8bb0..5aa7b15c8f 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/CompositeAttributeBindingContainer.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/EmbeddableBinding.java @@ -29,7 +29,7 @@ import org.hibernate.tuple.component.ComponentTuplizer; /** * @author Gail Badner */ -public interface CompositeAttributeBindingContainer extends AttributeBindingContainer { +public interface EmbeddableBinding extends AttributeBindingContainer { boolean isAggregated(); SingularAttribute getParentReference(); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/EmbeddableBindingContributor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/EmbeddableBindingContributor.java new file mode 100644 index 0000000000..5cb512e5eb --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/EmbeddableBindingContributor.java @@ -0,0 +1,31 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2014, 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.metamodel.spi.binding; + +/** + * @author Steve Ebersole + */ +public interface EmbeddableBindingContributor { + EmbeddableBinding getEmbeddableBinding(); +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/EmbeddedAttributeBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/EmbeddedAttributeBinding.java new file mode 100644 index 0000000000..0dbe158c96 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/EmbeddedAttributeBinding.java @@ -0,0 +1,309 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2012, 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.metamodel.spi.binding; + +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import org.hibernate.engine.spi.CascadeStyle; +import org.hibernate.engine.spi.CascadeStyles; +import org.hibernate.metamodel.source.spi.MetaAttributeContext; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; +import org.hibernate.metamodel.spi.NaturalIdMutability; +import org.hibernate.metamodel.spi.domain.AttributeContainer; +import org.hibernate.metamodel.spi.domain.SingularAttribute; +import org.hibernate.tuple.component.ComponentTuplizer; + +/** + * Models the binding information for embeddable/composite values. + * + * @author Gail Badner + * @author Steve Ebersole + */ +public class EmbeddedAttributeBinding + extends AbstractSingularAttributeBinding + implements SingularNonAssociationAttributeBinding, Cascadeable, EmbeddableBindingContributor { + + private final AbstractEmbeddableBinding embeddableBinding; + + private EmbeddedAttributeBinding( + AttributeBindingContainer container, + SingularAttribute attribute, + String propertyAccessorName, + boolean includedInOptimisticLocking, + boolean lazy, + NaturalIdMutability naturalIdMutability, + MetaAttributeContext metaAttributeContext, + AttributeRole attributeRole, + AttributePath attributePath, + AbstractEmbeddableBinding embeddableBinding) { + super( + container, + attribute, + propertyAccessorName, + includedInOptimisticLocking, + lazy, + naturalIdMutability, + metaAttributeContext, + attributeRole, + attributePath + ); + this.embeddableBinding = embeddableBinding; + + getHibernateTypeDescriptor().setJavaTypeDescriptor( embeddableBinding.getAttributeContainer().getDescriptor() ); + } + + public static EmbeddedAttributeBinding createEmbeddedAttributeBinding( + final AttributeBindingContainer container, + SingularAttribute attribute, + String propertyAccessorName, + boolean includedInOptimisticLocking, + boolean lazy, + NaturalIdMutability naturalIdMutability, + MetaAttributeContext metaAttributeContext, + AttributeRole attributeRole, + AttributePath attributePath, + SingularAttribute parentReference, + Class tuplizerClass) { + final AbstractEmbeddableBinding embeddableBinding = new AbstractEmbeddableBinding( + container.seekEntityBinding(), + (AttributeContainer) attribute.getSingularAttributeType(), + container.getPrimaryTable(), + attributeRole, + attributePath, + metaAttributeContext, + parentReference, + tuplizerClass) { + private final Map attributeBindingMap = new LinkedHashMap(); + + @Override + protected boolean isModifiable() { + return true; + } + + @Override + protected Map attributeBindingMapInternal() { + return attributeBindingMap; + } + + @Override + public boolean isAggregated() { + return true; + } + }; + + if ( ! attribute.getSingularAttributeType().isAggregate() ) { + throw new IllegalArgumentException( + "Cannot create an aggregated EmbeddableBinding with a non-aggregate attribute type" + ); + } + return new EmbeddedAttributeBinding( + container, + attribute, + propertyAccessorName, + includedInOptimisticLocking, + lazy, + naturalIdMutability, + metaAttributeContext, + attributeRole, + attributePath, + embeddableBinding + ); + } + + // TODO: Get rid of this when non-aggregated composite IDs is no longer modelled as a EmbeddedAttributeBinding. + public static EmbeddedAttributeBinding createVirtualEmbeddedAttributeBinding( + final AttributeBindingContainer container, + SingularAttribute syntheticAttribute, + NaturalIdMutability naturalIdMutability, + MetaAttributeContext metaAttributeContext, + AttributeRole attributeRole, + AttributePath attributePath, + final List subAttributeBindings) { + AbstractEmbeddableBinding embeddableBinding = new AbstractEmbeddableBinding( + container.seekEntityBinding(), + (AttributeContainer) syntheticAttribute.getSingularAttributeType(), + container.getPrimaryTable(), + attributeRole, + attributePath, + metaAttributeContext, + null, + null) { + private final Map attributeBindingMap = createUnmodifiableAttributeBindingMap( subAttributeBindings ); + + @Override + protected boolean isModifiable() { + return false; + } + + @Override + protected Map attributeBindingMapInternal() { + return this.attributeBindingMap; + } + + @Override + public boolean isAggregated() { + return false; + } + }; + + if ( syntheticAttribute.getSingularAttributeType().isAggregate() ) { + throw new IllegalArgumentException( + "Cannot create a non-aggregated EmbeddableBinding with an aggregate attribute type" + ); + } + return new EmbeddedAttributeBinding( + container, + syntheticAttribute, + "embedded", // TODO: get rid of "magic" string. + false, + false, + naturalIdMutability, + metaAttributeContext, + attributeRole, + attributePath, + embeddableBinding + ); + } + + private static Map createUnmodifiableAttributeBindingMap( + List subAttributeBindings) { + Map map = new LinkedHashMap( subAttributeBindings.size() ); + for ( AttributeBinding subAttributeBinding : subAttributeBindings ) { + map.put( subAttributeBinding.getAttribute().getName(), subAttributeBinding ); + } + return Collections.unmodifiableMap( map ); + } + + @Override + public boolean isAssociation() { + return false; + } + + @Override + protected RelationalValueBindingContainer getRelationalValueBindingContainer() { + return embeddableBinding.getRelationalValueBindingContainer(); + } + + @Override + public boolean hasDerivedValue() { + // todo : not sure this is even relevant for components + return false; + } + + @Override + public boolean isCascadeable() { + for ( AttributeBinding attributeBinding : embeddableBinding.attributeBindings() ) { + if ( attributeBinding.isCascadeable() ) { + return true; + } + } + return false; + } + + @Override + public CascadeStyle getCascadeStyle() { + for ( AttributeBinding attributeBinding : embeddableBinding.attributeBindings() ) { + if ( attributeBinding.isCascadeable() ) { + final Cascadeable cascadeable; + if ( attributeBinding.getAttribute().isSingular() ) { + cascadeable = Cascadeable.class.cast( attributeBinding ); + } + else { + cascadeable = Cascadeable.class.cast( ( (PluralAttributeBinding) attributeBinding ).getPluralAttributeElementBinding() ); + } + CascadeStyle cascadeStyle = cascadeable.getCascadeStyle(); + if ( cascadeStyle != CascadeStyles.NONE ) { + return CascadeStyles.ALL; + } + } + } + return CascadeStyles.NONE; + } + + @Override + public void setCascadeStyle(CascadeStyle cascadeStyle) { + throw new IllegalAccessError( "Composite attribute is not supposed to have cascade" ); + } + + @Override + public boolean isNullable() { + // return false if there are any singular attributes are non-nullable + for ( AttributeBinding attributeBinding : embeddableBinding.attributeBindings() ) { + // only check singular attributes + if ( attributeBinding.getAttribute().isSingular() && + ! ( (SingularAttributeBinding) attributeBinding ).isNullable() ) { + return false; + } + } + return true; + } + + @Override + public boolean isIncludedInInsert() { + // if the attribute is synthetic, this attribute binding (as a whole) is not insertable; + if ( getAttribute().isSynthetic() ) { + return false; + } + // otherwise, return true if there are any singular attributes that are included in the insert. + for ( AttributeBinding attributeBinding : embeddableBinding.attributeBindings() ) { + // only check singular attributes + if ( attributeBinding.getAttribute().isSingular() && + ( (SingularAttributeBinding) attributeBinding ).isIncludedInInsert() ) { + return true; + } + } + return false; + } + + @Override + public boolean isIncludedInUpdate() { + // if the attribute is synthetic, this attribute binding (as a whole) is not updateable; + if ( getAttribute().isSynthetic() ) { + return false; + } + // otherwise, return true if there are any singular attributes that are updatable; + for ( AttributeBinding attributeBinding : embeddableBinding.attributeBindings() ) { + // only check singular attributes + if ( attributeBinding.getAttribute().isSingular() && + ( (SingularAttributeBinding) attributeBinding ).isIncludedInUpdate() ) { + return true; + } + } + return false; + } + + @Override + protected void collectRelationalValueBindings(RelationalValueBindingContainer relationalValueBindingContainer) { + embeddableBinding.collectRelationalValueBindings( relationalValueBindingContainer ); + } + + @Override + public EmbeddableBinding getEmbeddableBinding() { + return embeddableBinding; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/EntityBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/EntityBinding.java index 20ba67e685..d42c6d07c6 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/EntityBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/EntityBinding.java @@ -38,6 +38,9 @@ import org.hibernate.internal.util.collections.ArrayHelper; import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; import org.hibernate.metamodel.source.spi.JpaCallbackSource; import org.hibernate.metamodel.source.spi.MetaAttributeContext; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; +import org.hibernate.metamodel.spi.NaturalIdMutability; import org.hibernate.metamodel.spi.domain.AttributeContainer; import org.hibernate.metamodel.spi.domain.Entity; import org.hibernate.metamodel.spi.domain.SingularAttribute; @@ -108,6 +111,9 @@ public class EntityBinding extends AbstractAttributeBindingContainer implements //for joined sub entitybinding only private boolean isCascadeDeleteEnabled = false; + private AttributePath pathBase; + private AttributeRole roleBase; + public EntityBinding(HierarchyDetails hierarchyDetails) { this.hierarchyDetails = hierarchyDetails; this.superEntityBinding = null; @@ -172,6 +178,9 @@ public class EntityBinding extends AbstractAttributeBindingContainer implements public void setEntity(Entity entity) { this.entity = entity; + + this.pathBase = new AttributePath(); + this.roleBase = new AttributeRole( entity.getName() ); } @Override @@ -241,13 +250,19 @@ public class EntityBinding extends AbstractAttributeBindingContainer implements String[] tokens = path.split( pathDelimiter ); AttributeBinding attributeBinding = locateAttributeBinding( tokens[ 0 ], searchParent ); for ( int i = 1 ; i < tokens.length && attributeBinding != null ; i++ ) { - if ( ! attributeBinding.getAttribute().isSingular() || - ! ( (SingularAttribute) attributeBinding.getAttribute() ).getSingularAttributeType().isAggregate() ) { + final AttributeBindingContainer attributeBindingContainer; + if ( AttributeBindingContainer.class.isInstance( attributeBinding ) ) { + attributeBindingContainer = (AttributeBindingContainer) attributeBinding; + } + else if ( EmbeddedAttributeBinding.class.isInstance( attributeBinding ) ) { + attributeBindingContainer = ( (EmbeddedAttributeBinding) attributeBinding ).getEmbeddableBinding(); + } + else { // TODO: improve this message!!! throw new MappingException( "improve this!!!" ); } - AttributeBindingContainer attributeBindingContainer = (AttributeBindingContainer) attributeBinding; - attributeBinding = attributeBindingContainer.locateAttributeBinding( tokens[ i ] ); + + attributeBinding = attributeBindingContainer.locateAttributeBinding( tokens[i] ); } return attributeBinding; } @@ -304,8 +319,13 @@ public class EntityBinding extends AbstractAttributeBindingContainer implements } @Override - public String getPathBase() { - return ""; + public AttributeRole getRoleBase() { + return roleBase; + } + + @Override + public AttributePath getPathBase() { + return pathBase; } @Override @@ -499,7 +519,7 @@ public class EntityBinding extends AbstractAttributeBindingContainer implements ); } - public CompositeAttributeBinding makeVirtualCompositeAttributeBinding( + public EmbeddedAttributeBinding makeVirtualCompositeAttributeBinding( SingularAttribute syntheticAttribute, MetaAttributeContext metaAttributeContext, List idAttributeBindings) { @@ -509,14 +529,15 @@ public class EntityBinding extends AbstractAttributeBindingContainer implements ); } // TODO: make sure all attributes are singular - final CompositeAttributeBinding binding = - CompositeAttributeBinding.createNonAggregatedCompositeAttributeBinding( - this, - syntheticAttribute, - SingularAttributeBinding.NaturalIdMutability.NOT_NATURAL_ID, - metaAttributeContext, - idAttributeBindings - ); + final EmbeddedAttributeBinding binding = EmbeddedAttributeBinding.createVirtualEmbeddedAttributeBinding( + this, + syntheticAttribute, + NaturalIdMutability.NOT_NATURAL_ID, + metaAttributeContext, + getRoleBase(), + getPathBase(), + idAttributeBindings + ); registerAttributeBinding( binding ); return binding; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/EntityIdentifier.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/EntityIdentifier.java index e3e04adde1..5ca57601d2 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/EntityIdentifier.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/EntityIdentifier.java @@ -93,7 +93,7 @@ public class EntityIdentifier { } public void prepareAsAggregatedCompositeIdentifier( - CompositeAttributeBinding attributeBinding, + EmbeddedAttributeBinding attributeBinding, IdentifierGeneratorDefinition identifierGeneratorDefinition, String unsavedValue, Class lookupIdClass, @@ -108,14 +108,14 @@ public class EntityIdentifier { } public void prepareAsNonAggregatedCompositeIdentifier( - CompositeAttributeBinding compositeAttributeBinding, + EmbeddedAttributeBinding embeddedAttributeBinding, IdentifierGeneratorDefinition identifierGeneratorDefinition, String unsavedValue, Class lookupIdClass, String lookupIdClassAccessType) { ensureNotBound(); this.entityIdentifierBinding = new NonAggregatedCompositeIdentifierBindingImpl( - compositeAttributeBinding, + embeddedAttributeBinding, identifierGeneratorDefinition, unsavedValue, lookupIdClass, @@ -421,14 +421,14 @@ public class EntityIdentifier { private class AggregatedComponentIdentifierBindingImpl extends EntityIdentifierBinding { AggregatedComponentIdentifierBindingImpl( - CompositeAttributeBinding identifierAttributeBinding, + EmbeddedAttributeBinding identifierAttributeBinding, IdentifierGeneratorDefinition identifierGeneratorDefinition, String unsavedValue) { super( AGGREGATED_COMPOSITE, identifierAttributeBinding, identifierGeneratorDefinition, unsavedValue ); - if ( ! identifierAttributeBinding.isAggregated() ) { + if ( ! identifierAttributeBinding.getEmbeddableBinding().isAggregated() ) { throw new IllegalArgumentException( String.format( - "identifierAttributeBinding must be an aggregated CompositeAttributeBinding: %s", + "identifierAttributeBinding must be an aggregated EmbeddedAttributeBinding: %s", identifierAttributeBinding.getAttribute().getName() ) ); @@ -498,28 +498,28 @@ public class EntityIdentifier { private final String externalAggregatingPropertyAccessorName; NonAggregatedCompositeIdentifierBindingImpl( - CompositeAttributeBinding identifierAttributeBinding, + EmbeddedAttributeBinding identifierAttributeBinding, IdentifierGeneratorDefinition identifierGeneratorDefinition, String unsavedValue, Class externalAggregatingClass, String externalAggregatingPropertyAccessorName) { super( NON_AGGREGATED_COMPOSITE, identifierAttributeBinding, identifierGeneratorDefinition, unsavedValue ); - if ( identifierAttributeBinding.isAggregated() ) { + if ( identifierAttributeBinding.getEmbeddableBinding().isAggregated() ) { throw new IllegalArgumentException( String.format( - "identifierAttributeBinding must be a non-aggregated CompositeAttributeBinding: %s", + "identifierAttributeBinding must be a non-aggregated EmbeddedAttributeBinding: %s", identifierAttributeBinding.getAttribute().getName() ) ); } this.externalAggregatingClass = externalAggregatingClass; this.externalAggregatingPropertyAccessorName = externalAggregatingPropertyAccessorName; - if ( identifierAttributeBinding.attributeBindingSpan() == 0 ) { + if ( identifierAttributeBinding.getEmbeddableBinding().attributeBindingSpan() == 0 ) { throw new MappingException( "A composite ID has 0 attributes for " + entityBinding.getEntityName() ); } - for ( AttributeBinding attributeBinding : identifierAttributeBinding.attributeBindings() ) { + for ( AttributeBinding attributeBinding : identifierAttributeBinding.getEmbeddableBinding().attributeBindings() ) { if ( ! attributeBinding.getAttribute().isSingular() ) { throw new MappingException( String.format( @@ -532,15 +532,15 @@ public class EntityIdentifier { } } - private CompositeAttributeBinding getNonAggregatedCompositeAttributeBinding() { - return (CompositeAttributeBinding) getAttributeBinding(); + private EmbeddedAttributeBinding getNonAggregatedCompositeAttributeBinding() { + return (EmbeddedAttributeBinding) getAttributeBinding(); } public boolean isIdentifierAttributeBinding(AttributeBinding attributeBinding) { if ( !isIdentifierMapper() && getNonAggregatedCompositeAttributeBinding().equals( attributeBinding ) ) { return true; } - for ( AttributeBinding idAttributeBindings : getNonAggregatedCompositeAttributeBinding().attributeBindings() ) { + for ( AttributeBinding idAttributeBindings : getNonAggregatedCompositeAttributeBinding().getEmbeddableBinding().attributeBindings() ) { if ( idAttributeBindings.equals( attributeBinding ) ) { return true; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/Helper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/Helper.java index 7440aacd90..594788d9f2 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/Helper.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/Helper.java @@ -24,6 +24,7 @@ package org.hibernate.metamodel.spi.binding; import org.hibernate.AssertionFailure; +import org.hibernate.metamodel.spi.PluralAttributeNature; import org.hibernate.metamodel.spi.domain.PluralAttribute; /** @@ -32,13 +33,13 @@ import org.hibernate.metamodel.spi.domain.PluralAttribute; * @author Steve Ebersole */ public class Helper { - public static void checkPluralAttributeNature(PluralAttribute attribute, PluralAttribute.Nature expected) { - if ( attribute.getNature() != expected ) { + public static void checkPluralAttributeNature(PluralAttribute attribute, PluralAttributeNature expected) { + if ( attribute.getPluralAttributeNature() != expected ) { throw new AssertionFailure( String.format( "Mismatched collection natures; expecting %s, but found %s", - expected.getName(), - attribute.getNature().getName() + expected.name(), + attribute.getPluralAttributeNature().name() ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/ListBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/ListBinding.java index 6a25c5d02c..77bf5a8a16 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/ListBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/ListBinding.java @@ -24,6 +24,9 @@ package org.hibernate.metamodel.spi.binding; import org.hibernate.metamodel.source.spi.MetaAttributeContext; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; +import org.hibernate.metamodel.spi.PluralAttributeElementNature; import org.hibernate.metamodel.spi.domain.PluralAttribute; /** @@ -37,11 +40,13 @@ public class ListBinding extends AbstractPluralAttributeBinding implements Index public ListBinding( AttributeBindingContainer container, PluralAttribute attribute, - PluralAttributeElementBinding.Nature pluralAttributeElementNature, + PluralAttributeElementNature pluralAttributeElementNature, SingularAttributeBinding referencedAttributeBinding, String propertyAccessorName, boolean includedInOptimisticLocking, MetaAttributeContext metaAttributeContext, + AttributeRole attributeRole, + AttributePath attributePath, int base) { super( container, @@ -50,7 +55,10 @@ public class ListBinding extends AbstractPluralAttributeBinding implements Index referencedAttributeBinding, propertyAccessorName, includedInOptimisticLocking, - metaAttributeContext ); + metaAttributeContext, + attributeRole, + attributePath + ); pluralAttributeIndexBinding = new BasicPluralAttributeIndexBinding( this ); this.base = base; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/ManyToOneAttributeBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/ManyToOneAttributeBinding.java index 7d2525bd25..fd70b1c78c 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/ManyToOneAttributeBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/ManyToOneAttributeBinding.java @@ -24,6 +24,9 @@ package org.hibernate.metamodel.spi.binding; import org.hibernate.metamodel.source.spi.MetaAttributeContext; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; +import org.hibernate.metamodel.spi.NaturalIdMutability; import org.hibernate.metamodel.spi.domain.SingularAttribute; /** @@ -44,6 +47,8 @@ public class ManyToOneAttributeBinding boolean isIgnoreNotFound, NaturalIdMutability naturalIdMutability, MetaAttributeContext metaAttributeContext, + AttributeRole attributeRole, + AttributePath attributePath, EntityBinding referencedEntityBinding, SingularAttributeBinding referencedAttributeBinding) { super( @@ -55,6 +60,8 @@ public class ManyToOneAttributeBinding isIgnoreNotFound, naturalIdMutability, metaAttributeContext, + attributeRole, + attributePath, referencedEntityBinding, referencedAttributeBinding ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/MapBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/MapBinding.java index a3d222eb72..02b98ae49c 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/MapBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/MapBinding.java @@ -26,6 +26,10 @@ package org.hibernate.metamodel.spi.binding; import org.hibernate.AssertionFailure; import org.hibernate.cfg.NotYetImplementedException; import org.hibernate.metamodel.source.spi.MetaAttributeContext; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; +import org.hibernate.metamodel.spi.PluralAttributeElementNature; +import org.hibernate.metamodel.spi.PluralAttributeIndexNature; import org.hibernate.metamodel.spi.domain.PluralAttribute; /** @@ -38,12 +42,14 @@ public class MapBinding extends AbstractPluralAttributeBinding implements Indexe public MapBinding( AttributeBindingContainer container, PluralAttribute attribute, - PluralAttributeElementBinding.Nature pluralAttributeElementNature, - PluralAttributeIndexBinding.Nature pluralAttributeIndexNature, + PluralAttributeElementNature pluralAttributeElementNature, + PluralAttributeIndexNature pluralAttributeIndexNature, SingularAttributeBinding referencedAttributeBinding, String propertyAccessorName, boolean includedInOptimisticLocking, - MetaAttributeContext metaAttributeContext) { + MetaAttributeContext metaAttributeContext, + AttributeRole attributeRole, + AttributePath attributePath) { super( container, attribute, @@ -51,7 +57,9 @@ public class MapBinding extends AbstractPluralAttributeBinding implements Indexe referencedAttributeBinding, propertyAccessorName, includedInOptimisticLocking, - metaAttributeContext + metaAttributeContext, + attributeRole, + attributePath ); pluralAttributeIndexBinding = createPluralAttributeIndexBinding( pluralAttributeIndexNature ); } @@ -66,7 +74,7 @@ public class MapBinding extends AbstractPluralAttributeBinding implements Indexe return pluralAttributeIndexBinding; } - private PluralAttributeIndexBinding createPluralAttributeIndexBinding(PluralAttributeIndexBinding.Nature nature) { + private PluralAttributeIndexBinding createPluralAttributeIndexBinding(PluralAttributeIndexNature nature) { switch ( nature ) { case BASIC: { return new BasicPluralAttributeIndexBinding( this ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/OneToOneAttributeBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/OneToOneAttributeBinding.java index 691048a178..06a8894596 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/OneToOneAttributeBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/OneToOneAttributeBinding.java @@ -24,6 +24,9 @@ package org.hibernate.metamodel.spi.binding; import org.hibernate.metamodel.source.spi.MetaAttributeContext; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; +import org.hibernate.metamodel.spi.NaturalIdMutability; import org.hibernate.metamodel.spi.domain.SingularAttribute; /** @@ -43,6 +46,8 @@ public class OneToOneAttributeBinding boolean lazy, NaturalIdMutability naturalIdMutability, MetaAttributeContext metaAttributeContext, + AttributeRole attributeRole, + AttributePath attributePath, EntityBinding referencedEntityBinding, SingularAttributeBinding referencedAttributeBinding, boolean isConstrained) { @@ -55,6 +60,8 @@ public class OneToOneAttributeBinding false, naturalIdMutability, metaAttributeContext, + attributeRole, + attributePath, referencedEntityBinding, referencedAttributeBinding ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/PluralAttributeElementBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/PluralAttributeElementBinding.java index 14b1efc332..b32eda5fc9 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/PluralAttributeElementBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/PluralAttributeElementBinding.java @@ -23,14 +23,11 @@ */ package org.hibernate.metamodel.spi.binding; -import java.util.List; - -import org.hibernate.FetchMode; -import org.hibernate.metamodel.spi.relational.Value; +import org.hibernate.metamodel.spi.PluralAttributeElementNature; /** - * Common information pertaining to the binding of the various plural attribute natures (one-to-many, basic, etc). + * Common "descriptor" for describing the elements of a persistent collection. * * @author Steve Ebersole */ @@ -42,30 +39,12 @@ public interface PluralAttributeElementBinding { */ PluralAttributeBinding getPluralAttributeBinding(); - List getValues(); - - /** - * Retrieve the relational aspect of the element binding. Essentially describes the column(s) to which the - * binding maps the elements - * - * @return The relation information. - */ - List getRelationalValueBindings(); - - boolean isNullable(); - - boolean hasDerivedValue(); - - boolean hasNonNullableValue(); - - FetchMode getFetchMode(); - /** * Retrieves an enumeration describing the mapping nature of the collection's elements. - * + * * @return The nature enum. */ - Nature getNature(); + PluralAttributeElementNature getNature(); /** * Retrieve the Hibernate type descriptor describing the mapping-typing of the elements. @@ -74,52 +53,7 @@ public interface PluralAttributeElementBinding { */ HibernateTypeDescriptor getHibernateTypeDescriptor(); - /** - * Describes the nature of plural attribute elements in terms of relational implications. - * - * @author Steve Ebersole - * @author Gail Badner - */ - public static enum Nature { - /** - * The collection elements are basic, simple values. - */ - BASIC( false, false ), - /** - * The collection elements are compositions. - */ - AGGREGATE( false, true ), - /** - * The collection elements represent entity's in a one-to-many association. - */ - ONE_TO_MANY, - /** - * The collection elements represent entity's in a many-to-many association. - */ - MANY_TO_MANY, - /** - * The collection elements represent entity's in a multi-valued ANY mapping. - */ - MANY_TO_ANY; + // not a fan of this, but for now... - private final boolean isAssociation; - private final boolean isCascadeable; - - private Nature() { - this( true, true ); - } - - private Nature(boolean association, boolean cascadeable) { - this.isAssociation = association; - this.isCascadeable = cascadeable; - } - - public boolean isAssociation() { - return isAssociation; - } - - public boolean isCascadeable() { - return isCascadeable; - } - } + RelationalValueBindingContainer getRelationalValueContainer(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/BasicPluralAttributeElementBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/PluralAttributeElementBindingBasic.java similarity index 62% rename from hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/BasicPluralAttributeElementBinding.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/PluralAttributeElementBindingBasic.java index 8ad5d3887b..f8cf003cb9 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/BasicPluralAttributeElementBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/PluralAttributeElementBindingBasic.java @@ -25,38 +25,54 @@ package org.hibernate.metamodel.spi.binding; import java.util.List; -import org.hibernate.FetchMode; +import org.hibernate.metamodel.spi.PluralAttributeElementNature; +import org.hibernate.metamodel.spi.relational.Value; /** - * Describes plural attributes of {@link org.hibernate.metamodel.spi.binding.PluralAttributeElementBinding.Nature#BASIC} elements + * Describes plural attributes of {@link org.hibernate.metamodel.spi.PluralAttributeElementNature#BASIC} elements * * @author Steve Ebersole * @author Gail Badner */ -public class BasicPluralAttributeElementBinding extends AbstractPluralAttributeElementBinding { - +public class PluralAttributeElementBindingBasic extends AbstractPluralAttributeElementBinding { private RelationalValueBindingContainer relationalValueBindingContainer; - public BasicPluralAttributeElementBinding(AbstractPluralAttributeBinding binding) { + public PluralAttributeElementBindingBasic(AbstractPluralAttributeBinding binding) { super( binding ); } @Override - protected RelationalValueBindingContainer getRelationalValueContainer() { + public PluralAttributeElementNature getNature() { + return PluralAttributeElementNature.BASIC; + } + + @Override + public RelationalValueBindingContainer getRelationalValueContainer() { return relationalValueBindingContainer; } - @Override - public Nature getNature() { - return Nature.BASIC; - } - - @Override - public FetchMode getFetchMode() { - return FetchMode.SELECT; - } - public void setRelationalValueBindings(List relationalValueBindings) { this.relationalValueBindingContainer = new RelationalValueBindingContainer( relationalValueBindings ); } + + + public List getValues() { + return getRelationalValueContainer().values(); + } + + public List getRelationalValueBindings() { + return getRelationalValueContainer().relationalValueBindings(); + } + + public boolean isNullable() { + return getRelationalValueContainer().hasNullableRelationalValueBinding(); + } + + public boolean hasDerivedValue() { + return getRelationalValueContainer().hasDerivedValue(); + } + + public boolean hasNonNullableValue() { + return getRelationalValueContainer().hasNonNullableRelationalValueBinding(); + } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/PluralAttributeElementBindingEmbedded.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/PluralAttributeElementBindingEmbedded.java new file mode 100644 index 0000000000..0e8a6f045a --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/PluralAttributeElementBindingEmbedded.java @@ -0,0 +1,122 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.metamodel.spi.binding; + +import java.util.LinkedHashMap; +import java.util.Map; + +import org.hibernate.engine.spi.CascadeStyle; +import org.hibernate.metamodel.source.spi.MetaAttributeContext; +import org.hibernate.metamodel.spi.PluralAttributeElementNature; +import org.hibernate.metamodel.spi.PluralAttributeNature; +import org.hibernate.metamodel.spi.domain.Aggregate; +import org.hibernate.metamodel.spi.domain.SingularAttribute; +import org.hibernate.tuple.component.ComponentTuplizer; + +/** + * Describes plural attributes of {@link org.hibernate.metamodel.spi.PluralAttributeElementNature#AGGREGATE} elements + * + * @author Steve Ebersole + * @author Gail Badner + */ +public class PluralAttributeElementBindingEmbedded + extends AbstractPluralAttributeElementBinding + implements Cascadeable, EmbeddableBindingContributor { + + private AbstractEmbeddableBinding embeddableBinding; + private CascadeStyle cascadeStyle; + + public PluralAttributeElementBindingEmbedded(AbstractPluralAttributeBinding binding) { + super( binding ); + } + + @Override + public PluralAttributeElementNature getNature() { + return PluralAttributeElementNature.AGGREGATE; + } + + @Override + public RelationalValueBindingContainer getRelationalValueContainer() { + return embeddableBinding.getRelationalValueBindingContainer(); + } + + @Override + public CascadeStyle getCascadeStyle() { + return cascadeStyle; + } + + @Override + public void setCascadeStyle(CascadeStyle cascadeStyle) { + this.cascadeStyle = cascadeStyle; + } + + @Override + public EmbeddableBinding getEmbeddableBinding() { + return embeddableBinding; + + } + + public EmbeddableBinding createBindingContainer( + Aggregate aggregate, + MetaAttributeContext metaAttributeContext, + SingularAttribute parentReference, + Class tuplizerClass) { + if ( embeddableBinding != null ) { + throw new IllegalStateException( "EmbeddableBinding was already set" ); + } + + final boolean isMap = getPluralAttributeBinding().getAttribute().getPluralAttributeNature() + == PluralAttributeNature.MAP; + final String virtualAttributeName = isMap ? "value" : "element"; + + embeddableBinding = new AbstractEmbeddableBinding( + getPluralAttributeBinding().getContainer().seekEntityBinding(), + aggregate, + getPluralAttributeBinding().getPluralAttributeKeyBinding().getCollectionTable(), + getPluralAttributeBinding().getAttributeRole().append( virtualAttributeName ), + getPluralAttributeBinding().getAttributePath().append( virtualAttributeName ), + metaAttributeContext, + parentReference, + tuplizerClass) { + final Map attributeBindingMap = new LinkedHashMap(); + + @Override + protected boolean isModifiable() { + return true; + } + + @Override + protected Map attributeBindingMapInternal() { + return attributeBindingMap; + } + + @Override + public boolean isAggregated() { + return true; + } + }; + + return embeddableBinding; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/ManyToAnyPluralAttributeElementBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/PluralAttributeElementBindingManyToAny.java similarity index 77% rename from hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/ManyToAnyPluralAttributeElementBinding.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/PluralAttributeElementBindingManyToAny.java index 4920baf428..cc6e133f84 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/ManyToAnyPluralAttributeElementBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/PluralAttributeElementBindingManyToAny.java @@ -23,25 +23,27 @@ */ package org.hibernate.metamodel.spi.binding; +import org.hibernate.metamodel.spi.PluralAttributeElementNature; + /** - * Describes plural attributes of {@link org.hibernate.metamodel.spi.binding.PluralAttributeElementBinding.Nature#MANY_TO_ANY} elements + * Describes plural attributes of {@link org.hibernate.metamodel.spi.PluralAttributeElementNature#MANY_TO_ANY} elements * * @author Steve Ebersole * @author Gail Badner */ -public class ManyToAnyPluralAttributeElementBinding extends AbstractPluralAttributeAssociationElementBinding { - ManyToAnyPluralAttributeElementBinding(AbstractPluralAttributeBinding binding) { +public class PluralAttributeElementBindingManyToAny extends AbstractPluralAttributeAssociationElementBinding { + PluralAttributeElementBindingManyToAny(AbstractPluralAttributeBinding binding) { super( binding ); } @Override - protected RelationalValueBindingContainer getRelationalValueContainer() { + public RelationalValueBindingContainer getRelationalValueContainer() { return null; //To change body of implemented methods use File | Settings | File Templates. } @Override - public Nature getNature() { - return Nature.MANY_TO_ANY; + public PluralAttributeElementNature getNature() { + return PluralAttributeElementNature.MANY_TO_ANY; } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/ManyToManyPluralAttributeElementBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/PluralAttributeElementBindingManyToMany.java similarity index 87% rename from hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/ManyToManyPluralAttributeElementBinding.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/PluralAttributeElementBindingManyToMany.java index 9c87d8a60f..0ec48baa04 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/ManyToManyPluralAttributeElementBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/PluralAttributeElementBindingManyToMany.java @@ -28,33 +28,34 @@ import java.util.List; import org.hibernate.FetchMode; import org.hibernate.internal.FilterConfiguration; +import org.hibernate.metamodel.spi.PluralAttributeElementNature; import org.hibernate.metamodel.spi.relational.ForeignKey; /** - * Describes plural attributes of {@link org.hibernate.metamodel.spi.binding.PluralAttributeElementBinding.Nature#MANY_TO_MANY} elements + * Describes plural attributes of {@link org.hibernate.metamodel.spi.PluralAttributeElementNature#MANY_TO_MANY} elements * * @author Steve Ebersole * @author Gail Badner */ -public class ManyToManyPluralAttributeElementBinding extends AbstractPluralAttributeAssociationElementBinding implements Filterable{ +public class PluralAttributeElementBindingManyToMany extends AbstractPluralAttributeAssociationElementBinding implements Filterable{ private List filterConfigurations = new ArrayList(); private String manyToManyWhere; private String manyToManyOrderBy; private FetchMode fetchMode; private JoinRelationalValueBindingContainer relationalValueBindingContainer; - ManyToManyPluralAttributeElementBinding(AbstractPluralAttributeBinding binding) { + PluralAttributeElementBindingManyToMany(AbstractPluralAttributeBinding binding) { super( binding ); } @Override - protected RelationalValueBindingContainer getRelationalValueContainer() { + public RelationalValueBindingContainer getRelationalValueContainer() { return relationalValueBindingContainer; } @Override - public Nature getNature() { - return Nature.MANY_TO_MANY; + public PluralAttributeElementNature getNature() { + return PluralAttributeElementNature.MANY_TO_MANY; } public void setJoinRelationalValueBindings( @@ -86,12 +87,6 @@ public class ManyToManyPluralAttributeElementBinding extends AbstractPluralAttri this.manyToManyOrderBy = manyToManyOrderBy; } - - @Override - public FetchMode getFetchMode() { - return fetchMode; - } - public void setFetchMode(FetchMode fetchMode) { this.fetchMode = fetchMode; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/OneToManyPluralAttributeElementBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/PluralAttributeElementBindingOneToMany.java similarity index 79% rename from hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/OneToManyPluralAttributeElementBinding.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/PluralAttributeElementBindingOneToMany.java index 368aba6f54..7dbb80b90a 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/OneToManyPluralAttributeElementBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/PluralAttributeElementBindingOneToMany.java @@ -25,37 +25,32 @@ package org.hibernate.metamodel.spi.binding; import java.util.List; -import org.hibernate.FetchMode; +import org.hibernate.metamodel.spi.PluralAttributeElementNature; /** - * Describes plural attributes of {@link org.hibernate.metamodel.spi.binding.PluralAttributeElementBinding.Nature#ONE_TO_MANY} elements + * Describes plural attributes of {@link org.hibernate.metamodel.spi.PluralAttributeElementNature#ONE_TO_MANY} elements * * @author Steve Ebersole * @author Gail Badner */ -public class OneToManyPluralAttributeElementBinding extends AbstractPluralAttributeAssociationElementBinding { +public class PluralAttributeElementBindingOneToMany extends AbstractPluralAttributeAssociationElementBinding { private RelationalValueBindingContainer relationalValueBindingContainer; - OneToManyPluralAttributeElementBinding(AbstractPluralAttributeBinding binding) { + PluralAttributeElementBindingOneToMany(AbstractPluralAttributeBinding binding) { super( binding ); } @Override - protected RelationalValueBindingContainer getRelationalValueContainer() { + public RelationalValueBindingContainer getRelationalValueContainer() { return relationalValueBindingContainer; } @Override - public Nature getNature() { - return Nature.ONE_TO_MANY; + public PluralAttributeElementNature getNature() { + return PluralAttributeElementNature.ONE_TO_MANY; } public void setElementEntityIdentifier(List relationalValueBindingList) { this.relationalValueBindingContainer = new RelationalValueBindingContainer( relationalValueBindingList ); } - - @Override - public FetchMode getFetchMode() { - return FetchMode.JOIN; - } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/PluralAttributeIndexBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/PluralAttributeIndexBinding.java index f462e536e9..e7b03fbeb1 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/PluralAttributeIndexBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/PluralAttributeIndexBinding.java @@ -25,6 +25,7 @@ package org.hibernate.metamodel.spi.binding; import java.util.List; +import org.hibernate.metamodel.spi.PluralAttributeIndexNature; import org.hibernate.metamodel.spi.domain.Type; import org.hibernate.metamodel.spi.relational.Value; @@ -34,7 +35,7 @@ import org.hibernate.metamodel.spi.relational.Value; public interface PluralAttributeIndexBinding { IndexedPluralAttributeBinding getIndexedPluralAttributeBinding(); - Nature getNature(); + PluralAttributeIndexNature getNature(); /** * Retrieve the relational aspect of the index binding. Essentially describes the @@ -50,27 +51,4 @@ public interface PluralAttributeIndexBinding { Type getPluralAttributeIndexType(); - /** - * Describes the nature of plural attribute indexes in terms of relational implications. - * - * @author Steve Ebersole - */ - enum Nature { - /** - * The collection indexes are basic, simple values. This is the only valid nature for lists - */ - BASIC, - /** - * The map key is an aggregated composite - */ - AGGREGATE, - /** - * The map key is an association identified by a column(s) on the collection table. - */ - MANY_TO_MANY, - /** - * The map key is represented by a Hibernate ANY mapping - */ - MANY_TO_ANY - } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/RelationalValueBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/RelationalValueBinding.java index 7365c8f023..95ae8145ac 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/RelationalValueBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/RelationalValueBinding.java @@ -108,4 +108,11 @@ public class RelationalValueBinding { public boolean isIncludeInUpdate() { return includeInUpdate; } + + @Override + public String toString() { + return "RelationalValueBinding{table=" + table.toLoggableString() + + ", value=" + value.toLoggableString() + + '}'; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/SetBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/SetBinding.java index ab2bd577d6..9d76571926 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/SetBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/SetBinding.java @@ -24,6 +24,9 @@ package org.hibernate.metamodel.spi.binding; import org.hibernate.metamodel.source.spi.MetaAttributeContext; +import org.hibernate.metamodel.spi.AttributePath; +import org.hibernate.metamodel.spi.AttributeRole; +import org.hibernate.metamodel.spi.PluralAttributeElementNature; import org.hibernate.metamodel.spi.domain.PluralAttribute; /** @@ -34,11 +37,13 @@ public class SetBinding extends AbstractPluralAttributeBinding { public SetBinding( AttributeBindingContainer container, PluralAttribute attribute, - PluralAttributeElementBinding.Nature pluralAttributeElementNature, + PluralAttributeElementNature pluralAttributeElementNature, SingularAttributeBinding referencedAttributeBinding, String propertyAccessorName, boolean includedInOptimisticLocking, - MetaAttributeContext metaAttributeContext) { + MetaAttributeContext metaAttributeContext, + AttributeRole attributeRole, + AttributePath attributePath) { super( container, attribute, @@ -46,7 +51,9 @@ public class SetBinding extends AbstractPluralAttributeBinding { referencedAttributeBinding, propertyAccessorName, includedInOptimisticLocking, - metaAttributeContext + metaAttributeContext, + attributeRole, + attributePath ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/SingularAttributeBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/SingularAttributeBinding.java index fa0d4f230f..a3910bb91b 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/SingularAttributeBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/SingularAttributeBinding.java @@ -25,6 +25,7 @@ package org.hibernate.metamodel.spi.binding; import java.util.List; +import org.hibernate.metamodel.spi.NaturalIdMutability; import org.hibernate.metamodel.spi.domain.SingularAttribute; import org.hibernate.metamodel.spi.relational.Value; @@ -82,16 +83,11 @@ public interface SingularAttributeBinding extends AttributeBinding { /** * Convenience method to determine if this attribute is an natural id and if it is, then returns its mutability. * - * @return The {@link NaturalIdMutability} linked with this attribute, + * @return The {@link org.hibernate.metamodel.spi.NaturalIdMutability} linked with this attribute, * {@code NaturalIdMutability#NOT_NATURAL_ID} indicates this is NOT a natural id attribute. */ public NaturalIdMutability getNaturalIdMutability(); public void setAlternateUniqueKey(boolean alternateUniqueKey); - public enum NaturalIdMutability { - MUTABLE, - IMMUTABLE, - NOT_NATURAL_ID - } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/AbstractAttributeContainer.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/AbstractAttributeContainer.java index 183f57936c..7a088a082b 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/AbstractAttributeContainer.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/AbstractAttributeContainer.java @@ -30,6 +30,7 @@ import java.util.Set; import org.hibernate.internal.util.StringHelper; import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; +import org.hibernate.metamodel.spi.PluralAttributeNature; /** * Convenient base class for {@link AttributeContainer}. Because in our model all @@ -153,35 +154,35 @@ public abstract class AbstractAttributeContainer implements AttributeContainer, @Override public PluralAttribute createBag(String name) { - return createPluralAttribute( name, PluralAttribute.Nature.BAG ); + return createPluralAttribute( name, PluralAttributeNature.BAG ); } - protected PluralAttribute createPluralAttribute(String name, PluralAttribute.Nature nature) { - PluralAttribute attribute = nature.isIndexable() - ? new IndexedPluralAttributeImpl( this, name, nature ) - : new PluralAttributeImpl( this, name, nature ); + protected PluralAttribute createPluralAttribute(String name, PluralAttributeNature pluralAttributeNature) { + PluralAttribute attribute = pluralAttributeNature.isIndexed() + ? new IndexedPluralAttributeImpl( this, name, pluralAttributeNature ) + : new PluralAttributeImpl( this, name, pluralAttributeNature ); addAttribute( attribute ); return attribute; } @Override public PluralAttribute createSet(String name) { - return createPluralAttribute( name, PluralAttribute.Nature.SET ); + return createPluralAttribute( name, PluralAttributeNature.SET ); } @Override public IndexedPluralAttribute createList(String name) { - return (IndexedPluralAttribute) createPluralAttribute( name, PluralAttribute.Nature.LIST ); + return (IndexedPluralAttribute) createPluralAttribute( name, PluralAttributeNature.LIST ); } @Override public IndexedPluralAttribute createArray(String name) { - return (IndexedPluralAttribute) createPluralAttribute( name, PluralAttribute.Nature.ARRAY ); + return (IndexedPluralAttribute) createPluralAttribute( name, PluralAttributeNature.ARRAY ); } @Override public IndexedPluralAttribute createMap(String name) { - return (IndexedPluralAttribute) createPluralAttribute( name, PluralAttribute.Nature.MAP ); + return (IndexedPluralAttribute) createPluralAttribute( name, PluralAttributeNature.MAP ); } protected void addAttribute(Attribute attribute) { @@ -244,15 +245,15 @@ public abstract class AbstractAttributeContainer implements AttributeContainer, public static class PluralAttributeImpl implements PluralAttribute { private final AttributeContainer attributeContainer; - private final Nature nature; + private final PluralAttributeNature pluralAttributeNature; private final String name; private Type elementType; - public PluralAttributeImpl(AbstractAttributeContainer attributeContainer, String name, Nature nature) { + public PluralAttributeImpl(AbstractAttributeContainer attributeContainer, String name, PluralAttributeNature pluralAttributeNature) { this.attributeContainer = attributeContainer; this.name = name; - this.nature = nature; + this.pluralAttributeNature = pluralAttributeNature; } @Override @@ -272,8 +273,8 @@ public abstract class AbstractAttributeContainer implements AttributeContainer, } @Override - public Nature getNature() { - return nature; + public PluralAttributeNature getPluralAttributeNature() { + return pluralAttributeNature; } @Override @@ -300,8 +301,8 @@ public abstract class AbstractAttributeContainer implements AttributeContainer, public static class IndexedPluralAttributeImpl extends PluralAttributeImpl implements IndexedPluralAttribute { private Type indexType; - public IndexedPluralAttributeImpl(AbstractAttributeContainer attributeContainer, String name, Nature nature) { - super( attributeContainer, name, nature ); + public IndexedPluralAttributeImpl(AbstractAttributeContainer attributeContainer, String name, PluralAttributeNature pluralAttributeNature) { + super( attributeContainer, name, pluralAttributeNature ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/PluralAttribute.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/PluralAttribute.java index 4cbe368d4b..6082fcf3eb 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/PluralAttribute.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/PluralAttribute.java @@ -23,10 +23,7 @@ */ package org.hibernate.metamodel.spi.domain; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Set; +import org.hibernate.metamodel.spi.PluralAttributeNature; /** * TODO : javadoc @@ -35,45 +32,7 @@ import java.util.Set; */ public interface PluralAttribute extends Attribute { public String getRole(); - public Nature getNature(); + public PluralAttributeNature getPluralAttributeNature(); public Type getElementType(); public void setElementType(Type elementType); - - /** - * Identifies the specific semantic of a plural valued attribute. - * - * @author Steve Ebersole - */ - enum Nature { - ARRAY( "array", Object[].class ), - BAG( "bag", Collection.class ), - IDBAG( "idbag", Collection.class ), - SET( "set", Set.class ), - LIST( "list", List.class ), - MAP( "map", Map.class ); - - private final String name; - private final Class javaContract; - private final boolean indexable; - - Nature(String name, Class javaContract) { - this.name = name; - this.javaContract = javaContract; - this.indexable = Map.class.isAssignableFrom( javaContract ) - || List.class.isAssignableFrom( javaContract ) - || javaContract.isArray(); - } - - public String getName() { - return name; - } - - public Class getJavaContract() { - return javaContract; - } - - public boolean isIndexable() { - return indexable; - } - } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/AbstractTableSpecification.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/AbstractTableSpecification.java index 85f9154e18..efe2625a0b 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/AbstractTableSpecification.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/AbstractTableSpecification.java @@ -37,7 +37,10 @@ import java.util.List; */ public abstract class AbstractTableSpecification implements TableSpecification { - // A column an derived value can have the same text, so use the Value.ValueType to disambiguate. + /** + * A column and derived value can have the same text; this value class helps + * to disambiguate. + */ private class ValueKey { private final Value.ValueType valueType; private final Identifier identifier; @@ -71,6 +74,13 @@ public abstract class AbstractTableSpecification implements TableSpecification { result = 31 * result + ( identifier != null ? identifier.hashCode() : 0 ); return result; } + + @Override + public String toString() { + return "ValueKey{valueType=" + valueType.name() + + ", identifier=" + identifier + + '}'; + } } private int tableNumber; diff --git a/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java index 5a97b7f9d3..72db73ef35 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java @@ -75,17 +75,17 @@ import org.hibernate.metadata.CollectionMetadata; import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; import org.hibernate.metamodel.reflite.spi.PrimitiveTypeDescriptor; import org.hibernate.metamodel.spi.MetadataImplementor; +import org.hibernate.metamodel.spi.PluralAttributeElementNature; +import org.hibernate.metamodel.spi.PluralAttributeNature; import org.hibernate.metamodel.spi.binding.AbstractPluralAttributeBinding; import org.hibernate.metamodel.spi.binding.Cascadeable; import org.hibernate.metamodel.spi.binding.CustomSQL; import org.hibernate.metamodel.spi.binding.IndexedPluralAttributeBinding; import org.hibernate.metamodel.spi.binding.ListBinding; -import org.hibernate.metamodel.spi.binding.ManyToManyPluralAttributeElementBinding; -import org.hibernate.metamodel.spi.binding.PluralAttributeElementBinding; +import org.hibernate.metamodel.spi.binding.PluralAttributeElementBindingManyToMany; import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding; import org.hibernate.metamodel.spi.binding.PluralAttributeKeyBinding; import org.hibernate.metamodel.spi.binding.RelationalValueBinding; -import org.hibernate.metamodel.spi.domain.PluralAttribute; import org.hibernate.metamodel.spi.relational.DerivedValue; import org.hibernate.metamodel.spi.relational.TableSpecification; import org.hibernate.metamodel.spi.relational.Value; @@ -268,8 +268,8 @@ public abstract class AbstractCollectionPersister this.factory = factory; this.cacheAccessStrategy = cacheAccessStrategy; if ( factory.getSettings().isStructuredCacheEntriesEnabled() ) { - cacheEntryStructure = collection.getAttribute().getNature() == PluralAttribute.Nature.MAP ? - StructuredMapCacheEntry.INSTANCE + cacheEntryStructure = collection.getAttribute().getPluralAttributeNature() == PluralAttributeNature.MAP + ? StructuredMapCacheEntry.INSTANCE : StructuredCollectionCacheEntry.INSTANCE; } else { @@ -299,7 +299,7 @@ public abstract class AbstractCollectionPersister isMutable = collection.isMutable(); TableSpecification table = collection.getPluralAttributeKeyBinding().getCollectionTable(); - fetchMode = collection.getPluralAttributeElementBinding().getFetchMode(); + fetchMode = collection.getFetchMode(); elementType = collection.getPluralAttributeElementBinding().getHibernateTypeDescriptor().getResolvedTypeMapping(); // isSet = collection.isSet(); // isSorted = collection.isSorted(); @@ -377,9 +377,9 @@ public abstract class AbstractCollectionPersister elementPersister = null; } elementNodeName = null; - int elementSpan = collection.getPluralAttributeElementBinding().getRelationalValueBindings() == null ? - 0 : - collection.getPluralAttributeElementBinding().getRelationalValueBindings().size(); + int elementSpan = collection.getPluralAttributeElementBinding().getRelationalValueContainer().relationalValueBindings() == null + ? 0 + : collection.getPluralAttributeElementBinding().getRelationalValueContainer().relationalValueBindings().size(); elementColumnAliases = new String[elementSpan]; elementColumnNames = new String[elementSpan]; elementColumnWriters = new String[elementSpan]; @@ -393,7 +393,7 @@ public abstract class AbstractCollectionPersister boolean hasNotNullableColumns = false; int j = 0; if ( elementSpan > 0 ) { - for ( RelationalValueBinding relationalValueBinding : collection.getPluralAttributeElementBinding().getRelationalValueBindings() ) { + for ( RelationalValueBinding relationalValueBinding : collection.getPluralAttributeElementBinding().getRelationalValueContainer().relationalValueBindings() ) { final Value value = relationalValueBinding.getValue(); elementColumnAliases[j] = value.getAlias( dialect, table ); if ( DerivedValue.class.isInstance( value ) ) { @@ -478,7 +478,7 @@ public abstract class AbstractCollectionPersister indexContainsFormula = false; } - hasIdentifier = collection.getAttribute().getNature() == PluralAttribute.Nature.IDBAG; + hasIdentifier = collection.getAttribute().getPluralAttributeNature() == PluralAttributeNature.ID_BAG; // TODO: fix this when IdBags are supported. //if ( hasIdentifier ) { //} @@ -549,7 +549,7 @@ public abstract class AbstractCollectionPersister sqlSelectSizeString = generateSelectSizeString( collection.hasIndex() && - collection.getAttribute().getNature() != PluralAttribute.Nature.MAP + collection.getAttribute().getPluralAttributeNature() != PluralAttributeNature.MAP ); sqlDetectRowByIndexString = generateDetectRowByIndexString(); sqlDetectRowByElementString = generateDetectRowByElementString(); @@ -623,9 +623,9 @@ public abstract class AbstractCollectionPersister filterHelper = new FilterHelper( collection.getFilterConfigurations(), factory ); if ( collection.getPluralAttributeElementBinding() - .getNature() == PluralAttributeElementBinding.Nature.MANY_TO_MANY ) { - final ManyToManyPluralAttributeElementBinding manyToManyElementBinding = - (ManyToManyPluralAttributeElementBinding) collection.getPluralAttributeElementBinding(); + .getNature() == PluralAttributeElementNature.MANY_TO_MANY ) { + final PluralAttributeElementBindingManyToMany manyToManyElementBinding = + (PluralAttributeElementBindingManyToMany) collection.getPluralAttributeElementBinding(); manyToManyFilterHelper = new FilterHelper( manyToManyElementBinding.getFilterConfigurations(), factory ); manyToManyWhereString = StringHelper.isNotEmpty( manyToManyElementBinding.getManyToManyWhere() ) ? "( " +manyToManyElementBinding.getManyToManyWhere() + ")" : diff --git a/hibernate-core/src/main/java/org/hibernate/persister/collection/OneToManyPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/collection/OneToManyPersister.java index 51e5796183..b790acc7a8 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/collection/OneToManyPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/collection/OneToManyPersister.java @@ -34,7 +34,6 @@ import org.hibernate.HibernateException; import org.hibernate.MappingException; import org.hibernate.cache.CacheException; import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy; -import org.hibernate.cfg.Configuration; import org.hibernate.collection.spi.PersistentCollection; import org.hibernate.engine.jdbc.batch.internal.BasicBatchKey; import org.hibernate.engine.spi.LoadQueryInfluencers; @@ -49,10 +48,9 @@ import org.hibernate.loader.collection.BatchingCollectionInitializerBuilder; import org.hibernate.loader.collection.CollectionInitializer; import org.hibernate.loader.collection.SubselectOneToManyLoader; import org.hibernate.loader.entity.CollectionElementLoader; -import org.hibernate.mapping.Collection; import org.hibernate.metamodel.spi.MetadataImplementor; +import org.hibernate.metamodel.spi.PluralAttributeElementNature; import org.hibernate.metamodel.spi.binding.AbstractPluralAttributeBinding; -import org.hibernate.metamodel.spi.binding.PluralAttributeElementBinding; import org.hibernate.metamodel.spi.binding.PluralAttributeKeyBinding; import org.hibernate.persister.entity.Joinable; import org.hibernate.persister.entity.OuterJoinLoadable; @@ -79,10 +77,10 @@ public class OneToManyPersister extends AbstractCollectionPersister { SessionFactoryImplementor factory) throws MappingException, CacheException { super( collection, cacheAccessStrategy, metadataImplementor, factory ); if ( collection.getPluralAttributeElementBinding().getNature() != - PluralAttributeElementBinding.Nature.ONE_TO_MANY ) { + PluralAttributeElementNature.ONE_TO_MANY ) { throw new AssertionError( String.format( "Unexpected plural attribute nature; expected=(%s), actual=(%s)", - PluralAttributeElementBinding.Nature.ONE_TO_MANY, + PluralAttributeElementNature.ONE_TO_MANY, collection.getPluralAttributeElementBinding().getNature() ) ); diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java index 219ef6accf..eca85d72c9 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java @@ -106,8 +106,8 @@ import org.hibernate.metadata.ClassMetadata; import org.hibernate.metamodel.spi.binding.AttributeBinding; import org.hibernate.metamodel.spi.binding.BasicAttributeBinding; import org.hibernate.metamodel.spi.binding.Cascadeable; -import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding; import org.hibernate.metamodel.spi.binding.CustomSQL; +import org.hibernate.metamodel.spi.binding.EmbeddedAttributeBinding; import org.hibernate.metamodel.spi.binding.EntityBinding; import org.hibernate.metamodel.spi.binding.Fetchable; import org.hibernate.metamodel.spi.binding.PluralAttributeBinding; @@ -2163,11 +2163,11 @@ public abstract class AbstractEntityPersister } SingularAttributeBinding singularProp = (SingularAttributeBinding) prop; String propname = path == null ? prop.getAttribute().getName() : path + "." + prop.getAttribute().getName(); - if ( prop instanceof CompositeAttributeBinding ) { - CompositeAttributeBinding component = (CompositeAttributeBinding) prop; - AttributeBinding[] abs = new AttributeBinding[component.attributeBindingSpan()]; + if ( prop instanceof EmbeddedAttributeBinding ) { + EmbeddedAttributeBinding component = (EmbeddedAttributeBinding) prop; + AttributeBinding[] abs = new AttributeBinding[component.getEmbeddableBinding().attributeBindingSpan()]; int i=0; - for(AttributeBinding ab : component.attributeBindings()){ + for(AttributeBinding ab : component.getEmbeddableBinding().attributeBindings()){ abs[i++] = ab; } internalInitSubclassPropertyAliasesMap( propname, abs ); diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractPropertyMapping.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractPropertyMapping.java index dc0f31dc43..65e0436841 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractPropertyMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractPropertyMapping.java @@ -174,11 +174,12 @@ public abstract class AbstractPropertyMapping implements PropertyMapping { final Mapping factory) throws MappingException { - if ( columns.length!=type.getColumnSpan(factory) ) { + if ( columns.length != type.getColumnSpan(factory) ) { throw new MappingException( - "broken column mapping for: " + path + - " of: " + getEntityName() - ); + "broken column mapping [" + getEntityName() + '#' + path + + "]; expecting " + columns.length + " columns, but type defined " + + type.getColumnSpan(factory) + ); } if ( type.isAssociationType() ) { diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/SingleTableEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/SingleTableEntityPersister.java index 07f76549b8..33c223192f 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/SingleTableEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/SingleTableEntityPersister.java @@ -43,7 +43,6 @@ import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.internal.DynamicFilterAliasGenerator; import org.hibernate.internal.FilterAliasGenerator; import org.hibernate.internal.util.MarkerObject; -import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.collections.ArrayHelper; import org.hibernate.metamodel.spi.binding.AttributeBinding; import org.hibernate.metamodel.spi.binding.EntityBinding; @@ -360,9 +359,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister { for ( AttributeBinding attributeBinding : entityBinding.getNonIdEntitiesAttributeBindingClosure() ) { final String entityName = attributeBinding.getContainer().seekEntityBinding().getEntityName(); - String path = StringHelper.isEmpty( attributeBinding.getContainer().getPathBase() ) ? - entityName + '.' + attributeBinding.getAttribute().getName() : - entityName + '.' + attributeBinding.getContainer().getPathBase() + '.' + attributeBinding.getAttribute().getName(); + final String path = entityName + '.' + attributeBinding.getAttributePath().getFullPath(); if ( attributeBinding.getAttribute().isSingular() ) { SingularAttributeBinding singularAttributeBinding = (SingularAttributeBinding) attributeBinding; int join = entityBinding.getSecondaryTableNumber( singularAttributeBinding ); diff --git a/hibernate-core/src/main/java/org/hibernate/persister/internal/StandardPersisterClassResolver.java b/hibernate-core/src/main/java/org/hibernate/persister/internal/StandardPersisterClassResolver.java index 30a1919338..f671f8cc96 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/internal/StandardPersisterClassResolver.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/internal/StandardPersisterClassResolver.java @@ -31,9 +31,9 @@ import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.RootClass; import org.hibernate.mapping.SingleTableSubclass; import org.hibernate.mapping.UnionSubclass; +import org.hibernate.metamodel.spi.PluralAttributeElementNature; import org.hibernate.metamodel.spi.binding.EntityBinding; import org.hibernate.metamodel.spi.binding.PluralAttributeBinding; -import org.hibernate.metamodel.spi.binding.PluralAttributeElementBinding; import org.hibernate.persister.collection.BasicCollectionPersister; import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.collection.OneToManyPersister; @@ -126,7 +126,7 @@ public class StandardPersisterClassResolver implements PersisterClassResolver { @Override public Class getCollectionPersisterClass(PluralAttributeBinding metadata) { - return metadata.getPluralAttributeElementBinding().getNature() == PluralAttributeElementBinding.Nature.ONE_TO_MANY + return metadata.getPluralAttributeElementBinding().getNature() == PluralAttributeElementNature.ONE_TO_MANY ? oneToManyPersister() : basicCollectionPersister(); } diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/PojoInstantiator.java b/hibernate-core/src/main/java/org/hibernate/tuple/PojoInstantiator.java index 1e0cdd0e16..07c3df2e72 100755 --- a/hibernate-core/src/main/java/org/hibernate/tuple/PojoInstantiator.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/PojoInstantiator.java @@ -34,7 +34,7 @@ import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.bytecode.spi.ReflectionOptimizer; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.ReflectHelper; -import org.hibernate.metamodel.spi.binding.CompositeAttributeBindingContainer; +import org.hibernate.metamodel.spi.binding.EmbeddableBinding; import org.hibernate.metamodel.spi.binding.EntityBinding; import org.hibernate.metamodel.spi.binding.EntityIdentifier; import org.hibernate.service.ServiceRegistry; @@ -58,18 +58,18 @@ public class PojoInstantiator implements Instantiator, Serializable { public PojoInstantiator( ServiceRegistry serviceRegistry, - CompositeAttributeBindingContainer compositeAttributeBindingContainer, + EmbeddableBinding embeddableBinding, boolean isIdentifierMapper, ReflectionOptimizer.InstantiationOptimizer optimizer) { if ( isIdentifierMapper ) { final EntityIdentifier entityIdentifier = - compositeAttributeBindingContainer.seekEntityBinding().getHierarchyDetails().getEntityIdentifier(); + embeddableBinding.seekEntityBinding().getHierarchyDetails().getEntityIdentifier(); this.mappedClass = entityIdentifier.getLookupClassBinding().getIdClassType(); } else { final ClassLoaderService cls = serviceRegistry.getService( ClassLoaderService.class ); this.mappedClass = cls.classForName( - compositeAttributeBindingContainer.getAttributeContainer().getDescriptor().getName().toString() + embeddableBinding.getAttributeContainer().getDescriptor().getName().toString() ); } this.isAbstract = ReflectHelper.isAbstractClass( mappedClass ); diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/PropertyFactory.java b/hibernate-core/src/main/java/org/hibernate/tuple/PropertyFactory.java index 2f1b17e2ac..0e99802534 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/PropertyFactory.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/PropertyFactory.java @@ -44,7 +44,7 @@ import org.hibernate.metamodel.spi.binding.AbstractPluralAttributeBinding; import org.hibernate.metamodel.spi.binding.AttributeBinding; import org.hibernate.metamodel.spi.binding.BasicAttributeBinding; import org.hibernate.metamodel.spi.binding.Cascadeable; -import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding; +import org.hibernate.metamodel.spi.binding.EmbeddedAttributeBinding; import org.hibernate.metamodel.spi.binding.EntityBinding; import org.hibernate.metamodel.spi.binding.Fetchable; import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; @@ -143,7 +143,7 @@ public final class PropertyFactory { type = sessionFactory.getTypeResolver().getTypeFactory().component( new ComponentMetamodel( sessionFactory.getServiceRegistry(), - ( (CompositeAttributeBinding) attributeBinding ), + ( (EmbeddedAttributeBinding) attributeBinding ).getEmbeddableBinding(), true, true ) @@ -395,6 +395,9 @@ public final class PropertyFactory { AttributeBinding property, boolean lazyAvailable) { final Type type = property.getHibernateTypeDescriptor().getResolvedTypeMapping(); + if ( type == null ) { + throw new HibernateException( "Could not resolve Type for attribute : " + property.getAttributeRole().getFullPath() ); + } final NonIdentifierAttributeNature nature = decode( type ); final boolean alwaysDirtyCheck = type.isAssociationType() && ( (AssociationType) type ).isAlwaysDirtyChecked(); diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/component/AbstractComponentTuplizer.java b/hibernate-core/src/main/java/org/hibernate/tuple/component/AbstractComponentTuplizer.java index bd86ba0baf..ce211402d6 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/component/AbstractComponentTuplizer.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/component/AbstractComponentTuplizer.java @@ -30,7 +30,7 @@ import org.hibernate.HibernateException; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.metamodel.spi.binding.AttributeBinding; -import org.hibernate.metamodel.spi.binding.CompositeAttributeBindingContainer; +import org.hibernate.metamodel.spi.binding.EmbeddableBinding; import org.hibernate.property.Getter; import org.hibernate.property.Setter; import org.hibernate.service.ServiceRegistry; @@ -53,32 +53,32 @@ public abstract class AbstractComponentTuplizer implements ComponentTuplizer { protected AbstractComponentTuplizer( ServiceRegistry serviceRegistry, - CompositeAttributeBindingContainer compositeAttributeBindingContainer, + EmbeddableBinding embeddableBinding, boolean isIdentifierMapper) { // TODO: Get rid of the need for isIdentifierMapper arg. - // Instead the CompositeAttributeBinding should be wrapped (e.g., by a proxy) + // Instead the EmbeddedAttributeBinding should be wrapped (e.g., by a proxy) // so it can provide the information needed to create getters and setters // for an identifier mapper. this.serviceRegistry = serviceRegistry; - propertySpan = compositeAttributeBindingContainer.attributeBindingSpan(); + propertySpan = embeddableBinding.attributeBindingSpan(); getters = new Getter[propertySpan]; setters = new Setter[propertySpan]; boolean foundCustomAccessor = false; int i = 0; - for ( AttributeBinding attributeBinding : compositeAttributeBindingContainer.attributeBindings() ) { - getters[i] = buildGetter( compositeAttributeBindingContainer, isIdentifierMapper, attributeBinding ); - setters[i] = buildSetter( compositeAttributeBindingContainer, isIdentifierMapper, attributeBinding ); + for ( AttributeBinding attributeBinding : embeddableBinding.attributeBindings() ) { + getters[i] = buildGetter( embeddableBinding, isIdentifierMapper, attributeBinding ); + setters[i] = buildSetter( embeddableBinding, isIdentifierMapper, attributeBinding ); if ( !attributeBinding.isBasicPropertyAccessor() ) { foundCustomAccessor = true; } i++; } hasCustomAccessors = foundCustomAccessor; - instantiator = buildInstantiator( compositeAttributeBindingContainer, isIdentifierMapper ); + instantiator = buildInstantiator( embeddableBinding, isIdentifierMapper ); } protected ServiceRegistry serviceRegistry() { @@ -116,18 +116,18 @@ public abstract class AbstractComponentTuplizer implements ComponentTuplizer { } protected abstract Instantiator buildInstantiator( - CompositeAttributeBindingContainer compositeAttributeBindingContainer, + EmbeddableBinding embeddableBinding, boolean isIdentifierMapper ); protected abstract Getter buildGetter( - CompositeAttributeBindingContainer compositeAttributeBindingContainer, + EmbeddableBinding embeddableBinding, boolean isIdentifierMapper, AttributeBinding attributeBinding ); protected abstract Setter buildSetter( - CompositeAttributeBindingContainer compositeAttributeBindingContainer, + EmbeddableBinding embeddableBinding, boolean isIdentifierMapper, AttributeBinding attributeBinding ); diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/component/ComponentMetamodel.java b/hibernate-core/src/main/java/org/hibernate/tuple/component/ComponentMetamodel.java index e36dc418b7..979af15ef6 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/component/ComponentMetamodel.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/component/ComponentMetamodel.java @@ -31,7 +31,7 @@ import java.util.Map; import org.hibernate.EntityMode; import org.hibernate.HibernateException; import org.hibernate.metamodel.spi.binding.AttributeBinding; -import org.hibernate.metamodel.spi.binding.CompositeAttributeBindingContainer; +import org.hibernate.metamodel.spi.binding.EmbeddableBinding; import org.hibernate.service.ServiceRegistry; import org.hibernate.tuple.PropertyFactory; import org.hibernate.tuple.StandardProperty; @@ -55,11 +55,11 @@ public class ComponentMetamodel implements Serializable { public ComponentMetamodel( ServiceRegistry serviceRegistry, - CompositeAttributeBindingContainer component, + EmbeddableBinding component, boolean isIdentifierAttributeBinding, boolean isIdentifierMapper) { this.isKey = isIdentifierAttributeBinding; - this.role = component.getPathBase(); + this.role = component.getPathBase().getFullPath(); propertySpan = component.attributeBindingSpan(); properties = new StandardProperty[propertySpan]; int i = 0; diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/component/ComponentTuplizer.java b/hibernate-core/src/main/java/org/hibernate/tuple/component/ComponentTuplizer.java index c1c388b819..8262a7ef34 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/component/ComponentTuplizer.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/component/ComponentTuplizer.java @@ -35,7 +35,7 @@ import org.hibernate.tuple.Tuplizer; *

* ComponentTuplizer implementations should have the following constructor with the following arguments:
    *
  1. {@link org.hibernate.service.ServiceRegistry}
  2. - *
  3. {@link org.hibernate.metamodel.spi.binding.CompositeAttributeBinding}
  4. + *
  5. {@link org.hibernate.metamodel.spi.binding.EmbeddedAttributeBinding}
  6. *
  7. boolean (whether the composite is a mapped identifier)
  8. *
* diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/component/ComponentTuplizerFactory.java b/hibernate-core/src/main/java/org/hibernate/tuple/component/ComponentTuplizerFactory.java index 94703a632f..2947f4d9d5 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/component/ComponentTuplizerFactory.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/component/ComponentTuplizerFactory.java @@ -29,7 +29,7 @@ import java.lang.reflect.Constructor; import org.hibernate.EntityMode; import org.hibernate.HibernateException; import org.hibernate.internal.util.ReflectHelper; -import org.hibernate.metamodel.spi.binding.CompositeAttributeBindingContainer; +import org.hibernate.metamodel.spi.binding.EmbeddableBinding; import org.hibernate.service.ServiceRegistry; /** @@ -40,7 +40,7 @@ import org.hibernate.service.ServiceRegistry; public class ComponentTuplizerFactory implements Serializable { private static final Class[] COMPONENT_TUP_CTOR_SIG_NEW = new Class[] { ServiceRegistry.class, - CompositeAttributeBindingContainer.class, + EmbeddableBinding.class, boolean.class }; @@ -59,7 +59,7 @@ public class ComponentTuplizerFactory implements Serializable { public ComponentTuplizer constructTuplizer( ServiceRegistry serviceRegistry, String tuplizerClassName, - CompositeAttributeBindingContainer metadata, + EmbeddableBinding metadata, boolean isIdentifierMapper) { try { final Class tuplizerClass = ReflectHelper.classForName( tuplizerClassName ); @@ -93,7 +93,7 @@ public class ComponentTuplizerFactory implements Serializable { public ComponentTuplizer constructTuplizer( Class tuplizerClass, ServiceRegistry serviceRegistry, - CompositeAttributeBindingContainer metadata, + EmbeddableBinding metadata, boolean isIdentifierMapper) { final Constructor constructor = getProperConstructor( tuplizerClass, @@ -123,7 +123,7 @@ public class ComponentTuplizerFactory implements Serializable { public ComponentTuplizer constructDefaultTuplizer( EntityMode entityMode, ServiceRegistry serviceRegistry, - CompositeAttributeBindingContainer metadata, + EmbeddableBinding metadata, boolean isIdentifierMapper) { final Class tuplizerClass = determineTuplizerClass( entityMode ); return constructTuplizer( tuplizerClass, serviceRegistry, metadata, isIdentifierMapper ); diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/component/DynamicMapComponentTuplizer.java b/hibernate-core/src/main/java/org/hibernate/tuple/component/DynamicMapComponentTuplizer.java index 579390098b..595a72fdef 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/component/DynamicMapComponentTuplizer.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/component/DynamicMapComponentTuplizer.java @@ -25,10 +25,8 @@ package org.hibernate.tuple.component; import java.util.Map; -import org.hibernate.mapping.Component; -import org.hibernate.mapping.Property; import org.hibernate.metamodel.spi.binding.AttributeBinding; -import org.hibernate.metamodel.spi.binding.CompositeAttributeBindingContainer; +import org.hibernate.metamodel.spi.binding.EmbeddableBinding; import org.hibernate.property.Getter; import org.hibernate.property.PropertyAccessor; import org.hibernate.property.PropertyAccessorFactory; @@ -46,7 +44,7 @@ import org.hibernate.tuple.Instantiator; public class DynamicMapComponentTuplizer extends AbstractComponentTuplizer { public DynamicMapComponentTuplizer( ServiceRegistry serviceRegistry, - CompositeAttributeBindingContainer component, + EmbeddableBinding component, boolean isIdentifierMapper) { super( serviceRegistry, component, isIdentifierMapper ); } @@ -62,14 +60,14 @@ public class DynamicMapComponentTuplizer extends AbstractComponentTuplizer { @Override protected Instantiator buildInstantiator( - CompositeAttributeBindingContainer compositeAttributeBindingContainer, + EmbeddableBinding embeddableBinding, boolean isIdentifierMapper) { return new DynamicMapInstantiator(); } @Override protected Getter buildGetter( - CompositeAttributeBindingContainer compositeAttributeBindingContainer, + EmbeddableBinding embeddableBinding, boolean isIdentifierMapper, AttributeBinding attributeBinding) { return buildPropertyAccessor().getGetter( null, attributeBinding.getAttribute().getName() ); @@ -77,7 +75,7 @@ public class DynamicMapComponentTuplizer extends AbstractComponentTuplizer { @Override protected Setter buildSetter( - CompositeAttributeBindingContainer compositeAttributeBindingContainer, + EmbeddableBinding embeddableBinding, boolean isIdentifierMapper, AttributeBinding attributeBinding) { return buildPropertyAccessor().getSetter( null, attributeBinding.getAttribute().getName() ); diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/component/PojoComponentTuplizer.java b/hibernate-core/src/main/java/org/hibernate/tuple/component/PojoComponentTuplizer.java index cb5146fb14..d7d4c573b4 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/component/PojoComponentTuplizer.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/component/PojoComponentTuplizer.java @@ -38,7 +38,7 @@ import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.internal.util.ReflectHelper; import org.hibernate.mapping.Component; import org.hibernate.metamodel.spi.binding.AttributeBinding; -import org.hibernate.metamodel.spi.binding.CompositeAttributeBindingContainer; +import org.hibernate.metamodel.spi.binding.EmbeddableBinding; import org.hibernate.metamodel.spi.binding.EntityIdentifier; import org.hibernate.property.BackrefPropertyAccessor; import org.hibernate.property.Getter; @@ -63,7 +63,7 @@ public class PojoComponentTuplizer extends AbstractComponentTuplizer { public PojoComponentTuplizer( ServiceRegistry serviceRegistry, - CompositeAttributeBindingContainer component, + EmbeddableBinding component, boolean isIdentifierMapper) { super( serviceRegistry, component, isIdentifierMapper ); @@ -162,20 +162,20 @@ public class PojoComponentTuplizer extends AbstractComponentTuplizer { @Override protected Instantiator buildInstantiator( - CompositeAttributeBindingContainer compositeAttributeBindingContainer, + EmbeddableBinding embeddableBinding, boolean isIdentifierMapper) { final Class clazz = classForName( - compositeAttributeBindingContainer.getAttributeContainer().getDescriptor().getName().toString() + embeddableBinding.getAttributeContainer().getDescriptor().getName().toString() ); - if ( !compositeAttributeBindingContainer.isAggregated() && ReflectHelper.isAbstractClass( clazz ) ) { + if ( !embeddableBinding.isAggregated() && ReflectHelper.isAbstractClass( clazz ) ) { return new ProxiedInstantiator( clazz ); } if ( optimizer == null ) { return new PojoInstantiator( serviceRegistry(), - compositeAttributeBindingContainer, + embeddableBinding, isIdentifierMapper, null ); @@ -183,7 +183,7 @@ public class PojoComponentTuplizer extends AbstractComponentTuplizer { else { return new PojoInstantiator( serviceRegistry(), - compositeAttributeBindingContainer, + embeddableBinding, isIdentifierMapper, optimizer.getInstantiationOptimizer() ); @@ -192,7 +192,7 @@ public class PojoComponentTuplizer extends AbstractComponentTuplizer { @Override protected Getter buildGetter( - CompositeAttributeBindingContainer compositeAttributeBindingContainer, + EmbeddableBinding embeddableBinding, boolean isIdentifierMapper, AttributeBinding attributeBinding) { // TODO: when compositeAttributeBinding is wrapped for an identifier mapper @@ -202,7 +202,7 @@ public class PojoComponentTuplizer extends AbstractComponentTuplizer { // HACK ALERT: when isIdentifierMapper is true, the entity identifier // must be completely bound when this method is called. final EntityIdentifier entityIdentifier = - compositeAttributeBindingContainer.seekEntityBinding().getHierarchyDetails().getEntityIdentifier(); + embeddableBinding.seekEntityBinding().getHierarchyDetails().getEntityIdentifier(); return getGetter( entityIdentifier.getLookupClassBinding().getIdClassType(), attributeBinding.getAttribute().getName(), @@ -212,7 +212,7 @@ public class PojoComponentTuplizer extends AbstractComponentTuplizer { else { final ClassLoaderService cls = serviceRegistry().getService( ClassLoaderService.class ); final Class clazz = cls.classForName( - compositeAttributeBindingContainer.getAttributeContainer().getDescriptor().getName().toString() + embeddableBinding.getAttributeContainer().getDescriptor().getName().toString() ); return getGetter( clazz, @@ -224,14 +224,14 @@ public class PojoComponentTuplizer extends AbstractComponentTuplizer { @Override protected Setter buildSetter( - CompositeAttributeBindingContainer compositeAttributeBindingContainer, + EmbeddableBinding embeddableBinding, boolean isIdentifierMapper, AttributeBinding attributeBinding) { if ( isIdentifierMapper ) { // HACK ALERT: when isIdentifierMapper is true, the entity identifier // must be completely bound when this method is called. final EntityIdentifier entityIdentifier = - compositeAttributeBindingContainer.seekEntityBinding().getHierarchyDetails().getEntityIdentifier(); + embeddableBinding.seekEntityBinding().getHierarchyDetails().getEntityIdentifier(); return getSetter( entityIdentifier.getLookupClassBinding().getIdClassType(), attributeBinding.getAttribute().getName(), @@ -241,7 +241,7 @@ public class PojoComponentTuplizer extends AbstractComponentTuplizer { } else { final Class clazz = classForName( - compositeAttributeBindingContainer.getAttributeContainer().getDescriptor().getName().toString() + embeddableBinding.getAttributeContainer().getDescriptor().getName().toString() ); return getSetter( clazz, diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java b/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java index c864e37407..2f85ae0cc0 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java @@ -50,6 +50,7 @@ import org.hibernate.internal.util.ReflectHelper; import org.hibernate.internal.util.collections.ArrayHelper; import org.hibernate.mapping.Component; import org.hibernate.mapping.Property; +import org.hibernate.metamodel.spi.NaturalIdMutability; import org.hibernate.metamodel.spi.binding.AttributeBinding; import org.hibernate.metamodel.spi.binding.BasicAttributeBinding; import org.hibernate.metamodel.spi.binding.EntityBinding; @@ -622,11 +623,11 @@ public class EntityMetamodel implements Serializable { SingularAttributeBinding singularAttributeBinding = SingularAttributeBinding.class.cast( attributeBinding ); - if ( singularAttributeBinding.getNaturalIdMutability() == SingularAttributeBinding.NaturalIdMutability.MUTABLE ) { + if ( singularAttributeBinding.getNaturalIdMutability() == NaturalIdMutability.MUTABLE ) { naturalIdNumbers.add( i ); foundUpdateableNaturalIdProperty = true; } - else if ( singularAttributeBinding.getNaturalIdMutability() == SingularAttributeBinding.NaturalIdMutability.IMMUTABLE ) { + else if ( singularAttributeBinding.getNaturalIdMutability() == NaturalIdMutability.IMMUTABLE ) { naturalIdNumbers.add( i ); } } diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/AssertSourcesTest.java b/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/AssertSourcesTest.java index fdf189785d..25cda5289c 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/AssertSourcesTest.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/AssertSourcesTest.java @@ -46,6 +46,7 @@ import org.hibernate.metamodel.source.spi.TableSource; import org.hibernate.metamodel.source.spi.TableSpecificationSource; import org.hibernate.metamodel.spi.BindingContext; import org.hibernate.metamodel.spi.MetadataSourceProcessor; +import org.hibernate.metamodel.spi.SingularAttributeNature; import org.hibernate.metamodel.spi.binding.IdentifierGeneratorDefinition; import org.hibernate.metamodel.spi.binding.InheritanceType; @@ -150,7 +151,7 @@ public class AssertSourcesTest extends BaseUnitTestCase { assertTrue( identifierAttributeSource.isSingular() ); assertFalse( identifierAttributeSource.isVirtualAttribute() ); assertFalse( identifierAttributeSource.isLazy() ); - assertEquals( SingularAttributeSource.Nature.BASIC, identifierAttributeSource.getNature() ); + assertEquals( SingularAttributeNature.BASIC, identifierAttributeSource.getSingularAttributeNature() ); assertEquals( PropertyGeneration.INSERT, identifierAttributeSource.getGeneration() ); // assertNull( identifierAttributeSource.getPropertyAccessorName() ); diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/entity/EmbeddableBindingTest.java b/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/entity/EmbeddableBindingTest.java index 6f41ccba8f..4dce03db2c 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/entity/EmbeddableBindingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/entity/EmbeddableBindingTest.java @@ -34,7 +34,7 @@ import javax.persistence.Id; import org.hibernate.annotations.Parent; import org.hibernate.annotations.Target; import org.hibernate.metamodel.spi.binding.BasicAttributeBinding; -import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding; +import org.hibernate.metamodel.spi.binding.EmbeddedAttributeBinding; import org.hibernate.metamodel.spi.binding.EntityBinding; import org.hibernate.testing.junit4.BaseAnnotationBindingTestCase; @@ -74,20 +74,32 @@ public class EmbeddableBindingTest extends BaseAnnotationBindingTestCase { final String componentName = "phone"; assertNotNull( binding.locateAttributeBinding( componentName ) ); - assertTrue( binding.locateAttributeBinding( componentName ) instanceof CompositeAttributeBinding ); - CompositeAttributeBinding compositeBinding = (CompositeAttributeBinding) binding.locateAttributeBinding( + assertTrue( binding.locateAttributeBinding( componentName ) instanceof EmbeddedAttributeBinding ); + EmbeddedAttributeBinding compositeBinding = (EmbeddedAttributeBinding) binding.locateAttributeBinding( componentName ); + assertNotNull( compositeBinding.getHibernateTypeDescriptor() ); + + assertNotNull( compositeBinding.getRelationalValueBindings() ); + assertEquals( 3, compositeBinding.getRelationalValueBindings().size() ); + assertEquals( "Wrong path", "phone", - compositeBinding.getPathBase() + compositeBinding.getEmbeddableBinding().getPathBase().getFullPath() ); - assertNotNull( compositeBinding.locateAttributeBinding( "countryCode" ) ); - assertNotNull( compositeBinding.locateAttributeBinding( "areaCode" ) ); - assertNotNull( compositeBinding.locateAttributeBinding( "number" ) ); + assertEquals( + "Wrong path", + "org.hibernate.metamodel.internal.source.annotations.entity.EmbeddableBindingTest$User#phone", + compositeBinding.getAttributeRole().getFullPath() + ); + + assertNotNull( compositeBinding.getEmbeddableBinding().locateAttributeBinding( "countryCode" ) ); + assertNotNull( compositeBinding.getEmbeddableBinding().locateAttributeBinding( "areaCode" ) ); + assertNotNull( compositeBinding.getEmbeddableBinding().locateAttributeBinding( "number" ) ); + } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -114,13 +126,15 @@ public class EmbeddableBindingTest extends BaseAnnotationBindingTestCase { final String componentName = "embedded"; assertNotNull( binding.locateAttributeBinding( componentName ) ); - assertTrue( binding.locateAttributeBinding( componentName ) instanceof CompositeAttributeBinding ); - CompositeAttributeBinding compositeBinding = (CompositeAttributeBinding) binding.locateAttributeBinding( + assertTrue( binding.locateAttributeBinding( componentName ) instanceof EmbeddedAttributeBinding ); + EmbeddedAttributeBinding compositeBinding = (EmbeddedAttributeBinding) binding.locateAttributeBinding( componentName ); - assertNotNull( compositeBinding.locateAttributeBinding( "name" ) ); - BasicAttributeBinding nameAttribute = (BasicAttributeBinding) compositeBinding.locateAttributeBinding( "name" ); + assertNotNull( compositeBinding.getEmbeddableBinding().locateAttributeBinding( "name" ) ); + BasicAttributeBinding nameAttribute = (BasicAttributeBinding) compositeBinding.getEmbeddableBinding().locateAttributeBinding( + "name" + ); assertEquals( 1, nameAttribute.getRelationalValueBindings().size() ); org.hibernate.metamodel.spi.relational.Column column = (org.hibernate.metamodel.spi.relational.Column) nameAttribute.getRelationalValueBindings().get( 0 ).getValue(); @@ -169,16 +183,16 @@ public class EmbeddableBindingTest extends BaseAnnotationBindingTestCase { final String addressComponentName = "address"; assertNotNull( binding.locateAttributeBinding( addressComponentName ) ); - assertTrue( binding.locateAttributeBinding( addressComponentName ) instanceof CompositeAttributeBinding ); - CompositeAttributeBinding attributeCompositeBinding = (CompositeAttributeBinding) binding.locateAttributeBinding( + assertTrue( binding.locateAttributeBinding( addressComponentName ) instanceof EmbeddedAttributeBinding ); + EmbeddedAttributeBinding attributeCompositeBinding = (EmbeddedAttributeBinding) binding.locateAttributeBinding( addressComponentName ); - assertNotNull( attributeCompositeBinding.locateAttributeBinding( "street" ) ); - assertNotNull( attributeCompositeBinding.locateAttributeBinding( "city" ) ); - assertNotNull( attributeCompositeBinding.locateAttributeBinding( "state" ) ); + assertNotNull( attributeCompositeBinding.getEmbeddableBinding().locateAttributeBinding( "street" ) ); + assertNotNull( attributeCompositeBinding.getEmbeddableBinding().locateAttributeBinding( "city" ) ); + assertNotNull( attributeCompositeBinding.getEmbeddableBinding().locateAttributeBinding( "state" ) ); - BasicAttributeBinding stateAttribute = (BasicAttributeBinding) attributeCompositeBinding.locateAttributeBinding( + BasicAttributeBinding stateAttribute = (BasicAttributeBinding) attributeCompositeBinding.getEmbeddableBinding().locateAttributeBinding( "state" ); assertEquals( 1, stateAttribute.getRelationalValueBindings().size() ); @@ -192,13 +206,15 @@ public class EmbeddableBindingTest extends BaseAnnotationBindingTestCase { final String zipComponentName = "zipcode"; - assertNotNull( attributeCompositeBinding.locateAttributeBinding( zipComponentName ) ); - assertTrue( attributeCompositeBinding.locateAttributeBinding( zipComponentName ) instanceof CompositeAttributeBinding ); - CompositeAttributeBinding zipCompositeBinding = (CompositeAttributeBinding) attributeCompositeBinding.locateAttributeBinding( + assertNotNull( attributeCompositeBinding.getEmbeddableBinding().locateAttributeBinding( zipComponentName ) ); + assertTrue( attributeCompositeBinding.getEmbeddableBinding().locateAttributeBinding( zipComponentName ) instanceof EmbeddedAttributeBinding ); + EmbeddedAttributeBinding zipCompositeBinding = (EmbeddedAttributeBinding) attributeCompositeBinding.getEmbeddableBinding().locateAttributeBinding( zipComponentName ); - BasicAttributeBinding nameAttribute = (BasicAttributeBinding) zipCompositeBinding.locateAttributeBinding( "zip" ); + BasicAttributeBinding nameAttribute = (BasicAttributeBinding) zipCompositeBinding.getEmbeddableBinding().locateAttributeBinding( + "zip" + ); assertEquals( 1, nameAttribute.getRelationalValueBindings().size() ); column = (org.hibernate.metamodel.spi.relational.Column) nameAttribute.getRelationalValueBindings().get( 0 ).getValue(); assertEquals( @@ -263,19 +279,21 @@ public class EmbeddableBindingTest extends BaseAnnotationBindingTestCase { final String aComponentName = "a"; assertNotNull( binding.locateAttributeBinding( aComponentName ) ); - assertTrue( binding.locateAttributeBinding( aComponentName ) instanceof CompositeAttributeBinding ); - CompositeAttributeBinding aCompositeBinding = (CompositeAttributeBinding) binding.locateAttributeBinding( + assertTrue( binding.locateAttributeBinding( aComponentName ) instanceof EmbeddedAttributeBinding ); + EmbeddedAttributeBinding aCompositeBinding = (EmbeddedAttributeBinding) binding.locateAttributeBinding( aComponentName ); final String bComponentName = "b"; - assertNotNull( aCompositeBinding.locateAttributeBinding( bComponentName ) ); - assertTrue( aCompositeBinding.locateAttributeBinding( bComponentName ) instanceof CompositeAttributeBinding ); - CompositeAttributeBinding bCompositeBinding = (CompositeAttributeBinding) aCompositeBinding.locateAttributeBinding( + assertNotNull( aCompositeBinding.getEmbeddableBinding().locateAttributeBinding( bComponentName ) ); + assertTrue( aCompositeBinding.getEmbeddableBinding().locateAttributeBinding( bComponentName ) instanceof EmbeddedAttributeBinding ); + EmbeddedAttributeBinding bCompositeBinding = (EmbeddedAttributeBinding) aCompositeBinding.getEmbeddableBinding().locateAttributeBinding( bComponentName ); - BasicAttributeBinding attribute = (BasicAttributeBinding) bCompositeBinding.locateAttributeBinding( "foo" ); + BasicAttributeBinding attribute = (BasicAttributeBinding) bCompositeBinding.getEmbeddableBinding().locateAttributeBinding( + "foo" + ); assertEquals( 1, attribute.getRelationalValueBindings().size() ); org.hibernate.metamodel.spi.relational.Column column = (org.hibernate.metamodel.spi.relational.Column) attribute.getRelationalValueBindings().get( 0 ).getValue(); @@ -285,7 +303,7 @@ public class EmbeddableBindingTest extends BaseAnnotationBindingTestCase { column.getColumnName().getText() ); - attribute = (BasicAttributeBinding) bCompositeBinding.locateAttributeBinding( "fubar" ); + attribute = (BasicAttributeBinding) bCompositeBinding.getEmbeddableBinding().locateAttributeBinding( "fubar" ); assertEquals( 1, attribute.getRelationalValueBindings().size() ); column = (org.hibernate.metamodel.spi.relational.Column) attribute.getRelationalValueBindings().get( 0 ).getValue(); assertEquals( @@ -329,13 +347,13 @@ public class EmbeddableBindingTest extends BaseAnnotationBindingTestCase { final String componentName = "embedded"; assertNotNull( binding.locateAttributeBinding( componentName ) ); - assertTrue( binding.locateAttributeBinding( componentName ) instanceof CompositeAttributeBinding ); - CompositeAttributeBinding compositeBinding = (CompositeAttributeBinding) binding.locateAttributeBinding( + assertTrue( binding.locateAttributeBinding( componentName ) instanceof EmbeddedAttributeBinding ); + EmbeddedAttributeBinding compositeBinding = (EmbeddedAttributeBinding) binding.locateAttributeBinding( componentName ); - assertNotNull( "No parent reference binding", compositeBinding.getParentReference() ); - assertEquals( "Wrong parent reference name", "parent", compositeBinding.getParentReference().getName() ); + assertNotNull( "No parent reference binding", compositeBinding.getEmbeddableBinding().getParentReference() ); + assertEquals( "Wrong parent reference name", "parent", compositeBinding.getEmbeddableBinding().getParentReference().getName() ); } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -384,12 +402,12 @@ public class EmbeddableBindingTest extends BaseAnnotationBindingTestCase { final String componentName = "car"; assertNotNull( binding.locateAttributeBinding( componentName ) ); - assertTrue( binding.locateAttributeBinding( componentName ) instanceof CompositeAttributeBinding ); - CompositeAttributeBinding compositeBinding = (CompositeAttributeBinding) binding.locateAttributeBinding( + assertTrue( binding.locateAttributeBinding( componentName ) instanceof EmbeddedAttributeBinding ); + EmbeddedAttributeBinding compositeBinding = (EmbeddedAttributeBinding) binding.locateAttributeBinding( componentName ); - BasicAttributeBinding attribute = (BasicAttributeBinding) compositeBinding.locateAttributeBinding( + BasicAttributeBinding attribute = (BasicAttributeBinding) compositeBinding.getEmbeddableBinding().locateAttributeBinding( "horsePower" ); assertTrue( attribute.getAttribute().isTypeResolved() ); diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/entity/NaturalIdBindingTests.java b/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/entity/NaturalIdBindingTests.java index 421fda3f7f..960a3a8931 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/entity/NaturalIdBindingTests.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/entity/NaturalIdBindingTests.java @@ -10,6 +10,7 @@ import javax.persistence.ManyToOne; import org.hibernate.TruthValue; import org.hibernate.annotations.NaturalId; import org.hibernate.annotations.NaturalIdCache; +import org.hibernate.metamodel.spi.NaturalIdMutability; import org.hibernate.metamodel.spi.binding.EntityBinding; import org.hibernate.metamodel.spi.binding.RelationalValueBinding; import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; @@ -50,7 +51,7 @@ public class NaturalIdBindingTests extends BaseAnnotationBindingTestCase { "name" ); assertEquals( - SingularAttributeBinding.NaturalIdMutability.IMMUTABLE, + NaturalIdMutability.IMMUTABLE, attributeBinding.getNaturalIdMutability() ); @@ -73,7 +74,7 @@ public class NaturalIdBindingTests extends BaseAnnotationBindingTestCase { "age" ); assertEquals( - SingularAttributeBinding.NaturalIdMutability.MUTABLE, + NaturalIdMutability.MUTABLE, attributeBinding.getNaturalIdMutability() ); @@ -122,7 +123,7 @@ public class NaturalIdBindingTests extends BaseAnnotationBindingTestCase { "component" ); assertEquals( - SingularAttributeBinding.NaturalIdMutability.IMMUTABLE, + NaturalIdMutability.IMMUTABLE, attributeBinding.getNaturalIdMutability() ); @@ -172,7 +173,7 @@ public class NaturalIdBindingTests extends BaseAnnotationBindingTestCase { assertNull( entityBinding.getHierarchyDetails().getNaturalIdCaching().getRegion() ); SingularAttributeBinding attributeBinding = (SingularAttributeBinding)entityBinding.locateAttributeBinding( "simpleEntity" ); - assertEquals( SingularAttributeBinding.NaturalIdMutability.IMMUTABLE, attributeBinding.getNaturalIdMutability() ); + assertEquals( NaturalIdMutability.IMMUTABLE, attributeBinding.getNaturalIdMutability() ); List relationalValueBindings = attributeBinding.getRelationalValueBindings(); assertEquals( 1, relationalValueBindings.size() ); diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/AbstractBasicBindingTests.java b/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/AbstractBasicBindingTests.java index cea3856e59..7f19074fe5 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/AbstractBasicBindingTests.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/AbstractBasicBindingTests.java @@ -245,13 +245,14 @@ public abstract class AbstractBasicBindingTests extends BaseUnitTestCase { assertRoot( metadata, entityBinding ); assertIdAndSimpleProperty( entityBinding ); - CompositeAttributeBinding compositeAttributeBinding = - (CompositeAttributeBinding) entityBinding.locateAttributeBinding( "simpleComponent" ); - assertNotNull( compositeAttributeBinding ); - assertSame( compositeAttributeBinding.getAttribute().getSingularAttributeType(), compositeAttributeBinding.getAttributeContainer() ); - assertEquals( "simpleComponent", compositeAttributeBinding.getPathBase() ); - assertSame( entityBinding, compositeAttributeBinding.seekEntityBinding() ); - assertTrue( compositeAttributeBinding.getAttribute().getSingularAttributeType() instanceof Aggregate ); + EmbeddedAttributeBinding embeddedAttributeBinding = + (EmbeddedAttributeBinding) entityBinding.locateAttributeBinding( "simpleComponent" ); + assertNotNull( embeddedAttributeBinding ); + assertSame( embeddedAttributeBinding.getAttribute().getSingularAttributeType(), embeddedAttributeBinding.getEmbeddableBinding().getAttributeContainer() ); + assertEquals( "simpleComponent", embeddedAttributeBinding.getAttributePath().getFullPath() ); + assertEquals( "simpleComponent", embeddedAttributeBinding.getEmbeddableBinding().getPathBase().getFullPath() ); + assertSame( entityBinding, embeddedAttributeBinding.getEmbeddableBinding().seekEntityBinding() ); + assertTrue( embeddedAttributeBinding.getAttribute().getSingularAttributeType() instanceof Aggregate ); } public abstract void addSourcesForSimpleVersionedEntityBinding(MetadataSources sources); diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/SimpleValueBindingTests.java b/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/SimpleValueBindingTests.java index 3be5a27c6a..7f94de27fe 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/SimpleValueBindingTests.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/SimpleValueBindingTests.java @@ -36,6 +36,7 @@ import org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptorRepository; import org.hibernate.metamodel.source.internal.annotations.JandexAccessImpl; +import org.hibernate.metamodel.spi.NaturalIdMutability; import org.hibernate.metamodel.spi.domain.Entity; import org.hibernate.metamodel.spi.domain.SingularAttribute; import org.hibernate.metamodel.spi.relational.Column; @@ -94,8 +95,10 @@ public class SimpleValueBindingTests extends BaseUnitTestCase { "property", true, false, - SingularAttributeBinding.NaturalIdMutability.NOT_NATURAL_ID, + NaturalIdMutability.NOT_NATURAL_ID, null, + entityBinding.getRoleBase().append( "id" ), + entityBinding.getPathBase().append( "id" ), PropertyGeneration.NEVER ); attributeBinding.getHibernateTypeDescriptor().setExplicitTypeName( "long" ); diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/basiccollections/AbstractBasicCollectionBindingTests.java b/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/basiccollections/AbstractBasicCollectionBindingTests.java index 6aa8b4e456..f19d926c1a 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/basiccollections/AbstractBasicCollectionBindingTests.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/basiccollections/AbstractBasicCollectionBindingTests.java @@ -32,15 +32,15 @@ import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl; import org.hibernate.engine.FetchTiming; import org.hibernate.metamodel.MetadataSources; import org.hibernate.metamodel.internal.MetadataImpl; +import org.hibernate.metamodel.spi.PluralAttributeElementNature; +import org.hibernate.metamodel.spi.PluralAttributeNature; import org.hibernate.metamodel.spi.binding.EntityBinding; import org.hibernate.metamodel.spi.binding.EntityIdentifier; import org.hibernate.metamodel.spi.binding.HibernateTypeDescriptor; import org.hibernate.metamodel.spi.binding.PluralAttributeBinding; -import org.hibernate.metamodel.spi.binding.PluralAttributeElementBinding; import org.hibernate.metamodel.spi.binding.PluralAttributeKeyBinding; import org.hibernate.metamodel.spi.binding.RelationalValueBinding; import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; -import org.hibernate.metamodel.spi.domain.PluralAttribute; import org.hibernate.metamodel.spi.relational.Column; import org.hibernate.metamodel.spi.relational.Identifier; import org.hibernate.metamodel.spi.relational.TableSpecification; @@ -95,7 +95,7 @@ public abstract class AbstractBasicCollectionBindingTests extends BaseUnitTestCa assertBasicCollectionBinding( entityBinding, - metadata.getCollection( EntityWithBasicCollections.class.getName() + ".theBag" ), + metadata.getCollection( EntityWithBasicCollections.class.getName() + "#theBag" ), BagType.class, Collection.class, String.class, @@ -108,7 +108,7 @@ public abstract class AbstractBasicCollectionBindingTests extends BaseUnitTestCa assertBasicCollectionBinding( entityBinding, - metadata.getCollection( EntityWithBasicCollections.class.getName() + ".theSet" ), + metadata.getCollection( EntityWithBasicCollections.class.getName() + "#theSet" ), SetType.class, Set.class, String.class, @@ -121,7 +121,7 @@ public abstract class AbstractBasicCollectionBindingTests extends BaseUnitTestCa assertBasicCollectionBinding( entityBinding, - metadata.getCollection( EntityWithBasicCollections.class.getName() + ".thePropertyRefSet" ), + metadata.getCollection( EntityWithBasicCollections.class.getName() + "#thePropertyRefSet" ), SetType.class, Set.class, Integer.class, @@ -197,7 +197,7 @@ public abstract class AbstractBasicCollectionBindingTests extends BaseUnitTestCa ); assertFalse( keyBinding.isInverse() ); Assert.assertEquals( - PluralAttributeElementBinding.Nature.BASIC, + PluralAttributeElementNature.BASIC, collectionBinding.getPluralAttributeElementBinding().getNature() ); assertEquals( @@ -209,13 +209,18 @@ public abstract class AbstractBasicCollectionBindingTests extends BaseUnitTestCa collectionBinding.getPluralAttributeElementBinding().getHibernateTypeDescriptor().getResolvedTypeMapping().getReturnedClass() ); - assertEquals( 1, collectionBinding.getPluralAttributeElementBinding().getRelationalValueBindings().size() ); - RelationalValueBinding elementRelationalValueBinding = collectionBinding.getPluralAttributeElementBinding().getRelationalValueBindings().get( 0 ); + assertEquals( 1, + collectionBinding.getPluralAttributeElementBinding() + .getRelationalValueContainer() + .relationalValueBindings() + .size() + ); + RelationalValueBinding elementRelationalValueBinding = collectionBinding.getPluralAttributeElementBinding().getRelationalValueContainer().relationalValueBindings().get( 0 ); assertEquals( expectedElementNullable, elementRelationalValueBinding.isNullable() ); - if ( collectionBinding.getAttribute().getNature() == PluralAttribute.Nature.BAG ) { + if ( collectionBinding.getAttribute().getPluralAttributeNature() == PluralAttributeNature.BAG ) { assertEquals( 0, collectionTable.getPrimaryKey().getColumnSpan() ); } - else if ( collectionBinding.getAttribute().getNature() == PluralAttribute.Nature.SET ) { + else if ( collectionBinding.getAttribute().getPluralAttributeNature() == PluralAttributeNature.SET ) { if ( expectedElementNullable ) { assertEquals( 0, collectionTable.getPrimaryKey().getColumnSpan() ); } diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/onetomany/AbstractUnidirectionalOneToManyBindingTests.java b/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/onetomany/AbstractUnidirectionalOneToManyBindingTests.java index f220e43158..2166b83d4d 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/onetomany/AbstractUnidirectionalOneToManyBindingTests.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/onetomany/AbstractUnidirectionalOneToManyBindingTests.java @@ -33,10 +33,10 @@ import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl; import org.hibernate.engine.FetchTiming; import org.hibernate.metamodel.MetadataSources; import org.hibernate.metamodel.internal.MetadataImpl; +import org.hibernate.metamodel.spi.PluralAttributeElementNature; import org.hibernate.metamodel.spi.binding.EntityBinding; import org.hibernate.metamodel.spi.binding.HibernateTypeDescriptor; import org.hibernate.metamodel.spi.binding.PluralAttributeBinding; -import org.hibernate.metamodel.spi.binding.PluralAttributeElementBinding; import org.hibernate.metamodel.spi.binding.PluralAttributeKeyBinding; import org.hibernate.metamodel.spi.binding.RelationalValueBinding; import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; @@ -100,7 +100,7 @@ public abstract class AbstractUnidirectionalOneToManyBindingTests extends BaseUn checkResult( entityBinding, - metadata.getCollection( EntityWithUnidirectionalOneToMany.class.getName() + ".theBag" ), + metadata.getCollection( EntityWithUnidirectionalOneToMany.class.getName() + "#theBag" ), BagType.class, Collection.class, simpleEntityBinding, @@ -112,7 +112,7 @@ public abstract class AbstractUnidirectionalOneToManyBindingTests extends BaseUn checkResult( entityBinding, - metadata.getCollection( EntityWithUnidirectionalOneToMany.class.getName() + ".theSet" ), + metadata.getCollection( EntityWithUnidirectionalOneToMany.class.getName() + "#theSet" ), SetType.class, Set.class, simpleEntityBinding, @@ -124,7 +124,7 @@ public abstract class AbstractUnidirectionalOneToManyBindingTests extends BaseUn checkResult( entityBinding, - metadata.getCollection( EntityWithUnidirectionalOneToMany.class.getName() + ".theList" ), + metadata.getCollection( EntityWithUnidirectionalOneToMany.class.getName() + "#theList" ), ListType.class, List.class, simpleEntityBinding, @@ -136,7 +136,7 @@ public abstract class AbstractUnidirectionalOneToManyBindingTests extends BaseUn checkResult( entityBinding, - metadata.getCollection( EntityWithUnidirectionalOneToMany.class.getName() + ".theMap" ), + metadata.getCollection( EntityWithUnidirectionalOneToMany.class.getName() + "#theMap" ), MapType.class, Map.class, simpleEntityBinding, @@ -148,7 +148,7 @@ public abstract class AbstractUnidirectionalOneToManyBindingTests extends BaseUn checkResult( entityBinding, - metadata.getCollection( EntityWithUnidirectionalOneToMany.class.getName() + ".thePropertyRefSet" ), + metadata.getCollection( EntityWithUnidirectionalOneToMany.class.getName() + "#thePropertyRefSet" ), BagType.class, Collection.class, simpleEntityBinding, @@ -170,7 +170,7 @@ public abstract class AbstractUnidirectionalOneToManyBindingTests extends BaseUn FetchTiming expectedFetchTiming, boolean expectedNullableCollectionKey) { Assert.assertEquals( - PluralAttributeElementBinding.Nature.ONE_TO_MANY, + PluralAttributeElementNature.ONE_TO_MANY, collectionBinding.getPluralAttributeElementBinding().getNature() ); assertSame( diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/embeddables/nested/NestedEmbeddableMetadataTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/embeddables/nested/NestedEmbeddableMetadataTest.java index ceb24d3351..15d9d27709 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/embeddables/nested/NestedEmbeddableMetadataTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/embeddables/nested/NestedEmbeddableMetadataTest.java @@ -27,10 +27,10 @@ import java.sql.Types; import org.hibernate.metamodel.Metadata; import org.hibernate.metamodel.MetadataSources; -import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding; -import org.hibernate.metamodel.spi.binding.CompositePluralAttributeElementBinding; +import org.hibernate.metamodel.spi.binding.EmbeddedAttributeBinding; import org.hibernate.metamodel.spi.binding.EntityBinding; import org.hibernate.metamodel.spi.binding.PluralAttributeBinding; +import org.hibernate.metamodel.spi.binding.PluralAttributeElementBindingEmbedded; import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; import org.hibernate.type.CustomType; @@ -52,9 +52,13 @@ public class NestedEmbeddableMetadataTest extends BaseUnitTestCase { Metadata metadata = new MetadataSources().addAnnotatedClass( Customer.class ).buildMetadata(); EntityBinding eb = metadata.getEntityBinding( Customer.class.getName() ); PluralAttributeBinding investmentsBinding = (PluralAttributeBinding) eb.locateAttributeBinding( "investments" ); - CompositePluralAttributeElementBinding investmentsElementBinding = (CompositePluralAttributeElementBinding) investmentsBinding.getPluralAttributeElementBinding(); - CompositeAttributeBinding amountBinding = (CompositeAttributeBinding) investmentsElementBinding.getCompositeAttributeBindingContainer().locateAttributeBinding( "amount" ); - SingularAttributeBinding currencyBinding = (SingularAttributeBinding) amountBinding.locateAttributeBinding( "currency" ); + PluralAttributeElementBindingEmbedded investmentsElementBinding = (PluralAttributeElementBindingEmbedded) investmentsBinding.getPluralAttributeElementBinding(); + EmbeddedAttributeBinding amountBinding = (EmbeddedAttributeBinding) investmentsElementBinding.getEmbeddableBinding().locateAttributeBinding( + "amount" + ); + SingularAttributeBinding currencyBinding = (SingularAttributeBinding) amountBinding.getEmbeddableBinding().locateAttributeBinding( + "currency" + ); CustomType currencyType = (CustomType) currencyBinding.getHibernateTypeDescriptor().getResolvedTypeMapping(); assertNotNull( currencyType ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/override/AttributeOverrideTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/override/AttributeOverrideTest.java index fd0db99c3e..1977c398fd 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/override/AttributeOverrideTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/override/AttributeOverrideTest.java @@ -23,18 +23,15 @@ */ package org.hibernate.test.annotations.override; -import org.junit.Test; - -import org.hibernate.test.util.SchemaUtil; -import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; +import org.hibernate.test.util.SchemaUtil; +import org.junit.Test; import static org.junit.Assert.assertTrue; /** * @author Emmanuel Bernard */ -@FailureExpectedWithNewMetamodel public class AttributeOverrideTest extends BaseCoreFunctionalTestCase { @Test public void testMapKeyValue() throws Exception { diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/tuplizer/DynamicComponentTuplizer.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/tuplizer/DynamicComponentTuplizer.java index b39770b1a4..d3204a0ed1 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/tuplizer/DynamicComponentTuplizer.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/tuplizer/DynamicComponentTuplizer.java @@ -1,6 +1,6 @@ package org.hibernate.test.annotations.tuplizer; -import org.hibernate.metamodel.spi.binding.CompositeAttributeBindingContainer; +import org.hibernate.metamodel.spi.binding.EmbeddableBinding; import org.hibernate.service.ServiceRegistry; import org.hibernate.tuple.Instantiator; import org.hibernate.tuple.component.PojoComponentTuplizer; @@ -12,17 +12,17 @@ public class DynamicComponentTuplizer extends PojoComponentTuplizer { public DynamicComponentTuplizer( ServiceRegistry serviceRegistry, - CompositeAttributeBindingContainer compositeAttributeBindingContainer, + EmbeddableBinding embeddableBinding, boolean isIdentifierMapper) { - super( serviceRegistry, compositeAttributeBindingContainer, isIdentifierMapper); + super( serviceRegistry, embeddableBinding, isIdentifierMapper); } @Override protected Instantiator buildInstantiator( - CompositeAttributeBindingContainer compositeAttributeBindingContainer, + EmbeddableBinding embeddableBinding, boolean isIdentifierMapper) { return new DynamicInstantiator( - compositeAttributeBindingContainer.getAttributeContainer().getDescriptor().getName().toString() + embeddableBinding.getAttributeContainer().getDescriptor().getName().toString() ); } } \ No newline at end of file diff --git a/hibernate-core/src/test/java/org/hibernate/test/legacy/NonReflectiveBinderTest.java b/hibernate-core/src/test/java/org/hibernate/test/legacy/NonReflectiveBinderTest.java index 50d37226d7..b9e1fd7cf0 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/legacy/NonReflectiveBinderTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/legacy/NonReflectiveBinderTest.java @@ -26,7 +26,7 @@ package org.hibernate.test.legacy; import org.hibernate.metamodel.MetadataSources; import org.hibernate.metamodel.spi.MetadataImplementor; import org.hibernate.metamodel.spi.binding.AttributeBinding; -import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding; +import org.hibernate.metamodel.spi.binding.EmbeddedAttributeBinding; import org.hibernate.metamodel.spi.binding.EntityBinding; import org.hibernate.metamodel.spi.binding.MetaAttribute; import org.hibernate.metamodel.spi.binding.PluralAttributeBinding; @@ -80,7 +80,7 @@ public class NonReflectiveBinderTest extends BaseUnitTestCase { assertNull( attributeBinding.getMetaAttributeContext().getMetaAttribute( "globalnoinherit" ) ); } - CompositeAttributeBinding componentAttributeBinding = (CompositeAttributeBinding) eb.locateAttributeBinding( "component" ); + EmbeddedAttributeBinding componentAttributeBinding = (EmbeddedAttributeBinding) eb.locateAttributeBinding( "component" ); assertNotNull( componentAttributeBinding.getMetaAttributeContext() ); assertNotNull( componentAttributeBinding.getMetaAttributeContext().getMetaAttribute( "global" ) ); assertNotNull( componentAttributeBinding.getMetaAttributeContext().getMetaAttribute( "componentonly" ) ); @@ -91,7 +91,7 @@ public class NonReflectiveBinderTest extends BaseUnitTestCase { assertNotNull( componentImplementsMeta ); assertEquals( componentImplementsMeta.getValue(), "AnotherInterface" ); - AttributeBinding xAttributeBinding = componentAttributeBinding.locateAttributeBinding( "x" ); + AttributeBinding xAttributeBinding = componentAttributeBinding.getEmbeddableBinding().locateAttributeBinding( "x" ); MetaAttribute xImplementsMeta = xAttributeBinding.getMetaAttributeContext().getMetaAttribute( "implements" ); assertNotNull( xImplementsMeta ); assertEquals( xImplementsMeta.getValue(), "AnotherInterface" ); @@ -107,12 +107,12 @@ public class NonReflectiveBinderTest extends BaseUnitTestCase { assertNotNull(metaAttribute); assertEquals( "wicked level", metaAttribute.getValue() ); - CompositeAttributeBinding componentAttributeBinding = (CompositeAttributeBinding) eb.locateAttributeBinding( "component" ); + EmbeddedAttributeBinding componentAttributeBinding = (EmbeddedAttributeBinding) eb.locateAttributeBinding( "component" ); MetaAttribute propertyAttribute = componentAttributeBinding.getMetaAttributeContext().getMetaAttribute( "globalmutated" ); assertNotNull( propertyAttribute ); assertEquals( "monetaryamount level", propertyAttribute.getValue() ); - AttributeBinding xAttributeBinding = componentAttributeBinding.locateAttributeBinding( "x" ); + AttributeBinding xAttributeBinding = componentAttributeBinding.getEmbeddableBinding().locateAttributeBinding( "x" ); propertyAttribute = xAttributeBinding.getMetaAttributeContext().getMetaAttribute( "globalmutated" ); assertNotNull( propertyAttribute ); assertEquals( "monetaryamount x level", propertyAttribute.getValue() ); diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/internal/metamodel/builder/AttributeBuilder.java b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/internal/metamodel/builder/AttributeBuilder.java index 22dea4dba3..ecaa86e8e1 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/internal/metamodel/builder/AttributeBuilder.java +++ b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/internal/metamodel/builder/AttributeBuilder.java @@ -30,8 +30,6 @@ import java.lang.reflect.ParameterizedType; import javax.persistence.OneToOne; import javax.persistence.metamodel.Attribute; import javax.persistence.metamodel.Attribute.PersistentAttributeType; -import javax.persistence.metamodel.EntityType; -import javax.persistence.metamodel.IdentifiableType; import javax.persistence.metamodel.PluralAttribute; import javax.persistence.metamodel.Type; @@ -42,18 +40,20 @@ import org.hibernate.jpa.internal.metamodel.AbstractManagedType; import org.hibernate.jpa.internal.metamodel.BasicTypeImpl; import org.hibernate.jpa.internal.metamodel.EmbeddableTypeImpl; import org.hibernate.jpa.internal.metamodel.MappedSuperclassTypeImpl; -import org.hibernate.jpa.internal.metamodel.SingularAttributeImpl; import org.hibernate.jpa.internal.metamodel.PluralAttributeImpl; +import org.hibernate.jpa.internal.metamodel.SingularAttributeImpl; +import org.hibernate.metamodel.spi.PluralAttributeElementNature; +import org.hibernate.metamodel.spi.PluralAttributeIndexNature; +import org.hibernate.metamodel.spi.PluralAttributeNature; import org.hibernate.metamodel.spi.binding.AttributeBinding; -import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding; -import org.hibernate.metamodel.spi.binding.CompositeAttributeBindingContainer; -import org.hibernate.metamodel.spi.binding.CompositePluralAttributeElementBinding; import org.hibernate.metamodel.spi.binding.CompositePluralAttributeIndexBinding; +import org.hibernate.metamodel.spi.binding.EmbeddableBinding; +import org.hibernate.metamodel.spi.binding.EmbeddedAttributeBinding; import org.hibernate.metamodel.spi.binding.IndexedPluralAttributeBinding; import org.hibernate.metamodel.spi.binding.MapBinding; import org.hibernate.metamodel.spi.binding.PluralAttributeBinding; import org.hibernate.metamodel.spi.binding.PluralAttributeElementBinding; -import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding; +import org.hibernate.metamodel.spi.binding.PluralAttributeElementBindingEmbedded; import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.tuple.entity.EntityMetamodel; @@ -250,18 +250,18 @@ public class AttributeBuilder { return getEntityAttributeMetaModelType( attributeTypeDescriptor ); } case EMBEDDABLE: { - if ( ! ( attributeBinding instanceof CompositeAttributeBinding ) ) { + if ( ! ( attributeBinding instanceof EmbeddedAttributeBinding ) ) { throw new IllegalArgumentException( String.format( "Unexpected type of attribute binding. Expected: %s; Actual: %s", - CompositeAttributeBinding.class.getName(), + EmbeddedAttributeBinding.class.getName(), attributeBinding.getClass().getName() ) ); } return getEmbeddableAttributeMetaModelType( attributeTypeDescriptor, - (CompositeAttributeBinding) attributeBinding + ( (EmbeddedAttributeBinding) attributeBinding ).getEmbeddableBinding() ); } default: { @@ -293,11 +293,11 @@ public class AttributeBuilder { } case EMBEDDABLE: { final PluralAttributeBinding pluralAttributeBinding = (PluralAttributeBinding) attributeBinding; - final CompositePluralAttributeElementBinding compositePluralAttributeElementBinding = - (CompositePluralAttributeElementBinding) pluralAttributeBinding.getPluralAttributeElementBinding(); + final PluralAttributeElementBindingEmbedded pluralAttributeElementBindingEmbedded = + (PluralAttributeElementBindingEmbedded) pluralAttributeBinding.getPluralAttributeElementBinding(); return getEmbeddableAttributeMetaModelType( attributeTypeDescriptor, - compositePluralAttributeElementBinding.getCompositeAttributeBindingContainer() + pluralAttributeElementBindingEmbedded.getEmbeddableBinding() ); } default: { @@ -369,9 +369,9 @@ public class AttributeBuilder { @SuppressWarnings( "unchecked" ) private Type getEmbeddableAttributeMetaModelType( AttributeTypeDescriptor attributeTypeDescriptor, - CompositeAttributeBindingContainer compositeAttributeBindingContainer) { + EmbeddableBinding embeddableBinding) { checkCorrectValueClassification( attributeTypeDescriptor, AttributeTypeDescriptor.ValueClassification.EMBEDDABLE ); - if ( ! compositeAttributeBindingContainer.isAggregated() ) { + if ( ! embeddableBinding.isAggregated() ) { throw new IllegalArgumentException( "Composite attribute binding is not aggregated." ); @@ -382,7 +382,7 @@ public class AttributeBuilder { (ComponentType) attributeTypeDescriptor.getHibernateType() ); context.registerEmbeddedableType( embeddableType ); - for ( AttributeBinding subAttributeBinding : compositeAttributeBindingContainer.attributeBindings() ) { + for ( AttributeBinding subAttributeBinding : embeddableBinding.attributeBindings() ) { final Attribute attribute = buildAttribute( embeddableType, subAttributeBinding ); if ( attribute != null ) { embeddableType.getBuilder().addAttribute( attribute ); @@ -470,7 +470,7 @@ public class AttributeBuilder { else { final PluralAttributeBinding pluralAttributeBinding = (PluralAttributeBinding) attributeBinding; - if ( pluralAttributeBinding.getAttribute().getNature() == org.hibernate.metamodel.spi.domain.PluralAttribute.Nature.ARRAY ) { + if ( pluralAttributeBinding.getAttribute().getPluralAttributeNature() == PluralAttributeNature.ARRAY ) { context.handleUnsupportedFeature( UnsupportedFeature.ARRAY ); return null; } @@ -478,46 +478,46 @@ public class AttributeBuilder { // First, determine the type of the elements and use that to help determine the // collection type) final PluralAttributeElementBinding elementBinding = pluralAttributeBinding.getPluralAttributeElementBinding(); - final PluralAttributeElementBinding.Nature elementNature = elementBinding.getNature(); + final PluralAttributeElementNature elementNature = elementBinding.getNature(); final PersistentAttributeType persistentAttributeType; final PersistentAttributeType elementPersistentAttributeType; PersistentAttributeType keyPersistentAttributeType = null; - if ( elementNature == PluralAttributeElementBinding.Nature.MANY_TO_ANY ) { + if ( elementNature == PluralAttributeElementNature.MANY_TO_ANY ) { // ANY mappings are currently not supported in the JPA metamodel; see HHH-6589 context.handleUnsupportedFeature( UnsupportedFeature.ANY ); return null; } - else if ( elementNature == PluralAttributeElementBinding.Nature.BASIC ) { + else if ( elementNature == PluralAttributeElementNature.BASIC ) { elementPersistentAttributeType = PersistentAttributeType.BASIC; persistentAttributeType = PersistentAttributeType.ELEMENT_COLLECTION; } - else if ( elementNature == PluralAttributeElementBinding.Nature.AGGREGATE ) { + else if ( elementNature == PluralAttributeElementNature.AGGREGATE ) { elementPersistentAttributeType = PersistentAttributeType.EMBEDDED; persistentAttributeType = PersistentAttributeType.ELEMENT_COLLECTION; } else { - elementPersistentAttributeType = elementNature == PluralAttributeElementBinding.Nature.MANY_TO_MANY + elementPersistentAttributeType = elementNature == PluralAttributeElementNature.MANY_TO_MANY ? PersistentAttributeType.MANY_TO_MANY : PersistentAttributeType.ONE_TO_MANY; persistentAttributeType = elementPersistentAttributeType; } // For maps, also check the key binding - if ( pluralAttributeBinding.getAttribute().getNature() == org.hibernate.metamodel.spi.domain.PluralAttribute.Nature.MAP ) { + if ( pluralAttributeBinding.getAttribute().getPluralAttributeNature() == PluralAttributeNature.MAP ) { final IndexedPluralAttributeBinding indexedPluralAttributeBinding = (IndexedPluralAttributeBinding) pluralAttributeBinding; - final PluralAttributeIndexBinding.Nature indexNature + final PluralAttributeIndexNature indexNature = indexedPluralAttributeBinding.getPluralAttributeIndexBinding().getNature(); - if ( indexNature == PluralAttributeIndexBinding.Nature.MANY_TO_ANY ) { + if ( indexNature == PluralAttributeIndexNature.MANY_TO_ANY ) { context.handleUnsupportedFeature( UnsupportedFeature.ANY ); return null; } - else if ( indexNature == PluralAttributeIndexBinding.Nature.MANY_TO_MANY ) { + else if ( indexNature == PluralAttributeIndexNature.MANY_TO_MANY ) { keyPersistentAttributeType = PersistentAttributeType.MANY_TO_ONE; } - else if ( indexNature == PluralAttributeIndexBinding.Nature.AGGREGATE ) { + else if ( indexNature == PluralAttributeIndexNature.AGGREGATE ) { keyPersistentAttributeType = PersistentAttributeType.EMBEDDED; } else { diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/internal/metamodel/builder/MetamodelBuilder.java b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/internal/metamodel/builder/MetamodelBuilder.java index 2191eb66f7..181811455e 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/internal/metamodel/builder/MetamodelBuilder.java +++ b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/internal/metamodel/builder/MetamodelBuilder.java @@ -51,7 +51,7 @@ import org.hibernate.metamodel.Metadata; import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; import org.hibernate.metamodel.spi.binding.AttributeBinding; import org.hibernate.metamodel.spi.binding.BasicAttributeBinding; -import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding; +import org.hibernate.metamodel.spi.binding.EmbeddedAttributeBinding; import org.hibernate.metamodel.spi.binding.EntityBinding; import org.hibernate.metamodel.spi.binding.HierarchyDetails; import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; @@ -337,8 +337,8 @@ public class MetamodelBuilder { break; } case AGGREGATED_COMPOSITE: { - CompositeAttributeBinding idAttributeBinding = - (CompositeAttributeBinding) hierarchyDetails.getEntityIdentifier().getAttributeBinding(); + EmbeddedAttributeBinding idAttributeBinding = + (EmbeddedAttributeBinding) hierarchyDetails.getEntityIdentifier().getAttributeBinding(); if ( idAttributeBinding != null ) { if ( idAttributeBinding.getAttribute().getAttributeContainer().equals( descriptor ) ) { //noinspection unchecked @@ -351,12 +351,12 @@ public class MetamodelBuilder { } default: { // nature == (non-aggregated) COMPOSITE - CompositeAttributeBinding idAttributeBinding = - (CompositeAttributeBinding) hierarchyDetails.getEntityIdentifier().getAttributeBinding(); + EmbeddedAttributeBinding idAttributeBinding = + (EmbeddedAttributeBinding) hierarchyDetails.getEntityIdentifier().getAttributeBinding(); if ( idAttributeBinding != null ) { if ( idAttributeBinding.getAttribute().getAttributeContainer().equals( descriptor ) ) { Set idClassAttributes = new HashSet(); - for ( AttributeBinding idClassAttributeBinding : idAttributeBinding.attributeBindings() ) { + for ( AttributeBinding idClassAttributeBinding : idAttributeBinding.getEmbeddableBinding().attributeBindings() ) { idClassAttributes.add( attributeBuilder.buildIdAttribute( jpaDescriptor, idClassAttributeBinding ) ); } //noinspection unchecked 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 b965b80b3f..0aa6511132 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 @@ -46,7 +46,7 @@ import org.hibernate.envers.internal.tools.Triple; import org.hibernate.envers.strategy.AuditStrategy; import org.hibernate.envers.strategy.ValidityAuditStrategy; import org.hibernate.metamodel.spi.binding.AttributeBinding; -import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding; +import org.hibernate.metamodel.spi.binding.EmbeddedAttributeBinding; import org.hibernate.metamodel.spi.binding.EntityBinding; import org.hibernate.metamodel.spi.binding.EntityDiscriminator; import org.hibernate.metamodel.spi.binding.ManyToOneAttributeBinding; @@ -237,7 +237,7 @@ public final class AuditMetadataGenerator { componentMetadataGenerator.addComponent( parent, propertyAuditingData, - (CompositeAttributeBinding) attributeBinding, + (EmbeddedAttributeBinding) attributeBinding, currentMapper, entityName, xmlMappingData, @@ -274,7 +274,7 @@ public final class AuditMetadataGenerator { componentMetadataGenerator.addComponent( parent, propertyAuditingData, - (CompositeAttributeBinding) attributeBinding, + (EmbeddedAttributeBinding) attributeBinding, currentMapper, entityName, xmlMappingData, 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 ae092b2f9a..21e1447094 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 @@ -78,19 +78,19 @@ import org.hibernate.envers.internal.tools.MappingTools; import org.hibernate.envers.internal.tools.ReflectionTools; import org.hibernate.envers.internal.tools.StringTools; import org.hibernate.envers.internal.tools.Tools; +import org.hibernate.metamodel.spi.PluralAttributeElementNature; +import org.hibernate.metamodel.spi.PluralAttributeNature; import org.hibernate.metamodel.spi.binding.AttributeBinding; -import org.hibernate.metamodel.spi.binding.CompositeAttributeBindingContainer; -import org.hibernate.metamodel.spi.binding.CompositePluralAttributeElementBinding; import org.hibernate.metamodel.spi.binding.CompositePluralAttributeIndexBinding; +import org.hibernate.metamodel.spi.binding.EmbeddableBinding; import org.hibernate.metamodel.spi.binding.EntityBinding; import org.hibernate.metamodel.spi.binding.HibernateTypeDescriptor; import org.hibernate.metamodel.spi.binding.IndexedPluralAttributeBinding; import org.hibernate.metamodel.spi.binding.PluralAttributeAssociationElementBinding; import org.hibernate.metamodel.spi.binding.PluralAttributeBinding; -import org.hibernate.metamodel.spi.binding.PluralAttributeElementBinding; +import org.hibernate.metamodel.spi.binding.PluralAttributeElementBindingEmbedded; import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding; import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; -import org.hibernate.metamodel.spi.domain.PluralAttribute; import org.hibernate.metamodel.spi.relational.TableSpecification; import org.hibernate.metamodel.spi.relational.Value; import org.hibernate.type.BagType; @@ -173,18 +173,18 @@ public final class CollectionMetadataGenerator { void addCollection() { final Type type = pluralAttributeBinding.getHibernateTypeDescriptor().getResolvedTypeMapping(); - final PluralAttributeElementBinding.Nature elementNature = + final PluralAttributeElementNature elementNature = pluralAttributeBinding.getPluralAttributeElementBinding().getNature(); final boolean oneToManyAttachedType = type instanceof BagType || type instanceof SetType || type instanceof MapType || type instanceof ListType; final boolean inverseOneToMany = - (elementNature == PluralAttributeElementBinding.Nature.ONE_TO_MANY) && + (elementNature == PluralAttributeElementNature.ONE_TO_MANY) && ( pluralAttributeBinding.getPluralAttributeKeyBinding().isInverse() ); final boolean owningManyToOneWithJoinTableBidirectional = - (elementNature == PluralAttributeAssociationElementBinding.Nature.MANY_TO_MANY) && + (elementNature == PluralAttributeElementNature.MANY_TO_MANY) && (propertyAuditingData.getRelationMappedBy() != null); final boolean fakeOneToManyBidirectional = - (elementNature == PluralAttributeElementBinding.Nature.ONE_TO_MANY) + (elementNature == PluralAttributeElementNature.ONE_TO_MANY) && (propertyAuditingData.getAuditMappedBy() != null); if ( oneToManyAttachedType && (inverseOneToMany || fakeOneToManyBidirectional || owningManyToOneWithJoinTableBidirectional) ) { @@ -350,7 +350,7 @@ public final class CollectionMetadataGenerator { private String getMiddleTableName(PluralAttributeBinding attributeBinding, String entityName) { // We check how Hibernate maps the collection. if ( attributeBinding.getPluralAttributeElementBinding().getNature() == - PluralAttributeElementBinding.Nature.ONE_TO_MANY && + PluralAttributeElementNature.ONE_TO_MANY && !attributeBinding.getPluralAttributeKeyBinding().isInverse() ) { // This must be a @JoinColumn+@OneToMany mapping. Generating the table name, as Hibernate doesn't use a // middle table for mapping this relation. @@ -508,7 +508,7 @@ public final class CollectionMetadataGenerator { } private MiddleComponentData addIndex(Element middleEntityXml, QueryGeneratorBuilder queryGeneratorBuilder) { - if ( pluralAttributeBinding.getAttribute().getNature().isIndexable() ) { + if ( pluralAttributeBinding.getAttribute().getPluralAttributeNature().isIndexed() ) { final PluralAttributeIndexBinding indexBinding = ( (IndexedPluralAttributeBinding) pluralAttributeBinding ).getPluralAttributeIndexBinding(); final String mapKey = propertyAuditingData.getMapKey(); @@ -555,7 +555,7 @@ public final class CollectionMetadataGenerator { } private PluralAttributeIndexBinding getPluralAttributeIndexBinding() { - if ( !pluralAttributeBinding.getAttribute().getNature().isIndexable() ) { + if ( !pluralAttributeBinding.getAttribute().getPluralAttributeNature().isIndexed() ) { throw new AssertionFailure( "This method is only valid for an indexed plural attribute binding." ); } return ( (IndexedPluralAttributeBinding) pluralAttributeBinding ).getPluralAttributeIndexBinding(); @@ -587,9 +587,9 @@ public final class CollectionMetadataGenerator { } else { hibernateTypeDescriptor = pluralAttributeBinding.getPluralAttributeElementBinding().getHibernateTypeDescriptor(); - values = pluralAttributeBinding.getPluralAttributeElementBinding().getValues(); + values = pluralAttributeBinding.getPluralAttributeElementBinding().getRelationalValueContainer().values(); - } ; + } if ( hibernateTypeDescriptor.getResolvedTypeMapping() instanceof ManyToOneType ) { final String prefixRelated = prefix + "_"; @@ -629,14 +629,14 @@ public final class CollectionMetadataGenerator { ); } else if ( hibernateTypeDescriptor.getResolvedTypeMapping() instanceof ComponentType ) { - final CompositeAttributeBindingContainer compositeAttributeBindingContainer; + final EmbeddableBinding embeddableBinding; if ( isIndex ) { - compositeAttributeBindingContainer = + embeddableBinding = ( ( CompositePluralAttributeIndexBinding ) getPluralAttributeIndexBinding() ).getCompositeAttributeBindingContainer(); } else { - compositeAttributeBindingContainer = - ( (CompositePluralAttributeElementBinding) pluralAttributeBinding.getPluralAttributeElementBinding() ).getCompositeAttributeBindingContainer(); + embeddableBinding = + ( (PluralAttributeElementBindingEmbedded) pluralAttributeBinding.getPluralAttributeElementBinding() ).getEmbeddableBinding(); } // Collection of embeddable elements. final Class componentClass = ReflectionTools.loadClass( @@ -655,8 +655,8 @@ public final class CollectionMetadataGenerator { context, auditData, new AuditedPropertiesReader.ComponentPropertiesSource( - context.getClassInfo( compositeAttributeBindingContainer.getAttributeContainer() ), - compositeAttributeBindingContainer + context.getClassInfo( embeddableBinding.getAttributeContainer() ), + embeddableBinding ), "" ).read(); @@ -666,7 +666,7 @@ public final class CollectionMetadataGenerator { final PropertyAuditingData nestedAuditingData = auditData.getPropertyAuditingData( auditedPropertyName ); mainGenerator.addValue( parentXmlMapping, - compositeAttributeBindingContainer.locateAttributeBinding( auditedPropertyName ), + embeddableBinding.locateAttributeBinding( auditedPropertyName ), componentMapper, prefix, xmlMappingData, nestedAuditingData, @@ -680,7 +680,7 @@ public final class CollectionMetadataGenerator { final PropertyAuditingData nestedAuditingData = auditData.getPropertyAuditingData( auditedPropertyName ); mainGenerator.addValue( parentXmlMapping, - compositeAttributeBindingContainer.locateAttributeBinding( auditedPropertyName ), + embeddableBinding.locateAttributeBinding( auditedPropertyName ), componentMapper, referencingEntityName, xmlMappingData, @@ -692,7 +692,7 @@ public final class CollectionMetadataGenerator { // 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 ( ( pluralAttributeBinding.getAttribute() ).getNature() == PluralAttribute.Nature.SET ) { + if ( ( pluralAttributeBinding.getAttribute() ).getPluralAttributeNature() == PluralAttributeNature.SET ) { final String setOrdinalPropertyName = context.getAuditEntitiesConfiguration() .getEmbeddableSetOrdinalPropertyName(); final Element ordinalProperty = MetadataTools.addProperty( @@ -950,7 +950,7 @@ public final class CollectionMetadataGenerator { attributeValues = ( (SingularAttributeBinding) attributeBinding ).getValues(); } else { - attributeValues = ( (PluralAttributeBinding) attributeBinding ).getPluralAttributeElementBinding().getValues(); + attributeValues = ( (PluralAttributeBinding) attributeBinding ).getPluralAttributeElementBinding().getRelationalValueContainer().values(); } if ( Tools.iteratorsContentEqual( 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 cf45d30646..8299a8be1b 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 @@ -31,8 +31,7 @@ import org.hibernate.envers.configuration.internal.metadata.reader.PropertyAudit import org.hibernate.envers.configuration.spi.AuditConfiguration; import org.hibernate.envers.internal.entities.mapper.CompositeMapperBuilder; import org.hibernate.metamodel.spi.binding.AttributeBinding; -import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding; -import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; +import org.hibernate.metamodel.spi.binding.EmbeddedAttributeBinding; import org.dom4j.Element; @@ -55,17 +54,17 @@ public final class ComponentMetadataGenerator { @SuppressWarnings({"unchecked"}) public void addComponent( Element parent, PropertyAuditingData propertyAuditingData, - CompositeAttributeBinding compositeAttributeBinding, CompositeMapperBuilder mapper, String entityName, + EmbeddedAttributeBinding embeddedAttributeBinding, CompositeMapperBuilder mapper, String entityName, EntityXmlMappingData xmlMappingData, boolean firstPass) { final Class componentClass; - final EntityMode entityMode = compositeAttributeBinding.seekEntityBinding().getHierarchyDetails().getEntityMode(); + final EntityMode entityMode = embeddedAttributeBinding.getEmbeddableBinding().seekEntityBinding().getHierarchyDetails().getEntityMode(); if ( entityMode == EntityMode.MAP ) { componentClass = context.getClassLoaderService().classForName( Map.class.getCanonicalName() ); } else { // TODO: get rid of classloading. componentClass = context.getClassLoaderService().classForName( - compositeAttributeBinding.getHibernateTypeDescriptor().getJavaTypeDescriptor().getName().toString() + embeddedAttributeBinding.getHibernateTypeDescriptor().getJavaTypeDescriptor().getName().toString() ); } final CompositeMapperBuilder componentMapper = mapper.addComponent( @@ -77,7 +76,7 @@ public final class ComponentMetadataGenerator { final ComponentAuditingData componentAuditingData = (ComponentAuditingData) propertyAuditingData; // Adding all properties of the component - for ( AttributeBinding attributeBinding : compositeAttributeBinding.attributeBindings() ) { + for ( AttributeBinding attributeBinding : embeddedAttributeBinding.getEmbeddableBinding().attributeBindings() ) { final PropertyAuditingData componentPropertyAuditingData = componentAuditingData.getPropertyAuditingData( attributeBinding.getAttribute().getName() ); 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 f4a1da25b2..10e9a4778c 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 @@ -37,7 +37,7 @@ import org.hibernate.envers.internal.entities.mapper.id.SimpleIdMapperBuilder; import org.hibernate.envers.internal.entities.mapper.id.SingleIdMapper; import org.hibernate.id.EntityIdentifierNature; import org.hibernate.metamodel.spi.binding.AttributeBinding; -import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding; +import org.hibernate.metamodel.spi.binding.EmbeddedAttributeBinding; import org.hibernate.metamodel.spi.binding.EntityBinding; import org.hibernate.metamodel.spi.binding.EntityIdentifier; import org.hibernate.metamodel.spi.binding.ManyToOneAttributeBinding; @@ -65,14 +65,14 @@ public final class IdMetadataGenerator { @SuppressWarnings({"unchecked"}) private boolean addIdProperties( Element parent, - CompositeAttributeBinding compositeAttributeBinding, + EmbeddedAttributeBinding embeddedAttributeBinding, SimpleMapperBuilder mapper, boolean key, boolean audited) { - //if ( compositeAttributeBinding.getAttribute().isSynthetic() ) { + //if ( embeddedAttributeBinding.getAttribute().isSynthetic() ) { // return true; //} - for ( AttributeBinding attributeBinding : compositeAttributeBinding.attributeBindings() ) { + for ( AttributeBinding attributeBinding : embeddedAttributeBinding.getEmbeddableBinding().attributeBindings() ) { final Type propertyType = attributeBinding.getHibernateTypeDescriptor().getResolvedTypeMapping(); final boolean added; if ( propertyType instanceof ManyToOneType ) { @@ -136,7 +136,7 @@ public final class IdMetadataGenerator { mapper = new MultipleIdMapper( componentClass ); if ( !addIdProperties( relIdMapping, - (CompositeAttributeBinding) entityIdentifier.getAttributeBinding(), + (EmbeddedAttributeBinding) entityIdentifier.getAttributeBinding(), mapper, false, audited @@ -147,7 +147,7 @@ public final class IdMetadataGenerator { // null mapper - the mapping where already added the first time, now we only want to generate the xml if ( !addIdProperties( origIdMapping, - (CompositeAttributeBinding) entityIdentifier.getAttributeBinding(), + (EmbeddedAttributeBinding) entityIdentifier.getAttributeBinding(), null, true, audited @@ -164,7 +164,7 @@ public final class IdMetadataGenerator { mapper = new EmbeddedIdMapper( getIdPropertyData( entityIdentifier.getAttributeBinding() ), embeddableClass ); if ( !addIdProperties( relIdMapping, - (CompositeAttributeBinding) entityIdentifier.getAttributeBinding(), + (EmbeddedAttributeBinding) entityIdentifier.getAttributeBinding(), mapper, false, audited @@ -175,7 +175,7 @@ public final class IdMetadataGenerator { // null mapper - the mapping where already added the first time, now we only want to generate the xml if ( !addIdProperties( origIdMapping, - (CompositeAttributeBinding) entityIdentifier.getAttributeBinding(), + (EmbeddedAttributeBinding) entityIdentifier.getAttributeBinding(), null, true, audited 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 32432e25e5..5ea34eaec5 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 @@ -33,10 +33,6 @@ import java.util.Map; import java.util.Set; import javax.persistence.JoinColumn; -import org.jboss.jandex.AnnotationInstance; -import org.jboss.jandex.ClassInfo; -import org.jboss.jandex.DotName; - import org.hibernate.MappingException; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.cfg.AccessType; @@ -57,11 +53,15 @@ import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames; import org.hibernate.metamodel.source.internal.annotations.util.JandexHelper; import org.hibernate.metamodel.spi.binding.AttributeBinding; import org.hibernate.metamodel.spi.binding.AttributeBindingContainer; -import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding; +import org.hibernate.metamodel.spi.binding.EmbeddedAttributeBinding; import org.hibernate.metamodel.spi.binding.EntityBinding; import org.hibernate.metamodel.spi.domain.Attribute; import org.hibernate.metamodel.spi.domain.Hierarchical; +import org.jboss.jandex.AnnotationInstance; +import org.jboss.jandex.ClassInfo; +import org.jboss.jandex.DotName; + import static org.hibernate.envers.internal.tools.Tools.newHashMap; import static org.hibernate.envers.internal.tools.Tools.newHashSet; @@ -352,9 +352,9 @@ public class AuditedPropertiesReader { String accessType = AccessType.PROPERTY.getType(); if ( !auditedPropertiesHolder.contains( property ) ) { final AttributeBinding attributeBinding = processedPersistentPropertiesSource.getAttributeBinding( property ); - if ( CompositeAttributeBinding.class.isInstance( attributeBinding ) ) { + if ( EmbeddedAttributeBinding.class.isInstance( attributeBinding ) ) { this.addFromComponentProperty( - (CompositeAttributeBinding) attributeBinding, + (EmbeddedAttributeBinding) attributeBinding, accessType, audited ); @@ -418,9 +418,9 @@ public class AuditedPropertiesReader { // If the property was already defined by the subclass, is ignored by superclasses final String attributeName = attributeBinding.getAttribute().getName(); if ( persistentProperties.contains( attributeName ) && !auditedPropertiesHolder.contains( attributeName ) ) { - if ( attributeBinding instanceof CompositeAttributeBinding ) { + if ( attributeBinding instanceof EmbeddedAttributeBinding ) { this.addFromComponentProperty( - (CompositeAttributeBinding) attributeBinding, accessType, allClassAudited + (EmbeddedAttributeBinding) attributeBinding, accessType, allClassAudited ); } else { @@ -469,7 +469,7 @@ public class AuditedPropertiesReader { // } private void addFromComponentProperty( - CompositeAttributeBinding attributeBinding, + EmbeddedAttributeBinding attributeBinding, String accessType, Audited allClassAudited) { final ComponentAuditingData componentData = new ComponentAuditingData(); @@ -482,8 +482,8 @@ public class AuditedPropertiesReader { //} //else { componentPropertiesSource = new ComponentPropertiesSource( - context.getClassInfo( attributeBinding.getAttributeContainer() ), - attributeBinding + context.getClassInfo( attributeBinding.getEmbeddableBinding().getAttributeContainer() ), + attributeBinding.getEmbeddableBinding() ); //} 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 ea97624260..4a98202dfe 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 @@ -23,6 +23,7 @@ */ package org.hibernate.envers.internal.tools; +import org.hibernate.metamodel.spi.PluralAttributeElementNature; import org.hibernate.metamodel.spi.binding.AttributeBinding; import org.hibernate.metamodel.spi.binding.ManyToOneAttributeBinding; import org.hibernate.metamodel.spi.binding.PluralAttributeAssociationElementBinding; @@ -87,9 +88,9 @@ public abstract class MappingTools { else if ( attributeBinding instanceof PluralAttributeBinding ) { final PluralAttributeBinding pluralAttributeBinding = (PluralAttributeBinding) attributeBinding; final PluralAttributeElementBinding elementBinding = pluralAttributeBinding.getPluralAttributeElementBinding(); - if ( elementBinding.getNature() == PluralAttributeElementBinding.Nature.ONE_TO_MANY ) { + if ( elementBinding.getNature() == PluralAttributeElementNature.ONE_TO_MANY ) { // TODO: FIX THIS!!! - //return !( (OneToManyPluralAttributeElementBinding) elementBinding ).isNotFoundAnException(); + //return !( (PluralAttributeElementBindingOneToMany) elementBinding ).isNotFoundAnException(); } } return false;