HHH-9077 - org.hibernate.metamodel.source.spi TLC

This commit is contained in:
Steve Ebersole 2014-03-25 21:06:24 -05:00
parent c7a07a170a
commit bab7fc6a47
224 changed files with 5815 additions and 4595 deletions

View File

@ -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;

View File

@ -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(),

View File

@ -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 );
}

View File

@ -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

View File

@ -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<AttributeSource> subAttributeSourceIterator = attributeSource.attributeSources().iterator();
for ( AttributeBinding subAttributeBinding : attributeBinding.attributeBindings() ) {
Iterator<AttributeSource> 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() );

View File

@ -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<Binder.DefaultNamingStrategy> defaultNameStrategies,
final boolean forceNonNullable) {
final List<RelationalValueBinding> valueBindings = new ArrayList<RelationalValueBinding>();
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() ) {

View File

@ -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<String, EntitySourceIndex> entitySourceIndexByEntityName = new HashMap<String, EntitySourceIndex>();
private final Map<AttributeSourceKey, AttributeSource> attributeSourcesByKey = new HashMap<AttributeSourceKey, AttributeSource>();
private final Map<AttributeSourceKey, AttributeSourceKey> mappedByAttributeKeysByOwnerAttributeKeys =
new HashMap<AttributeSourceKey, AttributeSourceKey>();
private final Map<AttributeRole, AttributeSource> attributeSourcesByKey = new HashMap<AttributeRole, AttributeSource>();
private final Map<AttributeRole, AttributeRole> mappedByAttributeKeysByOwnerAttributeKeys =
new HashMap<AttributeRole, AttributeRole>();
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<SingularAttributeSource> 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<AttributeSourceKey, SingularAttributeSource> getSingularAttributeSources(
public Map<AttributeRole, SingularAttributeSource> 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<AttributeSourceKey, PluralAttributeSource> getPluralAttributeSources(
public Map<AttributeRole, PluralAttributeSource> 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<AttributeSourceKey, SingularAttributeSource> unresolvedSingularAttributeSourcesByKey
= new HashMap<AttributeSourceKey, SingularAttributeSource>();
private final Map<AttributeRole, SingularAttributeSource> unresolvedSingularAttributeSourcesByKey
= new HashMap<AttributeRole, SingularAttributeSource>();
private final Map<SingularAttributeSource.Nature, Map<AttributeSourceKey, SingularAttributeSource>> identifierAttributeSourcesByNature
= new EnumMap<SingularAttributeSource.Nature, Map<AttributeSourceKey, SingularAttributeSource>>( SingularAttributeSource.Nature.class );
private final Map<SingularAttributeSource.Nature, Map<AttributeSourceKey, SingularAttributeSource>> nonMappedBySingularAttributeSourcesByNature
= new EnumMap<SingularAttributeSource.Nature, Map<AttributeSourceKey, SingularAttributeSource>>( SingularAttributeSource.Nature.class );
private final Map<SingularAttributeSource.Nature, Map<AttributeSourceKey, SingularAttributeSource>> mappedBySingularAttributeSourcesByNature
= new EnumMap<SingularAttributeSource.Nature, Map<AttributeSourceKey, SingularAttributeSource>>( SingularAttributeSource.Nature.class );
private final Map<SingularAttributeNature, Map<AttributeRole, SingularAttributeSource>> identifierAttributeSourcesByNature
= new EnumMap<SingularAttributeNature, Map<AttributeRole, SingularAttributeSource>>( SingularAttributeNature.class );
private final Map<SingularAttributeNature, Map<AttributeRole, SingularAttributeSource>> nonMappedBySingularAttributeSourcesByNature
= new EnumMap<SingularAttributeNature, Map<AttributeRole, SingularAttributeSource>>( SingularAttributeNature.class );
private final Map<SingularAttributeNature, Map<AttributeRole, SingularAttributeSource>> mappedBySingularAttributeSourcesByNature
= new EnumMap<SingularAttributeNature, Map<AttributeRole, SingularAttributeSource>>( 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<AttributeSourceKey, PluralAttributeSource> nonInversePluralAttributeSourcesByKey =
new LinkedHashMap<AttributeSourceKey, PluralAttributeSource>();
private final Map<AttributeSourceKey, PluralAttributeSource> inversePluralAttributeSourcesByKey =
new LinkedHashMap<AttributeSourceKey, PluralAttributeSource>();
protected AttributeSourceKey makeKey(String pathBase, AttributeSource attributeSource) {
return new AttributeSourceKey( getAttributeSourceKeyBase(), pathBase, attributeSource.getName() );
}
private final Map<AttributeRole, PluralAttributeSource> nonInversePluralAttributeSourcesByKey =
new LinkedHashMap<AttributeRole, PluralAttributeSource>();
private final Map<AttributeRole, PluralAttributeSource> inversePluralAttributeSourcesByKey =
new LinkedHashMap<AttributeRole, PluralAttributeSource>();
@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<SingularAttributeSource.Nature, Map<AttributeSourceKey, SingularAttributeSource>> map;
final Map<SingularAttributeNature, Map<AttributeRole, SingularAttributeSource>> 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<SingularAttributeSource.Nature, Map<AttributeSourceKey, SingularAttributeSource>> map) {
final Map<AttributeSourceKey, SingularAttributeSource> singularAttributeSources;
if ( map.containsKey( attributeSource.getNature() ) ) {
singularAttributeSources = map.get( attributeSource.getNature() );
Map<SingularAttributeNature, Map<AttributeRole, SingularAttributeSource>> map) {
final Map<AttributeRole, SingularAttributeSource> singularAttributeSources;
if ( map.containsKey( attributeSource.getSingularAttributeNature() ) ) {
singularAttributeSources = map.get( attributeSource.getSingularAttributeNature() );
}
else {
singularAttributeSources = new LinkedHashMap<AttributeSourceKey,SingularAttributeSource>();
map.put( attributeSource.getNature(), singularAttributeSources );
singularAttributeSources = new LinkedHashMap<AttributeRole,SingularAttributeSource>();
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<AttributeSourceKey,PluralAttributeSource> map = attributeSource.isInverse()
public void indexPluralAttributeSource(PluralAttributeSource attributeSource) {
final Map<AttributeRole,PluralAttributeSource> 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<AttributeSourceKey, SingularAttributeSource> getSingularAttributeSources(
public Map<AttributeRole, SingularAttributeSource> getSingularAttributeSources(
boolean isMappedBy,
SingularAttributeSource.Nature nature) {
final Map<AttributeSourceKey, SingularAttributeSource> entries;
if ( isMappedBy && mappedBySingularAttributeSourcesByNature.containsKey( nature ) ) {
entries = Collections.unmodifiableMap( mappedBySingularAttributeSourcesByNature.get( nature ) );
SingularAttributeNature singularAttributeNature) {
final Map<AttributeRole, SingularAttributeSource> 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<AttributeSourceKey, PluralAttributeSource> getPluralAttributeSources(boolean isInverse) {
final Map<AttributeSourceKey,PluralAttributeSource> map = isInverse
public Map<AttributeRole, PluralAttributeSource> getPluralAttributeSources(boolean isInverse) {
final Map<AttributeRole,PluralAttributeSource> 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<Map.Entry<AttributeSourceKey,SingularAttributeSource>> it = unresolvedSingularAttributeSourcesByKey.entrySet().iterator(); it.hasNext(); ) {
final Map.Entry<AttributeSourceKey,SingularAttributeSource> 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<AttributeSourceKey, PluralAttributeSource> getPluralAttributeSources(boolean isInverse) {
public Map<AttributeRole, PluralAttributeSource> getPluralAttributeSources(boolean isInverse) {
return Collections.emptyMap();
}
@ -553,17 +459,15 @@ public class SourceIndex {
}
@Override
public String getAttributeSourceKeyBase() {
return entitySource.getEntityName();
}
@Override
public Map<AttributeSourceKey, SingularAttributeSource> getSingularAttributeSources(
public Map<AttributeRole, SingularAttributeSource> getSingularAttributeSources(
boolean isMappedBy,
SingularAttributeSource.Nature nature) {
Map<AttributeSourceKey, SingularAttributeSource> values = hierarchyInfo.getSingularAttributeSources( isMappedBy, nature );
SingularAttributeNature singularAttributeNature) {
Map<AttributeRole, SingularAttributeSource> 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<String> dependantHierarchyKeys;
}
}

View File

@ -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<RelationalValueBinding> 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<RelationalValueBinding> relationalValueBindings,
final EntityBinding referencedEntityBinding);

View File

@ -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<RelationalValueBinding> 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<RelationalValueBinding> 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(),

View File

@ -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<RelationalValueBinding> resolveManyToManyElementRelationalValueBindings(
final EntityBinding entityBinding,
final ManyToManyPluralAttributeElementSource elementSource,
final PluralAttributeElementSourceManyToMany elementSource,
final TableSpecification collectionTable,
final EntityBinding referencedEntityBinding) {
final List<Column> 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<RelationalValueBinding> 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
);
}

View File

@ -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 );

View File

@ -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<? extends ToolingHintSource> getToolingHintSources() {
// todo : when hooking in unified (Hibernate-specific) xml elements need to account for this
return Collections.emptyList();
}
}

View File

@ -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);
}

View File

@ -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<CascadeStyle> cascadeStyles;
private final Set<MappedByAssociationSource> ownedAssociationSources = new HashSet<MappedByAssociationSource>();
private Nature nature;
public AbstractSingularAssociationAttributeSource(
AbstractManagedTypeSource container,
SingularAssociationAttribute attribute) {
super( container, attribute );
this.cascadeStyles = determineCascadeStyles( attribute );
}
private static Set<CascadeStyle> determineCascadeStyles(SingularAssociationAttribute associationAttribute) {
final Set<CascadeStyle> 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<MappedByAssociationSource> 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<CascadeStyle> 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;
}
}

View File

@ -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();
}
}

View File

@ -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<RelationalValueSource> 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<RelationalValueSource>();
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<RelationalValueSource> relationalValueSources() {
return relationalValueSources;
}
}

View File

@ -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

View File

@ -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;
}
}

View File

@ -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<MappedByAssociationSource> ownedAssociationSources = new HashSet<MappedByAssociationSource>( );
public AbstractPluralAssociationElementSourceImpl(PluralAttributeSourceImpl pluralAttributeSource) {
public AbstractPluralElementSourceAssociationImpl(PluralAttributeSourceImpl pluralAttributeSource) {
super( pluralAttributeSource );
}

View File

@ -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<CascadeStyle> unifiedCascadeStyles;
private SingularAttributeSource.Nature nature;
private SingularAttributeNature singularAttributeNature;
private final Set<MappedByAssociationSource> ownedAssociationSources = new HashSet<MappedByAssociationSource>();
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();
}
}

