HHH-6515 HHH-6516 : Support for map key annotations
This commit is contained in:
parent
2ad468ea73
commit
3244caa6cd
|
@ -131,6 +131,7 @@ import org.hibernate.metamodel.spi.source.CompositePluralAttributeIndexSource;
|
||||||
import org.hibernate.metamodel.spi.source.ConstraintSource;
|
import org.hibernate.metamodel.spi.source.ConstraintSource;
|
||||||
import org.hibernate.metamodel.spi.source.DerivedValueSource;
|
import org.hibernate.metamodel.spi.source.DerivedValueSource;
|
||||||
import org.hibernate.metamodel.spi.source.DiscriminatorSource;
|
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.EntityHierarchy;
|
||||||
import org.hibernate.metamodel.spi.source.EntitySource;
|
import org.hibernate.metamodel.spi.source.EntitySource;
|
||||||
import org.hibernate.metamodel.spi.source.FilterSource;
|
import org.hibernate.metamodel.spi.source.FilterSource;
|
||||||
|
@ -233,10 +234,11 @@ public class Binder {
|
||||||
* @param entityHierarchies The entity hierarchies resolved from mappings
|
* @param entityHierarchies The entity hierarchies resolved from mappings
|
||||||
*/
|
*/
|
||||||
public void addEntityHierarchies(final Iterable<EntityHierarchy> entityHierarchies) {
|
public void addEntityHierarchies(final Iterable<EntityHierarchy> entityHierarchies) {
|
||||||
|
|
||||||
LocalBindingContextExecutor executor = new LocalBindingContextExecutor() {
|
LocalBindingContextExecutor executor = new LocalBindingContextExecutor() {
|
||||||
@Override
|
@Override
|
||||||
public void execute(LocalBindingContextExecutionContext bindingContextContext) {
|
public void execute(LocalBindingContextExecutionContext bindingContextContext) {
|
||||||
sourceIndex.indexEntitySource( bindingContextContext.getEntitySource() );
|
sourceIndex.indexEntitySource( bindingContextContext.getRootEntitySource(), bindingContextContext.getEntitySource() );
|
||||||
createEntityBinding(
|
createEntityBinding(
|
||||||
bindingContextContext.getSuperEntityBinding(),
|
bindingContextContext.getSuperEntityBinding(),
|
||||||
bindingContextContext.getEntitySource()
|
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(
|
private void bindBasicCollectionIndex(
|
||||||
final IndexedPluralAttributeBinding attributeBinding,
|
final IndexedPluralAttributeBinding attributeBinding,
|
||||||
final BasicPluralAttributeIndexSource indexSource,
|
final BasicPluralAttributeIndexSource indexSource,
|
||||||
|
@ -2053,7 +2062,7 @@ public class Binder {
|
||||||
|
|
||||||
typeHelper.bindHibernateTypeDescriptor(
|
typeHelper.bindHibernateTypeDescriptor(
|
||||||
indexBinding.getHibernateTypeDescriptor(),
|
indexBinding.getHibernateTypeDescriptor(),
|
||||||
indexSource.explicitHibernateTypeSource(),
|
indexSource.getTypeInformation(),
|
||||||
defaultIndexJavaTypeName
|
defaultIndexJavaTypeName
|
||||||
);
|
);
|
||||||
typeHelper.bindJdbcDataType(
|
typeHelper.bindJdbcDataType(
|
||||||
|
@ -2069,9 +2078,11 @@ public class Binder {
|
||||||
|
|
||||||
private void bindCompositeCollectionIndex(
|
private void bindCompositeCollectionIndex(
|
||||||
final CompositePluralAttributeIndexBinding indexBinding,
|
final CompositePluralAttributeIndexBinding indexBinding,
|
||||||
final CompositePluralAttributeIndexSource indexSource,
|
final IndexedPluralAttributeSource indexedPluralAttributeSource,
|
||||||
final String defaultIndexJavaTypeName) {
|
final String defaultIndexJavaTypeName) {
|
||||||
final PluralAttributeBinding pluralAttributeBinding = indexBinding.getIndexedPluralAttributeBinding();
|
final PluralAttributeBinding pluralAttributeBinding = indexBinding.getIndexedPluralAttributeBinding();
|
||||||
|
final CompositePluralAttributeIndexSource indexSource =
|
||||||
|
(CompositePluralAttributeIndexSource) indexedPluralAttributeSource.getIndexSource();
|
||||||
ValueHolder<Class<?>> defaultElementJavaClassReference = null;
|
ValueHolder<Class<?>> defaultElementJavaClassReference = null;
|
||||||
// Create the aggregate type
|
// Create the aggregate type
|
||||||
// TODO: aggregateName should be set to elementSource.getPath() (which is currently not implemented)
|
// TODO: aggregateName should be set to elementSource.getPath() (which is currently not implemented)
|
||||||
|
@ -2105,6 +2116,19 @@ public class Binder {
|
||||||
);
|
);
|
||||||
|
|
||||||
bindAttributes( compositeAttributeBindingContainer, indexSource );
|
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(
|
Type resolvedType = metadata.getTypeResolver().getTypeFactory().component(
|
||||||
new ComponentMetamodel( compositeAttributeBindingContainer, false, false )
|
new ComponentMetamodel( compositeAttributeBindingContainer, false, false )
|
||||||
);
|
);
|
||||||
|
@ -2331,39 +2355,49 @@ public class Binder {
|
||||||
final ReflectedCollectionJavaTypes reflectedCollectionJavaTypes) {
|
final ReflectedCollectionJavaTypes reflectedCollectionJavaTypes) {
|
||||||
final String defaultCollectionIndexJavaTypeName =
|
final String defaultCollectionIndexJavaTypeName =
|
||||||
HibernateTypeHelper.defaultCollectionIndexJavaTypeName( reflectedCollectionJavaTypes );
|
HibernateTypeHelper.defaultCollectionIndexJavaTypeName( reflectedCollectionJavaTypes );
|
||||||
switch ( attributeSource.getIndexSource().getNature() ) {
|
final PluralAttributeIndexSource indexSource = attributeSource.getIndexSource();
|
||||||
case BASIC: {
|
if ( indexSource.isReferencedEntityAttribute() ) {
|
||||||
bindBasicCollectionIndex(
|
bindEntityAttributePluralAttributeIndex(
|
||||||
attributeBinding,
|
attributeBinding,
|
||||||
(BasicPluralAttributeIndexSource) attributeSource.getIndexSource(),
|
(EntityAttributePluralAttributeIndexSource) indexSource,
|
||||||
defaultCollectionIndexJavaTypeName
|
defaultCollectionIndexJavaTypeName
|
||||||
);
|
);
|
||||||
break;
|
|
||||||
}
|
|
||||||
case AGGREGATE: {
|
|
||||||
bindCompositeCollectionIndex(
|
|
||||||
(CompositePluralAttributeIndexBinding) attributeBinding.getPluralAttributeIndexBinding(),
|
|
||||||
(CompositePluralAttributeIndexSource) attributeSource.getIndexSource(),
|
|
||||||
defaultCollectionIndexJavaTypeName
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
throw new NotYetImplementedException(
|
|
||||||
String.format(
|
|
||||||
"%s collection indexes are not supported yet.",
|
|
||||||
attributeSource.getIndexSource().getNature()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if ( attributeBinding.getPluralAttributeElementBinding()
|
else {
|
||||||
.getNature() == PluralAttributeElementBinding.Nature.ONE_TO_MANY ) {
|
switch ( attributeSource.getIndexSource().getNature() ) {
|
||||||
for ( RelationalValueBinding relationalValueBinding : attributeBinding.getPluralAttributeIndexBinding().getRelationalValueBindings() ) {
|
case BASIC: {
|
||||||
if ( Column.class.isInstance( relationalValueBinding.getValue() ) ) {
|
bindBasicCollectionIndex(
|
||||||
// TODO: fix this when column nullability is refactored
|
attributeBinding,
|
||||||
Column column = (Column) relationalValueBinding.getValue();
|
(BasicPluralAttributeIndexSource) attributeSource.getIndexSource(),
|
||||||
column.setNullable( true );
|
defaultCollectionIndexJavaTypeName
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case AGGREGATE: {
|
||||||
|
bindCompositeCollectionIndex(
|
||||||
|
(CompositePluralAttributeIndexBinding) attributeBinding.getPluralAttributeIndexBinding(),
|
||||||
|
attributeSource,
|
||||||
|
defaultCollectionIndexJavaTypeName
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
throw new NotYetImplementedException(
|
||||||
|
String.format(
|
||||||
|
"%s collection indexes are not supported yet.",
|
||||||
|
attributeSource.getIndexSource().getNature()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( attributeBinding.getPluralAttributeElementBinding()
|
||||||
|
.getNature() == PluralAttributeElementBinding.Nature.ONE_TO_MANY ) {
|
||||||
|
for ( RelationalValueBinding relationalValueBinding : attributeBinding.getPluralAttributeIndexBinding().getRelationalValueBindings() ) {
|
||||||
|
if ( Column.class.isInstance( relationalValueBinding.getValue() ) ) {
|
||||||
|
// TODO: fix this when column nullability is refactored
|
||||||
|
Column column = (Column) relationalValueBinding.getValue();
|
||||||
|
column.setNullable( true );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3240,9 +3274,8 @@ public class Binder {
|
||||||
|
|
||||||
private static void bindIndexedCollectionTablePrimaryKey(
|
private static void bindIndexedCollectionTablePrimaryKey(
|
||||||
final IndexedPluralAttributeBinding attributeBinding) {
|
final IndexedPluralAttributeBinding attributeBinding) {
|
||||||
final PrimaryKey primaryKey = attributeBinding.getPluralAttributeKeyBinding()
|
final TableSpecification collectionTable = attributeBinding.getPluralAttributeKeyBinding().getCollectionTable();
|
||||||
.getCollectionTable()
|
final PrimaryKey primaryKey = collectionTable.getPrimaryKey();
|
||||||
.getPrimaryKey();
|
|
||||||
final List<RelationalValueBinding> keyRelationalValueBindings =
|
final List<RelationalValueBinding> keyRelationalValueBindings =
|
||||||
attributeBinding.getPluralAttributeKeyBinding().getRelationalValueBindings();
|
attributeBinding.getPluralAttributeKeyBinding().getRelationalValueBindings();
|
||||||
final PluralAttributeIndexBinding indexBinding = attributeBinding.getPluralAttributeIndexBinding();
|
final PluralAttributeIndexBinding indexBinding = attributeBinding.getPluralAttributeIndexBinding();
|
||||||
|
@ -3250,7 +3283,7 @@ public class Binder {
|
||||||
primaryKey.addColumn( (Column) keyRelationalValueBinding.getValue() );
|
primaryKey.addColumn( (Column) keyRelationalValueBinding.getValue() );
|
||||||
}
|
}
|
||||||
for ( RelationalValueBinding relationalValueBinding : indexBinding.getRelationalValueBindings() ) {
|
for ( RelationalValueBinding relationalValueBinding : indexBinding.getRelationalValueBindings() ) {
|
||||||
if ( !relationalValueBinding.isDerived() ) {
|
if ( !relationalValueBinding.isDerived() && relationalValueBinding.getTable().equals( collectionTable ) ) {
|
||||||
primaryKey.addColumn( (Column) relationalValueBinding.getValue() );
|
primaryKey.addColumn( (Column) relationalValueBinding.getValue() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,6 +92,7 @@ public class EntityHierarchyHelper {
|
||||||
applyToSubEntities(
|
applyToSubEntities(
|
||||||
executionContext.getEntityBinding(),
|
executionContext.getEntityBinding(),
|
||||||
rootEntitySource,
|
rootEntitySource,
|
||||||
|
rootEntitySource,
|
||||||
subEntityExecutor );
|
subEntityExecutor );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -127,27 +128,28 @@ public class EntityHierarchyHelper {
|
||||||
bindingContexts.push( rootEntitySource.getLocalBindingContext() );
|
bindingContexts.push( rootEntitySource.getLocalBindingContext() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void applyToSubEntities(
|
private void applyToSubEntities(
|
||||||
final EntityBinding entityBinding,
|
final EntityBinding entityBinding,
|
||||||
|
final RootEntitySource rootEntitySource,
|
||||||
final EntitySource entitySource,
|
final EntitySource entitySource,
|
||||||
final LocalBindingContextExecutor subEntityExecutor) {
|
final LocalBindingContextExecutor subEntityExecutor) {
|
||||||
for ( final SubclassEntitySource subEntitySource : entitySource.subclassEntitySources() ) {
|
for ( final SubclassEntitySource subEntitySource : entitySource.subclassEntitySources() ) {
|
||||||
applyToSubEntity( entityBinding, subEntitySource, subEntityExecutor );
|
applyToSubEntity( entityBinding, rootEntitySource, subEntitySource, subEntityExecutor );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyToSubEntity(
|
private void applyToSubEntity(
|
||||||
final EntityBinding superEntityBinding,
|
final EntityBinding superEntityBinding,
|
||||||
|
final RootEntitySource rootEntitySource,
|
||||||
final EntitySource entitySource,
|
final EntitySource entitySource,
|
||||||
final LocalBindingContextExecutor subEntityExecutor) {
|
final LocalBindingContextExecutor subEntityExecutor) {
|
||||||
final LocalBindingContext bindingContext = entitySource.getLocalBindingContext();
|
final LocalBindingContext bindingContext = entitySource.getLocalBindingContext();
|
||||||
bindingContexts.push( bindingContext );
|
bindingContexts.push( bindingContext );
|
||||||
try {
|
try {
|
||||||
LocalBindingContextExecutionContext executionContext =
|
LocalBindingContextExecutionContext executionContext =
|
||||||
new LocalBindingContextExecutionContextImpl( entitySource, superEntityBinding );
|
new LocalBindingContextExecutionContextImpl( rootEntitySource, entitySource, superEntityBinding );
|
||||||
subEntityExecutor.execute( executionContext );
|
subEntityExecutor.execute( executionContext );
|
||||||
applyToSubEntities( executionContext.getEntityBinding(), entitySource, subEntityExecutor );
|
applyToSubEntities( executionContext.getEntityBinding(), rootEntitySource, entitySource, subEntityExecutor );
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
bindingContexts.pop();
|
bindingContexts.pop();
|
||||||
|
@ -155,22 +157,38 @@ public class EntityHierarchyHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface LocalBindingContextExecutionContext {
|
public interface LocalBindingContextExecutionContext {
|
||||||
|
RootEntitySource getRootEntitySource();
|
||||||
EntitySource getEntitySource();
|
EntitySource getEntitySource();
|
||||||
EntityBinding getEntityBinding();
|
EntityBinding getEntityBinding();
|
||||||
EntityBinding getSuperEntityBinding();
|
EntityBinding getSuperEntityBinding();
|
||||||
}
|
}
|
||||||
|
|
||||||
private class LocalBindingContextExecutionContextImpl implements LocalBindingContextExecutionContext {
|
private class LocalBindingContextExecutionContextImpl implements LocalBindingContextExecutionContext {
|
||||||
|
private final RootEntitySource rootEntitySource;
|
||||||
private final EntitySource entitySource;
|
private final EntitySource entitySource;
|
||||||
private final EntityBinding superEntityBinding;
|
private final EntityBinding superEntityBinding;
|
||||||
|
|
||||||
private LocalBindingContextExecutionContextImpl(
|
private LocalBindingContextExecutionContextImpl(
|
||||||
|
RootEntitySource rootEntitySource,
|
||||||
|
EntityBinding superEntityBinding) {
|
||||||
|
this.rootEntitySource = rootEntitySource;
|
||||||
|
this.entitySource = rootEntitySource;
|
||||||
|
this.superEntityBinding = superEntityBinding;
|
||||||
|
}
|
||||||
|
|
||||||
|
private LocalBindingContextExecutionContextImpl(
|
||||||
|
RootEntitySource rootEntitySource,
|
||||||
EntitySource entitySource,
|
EntitySource entitySource,
|
||||||
EntityBinding superEntityBinding) {
|
EntityBinding superEntityBinding) {
|
||||||
|
this.rootEntitySource = rootEntitySource;
|
||||||
this.entitySource = entitySource;
|
this.entitySource = entitySource;
|
||||||
this.superEntityBinding = superEntityBinding;
|
this.superEntityBinding = superEntityBinding;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RootEntitySource getRootEntitySource() {
|
||||||
|
return rootEntitySource;
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public EntitySource getEntitySource() {
|
public EntitySource getEntitySource() {
|
||||||
return entitySource;
|
return entitySource;
|
||||||
|
|
|
@ -39,11 +39,12 @@ import org.hibernate.metamodel.spi.binding.EntityBinding;
|
||||||
import org.hibernate.metamodel.spi.relational.Column;
|
import org.hibernate.metamodel.spi.relational.Column;
|
||||||
import org.hibernate.metamodel.spi.source.AggregatedCompositeIdentifierSource;
|
import org.hibernate.metamodel.spi.source.AggregatedCompositeIdentifierSource;
|
||||||
import org.hibernate.metamodel.spi.source.AttributeSource;
|
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.ComponentAttributeSource;
|
||||||
import org.hibernate.metamodel.spi.source.EntitySource;
|
import org.hibernate.metamodel.spi.source.EntitySource;
|
||||||
import org.hibernate.metamodel.spi.source.IdentifierSource;
|
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.NonAggregatedCompositeIdentifierSource;
|
||||||
import org.hibernate.metamodel.spi.source.PluralAttributeElementSourceResolver;
|
|
||||||
import org.hibernate.metamodel.spi.source.PluralAttributeSource;
|
import org.hibernate.metamodel.spi.source.PluralAttributeSource;
|
||||||
import org.hibernate.metamodel.spi.source.RootEntitySource;
|
import org.hibernate.metamodel.spi.source.RootEntitySource;
|
||||||
import org.hibernate.metamodel.spi.source.SimpleIdentifierSource;
|
import org.hibernate.metamodel.spi.source.SimpleIdentifierSource;
|
||||||
|
@ -66,9 +67,13 @@ public class SourceIndex {
|
||||||
private final Map<AttributeSourceKey, AttributeSourceKey> mappedByAttributeKeysByOwnerAttributeKeys =
|
private final Map<AttributeSourceKey, AttributeSourceKey> mappedByAttributeKeysByOwnerAttributeKeys =
|
||||||
new HashMap<AttributeSourceKey, AttributeSourceKey>();
|
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();
|
String entityName = entitySource.getEntityName();
|
||||||
EntitySourceIndex entitySourceIndex = new EntitySourceIndex( this, entitySource );
|
EntitySourceIndex entitySourceIndex = new EntitySourceIndex( this, rootEntitySource, entitySource );
|
||||||
entitySourceIndexByEntityName.put( entityName, entitySourceIndex );
|
entitySourceIndexByEntityName.put( entityName, entitySourceIndex );
|
||||||
log.debugf( "Mapped entity source \"%s\"", entityName );
|
log.debugf( "Mapped entity source \"%s\"", entityName );
|
||||||
indexAttributes( entitySourceIndex );
|
indexAttributes( entitySourceIndex );
|
||||||
|
@ -106,6 +111,10 @@ public class SourceIndex {
|
||||||
return entitySourceIndexByEntityName.get( entityName ).entitySource;
|
return entitySourceIndexByEntityName.get( entityName ).entitySource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private EntitySourceIndex entitySourceIndex(String entityName) {
|
||||||
|
return entitySourceIndexByEntityName.get( entityName );
|
||||||
|
}
|
||||||
|
|
||||||
private void indexAttributes(EntitySourceIndex entitySourceIndex) {
|
private void indexAttributes(EntitySourceIndex entitySourceIndex) {
|
||||||
final String emptyString = "";
|
final String emptyString = "";
|
||||||
if ( entitySourceIndex.entitySource instanceof RootEntitySource ) {
|
if ( entitySourceIndex.entitySource instanceof RootEntitySource ) {
|
||||||
|
@ -267,6 +276,7 @@ public class SourceIndex {
|
||||||
|
|
||||||
private static class EntitySourceIndex {
|
private static class EntitySourceIndex {
|
||||||
private final SourceIndex sourceIndex;
|
private final SourceIndex sourceIndex;
|
||||||
|
private final RootEntitySource rootEntitySource;
|
||||||
private final EntitySource entitySource;
|
private final EntitySource entitySource;
|
||||||
private final Map<SingularAttributeSource.Nature, Map<AttributeSourceKey, SingularAttributeSource>> identifierAttributeSourcesByNature =
|
private final Map<SingularAttributeSource.Nature, Map<AttributeSourceKey, SingularAttributeSource>> identifierAttributeSourcesByNature =
|
||||||
new HashMap<SingularAttributeSource.Nature, Map<AttributeSourceKey, SingularAttributeSource>>();
|
new HashMap<SingularAttributeSource.Nature, Map<AttributeSourceKey, SingularAttributeSource>>();
|
||||||
|
@ -281,8 +291,16 @@ public class SourceIndex {
|
||||||
private final Map<AttributeSourceKey, PluralAttributeSource> inversePluralAttributeSourcesByKey =
|
private final Map<AttributeSourceKey, PluralAttributeSource> inversePluralAttributeSourcesByKey =
|
||||||
new LinkedHashMap<AttributeSourceKey, PluralAttributeSource>();
|
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.sourceIndex = sourceIndex;
|
||||||
|
this.rootEntitySource = rootEntitySource;
|
||||||
this.entitySource = entitySource;
|
this.entitySource = entitySource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -375,12 +393,20 @@ public class SourceIndex {
|
||||||
// so it needs to be resolved.
|
// so it needs to be resolved.
|
||||||
// TODO: this should really just resolve PluralAttributeElementSource.Nature
|
// TODO: this should really just resolve PluralAttributeElementSource.Nature
|
||||||
pluralAttributeSource.resolvePluralAttributeElementSource(
|
pluralAttributeSource.resolvePluralAttributeElementSource(
|
||||||
new PluralAttributeElementSourceResolver.PluralAttributeElementSourceResolutionContext() {
|
new AttributeSourceResolutionContext() {
|
||||||
|
@Override
|
||||||
|
public IdentifierSource resolveIdentifierSource(String entityName) {
|
||||||
|
return sourceIndex.entitySourceIndex( entityName ).rootEntitySource.getIdentifierSource();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AttributeSource resolveAttributeSource(String referencedEntityName, String mappedBy) {
|
public AttributeSource resolveAttributeSource(String referencedEntityName, String mappedBy) {
|
||||||
AttributeSourceKey ownerAttributeSourceKey = new AttributeSourceKey( referencedEntityName, mappedBy );
|
AttributeSourceKey ownerAttributeSourceKey = new AttributeSourceKey( referencedEntityName, mappedBy );
|
||||||
AttributeSource ownerAttributeSource = sourceIndex.attributeSource( referencedEntityName, mappedBy );
|
AttributeSource ownerAttributeSource = sourceIndex.attributeSource( referencedEntityName, mappedBy );
|
||||||
// TODO: is this needed? if so, make more obvious and rename method.
|
// 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(
|
sourceIndex.addMappedByAssociationByOwnerAssociation(
|
||||||
ownerAttributeSourceKey,
|
ownerAttributeSourceKey,
|
||||||
pluralAttributeSourceKey
|
pluralAttributeSourceKey
|
||||||
|
@ -388,9 +414,49 @@ public class SourceIndex {
|
||||||
return ownerAttributeSource;
|
return ownerAttributeSource;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
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 =
|
final Map<AttributeSourceKey,SingularAttributeSource> unresolvedSingularAttributeSourceMap =
|
||||||
singularAttributeSourcesByNature.get( null );
|
singularAttributeSourcesByNature.get( null );
|
||||||
if ( unresolvedSingularAttributeSourceMap != null ) {
|
if ( unresolvedSingularAttributeSourceMap != null ) {
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,7 +3,6 @@ package org.hibernate.metamodel.internal.source.annotations;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
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.Column;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.attribute.MappedAttribute;
|
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.attribute.PluralAssociationAttribute;
|
||||||
|
|
|
@ -23,10 +23,8 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.metamodel.internal.source.annotations;
|
package org.hibernate.metamodel.internal.source.annotations;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.jboss.jandex.AnnotationInstance;
|
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.internal.source.annotations.util.JandexHelper;
|
||||||
import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding;
|
import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding;
|
||||||
import org.hibernate.metamodel.spi.source.BasicPluralAttributeIndexSource;
|
import org.hibernate.metamodel.spi.source.BasicPluralAttributeIndexSource;
|
||||||
import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource;
|
|
||||||
import org.hibernate.metamodel.spi.source.RelationalValueSource;
|
import org.hibernate.metamodel.spi.source.RelationalValueSource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Strong Liu <stliu@hibernate.org>
|
* @author Strong Liu <stliu@hibernate.org>
|
||||||
*/
|
*/
|
||||||
public class BasicPluralAttributeIndexSourceImpl implements BasicPluralAttributeIndexSource {
|
public class BasicPluralAttributeIndexSourceImpl extends AbstractPluralAttributeIndexSourceImpl implements BasicPluralAttributeIndexSource {
|
||||||
private final PluralAssociationAttribute attribute;
|
|
||||||
private final IndexedPluralAttributeSourceImpl indexedPluralAttributeSource;
|
private final IndexedPluralAttributeSourceImpl indexedPluralAttributeSource;
|
||||||
private final List<RelationalValueSource> relationalValueSources = new ArrayList<RelationalValueSource>( 1 );
|
private final List<RelationalValueSource> relationalValueSources;
|
||||||
private final Binder.DefaultNamingStrategy defaultNamingStrategy;
|
private final Binder.DefaultNamingStrategy defaultNamingStrategy;
|
||||||
public BasicPluralAttributeIndexSourceImpl(
|
public BasicPluralAttributeIndexSourceImpl(
|
||||||
IndexedPluralAttributeSourceImpl indexedPluralAttributeSource,
|
IndexedPluralAttributeSourceImpl indexedPluralAttributeSource,
|
||||||
PluralAssociationAttribute attribute,
|
PluralAssociationAttribute attribute,
|
||||||
Binder.DefaultNamingStrategy defaultNamingStrategy) {
|
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.indexedPluralAttributeSource = indexedPluralAttributeSource;
|
||||||
|
this.relationalValueSources = relationalValueSources;
|
||||||
|
this.defaultNamingStrategy = defaultNamingStrategy;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<RelationalValueSource> createRelationalValueSources(PluralAssociationAttribute attribute) {
|
||||||
AnnotationInstance columnAnnotation = JandexHelper.getSingleAnnotation(
|
AnnotationInstance columnAnnotation = JandexHelper.getSingleAnnotation(
|
||||||
attribute.annotations(),
|
attribute.annotations(),
|
||||||
HibernateDotNames.INDEX_COLUMN
|
HibernateDotNames.INDEX_COLUMN
|
||||||
|
@ -72,10 +81,8 @@ public class BasicPluralAttributeIndexSourceImpl implements BasicPluralAttribute
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Column indexColumn = new Column( columnAnnotation );
|
Column indexColumn = new Column( columnAnnotation );
|
||||||
relationalValueSources.add( new ColumnValuesSourceImpl( indexColumn ) );
|
return Collections.singletonList( (RelationalValueSource) new ColumnValuesSourceImpl( indexColumn ) );
|
||||||
this.defaultNamingStrategy = defaultNamingStrategy;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PluralAttributeIndexBinding.Nature getNature() {
|
public PluralAttributeIndexBinding.Nature getNature() {
|
||||||
return PluralAttributeIndexBinding.Nature.BASIC;
|
return PluralAttributeIndexBinding.Nature.BASIC;
|
||||||
|
@ -86,38 +93,9 @@ public class BasicPluralAttributeIndexSourceImpl implements BasicPluralAttribute
|
||||||
return Collections.singletonList( defaultNamingStrategy );
|
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
|
@Override
|
||||||
public List<RelationalValueSource> relationalValueSources() {
|
public List<RelationalValueSource> relationalValueSources() {
|
||||||
return relationalValueSources;
|
return relationalValueSources;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean areValuesIncludedInInsertByDefault() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean areValuesIncludedInUpdateByDefault() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean areValuesNullableByDefault() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,27 +26,30 @@ package org.hibernate.metamodel.internal.source.annotations;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
|
|
||||||
import org.jboss.jandex.AnnotationInstance;
|
import org.jboss.jandex.AnnotationInstance;
|
||||||
import org.jboss.jandex.JandexAntTask;
|
|
||||||
|
|
||||||
import org.hibernate.cfg.NamingStrategy;
|
|
||||||
import org.hibernate.cfg.NotYetImplementedException;
|
import org.hibernate.cfg.NotYetImplementedException;
|
||||||
import org.hibernate.internal.util.StringHelper;
|
|
||||||
import org.hibernate.metamodel.internal.Binder;
|
import org.hibernate.metamodel.internal.Binder;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.attribute.MappedAttribute;
|
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.attribute.PluralAssociationAttribute;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.entity.ConfiguredClass;
|
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.JPADotNames;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
|
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.IndexedPluralAttributeSource;
|
||||||
import org.hibernate.metamodel.spi.source.MappingException;
|
import org.hibernate.metamodel.spi.source.MappingException;
|
||||||
import org.hibernate.metamodel.spi.source.PluralAttributeIndexSource;
|
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>
|
* @author Strong Liu <stliu@hibernate.org>
|
||||||
*/
|
*/
|
||||||
public class IndexedPluralAttributeSourceImpl extends PluralAttributeSourceImpl
|
public class IndexedPluralAttributeSourceImpl extends PluralAttributeSourceImpl
|
||||||
implements IndexedPluralAttributeSource {
|
implements IndexedPluralAttributeSource {
|
||||||
private final PluralAttributeIndexSource indexSource;
|
private PluralAttributeIndexSource indexSource;
|
||||||
private final static EnumSet<MappedAttribute.Nature> VALID_NATURES = EnumSet.of(
|
private final static EnumSet<MappedAttribute.Nature> VALID_NATURES = EnumSet.of(
|
||||||
MappedAttribute.Nature.MANY_TO_MANY,
|
MappedAttribute.Nature.MANY_TO_MANY,
|
||||||
MappedAttribute.Nature.ONE_TO_MANY,
|
MappedAttribute.Nature.ONE_TO_MANY,
|
||||||
|
@ -74,8 +77,8 @@ public class IndexedPluralAttributeSourceImpl extends PluralAttributeSourceImpl
|
||||||
indexSource = new SequentialPluralAttributeIndexSourceImpl( this, attribute, defaultNamingStrategy );
|
indexSource = new SequentialPluralAttributeIndexSourceImpl( this, attribute, defaultNamingStrategy );
|
||||||
}
|
}
|
||||||
else if ( attribute.annotations().containsKey( JPADotNames.MAP_KEY ) ) {
|
else if ( attribute.annotations().containsKey( JPADotNames.MAP_KEY ) ) {
|
||||||
// basic
|
// need to wait until the ID or attribute source can be resolved.
|
||||||
throw new NotYetImplementedException( "@MapKey is not supported yet." );
|
indexSource = null;
|
||||||
}
|
}
|
||||||
else if ( attribute.annotations().containsKey( JPADotNames.MAP_KEY_COLUMN ) ) {
|
else if ( attribute.annotations().containsKey( JPADotNames.MAP_KEY_COLUMN ) ) {
|
||||||
final Binder.DefaultNamingStrategy defaultNamingStrategy = new Binder.DefaultNamingStrategy() {
|
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
|
@Override
|
||||||
public PluralAttributeIndexSource getIndexSource() {
|
public PluralAttributeIndexSource getIndexSource() {
|
||||||
return indexSource;
|
return indexSource;
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -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.Caching;
|
||||||
import org.hibernate.metamodel.spi.binding.CustomSQL;
|
import org.hibernate.metamodel.spi.binding.CustomSQL;
|
||||||
import org.hibernate.metamodel.spi.source.AttributeSource;
|
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.ExplicitHibernateTypeSource;
|
||||||
import org.hibernate.metamodel.spi.source.FilterSource;
|
import org.hibernate.metamodel.spi.source.FilterSource;
|
||||||
import org.hibernate.metamodel.spi.source.MetaAttributeSource;
|
import org.hibernate.metamodel.spi.source.MetaAttributeSource;
|
||||||
|
@ -352,7 +353,7 @@ public class PluralAttributeSourceImpl implements PluralAttributeSource, Orderab
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PluralAttributeElementSource resolvePluralAttributeElementSource(
|
public PluralAttributeElementSource resolvePluralAttributeElementSource(
|
||||||
PluralAttributeElementSourceResolutionContext context) {
|
AttributeSourceResolutionContext context) {
|
||||||
if ( elementSource == null ) {
|
if ( elementSource == null ) {
|
||||||
// elementSource has not been initialized, so we need to resolve it using the
|
// elementSource has not been initialized, so we need to resolve it using the
|
||||||
// association owner.
|
// association owner.
|
||||||
|
@ -366,6 +367,10 @@ public class PluralAttributeSourceImpl implements PluralAttributeSource, Orderab
|
||||||
}
|
}
|
||||||
return elementSource;
|
return elementSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected PluralAssociationAttribute pluralAssociationAttribute() {
|
||||||
|
return associationAttribute;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,9 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.metamodel.internal.source.annotations;
|
package org.hibernate.metamodel.internal.source.annotations;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.jboss.jandex.AnnotationInstance;
|
import org.jboss.jandex.AnnotationInstance;
|
||||||
|
|
||||||
import org.hibernate.metamodel.internal.Binder;
|
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.HibernateDotNames;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames;
|
import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
|
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
|
||||||
|
import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource;
|
||||||
import org.hibernate.metamodel.spi.source.SequentialPluralAttributeIndexSource;
|
import org.hibernate.metamodel.spi.source.SequentialPluralAttributeIndexSource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -62,4 +66,18 @@ public class SequentialPluralAttributeIndexSourceImpl
|
||||||
public int base() {
|
public int base() {
|
||||||
return 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();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,6 @@ import org.jboss.jandex.AnnotationTarget;
|
||||||
import org.jboss.jandex.AnnotationValue;
|
import org.jboss.jandex.AnnotationValue;
|
||||||
import org.jboss.jandex.ClassInfo;
|
import org.jboss.jandex.ClassInfo;
|
||||||
import org.jboss.jandex.DotName;
|
import org.jboss.jandex.DotName;
|
||||||
import org.jboss.jandex.Index;
|
|
||||||
import org.jboss.jandex.IndexView;
|
import org.jboss.jandex.IndexView;
|
||||||
import org.jboss.logging.Logger;
|
import org.jboss.logging.Logger;
|
||||||
|
|
||||||
|
@ -50,7 +49,7 @@ import org.hibernate.internal.CoreMessageLogger;
|
||||||
import org.hibernate.internal.util.StringHelper;
|
import org.hibernate.internal.util.StringHelper;
|
||||||
import org.hibernate.mapping.PropertyGeneration;
|
import org.hibernate.mapping.PropertyGeneration;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.attribute.type.AttributeTypeResolver;
|
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.CompositeAttributeTypeResolver;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.entity.EntityBindingContext;
|
import org.hibernate.metamodel.internal.source.annotations.entity.EntityBindingContext;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.util.EnumConversionHelper;
|
import org.hibernate.metamodel.internal.source.annotations.util.EnumConversionHelper;
|
||||||
|
@ -275,8 +274,11 @@ public class AssociationAttribute extends MappedAttribute {
|
||||||
return PropertyGeneration.NEVER;
|
return PropertyGeneration.NEVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
private AttributeTypeResolver getDefaultHibernateTypeResolver() {
|
protected AttributeTypeResolver getDefaultHibernateTypeResolver() {
|
||||||
return new CompositeAttributeTypeResolver( this, new AttributeTypeResolverImpl( this ) );
|
return new CompositeAttributeTypeResolver(
|
||||||
|
this,
|
||||||
|
HibernateTypeResolver.createAttributeTypeResolver( this )
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean determineNotFoundBehavior() {
|
private boolean determineNotFoundBehavior() {
|
||||||
|
|
|
@ -43,7 +43,7 @@ import org.hibernate.internal.util.StringHelper;
|
||||||
import org.hibernate.mapping.PropertyGeneration;
|
import org.hibernate.mapping.PropertyGeneration;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.IdentifierGeneratorSourceContainer;
|
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.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.CompositeAttributeTypeResolver;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.attribute.type.EnumeratedTypeResolver;
|
import org.hibernate.metamodel.internal.source.annotations.attribute.type.EnumeratedTypeResolver;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.attribute.type.LobTypeResolver;
|
import org.hibernate.metamodel.internal.source.annotations.attribute.type.LobTypeResolver;
|
||||||
|
@ -422,10 +422,10 @@ public class BasicAttribute extends MappedAttribute {
|
||||||
|
|
||||||
private AttributeTypeResolver getDefaultHibernateTypeResolver() {
|
private AttributeTypeResolver getDefaultHibernateTypeResolver() {
|
||||||
CompositeAttributeTypeResolver resolver = new CompositeAttributeTypeResolver( this );
|
CompositeAttributeTypeResolver resolver = new CompositeAttributeTypeResolver( this );
|
||||||
resolver.addHibernateTypeResolver( new AttributeTypeResolverImpl( this ) );
|
resolver.addHibernateTypeResolver( HibernateTypeResolver.createAttributeTypeResolver( this ) );
|
||||||
resolver.addHibernateTypeResolver( new TemporalTypeResolver( this ) );
|
resolver.addHibernateTypeResolver( TemporalTypeResolver.createAttributeTypeResolver( this ) );
|
||||||
resolver.addHibernateTypeResolver( new LobTypeResolver( this ) );
|
resolver.addHibernateTypeResolver( LobTypeResolver.createAttributeTypeResolve( this ) );
|
||||||
resolver.addHibernateTypeResolver( new EnumeratedTypeResolver( this ) );
|
resolver.addHibernateTypeResolver( EnumeratedTypeResolver.createAttributeTypeResolver( this ) );
|
||||||
return resolver;
|
return resolver;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,6 @@ import org.jboss.jandex.AnnotationInstance;
|
||||||
import org.jboss.jandex.ClassInfo;
|
import org.jboss.jandex.ClassInfo;
|
||||||
import org.jboss.jandex.DotName;
|
import org.jboss.jandex.DotName;
|
||||||
|
|
||||||
import org.hibernate.AssertionFailure;
|
|
||||||
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
||||||
import org.hibernate.annotations.FetchMode;
|
import org.hibernate.annotations.FetchMode;
|
||||||
import org.hibernate.annotations.LazyCollectionOption;
|
import org.hibernate.annotations.LazyCollectionOption;
|
||||||
|
@ -44,7 +43,7 @@ import org.hibernate.annotations.OnDeleteAction;
|
||||||
import org.hibernate.annotations.SortType;
|
import org.hibernate.annotations.SortType;
|
||||||
import org.hibernate.internal.util.StringHelper;
|
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.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.CompositeAttributeTypeResolver;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.attribute.type.EnumeratedTypeResolver;
|
import org.hibernate.metamodel.internal.source.annotations.attribute.type.EnumeratedTypeResolver;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.attribute.type.LobTypeResolver;
|
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 boolean mutable;
|
||||||
private final int batchSize;
|
private final int batchSize;
|
||||||
|
|
||||||
|
private AttributeTypeResolver elementTypeResolver;
|
||||||
|
private AttributeTypeResolver indexTypeResolver;
|
||||||
|
|
||||||
public static PluralAssociationAttribute createPluralAssociationAttribute(
|
public static PluralAssociationAttribute createPluralAssociationAttribute(
|
||||||
ClassInfo entityClassInfo,
|
ClassInfo entityClassInfo,
|
||||||
|
@ -541,18 +542,38 @@ public class PluralAssociationAttribute extends AssociationAttribute {
|
||||||
return mutable;
|
return mutable;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
@Override
|
@Override
|
||||||
public AttributeTypeResolver getHibernateTypeResolver() {
|
public AttributeTypeResolver getHibernateTypeResolver() {
|
||||||
|
if ( elementTypeResolver == null ) {
|
||||||
|
elementTypeResolver = getDefaultElementHibernateTypeResolver();
|
||||||
|
}
|
||||||
|
return elementTypeResolver;
|
||||||
|
}
|
||||||
|
|
||||||
|
private AttributeTypeResolver getDefaultElementHibernateTypeResolver() {
|
||||||
CompositeAttributeTypeResolver resolver = new CompositeAttributeTypeResolver( this );
|
CompositeAttributeTypeResolver resolver = new CompositeAttributeTypeResolver( this );
|
||||||
resolver.addHibernateTypeResolver( new AttributeTypeResolverImpl( this ) );
|
resolver.addHibernateTypeResolver( HibernateTypeResolver.createCollectionElementTypeResolver( this ) );
|
||||||
// TODO: make it work for temporal elements
|
resolver.addHibernateTypeResolver( TemporalTypeResolver.createCollectionElementTypeResolver( this ) );
|
||||||
//resolver.addHibernateTypeResolver( new TemporalTypeResolver( this ) );
|
resolver.addHibernateTypeResolver( LobTypeResolver.createCollectionElementTypeResolve( this ) );
|
||||||
resolver.addHibernateTypeResolver( new LobTypeResolver( this ) );
|
resolver.addHibernateTypeResolver( EnumeratedTypeResolver.createCollectionElementTypeResolver( this ) );
|
||||||
resolver.addHibernateTypeResolver( new EnumeratedTypeResolver( this ) );
|
|
||||||
return resolver;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -26,24 +26,38 @@ package org.hibernate.metamodel.internal.source.annotations.attribute.type;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.jboss.jandex.AnnotationInstance;
|
import org.jboss.jandex.AnnotationInstance;
|
||||||
|
import org.jboss.jandex.DotName;
|
||||||
|
|
||||||
import org.hibernate.internal.util.StringHelper;
|
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;
|
import org.hibernate.usertype.DynamicParameterizedType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Strong Liu
|
* @author Strong Liu
|
||||||
* @author Brett Meyer
|
* @author Brett Meyer
|
||||||
|
* @author Gail Badner
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractAttributeTypeResolver implements AttributeTypeResolver {
|
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 ) {
|
public AbstractAttributeTypeResolver(
|
||||||
this.mappedAttribute = mappedAttribute;
|
String name,
|
||||||
|
Class<?> javaClass,
|
||||||
|
AnnotationInstance annotation,
|
||||||
|
EntityBindingContext context){
|
||||||
|
this.name = name;
|
||||||
|
this.javaClass = javaClass;
|
||||||
|
this.annotation = annotation;
|
||||||
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -54,42 +68,60 @@ public abstract class AbstractAttributeTypeResolver implements AttributeTypeReso
|
||||||
if ( !StringHelper.isEmpty( type ) ) {
|
if ( !StringHelper.isEmpty( type ) ) {
|
||||||
return type;
|
return type;
|
||||||
} else {
|
} else {
|
||||||
return hasEntityTypeDef() ? mappedAttribute.getAttributeType().getName() : null;
|
return hasTypeDef() ? javaClass().getName() : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
final public String getExplicitAnnotatedHibernateTypeName() {
|
final public String getExplicitAnnotatedHibernateTypeName() {
|
||||||
return resolveAnnotatedHibernateTypeName(
|
return resolveHibernateTypeName();
|
||||||
getTypeDeterminingAnnotationInstance() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
final public Map<String, String> getExplicitHibernateTypeParameters() {
|
final public Map<String, String> getExplicitHibernateTypeParameters() {
|
||||||
Map<String, String> result = new HashMap<String, String>( );
|
Map<String, String> result = new HashMap<String, String>( );
|
||||||
//this is only use by enum type and serializable blob type, but we put there anyway
|
//this is only use by enum type and serializable blob type, but we put there anyway
|
||||||
|
// TODO: why?
|
||||||
result.put(
|
result.put(
|
||||||
DynamicParameterizedType.RETURNED_CLASS,
|
DynamicParameterizedType.RETURNED_CLASS,
|
||||||
mappedAttribute.getAttributeType().getName()
|
javaClass().getName()
|
||||||
);
|
);
|
||||||
if ( StringHelper.isNotEmpty( getExplicitHibernateTypeName() ) ) {
|
if ( StringHelper.isNotEmpty( getExplicitHibernateTypeName() ) ) {
|
||||||
result.putAll( resolveHibernateTypeParameters(
|
result.putAll( resolveHibernateTypeParameters() );
|
||||||
getTypeDeterminingAnnotationInstance() ) );
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
final protected boolean hasEntityTypeDef() {
|
final protected boolean hasTypeDef() {
|
||||||
return mappedAttribute.getContext()
|
return context.getMetadataImplementor().hasTypeDefinition(
|
||||||
.getMetadataImplementor().hasTypeDefinition(
|
javaClass().getName()
|
||||||
mappedAttribute.getAttributeType().getName() );
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract AnnotationInstance getTypeDeterminingAnnotationInstance();
|
protected abstract String resolveHibernateTypeName();
|
||||||
|
|
||||||
protected abstract String resolveAnnotatedHibernateTypeName(AnnotationInstance annotationInstance);
|
protected Map<String, String> resolveHibernateTypeParameters() {
|
||||||
|
|
||||||
protected Map<String, String> resolveHibernateTypeParameters(AnnotationInstance annotationInstance) {
|
|
||||||
return Collections.emptyMap();
|
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
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -34,66 +34,88 @@ import org.hibernate.AnnotationException;
|
||||||
import org.hibernate.AssertionFailure;
|
import org.hibernate.AssertionFailure;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.attribute.MappedAttribute;
|
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.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.JPADotNames;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
|
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
|
||||||
import org.hibernate.type.EnumType;
|
import org.hibernate.type.EnumType;
|
||||||
import org.hibernate.usertype.DynamicParameterizedType;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Strong Liu
|
* @author Strong Liu
|
||||||
* @author Brett Meyer
|
* @author Brett Meyer
|
||||||
|
* @author Gail Badner
|
||||||
*/
|
*/
|
||||||
public class EnumeratedTypeResolver extends AbstractAttributeTypeResolver {
|
public class EnumeratedTypeResolver extends AbstractAttributeTypeResolver {
|
||||||
private final boolean isMapKey;
|
|
||||||
private final boolean isEnum;
|
private final boolean isEnum;
|
||||||
// private final String attributeType;
|
private final javax.persistence.EnumType enumType;
|
||||||
|
|
||||||
public EnumeratedTypeResolver(MappedAttribute mappedAttribute) {
|
public static EnumeratedTypeResolver createAttributeTypeResolver(MappedAttribute attribute) {
|
||||||
super( mappedAttribute );
|
return new EnumeratedTypeResolver(
|
||||||
isEnum = mappedAttribute.getAttributeType().isEnum();
|
attribute.getName(),
|
||||||
isMapKey = false;//todo
|
attribute.getAttributeType(),
|
||||||
// attributeType = mappedAttribute.getAttributeType().getName();
|
resolveAnnotationInstance( attribute.annotations(),JPADotNames.ENUMERATED ),
|
||||||
}
|
attribute.getContext()
|
||||||
|
|
||||||
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 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
|
@Override
|
||||||
public String resolveAnnotatedHibernateTypeName(AnnotationInstance enumeratedAnnotation) {
|
public String resolveHibernateTypeName() {
|
||||||
if ( enumeratedAnnotation != null ) {
|
if ( annotation() != null ) {
|
||||||
if ( isEnum ) {
|
if ( isEnum ) {
|
||||||
return EnumType.class.getName();
|
return EnumType.class.getName();
|
||||||
} else {
|
} 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 EnumType.class.getName();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Map<String, String> resolveHibernateTypeParameters(AnnotationInstance annotationInstance) {
|
protected Map<String, String> resolveHibernateTypeParameters() {
|
||||||
HashMap<String, String> typeParameters = new HashMap<String, String>();
|
HashMap<String, String> typeParameters = new HashMap<String, String>();
|
||||||
if ( annotationInstance != null ) {
|
|
||||||
javax.persistence.EnumType enumType = JandexHelper.getEnumValue(
|
if ( enumType != null ) {
|
||||||
annotationInstance,
|
|
||||||
"value",
|
|
||||||
javax.persistence.EnumType.class
|
|
||||||
);
|
|
||||||
if ( javax.persistence.EnumType.ORDINAL.equals( enumType ) ) {
|
if ( javax.persistence.EnumType.ORDINAL.equals( enumType ) ) {
|
||||||
typeParameters.put( EnumType.TYPE, String.valueOf( Types.INTEGER ) );
|
typeParameters.put( EnumType.TYPE, String.valueOf( Types.INTEGER ) );
|
||||||
typeParameters.put( EnumType.NAMED, String.valueOf( false ) );
|
typeParameters.put( EnumType.NAMED, String.valueOf( false ) );
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -27,14 +27,13 @@ package org.hibernate.metamodel.internal.source.annotations.attribute.type;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.sql.Blob;
|
import java.sql.Blob;
|
||||||
import java.sql.Clob;
|
import java.sql.Clob;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.jboss.jandex.AnnotationInstance;
|
import org.jboss.jandex.AnnotationInstance;
|
||||||
|
|
||||||
import org.hibernate.metamodel.internal.source.annotations.attribute.MappedAttribute;
|
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.JPADotNames;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
|
|
||||||
import org.hibernate.type.CharacterArrayClobType;
|
import org.hibernate.type.CharacterArrayClobType;
|
||||||
import org.hibernate.type.PrimitiveCharacterArrayClobType;
|
import org.hibernate.type.PrimitiveCharacterArrayClobType;
|
||||||
import org.hibernate.type.SerializableToBlobType;
|
import org.hibernate.type.SerializableToBlobType;
|
||||||
|
@ -44,54 +43,65 @@ import org.hibernate.type.WrappedMaterializedBlobType;
|
||||||
/**
|
/**
|
||||||
* @author Strong Liu
|
* @author Strong Liu
|
||||||
* @author Brett Meyer
|
* @author Brett Meyer
|
||||||
|
* @author Gail Badner
|
||||||
*/
|
*/
|
||||||
public class LobTypeResolver extends AbstractAttributeTypeResolver {
|
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) {
|
public static LobTypeResolver createCollectionElementTypeResolve(PluralAssociationAttribute pluralAssociationAttribute) {
|
||||||
super( mappedAttribute );
|
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
|
@Override
|
||||||
protected AnnotationInstance getTypeDeterminingAnnotationInstance() {
|
public String resolveHibernateTypeName() {
|
||||||
return JandexHelper.getSingleAnnotation( mappedAttribute.annotations(), JPADotNames.LOB );
|
if ( annotation() == null ) {
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String resolveAnnotatedHibernateTypeName(AnnotationInstance annotationInstance) {
|
|
||||||
if ( annotationInstance == null ) {
|
|
||||||
//only check attributes annotated with @Lob
|
//only check attributes annotated with @Lob
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
String type = "blob";
|
String type = "blob";
|
||||||
if ( Clob.class.isAssignableFrom( mappedAttribute.getAttributeType() ) ) {
|
if ( Clob.class.isAssignableFrom( javaClass() ) ) {
|
||||||
type = StandardBasicTypes.CLOB.getName();
|
type = StandardBasicTypes.CLOB.getName();
|
||||||
}
|
}
|
||||||
else if ( Blob.class.isAssignableFrom( mappedAttribute.getAttributeType() ) ) {
|
else if ( Blob.class.isAssignableFrom( javaClass() ) ) {
|
||||||
type = StandardBasicTypes.BLOB.getName();
|
type = StandardBasicTypes.BLOB.getName();
|
||||||
}
|
}
|
||||||
else if ( String.class.isAssignableFrom( mappedAttribute.getAttributeType() ) ) {
|
else if ( String.class.isAssignableFrom( javaClass() ) ) {
|
||||||
type = StandardBasicTypes.MATERIALIZED_CLOB.getName();
|
type = StandardBasicTypes.MATERIALIZED_CLOB.getName();
|
||||||
}
|
}
|
||||||
else if ( Character[].class.isAssignableFrom( mappedAttribute.getAttributeType() ) ) {
|
else if ( Character[].class.isAssignableFrom( javaClass() ) ) {
|
||||||
type = CharacterArrayClobType.class.getName();
|
type = CharacterArrayClobType.class.getName();
|
||||||
}
|
}
|
||||||
else if ( char[].class.isAssignableFrom( mappedAttribute.getAttributeType() ) ) {
|
else if ( char[].class.isAssignableFrom( javaClass() ) ) {
|
||||||
type = PrimitiveCharacterArrayClobType.class.getName();
|
type = PrimitiveCharacterArrayClobType.class.getName();
|
||||||
}
|
}
|
||||||
else if ( Byte[].class.isAssignableFrom( mappedAttribute.getAttributeType() ) ) {
|
else if ( Byte[].class.isAssignableFrom( javaClass() ) ) {
|
||||||
type = WrappedMaterializedBlobType.class.getName();
|
type = WrappedMaterializedBlobType.class.getName();
|
||||||
}
|
}
|
||||||
else if ( byte[].class.isAssignableFrom( mappedAttribute.getAttributeType() ) ) {
|
else if ( byte[].class.isAssignableFrom( javaClass() ) ) {
|
||||||
type = StandardBasicTypes.MATERIALIZED_BLOB.getName();
|
type = StandardBasicTypes.MATERIALIZED_BLOB.getName();
|
||||||
}
|
}
|
||||||
else if ( Serializable.class.isAssignableFrom( mappedAttribute.getAttributeType() ) ) {
|
else if ( Serializable.class.isAssignableFrom( javaClass() ) ) {
|
||||||
type = SerializableToBlobType.class.getName();
|
type = SerializableToBlobType.class.getName();
|
||||||
}
|
}
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Map<String, String> resolveHibernateTypeParameters(AnnotationInstance annotationInstance) {
|
|
||||||
return Collections.emptyMap();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,8 +33,11 @@ import org.jboss.jandex.AnnotationInstance;
|
||||||
|
|
||||||
import org.hibernate.AnnotationException;
|
import org.hibernate.AnnotationException;
|
||||||
import org.hibernate.AssertionFailure;
|
import org.hibernate.AssertionFailure;
|
||||||
|
import org.hibernate.annotations.SourceType;
|
||||||
import org.hibernate.cfg.NotYetImplementedException;
|
import org.hibernate.cfg.NotYetImplementedException;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.attribute.BasicAttribute;
|
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.JPADotNames;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
|
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
|
||||||
import org.hibernate.type.StandardBasicTypes;
|
import org.hibernate.type.StandardBasicTypes;
|
||||||
|
@ -42,26 +45,58 @@ import org.hibernate.type.StandardBasicTypes;
|
||||||
/**
|
/**
|
||||||
* @author Strong Liu
|
* @author Strong Liu
|
||||||
* @author Brett Meyer
|
* @author Brett Meyer
|
||||||
|
* @author Gail Badner
|
||||||
*/
|
*/
|
||||||
public class TemporalTypeResolver extends AbstractAttributeTypeResolver {
|
public class TemporalTypeResolver extends AbstractAttributeTypeResolver {
|
||||||
private final BasicAttribute basicAttribute;
|
private final SourceType versionSourceType;
|
||||||
private final boolean isMapKey;
|
|
||||||
|
|
||||||
public TemporalTypeResolver(BasicAttribute mappedAttribute) {
|
public static TemporalTypeResolver createAttributeTypeResolver(BasicAttribute attribute) {
|
||||||
super( mappedAttribute );
|
return new TemporalTypeResolver(
|
||||||
this.basicAttribute = mappedAttribute;
|
attribute.getName(),
|
||||||
this.isMapKey = false;//todo
|
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
|
@Override
|
||||||
public String resolveAnnotatedHibernateTypeName(AnnotationInstance temporalAnnotation) {
|
public String resolveHibernateTypeName() {
|
||||||
Class attributeType = mappedAttribute.getAttributeType();
|
Class attributeType = javaClass();
|
||||||
|
|
||||||
if ( isTemporalType( attributeType ) ) {
|
if ( isTemporalType( attributeType ) ) {
|
||||||
if ( basicAttribute.isVersioned() && basicAttribute.getVersionSourceType() != null ) {
|
if (versionSourceType != null ) {
|
||||||
return basicAttribute.getVersionSourceType().typeName();
|
return versionSourceType.typeName();
|
||||||
}
|
}
|
||||||
if ( temporalAnnotation == null ) {
|
if ( annotation() == null ) {
|
||||||
// Although JPA 2.1 states that @Temporal is required on
|
// Although JPA 2.1 states that @Temporal is required on
|
||||||
// Date/Calendar attributes, allow it to be left off in order
|
// Date/Calendar attributes, allow it to be left off in order
|
||||||
// to support legacy mappings.
|
// to support legacy mappings.
|
||||||
|
@ -80,7 +115,11 @@ public class TemporalTypeResolver extends AbstractAttributeTypeResolver {
|
||||||
return StandardBasicTypes.TIMESTAMP.getName();
|
return StandardBasicTypes.TIMESTAMP.getName();
|
||||||
}
|
}
|
||||||
} else {
|
} 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 );
|
final boolean isDate = Date.class.isAssignableFrom( attributeType );
|
||||||
String type;
|
String type;
|
||||||
switch ( temporalType ) {
|
switch ( temporalType ) {
|
||||||
|
@ -102,24 +141,15 @@ public class TemporalTypeResolver extends AbstractAttributeTypeResolver {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ( temporalAnnotation != null ) {
|
if ( annotation() != null ) {
|
||||||
throw new AnnotationException(
|
throw new AnnotationException(
|
||||||
"@Temporal should only be set on a java.util.Date or java.util.Calendar property: " + mappedAttribute
|
"@Temporal should only be set on a java.util.Date or java.util.Calendar property: " + name()
|
||||||
.getName()
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected AnnotationInstance getTypeDeterminingAnnotationInstance() {
|
|
||||||
return JandexHelper.getSingleAnnotation(
|
|
||||||
mappedAttribute.annotations(),
|
|
||||||
JPADotNames.TEMPORAL
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean isTemporalType(Class type) {
|
private static boolean isTemporalType(Class type) {
|
||||||
return Date.class.isAssignableFrom( type ) || Calendar.class.isAssignableFrom( type );
|
return Date.class.isAssignableFrom( type ) || Calendar.class.isAssignableFrom( type );
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@ import org.hibernate.jaxb.spi.hbm.PluralAttributeElement;
|
||||||
import org.hibernate.metamodel.spi.binding.Caching;
|
import org.hibernate.metamodel.spi.binding.Caching;
|
||||||
import org.hibernate.metamodel.spi.binding.CustomSQL;
|
import org.hibernate.metamodel.spi.binding.CustomSQL;
|
||||||
import org.hibernate.metamodel.spi.source.AttributeSourceContainer;
|
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.ExplicitHibernateTypeSource;
|
||||||
import org.hibernate.metamodel.spi.source.FilterSource;
|
import org.hibernate.metamodel.spi.source.FilterSource;
|
||||||
import org.hibernate.metamodel.spi.source.MappingException;
|
import org.hibernate.metamodel.spi.source.MappingException;
|
||||||
|
@ -164,7 +165,7 @@ public abstract class AbstractPluralAttributeSourceImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PluralAttributeElementSource resolvePluralAttributeElementSource(PluralAttributeElementSourceResolutionContext context) {
|
public PluralAttributeElementSource resolvePluralAttributeElementSource(AttributeSourceResolutionContext context) {
|
||||||
// elementSource is already resolved; nothing to do.
|
// elementSource is already resolved; nothing to do.
|
||||||
return elementSource;
|
return elementSource;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,9 +23,11 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.metamodel.internal.source.hbm;
|
package org.hibernate.metamodel.internal.source.hbm;
|
||||||
|
|
||||||
|
import org.hibernate.AssertionFailure;
|
||||||
import org.hibernate.jaxb.spi.hbm.JaxbArrayElement;
|
import org.hibernate.jaxb.spi.hbm.JaxbArrayElement;
|
||||||
import org.hibernate.jaxb.spi.hbm.JaxbListIndexElement;
|
import org.hibernate.jaxb.spi.hbm.JaxbListIndexElement;
|
||||||
import org.hibernate.metamodel.spi.source.AttributeSourceContainer;
|
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.IndexedPluralAttributeSource;
|
||||||
import org.hibernate.metamodel.spi.source.PluralAttributeIndexSource;
|
import org.hibernate.metamodel.spi.source.PluralAttributeIndexSource;
|
||||||
import org.hibernate.metamodel.spi.source.SequentialPluralAttributeIndexSource;
|
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
|
@Override
|
||||||
public PluralAttributeIndexSource getIndexSource() {
|
public PluralAttributeIndexSource getIndexSource() {
|
||||||
return indexSource;
|
return indexSource;
|
||||||
|
|
|
@ -34,8 +34,10 @@ import org.hibernate.jaxb.spi.hbm.JaxbKeyPropertyElement;
|
||||||
import org.hibernate.metamodel.internal.Binder;
|
import org.hibernate.metamodel.internal.Binder;
|
||||||
import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding;
|
import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding;
|
||||||
import org.hibernate.metamodel.spi.binding.SingularAttributeBinding;
|
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.AttributeSource;
|
||||||
import org.hibernate.metamodel.spi.source.CompositePluralAttributeIndexSource;
|
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.LocalBindingContext;
|
||||||
import org.hibernate.metamodel.spi.source.RelationalValueSource;
|
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.
|
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
|
@Override
|
||||||
public String getClassName() {
|
public String getClassName() {
|
||||||
return className;
|
return className;
|
||||||
|
|
|
@ -23,9 +23,11 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.metamodel.internal.source.hbm;
|
package org.hibernate.metamodel.internal.source.hbm;
|
||||||
|
|
||||||
|
import org.hibernate.AssertionFailure;
|
||||||
import org.hibernate.jaxb.spi.hbm.JaxbListElement;
|
import org.hibernate.jaxb.spi.hbm.JaxbListElement;
|
||||||
import org.hibernate.jaxb.spi.hbm.JaxbListIndexElement;
|
import org.hibernate.jaxb.spi.hbm.JaxbListIndexElement;
|
||||||
import org.hibernate.metamodel.spi.source.AttributeSourceContainer;
|
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.IndexedPluralAttributeSource;
|
||||||
import org.hibernate.metamodel.spi.source.PluralAttributeIndexSource;
|
import org.hibernate.metamodel.spi.source.PluralAttributeIndexSource;
|
||||||
import org.hibernate.metamodel.spi.source.SequentialPluralAttributeIndexSource;
|
import org.hibernate.metamodel.spi.source.SequentialPluralAttributeIndexSource;
|
||||||
|
@ -74,4 +76,12 @@ public class ListSourceImpl extends AbstractPluralAttributeSourceImpl implements
|
||||||
public Nature getNature() {
|
public Nature getNature() {
|
||||||
return Nature.LIST;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ import org.hibernate.jaxb.spi.hbm.JaxbIndexElement;
|
||||||
import org.hibernate.jaxb.spi.hbm.JaxbMapKeyElement;
|
import org.hibernate.jaxb.spi.hbm.JaxbMapKeyElement;
|
||||||
import org.hibernate.metamodel.internal.Binder;
|
import org.hibernate.metamodel.internal.Binder;
|
||||||
import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding;
|
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.BasicPluralAttributeIndexSource;
|
||||||
import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource;
|
import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource;
|
||||||
import org.hibernate.metamodel.spi.source.RelationalValueSource;
|
import org.hibernate.metamodel.spi.source.RelationalValueSource;
|
||||||
|
@ -191,10 +192,15 @@ public class MapKeySourceImpl extends AbstractHbmSourceNode implements BasicPlur
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ExplicitHibernateTypeSource explicitHibernateTypeSource() {
|
public ExplicitHibernateTypeSource getTypeInformation() {
|
||||||
return typeSource;
|
return typeSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isReferencedEntityAttribute() {
|
||||||
|
return false; //To change body of implemented methods use File | Settings | File Templates.
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<RelationalValueSource> relationalValueSources() {
|
public List<RelationalValueSource> relationalValueSources() {
|
||||||
return valueSources;
|
return valueSources;
|
||||||
|
|
|
@ -27,6 +27,7 @@ import org.hibernate.AssertionFailure;
|
||||||
import org.hibernate.cfg.NotYetImplementedException;
|
import org.hibernate.cfg.NotYetImplementedException;
|
||||||
import org.hibernate.jaxb.spi.hbm.JaxbMapElement;
|
import org.hibernate.jaxb.spi.hbm.JaxbMapElement;
|
||||||
import org.hibernate.metamodel.spi.source.AttributeSourceContainer;
|
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.IndexedPluralAttributeSource;
|
||||||
import org.hibernate.metamodel.spi.source.PluralAttributeIndexSource;
|
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
|
@Override
|
||||||
public PluralAttributeIndexSource getIndexSource() {
|
public PluralAttributeIndexSource getIndexSource() {
|
||||||
return indexSource;
|
return indexSource;
|
||||||
|
|
|
@ -39,7 +39,7 @@ public class OneToManyPluralAttributeElementSourceImpl
|
||||||
|
|
||||||
public OneToManyPluralAttributeElementSourceImpl(
|
public OneToManyPluralAttributeElementSourceImpl(
|
||||||
MappingDocument mappingDocument,
|
MappingDocument mappingDocument,
|
||||||
JaxbOneToManyElement oneToManyElement,
|
final JaxbOneToManyElement oneToManyElement,
|
||||||
String cascadeString) {
|
String cascadeString) {
|
||||||
super( mappingDocument );
|
super( mappingDocument );
|
||||||
this.oneToManyElement = oneToManyElement;
|
this.oneToManyElement = oneToManyElement;
|
||||||
|
|
|
@ -164,10 +164,15 @@ public class SequentialPluralAttributeIndexSourceImpl extends AbstractHbmSourceN
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ExplicitHibernateTypeSource explicitHibernateTypeSource() {
|
public ExplicitHibernateTypeSource getTypeInformation() {
|
||||||
return typeSource;
|
return typeSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isReferencedEntityAttribute() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List< RelationalValueSource > relationalValueSources() {
|
public List< RelationalValueSource > relationalValueSources() {
|
||||||
return valueSources;
|
return valueSources;
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
|
@ -27,5 +27,4 @@ package org.hibernate.metamodel.spi.source;
|
||||||
* @author Gail Badner
|
* @author Gail Badner
|
||||||
*/
|
*/
|
||||||
public interface BasicPluralAttributeIndexSource extends PluralAttributeIndexSource {
|
public interface BasicPluralAttributeIndexSource extends PluralAttributeIndexSource {
|
||||||
ExplicitHibernateTypeSource explicitHibernateTypeSource();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
|
@ -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();
|
PluralAttributeIndexSource getIndexSource();
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,10 +27,5 @@ package org.hibernate.metamodel.spi.source;
|
||||||
* @author Gail Badner
|
* @author Gail Badner
|
||||||
*/
|
*/
|
||||||
public interface PluralAttributeElementSourceResolver {
|
public interface PluralAttributeElementSourceResolver {
|
||||||
|
PluralAttributeElementSource resolvePluralAttributeElementSource(AttributeSourceResolutionContext context);
|
||||||
PluralAttributeElementSource resolvePluralAttributeElementSource(PluralAttributeElementSourceResolutionContext context);
|
|
||||||
|
|
||||||
public static interface PluralAttributeElementSourceResolutionContext {
|
|
||||||
public AttributeSource resolveAttributeSource(String referencedEntityName, String mappedBy);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,4 +34,23 @@ import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding;
|
||||||
public interface PluralAttributeIndexSource extends RelationalValueSourceContainer {
|
public interface PluralAttributeIndexSource extends RelationalValueSourceContainer {
|
||||||
PluralAttributeIndexBinding.Nature getNature();
|
PluralAttributeIndexBinding.Nature getNature();
|
||||||
List<Binder.DefaultNamingStrategy> getDefaultNamingStrategies();
|
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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
|
@ -52,7 +52,6 @@ import org.junit.Test;
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public class CollectionElementTest extends BaseCoreFunctionalTestCase {
|
public class CollectionElementTest extends BaseCoreFunctionalTestCase {
|
||||||
@Test
|
@Test
|
||||||
@FailureExpectedWithNewMetamodel( message = "Map with EnumType value not supported yet.")
|
|
||||||
public void testSimpleElement() throws Exception {
|
public void testSimpleElement() throws Exception {
|
||||||
assertEquals( "BoyFavoriteNumbers", SchemaUtil.getCollection( Boy.class, "favoriteNumbers", metadata() )
|
assertEquals( "BoyFavoriteNumbers", SchemaUtil.getCollection( Boy.class, "favoriteNumbers", metadata() )
|
||||||
.getPluralAttributeKeyBinding().getCollectionTable().getLogicalName().toString() );
|
.getPluralAttributeKeyBinding().getCollectionTable().getLogicalName().toString() );
|
||||||
|
@ -160,7 +159,6 @@ public class CollectionElementTest extends BaseCoreFunctionalTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@FailureExpectedWithNewMetamodel( message = "Collection with EnumType element not supported yet.")
|
|
||||||
public void testLazyCollectionofElements() throws Exception {
|
public void testLazyCollectionofElements() throws Exception {
|
||||||
assertEquals( "BoyFavoriteNumbers", SchemaUtil.getCollection( Boy.class, "favoriteNumbers", metadata() )
|
assertEquals( "BoyFavoriteNumbers", SchemaUtil.getCollection( Boy.class, "favoriteNumbers", metadata() )
|
||||||
.getPluralAttributeKeyBinding().getCollectionTable().getLogicalName().toString() );
|
.getPluralAttributeKeyBinding().getCollectionTable().getLogicalName().toString() );
|
||||||
|
@ -202,7 +200,6 @@ public class CollectionElementTest extends BaseCoreFunctionalTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@FailureExpectedWithNewMetamodel( message = "Map with EnumType key not supported yet.")
|
|
||||||
public void testFetchEagerAndFilter() throws Exception {
|
public void testFetchEagerAndFilter() throws Exception {
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
Transaction tx = s.beginTransaction();
|
Transaction tx = s.beginTransaction();
|
||||||
|
|
|
@ -32,7 +32,6 @@ import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||||
/**
|
/**
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
@FailureExpectedWithNewMetamodel
|
|
||||||
public class MapKeyEnumeratedTest extends BaseCoreFunctionalTestCase {
|
public class MapKeyEnumeratedTest extends BaseCoreFunctionalTestCase {
|
||||||
@Override
|
@Override
|
||||||
protected Class<?>[] getAnnotatedClasses() {
|
protected Class<?>[] getAnnotatedClasses() {
|
||||||
|
|
Loading…
Reference in New Issue