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
* 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<String> values = new ArrayList<String>();
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<String> 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() {

View File

@ -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;
/**

View File

@ -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,

View File

@ -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;

View File

@ -78,7 +78,7 @@ public abstract class AbstractHbmAttributeBindingState implements AttributeBindi
}
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<CascadeType> cascadeTypes = new HashSet<CascadeType>( cascades.size() );
for ( String s : cascades ) {

View File

@ -50,7 +50,7 @@ public class HbmDiscriminatorBindingState
XMLHibernateMapping.XMLClass xmlEntityClazz) {
super(
ownerClassName,
bindingContext.getMappingDefaults().getDefaultDiscriminatorColumnName(),
bindingContext.getMappingDefaults().getDiscriminatorColumnName(),
bindingContext,
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.
lazy = MappingHelper.getBooleanValue(
entityClazz.isLazy(), bindingContext.getMappingDefaults().isDefaultLazy()
entityClazz.isLazy(), bindingContext.getMappingDefaults().areAssociationsLazy()
);
mutable = entityClazz.isMutable();

View File

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

View File

@ -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()
);
}

View File

@ -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();

View File

@ -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<String, MetaAttribute> getMappingMetas() {
return Collections.emptyMap();
}
}
}

View File

@ -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<String, MetaAttribute> getMappingMetas() {
return null; // todo : implement method body
public boolean areAssociationsLazy() {
return associationLaziness == null ? overriddenValues.areAssociationsLazy() : associationLaziness;
}
}

View File

@ -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<String, MetaAttribute> getMappingMetas();
/**
* Identifies whether associations are lazy by default if not specified in the mapping.
*
* @return The default association laziness
*/
public boolean areAssociationsLazy();
}

View File

@ -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