View File

@ -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;
}

View File

@ -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();
}
}

View File

@ -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 <stliu@hibernate.org>
*/
public class BasicPluralAttributeIndexSourceImpl extends AbstractPluralAttributeIndexSourceImpl implements BasicPluralAttributeIndexSource {
private final IndexedPluralAttributeSourceImpl indexedPluralAttributeSource;
private final List<RelationalValueSource> 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<RelationalValueSource> relationalValueSources) {
super( attribute );
this.indexedPluralAttributeSource = indexedPluralAttributeSource;
this.relationalValueSources = relationalValueSources;
this.defaultNamingStrategy = defaultNamingStrategy;
}
private static List<RelationalValueSource> 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<Binder.DefaultNamingStrategy> getDefaultNamingStrategies() {
return Collections.singletonList( defaultNamingStrategy );
}
@Override
public List<RelationalValueSource> relationalValueSources() {
return relationalValueSources;
}
}

View File

@ -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<CascadeStyle> unifiedCascadeStyles;
private final PluralAttributeElementDetailsEmbedded elementDescriptor;
private final EmbeddableTypeMetadata embeddableTypeMetadata;
private final List<AttributeSource> 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<AttributeSource> attributeSources() {
return attributeSources;
}
@Override
public LocalBindingContext getLocalBindingContext() {
return pluralAttribute.getContext();
}
@Override
public Set<CascadeStyle> getCascadeStyles() {
return unifiedCascadeStyles;
}
@Override
public Collection<? extends ToolingHintSource> 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 );
// }
}

