HHH-7900 Began skeleton code for annotated M2M maps

This commit is contained in:
Brett Meyer 2013-01-03 14:11:40 -05:00
parent 1cd75bbdd4
commit 48816a2c8a
14 changed files with 373 additions and 141 deletions

View File

@ -112,6 +112,7 @@ 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.AttributeSourceContainer; import org.hibernate.metamodel.spi.source.AttributeSourceContainer;
import org.hibernate.metamodel.spi.source.BasicPluralAttributeElementSource; import org.hibernate.metamodel.spi.source.BasicPluralAttributeElementSource;
import org.hibernate.metamodel.spi.source.BasicPluralAttributeIndexSource;
import org.hibernate.metamodel.spi.source.ColumnSource; import org.hibernate.metamodel.spi.source.ColumnSource;
import org.hibernate.metamodel.spi.source.ComponentAttributeSource; import org.hibernate.metamodel.spi.source.ComponentAttributeSource;
import org.hibernate.metamodel.spi.source.CompositePluralAttributeElementSource; import org.hibernate.metamodel.spi.source.CompositePluralAttributeElementSource;
@ -161,7 +162,6 @@ import org.hibernate.type.ComponentType;
import org.hibernate.type.EntityType; import org.hibernate.type.EntityType;
import org.hibernate.type.ForeignKeyDirection; import org.hibernate.type.ForeignKeyDirection;
import org.hibernate.type.Type; import org.hibernate.type.Type;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
/** /**
@ -1428,10 +1428,14 @@ public class Binder {
if ( attribute == null ) { if ( attribute == null ) {
attribute = attributeBindingContainer.getAttributeContainer().createList( attributeSource.getName() ); attribute = attributeBindingContainer.getAttributeContainer().createList( attributeSource.getName() );
} }
final int base = IndexedPluralAttributeSource.class.isInstance( attributeSource ) ? IndexedPluralAttributeSource.class int base = 0;
.cast( attributeSource ) if ( IndexedPluralAttributeSource.class.isInstance( attributeSource ) ) {
.getIndexSource() IndexedPluralAttributeSource indexedAttributeSource
.base() : 0; = ( IndexedPluralAttributeSource ) attributeSource;
base = BasicPluralAttributeIndexSource.class.isInstance( attributeSource )
? BasicPluralAttributeIndexSource.class.cast(
indexedAttributeSource.getIndexSource() ).base() : 0;
}
return attributeBindingContainer.makeListAttributeBinding( return attributeBindingContainer.makeListAttributeBinding(
attribute, attribute,
pluralAttributeElementNature( attributeSource ), pluralAttributeElementNature( attributeSource ),
@ -1450,10 +1454,14 @@ public class Binder {
if ( attribute == null ) { if ( attribute == null ) {
attribute = attributeBindingContainer.getAttributeContainer().createArray( attributeSource.getName() ); attribute = attributeBindingContainer.getAttributeContainer().createArray( attributeSource.getName() );
} }
final int base = IndexedPluralAttributeSource.class.isInstance( attributeSource ) ? IndexedPluralAttributeSource.class int base = 0;
.cast( attributeSource ) if ( IndexedPluralAttributeSource.class.isInstance( attributeSource ) ) {
.getIndexSource() IndexedPluralAttributeSource indexedAttributeSource
.base() : 0; = ( IndexedPluralAttributeSource ) attributeSource;
base = BasicPluralAttributeIndexSource.class.isInstance( attributeSource )
? BasicPluralAttributeIndexSource.class.cast(
indexedAttributeSource.getIndexSource() ).base() : 0;
}
return attributeBindingContainer.makeArrayAttributeBinding( return attributeBindingContainer.makeArrayAttributeBinding(
attribute, attribute,
pluralAttributeElementNature( attributeSource ), pluralAttributeElementNature( attributeSource ),
@ -1622,8 +1630,8 @@ public class Binder {
final PluralAttributeIndexSource attributeSource, final PluralAttributeIndexSource attributeSource,
final String defaultIndexJavaTypeName) { final String defaultIndexJavaTypeName) {
IndexedPluralAttributeBinding indexedAttributeBinding = attributeBinding; IndexedPluralAttributeBinding indexedAttributeBinding = attributeBinding;
final BasicPluralAttributeIndexBinding indexBinding = final PluralAttributeIndexBinding indexBinding =
(BasicPluralAttributeIndexBinding) indexedAttributeBinding.getPluralAttributeIndexBinding(); indexedAttributeBinding.getPluralAttributeIndexBinding();
indexBinding.setIndexRelationalValue( indexBinding.setIndexRelationalValue(
bindValues( bindValues(
indexedAttributeBinding.getContainer(), indexedAttributeBinding.getContainer(),

View File

@ -4,29 +4,28 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.jboss.jandex.AnnotationInstance;
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.PluralAssociationAttribute; import org.hibernate.metamodel.internal.source.annotations.attribute.PluralAssociationAttribute;
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.binding.PluralAttributeIndexBinding; import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding;
import org.hibernate.metamodel.spi.source.BasicPluralAttributeIndexSource;
import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource; import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource;
import org.hibernate.metamodel.spi.source.PluralAttributeIndexSource;
import org.hibernate.metamodel.spi.source.RelationalValueSource; import org.hibernate.metamodel.spi.source.RelationalValueSource;
import org.jboss.jandex.AnnotationInstance;
/** /**
* @author Strong Liu <stliu@hibernate.org> * @author Strong Liu <stliu@hibernate.org>
* @author Brett Meyer
*/ */
public class PluralAttributeIndexSourceImpl implements PluralAttributeIndexSource { public class BasicPluralAttributeIndexSourceImpl implements BasicPluralAttributeIndexSource {
private final PluralAssociationAttribute attribute; // private final PluralAssociationAttribute attribute;
private final IndexedPluralAttributeSourceImpl indexedPluralAttributeSource;
private final int base; private final int base;
private final List<RelationalValueSource> relationalValueSources = new ArrayList<RelationalValueSource>( 1 ); private final List<RelationalValueSource> relationalValueSources = new ArrayList<RelationalValueSource>( 1 );
public PluralAttributeIndexSourceImpl(IndexedPluralAttributeSourceImpl indexedPluralAttributeSource, PluralAssociationAttribute attribute) { public BasicPluralAttributeIndexSourceImpl(
this.attribute = attribute; PluralAssociationAttribute attribute ) {
this.indexedPluralAttributeSource = indexedPluralAttributeSource; // this.attribute = attribute;
AnnotationInstance columnAnnotation = JandexHelper.getSingleAnnotation( AnnotationInstance columnAnnotation = JandexHelper.getSingleAnnotation(
attribute.annotations(), attribute.annotations(),
HibernateDotNames.INDEX_COLUMN HibernateDotNames.INDEX_COLUMN
@ -46,17 +45,7 @@ public class PluralAttributeIndexSourceImpl implements PluralAttributeIndexSourc
@Override @Override
public PluralAttributeIndexBinding.Nature getNature() { public PluralAttributeIndexBinding.Nature getNature() {
switch ( indexedPluralAttributeSource.getElementSource().getNature() ) { return PluralAttributeIndexBinding.Nature.BASIC;
case BASIC:
return PluralAttributeIndexBinding.Nature.BASIC;
case AGGREGATE:
return PluralAttributeIndexBinding.Nature.AGGREGATE;
case MANY_TO_ANY:
return PluralAttributeIndexBinding.Nature.MANY_TO_ANY;
case MANY_TO_MANY:
return PluralAttributeIndexBinding.Nature.MANY_TO_MANY;
}
return null;
} }
@Override @Override

View File

@ -0,0 +1,67 @@
package org.hibernate.metamodel.internal.source.annotations;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.hibernate.metamodel.internal.source.annotations.attribute.PluralAssociationAttribute;
import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding;
import org.hibernate.metamodel.spi.source.CompositePluralAttributeIndexSource;
import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource;
import org.hibernate.metamodel.spi.source.RelationalValueSource;
/**
* @author Brett Meyer
*/
public class CompositePluralAttributeIndexSourceImpl implements CompositePluralAttributeIndexSource {
private final PluralAssociationAttribute attribute;
private final List<RelationalValueSource> relationalValueSources = new ArrayList<RelationalValueSource>( 1 );
public CompositePluralAttributeIndexSourceImpl(
PluralAssociationAttribute attribute ) {
this.attribute = attribute;
// Column indexColumn = new Column( columnAnnotation );
// relationalValueSources.add( new ColumnValuesSourceImpl( indexColumn ) );
}
@Override
public PluralAttributeIndexBinding.Nature getNature() {
return PluralAttributeIndexBinding.Nature.AGGREGATE;
}
@Override
public ExplicitHibernateTypeSource explicitHibernateTypeSource() {
return new ExplicitHibernateTypeSource() {
@Override
public String getName() {
return attribute.getReferencedKeyType();
}
@Override
public Map<String, String> getParameters() {
// TODO?
return java.util.Collections.emptyMap();
}
};
}
@Override
public List<RelationalValueSource> relationalValueSources() {
return relationalValueSources;
}
@Override
public boolean areValuesIncludedInInsertByDefault() {
return false;
}
@Override
public boolean areValuesIncludedInUpdateByDefault() {
return false;
}
@Override
public boolean areValuesNullableByDefault() {
return false;
}
}

View File

@ -5,7 +5,6 @@ import java.util.EnumSet;
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.entity.EntityClass;
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;
@ -31,7 +30,14 @@ public class IndexedPluralAttributeSourceImpl extends PluralAttributeSourceImpl
attribute.getContext().getOrigin() attribute.getContext().getOrigin()
); );
} }
this.indexSource = new PluralAttributeIndexSourceImpl( this, attribute ); switch ( attribute.getPluralAttributeNature() ) {
case MAP:
// TODO: Need to support MANY_TO_MANY too
this.indexSource = new CompositePluralAttributeIndexSourceImpl( attribute );
break;
default:
this.indexSource = new BasicPluralAttributeIndexSourceImpl( attribute );
}
} }
@Override @Override

