diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/ColumnSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/ColumnSourceImpl.java index b7ce756d69..4905926f2c 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/ColumnSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/ColumnSourceImpl.java @@ -32,44 +32,41 @@ import org.hibernate.metamodel.internal.source.annotations.attribute.MappedAttri * @author Hardy Ferentschik */ public class ColumnSourceImpl extends ColumnValuesSourceImpl { - private final MappedAttribute attribute; + private final String readFragement; + private final String writeFragement; + private final String checkCondition; ColumnSourceImpl(MappedAttribute attribute, AttributeOverride attributeOverride, Column columnValues) { super( columnValues ); if ( attributeOverride != null ) { setOverrideColumnValues( attributeOverride.getColumnValues() ); } - this.attribute = attribute; + if(BasicAttribute.class.isInstance( attribute )){ + BasicAttribute basicAttribute = BasicAttribute.class.cast( attribute ); + this.readFragement = basicAttribute.getCustomReadFragment(); + this.writeFragement = basicAttribute.getCustomWriteFragment(); + this.checkCondition = basicAttribute.getCheckCondition(); + } else { + this.readFragement = null; + this.writeFragement = null; + this.checkCondition = null; + } + } @Override public String getReadFragment() { - if ( attribute instanceof BasicAttribute ) { - return ( ( BasicAttribute ) attribute ).getCustomReadFragment(); - } - else { - return null; - } + return readFragement; } @Override public String getWriteFragment() { - if ( attribute instanceof BasicAttribute ) { - return ( ( BasicAttribute ) attribute ).getCustomWriteFragment(); - } - else { - return null; - } + return writeFragement; } @Override public String getCheckCondition() { - if ( attribute instanceof BasicAttribute ) { - return attribute.getCheckCondition(); - } - else { - return null; - } + return checkCondition; } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/PluralAttributeIndexSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/PluralAttributeIndexSourceImpl.java index 06dafe8956..fb60516fd8 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/PluralAttributeIndexSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/PluralAttributeIndexSourceImpl.java @@ -3,6 +3,7 @@ package org.hibernate.metamodel.internal.source.annotations; import java.util.List; import org.hibernate.metamodel.internal.source.annotations.attribute.PluralAssociationAttribute; +import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding; import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource; import org.hibernate.metamodel.spi.source.PluralAttributeIndexSource; import org.hibernate.metamodel.spi.source.RelationalValueSource; @@ -20,20 +21,25 @@ public class PluralAttributeIndexSourceImpl implements PluralAttributeIndexSourc } @Override - public Nature getNature() { + public PluralAttributeIndexBinding.Nature getNature() { switch ( indexedPluralAttributeSource.getElementSource().getNature() ){ case BASIC: - return Nature.BASIC; + return PluralAttributeIndexBinding.Nature.BASIC; case COMPONENT: - return Nature.COMPOSITE; + return PluralAttributeIndexBinding.Nature.COMPOSITE; case MANY_TO_ANY: - return Nature.MANY_TO_ANY; + return PluralAttributeIndexBinding.Nature.MANY_TO_ANY; case MANY_TO_MANY: - return Nature.MANY_TO_MANY; + return PluralAttributeIndexBinding.Nature.MANY_TO_MANY; } return null; } + @Override + public int base() { + return 0; + } + @Override public ExplicitHibernateTypeSource explicitHibernateTypeSource() { return null; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/ListAttributeIndexSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/ListAttributeIndexSource.java index 6920f7d60b..f4f757e88e 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/ListAttributeIndexSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/ListAttributeIndexSource.java @@ -30,6 +30,7 @@ import java.util.Map; import org.hibernate.jaxb.spi.hbm.JaxbColumnElement; import org.hibernate.jaxb.spi.hbm.JaxbIndexElement; import org.hibernate.jaxb.spi.hbm.JaxbListIndexElement; +import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding; import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource; import org.hibernate.metamodel.spi.source.PluralAttributeIndexSource; import org.hibernate.metamodel.spi.source.RelationalValueSource; @@ -136,14 +137,14 @@ public class ListAttributeIndexSource extends AbstractHbmSourceNode implements P public boolean areValuesNullableByDefault() { return false; } - + @Override public int base() { return base; } @Override - public Nature getNature() { - return Nature.BASIC; + public PluralAttributeIndexBinding.Nature getNature() { + return PluralAttributeIndexBinding.Nature.BASIC; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/MapAttributeIndexSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/MapAttributeIndexSource.java index 5fa1112fc3..82b58a3ec5 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/MapAttributeIndexSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/MapAttributeIndexSource.java @@ -29,6 +29,7 @@ import java.util.Map; import org.hibernate.jaxb.spi.hbm.JaxbColumnElement; import org.hibernate.jaxb.spi.hbm.JaxbIndexElement; import org.hibernate.jaxb.spi.hbm.JaxbMapKeyElement; +import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding; import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource; import org.hibernate.metamodel.spi.source.PluralAttributeIndexSource; import org.hibernate.metamodel.spi.source.RelationalValueSource; @@ -37,7 +38,7 @@ import org.hibernate.metamodel.spi.source.RelationalValueSource; * */ public class MapAttributeIndexSource extends AbstractHbmSourceNode implements PluralAttributeIndexSource { - private final Nature nature; + private final PluralAttributeIndexBinding.Nature nature; private final List valueSources; private final ExplicitHibernateTypeSource typeSource; @@ -97,7 +98,7 @@ public class MapAttributeIndexSource extends AbstractHbmSourceNode implements Pl : java.util.Collections.emptyMap(); } }; - this.nature = Nature.BASIC; + this.nature = PluralAttributeIndexBinding.Nature.BASIC; } public MapAttributeIndexSource(MappingDocument sourceMappingDocument, final JaxbIndexElement indexElement) { @@ -139,7 +140,7 @@ public class MapAttributeIndexSource extends AbstractHbmSourceNode implements Pl } }; - this.nature = Nature.BASIC; + this.nature = PluralAttributeIndexBinding.Nature.BASIC; } @Override @@ -158,7 +159,7 @@ public class MapAttributeIndexSource extends AbstractHbmSourceNode implements Pl } @Override - public Nature getNature() { + public PluralAttributeIndexBinding.Nature getNature() { return nature; } @@ -171,4 +172,9 @@ public class MapAttributeIndexSource extends AbstractHbmSourceNode implements Pl public List relationalValueSources() { return valueSources; } + + @Override + public int base() { + return 0; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/PluralAttributeKeyBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/PluralAttributeKeyBinding.java index 312a523d15..288cbc20fc 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/PluralAttributeKeyBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/PluralAttributeKeyBinding.java @@ -37,14 +37,14 @@ import org.hibernate.metamodel.spi.relational.TableSpecification; */ public class PluralAttributeKeyBinding { private final AbstractPluralAttributeBinding pluralAttributeBinding; - + private final SingularAttributeBinding referencedAttributeBinding; private ForeignKey foreignKey; private boolean inverse; private boolean isIncludedInUpdate; // this knowledge can be implicitly resolved based on the typing information on the referenced owner attribute private final HibernateTypeDescriptor hibernateTypeDescriptor = new HibernateTypeDescriptor(); - private final SingularAttributeBinding referencedAttributeBinding; + // todo : this would be nice to have but we do not always know it, especially in HBM case. // private BasicAttributeBinding otherSide; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/Orderable.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/Orderable.java index 05ceb0007b..15add5c397 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/Orderable.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/Orderable.java @@ -24,9 +24,20 @@ package org.hibernate.metamodel.spi.source; /** + * Contact to define if a plural attribute source is orderable or not. + * * @author Steve Ebersole */ public interface Orderable { - public boolean isOrdered(); - public String getOrder(); + /** + * If the source of plural attribute is supposed to be applied the order by when loading. + * + * @return true for applying the order by or false means not. + */ + boolean isOrdered(); + + /** + * @return The order by clause used during loading this plural attribute from DB. + */ + String getOrder(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/PluralAttributeIndexSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/PluralAttributeIndexSource.java index 58851d01d4..ce99eba611 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/PluralAttributeIndexSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/PluralAttributeIndexSource.java @@ -23,24 +23,13 @@ */ package org.hibernate.metamodel.spi.source; +import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding; + /** * */ public interface PluralAttributeIndexSource extends RelationalValueSourceContainer { - Nature getNature(); + PluralAttributeIndexBinding.Nature getNature(); ExplicitHibernateTypeSource explicitHibernateTypeSource(); - - /** - * Describes the nature of the collection indexes as declared by the sources. - * - * @author Steve Ebersole - * - * @see {@link org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding.Nature} - */ - enum Nature { - BASIC, - COMPOSITE, - MANY_TO_MANY, - MANY_TO_ANY - } + int base(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/Sortable.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/Sortable.java index 966ccc9cdd..bad33ea2e6 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/Sortable.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/Sortable.java @@ -24,10 +24,23 @@ package org.hibernate.metamodel.spi.source; /** + * Contact to define if the source of plural attribute is sortable or not. + * * @author Steve Ebersole */ public interface Sortable { - public boolean isSorted(); - public String getComparatorName(); + /** + * If the source of plural attribute is supposed to be sorted. + * + * @return true the attribute will be sortable or false means not. + */ + boolean isSorted(); + + /** + * The comparator class name which will be used to sort the attribute. + * + * @return Qualified class name which implements {@link java.util.Comparator} contact. + */ + String getComparatorName(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/TableSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/TableSource.java index a3a19adcc3..62f66e9bb4 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/TableSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/TableSource.java @@ -34,5 +34,5 @@ public interface TableSource extends TableSpecificationSource { * * @return The table name, or {@code null} is no name specified. */ - public String getExplicitTableName(); + String getExplicitTableName(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/TypeDescriptorSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/TypeDescriptorSource.java index ba7ff6329b..1d3898b786 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/TypeDescriptorSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/TypeDescriptorSource.java @@ -37,7 +37,7 @@ public interface TypeDescriptorSource { * * @return The name. */ - public String getName(); + String getName(); /** * Retrieve the name of the class implementing {@link org.hibernate.type.Type}, @@ -45,7 +45,7 @@ public interface TypeDescriptorSource { * * @return The implementation class name. */ - public String getTypeImplementationClassName(); + String getTypeImplementationClassName(); /** * For what are termed "basic types" there is a registry that contain the type keyed by various @@ -58,7 +58,7 @@ public interface TypeDescriptorSource { * * @return The registration keys for the type built from this type def. */ - public String[] getRegistrationKeys(); + String[] getRegistrationKeys(); /** * Types accept configuration. The values here represent the user supplied values that will be given @@ -66,5 +66,5 @@ public interface TypeDescriptorSource { * * @return The configuration parameters from the underlying source. */ - public Map getParameters(); + Map getParameters(); } diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/entity/OneToManyBindingTest.java b/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/entity/OneToManyBindingTest.java index b8d03afaf2..60ced5a9a0 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/entity/OneToManyBindingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/entity/OneToManyBindingTest.java @@ -25,13 +25,18 @@ package org.hibernate.metamodel.internal.source.annotations.entity; import org.junit.Test; +import org.hibernate.metamodel.spi.binding.AttributeBinding; import org.hibernate.metamodel.spi.binding.EntityBinding; +import org.hibernate.metamodel.spi.binding.HibernateTypeDescriptor; +import org.hibernate.metamodel.spi.binding.PluralAttributeBinding; import org.hibernate.test.annotations.loader.Player; import org.hibernate.test.annotations.loader.Team; import org.hibernate.testing.junit4.BaseAnnotationBindingTestCase; import org.hibernate.testing.junit4.Resources; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; /** * @author Strong Liu @@ -43,7 +48,19 @@ public class OneToManyBindingTest extends BaseAnnotationBindingTestCase { EntityBinding playerBinding = getEntityBinding( Player.class ); assertNotNull( playerBinding ); + AttributeBinding attributeBinding = playerBinding.locateAttributeBinding( "team" ); + assertTrue( attributeBinding.isAssociation() ); + + HibernateTypeDescriptor typeDescriptor = attributeBinding.getHibernateTypeDescriptor(); + EntityBinding teamBinding = getEntityBinding( Team.class ); assertNotNull( teamBinding ); + attributeBinding = teamBinding.locateAttributeBinding( "players" ); + assertTrue( attributeBinding.isAssociation() ); + typeDescriptor = attributeBinding.getHibernateTypeDescriptor(); + + PluralAttributeBinding pluralAttributeBinding = PluralAttributeBinding.class.cast( attributeBinding ); + + } }