View File

@ -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<AttributeSource> 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<AttributeSource> 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();
}
}

View File

@ -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<? extends ToolingHintSource> 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() + "}";
}
}

View File

@ -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

View File

@ -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 <stliu@hibernate.org>
*/
public class IndexedPluralAttributeSourceImpl extends PluralAttributeSourceImpl
implements IndexedPluralAttributeSource {
private final static EnumSet<AbstractPersistentAttribute.Nature> 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;
}
}

View File

@ -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;
}
}

View File

@ -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." );

View File

@ -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." );

View File

@ -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;
}
}

View File

@ -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<RelationalValueSource> relationalValueSources = new ArrayList<RelationalValueSource>();
public ManyToManyPluralAttributeElementSourceImpl(PluralAttributeSourceImpl pluralAttributeSource) {
public PluralAttributeElementSourceAssociationManyToManyImpl(PluralAttributeSourceImpl pluralAttributeSource) {
super( pluralAttributeSource );
if ( pluralAttributeSource.getMappedBy() != null ) {
throw new AssertionFailure( "pluralAttributeSource.getMappedByAttributeName() must be null." );

View File

@ -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;
}
}

View File

@ -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(

View File

@ -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<CascadeStyle> 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<CascadeStyle> getCascadeStyles() {
return unifiedCascadeStyles;
}
@Override
public Collection<? extends ToolingHintSource> getToolingHintSources() {
// HBM only
return Collections.emptyList();
}
}

View File

@ -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
}