View File

@ -33,11 +33,6 @@ import java.util.SortedSet;
import javax.persistence.FetchType; import javax.persistence.FetchType;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.hibernate.AnnotationException;
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;
@ -53,12 +48,16 @@ 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.MappingException; import org.hibernate.metamodel.spi.source.MappingException;
import org.hibernate.metamodel.spi.source.PluralAttributeSource; import org.hibernate.metamodel.spi.source.PluralAttributeSource;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
/** /**
* Represents an collection (collection, list, set, map) association attribute. * Represents an collection (collection, list, set, map) association attribute.
* *
* @author Hardy Ferentschik * @author Hardy Ferentschik
* @author Strong Liu * @author Strong Liu
* @author Brett Meyer
*/ */
public class PluralAssociationAttribute extends AssociationAttribute { public class PluralAssociationAttribute extends AssociationAttribute {
private final String whereClause; private final String whereClause;
@ -87,103 +86,14 @@ public class PluralAssociationAttribute extends AssociationAttribute {
private LazyCollectionOption lazyOption; private LazyCollectionOption lazyOption;
private final boolean isCollectionIdPresent; private final boolean isCollectionIdPresent;
private final String referencedKeyType;
public static PluralAssociationAttribute createPluralAssociationAttribute(
ClassInfo entityClassInfo,
String name,
Class<?> attributeType,
Class<?> referencedAttributeType,
Nature attributeNature,
String accessType,
Map<DotName, List<AnnotationInstance>> annotations,
EntityBindingContext context) {
return new PluralAssociationAttribute(
entityClassInfo,
name,
attributeType,
referencedAttributeType,
attributeNature,
accessType,
annotations,
context
);
}
public PluralAttributeSource.Nature getPluralAttributeNature() { public PluralAssociationAttribute(
return pluralAttributeNature;
}
public String getWhereClause() {
return whereClause;
}
public String getOrderBy() {
return orderBy;
}
public String getInverseForeignKeyName() {
return inverseForeignKeyName;
}
public String getExplicitForeignKeyName(){
return explicitForeignKeyName;
}
public Caching getCaching() {
return caching;
}
public String getCustomPersister() {
return customPersister;
}
public String getCustomLoaderName() {
return customLoaderName;
}
public CustomSQL getCustomInsert() {
return customInsert;
}
public CustomSQL getCustomUpdate() {
return customUpdate;
}
public CustomSQL getCustomDelete() {
return customDelete;
}
public CustomSQL getCustomDeleteAll() {
return customDeleteAll;
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder();
sb.append( "PluralAssociationAttribute" );
sb.append( "{name='" ).append( getName() ).append( '\'' );
sb.append( '}' );
return sb.toString();
}
public OnDeleteAction getOnDeleteAction() {
return onDeleteAction;
}
public String getComparatorName() {
return comparatorName;
}
public boolean isSorted() {
return sorted;
}
public boolean isIndexed() {
return isIndexed;
}
private PluralAssociationAttribute(
final ClassInfo entityClassInfo, final ClassInfo entityClassInfo,
final String name, final String name,
final Class<?> attributeType, final Class<?> attributeType,
final Class<?> referencedKeyType,
final Class<?> referencedAttributeType, final Class<?> referencedAttributeType,
final Nature associationType, final Nature associationType,
final String accessType, final String accessType,
@ -260,12 +170,91 @@ public class PluralAssociationAttribute extends AssociationAttribute {
getContext().getOrigin() getContext().getOrigin()
); );
} }
this.isIndexed = orderColumnAnnotation != null || indexColumnAnnotation != null; this.isIndexed = orderColumnAnnotation != null
|| indexColumnAnnotation != null
|| Map.class.isAssignableFrom( getAttributeType() );
this.pluralAttributeNature = resolvePluralAttributeNature(); this.pluralAttributeNature = resolvePluralAttributeNature();
this.referencedKeyType = determineReferencedKeyType( referencedKeyType );
validateMapping(); validateMapping();
} }
public PluralAttributeSource.Nature getPluralAttributeNature() {
return pluralAttributeNature;
}
public String getWhereClause() {
return whereClause;
}
public String getOrderBy() {
return orderBy;
}
public String getInverseForeignKeyName() {
return inverseForeignKeyName;
}
public String getExplicitForeignKeyName(){
return explicitForeignKeyName;
}
public Caching getCaching() {
return caching;
}
public String getCustomPersister() {
return customPersister;
}
public String getCustomLoaderName() {
return customLoaderName;
}
public CustomSQL getCustomInsert() {
return customInsert;
}
public CustomSQL getCustomUpdate() {
return customUpdate;
}
public CustomSQL getCustomDelete() {
return customDelete;
}
public CustomSQL getCustomDeleteAll() {
return customDeleteAll;
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder();
sb.append( "PluralAssociationAttribute" );
sb.append( "{name='" ).append( getName() ).append( '\'' );
sb.append( '}' );
return sb.toString();
}
public OnDeleteAction getOnDeleteAction() {
return onDeleteAction;
}
public String getComparatorName() {
return comparatorName;
}
public boolean isSorted() {
return sorted;
}
public boolean isIndexed() {
return isIndexed;
}
public String getReferencedKeyType() {
return referencedKeyType;
}
private void validateMapping() { private void validateMapping() {
checkSortedTypeIsSortable(); checkSortedTypeIsSortable();
checkIfCollectionIdIsWronglyPlaced(); checkIfCollectionIdIsWronglyPlaced();
@ -487,7 +476,26 @@ public class PluralAssociationAttribute extends AssociationAttribute {
return caching; return caching;
} }
// TODO: For Maps only -- should this be here?
private String determineReferencedKeyType(
Class<?> referencedKeyType ) {
String typeName = null;
// @MapKeyClass
AnnotationInstance mapKeyClassAnnotation
= JandexHelper.getSingleAnnotation(
annotations(), JPADotNames.MAP_KEY_CLASS );
if ( mapKeyClassAnnotation != null ) {
typeName = mapKeyClassAnnotation.value().asClass().name().toString();
}
else {
if ( referencedKeyType != null ) {
typeName = referencedKeyType.getName();
}
}
return typeName;
}
} }

