HHH-6229 - Clean up MappingDefaults

This commit is contained in:
Steve Ebersole 2011-06-08 10:53:18 -05:00
parent 6d52bcff6b
commit 98e7f9537f
14 changed files with 102 additions and 91 deletions

View File

@ -21,11 +21,12 @@
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.metamodel.domain; package org.hibernate.metamodel.binding;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List;
/** /**
* A meta attribute is a named value or values. * A meta attribute is a named value or values.
@ -33,11 +34,8 @@ import java.util.Collections;
* @author Gavin King * @author Gavin King
*/ */
public class MetaAttribute implements Serializable { public class MetaAttribute implements Serializable {
private final String name;
// todo : this really belongs in the binding package private List<String> values = new ArrayList<String>();
private String name;
private java.util.List values = new ArrayList();
public MetaAttribute(String name) { public MetaAttribute(String name) {
this.name = name; this.name = name;
@ -47,19 +45,19 @@ public class MetaAttribute implements Serializable {
return name; return name;
} }
public java.util.List getValues() { public List<String> getValues() {
return Collections.unmodifiableList(values); return Collections.unmodifiableList(values);
} }
public void addValue(String value) { public void addValue(String value) {
values.add(value); values.add( value );
} }
public String getValue() { public String getValue() {
if ( values.size()!=1 ) { if ( values.size() != 1 ) {
throw new IllegalStateException("no unique value"); throw new IllegalStateException( "no unique value" );
} }
return (String) values.get(0); return values.get( 0 );
} }
public boolean isMultiValued() { public boolean isMultiValued() {

View File

@ -27,7 +27,6 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import org.hibernate.metamodel.binding.CascadeType; import org.hibernate.metamodel.binding.CascadeType;
import org.hibernate.metamodel.domain.MetaAttribute;
import org.hibernate.metamodel.source.spi.MetaAttributeContext; import org.hibernate.metamodel.source.spi.MetaAttributeContext;
/** /**

View File

@ -23,13 +23,9 @@
*/ */
package org.hibernate.metamodel.source.hbm; package org.hibernate.metamodel.source.hbm;
import org.dom4j.Attribute;
import org.hibernate.AssertionFailure; import org.hibernate.AssertionFailure;
import org.hibernate.EntityMode; import org.hibernate.EntityMode;
import org.hibernate.MappingException;
import org.hibernate.cfg.NamingStrategy; import org.hibernate.cfg.NamingStrategy;
import org.hibernate.engine.internal.Versioning;
import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.StringHelper;
import org.hibernate.metamodel.binding.AttributeBinding; import org.hibernate.metamodel.binding.AttributeBinding;
import org.hibernate.metamodel.binding.BagBinding; 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.binding.state.SimpleAttributeBindingState;
import org.hibernate.metamodel.relational.state.TupleRelationalState; import org.hibernate.metamodel.relational.state.TupleRelationalState;
import org.hibernate.metamodel.relational.state.ValueRelationalState; import org.hibernate.metamodel.relational.state.ValueRelationalState;
import org.hibernate.metamodel.source.spi.BindingContext;
import org.hibernate.metamodel.source.spi.MetadataImplementor; import org.hibernate.metamodel.source.spi.MetadataImplementor;
/** /**
@ -94,10 +89,10 @@ abstract class AbstractEntityBinder {
this.bindingContext = bindingContext; this.bindingContext = bindingContext;
this.schemaName = new Schema.Name( this.schemaName = new Schema.Name(
entityClazz.getSchema() == null entityClazz.getSchema() == null
? bindingContext.getMappingDefaults().getDefaultSchemaName() ? bindingContext.getMappingDefaults().getSchemaName()
: entityClazz.getSchema(), : entityClazz.getSchema(),
entityClazz.getCatalog() == null entityClazz.getCatalog() == null
? bindingContext.getMappingDefaults().getDefaultCatalogName() : ? bindingContext.getMappingDefaults().getCatalogName() :
entityClazz.getCatalog() entityClazz.getCatalog()
); );
} }
@ -152,7 +147,7 @@ abstract class AbstractEntityBinder {
} }
protected String getDefaultAccess() { protected String getDefaultAccess() {
return bindingContext.getMappingDefaults().getDefaultAccess(); return bindingContext.getMappingDefaults().getPropertyAccessorName();
} }
private void bindPojoRepresentation(XMLHibernateMapping.XMLClass entityClazz, private void bindPojoRepresentation(XMLHibernateMapping.XMLClass entityClazz,

View File

@ -33,7 +33,7 @@ import org.dom4j.Element;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle; import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle;
import org.hibernate.metamodel.binding.CustomSQL; 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.XMLHibernateMapping.XMLClass;
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLMetaElement; import org.hibernate.metamodel.source.hbm.xml.mapping.XMLMetaElement;
import org.hibernate.metamodel.source.hbm.util.MappingHelper; import org.hibernate.metamodel.source.hbm.util.MappingHelper;

View File

@ -78,7 +78,7 @@ public abstract class AbstractHbmAttributeBindingState implements AttributeBindi
} }
protected Set<CascadeType> determineCascadeTypes(String cascade) { protected Set<CascadeType> determineCascadeTypes(String cascade) {
String commaSeparatedCascades = MappingHelper.getStringValue( cascade, getBindingContext().getMappingDefaults().getDefaultCascade() ); String commaSeparatedCascades = MappingHelper.getStringValue( cascade, getBindingContext().getMappingDefaults().getCascadeStyle() );
Set<String> cascades = MappingHelper.getStringValueTokens( commaSeparatedCascades, "," ); Set<String> cascades = MappingHelper.getStringValueTokens( commaSeparatedCascades, "," );
Set<CascadeType> cascadeTypes = new HashSet<CascadeType>( cascades.size() ); Set<CascadeType> cascadeTypes = new HashSet<CascadeType>( cascades.size() );
for ( String s : cascades ) { for ( String s : cascades ) {

View File

@ -50,7 +50,7 @@ public class HbmDiscriminatorBindingState
XMLHibernateMapping.XMLClass xmlEntityClazz) { XMLHibernateMapping.XMLClass xmlEntityClazz) {
super( super(
ownerClassName, ownerClassName,
bindingContext.getMappingDefaults().getDefaultDiscriminatorColumnName(), bindingContext.getMappingDefaults().getDiscriminatorColumnName(),
bindingContext, bindingContext,
null, null,
null, null,

View File

@ -92,7 +92,7 @@ public class HbmEntityBindingState implements EntityBindingState {
// go ahead and set the lazy here, since pojo.proxy can override it. // go ahead and set the lazy here, since pojo.proxy can override it.
lazy = MappingHelper.getBooleanValue( lazy = MappingHelper.getBooleanValue(
entityClazz.isLazy(), bindingContext.getMappingDefaults().isDefaultLazy() entityClazz.isLazy(), bindingContext.getMappingDefaults().areAssociationsLazy()
); );
mutable = entityClazz.isMutable(); mutable = entityClazz.isMutable();

View File

@ -67,7 +67,7 @@ public class HbmManyToOneAttributeBindingState
HbmHelper.getPropertyAccessorName( HbmHelper.getPropertyAccessorName(
manyToOne.getAccess(), manyToOne.getAccess(),
manyToOne.isEmbedXml(), manyToOne.isEmbedXml(),
bindingContext.getMappingDefaults().getDefaultAccess() bindingContext.getMappingDefaults().getPropertyAccessorName()
), ),
manyToOne.isOptimisticLock() manyToOne.isOptimisticLock()
); );

View File

@ -65,7 +65,7 @@ public class HbmPluralAttributeBindingState extends AbstractHbmAttributeBindingS
collection.getNode(), collection.getNode(),
HbmHelper.extractMetaAttributeContext( collection.getMeta(), parentMetaAttributeContext ), HbmHelper.extractMetaAttributeContext( collection.getMeta(), parentMetaAttributeContext ),
HbmHelper.getPropertyAccessorName( HbmHelper.getPropertyAccessorName(
collection.getAccess(), collection.isEmbedXml(), bindingContext.getMappingDefaults().getDefaultAccess() collection.getAccess(), collection.isEmbedXml(), bindingContext.getMappingDefaults().getPropertyAccessorName()
), ),
collection.isOptimisticLock() collection.isOptimisticLock()
); );
@ -117,7 +117,7 @@ public class HbmPluralAttributeBindingState extends AbstractHbmAttributeBindingS
public boolean isLazy() { public boolean isLazy() {
return isExtraLazy() || return isExtraLazy() ||
MappingHelper.getBooleanValue( MappingHelper.getBooleanValue(
collection.getLazy().value(), getBindingContext().getMappingDefaults().isDefaultLazy() collection.getLazy().value(), getBindingContext().getMappingDefaults().areAssociationsLazy()
); );
} }

View File

@ -62,11 +62,11 @@ public class HbmSimpleAttributeBindingState extends AbstractHbmAttributeBindingS
XMLId id) { XMLId id) {
super( super(
ownerClassName, ownerClassName,
id.getName() != null ? id.getName() : bindingContext.getMappingDefaults().getDefaultIdColumnName(), id.getName() != null ? id.getName() : bindingContext.getMappingDefaults().getIdColumnName(),
bindingContext, bindingContext,
id.getNode(), id.getNode(),
HbmHelper.extractMetaAttributeContext( id.getMeta(), parentMetaAttributeContext ), HbmHelper.extractMetaAttributeContext( id.getMeta(), parentMetaAttributeContext ),
HbmHelper.getPropertyAccessorName( id.getAccess(), false, bindingContext.getMappingDefaults().getDefaultAccess() ), HbmHelper.getPropertyAccessorName( id.getAccess(), false, bindingContext.getMappingDefaults().getPropertyAccessorName() ),
true true
); );
@ -109,7 +109,7 @@ public class HbmSimpleAttributeBindingState extends AbstractHbmAttributeBindingS
bindingContext, bindingContext,
version.getNode(), version.getNode(),
HbmHelper.extractMetaAttributeContext( version.getMeta(), parentMetaAttributeContext ), HbmHelper.extractMetaAttributeContext( version.getMeta(), parentMetaAttributeContext ),
HbmHelper.getPropertyAccessorName( version.getAccess(), false, bindingContext.getMappingDefaults().getDefaultAccess() ), HbmHelper.getPropertyAccessorName( version.getAccess(), false, bindingContext.getMappingDefaults().getPropertyAccessorName() ),
true true
); );
this.typeName = version.getType() == null ? "integer" : version.getType(); this.typeName = version.getType() == null ? "integer" : version.getType();
@ -139,7 +139,7 @@ public class HbmSimpleAttributeBindingState extends AbstractHbmAttributeBindingS
bindingContext, bindingContext,
timestamp.getNode(), timestamp.getNode(),
HbmHelper.extractMetaAttributeContext( timestamp.getMeta(), parentMetaAttributeContext ), HbmHelper.extractMetaAttributeContext( timestamp.getMeta(), parentMetaAttributeContext ),
HbmHelper.getPropertyAccessorName( timestamp.getAccess(), false, bindingContext.getMappingDefaults().getDefaultAccess() ), HbmHelper.getPropertyAccessorName( timestamp.getAccess(), false, bindingContext.getMappingDefaults().getPropertyAccessorName() ),
true true
); );
@ -169,7 +169,7 @@ public class HbmSimpleAttributeBindingState extends AbstractHbmAttributeBindingS
bindingContext, bindingContext,
property.getNode(), property.getNode(),
HbmHelper.extractMetaAttributeContext( property.getMeta(), parentMetaAttributeContext ), HbmHelper.extractMetaAttributeContext( property.getMeta(), parentMetaAttributeContext ),
HbmHelper.getPropertyAccessorName( property.getAccess(), false, bindingContext.getMappingDefaults().getDefaultAccess() ), HbmHelper.getPropertyAccessorName( property.getAccess(), false, bindingContext.getMappingDefaults().getPropertyAccessorName() ),
property.isOptimisticLock() property.isOptimisticLock()
); );
this.isLazy = property.isLazy(); this.isLazy = property.isLazy();

View File

@ -25,7 +25,6 @@ package org.hibernate.metamodel.source.internal;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; 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.IdGenerator;
import org.hibernate.metamodel.binding.PluralAttributeBinding; import org.hibernate.metamodel.binding.PluralAttributeBinding;
import org.hibernate.metamodel.binding.TypeDef; import org.hibernate.metamodel.binding.TypeDef;
import org.hibernate.metamodel.domain.MetaAttribute;
import org.hibernate.metamodel.relational.AuxiliaryDatabaseObject; import org.hibernate.metamodel.relational.AuxiliaryDatabaseObject;
import org.hibernate.metamodel.relational.Database; import org.hibernate.metamodel.relational.Database;
import org.hibernate.metamodel.source.annotations.AnnotationBinder; import org.hibernate.metamodel.source.annotations.AnnotationBinder;
@ -484,43 +482,38 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
} }
@Override @Override
public String getDefaultSchemaName() { public String getSchemaName() {
return options.getDefaultSchemaName(); return options.getDefaultSchemaName();
} }
@Override @Override
public String getDefaultCatalogName() { public String getCatalogName() {
return options.getDefaultCatalogName(); return options.getDefaultCatalogName();
} }
@Override @Override
public String getDefaultIdColumnName() { public String getIdColumnName() {
return DEFAULT_IDENTIFIER_COLUMN_NAME; return DEFAULT_IDENTIFIER_COLUMN_NAME;
} }
@Override @Override
public String getDefaultDiscriminatorColumnName() { public String getDiscriminatorColumnName() {
return DEFAULT_DISCRIMINATOR_COLUMN_NAME; return DEFAULT_DISCRIMINATOR_COLUMN_NAME;
} }
@Override @Override
public String getDefaultCascade() { public String getCascadeStyle() {
return DEFAULT_CASCADE; return DEFAULT_CASCADE;
} }
@Override @Override
public String getDefaultAccess() { public String getPropertyAccessorName() {
return DEFAULT_PROPERTY_ACCESS; return DEFAULT_PROPERTY_ACCESS;
} }
@Override @Override
public boolean isDefaultLazy() { public boolean areAssociationsLazy() {
return true; return true;
} }
@Override
public Map<String, MetaAttribute> getMappingMetas() {
return Collections.emptyMap();
}
} }
} }

View File

@ -23,14 +23,11 @@
*/ */
package org.hibernate.metamodel.source.internal; 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.metamodel.source.spi.MappingDefaults;
import org.hibernate.service.ServiceRegistry;
/** /**
* Represents a "nested level" in the mapping defaults stack.
*
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class OverriddenMappingDefaults implements MappingDefaults { public class OverriddenMappingDefaults implements MappingDefaults {
@ -75,42 +72,37 @@ public class OverriddenMappingDefaults implements MappingDefaults {
} }
@Override @Override
public String getDefaultSchemaName() { public String getSchemaName() {
return schemaName == null ? overriddenValues.getDefaultSchemaName() : schemaName; return schemaName == null ? overriddenValues.getSchemaName() : schemaName;
} }
@Override @Override
public String getDefaultCatalogName() { public String getCatalogName() {
return catalogName == null ? overriddenValues.getDefaultCatalogName() : catalogName; return catalogName == null ? overriddenValues.getCatalogName() : catalogName;
} }
@Override @Override
public String getDefaultIdColumnName() { public String getIdColumnName() {
return idColumnName == null ? overriddenValues.getDefaultIdColumnName() : idColumnName; return idColumnName == null ? overriddenValues.getIdColumnName() : idColumnName;
} }
@Override @Override
public String getDefaultDiscriminatorColumnName() { public String getDiscriminatorColumnName() {
return discriminatorColumnName == null ? overriddenValues.getDefaultDiscriminatorColumnName() : discriminatorColumnName; return discriminatorColumnName == null ? overriddenValues.getDiscriminatorColumnName() : discriminatorColumnName;
} }
@Override @Override
public String getDefaultCascade() { public String getCascadeStyle() {
return cascade == null ? overriddenValues.getDefaultCascade() : cascade; return cascade == null ? overriddenValues.getCascadeStyle() : cascade;
} }
@Override @Override
public String getDefaultAccess() { public String getPropertyAccessorName() {
return propertyAccess == null ? overriddenValues.getDefaultAccess() : propertyAccess; return propertyAccess == null ? overriddenValues.getPropertyAccessorName() : propertyAccess;
} }
@Override @Override
public boolean isDefaultLazy() { public boolean areAssociationsLazy() {
return associationLaziness == null ? overriddenValues.isDefaultLazy() : associationLaziness; return associationLaziness == null ? overriddenValues.areAssociationsLazy() : associationLaziness;
}
@Override
public Map<String, MetaAttribute> getMappingMetas() {
return null; // todo : implement method body
} }
} }

View File

@ -23,36 +23,70 @@
*/ */
package org.hibernate.metamodel.source.spi; 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 Gail Badner
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public interface MappingDefaults { 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(); /**
* Identifies whether associations are lazy by default if not specified in the mapping.
boolean isDefaultLazy(); *
* @return The default association laziness
*/
// Not happy about these here ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ public boolean areAssociationsLazy();
Map<String, MetaAttribute> getMappingMetas();
} }

View File

@ -27,7 +27,7 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import org.hibernate.metamodel.domain.MetaAttribute; import org.hibernate.metamodel.binding.MetaAttribute;
/** /**
* @author Steve Ebersole * @author Steve Ebersole