View File

@ -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<AbstractPersistentAttribute.Nature> 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;
}
}

View File

@ -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<RelationalValueSource> 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<Binder.DefaultNamingStrategy> getDefaultNamingStrategies() {
return pluralAttributeIndexSource.getDefaultNamingStrategies();
}
@Override
public boolean isReferencedEntityAttribute() {
return true;
return Collections.singletonList( defaultNamingStrategy );
}
@Override
public List<RelationalValueSource> relationalValueSources() {
return pluralAttributeIndexSource.relationalValueSources();
return relationalValueSources;
}
}

View File

@ -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<RelationalValueSource> relationalValueSources = new ArrayList<RelationalValueSource>( 1 );
private final Binder.DefaultNamingStrategy defaultNamingStrategy;
private final List<AttributeSource> attributeSources;
public class PluralAttributeMapKeySourceEmbeddedImpl
extends AbstractPluralAttributeIndexSourceImpl
implements PluralAttributeMapKeySourceEmbedded {
public CompositePluralAttributeIndexSourceImpl(
private final EmbeddableSourceImpl embeddableSource;
private final Binder.DefaultNamingStrategy defaultNamingStrategy;
public PluralAttributeMapKeySourceEmbeddedImpl(
PluralAttribute attribute,
List<AttributeSource> 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<RelationalValueSource> 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<AttributeSource> attributeSources() {
return attributeSources;
}
@Override
public LocalBindingContext getLocalBindingContext() {
return pluralAssociationAttribute().getContext();
return embeddableSource.getTypeDescriptor();
}
}

View File

@ -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<Binder.DefaultNamingStrategy> getDefaultNamingStrategies() {
return null;
}
@Override
public List<RelationalValueSource> relationalValueSources() {
if ( mapKeyAttributeSource == null ) {
return null;
}
return mapKeyAttributeSource.relationalValueSources();
}
}

View File

@ -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";
}
}
}

