diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/domain/MetaAttribute.java b/hibernate-core/src/main/java/org/hibernate/metamodel/binding/MetaAttribute.java similarity index 82% rename from hibernate-core/src/main/java/org/hibernate/metamodel/domain/MetaAttribute.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/binding/MetaAttribute.java index 9644ac6758..18babda0e3 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/domain/MetaAttribute.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/binding/MetaAttribute.java @@ -21,11 +21,12 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.domain; +package org.hibernate.metamodel.binding; import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; +import java.util.List; /** * A meta attribute is a named value or values. @@ -33,11 +34,8 @@ import java.util.Collections; * @author Gavin King */ public class MetaAttribute implements Serializable { - - // todo : this really belongs in the binding package - - private String name; - private java.util.List values = new ArrayList(); + private final String name; + private List values = new ArrayList(); public MetaAttribute(String name) { this.name = name; @@ -47,19 +45,19 @@ public class MetaAttribute implements Serializable { return name; } - public java.util.List getValues() { + public List getValues() { return Collections.unmodifiableList(values); } public void addValue(String value) { - values.add(value); + values.add( value ); } public String getValue() { - if ( values.size()!=1 ) { - throw new IllegalStateException("no unique value"); + if ( values.size() != 1 ) { + throw new IllegalStateException( "no unique value" ); } - return (String) values.get(0); + return values.get( 0 ); } public boolean isMultiValued() { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/binding/state/AttributeBindingState.java b/hibernate-core/src/main/java/org/hibernate/metamodel/binding/state/AttributeBindingState.java index 4803da6b8d..d1ab828718 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/binding/state/AttributeBindingState.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/binding/state/AttributeBindingState.java @@ -27,7 +27,6 @@ import java.util.Map; import java.util.Set; import org.hibernate.metamodel.binding.CascadeType; -import org.hibernate.metamodel.domain.MetaAttribute; import org.hibernate.metamodel.source.spi.MetaAttributeContext; /** diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/AbstractEntityBinder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/AbstractEntityBinder.java index b20b4b4d09..0ba10e8905 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/AbstractEntityBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/AbstractEntityBinder.java @@ -23,13 +23,9 @@ */ package org.hibernate.metamodel.source.hbm; -import org.dom4j.Attribute; - import org.hibernate.AssertionFailure; import org.hibernate.EntityMode; -import org.hibernate.MappingException; import org.hibernate.cfg.NamingStrategy; -import org.hibernate.engine.internal.Versioning; import org.hibernate.internal.util.StringHelper; import org.hibernate.metamodel.binding.AttributeBinding; import org.hibernate.metamodel.binding.BagBinding; @@ -78,7 +74,6 @@ import org.hibernate.metamodel.binding.state.PluralAttributeBindingState; import org.hibernate.metamodel.binding.state.SimpleAttributeBindingState; import org.hibernate.metamodel.relational.state.TupleRelationalState; import org.hibernate.metamodel.relational.state.ValueRelationalState; -import org.hibernate.metamodel.source.spi.BindingContext; import org.hibernate.metamodel.source.spi.MetadataImplementor; /** @@ -94,10 +89,10 @@ abstract class AbstractEntityBinder { this.bindingContext = bindingContext; this.schemaName = new Schema.Name( entityClazz.getSchema() == null - ? bindingContext.getMappingDefaults().getDefaultSchemaName() + ? bindingContext.getMappingDefaults().getSchemaName() : entityClazz.getSchema(), entityClazz.getCatalog() == null - ? bindingContext.getMappingDefaults().getDefaultCatalogName() : + ? bindingContext.getMappingDefaults().getCatalogName() : entityClazz.getCatalog() ); } @@ -152,7 +147,7 @@ abstract class AbstractEntityBinder { } protected String getDefaultAccess() { - return bindingContext.getMappingDefaults().getDefaultAccess(); + return bindingContext.getMappingDefaults().getPropertyAccessorName(); } private void bindPojoRepresentation(XMLHibernateMapping.XMLClass entityClazz, diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/HbmHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/HbmHelper.java index 2c08f931a5..cd3529c850 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/HbmHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/HbmHelper.java @@ -33,7 +33,7 @@ import org.dom4j.Element; import org.hibernate.MappingException; import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle; import org.hibernate.metamodel.binding.CustomSQL; -import org.hibernate.metamodel.domain.MetaAttribute; +import org.hibernate.metamodel.binding.MetaAttribute; import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping.XMLClass; import org.hibernate.metamodel.source.hbm.xml.mapping.XMLMetaElement; import org.hibernate.metamodel.source.hbm.util.MappingHelper; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/binding/AbstractHbmAttributeBindingState.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/binding/AbstractHbmAttributeBindingState.java index 43cd1215c2..5b8cf038bf 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/binding/AbstractHbmAttributeBindingState.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/binding/AbstractHbmAttributeBindingState.java @@ -78,7 +78,7 @@ public abstract class AbstractHbmAttributeBindingState implements AttributeBindi } protected Set determineCascadeTypes(String cascade) { - String commaSeparatedCascades = MappingHelper.getStringValue( cascade, getBindingContext().getMappingDefaults().getDefaultCascade() ); + String commaSeparatedCascades = MappingHelper.getStringValue( cascade, getBindingContext().getMappingDefaults().getCascadeStyle() ); Set cascades = MappingHelper.getStringValueTokens( commaSeparatedCascades, "," ); Set cascadeTypes = new HashSet( cascades.size() ); for ( String s : cascades ) { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/binding/HbmDiscriminatorBindingState.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/binding/HbmDiscriminatorBindingState.java index d65b055dfa..a52e9dc256 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/binding/HbmDiscriminatorBindingState.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/binding/HbmDiscriminatorBindingState.java @@ -50,7 +50,7 @@ public class HbmDiscriminatorBindingState XMLHibernateMapping.XMLClass xmlEntityClazz) { super( ownerClassName, - bindingContext.getMappingDefaults().getDefaultDiscriminatorColumnName(), + bindingContext.getMappingDefaults().getDiscriminatorColumnName(), bindingContext, null, null, diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/binding/HbmEntityBindingState.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/binding/HbmEntityBindingState.java index cac132dd6a..e1447f5889 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/binding/HbmEntityBindingState.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/binding/HbmEntityBindingState.java @@ -92,7 +92,7 @@ public class HbmEntityBindingState implements EntityBindingState { // go ahead and set the lazy here, since pojo.proxy can override it. lazy = MappingHelper.getBooleanValue( - entityClazz.isLazy(), bindingContext.getMappingDefaults().isDefaultLazy() + entityClazz.isLazy(), bindingContext.getMappingDefaults().areAssociationsLazy() ); mutable = entityClazz.isMutable(); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/binding/HbmManyToOneAttributeBindingState.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/binding/HbmManyToOneAttributeBindingState.java index 7087ff647d..d402c1cf9f 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/binding/HbmManyToOneAttributeBindingState.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/binding/HbmManyToOneAttributeBindingState.java @@ -67,7 +67,7 @@ public class HbmManyToOneAttributeBindingState HbmHelper.getPropertyAccessorName( manyToOne.getAccess(), manyToOne.isEmbedXml(), - bindingContext.getMappingDefaults().getDefaultAccess() + bindingContext.getMappingDefaults().getPropertyAccessorName() ), manyToOne.isOptimisticLock() ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/binding/HbmPluralAttributeBindingState.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/binding/HbmPluralAttributeBindingState.java index 4662ad2021..bef4ac5152 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/binding/HbmPluralAttributeBindingState.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/binding/HbmPluralAttributeBindingState.java @@ -65,7 +65,7 @@ public class HbmPluralAttributeBindingState extends AbstractHbmAttributeBindingS collection.getNode(), HbmHelper.extractMetaAttributeContext( collection.getMeta(), parentMetaAttributeContext ), HbmHelper.getPropertyAccessorName( - collection.getAccess(), collection.isEmbedXml(), bindingContext.getMappingDefaults().getDefaultAccess() + collection.getAccess(), collection.isEmbedXml(), bindingContext.getMappingDefaults().getPropertyAccessorName() ), collection.isOptimisticLock() ); @@ -117,7 +117,7 @@ public class HbmPluralAttributeBindingState extends AbstractHbmAttributeBindingS public boolean isLazy() { return isExtraLazy() || MappingHelper.getBooleanValue( - collection.getLazy().value(), getBindingContext().getMappingDefaults().isDefaultLazy() + collection.getLazy().value(), getBindingContext().getMappingDefaults().areAssociationsLazy() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/binding/HbmSimpleAttributeBindingState.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/binding/HbmSimpleAttributeBindingState.java index 47ec65ee38..c9f66109aa 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/binding/HbmSimpleAttributeBindingState.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/binding/HbmSimpleAttributeBindingState.java @@ -62,11 +62,11 @@ public class HbmSimpleAttributeBindingState extends AbstractHbmAttributeBindingS XMLId id) { super( ownerClassName, - id.getName() != null ? id.getName() : bindingContext.getMappingDefaults().getDefaultIdColumnName(), + id.getName() != null ? id.getName() : bindingContext.getMappingDefaults().getIdColumnName(), bindingContext, id.getNode(), HbmHelper.extractMetaAttributeContext( id.getMeta(), parentMetaAttributeContext ), - HbmHelper.getPropertyAccessorName( id.getAccess(), false, bindingContext.getMappingDefaults().getDefaultAccess() ), + HbmHelper.getPropertyAccessorName( id.getAccess(), false, bindingContext.getMappingDefaults().getPropertyAccessorName() ), true ); @@ -109,7 +109,7 @@ public class HbmSimpleAttributeBindingState extends AbstractHbmAttributeBindingS bindingContext, version.getNode(), HbmHelper.extractMetaAttributeContext( version.getMeta(), parentMetaAttributeContext ), - HbmHelper.getPropertyAccessorName( version.getAccess(), false, bindingContext.getMappingDefaults().getDefaultAccess() ), + HbmHelper.getPropertyAccessorName( version.getAccess(), false, bindingContext.getMappingDefaults().getPropertyAccessorName() ), true ); this.typeName = version.getType() == null ? "integer" : version.getType(); @@ -139,7 +139,7 @@ public class HbmSimpleAttributeBindingState extends AbstractHbmAttributeBindingS bindingContext, timestamp.getNode(), HbmHelper.extractMetaAttributeContext( timestamp.getMeta(), parentMetaAttributeContext ), - HbmHelper.getPropertyAccessorName( timestamp.getAccess(), false, bindingContext.getMappingDefaults().getDefaultAccess() ), + HbmHelper.getPropertyAccessorName( timestamp.getAccess(), false, bindingContext.getMappingDefaults().getPropertyAccessorName() ), true ); @@ -169,7 +169,7 @@ public class HbmSimpleAttributeBindingState extends AbstractHbmAttributeBindingS bindingContext, property.getNode(), HbmHelper.extractMetaAttributeContext( property.getMeta(), parentMetaAttributeContext ), - HbmHelper.getPropertyAccessorName( property.getAccess(), false, bindingContext.getMappingDefaults().getDefaultAccess() ), + HbmHelper.getPropertyAccessorName( property.getAccess(), false, bindingContext.getMappingDefaults().getPropertyAccessorName() ), property.isOptimisticLock() ); this.isLazy = property.isLazy(); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/MetadataImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/MetadataImpl.java index 29cf6993bf..8a977c560d 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/MetadataImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/MetadataImpl.java @@ -25,7 +25,6 @@ package org.hibernate.metamodel.source.internal; import java.io.Serializable; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -52,7 +51,6 @@ import org.hibernate.metamodel.binding.FetchProfile; import org.hibernate.metamodel.binding.IdGenerator; import org.hibernate.metamodel.binding.PluralAttributeBinding; import org.hibernate.metamodel.binding.TypeDef; -import org.hibernate.metamodel.domain.MetaAttribute; import org.hibernate.metamodel.relational.AuxiliaryDatabaseObject; import org.hibernate.metamodel.relational.Database; import org.hibernate.metamodel.source.annotations.AnnotationBinder; @@ -484,43 +482,38 @@ public class MetadataImpl implements MetadataImplementor, Serializable { } @Override - public String getDefaultSchemaName() { + public String getSchemaName() { return options.getDefaultSchemaName(); } @Override - public String getDefaultCatalogName() { + public String getCatalogName() { return options.getDefaultCatalogName(); } @Override - public String getDefaultIdColumnName() { + public String getIdColumnName() { return DEFAULT_IDENTIFIER_COLUMN_NAME; } @Override - public String getDefaultDiscriminatorColumnName() { + public String getDiscriminatorColumnName() { return DEFAULT_DISCRIMINATOR_COLUMN_NAME; } @Override - public String getDefaultCascade() { + public String getCascadeStyle() { return DEFAULT_CASCADE; } @Override - public String getDefaultAccess() { + public String getPropertyAccessorName() { return DEFAULT_PROPERTY_ACCESS; } @Override - public boolean isDefaultLazy() { + public boolean areAssociationsLazy() { return true; } - - @Override - public Map getMappingMetas() { - return Collections.emptyMap(); - } } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/OverriddenMappingDefaults.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/OverriddenMappingDefaults.java index 14fbabc782..b94256b8ad 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/OverriddenMappingDefaults.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/OverriddenMappingDefaults.java @@ -23,14 +23,11 @@ */ package org.hibernate.metamodel.source.internal; -import java.util.Map; - -import org.hibernate.cfg.NamingStrategy; -import org.hibernate.metamodel.domain.MetaAttribute; import org.hibernate.metamodel.source.spi.MappingDefaults; -import org.hibernate.service.ServiceRegistry; /** + * Represents a "nested level" in the mapping defaults stack. + * * @author Steve Ebersole */ public class OverriddenMappingDefaults implements MappingDefaults { @@ -75,42 +72,37 @@ public class OverriddenMappingDefaults implements MappingDefaults { } @Override - public String getDefaultSchemaName() { - return schemaName == null ? overriddenValues.getDefaultSchemaName() : schemaName; + public String getSchemaName() { + return schemaName == null ? overriddenValues.getSchemaName() : schemaName; } @Override - public String getDefaultCatalogName() { - return catalogName == null ? overriddenValues.getDefaultCatalogName() : catalogName; + public String getCatalogName() { + return catalogName == null ? overriddenValues.getCatalogName() : catalogName; } @Override - public String getDefaultIdColumnName() { - return idColumnName == null ? overriddenValues.getDefaultIdColumnName() : idColumnName; + public String getIdColumnName() { + return idColumnName == null ? overriddenValues.getIdColumnName() : idColumnName; } @Override - public String getDefaultDiscriminatorColumnName() { - return discriminatorColumnName == null ? overriddenValues.getDefaultDiscriminatorColumnName() : discriminatorColumnName; + public String getDiscriminatorColumnName() { + return discriminatorColumnName == null ? overriddenValues.getDiscriminatorColumnName() : discriminatorColumnName; } @Override - public String getDefaultCascade() { - return cascade == null ? overriddenValues.getDefaultCascade() : cascade; + public String getCascadeStyle() { + return cascade == null ? overriddenValues.getCascadeStyle() : cascade; } @Override - public String getDefaultAccess() { - return propertyAccess == null ? overriddenValues.getDefaultAccess() : propertyAccess; + public String getPropertyAccessorName() { + return propertyAccess == null ? overriddenValues.getPropertyAccessorName() : propertyAccess; } @Override - public boolean isDefaultLazy() { - return associationLaziness == null ? overriddenValues.isDefaultLazy() : associationLaziness; - } - - @Override - public Map getMappingMetas() { - return null; // todo : implement method body + public boolean areAssociationsLazy() { + return associationLaziness == null ? overriddenValues.areAssociationsLazy() : associationLaziness; } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/MappingDefaults.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/MappingDefaults.java index d71acbf813..8dd1ebd98f 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/MappingDefaults.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/MappingDefaults.java @@ -23,36 +23,70 @@ */ package org.hibernate.metamodel.source.spi; -import java.util.Map; - -import org.hibernate.cfg.NamingStrategy; -import org.hibernate.metamodel.domain.MetaAttribute; -import org.hibernate.service.ServiceRegistry; - /** + * Defines a (contextual) set of values to use as defaults in the absence of related mapping information. The + * context here is conceptually a stack. The "global" level is configuration settings. + * * @author Gail Badner * @author Steve Ebersole */ public interface MappingDefaults { + /** + * Identifies the default package name to use if none specified in the mapping. Really only pertinent for + * {@code hbm.xml} mappings. + * + * @return The default package name. + */ + public String getPackageName(); - String getPackageName(); + /** + * Identifies the default database schema name to use if none specified in the mapping. + * + * @return The default schema name + */ + public String getSchemaName(); - String getDefaultSchemaName(); + /** + * Identifies the default database catalog name to use if none specified in the mapping. + * + * @return The default catalog name + */ + public String getCatalogName(); - String getDefaultCatalogName(); + /** + * Identifies the default column name to use for the identifier column if none specified in the mapping. + * + * @return The default identifier column name + */ + public String getIdColumnName(); - String getDefaultIdColumnName(); + /** + * Identifies the default column name to use for the discriminator column if none specified in the mapping. + * + * @return The default discriminator column name + */ + public String getDiscriminatorColumnName(); - String getDefaultDiscriminatorColumnName(); + /** + * Identifies the default cascade style to apply to associations if none specified in the mapping. + * + * @return The default cascade style + */ + public String getCascadeStyle(); - String getDefaultCascade(); + /** + * Identifies the default {@link org.hibernate.property.PropertyAccessor} name to use if none specified in the + * mapping. + * + * @return The default property accessor name + * @see org.hibernate.property.PropertyAccessorFactory + */ + public String getPropertyAccessorName(); - String getDefaultAccess(); - - boolean isDefaultLazy(); - - - // Not happy about these here ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - Map getMappingMetas(); + /** + * Identifies whether associations are lazy by default if not specified in the mapping. + * + * @return The default association laziness + */ + public boolean areAssociationsLazy(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/MetaAttributeContext.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/MetaAttributeContext.java index decafeeb24..c7d744fa5a 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/MetaAttributeContext.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/MetaAttributeContext.java @@ -27,7 +27,7 @@ import java.util.HashSet; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import org.hibernate.metamodel.domain.MetaAttribute; +import org.hibernate.metamodel.binding.MetaAttribute; /** * @author Steve Ebersole