HHH-6515 HHH-6516 : Support for map key annotations

This commit is contained in:
Gail Badner 2013-05-30 13:43:23 -07:00
parent 2ad468ea73
commit 3244caa6cd
36 changed files with 979 additions and 319 deletions

View File

@ -131,6 +131,7 @@ import org.hibernate.metamodel.spi.source.CompositePluralAttributeIndexSource;
import org.hibernate.metamodel.spi.source.ConstraintSource;
import org.hibernate.metamodel.spi.source.DerivedValueSource;
import org.hibernate.metamodel.spi.source.DiscriminatorSource;
import org.hibernate.metamodel.spi.source.EntityAttributePluralAttributeIndexSource;
import org.hibernate.metamodel.spi.source.EntityHierarchy;
import org.hibernate.metamodel.spi.source.EntitySource;
import org.hibernate.metamodel.spi.source.FilterSource;
@ -233,10 +234,11 @@ public class Binder {
* @param entityHierarchies The entity hierarchies resolved from mappings
*/
public void addEntityHierarchies(final Iterable<EntityHierarchy> entityHierarchies) {
LocalBindingContextExecutor executor = new LocalBindingContextExecutor() {
@Override
public void execute(LocalBindingContextExecutionContext bindingContextContext) {
sourceIndex.indexEntitySource( bindingContextContext.getEntitySource() );
sourceIndex.indexEntitySource( bindingContextContext.getRootEntitySource(), bindingContextContext.getEntitySource() );
createEntityBinding(
bindingContextContext.getSuperEntityBinding(),
bindingContextContext.getEntitySource()
@ -2031,6 +2033,13 @@ public class Binder {
}
}
private void bindEntityAttributePluralAttributeIndex(
final IndexedPluralAttributeBinding attributeBinding,
final EntityAttributePluralAttributeIndexSource indexSource,
final String defaultIndexJavaTypeName) {
throw new NotYetImplementedException( "Plural attribute index that is an attribute of the referenced entity is not supported yet." );
}
private void bindBasicCollectionIndex(
final IndexedPluralAttributeBinding attributeBinding,
final BasicPluralAttributeIndexSource indexSource,
@ -2053,7 +2062,7 @@ public class Binder {
typeHelper.bindHibernateTypeDescriptor(
indexBinding.getHibernateTypeDescriptor(),
indexSource.explicitHibernateTypeSource(),
indexSource.getTypeInformation(),
defaultIndexJavaTypeName
);
typeHelper.bindJdbcDataType(
@ -2069,9 +2078,11 @@ public class Binder {
private void bindCompositeCollectionIndex(
final CompositePluralAttributeIndexBinding indexBinding,
final CompositePluralAttributeIndexSource indexSource,
final IndexedPluralAttributeSource indexedPluralAttributeSource,
final String defaultIndexJavaTypeName) {
final PluralAttributeBinding pluralAttributeBinding = indexBinding.getIndexedPluralAttributeBinding();
final CompositePluralAttributeIndexSource indexSource =
(CompositePluralAttributeIndexSource) indexedPluralAttributeSource.getIndexSource();
ValueHolder<Class<?>> defaultElementJavaClassReference = null;
// Create the aggregate type
// TODO: aggregateName should be set to elementSource.getPath() (which is currently not implemented)
@ -2105,6 +2116,19 @@ public class Binder {
);
bindAttributes( compositeAttributeBindingContainer, indexSource );
/*
final boolean isAssociation = pluralAttributeBinding.getPluralAttributeElementBinding().getNature().isAssociation();
switch( pluralAttributeBinding.getPluralAttributeElementBinding().getNature() ) {
case ONE_TO_MANY:
OneToManyPluralAttributeElementSource elementSource =
(OneToManyPluralAttributeElementSource) indexedPluralAttributeSource.getElementSource();
final EntityBinding referencedEntityBinding = locateEntityBinding( elementSource.getReferencedEntityName() );
for ( final AttributeSource attributeSource : indexSource.attributeSources() ) {
bindAttribute( compositeAttributeBindingContainer, attributeSource );
}
}
*/
Type resolvedType = metadata.getTypeResolver().getTypeFactory().component(
new ComponentMetamodel( compositeAttributeBindingContainer, false, false )
);
@ -2331,6 +2355,15 @@ public class Binder {
final ReflectedCollectionJavaTypes reflectedCollectionJavaTypes) {
final String defaultCollectionIndexJavaTypeName =
HibernateTypeHelper.defaultCollectionIndexJavaTypeName( reflectedCollectionJavaTypes );
final PluralAttributeIndexSource indexSource = attributeSource.getIndexSource();
if ( indexSource.isReferencedEntityAttribute() ) {
bindEntityAttributePluralAttributeIndex(
attributeBinding,
(EntityAttributePluralAttributeIndexSource) indexSource,
defaultCollectionIndexJavaTypeName
);
}
else {
switch ( attributeSource.getIndexSource().getNature() ) {
case BASIC: {
bindBasicCollectionIndex(
@ -2343,7 +2376,7 @@ public class Binder {
case AGGREGATE: {
bindCompositeCollectionIndex(
(CompositePluralAttributeIndexBinding) attributeBinding.getPluralAttributeIndexBinding(),
(CompositePluralAttributeIndexSource) attributeSource.getIndexSource(),
attributeSource,
defaultCollectionIndexJavaTypeName
);
break;
@ -2368,6 +2401,7 @@ public class Binder {
}
}
}
}
private void bindPluralAggregateAttribute(
final PluralAttributeSource attributeSource,
@ -3240,9 +3274,8 @@ public class Binder {
private static void bindIndexedCollectionTablePrimaryKey(
final IndexedPluralAttributeBinding attributeBinding) {
final PrimaryKey primaryKey = attributeBinding.getPluralAttributeKeyBinding()
.getCollectionTable()
.getPrimaryKey();
final TableSpecification collectionTable = attributeBinding.getPluralAttributeKeyBinding().getCollectionTable();
final PrimaryKey primaryKey = collectionTable.getPrimaryKey();
final List<RelationalValueBinding> keyRelationalValueBindings =
attributeBinding.getPluralAttributeKeyBinding().getRelationalValueBindings();
final PluralAttributeIndexBinding indexBinding = attributeBinding.getPluralAttributeIndexBinding();
@ -3250,7 +3283,7 @@ public class Binder {
primaryKey.addColumn( (Column) keyRelationalValueBinding.getValue() );
}
for ( RelationalValueBinding relationalValueBinding : indexBinding.getRelationalValueBindings() ) {
if ( !relationalValueBinding.isDerived() ) {
if ( !relationalValueBinding.isDerived() && relationalValueBinding.getTable().equals( collectionTable ) ) {
primaryKey.addColumn( (Column) relationalValueBinding.getValue() );
}
}

View File

@ -92,6 +92,7 @@ public class EntityHierarchyHelper {
applyToSubEntities(
executionContext.getEntityBinding(),
rootEntitySource,
rootEntitySource,
subEntityExecutor );
}
}
@ -127,27 +128,28 @@ public class EntityHierarchyHelper {
bindingContexts.push( rootEntitySource.getLocalBindingContext() );
}
private void applyToSubEntities(
final EntityBinding entityBinding,
final RootEntitySource rootEntitySource,
final EntitySource entitySource,
final LocalBindingContextExecutor subEntityExecutor) {
for ( final SubclassEntitySource subEntitySource : entitySource.subclassEntitySources() ) {
applyToSubEntity( entityBinding, subEntitySource, subEntityExecutor );
applyToSubEntity( entityBinding, rootEntitySource, subEntitySource, subEntityExecutor );
}
}
private void applyToSubEntity(
final EntityBinding superEntityBinding,
final RootEntitySource rootEntitySource,
final EntitySource entitySource,
final LocalBindingContextExecutor subEntityExecutor) {
final LocalBindingContext bindingContext = entitySource.getLocalBindingContext();
bindingContexts.push( bindingContext );
try {
LocalBindingContextExecutionContext executionContext =
new LocalBindingContextExecutionContextImpl( entitySource, superEntityBinding );
new LocalBindingContextExecutionContextImpl( rootEntitySource, entitySource, superEntityBinding );
subEntityExecutor.execute( executionContext );
applyToSubEntities( executionContext.getEntityBinding(), entitySource, subEntityExecutor );
applyToSubEntities( executionContext.getEntityBinding(), rootEntitySource, entitySource, subEntityExecutor );
}
finally {
bindingContexts.pop();
@ -155,22 +157,38 @@ public class EntityHierarchyHelper {
}
public interface LocalBindingContextExecutionContext {
RootEntitySource getRootEntitySource();
EntitySource getEntitySource();
EntityBinding getEntityBinding();
EntityBinding getSuperEntityBinding();
}
private class LocalBindingContextExecutionContextImpl implements LocalBindingContextExecutionContext {
private final RootEntitySource rootEntitySource;
private final EntitySource entitySource;
private final EntityBinding superEntityBinding;
private LocalBindingContextExecutionContextImpl(
RootEntitySource rootEntitySource,
EntityBinding superEntityBinding) {
this.rootEntitySource = rootEntitySource;
this.entitySource = rootEntitySource;
this.superEntityBinding = superEntityBinding;
}
private LocalBindingContextExecutionContextImpl(
RootEntitySource rootEntitySource,
EntitySource entitySource,
EntityBinding superEntityBinding) {
this.rootEntitySource = rootEntitySource;
this.entitySource = entitySource;
this.superEntityBinding = superEntityBinding;
}
@Override
public RootEntitySource getRootEntitySource() {
return rootEntitySource;
}
@Override
public EntitySource getEntitySource() {
return entitySource;

View File

@ -39,11 +39,12 @@ import org.hibernate.metamodel.spi.binding.EntityBinding;
import org.hibernate.metamodel.spi.relational.Column;
import org.hibernate.metamodel.spi.source.AggregatedCompositeIdentifierSource;
import org.hibernate.metamodel.spi.source.AttributeSource;
import org.hibernate.metamodel.spi.source.AttributeSourceResolutionContext;
import org.hibernate.metamodel.spi.source.ComponentAttributeSource;
import org.hibernate.metamodel.spi.source.EntitySource;
import org.hibernate.metamodel.spi.source.IdentifierSource;
import org.hibernate.metamodel.spi.source.IndexedPluralAttributeSource;
import org.hibernate.metamodel.spi.source.NonAggregatedCompositeIdentifierSource;
import org.hibernate.metamodel.spi.source.PluralAttributeElementSourceResolver;
import org.hibernate.metamodel.spi.source.PluralAttributeSource;
import org.hibernate.metamodel.spi.source.RootEntitySource;
import org.hibernate.metamodel.spi.source.SimpleIdentifierSource;
@ -66,9 +67,13 @@ public class SourceIndex {
private final Map<AttributeSourceKey, AttributeSourceKey> mappedByAttributeKeysByOwnerAttributeKeys =
new HashMap<AttributeSourceKey, AttributeSourceKey>();
public void indexEntitySource(final EntitySource entitySource) {
public void indexRootEntitySource(final RootEntitySource entitySource) {
indexEntitySource( entitySource, entitySource );
}
public void indexEntitySource(final RootEntitySource rootEntitySource, final EntitySource entitySource) {
String entityName = entitySource.getEntityName();
EntitySourceIndex entitySourceIndex = new EntitySourceIndex( this, entitySource );
EntitySourceIndex entitySourceIndex = new EntitySourceIndex( this, rootEntitySource, entitySource );
entitySourceIndexByEntityName.put( entityName, entitySourceIndex );
log.debugf( "Mapped entity source \"%s\"", entityName );
indexAttributes( entitySourceIndex );
@ -106,6 +111,10 @@ public class SourceIndex {
return entitySourceIndexByEntityName.get( entityName ).entitySource;
}
private EntitySourceIndex entitySourceIndex(String entityName) {
return entitySourceIndexByEntityName.get( entityName );
}
private void indexAttributes(EntitySourceIndex entitySourceIndex) {
final String emptyString = "";
if ( entitySourceIndex.entitySource instanceof RootEntitySource ) {
@ -267,6 +276,7 @@ public class SourceIndex {
private static class EntitySourceIndex {
private final SourceIndex sourceIndex;
private final RootEntitySource rootEntitySource;
private final EntitySource entitySource;
private final Map<SingularAttributeSource.Nature, Map<AttributeSourceKey, SingularAttributeSource>> identifierAttributeSourcesByNature =
new HashMap<SingularAttributeSource.Nature, Map<AttributeSourceKey, SingularAttributeSource>>();
@ -281,8 +291,16 @@ public class SourceIndex {
private final Map<AttributeSourceKey, PluralAttributeSource> inversePluralAttributeSourcesByKey =
new LinkedHashMap<AttributeSourceKey, PluralAttributeSource>();
private EntitySourceIndex(final SourceIndex sourceIndex, final EntitySource entitySource) {
private EntitySourceIndex(final SourceIndex sourceIndex, final RootEntitySource rootEntitySource) {
this( sourceIndex, rootEntitySource, rootEntitySource );
}
private EntitySourceIndex(
final SourceIndex sourceIndex,
final RootEntitySource rootEntitySource,
final EntitySource entitySource) {
this.sourceIndex = sourceIndex;
this.rootEntitySource = rootEntitySource;
this.entitySource = entitySource;
}
@ -375,12 +393,20 @@ public class SourceIndex {
// so it needs to be resolved.
// TODO: this should really just resolve PluralAttributeElementSource.Nature
pluralAttributeSource.resolvePluralAttributeElementSource(
new PluralAttributeElementSourceResolver.PluralAttributeElementSourceResolutionContext() {
new AttributeSourceResolutionContext() {
@Override
public IdentifierSource resolveIdentifierSource(String entityName) {
return sourceIndex.entitySourceIndex( entityName ).rootEntitySource.getIdentifierSource();
}
@Override
public AttributeSource resolveAttributeSource(String referencedEntityName, String mappedBy) {
AttributeSourceKey ownerAttributeSourceKey = new AttributeSourceKey( referencedEntityName, mappedBy );
AttributeSource ownerAttributeSource = sourceIndex.attributeSource( referencedEntityName, mappedBy );
// TODO: is this needed? if so, make more obvious and rename method.
// If it's not needed, then resolvePluralAttributeElementSource() and
// and resolvePluralAttributeIndexSource() can use the same
// AttributeSourceResolutionContext.
sourceIndex.addMappedByAssociationByOwnerAssociation(
ownerAttributeSourceKey,
pluralAttributeSourceKey
@ -390,7 +416,47 @@ public class SourceIndex {
}
);
}
if ( IndexedPluralAttributeSource.class.isInstance( pluralAttributeSource ) ) {
IndexedPluralAttributeSource indexedPluralAttributeSource =
(IndexedPluralAttributeSource) pluralAttributeSource;
indexedPluralAttributeSource.resolvePluralAttributeIndexSource(
new AttributeSourceResolutionContext() {
@Override
public IdentifierSource resolveIdentifierSource(String entityName) {
return sourceIndex.entitySourceIndex( entityName ).rootEntitySource.getIdentifierSource();
}
@Override
public AttributeSource resolveAttributeSource(String referencedEntityName, String mappedBy) {;
return sourceIndex.attributeSource( referencedEntityName, mappedBy );
}
}
);
}
}
for ( Map.Entry<AttributeSourceKey,PluralAttributeSource> entry : nonInversePluralAttributeSourcesByKey.entrySet() ) {
final AttributeSourceKey pluralAttributeSourceKey = entry.getKey();
final PluralAttributeSource pluralAttributeSource = entry.getValue();
if ( IndexedPluralAttributeSource.class.isInstance( pluralAttributeSource ) ) {
IndexedPluralAttributeSource indexedPluralAttributeSource =
(IndexedPluralAttributeSource) pluralAttributeSource;
indexedPluralAttributeSource.resolvePluralAttributeIndexSource(
new AttributeSourceResolutionContext() {
@Override
public IdentifierSource resolveIdentifierSource(String entityName) {
return sourceIndex.entitySourceIndex( entityName ).rootEntitySource.getIdentifierSource();
}
@Override
public AttributeSource resolveAttributeSource(String referencedEntityName, String mappedBy) {;
return sourceIndex.attributeSource( referencedEntityName, mappedBy );
}
}
);
}
}
final Map<AttributeSourceKey,SingularAttributeSource> unresolvedSingularAttributeSourceMap =
singularAttributeSourcesByNature.get( null );
if ( unresolvedSingularAttributeSourceMap != null ) {

View File

@ -0,0 +1,80 @@
/*
* 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.internal.source.annotations;
import java.util.Map;
import org.hibernate.metamodel.internal.source.annotations.attribute.PluralAssociationAttribute;
import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource;
import org.hibernate.metamodel.spi.source.PluralAttributeIndexSource;
/**
* @author Gail Badner
*/
public abstract class AbstractPluralAttributeIndexSourceImpl implements PluralAttributeIndexSource {
private final PluralAssociationAttribute attribute;
public AbstractPluralAttributeIndexSourceImpl(PluralAssociationAttribute attribute) {
this.attribute = attribute;
}
@Override
public ExplicitHibernateTypeSource getTypeInformation() {
return new ExplicitHibernateTypeSource() {
@Override
public String getName() {
return attribute.getIndexTypeResolver().getExplicitHibernateTypeName();
}
@Override
public Map<String, String> getParameters() {
return attribute.getIndexTypeResolver().getExplicitHibernateTypeParameters();
}
};
}
@Override
public boolean isReferencedEntityAttribute() {
return false;
}
@Override
public boolean areValuesIncludedInInsertByDefault() {
return false;
}
@Override
public boolean areValuesIncludedInUpdateByDefault() {
return false;
}
@Override
public boolean areValuesNullableByDefault() {
return false;
}
protected PluralAssociationAttribute pluralAssociationAttribute() {
return attribute;
}
}

View File

@ -3,7 +3,6 @@ package org.hibernate.metamodel.internal.source.annotations;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.metamodel.internal.source.annotations.attribute.AssociationAttribute;
import org.hibernate.metamodel.internal.source.annotations.attribute.Column;
import org.hibernate.metamodel.internal.source.annotations.attribute.MappedAttribute;
import org.hibernate.metamodel.internal.source.annotations.attribute.PluralAssociationAttribute;

View File

@ -23,10 +23,8 @@
*/
package org.hibernate.metamodel.internal.source.annotations;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.jboss.jandex.AnnotationInstance;
@ -38,23 +36,34 @@ import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames;
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding;
import org.hibernate.metamodel.spi.source.BasicPluralAttributeIndexSource;
import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource;
import org.hibernate.metamodel.spi.source.RelationalValueSource;
/**
* @author Strong Liu <stliu@hibernate.org>
*/
public class BasicPluralAttributeIndexSourceImpl implements BasicPluralAttributeIndexSource {
private final PluralAssociationAttribute attribute;
public class BasicPluralAttributeIndexSourceImpl extends AbstractPluralAttributeIndexSourceImpl implements BasicPluralAttributeIndexSource {
private final IndexedPluralAttributeSourceImpl indexedPluralAttributeSource;
private final List<RelationalValueSource> relationalValueSources = new ArrayList<RelationalValueSource>( 1 );
private final List<RelationalValueSource> relationalValueSources;
private final Binder.DefaultNamingStrategy defaultNamingStrategy;
public BasicPluralAttributeIndexSourceImpl(
IndexedPluralAttributeSourceImpl indexedPluralAttributeSource,
PluralAssociationAttribute attribute,
Binder.DefaultNamingStrategy defaultNamingStrategy) {
this.attribute = attribute;
this( indexedPluralAttributeSource, attribute, defaultNamingStrategy, createRelationalValueSources( attribute ) );
}
public BasicPluralAttributeIndexSourceImpl(
IndexedPluralAttributeSourceImpl indexedPluralAttributeSource,
PluralAssociationAttribute attribute,
Binder.DefaultNamingStrategy defaultNamingStrategy,
List<RelationalValueSource> relationalValueSources) {
super( attribute );
this.indexedPluralAttributeSource = indexedPluralAttributeSource;
this.relationalValueSources = relationalValueSources;
this.defaultNamingStrategy = defaultNamingStrategy;
}
private static List<RelationalValueSource> createRelationalValueSources(PluralAssociationAttribute attribute) {
AnnotationInstance columnAnnotation = JandexHelper.getSingleAnnotation(
attribute.annotations(),
HibernateDotNames.INDEX_COLUMN
@ -72,10 +81,8 @@ public class BasicPluralAttributeIndexSourceImpl implements BasicPluralAttribute
);
}
Column indexColumn = new Column( columnAnnotation );
relationalValueSources.add( new ColumnValuesSourceImpl( indexColumn ) );
this.defaultNamingStrategy = defaultNamingStrategy;
return Collections.singletonList( (RelationalValueSource) new ColumnValuesSourceImpl( indexColumn ) );
}
@Override
public PluralAttributeIndexBinding.Nature getNature() {
return PluralAttributeIndexBinding.Nature.BASIC;
@ -86,38 +93,9 @@ public class BasicPluralAttributeIndexSourceImpl implements BasicPluralAttribute
return Collections.singletonList( defaultNamingStrategy );
}
@Override
public ExplicitHibernateTypeSource explicitHibernateTypeSource() {
return new ExplicitHibernateTypeSource() {
@Override
public String getName() {
return "integer";
}
@Override
public Map<String, String> getParameters() {
return null;
}
};
}
@Override
public List<RelationalValueSource> relationalValueSources() {
return relationalValueSources;
}
@Override
public boolean areValuesIncludedInInsertByDefault() {
return false;
}
@Override
public boolean areValuesIncludedInUpdateByDefault() {
return false;
}
@Override
public boolean areValuesNullableByDefault() {
return false;
}
}

View File

@ -26,27 +26,30 @@ package org.hibernate.metamodel.internal.source.annotations;
import java.util.EnumSet;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.JandexAntTask;
import org.hibernate.cfg.NamingStrategy;
import org.hibernate.cfg.NotYetImplementedException;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.metamodel.internal.Binder;
import org.hibernate.metamodel.internal.source.annotations.attribute.MappedAttribute;
import org.hibernate.metamodel.internal.source.annotations.attribute.PluralAssociationAttribute;
import org.hibernate.metamodel.internal.source.annotations.entity.ConfiguredClass;
import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames;
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
import org.hibernate.metamodel.spi.source.AttributeSource;
import org.hibernate.metamodel.spi.source.AttributeSourceResolutionContext;
import org.hibernate.metamodel.spi.source.ComponentAttributeSource;
import org.hibernate.metamodel.spi.source.IdentifierSource;
import org.hibernate.metamodel.spi.source.IndexedPluralAttributeSource;
import org.hibernate.metamodel.spi.source.MappingException;
import org.hibernate.metamodel.spi.source.PluralAttributeIndexSource;
import org.hibernate.metamodel.spi.source.SimpleIdentifierSource;
import org.hibernate.metamodel.spi.source.SingularAttributeSource;
/**
* @author Strong Liu <stliu@hibernate.org>
*/
public class IndexedPluralAttributeSourceImpl extends PluralAttributeSourceImpl
implements IndexedPluralAttributeSource {
private final PluralAttributeIndexSource indexSource;
private PluralAttributeIndexSource indexSource;
private final static EnumSet<MappedAttribute.Nature> VALID_NATURES = EnumSet.of(
MappedAttribute.Nature.MANY_TO_MANY,
MappedAttribute.Nature.ONE_TO_MANY,
@ -74,8 +77,8 @@ public class IndexedPluralAttributeSourceImpl extends PluralAttributeSourceImpl
indexSource = new SequentialPluralAttributeIndexSourceImpl( this, attribute, defaultNamingStrategy );
}
else if ( attribute.annotations().containsKey( JPADotNames.MAP_KEY ) ) {
// basic
throw new NotYetImplementedException( "@MapKey is not supported yet." );
// need to wait until the ID or attribute source can be resolved.
indexSource = null;
}
else if ( attribute.annotations().containsKey( JPADotNames.MAP_KEY_COLUMN ) ) {
final Binder.DefaultNamingStrategy defaultNamingStrategy = new Binder.DefaultNamingStrategy() {
@ -130,6 +133,78 @@ public class IndexedPluralAttributeSourceImpl extends PluralAttributeSourceImpl
}
}
@Override
public PluralAttributeIndexSource resolvePluralAttributeIndexSource(AttributeSourceResolutionContext attributeSourceResolutionContext) {
if ( indexSource == null ) {
if ( pluralAssociationAttribute().annotations().containsKey( JPADotNames.MAP_KEY ) ) {
indexSource = resolveMapKeyPluralAttributeIndexSource( attributeSourceResolutionContext );
}
else {
throw new NotYetImplementedException( "caonnot resolve index source." );
}
}
return indexSource;
}
private PluralAttributeIndexSource resolveMapKeyPluralAttributeIndexSource(AttributeSourceResolutionContext attributeSourceResolutionContext) {
final AnnotationInstance mapKeyAnnotation =
JandexHelper.getSingleAnnotation( pluralAssociationAttribute().annotations(), JPADotNames.MAP_KEY );
final String attributeName = JandexHelper.getValue( mapKeyAnnotation, "name", String.class );
final PluralAttributeIndexSource innerIndexSource;
if ( attributeName == null ) {
IdentifierSource identifierSource = attributeSourceResolutionContext.resolveIdentifierSource(
pluralAssociationAttribute().getReferencedEntityType()
);
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().getReferencedEntityType(),
attributeName
);
if ( ! attributeSource.isSingular() ) {
throw new MappingException(
String.format(
"Plural attribute index [%s.%s] is not a singular attribute.",
pluralAssociationAttribute().getReferencedEntityType(),
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

@ -0,0 +1,76 @@
/*
* 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.internal.source.annotations;
import java.util.List;
import org.hibernate.metamodel.internal.Binder;
import org.hibernate.metamodel.internal.source.annotations.attribute.PluralAssociationAttribute;
import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding;
import org.hibernate.metamodel.spi.source.AttributeSource;
import org.hibernate.metamodel.spi.source.EntityAttributePluralAttributeIndexSource;
import org.hibernate.metamodel.spi.source.PluralAttributeIndexSource;
import org.hibernate.metamodel.spi.source.RelationalValueSource;
/**
* @author Gail Badner
*/
public class MapKeyPluralAttributeIndexSourceImpl extends AbstractPluralAttributeIndexSourceImpl implements EntityAttributePluralAttributeIndexSource {
private final PluralAttributeIndexSource pluralAttributeIndexSource;
private final String attributeName;
public MapKeyPluralAttributeIndexSourceImpl(
PluralAssociationAttribute attribute,
PluralAttributeIndexSource pluralAttributeIndexSource,
String attributeName) {
super( attribute );
this.pluralAttributeIndexSource = pluralAttributeIndexSource;
this.attributeName = attributeName;
}
@Override
public String getAttributeName() {
return attributeName;
}
@Override
public PluralAttributeIndexBinding.Nature getNature() {
return pluralAttributeIndexSource.getNature();
}
@Override
public List<Binder.DefaultNamingStrategy> getDefaultNamingStrategies() {
return pluralAttributeIndexSource.getDefaultNamingStrategies();
}
@Override
public boolean isReferencedEntityAttribute() {
return true;
}
@Override
public List<RelationalValueSource> relationalValueSources() {
return pluralAttributeIndexSource.relationalValueSources();
}
}

View File

@ -41,6 +41,7 @@ import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
import org.hibernate.metamodel.spi.binding.Caching;
import org.hibernate.metamodel.spi.binding.CustomSQL;
import org.hibernate.metamodel.spi.source.AttributeSource;
import org.hibernate.metamodel.spi.source.AttributeSourceResolutionContext;
import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource;
import org.hibernate.metamodel.spi.source.FilterSource;
import org.hibernate.metamodel.spi.source.MetaAttributeSource;
@ -352,7 +353,7 @@ public class PluralAttributeSourceImpl implements PluralAttributeSource, Orderab
@Override
public PluralAttributeElementSource resolvePluralAttributeElementSource(
PluralAttributeElementSourceResolutionContext context) {
AttributeSourceResolutionContext context) {
if ( elementSource == null ) {
// elementSource has not been initialized, so we need to resolve it using the
// association owner.
@ -366,6 +367,10 @@ public class PluralAttributeSourceImpl implements PluralAttributeSource, Orderab
}
return elementSource;
}
protected PluralAssociationAttribute pluralAssociationAttribute() {
return associationAttribute;
}
}

View File

@ -23,6 +23,9 @@
*/
package org.hibernate.metamodel.internal.source.annotations;
import java.util.Collections;
import java.util.Map;
import org.jboss.jandex.AnnotationInstance;
import org.hibernate.metamodel.internal.Binder;
@ -30,6 +33,7 @@ import org.hibernate.metamodel.internal.source.annotations.attribute.PluralAssoc
import org.hibernate.metamodel.internal.source.annotations.util.HibernateDotNames;
import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames;
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource;
import org.hibernate.metamodel.spi.source.SequentialPluralAttributeIndexSource;
/**
@ -62,4 +66,18 @@ public class SequentialPluralAttributeIndexSourceImpl
public int base() {
return base;
}
@Override
public ExplicitHibernateTypeSource getTypeInformation() {
return new ExplicitHibernateTypeSource() {
@Override
public String getName() {
return "integer";
}
@Override
public Map<String, String> getParameters() {
return Collections.emptyMap();
}
};
}
}

View File

@ -37,7 +37,6 @@ import org.jboss.jandex.AnnotationTarget;
import org.jboss.jandex.AnnotationValue;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.jandex.Index;
import org.jboss.jandex.IndexView;
import org.jboss.logging.Logger;
@ -50,7 +49,7 @@ import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.mapping.PropertyGeneration;
import org.hibernate.metamodel.internal.source.annotations.attribute.type.AttributeTypeResolver;
import org.hibernate.metamodel.internal.source.annotations.attribute.type.AttributeTypeResolverImpl;
import org.hibernate.metamodel.internal.source.annotations.attribute.type.HibernateTypeResolver;
import org.hibernate.metamodel.internal.source.annotations.attribute.type.CompositeAttributeTypeResolver;
import org.hibernate.metamodel.internal.source.annotations.entity.EntityBindingContext;
import org.hibernate.metamodel.internal.source.annotations.util.EnumConversionHelper;
@ -275,8 +274,11 @@ public class AssociationAttribute extends MappedAttribute {
return PropertyGeneration.NEVER;
}
private AttributeTypeResolver getDefaultHibernateTypeResolver() {
return new CompositeAttributeTypeResolver( this, new AttributeTypeResolverImpl( this ) );
protected AttributeTypeResolver getDefaultHibernateTypeResolver() {
return new CompositeAttributeTypeResolver(
this,
HibernateTypeResolver.createAttributeTypeResolver( this )
);
}
private boolean determineNotFoundBehavior() {

View File

@ -43,7 +43,7 @@ import org.hibernate.internal.util.StringHelper;
import org.hibernate.mapping.PropertyGeneration;
import org.hibernate.metamodel.internal.source.annotations.IdentifierGeneratorSourceContainer;
import org.hibernate.metamodel.internal.source.annotations.attribute.type.AttributeTypeResolver;
import org.hibernate.metamodel.internal.source.annotations.attribute.type.AttributeTypeResolverImpl;
import org.hibernate.metamodel.internal.source.annotations.attribute.type.HibernateTypeResolver;
import org.hibernate.metamodel.internal.source.annotations.attribute.type.CompositeAttributeTypeResolver;
import org.hibernate.metamodel.internal.source.annotations.attribute.type.EnumeratedTypeResolver;
import org.hibernate.metamodel.internal.source.annotations.attribute.type.LobTypeResolver;
@ -422,10 +422,10 @@ public class BasicAttribute extends MappedAttribute {
private AttributeTypeResolver getDefaultHibernateTypeResolver() {
CompositeAttributeTypeResolver resolver = new CompositeAttributeTypeResolver( this );
resolver.addHibernateTypeResolver( new AttributeTypeResolverImpl( this ) );
resolver.addHibernateTypeResolver( new TemporalTypeResolver( this ) );
resolver.addHibernateTypeResolver( new LobTypeResolver( this ) );
resolver.addHibernateTypeResolver( new EnumeratedTypeResolver( this ) );
resolver.addHibernateTypeResolver( HibernateTypeResolver.createAttributeTypeResolver( this ) );
resolver.addHibernateTypeResolver( TemporalTypeResolver.createAttributeTypeResolver( this ) );
resolver.addHibernateTypeResolver( LobTypeResolver.createAttributeTypeResolve( this ) );
resolver.addHibernateTypeResolver( EnumeratedTypeResolver.createAttributeTypeResolver( this ) );
return resolver;
}
}

View File

@ -36,7 +36,6 @@ import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.hibernate.AssertionFailure;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.LazyCollectionOption;
@ -44,7 +43,7 @@ import org.hibernate.annotations.OnDeleteAction;
import org.hibernate.annotations.SortType;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.metamodel.internal.source.annotations.attribute.type.AttributeTypeResolver;
import org.hibernate.metamodel.internal.source.annotations.attribute.type.AttributeTypeResolverImpl;
import org.hibernate.metamodel.internal.source.annotations.attribute.type.HibernateTypeResolver;
import org.hibernate.metamodel.internal.source.annotations.attribute.type.CompositeAttributeTypeResolver;
import org.hibernate.metamodel.internal.source.annotations.attribute.type.EnumeratedTypeResolver;
import org.hibernate.metamodel.internal.source.annotations.attribute.type.LobTypeResolver;
@ -95,6 +94,8 @@ public class PluralAssociationAttribute extends AssociationAttribute {
private final boolean mutable;
private final int batchSize;
private AttributeTypeResolver elementTypeResolver;
private AttributeTypeResolver indexTypeResolver;
public static PluralAssociationAttribute createPluralAssociationAttribute(
ClassInfo entityClassInfo,
@ -541,18 +542,38 @@ public class PluralAssociationAttribute extends AssociationAttribute {
return mutable;
}
/*
@Override
public AttributeTypeResolver getHibernateTypeResolver() {
if ( elementTypeResolver == null ) {
elementTypeResolver = getDefaultElementHibernateTypeResolver();
}
return elementTypeResolver;
}
private AttributeTypeResolver getDefaultElementHibernateTypeResolver() {
CompositeAttributeTypeResolver resolver = new CompositeAttributeTypeResolver( this );
resolver.addHibernateTypeResolver( new AttributeTypeResolverImpl( this ) );
// TODO: make it work for temporal elements
//resolver.addHibernateTypeResolver( new TemporalTypeResolver( this ) );
resolver.addHibernateTypeResolver( new LobTypeResolver( this ) );
resolver.addHibernateTypeResolver( new EnumeratedTypeResolver( this ) );
resolver.addHibernateTypeResolver( HibernateTypeResolver.createCollectionElementTypeResolver( this ) );
resolver.addHibernateTypeResolver( TemporalTypeResolver.createCollectionElementTypeResolver( this ) );
resolver.addHibernateTypeResolver( LobTypeResolver.createCollectionElementTypeResolve( this ) );
resolver.addHibernateTypeResolver( EnumeratedTypeResolver.createCollectionElementTypeResolver( this ) );
return resolver;
}
*/
public AttributeTypeResolver getIndexTypeResolver() {
if ( indexType == null ) {
return getDefaultHibernateTypeResolver();
}
else if ( indexTypeResolver == null ) {
CompositeAttributeTypeResolver resolver = new CompositeAttributeTypeResolver( this );
final String name = getName() + ".index";
resolver.addHibernateTypeResolver( HibernateTypeResolver.createCollectionIndexTypeResolver( this ) );
// TODO: Lob allowed as collection index? I don't see an annotation for that.
resolver.addHibernateTypeResolver( EnumeratedTypeResolver.createCollectionIndexTypeResolver( this ) );
resolver.addHibernateTypeResolver( TemporalTypeResolver.createCollectionIndexTypeResolver( this ) );
indexTypeResolver = resolver;
}
return indexTypeResolver;
}
}

View File

@ -26,24 +26,38 @@ package org.hibernate.metamodel.internal.source.annotations.attribute.type;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.DotName;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.metamodel.internal.source.annotations.attribute.MappedAttribute;
import org.hibernate.metamodel.internal.source.annotations.entity.EntityBindingContext;
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
import org.hibernate.usertype.DynamicParameterizedType;
/**
* @author Strong Liu
* @author Brett Meyer
* @author Gail Badner
*/
public abstract class AbstractAttributeTypeResolver implements AttributeTypeResolver {
protected final MappedAttribute mappedAttribute;
private final String name;
private final Class<?> javaClass;
private final AnnotationInstance annotation;
private final EntityBindingContext context;
public AbstractAttributeTypeResolver( MappedAttribute mappedAttribute ) {
this.mappedAttribute = mappedAttribute;
public AbstractAttributeTypeResolver(
String name,
Class<?> javaClass,
AnnotationInstance annotation,
EntityBindingContext context){
this.name = name;
this.javaClass = javaClass;
this.annotation = annotation;
this.context = context;
}
@Override
@ -54,42 +68,60 @@ public abstract class AbstractAttributeTypeResolver implements AttributeTypeReso
if ( !StringHelper.isEmpty( type ) ) {
return type;
} else {
return hasEntityTypeDef() ? mappedAttribute.getAttributeType().getName() : null;
return hasTypeDef() ? javaClass().getName() : null;
}
}
@Override
final public String getExplicitAnnotatedHibernateTypeName() {
return resolveAnnotatedHibernateTypeName(
getTypeDeterminingAnnotationInstance() );
return resolveHibernateTypeName();
}
@Override
final public Map<String, String> getExplicitHibernateTypeParameters() {
Map<String, String> result = new HashMap<String, String>( );
//this is only use by enum type and serializable blob type, but we put there anyway
// TODO: why?
result.put(
DynamicParameterizedType.RETURNED_CLASS,
mappedAttribute.getAttributeType().getName()
javaClass().getName()
);
if ( StringHelper.isNotEmpty( getExplicitHibernateTypeName() ) ) {
result.putAll( resolveHibernateTypeParameters(
getTypeDeterminingAnnotationInstance() ) );
result.putAll( resolveHibernateTypeParameters() );
}
return result;
}
final protected boolean hasEntityTypeDef() {
return mappedAttribute.getContext()
.getMetadataImplementor().hasTypeDefinition(
mappedAttribute.getAttributeType().getName() );
final protected boolean hasTypeDef() {
return context.getMetadataImplementor().hasTypeDefinition(
javaClass().getName()
);
}
protected abstract AnnotationInstance getTypeDeterminingAnnotationInstance();
protected abstract String resolveHibernateTypeName();
protected abstract String resolveAnnotatedHibernateTypeName(AnnotationInstance annotationInstance);
protected Map<String, String> resolveHibernateTypeParameters(AnnotationInstance annotationInstance) {
protected Map<String, String> resolveHibernateTypeParameters() {
return Collections.emptyMap();
}
protected String name() {
return name;
}
protected Class<?> javaClass() {
return javaClass;
}
protected AnnotationInstance annotation() {
return annotation;
}
protected static AnnotationInstance resolveAnnotationInstance(
Map<DotName, List<AnnotationInstance>> annotations,
DotName dotName) {
return JandexHelper.getSingleAnnotation(
annotations,
dotName
);
}
}

View File

@ -1,87 +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.internal.source.annotations.attribute.type;
import java.util.HashMap;
import java.util.Map;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationValue;
import org.hibernate.metamodel.internal.source.annotations.attribute.MappedAttribute;
import org.hibernate.metamodel.internal.source.annotations.util.HibernateDotNames;
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
/**
* Type Resolver which checks {@link org.hibernate.annotations.Type} to find the type info.
*
* @author Strong Liu
* @author Brett Meyer
*/
public class AttributeTypeResolverImpl extends AbstractAttributeTypeResolver {
public AttributeTypeResolverImpl(MappedAttribute mappedAttribute) {
super( mappedAttribute );
}
@Override
protected String resolveAnnotatedHibernateTypeName(AnnotationInstance typeAnnotation) {
if ( typeAnnotation != null ) {
return JandexHelper.getValue(
typeAnnotation, "type", String.class );
}
else {
return null;
}
}
@Override
protected Map<String, String> resolveHibernateTypeParameters(AnnotationInstance typeAnnotation) {
HashMap<String, String> typeParameters = new HashMap<String, String>();
if ( typeAnnotation != null ) {
AnnotationValue parameterAnnotationValue = typeAnnotation.value( "parameters" );
if ( parameterAnnotationValue != null ) {
AnnotationInstance[] parameterAnnotations = parameterAnnotationValue.asNestedArray();
for ( AnnotationInstance parameterAnnotationInstance : parameterAnnotations ) {
typeParameters.put(
JandexHelper.getValue( parameterAnnotationInstance, "name", String.class ),
JandexHelper.getValue( parameterAnnotationInstance, "value", String.class )
);
}
}
}
return typeParameters;
}
@Override
protected AnnotationInstance getTypeDeterminingAnnotationInstance() {
return JandexHelper.getSingleAnnotation(
mappedAttribute.annotations(),
HibernateDotNames.TYPE
);
}
}

View File

@ -34,66 +34,88 @@ import org.hibernate.AnnotationException;
import org.hibernate.AssertionFailure;
import org.hibernate.metamodel.internal.source.annotations.attribute.MappedAttribute;
import org.hibernate.metamodel.internal.source.annotations.attribute.PluralAssociationAttribute;
import org.hibernate.metamodel.internal.source.annotations.entity.EntityBindingContext;
import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames;
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
import org.hibernate.type.EnumType;
import org.hibernate.usertype.DynamicParameterizedType;
/**
* @author Strong Liu
* @author Brett Meyer
* @author Gail Badner
*/
public class EnumeratedTypeResolver extends AbstractAttributeTypeResolver {
private final boolean isMapKey;
private final boolean isEnum;
// private final String attributeType;
private final javax.persistence.EnumType enumType;
public EnumeratedTypeResolver(MappedAttribute mappedAttribute) {
super( mappedAttribute );
isEnum = mappedAttribute.getAttributeType().isEnum();
isMapKey = false;//todo
// attributeType = mappedAttribute.getAttributeType().getName();
}
public EnumeratedTypeResolver(PluralAssociationAttribute pluralAssociationAttribute) {
super( pluralAssociationAttribute );
isEnum = pluralAssociationAttribute.getReferencedAttributeType().isEnum();
isMapKey = false;//todo
// attributeType = pluralAssociationAttribute.getReferencedAttributeType().getName();
}
@Override
protected AnnotationInstance getTypeDeterminingAnnotationInstance() {
return JandexHelper.getSingleAnnotation(
mappedAttribute.annotations(),
JPADotNames.ENUMERATED
public static EnumeratedTypeResolver createAttributeTypeResolver(MappedAttribute attribute) {
return new EnumeratedTypeResolver(
attribute.getName(),
attribute.getAttributeType(),
resolveAnnotationInstance( attribute.annotations(),JPADotNames.ENUMERATED ),
attribute.getContext()
);
}
public static EnumeratedTypeResolver createCollectionElementTypeResolver(
PluralAssociationAttribute pluralAssociationAttribute) {
return new EnumeratedTypeResolver(
pluralAssociationAttribute.getName(),
pluralAssociationAttribute.getReferencedAttributeType(),
resolveAnnotationInstance( pluralAssociationAttribute.annotations(),JPADotNames.ENUMERATED ),
pluralAssociationAttribute.getContext()
);
}
public static EnumeratedTypeResolver createCollectionIndexTypeResolver(
PluralAssociationAttribute pluralAssociationAttribute) {
return new EnumeratedTypeResolver(
pluralAssociationAttribute.getName(),
pluralAssociationAttribute.getIndexType(),
resolveAnnotationInstance( pluralAssociationAttribute.annotations(), JPADotNames.MAP_KEY_ENUMERATED ),
pluralAssociationAttribute.getContext()
);
}
private EnumeratedTypeResolver(
String name,
Class<?> javaClass,
AnnotationInstance annotation,
EntityBindingContext context) {
super( name, javaClass, annotation, context );
this.isEnum = javaClass().isEnum();
this.enumType = annotation == null ?
null :
JandexHelper.getEnumValue( annotation, "value", javax.persistence.EnumType.class );
}
@Override
public String resolveAnnotatedHibernateTypeName(AnnotationInstance enumeratedAnnotation) {
if ( enumeratedAnnotation != null ) {
public String resolveHibernateTypeName() {
if ( annotation() != null ) {
if ( isEnum ) {
return EnumType.class.getName();
} else {
throw new AnnotationException( "Attribute " + mappedAttribute.getName() + " is not a Enumerated type, but has a @Enumerated annotation." );
throw new AnnotationException(
String.format(
"Attribute %s is not a Enumerated type, but has %s or %s annotation.",
name(),
JPADotNames.ENUMERATED,
JPADotNames.MAP_KEY_ENUMERATED
)
);
}
}
else if ( !hasEntityTypeDef() && isEnum ) {
else if ( !hasTypeDef() && isEnum ) {
return EnumType.class.getName();
}
return null;
}
@Override
protected Map<String, String> resolveHibernateTypeParameters(AnnotationInstance annotationInstance) {
protected Map<String, String> resolveHibernateTypeParameters() {
HashMap<String, String> typeParameters = new HashMap<String, String>();
if ( annotationInstance != null ) {
javax.persistence.EnumType enumType = JandexHelper.getEnumValue(
annotationInstance,
"value",
javax.persistence.EnumType.class
);
if ( enumType != null ) {
if ( javax.persistence.EnumType.ORDINAL.equals( enumType ) ) {
typeParameters.put( EnumType.TYPE, String.valueOf( Types.INTEGER ) );
typeParameters.put( EnumType.NAMED, String.valueOf( false ) );

View File

@ -0,0 +1,118 @@
/*
* 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.internal.source.annotations.attribute.type;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationValue;
import org.hibernate.metamodel.internal.source.annotations.attribute.MappedAttribute;
import org.hibernate.metamodel.internal.source.annotations.attribute.PluralAssociationAttribute;
import org.hibernate.metamodel.internal.source.annotations.entity.EntityBindingContext;
import org.hibernate.metamodel.internal.source.annotations.util.HibernateDotNames;
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
/**
* Type Resolver which checks {@link org.hibernate.annotations.Type} to find the type info.
*
* @author Strong Liu
* @author Brett Meyer
* @author Gail Badner
*/
public class HibernateTypeResolver extends AbstractAttributeTypeResolver {
public static HibernateTypeResolver createAttributeTypeResolver(MappedAttribute attribute) {
return new HibernateTypeResolver(
attribute.getName(),
attribute.getAttributeType(),
resolveAnnotationInstance( attribute.annotations(), HibernateDotNames.TYPE ),
attribute.getContext()
);
}
public static HibernateTypeResolver createCollectionElementTypeResolver(
PluralAssociationAttribute pluralAssociationAttribute) {
return new HibernateTypeResolver(
pluralAssociationAttribute.getName(),
pluralAssociationAttribute.getReferencedAttributeType(),
resolveAnnotationInstance( pluralAssociationAttribute.annotations(), HibernateDotNames.TYPE ),
pluralAssociationAttribute.getContext()
);
}
public static HibernateTypeResolver createCollectionIndexTypeResolver(
PluralAssociationAttribute pluralAssociationAttribute) {
final AnnotationInstance annotation = resolveAnnotationInstance(
pluralAssociationAttribute.annotations(),
HibernateDotNames.MAP_KEY_TYPE
);
final AnnotationInstance typeAnnotation = annotation == null ?
null :
JandexHelper.getValue( annotation, "value", AnnotationInstance.class );
return new HibernateTypeResolver(
pluralAssociationAttribute.getName(),
pluralAssociationAttribute.getIndexType(),
typeAnnotation,
pluralAssociationAttribute.getContext()
);
}
private HibernateTypeResolver(
String name,
Class<?> javaClass,
AnnotationInstance annotation,
EntityBindingContext context) {
super( name, javaClass, annotation, context );
}
@Override
protected String resolveHibernateTypeName() {
return annotation() == null ?
null :
JandexHelper.getValue( annotation(), "type", String.class );
}
@Override
protected Map<String, String> resolveHibernateTypeParameters() {
if ( annotation() != null ) {
AnnotationValue parameterAnnotationValue = annotation().value( "parameters" );
if ( parameterAnnotationValue != null ) {
AnnotationInstance[] parameterAnnotations = parameterAnnotationValue.asNestedArray();
final HashMap<String, String> typeParameters = new HashMap<String, String>( parameterAnnotations.length );
for ( AnnotationInstance parameterAnnotationInstance : parameterAnnotations ) {
typeParameters.put(
JandexHelper.getValue( parameterAnnotationInstance, "name", String.class ),
JandexHelper.getValue( parameterAnnotationInstance, "value", String.class )
);
}
return typeParameters;
}
}
return Collections.emptyMap();
}
}

View File

@ -27,14 +27,13 @@ package org.hibernate.metamodel.internal.source.annotations.attribute.type;
import java.io.Serializable;
import java.sql.Blob;
import java.sql.Clob;
import java.util.Collections;
import java.util.Map;
import org.jboss.jandex.AnnotationInstance;
import org.hibernate.metamodel.internal.source.annotations.attribute.MappedAttribute;
import org.hibernate.metamodel.internal.source.annotations.attribute.PluralAssociationAttribute;
import org.hibernate.metamodel.internal.source.annotations.entity.EntityBindingContext;
import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames;
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
import org.hibernate.type.CharacterArrayClobType;
import org.hibernate.type.PrimitiveCharacterArrayClobType;
import org.hibernate.type.SerializableToBlobType;
@ -44,54 +43,65 @@ import org.hibernate.type.WrappedMaterializedBlobType;
/**
* @author Strong Liu
* @author Brett Meyer
* @author Gail Badner
*/
public class LobTypeResolver extends AbstractAttributeTypeResolver {
public static LobTypeResolver createAttributeTypeResolve(MappedAttribute attribute) {
return new LobTypeResolver(
attribute.getName(),
attribute.getAttributeType(),
resolveAnnotationInstance( attribute.annotations(), JPADotNames.LOB ),
attribute.getContext()
);
}
public LobTypeResolver(MappedAttribute mappedAttribute) {
super( mappedAttribute );
public static LobTypeResolver createCollectionElementTypeResolve(PluralAssociationAttribute pluralAssociationAttribute) {
return new LobTypeResolver(
pluralAssociationAttribute.getName(),
pluralAssociationAttribute.getReferencedAttributeType(),
resolveAnnotationInstance( pluralAssociationAttribute.annotations(), JPADotNames.LOB ),
pluralAssociationAttribute.getContext()
);
}
private LobTypeResolver(String name,
Class<?> javaClass,
AnnotationInstance annotation,
EntityBindingContext context) {
super( name, javaClass, annotation, context );
}
@Override
protected AnnotationInstance getTypeDeterminingAnnotationInstance() {
return JandexHelper.getSingleAnnotation( mappedAttribute.annotations(), JPADotNames.LOB );
}
@Override
public String resolveAnnotatedHibernateTypeName(AnnotationInstance annotationInstance) {
if ( annotationInstance == null ) {
public String resolveHibernateTypeName() {
if ( annotation() == null ) {
//only check attributes annotated with @Lob
return null;
}
String type = "blob";
if ( Clob.class.isAssignableFrom( mappedAttribute.getAttributeType() ) ) {
if ( Clob.class.isAssignableFrom( javaClass() ) ) {
type = StandardBasicTypes.CLOB.getName();
}
else if ( Blob.class.isAssignableFrom( mappedAttribute.getAttributeType() ) ) {
else if ( Blob.class.isAssignableFrom( javaClass() ) ) {
type = StandardBasicTypes.BLOB.getName();
}
else if ( String.class.isAssignableFrom( mappedAttribute.getAttributeType() ) ) {
else if ( String.class.isAssignableFrom( javaClass() ) ) {
type = StandardBasicTypes.MATERIALIZED_CLOB.getName();
}
else if ( Character[].class.isAssignableFrom( mappedAttribute.getAttributeType() ) ) {
else if ( Character[].class.isAssignableFrom( javaClass() ) ) {
type = CharacterArrayClobType.class.getName();
}
else if ( char[].class.isAssignableFrom( mappedAttribute.getAttributeType() ) ) {
else if ( char[].class.isAssignableFrom( javaClass() ) ) {
type = PrimitiveCharacterArrayClobType.class.getName();
}
else if ( Byte[].class.isAssignableFrom( mappedAttribute.getAttributeType() ) ) {
else if ( Byte[].class.isAssignableFrom( javaClass() ) ) {
type = WrappedMaterializedBlobType.class.getName();
}
else if ( byte[].class.isAssignableFrom( mappedAttribute.getAttributeType() ) ) {
else if ( byte[].class.isAssignableFrom( javaClass() ) ) {
type = StandardBasicTypes.MATERIALIZED_BLOB.getName();
}
else if ( Serializable.class.isAssignableFrom( mappedAttribute.getAttributeType() ) ) {
else if ( Serializable.class.isAssignableFrom( javaClass() ) ) {
type = SerializableToBlobType.class.getName();
}
return type;
}
@Override
protected Map<String, String> resolveHibernateTypeParameters(AnnotationInstance annotationInstance) {
return Collections.emptyMap();
}
}

View File

@ -33,8 +33,11 @@ import org.jboss.jandex.AnnotationInstance;
import org.hibernate.AnnotationException;
import org.hibernate.AssertionFailure;
import org.hibernate.annotations.SourceType;
import org.hibernate.cfg.NotYetImplementedException;
import org.hibernate.metamodel.internal.source.annotations.attribute.BasicAttribute;
import org.hibernate.metamodel.internal.source.annotations.attribute.PluralAssociationAttribute;
import org.hibernate.metamodel.internal.source.annotations.entity.EntityBindingContext;
import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames;
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
import org.hibernate.type.StandardBasicTypes;
@ -42,26 +45,58 @@ import org.hibernate.type.StandardBasicTypes;
/**
* @author Strong Liu
* @author Brett Meyer
* @author Gail Badner
*/
public class TemporalTypeResolver extends AbstractAttributeTypeResolver {
private final BasicAttribute basicAttribute;
private final boolean isMapKey;
private final SourceType versionSourceType;
public TemporalTypeResolver(BasicAttribute mappedAttribute) {
super( mappedAttribute );
this.basicAttribute = mappedAttribute;
this.isMapKey = false;//todo
public static TemporalTypeResolver createAttributeTypeResolver(BasicAttribute attribute) {
return new TemporalTypeResolver(
attribute.getName(),
attribute.getAttributeType(),
resolveAnnotationInstance( attribute.annotations(), JPADotNames.TEMPORAL ),
attribute.getContext(),
attribute.isVersioned() ? attribute.getVersionSourceType() : null
);
}
public static TemporalTypeResolver createCollectionElementTypeResolver(PluralAssociationAttribute attribute) {
return new TemporalTypeResolver(
attribute.getName(),
attribute.getReferencedAttributeType(),
resolveAnnotationInstance( attribute.annotations(), JPADotNames.TEMPORAL ),
attribute.getContext(),
null
);
}
public static TemporalTypeResolver createCollectionIndexTypeResolver(PluralAssociationAttribute attribute) {
return new TemporalTypeResolver(
attribute.getName(),
attribute.getIndexType(),
resolveAnnotationInstance( attribute.annotations(), JPADotNames.MAP_KEY_TEMPORAL ),
attribute.getContext(),
null
);
}
private TemporalTypeResolver(String name,
Class<?> javaClass,
AnnotationInstance annotation,
EntityBindingContext context,
SourceType versionSourceType) {
super( name, javaClass, annotation, context );
this.versionSourceType = versionSourceType;
}
@Override
public String resolveAnnotatedHibernateTypeName(AnnotationInstance temporalAnnotation) {
Class attributeType = mappedAttribute.getAttributeType();
public String resolveHibernateTypeName() {
Class attributeType = javaClass();
if ( isTemporalType( attributeType ) ) {
if ( basicAttribute.isVersioned() && basicAttribute.getVersionSourceType() != null ) {
return basicAttribute.getVersionSourceType().typeName();
if (versionSourceType != null ) {
return versionSourceType.typeName();
}
if ( temporalAnnotation == null ) {
if ( annotation() == null ) {
// Although JPA 2.1 states that @Temporal is required on
// Date/Calendar attributes, allow it to be left off in order
// to support legacy mappings.
@ -80,7 +115,11 @@ public class TemporalTypeResolver extends AbstractAttributeTypeResolver {
return StandardBasicTypes.TIMESTAMP.getName();
}
} else {
final TemporalType temporalType = JandexHelper.getEnumValue( temporalAnnotation, "value", TemporalType.class );
final TemporalType temporalType = JandexHelper.getEnumValue(
annotation(),
"value",
TemporalType.class
);
final boolean isDate = Date.class.isAssignableFrom( attributeType );
String type;
switch ( temporalType ) {
@ -102,24 +141,15 @@ public class TemporalTypeResolver extends AbstractAttributeTypeResolver {
return type;
}
} else {
if ( temporalAnnotation != null ) {
if ( annotation() != null ) {
throw new AnnotationException(
"@Temporal should only be set on a java.util.Date or java.util.Calendar property: " + mappedAttribute
.getName()
"@Temporal should only be set on a java.util.Date or java.util.Calendar property: " + name()
);
}
}
return null;
}
@Override
protected AnnotationInstance getTypeDeterminingAnnotationInstance() {
return JandexHelper.getSingleAnnotation(
mappedAttribute.annotations(),
JPADotNames.TEMPORAL
);
}
private static boolean isTemporalType(Class type) {
return Date.class.isAssignableFrom( type ) || Calendar.class.isAssignableFrom( type );
}

View File

@ -37,6 +37,7 @@ import org.hibernate.jaxb.spi.hbm.PluralAttributeElement;
import org.hibernate.metamodel.spi.binding.Caching;
import org.hibernate.metamodel.spi.binding.CustomSQL;
import org.hibernate.metamodel.spi.source.AttributeSourceContainer;
import org.hibernate.metamodel.spi.source.AttributeSourceResolutionContext;
import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource;
import org.hibernate.metamodel.spi.source.FilterSource;
import org.hibernate.metamodel.spi.source.MappingException;
@ -164,7 +165,7 @@ public abstract class AbstractPluralAttributeSourceImpl
}
@Override
public PluralAttributeElementSource resolvePluralAttributeElementSource(PluralAttributeElementSourceResolutionContext context) {
public PluralAttributeElementSource resolvePluralAttributeElementSource(AttributeSourceResolutionContext context) {
// elementSource is already resolved; nothing to do.
return elementSource;
}

View File

@ -23,9 +23,11 @@
*/
package org.hibernate.metamodel.internal.source.hbm;
import org.hibernate.AssertionFailure;
import org.hibernate.jaxb.spi.hbm.JaxbArrayElement;
import org.hibernate.jaxb.spi.hbm.JaxbListIndexElement;
import org.hibernate.metamodel.spi.source.AttributeSourceContainer;
import org.hibernate.metamodel.spi.source.AttributeSourceResolutionContext;
import org.hibernate.metamodel.spi.source.IndexedPluralAttributeSource;
import org.hibernate.metamodel.spi.source.PluralAttributeIndexSource;
import org.hibernate.metamodel.spi.source.SequentialPluralAttributeIndexSource;
@ -50,6 +52,14 @@ public class ArraySourceImpl extends AbstractPluralAttributeSourceImpl implement
}
}
@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;

View File

@ -34,8 +34,10 @@ import org.hibernate.jaxb.spi.hbm.JaxbKeyPropertyElement;
import org.hibernate.metamodel.internal.Binder;
import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding;
import org.hibernate.metamodel.spi.binding.SingularAttributeBinding;
import org.hibernate.metamodel.spi.relational.TableSpecification;
import org.hibernate.metamodel.spi.source.AttributeSource;
import org.hibernate.metamodel.spi.source.CompositePluralAttributeIndexSource;
import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource;
import org.hibernate.metamodel.spi.source.LocalBindingContext;
import org.hibernate.metamodel.spi.source.RelationalValueSource;
@ -95,6 +97,16 @@ public class CompositePluralAttributeIndexSourceImpl
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
public ExplicitHibernateTypeSource 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 String getClassName() {
return className;

View File

@ -23,9 +23,11 @@
*/
package org.hibernate.metamodel.internal.source.hbm;
import org.hibernate.AssertionFailure;
import org.hibernate.jaxb.spi.hbm.JaxbListElement;
import org.hibernate.jaxb.spi.hbm.JaxbListIndexElement;
import org.hibernate.metamodel.spi.source.AttributeSourceContainer;
import org.hibernate.metamodel.spi.source.AttributeSourceResolutionContext;
import org.hibernate.metamodel.spi.source.IndexedPluralAttributeSource;
import org.hibernate.metamodel.spi.source.PluralAttributeIndexSource;
import org.hibernate.metamodel.spi.source.SequentialPluralAttributeIndexSource;
@ -74,4 +76,12 @@ public class ListSourceImpl extends AbstractPluralAttributeSourceImpl implements
public Nature getNature() {
return Nature.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

@ -31,6 +31,7 @@ import org.hibernate.jaxb.spi.hbm.JaxbIndexElement;
import org.hibernate.jaxb.spi.hbm.JaxbMapKeyElement;
import org.hibernate.metamodel.internal.Binder;
import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding;
import org.hibernate.metamodel.spi.relational.TableSpecification;
import org.hibernate.metamodel.spi.source.BasicPluralAttributeIndexSource;
import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource;
import org.hibernate.metamodel.spi.source.RelationalValueSource;
@ -191,10 +192,15 @@ public class MapKeySourceImpl extends AbstractHbmSourceNode implements BasicPlur
}
@Override
public ExplicitHibernateTypeSource explicitHibernateTypeSource() {
public ExplicitHibernateTypeSource getTypeInformation() {
return typeSource;
}
@Override
public boolean isReferencedEntityAttribute() {
return false; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
public List<RelationalValueSource> relationalValueSources() {
return valueSources;

View File

@ -27,6 +27,7 @@ import org.hibernate.AssertionFailure;
import org.hibernate.cfg.NotYetImplementedException;
import org.hibernate.jaxb.spi.hbm.JaxbMapElement;
import org.hibernate.metamodel.spi.source.AttributeSourceContainer;
import org.hibernate.metamodel.spi.source.AttributeSourceResolutionContext;
import org.hibernate.metamodel.spi.source.IndexedPluralAttributeSource;
import org.hibernate.metamodel.spi.source.PluralAttributeIndexSource;
@ -73,6 +74,15 @@ public class MapSourceImpl extends AbstractPluralAttributeSourceImpl implements
}
}
@Override
public PluralAttributeIndexSource resolvePluralAttributeIndexSource(AttributeSourceResolutionContext context) {
if ( indexSource == null ) {
throw new NotYetImplementedException( "Plural attribute index source resolution not implemented yet." );
}
return indexSource;
}
@Override
public PluralAttributeIndexSource getIndexSource() {
return indexSource;

View File

@ -39,7 +39,7 @@ public class OneToManyPluralAttributeElementSourceImpl
public OneToManyPluralAttributeElementSourceImpl(
MappingDocument mappingDocument,
JaxbOneToManyElement oneToManyElement,
final JaxbOneToManyElement oneToManyElement,
String cascadeString) {
super( mappingDocument );
this.oneToManyElement = oneToManyElement;

View File

@ -164,10 +164,15 @@ public class SequentialPluralAttributeIndexSourceImpl extends AbstractHbmSourceN
}
@Override
public ExplicitHibernateTypeSource explicitHibernateTypeSource() {
public ExplicitHibernateTypeSource getTypeInformation() {
return typeSource;
}
@Override
public boolean isReferencedEntityAttribute() {
return false;
}
@Override
public List< RelationalValueSource > relationalValueSources() {
return valueSources;

View File

@ -0,0 +1,33 @@
/*
* 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.spi.source;
/**
*
* @author Gail Badner
*/
public interface AttributeSourceResolutionContext {
public IdentifierSource resolveIdentifierSource(String entityName);
public AttributeSource resolveAttributeSource(String entityName, String attributeName);
}

View File

@ -27,5 +27,4 @@ package org.hibernate.metamodel.spi.source;
* @author Gail Badner
*/
public interface BasicPluralAttributeIndexSource extends PluralAttributeIndexSource {
ExplicitHibernateTypeSource explicitHibernateTypeSource();
}

View File

@ -0,0 +1,35 @@
/*
* 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.spi.source;
/**
* Represents a plural attribute index source that is an attribute
* of the referenced entity (relevant only to one-to-many and many-to-many
* associations).
*
* @author Gail Badner
*/
public interface EntityAttributePluralAttributeIndexSource extends PluralAttributeIndexSource {
public String getAttributeName();
}

View File

@ -26,7 +26,9 @@ package org.hibernate.metamodel.spi.source;
/**
*
*/
public interface IndexedPluralAttributeSource extends PluralAttributeSource {
public interface IndexedPluralAttributeSource extends PluralAttributeSource, PluralAttributeIndexSourceResolver {
PluralAttributeIndexSource resolvePluralAttributeIndexSource(AttributeSourceResolutionContext context);
PluralAttributeIndexSource getIndexSource();
}

View File

@ -27,10 +27,5 @@ package org.hibernate.metamodel.spi.source;
* @author Gail Badner
*/
public interface PluralAttributeElementSourceResolver {
PluralAttributeElementSource resolvePluralAttributeElementSource(PluralAttributeElementSourceResolutionContext context);
public static interface PluralAttributeElementSourceResolutionContext {
public AttributeSource resolveAttributeSource(String referencedEntityName, String mappedBy);
}
PluralAttributeElementSource resolvePluralAttributeElementSource(AttributeSourceResolutionContext context);
}

View File

@ -34,4 +34,23 @@ import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding;
public interface PluralAttributeIndexSource extends RelationalValueSourceContainer {
PluralAttributeIndexBinding.Nature getNature();
List<Binder.DefaultNamingStrategy> getDefaultNamingStrategies();
/**
* Obtain information about the Hibernate index type ({@link org.hibernate.type.Type})
* for this plural attribute index.
*
* @return The Hibernate type information
*/
public ExplicitHibernateTypeSource getTypeInformation();
/**
* Is this plural attribute index source for an attribute of the referenced entity
* (relevant only for one-to-many and many-to-many associations)?
*
* If this method returns {@code true}, then this object can safely
* be cast to EntityAttributePluralAttributeIndexSource.
*
* @return true, if this plural attribute index source for an attribute of the referenced
* entity; false, otherwise.
*/
public boolean isReferencedEntityAttribute();
}

View File

@ -0,0 +1,31 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.metamodel.spi.source;
/**
* @author Gail Badner
*/
public interface PluralAttributeIndexSourceResolver {
PluralAttributeElementSource resolvePluralAttributeElementSource(AttributeSourceResolutionContext context);
}

View File

@ -52,7 +52,6 @@ import org.junit.Test;
@SuppressWarnings("unchecked")
public class CollectionElementTest extends BaseCoreFunctionalTestCase {
@Test
@FailureExpectedWithNewMetamodel( message = "Map with EnumType value not supported yet.")
public void testSimpleElement() throws Exception {
assertEquals( "BoyFavoriteNumbers", SchemaUtil.getCollection( Boy.class, "favoriteNumbers", metadata() )
.getPluralAttributeKeyBinding().getCollectionTable().getLogicalName().toString() );
@ -160,7 +159,6 @@ public class CollectionElementTest extends BaseCoreFunctionalTestCase {
}
@Test
@FailureExpectedWithNewMetamodel( message = "Collection with EnumType element not supported yet.")
public void testLazyCollectionofElements() throws Exception {
assertEquals( "BoyFavoriteNumbers", SchemaUtil.getCollection( Boy.class, "favoriteNumbers", metadata() )
.getPluralAttributeKeyBinding().getCollectionTable().getLogicalName().toString() );
@ -202,7 +200,6 @@ public class CollectionElementTest extends BaseCoreFunctionalTestCase {
}
@Test
@FailureExpectedWithNewMetamodel( message = "Map with EnumType key not supported yet.")
public void testFetchEagerAndFilter() throws Exception {
Session s = openSession();
Transaction tx = s.beginTransaction();

View File

@ -32,7 +32,6 @@ import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
/**
* @author Steve Ebersole
*/
@FailureExpectedWithNewMetamodel
public class MapKeyEnumeratedTest extends BaseCoreFunctionalTestCase {
@Override
protected Class<?>[] getAnnotatedClasses() {