View File

@ -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<Binder.DefaultNamingStrategy> getDefaultNamingStrategies() {
return Collections.singletonList( defaultNamingStrategy );
}
@Override
public HibernateTypeSource getTypeInformation() {
return INTERGER_TYPE;
return INTEGER_TYPE;
}
@Override
public List<RelationalValueSource> relationalValueSources() {
return Collections.singletonList( relationalValueSource );
}
}

View File

@ -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<CascadeStyle> 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<CascadeStyle> 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<Column> 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<String, String> 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<String, String> getParameters() {
return null;
}
@Override
public JavaTypeDescriptor getJavaType() {
return null;
}
}
}

View File

@ -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

View File

@ -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<AttributeSource> 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 );

View File

@ -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<org.hibernate.metamodel.spi.relational.Column> idColumns = context.resolveIdentifierColumns();
if ( associationAttribute().getJoinColumnValues().size() != idColumns.size() ) {
setNature( Nature.MANY_TO_ONE );
setSingularAttributeNature( SingularAttributeNature.MANY_TO_ONE );
}
else {
Set<String> joinColumnNames = new HashSet<String>( 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<Binder.DefaultNamingStrategy> 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<Binder.DefaultNamingStrategy> result = new ArrayList<Binder.DefaultNamingStrategy>( );
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 {

View File

@ -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 );
}
}

View File

@ -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

View File

@ -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
*

View File

@ -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;
}
}

View File

@ -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();
}
}

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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();

View File

@ -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

View File

@ -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;

View File

@ -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<PluralAttributeSource.Nature> CANNOT_HAVE_COLLECTION_ID = EnumSet.of(
PluralAttributeSource.Nature.SET,
PluralAttributeSource.Nature.MAP,
PluralAttributeSource.Nature.LIST,
PluralAttributeSource.Nature.ARRAY
private static final EnumSet<PluralAttributeNature> 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<AnnotationInstance> 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<AnnotationInstance> 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;
}

View File

@ -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.
*

View File

@ -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;

View File

@ -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;
}

View File

@ -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;

View File

@ -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.
*

View File

@ -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;
}
}

View File

@ -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 );
}
}

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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<AnnotationInstance> 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<AnnotationInstance> 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<AnnotationInstance> getMapKeyJoinColumnAnnotations() {
return mapKeyJoinColumnAnnotations;
}
@Override
public JavaTypeDescriptor getJavaType() {
return resolvedMapKeyType;
}
@Override
public AttributeTypeResolver getTypeResolver() {
return typeResolver;
}
}

View File