View File

@ -533,10 +533,11 @@ public class ConfiguredClass {
case ELEMENT_COLLECTION_BASIC: case ELEMENT_COLLECTION_BASIC:
case ONE_TO_MANY: case ONE_TO_MANY:
case MANY_TO_MANY: { case MANY_TO_MANY: {
AssociationAttribute attribute = PluralAssociationAttribute.createPluralAssociationAttribute( AssociationAttribute attribute = new PluralAssociationAttribute(
classInfo, classInfo,
attributeName, attributeName,
resolvedMember.getType().getErasedType(), resolvedMember.getType().getErasedType(),
resolveCollectionKeyType( resolvedMember ),
referencedCollectionType, referencedCollectionType,
attributeNature, attributeNature,
accessTypeString, accessTypeString,
@ -712,6 +713,16 @@ public class ConfiguredClass {
} }
} }
private Class<?> resolveCollectionKeyType(ResolvedMember resolvedMember) {
Class<?> type = resolvedMember.getType().getErasedType();
if ( Map.class.isAssignableFrom( type ) ) {
return resolvedMember.getType().getTypeParameters().get( 0 ).getErasedType();
}
else {
return null;
}
}
/** /**
* Populates the sets of transient field and method names. * Populates the sets of transient field and method names.
*/ */

View File

@ -32,14 +32,14 @@ import org.hibernate.jaxb.spi.hbm.JaxbColumnElement;
import org.hibernate.jaxb.spi.hbm.JaxbIndexElement; import org.hibernate.jaxb.spi.hbm.JaxbIndexElement;
import org.hibernate.jaxb.spi.hbm.JaxbListIndexElement; import org.hibernate.jaxb.spi.hbm.JaxbListIndexElement;
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.ExplicitHibernateTypeSource; import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource;
import org.hibernate.metamodel.spi.source.PluralAttributeIndexSource;
import org.hibernate.metamodel.spi.source.RelationalValueSource; import org.hibernate.metamodel.spi.source.RelationalValueSource;
/** /**
* *
*/ */
public class ListAttributeIndexSource extends AbstractHbmSourceNode implements PluralAttributeIndexSource { public class ListAttributeIndexSource extends AbstractHbmSourceNode implements BasicPluralAttributeIndexSource {
private final List< RelationalValueSource > valueSources; private final List< RelationalValueSource > valueSources;
private final ExplicitHibernateTypeSource typeSource; private final ExplicitHibernateTypeSource typeSource;
private final int base; private final int base;

View File

@ -30,14 +30,15 @@ import org.hibernate.jaxb.spi.hbm.JaxbColumnElement;
import org.hibernate.jaxb.spi.hbm.JaxbIndexElement; 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.spi.binding.PluralAttributeIndexBinding; import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding;
import org.hibernate.metamodel.spi.source.BasicPluralAttributeIndexSource;
import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource; import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource;
import org.hibernate.metamodel.spi.source.PluralAttributeIndexSource;
import org.hibernate.metamodel.spi.source.RelationalValueSource; import org.hibernate.metamodel.spi.source.RelationalValueSource;
/** /**
* *
*/ */
public class MapAttributeIndexSource extends AbstractHbmSourceNode implements PluralAttributeIndexSource { // TODO: This probably needs to support non-basic.
public class MapAttributeIndexSource extends AbstractHbmSourceNode implements BasicPluralAttributeIndexSource {
private final PluralAttributeIndexBinding.Nature nature; private final PluralAttributeIndexBinding.Nature nature;
private final List<RelationalValueSource> valueSources; private final List<RelationalValueSource> valueSources;
private final ExplicitHibernateTypeSource typeSource; private final ExplicitHibernateTypeSource typeSource;

View File

@ -0,0 +1,75 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.metamodel.spi.binding;
import org.hibernate.metamodel.spi.domain.IndexedPluralAttribute;
import org.hibernate.metamodel.spi.domain.Type;
import org.hibernate.metamodel.spi.relational.Value;
/**
* @author Brett Meyer
*/
public class CompositePluralAttributeIndexBinding implements PluralAttributeIndexBinding {
private final IndexedPluralAttributeBinding pluralAttributeBinding;
private final Nature pluralAttributeIndexNature;
private final HibernateTypeDescriptor hibernateTypeDescriptor = new HibernateTypeDescriptor();
private Value value;
public CompositePluralAttributeIndexBinding(
IndexedPluralAttributeBinding pluralAttributeBinding,
Nature pluralAttributeIndexNature) {
this.pluralAttributeBinding = pluralAttributeBinding;
this.pluralAttributeIndexNature = pluralAttributeIndexNature;
}
@Override
public HibernateTypeDescriptor getHibernateTypeDescriptor() {
return hibernateTypeDescriptor;
}
@Override
public Value getIndexRelationalValue() {
return value;
}
@Override
public IndexedPluralAttributeBinding getIndexedPluralAttributeBinding() {
return pluralAttributeBinding;
}
public void setIndexRelationalValue( Value value ) {
this.value = value;
}
@Override
public Type getPluralAttributeIndexType() {
return ( (IndexedPluralAttribute) getIndexedPluralAttributeBinding().getAttribute() ).getIndexType();
}
@Override
public Nature getNature() {
return Nature.AGGREGATE;
}
}

View File

@ -51,7 +51,15 @@ public class MapBinding extends AbstractPluralAttributeBinding implements Indexe
includedInOptimisticLocking, includedInOptimisticLocking,
metaAttributeContext metaAttributeContext
); );
pluralAttributeIndexBinding = new BasicPluralAttributeIndexBinding( this, pluralAttributeIndexNature ); switch ( pluralAttributeIndexNature ) {
// TODO: support MANY_TO_MANY & MANY_TO_ANY
case AGGREGATE:
pluralAttributeIndexBinding = new CompositePluralAttributeIndexBinding( this, pluralAttributeIndexNature );
break;
default:
// TODO: Will this ever happen?
pluralAttributeIndexBinding = new BasicPluralAttributeIndexBinding( this, pluralAttributeIndexNature );
}
} }
/** /**

View File

@ -36,6 +36,9 @@ public interface PluralAttributeIndexBinding {
Value getIndexRelationalValue(); Value getIndexRelationalValue();
// TODO: Easier to add this here, but maybe it shouldn't be.
void setIndexRelationalValue(Value value);
HibernateTypeDescriptor getHibernateTypeDescriptor(); HibernateTypeDescriptor getHibernateTypeDescriptor();
Type getPluralAttributeIndexType(); Type getPluralAttributeIndexType();

View File

@ -0,0 +1,28 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* JBoss, Home of Professional Open Source
* Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors
* as indicated by the @authors tag. All rights reserved.
* See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU Lesser General Public License, v. 2.1.
* This program is distributed in the hope that it will be useful, but WITHOUT A
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License,
* v.2.1 along with this distribution; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
package org.hibernate.metamodel.spi.source;
/**
* @author Brett Meyer
*/
public interface BasicPluralAttributeIndexSource extends PluralAttributeIndexSource {
int base();
}

View File

@ -0,0 +1,28 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* JBoss, Home of Professional Open Source
* Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors
* as indicated by the @authors tag. All rights reserved.
* See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU Lesser General Public License, v. 2.1.
* This program is distributed in the hope that it will be useful, but WITHOUT A
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License,
* v.2.1 along with this distribution; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
package org.hibernate.metamodel.spi.source;
/**
* @author Brett Meyer
*/
public interface CompositePluralAttributeIndexSource extends PluralAttributeIndexSource {
}

View File

@ -26,10 +26,10 @@ package org.hibernate.metamodel.spi.source;
import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding; import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding;
/** /**
* * @author Brett Meyer
*/ */
public interface PluralAttributeIndexSource extends RelationalValueSourceContainer { public interface PluralAttributeIndexSource extends RelationalValueSourceContainer {
PluralAttributeIndexBinding.Nature getNature(); // TODO: Should these be basic only?
ExplicitHibernateTypeSource explicitHibernateTypeSource(); ExplicitHibernateTypeSource explicitHibernateTypeSource();
int base(); PluralAttributeIndexBinding.Nature getNature();
} }