@ -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;
/**

View File

@ -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();

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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<? extends AttributeBinding> 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 {

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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<JaxbKeyPropertyElement> getKeyPropertyElementList() {
return Collections.emptyList();
}
@Override
public List<JaxbKeyManyToOneElement> getKeyManyToOneElementList() {
return Collections.emptyList();
}
@Override
public List<JaxbPropertyElement> getPropertyElementList() {
return Collections.emptyList();
}
@Override
public List<JaxbManyToOneElement> getManyToOneElementList() {
return Collections.emptyList();
}
@Override
public List<JaxbOneToOneElement> getOneToOneElementList() {
return Collections.emptyList();
}
@Override
public List<JaxbComponentElement> getComponentElementList() {
return Collections.emptyList();
}
@Override
public List<JaxbNestedCompositeElementElement> getNestedCompositeElementList() {
return Collections.emptyList();
}
@Override
public List<JaxbDynamicComponentElement> getDynamicComponentElementList() {
return Collections.emptyList();
}
@Override
public List<JaxbPropertiesElement> getPropertiesElementList() {
return Collections.emptyList();
}
@Override
public List<JaxbAnyElement> getAnyElementList() {
return Collections.emptyList();
}
@Override
public List<JaxbMapElement> getMapElementList() {
return Collections.emptyList();
}
@Override
public List<JaxbSetElement> getSetElementList() {
return Collections.emptyList();
}
@Override
public List<JaxbListElement> getListElementList() {
return Collections.emptyList();
}
@Override
public List<JaxbBagElement> getBagElementList() {
return Collections.emptyList();
}
@Override
public List<JaxbArrayElement> getArrayElementList() {
return Collections.emptyList();
}
@Override
public List<JaxbPrimitiveArrayElement> getPrimitiveArrayElementList() {
return Collections.emptyList();
}
}

View File

@ -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 <component/> and <composite-id/> 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() {
// <component/> does not support type information.
return null;
}
@Override
public String getPropertyAccessorName() {
return jaxbComponentSourceElement.getAccess();
}
@Override
public NaturalIdMutability getNaturalIdMutability() {
return null;
}
@Override
public Collection<? extends ToolingHintSource> 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<RelationalValueSource> relationalValueSources() {
// none, they are defined on the simple sub-attributes
return null;
}
}

View File

@ -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<IdentifiableTypeSource> subclassEntitySources = new ArrayList<IdentifiableTypeSource>();
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<IdentifiableTypeSource> getSubTypes() {
return subclassEntitySources;
@ -166,14 +184,14 @@ public abstract class AbstractEntitySourceImpl
}
protected List<AttributeSource> buildAttributeSources(List<AttributeSource> attributeSources) {
return buildAttributeSources( entityElement, attributeSources, null, SingularAttributeBinding.NaturalIdMutability.NOT_NATURAL_ID );
return buildAttributeSources( entityElement, attributeSources, null, NaturalIdMutability.NOT_NATURAL_ID );
}
protected List<AttributeSource> buildAttributeSources(
EntityElement element,
List<AttributeSource> 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<AttributeSource> results,
List<JaxbPropertyElement> 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<AttributeSource> results,
List<JaxbComponentElement> 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<AttributeSource> results,
List<JaxbDynamicComponentElement> elements,
String logicalTableName,
SingularAttributeBinding.NaturalIdMutability naturalIdMutability) {
NaturalIdMutability naturalIdMutability) {
// todo : implement
}
protected void processManyToOneAttributes(List<AttributeSource> results,
List<JaxbManyToOneElement> 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<AttributeSource> results,
List<JaxbOneToOneElement> 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<AttributeSource> results,
List<JaxbAnyElement> elements,
String logicalTableName,
SingularAttributeBinding.NaturalIdMutability naturalIdMutability) {
NaturalIdMutability naturalIdMutability) {
// todo : implement
}
@ -357,15 +378,24 @@ public abstract class AbstractEntitySourceImpl
);
}
}
protected void processIdBagAttributes(List<AttributeSource> results,
List<JaxbIdbagElement> propertyElements){
if ( !propertyElements.isEmpty() ) {
throw new NotYetImplementedException( "<idbag> is not supported yet" );
protected void processIdBagAttributes(
List<AttributeSource> results,
List<JaxbIdbagElement> elements){
for ( JaxbIdbagElement element : elements ) {
results.add(
new IdBagSourceImpl(
sourceMappingDocument(),
element,
this
)
);
}
}
protected void processBagAttributes(List<AttributeSource> results,
List<JaxbBagElement> propertyElements) {
protected void processBagAttributes(
List<AttributeSource> results,
List<JaxbBagElement> 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<AttributeSource> attributeSources() {
return attributeSources;

View File

@ -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

View File

@ -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<MappedByAssociationSource> ownedAssociationSources = new HashSet<MappedByAssociationSource>( );
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<Binder.DefaultNamingStrategy> result = new ArrayList<Binder.DefaultNamingStrategy>();
for ( final AttributeBinding attributeBinding : compositeAttributeBinding.attributeBindings() ) {
for ( final AttributeBinding attributeBinding : embeddedAttributeBinding.getEmbeddableBinding().attributeBindings() ) {
result.addAll( getDefaultNamingStrategies( entityName, tableName, attributeBinding ) );
}
return result;

View File

@ -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;
}
}

View File

@ -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

View File

@ -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<AttributeSource> buildAttributeSources() {
List<AttributeSource> attributeSources = new ArrayList<AttributeSource>();
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<RelationalValueSource> relationalValueSources() {
// none, they are defined on the simple sub-attributes
return null;
}
}

View File

@ -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<CascadeStyle> cascadeStyles;
private final List<AttributeSource> 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<AttributeSource> attributeSources() {
return attributeSources;
}
private static List<AttributeSource> buildAttributeSources(
MappingDocument mappingDocument,
JaxbCompositeElementElement compositeElement) {
List<AttributeSource> attributeSources = new ArrayList<AttributeSource>();
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<CascadeStyle> 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<? extends ToolingHintSource> getToolingHintSources() {
return compositeElement.getMeta();
}
}

View File

@ -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<AttributeSource> 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<JaxbKeyPropertyElement> keyPropertyElements,
List<JaxbKeyManyToOneElement> 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<Binder.DefaultNamingStrategy> 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<AttributeSource> attributeSources() {
return attributeSources;
}
private static List<AttributeSource> buildAttributeSources(
MappingDocument mappingDocument,
List<JaxbKeyPropertyElement> keyPropertyElements,
List<JaxbKeyManyToOneElement> keyManyToOneElements) {
List<AttributeSource> attributeSources = new ArrayList<AttributeSource>();
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<RelationalValueSource> relationalValueSources() {
return null;
}
@Override
public boolean areValuesIncludedInInsertByDefault() {
return true;
}
@Override
public boolean areValuesIncludedInUpdateByDefault() {
return false;
}
@Override
public boolean areValuesNullableByDefault() {
return true;
}
}

View File

@ -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 <component/>} and {@code <composite-id/>}, 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<JaxbKeyPropertyElement> getKeyPropertyElementList();
public List<JaxbKeyManyToOneElement> getKeyManyToOneElementList();
public List<JaxbPropertyElement> getPropertyElementList();
public List<JaxbManyToOneElement> getManyToOneElementList();
public List<JaxbOneToOneElement> getOneToOneElementList();
public List<JaxbComponentElement> getComponentElementList();
public List<JaxbNestedCompositeElementElement> getNestedCompositeElementList();
public List<JaxbDynamicComponentElement> getDynamicComponentElementList();
public List<JaxbPropertiesElement> getPropertiesElementList();
public List<JaxbAnyElement> getAnyElementList();
public List<JaxbMapElement> getMapElementList();
public List<JaxbSetElement> getSetElementList();
public List<JaxbListElement> getListElementList();
public List<JaxbBagElement> getBagElementList();
public List<JaxbArrayElement> getArrayElementList();
public List<JaxbPrimitiveArrayElement> getPrimitiveArrayElementList();
}

View File

@ -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<AttributeSource> 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<AttributeSource> 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<AttributeSource> attributeSources() {
return attributeSources;
}
@Override
public LocalBindingContext getLocalBindingContext() {
return bindingContext();
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Attribute building
protected static List<AttributeSource> buildAttributeSources(
EmbeddableJaxbSource container,
EmbeddableSourceImpl embeddableSource) {
final List<AttributeSource> attributeSources = new ArrayList<AttributeSource>();
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<AttributeSource> 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<AttributeSource> attributeSources() {
return subAttributeSources;
}
@Override
public boolean isVirtualAttribute() {
return false;
}
@Override
public Nature getNature() {
return Nature.COMPOSITE;
}
@Override
public HibernateTypeSource getTypeInformation() {
// <component/> 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<? extends ToolingHintSource> getToolingHintSources() {
return componentSourceElement.getMeta();
}
}

View File

@ -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<JaxbPropertyElement> getPropertyElementList() {
return jaxbComponentElement.getProperty();
}
@Override
public List<JaxbManyToOneElement> getManyToOneElementList() {
return jaxbComponentElement.getManyToOne();
}
@Override
public List<JaxbOneToOneElement> getOneToOneElementList() {
return jaxbComponentElement.getOneToOne();
}
@Override
public List<JaxbComponentElement> getComponentElementList() {
return jaxbComponentElement.getComponent();
}
@Override
public List<JaxbDynamicComponentElement> getDynamicComponentElementList() {
return jaxbComponentElement.getDynamicComponent();
}
@Override
public List<JaxbPropertiesElement> getPropertiesElementList() {
return jaxbComponentElement.getProperties();
}
@Override
public List<JaxbAnyElement> getAnyElementList() {
return jaxbComponentElement.getAny();
}
@Override
public List<JaxbMapElement> getMapElementList() {
return jaxbComponentElement.getMap();
}
@Override
public List<JaxbSetElement> getSetElementList() {
return jaxbComponentElement.getSet();
}
@Override
public List<JaxbListElement> getListElementList() {
return jaxbComponentElement.getList();
}
@Override
public List<JaxbBagElement> getBagElementList() {
return jaxbComponentElement.getBag();
}
@Override
public List<JaxbArrayElement> getArrayElementList() {
return jaxbComponentElement.getArray();
}
@Override
public List<JaxbPrimitiveArrayElement> getPrimitiveArrayElementList() {
return jaxbComponentElement.getPrimitiveArray();
}
}
}

View File

@ -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<JaxbKeyPropertyElement> keyPropertyElementList;
private final List<JaxbKeyManyToOneElement> 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<JaxbKeyPropertyElement>();
this.keyManyToOneElementList = new ArrayList<JaxbKeyManyToOneElement>();
@Override
protected List<AttributeSource> buildAttributeSources() {
List<AttributeSource> attributeSources = new ArrayList<AttributeSource>();
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<RelationalValueSource> 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<JaxbKeyPropertyElement> keyPropertyElementList;
private final List<JaxbKeyManyToOneElement> keyManyToOneElementList;
public EmbeddableJaxbSourceImpl(JaxbCompositeIdElement compositeIdElement) {
this.compositeIdElement = compositeIdElement;
this.keyPropertyElementList = new ArrayList<JaxbKeyPropertyElement>();
this.keyManyToOneElementList = new ArrayList<JaxbKeyManyToOneElement>();
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<JaxbKeyPropertyElement> getKeyPropertyElementList() {
return keyPropertyElementList;
}
@Override
public List<JaxbKeyManyToOneElement> getKeyManyToOneElementList() {
return keyManyToOneElementList;
}
}
private Class determineJpaIdClass() {
// this would be a <composite-id/> defined with mapped="false"
final JaxbCompositeIdElement compositeId = entityElement().getCompositeId();

View File

@ -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 <T>
* @param <T> Generic type of values to coalesce
*
* @return The first non-empty value, or null if all values were empty
*/

View File

@ -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<RelationalValueSource> 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<JaxbColumnElement> 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<String, String> 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;
}
}
}

View File

@ -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

View File

@ -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

View File

@ -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 <key-property/>} 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<RelationalValueSource> 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

View File

@ -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<RelationalValueSource> 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

View File

@ -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;
}
}

View File

@ -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<RelationalValueSource> 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

Some files were not shown because too many files have changed in this diff Show More