HHH-6281 - Basic HbmBinder cleanup
This commit is contained in:
parent
b84ec25b63
commit
e68f4fb085
|
@ -29,6 +29,10 @@ import javax.persistence.SharedCacheMode;
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
import org.hibernate.cache.spi.access.AccessType;
|
import org.hibernate.cache.spi.access.AccessType;
|
||||||
import org.hibernate.cfg.NamingStrategy;
|
import org.hibernate.cfg.NamingStrategy;
|
||||||
|
import org.hibernate.engine.spi.FilterDefinition;
|
||||||
|
import org.hibernate.metamodel.binding.EntityBinding;
|
||||||
|
import org.hibernate.metamodel.binding.IdGenerator;
|
||||||
|
import org.hibernate.metamodel.binding.TypeDef;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
|
@ -43,9 +47,21 @@ public interface Metadata {
|
||||||
public SharedCacheMode getSharedCacheMode();
|
public SharedCacheMode getSharedCacheMode();
|
||||||
public AccessType getDefaultAccessType();
|
public AccessType getDefaultAccessType();
|
||||||
public boolean useNewIdentifierGenerators();
|
public boolean useNewIdentifierGenerators();
|
||||||
|
public String getDefaultSchemaName();
|
||||||
|
public String getDefaultCatalogName();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Options getOptions();
|
public Options getOptions();
|
||||||
|
|
||||||
public SessionFactory buildSessionFactory();
|
public SessionFactory buildSessionFactory();
|
||||||
|
|
||||||
|
public Iterable<EntityBinding> getEntityBindings();
|
||||||
|
|
||||||
|
public EntityBinding getEntityBinding(String entityName);
|
||||||
|
|
||||||
|
public Iterable<TypeDef> getTypeDefinitions();
|
||||||
|
|
||||||
|
public Iterable<FilterDefinition> getFilterDefinitions();
|
||||||
|
|
||||||
|
public IdGenerator getIdGenerator(String name);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,13 +27,11 @@ import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.hibernate.MappingException;
|
import org.hibernate.MappingException;
|
||||||
import org.hibernate.metamodel.binding.state.AttributeBindingState;
|
import org.hibernate.metamodel.binding.state.AttributeBindingState;
|
||||||
import org.hibernate.metamodel.domain.Attribute;
|
import org.hibernate.metamodel.domain.Attribute;
|
||||||
import org.hibernate.metamodel.domain.MetaAttribute;
|
|
||||||
import org.hibernate.metamodel.relational.Column;
|
import org.hibernate.metamodel.relational.Column;
|
||||||
import org.hibernate.metamodel.relational.DerivedValue;
|
import org.hibernate.metamodel.relational.DerivedValue;
|
||||||
import org.hibernate.metamodel.relational.SimpleValue;
|
import org.hibernate.metamodel.relational.SimpleValue;
|
||||||
|
@ -43,6 +41,7 @@ import org.hibernate.metamodel.relational.state.SimpleValueRelationalState;
|
||||||
import org.hibernate.metamodel.relational.state.TupleRelationalState;
|
import org.hibernate.metamodel.relational.state.TupleRelationalState;
|
||||||
import org.hibernate.metamodel.relational.state.ValueCreator;
|
import org.hibernate.metamodel.relational.state.ValueCreator;
|
||||||
import org.hibernate.metamodel.relational.state.ValueRelationalState;
|
import org.hibernate.metamodel.relational.state.ValueRelationalState;
|
||||||
|
import org.hibernate.metamodel.source.spi.MetaAttributeContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO : javadoc
|
* TODO : javadoc
|
||||||
|
@ -66,7 +65,7 @@ public abstract class AbstractAttributeBinding implements AttributeBinding {
|
||||||
// DOM4J specific...
|
// DOM4J specific...
|
||||||
private String nodeName;
|
private String nodeName;
|
||||||
|
|
||||||
private Map<String, MetaAttribute> metaAttributes;
|
private MetaAttributeContext metaAttributeContext;
|
||||||
|
|
||||||
protected AbstractAttributeBinding(EntityBinding entityBinding) {
|
protected AbstractAttributeBinding(EntityBinding entityBinding) {
|
||||||
this.entityBinding = entityBinding;
|
this.entityBinding = entityBinding;
|
||||||
|
@ -81,7 +80,7 @@ public abstract class AbstractAttributeBinding implements AttributeBinding {
|
||||||
cascadeTypes = state.getCascadeTypes();
|
cascadeTypes = state.getCascadeTypes();
|
||||||
optimisticLockable = state.isOptimisticLockable();
|
optimisticLockable = state.isOptimisticLockable();
|
||||||
nodeName = state.getNodeName();
|
nodeName = state.getNodeName();
|
||||||
metaAttributes = state.getMetaAttributes();
|
metaAttributeContext = state.getMetaAttributeContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -158,8 +157,8 @@ public abstract class AbstractAttributeBinding implements AttributeBinding {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, MetaAttribute> getMetaAttributes() {
|
public MetaAttributeContext getMetaAttributeContext() {
|
||||||
return metaAttributes;
|
return metaAttributeContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -23,13 +23,12 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.metamodel.binding;
|
package org.hibernate.metamodel.binding;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.hibernate.metamodel.domain.Attribute;
|
import org.hibernate.metamodel.domain.Attribute;
|
||||||
import org.hibernate.metamodel.domain.MetaAttribute;
|
|
||||||
import org.hibernate.metamodel.relational.SimpleValue;
|
import org.hibernate.metamodel.relational.SimpleValue;
|
||||||
import org.hibernate.metamodel.relational.Value;
|
import org.hibernate.metamodel.relational.Value;
|
||||||
|
import org.hibernate.metamodel.source.spi.MetaAttributeContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The basic contract for binding between an {@link #getAttribute() attribute} and a {@link #getValue() value}
|
* The basic contract for binding between an {@link #getAttribute() attribute} and a {@link #getValue() value}
|
||||||
|
@ -66,11 +65,11 @@ public interface AttributeBinding {
|
||||||
public HibernateTypeDescriptor getHibernateTypeDescriptor();
|
public HibernateTypeDescriptor getHibernateTypeDescriptor();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtain the map of meta attributes associated with this binding
|
* Obtain the meta attributes associated with this binding
|
||||||
*
|
*
|
||||||
* @return The meta attributes
|
* @return The meta attributes
|
||||||
*/
|
*/
|
||||||
public Map<String, MetaAttribute> getMetaAttributes();
|
public MetaAttributeContext getMetaAttributeContext();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return In the case that {@link #getValue()} represents a {@link org.hibernate.metamodel.relational.Tuple} this method
|
* @return In the case that {@link #getValue()} represents a {@link org.hibernate.metamodel.relational.Tuple} this method
|
||||||
|
|
|
@ -35,17 +35,17 @@ import org.hibernate.MappingException;
|
||||||
import org.hibernate.engine.internal.Versioning;
|
import org.hibernate.engine.internal.Versioning;
|
||||||
import org.hibernate.internal.util.ReflectHelper;
|
import org.hibernate.internal.util.ReflectHelper;
|
||||||
import org.hibernate.metamodel.domain.Entity;
|
import org.hibernate.metamodel.domain.Entity;
|
||||||
import org.hibernate.metamodel.domain.MetaAttribute;
|
|
||||||
import org.hibernate.metamodel.relational.Column;
|
import org.hibernate.metamodel.relational.Column;
|
||||||
import org.hibernate.metamodel.relational.TableSpecification;
|
import org.hibernate.metamodel.relational.TableSpecification;
|
||||||
import org.hibernate.metamodel.source.hbm.HbmHelper;
|
import org.hibernate.metamodel.source.hbm.HbmHelper;
|
||||||
import org.hibernate.metamodel.source.hbm.MappingDefaults;
|
import org.hibernate.metamodel.source.hbm.util.MappingHelper;
|
||||||
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.XMLSqlDeleteElement;
|
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSqlDeleteElement;
|
||||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSqlInsertElement;
|
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSqlInsertElement;
|
||||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSqlUpdateElement;
|
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSqlUpdateElement;
|
||||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSynchronizeElement;
|
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSynchronizeElement;
|
||||||
import org.hibernate.metamodel.source.hbm.util.MappingHelper;
|
import org.hibernate.metamodel.source.spi.BindingContext;
|
||||||
|
import org.hibernate.metamodel.source.spi.MetaAttributeContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides the link between the domain and the relational model for an entity.
|
* Provides the link between the domain and the relational model for an entity.
|
||||||
|
@ -68,7 +68,7 @@ public class EntityBinding {
|
||||||
|
|
||||||
private Caching caching;
|
private Caching caching;
|
||||||
|
|
||||||
private Map<String, MetaAttribute> metaAttributes;
|
private MetaAttributeContext metaAttributeContext;
|
||||||
|
|
||||||
private String proxyInterfaceName;
|
private String proxyInterfaceName;
|
||||||
private boolean lazy;
|
private boolean lazy;
|
||||||
|
@ -95,12 +95,14 @@ public class EntityBinding {
|
||||||
private List<String> synchronizedTableNames;
|
private List<String> synchronizedTableNames;
|
||||||
|
|
||||||
// TODO: change to intialize from Doimain
|
// TODO: change to intialize from Doimain
|
||||||
public void fromHbmXml(MappingDefaults defaults, XMLClass entityClazz, Entity entity) {
|
public void fromHbmXml(BindingContext bindingContext, XMLClass entityClazz, Entity entity) {
|
||||||
this.entity = entity;
|
this.entity = entity;
|
||||||
metaAttributes = HbmHelper.extractMetas( entityClazz.getMeta(), true, defaults.getMappingMetas() );
|
metaAttributeContext = HbmHelper.extractMetaAttributeContext( entityClazz.getMeta(), true, bindingContext.getMetaAttributeContext() );
|
||||||
|
|
||||||
// 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( entityClazz.isLazy(), defaults.isDefaultLazy() );
|
lazy = MappingHelper.getBooleanValue(
|
||||||
|
entityClazz.isLazy(), bindingContext.getMappingDefaults().isDefaultLazy()
|
||||||
|
);
|
||||||
proxyInterfaceName = entityClazz.getProxy();
|
proxyInterfaceName = entityClazz.getProxy();
|
||||||
dynamicUpdate = entityClazz.isDynamicUpdate();
|
dynamicUpdate = entityClazz.isDynamicUpdate();
|
||||||
dynamicInsert = entityClazz.isDynamicInsert();
|
dynamicInsert = entityClazz.isDynamicInsert();
|
||||||
|
@ -295,12 +297,8 @@ public class EntityBinding {
|
||||||
this.caching = caching;
|
this.caching = caching;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, MetaAttribute> getMetaAttributes() {
|
public MetaAttributeContext getMetaAttributeContext() {
|
||||||
return metaAttributes;
|
return metaAttributeContext;
|
||||||
}
|
|
||||||
|
|
||||||
public void setMetaAttributes(Map<String, MetaAttribute> metaAttributes) {
|
|
||||||
this.metaAttributes = metaAttributes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isMutable() {
|
public boolean isMutable() {
|
||||||
|
|
|
@ -28,6 +28,7 @@ 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.domain.MetaAttribute;
|
||||||
|
import org.hibernate.metamodel.source.spi.MetaAttributeContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Gail Badner
|
* @author Gail Badner
|
||||||
|
@ -51,5 +52,5 @@ public interface AttributeBindingState {
|
||||||
|
|
||||||
String getNodeName();
|
String getNodeName();
|
||||||
|
|
||||||
Map<String, MetaAttribute> getMetaAttributes();
|
public MetaAttributeContext getMetaAttributeContext();
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,8 +29,8 @@ import java.util.Set;
|
||||||
import org.hibernate.mapping.PropertyGeneration;
|
import org.hibernate.mapping.PropertyGeneration;
|
||||||
import org.hibernate.metamodel.binding.CascadeType;
|
import org.hibernate.metamodel.binding.CascadeType;
|
||||||
import org.hibernate.metamodel.binding.state.SimpleAttributeBindingState;
|
import org.hibernate.metamodel.binding.state.SimpleAttributeBindingState;
|
||||||
import org.hibernate.metamodel.domain.MetaAttribute;
|
|
||||||
import org.hibernate.metamodel.source.annotations.entity.SimpleAttribute;
|
import org.hibernate.metamodel.source.annotations.entity.SimpleAttribute;
|
||||||
|
import org.hibernate.metamodel.source.spi.MetaAttributeContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of the attribute binding state via annotation configuration.
|
* Implementation of the attribute binding state via annotation configuration.
|
||||||
|
@ -117,7 +117,7 @@ public class AttributeBindingStateImpl implements SimpleAttributeBindingState {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, MetaAttribute> getMetaAttributes() {
|
public MetaAttributeContext getMetaAttributeContext() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,8 @@ import org.hibernate.metamodel.source.annotations.entity.SimpleAttribute;
|
||||||
* @author Gail Badner
|
* @author Gail Badner
|
||||||
*/
|
*/
|
||||||
public class DiscriminatorBindingStateImpl
|
public class DiscriminatorBindingStateImpl
|
||||||
extends AttributeBindingStateImpl implements DiscriminatorBindingState {
|
extends AttributeBindingStateImpl
|
||||||
|
implements DiscriminatorBindingState {
|
||||||
private final String discriminatorValue;
|
private final String discriminatorValue;
|
||||||
private final boolean isForced;
|
private final boolean isForced;
|
||||||
private final boolean isInserted;
|
private final boolean isInserted;
|
||||||
|
|
|
@ -92,10 +92,10 @@ abstract class AbstractEntityBinder {
|
||||||
this.hibernateMappingBinder = hibernateMappingBinder;
|
this.hibernateMappingBinder = hibernateMappingBinder;
|
||||||
this.schemaName = new Schema.Name(
|
this.schemaName = new Schema.Name(
|
||||||
( entityClazz.getSchema() == null ?
|
( entityClazz.getSchema() == null ?
|
||||||
hibernateMappingBinder.getDefaultSchemaName() :
|
hibernateMappingBinder.getMappingDefaults().getDefaultSchemaName() :
|
||||||
entityClazz.getSchema() ),
|
entityClazz.getSchema() ),
|
||||||
( entityClazz.getCatalog() == null ?
|
( entityClazz.getCatalog() == null ?
|
||||||
hibernateMappingBinder.getDefaultCatalogName() :
|
hibernateMappingBinder.getMappingDefaults().getDefaultCatalogName() :
|
||||||
entityClazz.getCatalog() )
|
entityClazz.getCatalog() )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -145,7 +145,7 @@ abstract class AbstractEntityBinder {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getDefaultAccess() {
|
protected String getDefaultAccess() {
|
||||||
return hibernateMappingBinder.getDefaultAccess();
|
return hibernateMappingBinder.getMappingDefaults().getDefaultAccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindPojoRepresentation(XMLHibernateMapping.XMLClass entityClazz,
|
private void bindPojoRepresentation(XMLHibernateMapping.XMLClass entityClazz,
|
||||||
|
@ -439,12 +439,13 @@ PrimitiveArray
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected SimpleAttributeBinding bindProperty(XMLPropertyElement property,
|
protected SimpleAttributeBinding bindProperty(
|
||||||
|
XMLPropertyElement property,
|
||||||
EntityBinding entityBinding) {
|
EntityBinding entityBinding) {
|
||||||
SimpleAttributeBindingState bindingState = new HbmSimpleAttributeBindingState(
|
SimpleAttributeBindingState bindingState = new HbmSimpleAttributeBindingState(
|
||||||
entityBinding.getEntity().getPojoEntitySpecifics().getClassName(),
|
entityBinding.getEntity().getPojoEntitySpecifics().getClassName(),
|
||||||
hibernateMappingBinder,
|
hibernateMappingBinder,
|
||||||
entityBinding.getMetaAttributes(),
|
entityBinding.getMetaAttributeContext(),
|
||||||
property
|
property
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -483,8 +484,8 @@ PrimitiveArray
|
||||||
new HbmPluralAttributeBindingState(
|
new HbmPluralAttributeBindingState(
|
||||||
entityBinding.getEntity().getPojoEntitySpecifics().getClassName(),
|
entityBinding.getEntity().getPojoEntitySpecifics().getClassName(),
|
||||||
hibernateMappingBinder,
|
hibernateMappingBinder,
|
||||||
collection,
|
entityBinding.getMetaAttributeContext(),
|
||||||
entityBinding.getMetaAttributes()
|
collection
|
||||||
);
|
);
|
||||||
|
|
||||||
BagBinding collectionBinding = entityBinding.makeBagAttributeBinding(
|
BagBinding collectionBinding = entityBinding.makeBagAttributeBinding(
|
||||||
|
@ -523,7 +524,7 @@ PrimitiveArray
|
||||||
new HbmManyToOneAttributeBindingState(
|
new HbmManyToOneAttributeBindingState(
|
||||||
entityBinding.getEntity().getPojoEntitySpecifics().getClassName(),
|
entityBinding.getEntity().getPojoEntitySpecifics().getClassName(),
|
||||||
hibernateMappingBinder,
|
hibernateMappingBinder,
|
||||||
entityBinding.getMetaAttributes(),
|
entityBinding.getMetaAttributeContext(),
|
||||||
manyToOne
|
manyToOne
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -32,15 +32,13 @@ import java.util.Set;
|
||||||
import org.hibernate.cfg.NamingStrategy;
|
import org.hibernate.cfg.NamingStrategy;
|
||||||
import org.hibernate.engine.spi.FilterDefinition;
|
import org.hibernate.engine.spi.FilterDefinition;
|
||||||
import org.hibernate.internal.util.StringHelper;
|
import org.hibernate.internal.util.StringHelper;
|
||||||
import org.hibernate.metamodel.relational.AuxiliaryDatabaseObject;
|
|
||||||
import org.hibernate.metamodel.binding.FetchProfile;
|
import org.hibernate.metamodel.binding.FetchProfile;
|
||||||
import org.hibernate.metamodel.binding.FetchProfile.Fetch;
|
import org.hibernate.metamodel.binding.FetchProfile.Fetch;
|
||||||
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.BasicAuxiliaryDatabaseObjectImpl;
|
import org.hibernate.metamodel.relational.BasicAuxiliaryDatabaseObjectImpl;
|
||||||
import org.hibernate.metamodel.source.MappingException;
|
import org.hibernate.metamodel.source.MappingException;
|
||||||
import org.hibernate.metamodel.source.Origin;
|
import org.hibernate.metamodel.source.Origin;
|
||||||
import org.hibernate.metamodel.source.hbm.util.MappingHelper;
|
|
||||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLFetchProfileElement;
|
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLFetchProfileElement;
|
||||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLFetchProfileElement.XMLFetch;
|
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLFetchProfileElement.XMLFetch;
|
||||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping;
|
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping;
|
||||||
|
@ -53,6 +51,10 @@ import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSqlQueryElement;
|
||||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSubclassElement;
|
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSubclassElement;
|
||||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLUnionSubclassElement;
|
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLUnionSubclassElement;
|
||||||
import org.hibernate.metamodel.source.internal.JaxbRoot;
|
import org.hibernate.metamodel.source.internal.JaxbRoot;
|
||||||
|
import org.hibernate.metamodel.source.internal.OverriddenMappingDefaults;
|
||||||
|
import org.hibernate.metamodel.source.spi.BindingContext;
|
||||||
|
import org.hibernate.metamodel.source.spi.MappingDefaults;
|
||||||
|
import org.hibernate.metamodel.source.spi.MetaAttributeContext;
|
||||||
import org.hibernate.metamodel.source.spi.MetadataImplementor;
|
import org.hibernate.metamodel.source.spi.MetadataImplementor;
|
||||||
import org.hibernate.service.ServiceRegistry;
|
import org.hibernate.service.ServiceRegistry;
|
||||||
import org.hibernate.service.classloading.spi.ClassLoaderService;
|
import org.hibernate.service.classloading.spi.ClassLoaderService;
|
||||||
|
@ -62,42 +64,45 @@ import org.hibernate.type.Type;
|
||||||
/**
|
/**
|
||||||
* Responsible for performing binding of hbm xml.
|
* Responsible for performing binding of hbm xml.
|
||||||
*/
|
*/
|
||||||
public class HbmBinder implements MappingDefaults {
|
public class HbmBinder implements BindingContext {
|
||||||
private static final String DEFAULT_IDENTIFIER_COLUMN_NAME = "id";
|
|
||||||
private static final String DEFAULT_DISCRIMINATOR_COLUMN_NAME = "class";
|
|
||||||
|
|
||||||
private final JaxbRoot<XMLHibernateMapping> jaxbRoot;
|
private final JaxbRoot<XMLHibernateMapping> jaxbRoot;
|
||||||
private final XMLHibernateMapping hibernateMapping;
|
private final XMLHibernateMapping hibernateMapping;
|
||||||
|
|
||||||
private final String defaultSchemaName;
|
private final MappingDefaults mappingDefaults;
|
||||||
private final String defaultCatalogName;
|
private final MetaAttributeContext metaAttributeContext;
|
||||||
private final String defaultCascade;
|
|
||||||
private final String defaultAccess;
|
|
||||||
private final boolean defaultLazy;
|
|
||||||
private final String packageName;
|
|
||||||
private final boolean autoImport;
|
private final boolean autoImport;
|
||||||
|
|
||||||
private final MetadataImplementor metadata;
|
private final MetadataImplementor metadata;
|
||||||
private final Map<String, MetaAttribute> globalMetas;
|
|
||||||
|
|
||||||
private Map<String, MetaAttribute> mappingMetas;
|
public HbmBinder(MetadataImplementor metadata, JaxbRoot<XMLHibernateMapping> jaxbRoot) {
|
||||||
|
|
||||||
public HbmBinder(MetadataImplementor metadata, Map<String, MetaAttribute> globalMetas, JaxbRoot<XMLHibernateMapping> jaxbRoot) {
|
|
||||||
this.jaxbRoot = jaxbRoot;
|
this.jaxbRoot = jaxbRoot;
|
||||||
this.hibernateMapping = jaxbRoot.getRoot();
|
this.hibernateMapping = jaxbRoot.getRoot();
|
||||||
|
|
||||||
this.metadata = metadata;
|
this.metadata = metadata;
|
||||||
this.globalMetas = globalMetas;
|
|
||||||
|
|
||||||
defaultSchemaName = hibernateMapping.getSchema();
|
this.mappingDefaults = new OverriddenMappingDefaults(
|
||||||
defaultCatalogName = hibernateMapping.getCatalog();
|
metadata.getMappingDefaults(),
|
||||||
defaultCascade = MappingHelper.getStringValue( hibernateMapping.getDefaultCascade(), "none" );
|
hibernateMapping.getPackage(),
|
||||||
defaultAccess = MappingHelper.getStringValue( hibernateMapping.getDefaultAccess(), "property" );
|
hibernateMapping.getSchema(),
|
||||||
defaultLazy = hibernateMapping.isDefaultLazy();
|
hibernateMapping.getCatalog(),
|
||||||
packageName = hibernateMapping.getPackage();
|
null,
|
||||||
|
null,
|
||||||
|
hibernateMapping.getDefaultCascade(),
|
||||||
|
hibernateMapping.getDefaultAccess(),
|
||||||
|
hibernateMapping.isDefaultLazy()
|
||||||
|
);
|
||||||
|
|
||||||
autoImport = hibernateMapping.isAutoImport();
|
autoImport = hibernateMapping.isAutoImport();
|
||||||
|
|
||||||
mappingMetas = HbmHelper.extractMetas( hibernateMapping.getMeta(), true, globalMetas );
|
metaAttributeContext = extractMetaAttributes();
|
||||||
|
}
|
||||||
|
|
||||||
|
private MetaAttributeContext extractMetaAttributes() {
|
||||||
|
return hibernateMapping.getMeta() == null
|
||||||
|
? new MetaAttributeContext( metadata.getMetaAttributeContext() )
|
||||||
|
: HbmHelper.extractMetaAttributeContext( hibernateMapping.getMeta(), true, metadata.getMetaAttributeContext() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public MetadataImplementor getMetadata() {
|
public MetadataImplementor getMetadata() {
|
||||||
|
@ -108,113 +113,62 @@ public class HbmBinder implements MappingDefaults {
|
||||||
return jaxbRoot.getOrigin();
|
return jaxbRoot.getOrigin();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDefaultSchemaName() {
|
|
||||||
return defaultSchemaName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDefaultCatalogName() {
|
|
||||||
return defaultCatalogName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDefaultIdColumnName() {
|
|
||||||
return DEFAULT_IDENTIFIER_COLUMN_NAME;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDefaultDiscriminatorColumnName() {
|
|
||||||
return DEFAULT_DISCRIMINATOR_COLUMN_NAME;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDefaultCascade() {
|
|
||||||
return defaultCascade;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDefaultAccess() {
|
|
||||||
return defaultAccess;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isDefaultLazy() {
|
|
||||||
return defaultLazy;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ServiceRegistry getServiceRegistry() {
|
public ServiceRegistry getServiceRegistry() {
|
||||||
return metadata.getServiceRegistry();
|
return metadata.getServiceRegistry();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public NamingStrategy getNamingStrategy() {
|
public NamingStrategy getNamingStrategy() {
|
||||||
return metadata.getOptions().getNamingStrategy();
|
return metadata.getOptions().getNamingStrategy();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPackageName() {
|
@Override
|
||||||
return packageName;
|
public MappingDefaults getMappingDefaults() {
|
||||||
|
return mappingDefaults;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MetaAttributeContext getMetaAttributeContext() {
|
||||||
|
return metaAttributeContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MetadataImplementor getMetadataImplementor() {
|
||||||
|
return metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isAutoImport() {
|
boolean isAutoImport() {
|
||||||
return autoImport;
|
return autoImport;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, MetaAttribute> getMappingMetas() {
|
|
||||||
return mappingMetas;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void processHibernateMapping() {
|
public void processHibernateMapping() {
|
||||||
// perform bindings with no pre-requisites
|
// no pre-requisites
|
||||||
bindDatabaseObjectDefinitions();
|
bindDatabaseObjectDefinitions();
|
||||||
|
|
||||||
|
// no pre-requisites
|
||||||
bindTypeDefinitions();
|
bindTypeDefinitions();
|
||||||
|
|
||||||
|
// potentially depends on type definitions
|
||||||
bindFilterDefinitions();
|
bindFilterDefinitions();
|
||||||
|
|
||||||
|
// potentially depends on type definitions
|
||||||
bindIdentifierGenerators();
|
bindIdentifierGenerators();
|
||||||
|
|
||||||
if ( hibernateMapping.getClazzOrSubclassOrJoinedSubclass() != null ) {
|
// potentially depends on type definitions and identifier generators
|
||||||
for ( Object clazzOrSubclass : hibernateMapping.getClazzOrSubclassOrJoinedSubclass() ) {
|
bindMappings();
|
||||||
if ( XMLClass.class.isInstance( clazzOrSubclass ) ) {
|
|
||||||
XMLClass clazz =
|
|
||||||
XMLClass.class.cast( clazzOrSubclass );
|
|
||||||
new RootEntityBinder( this, clazz ).process( clazz );
|
|
||||||
}
|
|
||||||
else if ( XMLSubclassElement.class.isInstance( clazzOrSubclass ) ) {
|
|
||||||
// PersistentClass superModel = getSuperclass( mappings, element );
|
|
||||||
// handleSubclass( superModel, mappings, element, inheritedMetas );
|
|
||||||
}
|
|
||||||
else if ( XMLJoinedSubclassElement.class.isInstance( clazzOrSubclass ) ) {
|
|
||||||
// PersistentClass superModel = getSuperclass( mappings, element );
|
|
||||||
// handleJoinedSubclass( superModel, mappings, element, inheritedMetas );
|
|
||||||
}
|
|
||||||
else if ( XMLUnionSubclassElement.class.isInstance( clazzOrSubclass ) ) {
|
|
||||||
// PersistentClass superModel = getSuperclass( mappings, element );
|
|
||||||
// handleUnionSubclass( superModel, mappings, element, inheritedMetas );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new org.hibernate.metamodel.source.MappingException(
|
|
||||||
"unknown type of class or subclass: " +
|
|
||||||
clazzOrSubclass.getClass().getName(), jaxbRoot.getOrigin()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// depends on mappings
|
||||||
bindFetchProfiles();
|
bindFetchProfiles();
|
||||||
|
|
||||||
|
// depends on mappings
|
||||||
bindImports();
|
bindImports();
|
||||||
|
|
||||||
if ( hibernateMapping.getQueryOrSqlQuery() != null ) {
|
// depends on mappings and potentially on type definitions
|
||||||
for ( Object queryOrSqlQuery : hibernateMapping.getQueryOrSqlQuery() ) {
|
bindResultSetMappings();
|
||||||
if ( XMLQueryElement.class.isInstance( queryOrSqlQuery ) ) {
|
|
||||||
// bindNamedQuery( element, null, mappings );
|
// depends on mappings and potentially on type definitions and result set mappings
|
||||||
}
|
bindNamedQueries();
|
||||||
else if ( XMLSqlQueryElement.class.isInstance( queryOrSqlQuery ) ) {
|
|
||||||
// bindNamedSQLQuery( element, null, mappings );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new MappingException(
|
|
||||||
"unknown type of query: " +
|
|
||||||
queryOrSqlQuery.getClass().getName(), jaxbRoot.getOrigin()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( hibernateMapping.getResultset() != null ) {
|
|
||||||
// bindResultSetMappingDefinitions( element, null, mappings );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindDatabaseObjectDefinitions() {
|
private void bindDatabaseObjectDefinitions() {
|
||||||
|
@ -268,56 +222,6 @@ public class HbmBinder implements MappingDefaults {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindIdentifierGenerators() {
|
|
||||||
if ( hibernateMapping.getIdentifierGenerator() == null ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for ( XMLHibernateMapping.XMLIdentifierGenerator identifierGeneratorElement : hibernateMapping.getIdentifierGenerator() ) {
|
|
||||||
metadata.registerIdentifierGenerator(
|
|
||||||
identifierGeneratorElement.getName(),
|
|
||||||
identifierGeneratorElement.getClazz()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void bindImports() {
|
|
||||||
if ( hibernateMapping.getImport() == null ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for ( XMLImport importValue : hibernateMapping.getImport() ) {
|
|
||||||
String className = getClassName( importValue.getClazz() );
|
|
||||||
String rename = importValue.getRename();
|
|
||||||
rename = ( rename == null ) ? StringHelper.unqualify( className ) : rename;
|
|
||||||
metadata.addImport( className, rename );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void bindFetchProfiles(){
|
|
||||||
if(hibernateMapping.getFetchProfile() == null){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
bindFetchProfiles( hibernateMapping.getFetchProfile(),null );
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void bindFetchProfiles(List<XMLFetchProfileElement> fetchProfiles, String containingEntityName) {
|
|
||||||
for ( XMLFetchProfileElement fetchProfile : fetchProfiles ) {
|
|
||||||
String profileName = fetchProfile.getName();
|
|
||||||
Set<Fetch> fetches = new HashSet<Fetch>();
|
|
||||||
for ( XMLFetch fetch : fetchProfile.getFetch() ) {
|
|
||||||
String entityName = fetch.getEntity() == null ? containingEntityName : fetch.getEntity();
|
|
||||||
if ( entityName == null ) {
|
|
||||||
throw new MappingException(
|
|
||||||
"could not determine entity for fetch-profile fetch [" + profileName + "]:[" +
|
|
||||||
fetch.getAssociation() + "]",
|
|
||||||
jaxbRoot.getOrigin()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
fetches.add( new Fetch( entityName, fetch.getAssociation(), fetch.getStyle() ) );
|
|
||||||
}
|
|
||||||
metadata.addFetchProfile( new FetchProfile( profileName, fetches ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void bindFilterDefinitions() {
|
private void bindFilterDefinitions() {
|
||||||
if(hibernateMapping.getFilterDef() == null){
|
if(hibernateMapping.getFilterDef() == null){
|
||||||
return;
|
return;
|
||||||
|
@ -353,6 +257,114 @@ public class HbmBinder implements MappingDefaults {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void bindIdentifierGenerators() {
|
||||||
|
if ( hibernateMapping.getIdentifierGenerator() == null ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for ( XMLHibernateMapping.XMLIdentifierGenerator identifierGeneratorElement : hibernateMapping.getIdentifierGenerator() ) {
|
||||||
|
metadata.registerIdentifierGenerator(
|
||||||
|
identifierGeneratorElement.getName(),
|
||||||
|
identifierGeneratorElement.getClazz()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void bindMappings() {
|
||||||
|
if ( hibernateMapping.getClazzOrSubclassOrJoinedSubclass() == null ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for ( Object clazzOrSubclass : hibernateMapping.getClazzOrSubclassOrJoinedSubclass() ) {
|
||||||
|
if ( XMLClass.class.isInstance( clazzOrSubclass ) ) {
|
||||||
|
XMLClass clazz =
|
||||||
|
XMLClass.class.cast( clazzOrSubclass );
|
||||||
|
new RootEntityBinder( this, clazz ).process( clazz );
|
||||||
|
}
|
||||||
|
else if ( XMLSubclassElement.class.isInstance( clazzOrSubclass ) ) {
|
||||||
|
// PersistentClass superModel = getSuperclass( mappings, element );
|
||||||
|
// handleSubclass( superModel, mappings, element, inheritedMetas );
|
||||||
|
}
|
||||||
|
else if ( XMLJoinedSubclassElement.class.isInstance( clazzOrSubclass ) ) {
|
||||||
|
// PersistentClass superModel = getSuperclass( mappings, element );
|
||||||
|
// handleJoinedSubclass( superModel, mappings, element, inheritedMetas );
|
||||||
|
}
|
||||||
|
else if ( XMLUnionSubclassElement.class.isInstance( clazzOrSubclass ) ) {
|
||||||
|
// PersistentClass superModel = getSuperclass( mappings, element );
|
||||||
|
// handleUnionSubclass( superModel, mappings, element, inheritedMetas );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new org.hibernate.metamodel.source.MappingException(
|
||||||
|
"unknown type of class or subclass: " +
|
||||||
|
clazzOrSubclass.getClass().getName(), jaxbRoot.getOrigin()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void bindFetchProfiles(){
|
||||||
|
if(hibernateMapping.getFetchProfile() == null){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
bindFetchProfiles( hibernateMapping.getFetchProfile(),null );
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void bindFetchProfiles(List<XMLFetchProfileElement> fetchProfiles, String containingEntityName) {
|
||||||
|
for ( XMLFetchProfileElement fetchProfile : fetchProfiles ) {
|
||||||
|
String profileName = fetchProfile.getName();
|
||||||
|
Set<Fetch> fetches = new HashSet<Fetch>();
|
||||||
|
for ( XMLFetch fetch : fetchProfile.getFetch() ) {
|
||||||
|
String entityName = fetch.getEntity() == null ? containingEntityName : fetch.getEntity();
|
||||||
|
if ( entityName == null ) {
|
||||||
|
throw new MappingException(
|
||||||
|
"could not determine entity for fetch-profile fetch [" + profileName + "]:[" +
|
||||||
|
fetch.getAssociation() + "]",
|
||||||
|
jaxbRoot.getOrigin()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
fetches.add( new Fetch( entityName, fetch.getAssociation(), fetch.getStyle() ) );
|
||||||
|
}
|
||||||
|
metadata.addFetchProfile( new FetchProfile( profileName, fetches ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void bindImports() {
|
||||||
|
if ( hibernateMapping.getImport() == null ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for ( XMLImport importValue : hibernateMapping.getImport() ) {
|
||||||
|
String className = getClassName( importValue.getClazz() );
|
||||||
|
String rename = importValue.getRename();
|
||||||
|
rename = ( rename == null ) ? StringHelper.unqualify( className ) : rename;
|
||||||
|
metadata.addImport( className, rename );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void bindResultSetMappings() {
|
||||||
|
if ( hibernateMapping.getResultset() == null ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// bindResultSetMappingDefinitions( element, null, mappings );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void bindNamedQueries() {
|
||||||
|
if ( hibernateMapping.getQueryOrSqlQuery() == null ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for ( Object queryOrSqlQuery : hibernateMapping.getQueryOrSqlQuery() ) {
|
||||||
|
if ( XMLQueryElement.class.isInstance( queryOrSqlQuery ) ) {
|
||||||
|
// bindNamedQuery( element, null, mappings );
|
||||||
|
}
|
||||||
|
else if ( XMLSqlQueryElement.class.isInstance( queryOrSqlQuery ) ) {
|
||||||
|
// bindNamedSQLQuery( element, null, mappings );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new MappingException(
|
||||||
|
"unknown type of query: " +
|
||||||
|
queryOrSqlQuery.getClass().getName(), jaxbRoot.getOrigin()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private ClassLoaderService classLoaderService;
|
private ClassLoaderService classLoaderService;
|
||||||
|
|
||||||
private ClassLoaderService classLoaderService() {
|
private ClassLoaderService classLoaderService() {
|
||||||
|
@ -363,10 +375,10 @@ public class HbmBinder implements MappingDefaults {
|
||||||
}
|
}
|
||||||
|
|
||||||
String extractEntityName(XMLClass entityClazz) {
|
String extractEntityName(XMLClass entityClazz) {
|
||||||
return HbmHelper.extractEntityName( entityClazz, packageName );
|
return HbmHelper.extractEntityName( entityClazz, mappingDefaults.getPackageName() );
|
||||||
}
|
}
|
||||||
|
|
||||||
String getClassName(String unqualifiedName) {
|
String getClassName(String unqualifiedName) {
|
||||||
return HbmHelper.getClassName( unqualifiedName, packageName );
|
return HbmHelper.getClassName( unqualifiedName, mappingDefaults.getPackageName() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@ import org.hibernate.metamodel.domain.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;
|
||||||
|
import org.hibernate.metamodel.source.spi.MetaAttributeContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO : javadoc
|
* TODO : javadoc
|
||||||
|
@ -128,4 +129,34 @@ public class HbmHelper {
|
||||||
isEmbedded ? "embedded" : defaultAccess
|
isEmbedded ? "embedded" : defaultAccess
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static MetaAttributeContext extractMetaAttributeContext(
|
||||||
|
List<XMLMetaElement> metaElementList,
|
||||||
|
MetaAttributeContext parentContext) {
|
||||||
|
return extractMetaAttributeContext( metaElementList, false, parentContext );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MetaAttributeContext extractMetaAttributeContext(
|
||||||
|
List<XMLMetaElement> metaElementList,
|
||||||
|
boolean onlyInheritable,
|
||||||
|
MetaAttributeContext parentContext) {
|
||||||
|
final MetaAttributeContext subContext = new MetaAttributeContext( parentContext );
|
||||||
|
|
||||||
|
for ( XMLMetaElement metaElement : metaElementList ) {
|
||||||
|
if ( onlyInheritable & !metaElement.isInherit() ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String name = metaElement.getAttribute();
|
||||||
|
final MetaAttribute inheritedMetaAttribute = parentContext.getMetaAttribute( name );
|
||||||
|
MetaAttribute metaAttribute = subContext.getLocalMetaAttribute( name );
|
||||||
|
if ( metaAttribute == null || metaAttribute == inheritedMetaAttribute ) {
|
||||||
|
metaAttribute = new MetaAttribute( name );
|
||||||
|
subContext.add( metaAttribute );
|
||||||
|
}
|
||||||
|
metaAttribute.addValue( metaElement.getValue() );
|
||||||
|
}
|
||||||
|
|
||||||
|
return subContext;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,7 +142,7 @@ class RootEntityBinder extends AbstractEntityBinder {
|
||||||
SimpleAttributeBindingState bindingState = new HbmSimpleAttributeBindingState(
|
SimpleAttributeBindingState bindingState = new HbmSimpleAttributeBindingState(
|
||||||
entityBinding.getEntity().getPojoEntitySpecifics().getClassName(),
|
entityBinding.getEntity().getPojoEntitySpecifics().getClassName(),
|
||||||
getHibernateMappingBinder(),
|
getHibernateMappingBinder(),
|
||||||
entityBinding.getMetaAttributes(),
|
entityBinding.getMetaAttributeContext(),
|
||||||
id
|
id
|
||||||
);
|
);
|
||||||
// boolean (true here) indicates that by default column names should be guessed
|
// boolean (true here) indicates that by default column names should be guessed
|
||||||
|
@ -289,7 +289,7 @@ class RootEntityBinder extends AbstractEntityBinder {
|
||||||
new HbmSimpleAttributeBindingState(
|
new HbmSimpleAttributeBindingState(
|
||||||
entityBinding.getEntity().getPojoEntitySpecifics().getClassName(),
|
entityBinding.getEntity().getPojoEntitySpecifics().getClassName(),
|
||||||
getHibernateMappingBinder(),
|
getHibernateMappingBinder(),
|
||||||
entityBinding.getMetaAttributes(),
|
entityBinding.getMetaAttributeContext(),
|
||||||
version
|
version
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -316,7 +316,7 @@ class RootEntityBinder extends AbstractEntityBinder {
|
||||||
new HbmSimpleAttributeBindingState(
|
new HbmSimpleAttributeBindingState(
|
||||||
entityBinding.getEntity().getPojoEntitySpecifics().getClassName(),
|
entityBinding.getEntity().getPojoEntitySpecifics().getClassName(),
|
||||||
getHibernateMappingBinder(),
|
getHibernateMappingBinder(),
|
||||||
entityBinding.getMetaAttributes(),
|
entityBinding.getMetaAttributeContext(),
|
||||||
timestamp
|
timestamp
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -32,9 +32,10 @@ import org.hibernate.internal.util.ReflectHelper;
|
||||||
import org.hibernate.mapping.PropertyGeneration;
|
import org.hibernate.mapping.PropertyGeneration;
|
||||||
import org.hibernate.metamodel.binding.CascadeType;
|
import org.hibernate.metamodel.binding.CascadeType;
|
||||||
import org.hibernate.metamodel.binding.state.AttributeBindingState;
|
import org.hibernate.metamodel.binding.state.AttributeBindingState;
|
||||||
import org.hibernate.metamodel.domain.MetaAttribute;
|
|
||||||
import org.hibernate.metamodel.source.hbm.MappingDefaults;
|
|
||||||
import org.hibernate.metamodel.source.hbm.util.MappingHelper;
|
import org.hibernate.metamodel.source.hbm.util.MappingHelper;
|
||||||
|
import org.hibernate.metamodel.source.spi.BindingContext;
|
||||||
|
import org.hibernate.metamodel.source.spi.MappingDefaults;
|
||||||
|
import org.hibernate.metamodel.source.spi.MetaAttributeContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Gail Badner
|
* @author Gail Badner
|
||||||
|
@ -42,18 +43,18 @@ import org.hibernate.metamodel.source.hbm.util.MappingHelper;
|
||||||
public abstract class AbstractHbmAttributeBindingState implements AttributeBindingState {
|
public abstract class AbstractHbmAttributeBindingState implements AttributeBindingState {
|
||||||
private final String ownerClassName;
|
private final String ownerClassName;
|
||||||
private final String attributeName;
|
private final String attributeName;
|
||||||
private final MappingDefaults defaults;
|
private final BindingContext bindingContext;
|
||||||
private final String nodeName;
|
private final String nodeName;
|
||||||
private final String accessorName;
|
private final String accessorName;
|
||||||
private final boolean isOptimisticLockable;
|
private final boolean isOptimisticLockable;
|
||||||
private final Map<String, MetaAttribute> metaAttributes;
|
private final MetaAttributeContext metaAttributeContext;
|
||||||
|
|
||||||
public AbstractHbmAttributeBindingState(
|
public AbstractHbmAttributeBindingState(
|
||||||
String ownerClassName,
|
String ownerClassName,
|
||||||
String attributeName,
|
String attributeName,
|
||||||
MappingDefaults defaults,
|
BindingContext bindingContext,
|
||||||
String nodeName,
|
String nodeName,
|
||||||
Map<String, MetaAttribute> metaAttributes,
|
MetaAttributeContext metaAttributeContext,
|
||||||
String accessorName,
|
String accessorName,
|
||||||
boolean isOptimisticLockable) {
|
boolean isOptimisticLockable) {
|
||||||
if ( attributeName == null ) {
|
if ( attributeName == null ) {
|
||||||
|
@ -64,9 +65,9 @@ public abstract class AbstractHbmAttributeBindingState implements AttributeBindi
|
||||||
|
|
||||||
this.ownerClassName = ownerClassName;
|
this.ownerClassName = ownerClassName;
|
||||||
this.attributeName = attributeName;
|
this.attributeName = attributeName;
|
||||||
this.defaults = defaults;
|
this.bindingContext = bindingContext;
|
||||||
this.nodeName = nodeName;
|
this.nodeName = nodeName;
|
||||||
this.metaAttributes = metaAttributes;
|
this.metaAttributeContext = metaAttributeContext;
|
||||||
this.accessorName = accessorName;
|
this.accessorName = accessorName;
|
||||||
this.isOptimisticLockable = isOptimisticLockable;
|
this.isOptimisticLockable = isOptimisticLockable;
|
||||||
}
|
}
|
||||||
|
@ -77,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, getDefaults().getDefaultCascade() );
|
String commaSeparatedCascades = MappingHelper.getStringValue( cascade, getBindingContext().getMappingDefaults().getDefaultCascade() );
|
||||||
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 ) {
|
||||||
|
@ -91,7 +92,7 @@ public abstract class AbstractHbmAttributeBindingState implements AttributeBindi
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final String getTypeNameByReflection() {
|
protected final String getTypeNameByReflection() {
|
||||||
Class ownerClass = MappingHelper.classForName( ownerClassName, defaults.getServiceRegistry() );
|
Class ownerClass = MappingHelper.classForName( ownerClassName, bindingContext.getServiceRegistry() );
|
||||||
return ReflectHelper.reflectedPropertyClass( ownerClass, attributeName ).getName();
|
return ReflectHelper.reflectedPropertyClass( ownerClass, attributeName ).getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,29 +100,39 @@ public abstract class AbstractHbmAttributeBindingState implements AttributeBindi
|
||||||
return attributeName;
|
return attributeName;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final MappingDefaults getDefaults() {
|
public BindingContext getBindingContext() {
|
||||||
return defaults;
|
return bindingContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
protected final MappingDefaults getDefaults() {
|
||||||
|
return getBindingContext().getMappingDefaults();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public final String getPropertyAccessorName() {
|
public final String getPropertyAccessorName() {
|
||||||
return accessorName;
|
return accessorName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public final boolean isAlternateUniqueKey() {
|
public final boolean isAlternateUniqueKey() {
|
||||||
//TODO: implement
|
//TODO: implement
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public final boolean isOptimisticLockable() {
|
public final boolean isOptimisticLockable() {
|
||||||
return isOptimisticLockable;
|
return isOptimisticLockable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public final String getNodeName() {
|
public final String getNodeName() {
|
||||||
return nodeName == null ? getAttributeName() : nodeName;
|
return nodeName == null ? getAttributeName() : nodeName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final Map<String, MetaAttribute> getMetaAttributes() {
|
@Override
|
||||||
return metaAttributes;
|
public MetaAttributeContext getMetaAttributeContext() {
|
||||||
|
return metaAttributeContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PropertyGeneration getPropertyGeneration() {
|
public PropertyGeneration getPropertyGeneration() {
|
||||||
|
|
|
@ -26,16 +26,17 @@ package org.hibernate.metamodel.source.hbm.state.binding;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.hibernate.metamodel.binding.CascadeType;
|
import org.hibernate.metamodel.binding.CascadeType;
|
||||||
import org.hibernate.metamodel.source.hbm.MappingDefaults;
|
|
||||||
import org.hibernate.metamodel.binding.state.DiscriminatorBindingState;
|
import org.hibernate.metamodel.binding.state.DiscriminatorBindingState;
|
||||||
import org.hibernate.metamodel.source.hbm.util.MappingHelper;
|
import org.hibernate.metamodel.source.hbm.util.MappingHelper;
|
||||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping;
|
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping;
|
||||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping.XMLClass.XMLDiscriminator;
|
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping.XMLClass.XMLDiscriminator;
|
||||||
|
import org.hibernate.metamodel.source.spi.BindingContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Gail Badner
|
* @author Gail Badner
|
||||||
*/
|
*/
|
||||||
public class HbmDiscriminatorBindingState extends AbstractHbmAttributeBindingState
|
public class HbmDiscriminatorBindingState
|
||||||
|
extends AbstractHbmAttributeBindingState
|
||||||
implements DiscriminatorBindingState {
|
implements DiscriminatorBindingState {
|
||||||
private final String discriminatorValue;
|
private final String discriminatorValue;
|
||||||
private final boolean isForced;
|
private final boolean isForced;
|
||||||
|
@ -45,12 +46,16 @@ public class HbmDiscriminatorBindingState extends AbstractHbmAttributeBindingSta
|
||||||
public HbmDiscriminatorBindingState(
|
public HbmDiscriminatorBindingState(
|
||||||
String entityName,
|
String entityName,
|
||||||
String ownerClassName,
|
String ownerClassName,
|
||||||
MappingDefaults defaults,
|
BindingContext bindingContext,
|
||||||
XMLHibernateMapping.XMLClass xmlEntityClazz) {
|
XMLHibernateMapping.XMLClass xmlEntityClazz) {
|
||||||
// Discriminator.getName() is not defined, so the attribute will always be
|
|
||||||
// defaults.getDefaultDescriminatorColumnName()
|
|
||||||
super(
|
super(
|
||||||
ownerClassName, defaults.getDefaultDiscriminatorColumnName(), defaults, null, null, null, true
|
ownerClassName,
|
||||||
|
bindingContext.getMappingDefaults().getDefaultDiscriminatorColumnName(),
|
||||||
|
bindingContext,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
true
|
||||||
);
|
);
|
||||||
XMLDiscriminator discriminator = xmlEntityClazz.getDiscriminator();
|
XMLDiscriminator discriminator = xmlEntityClazz.getDiscriminator();
|
||||||
this.discriminatorValue = MappingHelper.getStringValue(
|
this.discriminatorValue = MappingHelper.getStringValue(
|
||||||
|
|
|
@ -23,20 +23,17 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.metamodel.source.hbm.state.binding;
|
package org.hibernate.metamodel.source.hbm.state.binding;
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.hibernate.FetchMode;
|
import org.hibernate.FetchMode;
|
||||||
import org.hibernate.MappingException;
|
|
||||||
import org.hibernate.internal.util.ReflectHelper;
|
import org.hibernate.internal.util.ReflectHelper;
|
||||||
import org.hibernate.metamodel.binding.CascadeType;
|
import org.hibernate.metamodel.binding.CascadeType;
|
||||||
import org.hibernate.metamodel.binding.state.ManyToOneAttributeBindingState;
|
import org.hibernate.metamodel.binding.state.ManyToOneAttributeBindingState;
|
||||||
import org.hibernate.metamodel.domain.MetaAttribute;
|
|
||||||
import org.hibernate.metamodel.source.hbm.HbmHelper;
|
import org.hibernate.metamodel.source.hbm.HbmHelper;
|
||||||
import org.hibernate.metamodel.source.hbm.MappingDefaults;
|
|
||||||
import org.hibernate.metamodel.source.hbm.util.MappingHelper;
|
import org.hibernate.metamodel.source.hbm.util.MappingHelper;
|
||||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLManyToOneElement;
|
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLManyToOneElement;
|
||||||
|
import org.hibernate.metamodel.source.spi.BindingContext;
|
||||||
|
import org.hibernate.metamodel.source.spi.MetaAttributeContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Gail Badner
|
* @author Gail Badner
|
||||||
|
@ -58,17 +55,19 @@ public class HbmManyToOneAttributeBindingState
|
||||||
|
|
||||||
public HbmManyToOneAttributeBindingState(
|
public HbmManyToOneAttributeBindingState(
|
||||||
String ownerClassName,
|
String ownerClassName,
|
||||||
MappingDefaults defaults,
|
BindingContext bindingContext,
|
||||||
Map<String, MetaAttribute> entityMetaAttributes,
|
MetaAttributeContext parentMetaAttributeContext,
|
||||||
XMLManyToOneElement manyToOne) {
|
XMLManyToOneElement manyToOne) {
|
||||||
super(
|
super(
|
||||||
ownerClassName,
|
ownerClassName,
|
||||||
manyToOne.getName(),
|
manyToOne.getName(),
|
||||||
defaults,
|
bindingContext,
|
||||||
manyToOne.getNode(),
|
manyToOne.getNode(),
|
||||||
HbmHelper.extractMetas( manyToOne.getMeta(), entityMetaAttributes ),
|
HbmHelper.extractMetaAttributeContext( manyToOne.getMeta(), parentMetaAttributeContext ),
|
||||||
HbmHelper.getPropertyAccessorName(
|
HbmHelper.getPropertyAccessorName(
|
||||||
manyToOne.getAccess(), manyToOne.isEmbedXml(), defaults.getDefaultAccess()
|
manyToOne.getAccess(),
|
||||||
|
manyToOne.isEmbedXml(),
|
||||||
|
bindingContext.getMappingDefaults().getDefaultAccess()
|
||||||
),
|
),
|
||||||
manyToOne.isOptimisticLock()
|
manyToOne.isOptimisticLock()
|
||||||
);
|
);
|
||||||
|
@ -80,7 +79,7 @@ public class HbmManyToOneAttributeBindingState
|
||||||
"proxy".equals( manyToOne.getLazy().value() );
|
"proxy".equals( manyToOne.getLazy().value() );
|
||||||
cascadeTypes = determineCascadeTypes( manyToOne.getCascade() );
|
cascadeTypes = determineCascadeTypes( manyToOne.getCascade() );
|
||||||
isEmbedded = manyToOne.isEmbedXml();
|
isEmbedded = manyToOne.isEmbedXml();
|
||||||
referencedEntityName = getReferencedEntityName( ownerClassName, manyToOne, defaults );
|
referencedEntityName = getReferencedEntityName( ownerClassName, manyToOne, bindingContext );
|
||||||
referencedPropertyName = manyToOne.getPropertyRef();
|
referencedPropertyName = manyToOne.getPropertyRef();
|
||||||
ignoreNotFound = "ignore".equals( manyToOne.getNotFound().value() );
|
ignoreNotFound = "ignore".equals( manyToOne.getNotFound().value() );
|
||||||
isInsertable = manyToOne.isInsert();
|
isInsertable = manyToOne.isInsert();
|
||||||
|
@ -92,16 +91,21 @@ public class HbmManyToOneAttributeBindingState
|
||||||
return isEmbedded;
|
return isEmbedded;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getReferencedEntityName(String ownerClassName, XMLManyToOneElement manyToOne, MappingDefaults defaults) {
|
private static String getReferencedEntityName(
|
||||||
|
String ownerClassName,
|
||||||
|
XMLManyToOneElement manyToOne,
|
||||||
|
BindingContext bindingContext) {
|
||||||
String referencedEntityName;
|
String referencedEntityName;
|
||||||
if ( manyToOne.getEntityName() != null ) {
|
if ( manyToOne.getEntityName() != null ) {
|
||||||
referencedEntityName = manyToOne.getEntityName();
|
referencedEntityName = manyToOne.getEntityName();
|
||||||
}
|
}
|
||||||
else if ( manyToOne.getClazz() != null ) {
|
else if ( manyToOne.getClazz() != null ) {
|
||||||
referencedEntityName = HbmHelper.getClassName( manyToOne.getClazz(), defaults.getPackageName() );
|
referencedEntityName = HbmHelper.getClassName(
|
||||||
|
manyToOne.getClazz(), bindingContext.getMappingDefaults().getPackageName()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Class ownerClazz = MappingHelper.classForName( ownerClassName, defaults.getServiceRegistry() );
|
Class ownerClazz = MappingHelper.classForName( ownerClassName, bindingContext.getServiceRegistry() );
|
||||||
referencedEntityName = ReflectHelper.reflectedPropertyClass( ownerClazz, manyToOne.getName() ).getName();
|
referencedEntityName = ReflectHelper.reflectedPropertyClass( ownerClazz, manyToOne.getName() ).getName();
|
||||||
}
|
}
|
||||||
return referencedEntityName;
|
return referencedEntityName;
|
||||||
|
|
|
@ -26,16 +26,13 @@ package org.hibernate.metamodel.source.hbm.state.binding;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.hibernate.FetchMode;
|
import org.hibernate.FetchMode;
|
||||||
import org.hibernate.metamodel.binding.CascadeType;
|
import org.hibernate.metamodel.binding.CascadeType;
|
||||||
import org.hibernate.metamodel.binding.CustomSQL;
|
import org.hibernate.metamodel.binding.CustomSQL;
|
||||||
import org.hibernate.metamodel.binding.state.PluralAttributeBindingState;
|
import org.hibernate.metamodel.binding.state.PluralAttributeBindingState;
|
||||||
import org.hibernate.metamodel.domain.MetaAttribute;
|
|
||||||
import org.hibernate.metamodel.source.hbm.HbmHelper;
|
import org.hibernate.metamodel.source.hbm.HbmHelper;
|
||||||
import org.hibernate.metamodel.source.hbm.MappingDefaults;
|
|
||||||
import org.hibernate.metamodel.source.hbm.util.MappingHelper;
|
import org.hibernate.metamodel.source.hbm.util.MappingHelper;
|
||||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLBagElement;
|
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLBagElement;
|
||||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSqlDeleteAllElement;
|
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSqlDeleteAllElement;
|
||||||
|
@ -43,6 +40,8 @@ import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSqlDeleteElement;
|
||||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSqlInsertElement;
|
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSqlInsertElement;
|
||||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSqlUpdateElement;
|
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSqlUpdateElement;
|
||||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSynchronizeElement;
|
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSynchronizeElement;
|
||||||
|
import org.hibernate.metamodel.source.spi.BindingContext;
|
||||||
|
import org.hibernate.metamodel.source.spi.MetaAttributeContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Gail Badner
|
* @author Gail Badner
|
||||||
|
@ -56,23 +55,23 @@ public class HbmPluralAttributeBindingState extends AbstractHbmAttributeBindingS
|
||||||
|
|
||||||
public HbmPluralAttributeBindingState(
|
public HbmPluralAttributeBindingState(
|
||||||
String ownerClassName,
|
String ownerClassName,
|
||||||
MappingDefaults mappingDefaults,
|
BindingContext bindingContext,
|
||||||
XMLBagElement collection,
|
MetaAttributeContext parentMetaAttributeContext,
|
||||||
Map<String, MetaAttribute> entityMetaAttributes) {
|
XMLBagElement collection) {
|
||||||
super(
|
super(
|
||||||
ownerClassName,
|
ownerClassName,
|
||||||
collection.getName(),
|
collection.getName(),
|
||||||
mappingDefaults,
|
bindingContext,
|
||||||
collection.getNode(),
|
collection.getNode(),
|
||||||
HbmHelper.extractMetas( collection.getMeta(), entityMetaAttributes ),
|
HbmHelper.extractMetaAttributeContext( collection.getMeta(), parentMetaAttributeContext ),
|
||||||
HbmHelper.getPropertyAccessorName(
|
HbmHelper.getPropertyAccessorName(
|
||||||
collection.getAccess(), collection.isEmbedXml(), mappingDefaults.getDefaultAccess()
|
collection.getAccess(), collection.isEmbedXml(), bindingContext.getMappingDefaults().getDefaultAccess()
|
||||||
),
|
),
|
||||||
collection.isOptimisticLock()
|
collection.isOptimisticLock()
|
||||||
);
|
);
|
||||||
this.collection = collection;
|
this.collection = collection;
|
||||||
this.collectionPersisterClass = MappingHelper.classForName(
|
this.collectionPersisterClass = MappingHelper.classForName(
|
||||||
collection.getPersister(), getDefaults().getServiceRegistry()
|
collection.getPersister(), getBindingContext().getServiceRegistry()
|
||||||
);
|
);
|
||||||
this.cascadeTypes = determineCascadeTypes( collection.getCascade() );
|
this.cascadeTypes = determineCascadeTypes( collection.getCascade() );
|
||||||
|
|
||||||
|
@ -117,7 +116,9 @@ public class HbmPluralAttributeBindingState extends AbstractHbmAttributeBindingS
|
||||||
|
|
||||||
public boolean isLazy() {
|
public boolean isLazy() {
|
||||||
return isExtraLazy() ||
|
return isExtraLazy() ||
|
||||||
MappingHelper.getBooleanValue( collection.getLazy().value(), getDefaults().isDefaultLazy() );
|
MappingHelper.getBooleanValue(
|
||||||
|
collection.getLazy().value(), getBindingContext().getMappingDefaults().isDefaultLazy()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isExtraLazy() {
|
public boolean isExtraLazy() {
|
||||||
|
|
|
@ -31,15 +31,16 @@ import org.hibernate.MappingException;
|
||||||
import org.hibernate.mapping.PropertyGeneration;
|
import org.hibernate.mapping.PropertyGeneration;
|
||||||
import org.hibernate.metamodel.binding.CascadeType;
|
import org.hibernate.metamodel.binding.CascadeType;
|
||||||
import org.hibernate.metamodel.binding.state.SimpleAttributeBindingState;
|
import org.hibernate.metamodel.binding.state.SimpleAttributeBindingState;
|
||||||
import org.hibernate.metamodel.domain.MetaAttribute;
|
|
||||||
import org.hibernate.metamodel.source.hbm.HbmHelper;
|
import org.hibernate.metamodel.source.hbm.HbmHelper;
|
||||||
import org.hibernate.metamodel.source.hbm.MappingDefaults;
|
|
||||||
import org.hibernate.metamodel.source.hbm.util.MappingHelper;
|
import org.hibernate.metamodel.source.hbm.util.MappingHelper;
|
||||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping.XMLClass.XMLId;
|
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping.XMLClass.XMLId;
|
||||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping.XMLClass.XMLTimestamp;
|
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping.XMLClass.XMLTimestamp;
|
||||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping.XMLClass.XMLVersion;
|
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping.XMLClass.XMLVersion;
|
||||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLParamElement;
|
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLParamElement;
|
||||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLPropertyElement;
|
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLPropertyElement;
|
||||||
|
import org.hibernate.metamodel.source.spi.BindingContext;
|
||||||
|
import org.hibernate.metamodel.source.spi.MappingDefaults;
|
||||||
|
import org.hibernate.metamodel.source.spi.MetaAttributeContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Gail Badner
|
* @author Gail Badner
|
||||||
|
@ -56,25 +57,25 @@ public class HbmSimpleAttributeBindingState extends AbstractHbmAttributeBindingS
|
||||||
|
|
||||||
public HbmSimpleAttributeBindingState(
|
public HbmSimpleAttributeBindingState(
|
||||||
String ownerClassName,
|
String ownerClassName,
|
||||||
MappingDefaults defaults,
|
BindingContext bindingContext,
|
||||||
Map<String, MetaAttribute> entityMetaAttributes,
|
MetaAttributeContext parentMetaAttributeContext,
|
||||||
XMLId id) {
|
XMLId id) {
|
||||||
super(
|
super(
|
||||||
ownerClassName,
|
ownerClassName,
|
||||||
id.getName() != null ? id.getName() : defaults.getDefaultIdColumnName(),
|
id.getName() != null ? id.getName() : bindingContext.getMappingDefaults().getDefaultIdColumnName(),
|
||||||
defaults,
|
bindingContext,
|
||||||
id.getNode(),
|
id.getNode(),
|
||||||
HbmHelper.extractMetas( id.getMeta(), entityMetaAttributes ),
|
HbmHelper.extractMetaAttributeContext( id.getMeta(), parentMetaAttributeContext ),
|
||||||
HbmHelper.getPropertyAccessorName( id.getAccess(), false, defaults.getDefaultAccess() ),
|
HbmHelper.getPropertyAccessorName( id.getAccess(), false, bindingContext.getMappingDefaults().getDefaultAccess() ),
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
this.isLazy = false;
|
this.isLazy = false;
|
||||||
if ( id.getTypeAttribute() != null ) {
|
if ( id.getTypeAttribute() != null ) {
|
||||||
typeName = maybeConvertToTypeDefName( id.getTypeAttribute(), defaults );
|
typeName = maybeConvertToTypeDefName( id.getTypeAttribute(), bindingContext.getMappingDefaults() );
|
||||||
}
|
}
|
||||||
else if ( id.getType() != null ) {
|
else if ( id.getType() != null ) {
|
||||||
typeName = maybeConvertToTypeDefName( id.getType().getName(), defaults );
|
typeName = maybeConvertToTypeDefName( id.getType().getName(), bindingContext.getMappingDefaults() );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
typeName = getTypeNameByReflection();
|
typeName = getTypeNameByReflection();
|
||||||
|
@ -99,16 +100,16 @@ public class HbmSimpleAttributeBindingState extends AbstractHbmAttributeBindingS
|
||||||
|
|
||||||
public HbmSimpleAttributeBindingState(
|
public HbmSimpleAttributeBindingState(
|
||||||
String ownerClassName,
|
String ownerClassName,
|
||||||
MappingDefaults defaults,
|
BindingContext bindingContext,
|
||||||
Map<String, MetaAttribute> entityMetaAttributes,
|
MetaAttributeContext parentMetaAttributeContext,
|
||||||
XMLVersion version) {
|
XMLVersion version) {
|
||||||
super(
|
super(
|
||||||
ownerClassName,
|
ownerClassName,
|
||||||
version.getName(),
|
version.getName(),
|
||||||
defaults,
|
bindingContext,
|
||||||
version.getNode(),
|
version.getNode(),
|
||||||
HbmHelper.extractMetas( version.getMeta(), entityMetaAttributes ),
|
HbmHelper.extractMetaAttributeContext( version.getMeta(), parentMetaAttributeContext ),
|
||||||
HbmHelper.getPropertyAccessorName( version.getAccess(), false, defaults.getDefaultAccess() ),
|
HbmHelper.getPropertyAccessorName( version.getAccess(), false, bindingContext.getMappingDefaults().getDefaultAccess() ),
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
this.typeName = version.getType() == null ? "integer" : version.getType();
|
this.typeName = version.getType() == null ? "integer" : version.getType();
|
||||||
|
@ -128,17 +129,17 @@ public class HbmSimpleAttributeBindingState extends AbstractHbmAttributeBindingS
|
||||||
|
|
||||||
public HbmSimpleAttributeBindingState(
|
public HbmSimpleAttributeBindingState(
|
||||||
String ownerClassName,
|
String ownerClassName,
|
||||||
MappingDefaults defaults,
|
BindingContext bindingContext,
|
||||||
Map<String, MetaAttribute> entityMetaAttributes,
|
MetaAttributeContext parentMetaAttributeContext,
|
||||||
XMLTimestamp timestamp) {
|
XMLTimestamp timestamp) {
|
||||||
|
|
||||||
super(
|
super(
|
||||||
ownerClassName,
|
ownerClassName,
|
||||||
timestamp.getName(),
|
timestamp.getName(),
|
||||||
defaults,
|
bindingContext,
|
||||||
timestamp.getNode(),
|
timestamp.getNode(),
|
||||||
HbmHelper.extractMetas( timestamp.getMeta(), entityMetaAttributes ),
|
HbmHelper.extractMetaAttributeContext( timestamp.getMeta(), parentMetaAttributeContext ),
|
||||||
HbmHelper.getPropertyAccessorName( timestamp.getAccess(), false, defaults.getDefaultAccess() ),
|
HbmHelper.getPropertyAccessorName( timestamp.getAccess(), false, bindingContext.getMappingDefaults().getDefaultAccess() ),
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -159,16 +160,16 @@ public class HbmSimpleAttributeBindingState extends AbstractHbmAttributeBindingS
|
||||||
|
|
||||||
public HbmSimpleAttributeBindingState(
|
public HbmSimpleAttributeBindingState(
|
||||||
String ownerClassName,
|
String ownerClassName,
|
||||||
MappingDefaults defaults,
|
BindingContext bindingContext,
|
||||||
Map<String, MetaAttribute> entityMetaAttributes,
|
MetaAttributeContext parentMetaAttributeContext,
|
||||||
XMLPropertyElement property) {
|
XMLPropertyElement property) {
|
||||||
super(
|
super(
|
||||||
ownerClassName,
|
ownerClassName,
|
||||||
property.getName(),
|
property.getName(),
|
||||||
defaults,
|
bindingContext,
|
||||||
property.getNode(),
|
property.getNode(),
|
||||||
HbmHelper.extractMetas( property.getMeta(), entityMetaAttributes ),
|
HbmHelper.extractMetaAttributeContext( property.getMeta(), parentMetaAttributeContext ),
|
||||||
HbmHelper.getPropertyAccessorName( property.getAccess(), false, defaults.getDefaultAccess() ),
|
HbmHelper.getPropertyAccessorName( property.getAccess(), false, bindingContext.getMappingDefaults().getDefaultAccess() ),
|
||||||
property.isOptimisticLock()
|
property.isOptimisticLock()
|
||||||
);
|
);
|
||||||
this.isLazy = property.isLazy();
|
this.isLazy = property.isLazy();
|
||||||
|
@ -206,10 +207,10 @@ public class HbmSimpleAttributeBindingState extends AbstractHbmAttributeBindingS
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( property.getTypeAttribute() != null ) {
|
if ( property.getTypeAttribute() != null ) {
|
||||||
typeName = maybeConvertToTypeDefName( property.getTypeAttribute(), defaults );
|
typeName = maybeConvertToTypeDefName( property.getTypeAttribute(), bindingContext.getMappingDefaults() );
|
||||||
}
|
}
|
||||||
else if ( property.getType() != null ) {
|
else if ( property.getType() != null ) {
|
||||||
typeName = maybeConvertToTypeDefName( property.getType().getName(), defaults );
|
typeName = maybeConvertToTypeDefName( property.getType().getName(), bindingContext.getMappingDefaults() );
|
||||||
for ( XMLParamElement typeParameter : property.getType().getParam() ) {
|
for ( XMLParamElement typeParameter : property.getType().getParam() ) {
|
||||||
//TODO: add parameters from typedef
|
//TODO: add parameters from typedef
|
||||||
typeParameters.put( typeParameter.getName(), typeParameter.getValue().trim() );
|
typeParameters.put( typeParameter.getName(), typeParameter.getValue().trim() );
|
||||||
|
|
|
@ -23,9 +23,9 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.metamodel.source.hbm.state.relational;
|
package org.hibernate.metamodel.source.hbm.state.relational;
|
||||||
|
|
||||||
import org.hibernate.metamodel.source.hbm.MappingDefaults;
|
|
||||||
import org.hibernate.metamodel.relational.state.ManyToOneRelationalState;
|
import org.hibernate.metamodel.relational.state.ManyToOneRelationalState;
|
||||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLManyToOneElement;
|
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLManyToOneElement;
|
||||||
|
import org.hibernate.metamodel.source.spi.BindingContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Gail Badner
|
* @author Gail Badner
|
||||||
|
@ -36,10 +36,11 @@ implements ManyToOneRelationalState {
|
||||||
private final boolean isLogicalOneToOne;
|
private final boolean isLogicalOneToOne;
|
||||||
private final String foreignKeyName;
|
private final String foreignKeyName;
|
||||||
|
|
||||||
public HbmManyToOneRelationalStateContainer(MappingDefaults defaults,
|
public HbmManyToOneRelationalStateContainer(
|
||||||
|
BindingContext bindingContext,
|
||||||
boolean autoColumnCreation,
|
boolean autoColumnCreation,
|
||||||
XMLManyToOneElement manyToOne ) {
|
XMLManyToOneElement manyToOne ) {
|
||||||
super( defaults, autoColumnCreation, manyToOne );
|
super( bindingContext, autoColumnCreation, manyToOne );
|
||||||
this.isLogicalOneToOne = manyToOne.isUnique();
|
this.isLogicalOneToOne = manyToOne.isUnique();
|
||||||
this.foreignKeyName = manyToOne.getForeignKey();
|
this.foreignKeyName = manyToOne.getForeignKey();
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,6 @@ import java.util.Set;
|
||||||
import org.hibernate.MappingException;
|
import org.hibernate.MappingException;
|
||||||
import org.hibernate.cfg.NamingStrategy;
|
import org.hibernate.cfg.NamingStrategy;
|
||||||
import org.hibernate.metamodel.binding.HibernateTypeDescriptor;
|
import org.hibernate.metamodel.binding.HibernateTypeDescriptor;
|
||||||
import org.hibernate.metamodel.source.hbm.MappingDefaults;
|
|
||||||
import org.hibernate.metamodel.relational.state.SimpleValueRelationalState;
|
import org.hibernate.metamodel.relational.state.SimpleValueRelationalState;
|
||||||
import org.hibernate.metamodel.relational.state.TupleRelationalState;
|
import org.hibernate.metamodel.relational.state.TupleRelationalState;
|
||||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLColumnElement;
|
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLColumnElement;
|
||||||
|
@ -41,27 +40,33 @@ import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping.XMLCla
|
||||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping.XMLClass.XMLVersion;
|
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping.XMLClass.XMLVersion;
|
||||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLManyToOneElement;
|
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLManyToOneElement;
|
||||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLPropertyElement;
|
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLPropertyElement;
|
||||||
|
import org.hibernate.metamodel.source.spi.BindingContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Gail Badner
|
* @author Gail Badner
|
||||||
*/
|
*/
|
||||||
public class HbmSimpleValueRelationalStateContainer implements TupleRelationalState {
|
public class HbmSimpleValueRelationalStateContainer implements TupleRelationalState {
|
||||||
private final MappingDefaults defaults;
|
private final BindingContext bindingContext;
|
||||||
private final Set<String> propertyUniqueKeys;
|
private final Set<String> propertyUniqueKeys;
|
||||||
private final Set<String> propertyIndexes;
|
private final Set<String> propertyIndexes;
|
||||||
private final List<SimpleValueRelationalState> simpleValueStates;
|
private final List<SimpleValueRelationalState> simpleValueStates;
|
||||||
private final HibernateTypeDescriptor hibernateTypeDescriptor = new HibernateTypeDescriptor();
|
private final HibernateTypeDescriptor hibernateTypeDescriptor = new HibernateTypeDescriptor();
|
||||||
|
|
||||||
|
public BindingContext getBindingContext() {
|
||||||
|
return bindingContext;
|
||||||
|
}
|
||||||
|
|
||||||
public NamingStrategy getNamingStrategy() {
|
public NamingStrategy getNamingStrategy() {
|
||||||
return defaults.getNamingStrategy();
|
return getBindingContext().getNamingStrategy();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: remove duplication after Id, Discriminator, Version, Timestamp, and Property extend a common interface.
|
// TODO: remove duplication after Id, Discriminator, Version, Timestamp, and Property extend a common interface.
|
||||||
|
|
||||||
public HbmSimpleValueRelationalStateContainer(MappingDefaults defaults,
|
public HbmSimpleValueRelationalStateContainer(
|
||||||
|
BindingContext bindingContext,
|
||||||
boolean autoColumnCreation,
|
boolean autoColumnCreation,
|
||||||
XMLId id) {
|
XMLId id) {
|
||||||
this( defaults, id.getColumn() );
|
this( bindingContext, id.getColumn() );
|
||||||
if ( simpleValueStates.isEmpty() ) {
|
if ( simpleValueStates.isEmpty() ) {
|
||||||
if ( id.getColumn() == null && ! autoColumnCreation ) {
|
if ( id.getColumn() == null && ! autoColumnCreation ) {
|
||||||
throw new MappingException( "No columns to map and auto column creation is disabled." );
|
throw new MappingException( "No columns to map and auto column creation is disabled." );
|
||||||
|
@ -74,10 +79,11 @@ public class HbmSimpleValueRelationalStateContainer implements TupleRelationalSt
|
||||||
this.hibernateTypeDescriptor.setTypeName( id.getTypeAttribute() );
|
this.hibernateTypeDescriptor.setTypeName( id.getTypeAttribute() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public HbmSimpleValueRelationalStateContainer(MappingDefaults defaults,
|
public HbmSimpleValueRelationalStateContainer(
|
||||||
|
BindingContext bindingContext,
|
||||||
boolean autoColumnCreation,
|
boolean autoColumnCreation,
|
||||||
XMLDiscriminator discriminator) {
|
XMLDiscriminator discriminator) {
|
||||||
this( defaults, discriminator.getFormula(), discriminator.getColumn() );
|
this( bindingContext, discriminator.getFormula(), discriminator.getColumn() );
|
||||||
if ( simpleValueStates.isEmpty() ) {
|
if ( simpleValueStates.isEmpty() ) {
|
||||||
if ( discriminator.getColumn() == null && discriminator.getFormula() == null && ! autoColumnCreation ) {
|
if ( discriminator.getColumn() == null && discriminator.getFormula() == null && ! autoColumnCreation ) {
|
||||||
throw new MappingException( "No column or formula to map and auto column creation is disabled." );
|
throw new MappingException( "No column or formula to map and auto column creation is disabled." );
|
||||||
|
@ -90,10 +96,11 @@ public class HbmSimpleValueRelationalStateContainer implements TupleRelationalSt
|
||||||
this.hibernateTypeDescriptor.setTypeName( discriminator.getType() == null ? "string" : discriminator.getType() );
|
this.hibernateTypeDescriptor.setTypeName( discriminator.getType() == null ? "string" : discriminator.getType() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public HbmSimpleValueRelationalStateContainer(MappingDefaults defaults,
|
public HbmSimpleValueRelationalStateContainer(
|
||||||
|
BindingContext bindingContext,
|
||||||
boolean autoColumnCreation,
|
boolean autoColumnCreation,
|
||||||
XMLVersion version) {
|
XMLVersion version) {
|
||||||
this( defaults, version.getColumn() );
|
this( bindingContext, version.getColumn() );
|
||||||
if ( simpleValueStates.isEmpty() ) {
|
if ( simpleValueStates.isEmpty() ) {
|
||||||
if ( version.getColumn() == null && ! autoColumnCreation ) {
|
if ( version.getColumn() == null && ! autoColumnCreation ) {
|
||||||
throw new MappingException( "No column or formula to map and auto column creation is disabled." );
|
throw new MappingException( "No column or formula to map and auto column creation is disabled." );
|
||||||
|
@ -106,10 +113,11 @@ public class HbmSimpleValueRelationalStateContainer implements TupleRelationalSt
|
||||||
this.hibernateTypeDescriptor.setTypeName( version.getType() == null ? "integer" : version.getType() );
|
this.hibernateTypeDescriptor.setTypeName( version.getType() == null ? "integer" : version.getType() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public HbmSimpleValueRelationalStateContainer(MappingDefaults defaults,
|
public HbmSimpleValueRelationalStateContainer(
|
||||||
|
BindingContext bindingContext,
|
||||||
boolean autoColumnCreation,
|
boolean autoColumnCreation,
|
||||||
XMLTimestamp timestamp) {
|
XMLTimestamp timestamp) {
|
||||||
this( defaults, null );
|
this( bindingContext, null );
|
||||||
if ( simpleValueStates.isEmpty() ) {
|
if ( simpleValueStates.isEmpty() ) {
|
||||||
if ( timestamp.getColumn() == null && ! autoColumnCreation ) {
|
if ( timestamp.getColumn() == null && ! autoColumnCreation ) {
|
||||||
throw new MappingException( "No columns to map and auto column creation is disabled." );
|
throw new MappingException( "No columns to map and auto column creation is disabled." );
|
||||||
|
@ -122,10 +130,11 @@ public class HbmSimpleValueRelationalStateContainer implements TupleRelationalSt
|
||||||
this.hibernateTypeDescriptor.setTypeName( "db".equals( timestamp.getSource() ) ? "dbtimestamp" : "timestamp" );
|
this.hibernateTypeDescriptor.setTypeName( "db".equals( timestamp.getSource() ) ? "dbtimestamp" : "timestamp" );
|
||||||
}
|
}
|
||||||
|
|
||||||
public HbmSimpleValueRelationalStateContainer(MappingDefaults defaults,
|
public HbmSimpleValueRelationalStateContainer(
|
||||||
|
BindingContext bindingContext,
|
||||||
boolean autoColumnCreation,
|
boolean autoColumnCreation,
|
||||||
XMLPropertyElement property) {
|
XMLPropertyElement property) {
|
||||||
this( defaults, property.getColumnOrFormula() );
|
this( bindingContext, property.getColumnOrFormula() );
|
||||||
if ( simpleValueStates.isEmpty() ) {
|
if ( simpleValueStates.isEmpty() ) {
|
||||||
if ( property.getColumn() == null && property.getFormula() == null && ! autoColumnCreation ) {
|
if ( property.getColumn() == null && property.getFormula() == null && ! autoColumnCreation ) {
|
||||||
throw new MappingException( "No column or formula to map and auto column creation is disabled." );
|
throw new MappingException( "No column or formula to map and auto column creation is disabled." );
|
||||||
|
@ -138,10 +147,11 @@ public class HbmSimpleValueRelationalStateContainer implements TupleRelationalSt
|
||||||
this.hibernateTypeDescriptor.setTypeName( property.getTypeAttribute() );
|
this.hibernateTypeDescriptor.setTypeName( property.getTypeAttribute() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public HbmSimpleValueRelationalStateContainer(MappingDefaults defaults,
|
public HbmSimpleValueRelationalStateContainer(
|
||||||
|
BindingContext bindingContext,
|
||||||
boolean autoColumnCreation,
|
boolean autoColumnCreation,
|
||||||
XMLManyToOneElement manyToOne) {
|
XMLManyToOneElement manyToOne) {
|
||||||
this( defaults, manyToOne.getColumnOrFormula() );
|
this( bindingContext, manyToOne.getColumnOrFormula() );
|
||||||
if ( simpleValueStates.isEmpty() ) {
|
if ( simpleValueStates.isEmpty() ) {
|
||||||
if ( manyToOne.getColumn() == null && manyToOne.getFormula() == null && ! autoColumnCreation ) {
|
if ( manyToOne.getColumn() == null && manyToOne.getFormula() == null && ! autoColumnCreation ) {
|
||||||
throw new MappingException( "No column or formula to map and auto column creation is disabled." );
|
throw new MappingException( "No column or formula to map and auto column creation is disabled." );
|
||||||
|
@ -153,26 +163,29 @@ public class HbmSimpleValueRelationalStateContainer implements TupleRelationalSt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private HbmSimpleValueRelationalStateContainer(MappingDefaults defaults,
|
private HbmSimpleValueRelationalStateContainer(
|
||||||
|
BindingContext bindingContext,
|
||||||
String formulaElement,
|
String formulaElement,
|
||||||
XMLColumnElement columnElement
|
XMLColumnElement columnElement) {
|
||||||
) {
|
this( bindingContext,
|
||||||
this( defaults,
|
formulaElement != null
|
||||||
formulaElement != null ?
|
? Collections.singletonList( formulaElement )
|
||||||
Collections.singletonList( formulaElement ) :
|
: columnElement != null
|
||||||
columnElement != null ? Collections.singletonList( columnElement ) : Collections.<Object>emptyList()
|
? Collections.singletonList( columnElement )
|
||||||
|
: Collections.<Object>emptyList()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private HbmSimpleValueRelationalStateContainer(MappingDefaults defaults,
|
private HbmSimpleValueRelationalStateContainer(
|
||||||
|
BindingContext bindingContext,
|
||||||
List mappedColumnsOrFormulas) {
|
List mappedColumnsOrFormulas) {
|
||||||
this.defaults = defaults;
|
this.bindingContext = bindingContext;
|
||||||
this.propertyUniqueKeys = Collections.emptySet();
|
this.propertyUniqueKeys = Collections.emptySet();
|
||||||
this.propertyIndexes = Collections.emptySet();
|
this.propertyIndexes = Collections.emptySet();
|
||||||
simpleValueStates = new ArrayList<SimpleValueRelationalState>(
|
simpleValueStates = new ArrayList<SimpleValueRelationalState>(
|
||||||
mappedColumnsOrFormulas == null || mappedColumnsOrFormulas.isEmpty() ?
|
mappedColumnsOrFormulas == null || mappedColumnsOrFormulas.isEmpty()
|
||||||
1 :
|
? 1
|
||||||
mappedColumnsOrFormulas.size()
|
: mappedColumnsOrFormulas.size()
|
||||||
);
|
);
|
||||||
if ( mappedColumnsOrFormulas != null && ! mappedColumnsOrFormulas.isEmpty() ) {
|
if ( mappedColumnsOrFormulas != null && ! mappedColumnsOrFormulas.isEmpty() ) {
|
||||||
for ( Object mappedColumnOrFormula : mappedColumnsOrFormulas ) {
|
for ( Object mappedColumnOrFormula : mappedColumnsOrFormulas ) {
|
||||||
|
|
|
@ -89,6 +89,8 @@ public class MetadataBuilderImpl implements MetadataBuilder {
|
||||||
private SharedCacheMode sharedCacheMode = SharedCacheMode.ENABLE_SELECTIVE;
|
private SharedCacheMode sharedCacheMode = SharedCacheMode.ENABLE_SELECTIVE;
|
||||||
private AccessType defaultCacheAccessType;
|
private AccessType defaultCacheAccessType;
|
||||||
private boolean useNewIdentifierGenerators;
|
private boolean useNewIdentifierGenerators;
|
||||||
|
private String defaultSchemaName;
|
||||||
|
private String defaultCatalogName;
|
||||||
|
|
||||||
public OptionsImpl(BasicServiceRegistry serviceRegistry) {
|
public OptionsImpl(BasicServiceRegistry serviceRegistry) {
|
||||||
ConfigurationService configService = serviceRegistry.getService( ConfigurationService.class );
|
ConfigurationService configService = serviceRegistry.getService( ConfigurationService.class );
|
||||||
|
@ -114,6 +116,28 @@ public class MetadataBuilderImpl implements MetadataBuilder {
|
||||||
},
|
},
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
|
defaultSchemaName = configService.getSetting(
|
||||||
|
AvailableSettings.DEFAULT_SCHEMA,
|
||||||
|
new ConfigurationService.Converter<String>() {
|
||||||
|
@Override
|
||||||
|
public String convert(Object value) {
|
||||||
|
return value.toString();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
null
|
||||||
|
);
|
||||||
|
|
||||||
|
defaultCatalogName = configService.getSetting(
|
||||||
|
AvailableSettings.DEFAULT_CATALOG,
|
||||||
|
new ConfigurationService.Converter<String>() {
|
||||||
|
@Override
|
||||||
|
public String convert(Object value) {
|
||||||
|
return value.toString();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
null
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -141,5 +165,15 @@ public class MetadataBuilderImpl implements MetadataBuilder {
|
||||||
public boolean useNewIdentifierGenerators() {
|
public boolean useNewIdentifierGenerators() {
|
||||||
return useNewIdentifierGenerators;
|
return useNewIdentifierGenerators;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDefaultSchemaName() {
|
||||||
|
return defaultSchemaName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDefaultCatalogName() {
|
||||||
|
return defaultCatalogName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,7 @@ import org.jboss.logging.Logger;
|
||||||
import org.hibernate.DuplicateMappingException;
|
import org.hibernate.DuplicateMappingException;
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
|
import org.hibernate.cfg.NamingStrategy;
|
||||||
import org.hibernate.engine.spi.FilterDefinition;
|
import org.hibernate.engine.spi.FilterDefinition;
|
||||||
import org.hibernate.engine.spi.NamedQueryDefinition;
|
import org.hibernate.engine.spi.NamedQueryDefinition;
|
||||||
import org.hibernate.engine.spi.NamedSQLQueryDefinition;
|
import org.hibernate.engine.spi.NamedSQLQueryDefinition;
|
||||||
|
@ -59,8 +60,12 @@ import org.hibernate.metamodel.source.annotations.AnnotationBinder;
|
||||||
import org.hibernate.metamodel.source.annotations.xml.OrmXmlParser;
|
import org.hibernate.metamodel.source.annotations.xml.OrmXmlParser;
|
||||||
import org.hibernate.metamodel.source.hbm.HbmBinder;
|
import org.hibernate.metamodel.source.hbm.HbmBinder;
|
||||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping;
|
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping;
|
||||||
|
import org.hibernate.metamodel.source.spi.BindingContext;
|
||||||
|
import org.hibernate.metamodel.source.spi.MappingDefaults;
|
||||||
|
import org.hibernate.metamodel.source.spi.MetaAttributeContext;
|
||||||
import org.hibernate.metamodel.source.spi.MetadataImplementor;
|
import org.hibernate.metamodel.source.spi.MetadataImplementor;
|
||||||
import org.hibernate.service.BasicServiceRegistry;
|
import org.hibernate.service.BasicServiceRegistry;
|
||||||
|
import org.hibernate.service.ServiceRegistry;
|
||||||
import org.hibernate.service.classloading.spi.ClassLoaderService;
|
import org.hibernate.service.classloading.spi.ClassLoaderService;
|
||||||
import org.hibernate.type.TypeResolver;
|
import org.hibernate.type.TypeResolver;
|
||||||
|
|
||||||
|
@ -86,6 +91,8 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
|
||||||
|
|
||||||
private final Database database = new Database();
|
private final Database database = new Database();
|
||||||
|
|
||||||
|
private final MappingDefaults mappingDefaults;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maps the fully qualified class name of an entity to its entity binding
|
* Maps the fully qualified class name of an entity to its entity binding
|
||||||
*/
|
*/
|
||||||
|
@ -106,6 +113,9 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
|
||||||
this.serviceRegistry = metadataSources.getServiceRegistry();
|
this.serviceRegistry = metadataSources.getServiceRegistry();
|
||||||
this.options = options;
|
this.options = options;
|
||||||
|
|
||||||
|
this.mappingDefaults = new MappingDefaultsImpl();
|
||||||
|
|
||||||
|
applyIndependentMetadata();
|
||||||
final ArrayList<String> processedEntityNames = new ArrayList<String>();
|
final ArrayList<String> processedEntityNames = new ArrayList<String>();
|
||||||
if ( options.getSourceProcessingOrder() == SourceProcessingOrder.HBM_FIRST ) {
|
if ( options.getSourceProcessingOrder() == SourceProcessingOrder.HBM_FIRST ) {
|
||||||
applyHibernateMappings( metadataSources, processedEntityNames );
|
applyHibernateMappings( metadataSources, processedEntityNames );
|
||||||
|
@ -119,6 +129,10 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
|
||||||
new EntityReferenceResolver( this ).resolve();
|
new EntityReferenceResolver( this ).resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void applyIndependentMetadata() {
|
||||||
|
// todo : implement method body
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addFetchProfile(FetchProfile profile) {
|
public void addFetchProfile(FetchProfile profile) {
|
||||||
fetchProfiles.put( profile.getName(), profile );
|
fetchProfiles.put( profile.getName(), profile );
|
||||||
|
@ -193,12 +207,11 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyHibernateMappings(MetadataSources metadataSources, List<String> processedEntityNames) {
|
private void applyHibernateMappings(MetadataSources metadataSources, List<String> processedEntityNames) {
|
||||||
|
|
||||||
for ( JaxbRoot jaxbRoot : metadataSources.getJaxbRootList() ) {
|
for ( JaxbRoot jaxbRoot : metadataSources.getJaxbRootList() ) {
|
||||||
// filter to just hbm-based roots
|
// filter to just hbm-based roots
|
||||||
if ( jaxbRoot.getRoot() instanceof XMLHibernateMapping ) {
|
if ( jaxbRoot.getRoot() instanceof XMLHibernateMapping ) {
|
||||||
final HbmBinder mappingBinder = new HbmBinder(
|
final HbmBinder mappingBinder = new HbmBinder( this, jaxbRoot );
|
||||||
this, Collections.<String, MetaAttribute>emptyMap(), jaxbRoot
|
|
||||||
);
|
|
||||||
mappingBinder.processHibernateMapping();
|
mappingBinder.processHibernateMapping();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -331,4 +344,79 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
|
||||||
public TypeResolver getTypeResolver() {
|
public TypeResolver getTypeResolver() {
|
||||||
return typeResolver;
|
return typeResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NamingStrategy getNamingStrategy() {
|
||||||
|
return options.getNamingStrategy();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MappingDefaults getMappingDefaults() {
|
||||||
|
return mappingDefaults;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final MetaAttributeContext globalMetaAttributeContext = new MetaAttributeContext();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MetaAttributeContext getMetaAttributeContext() {
|
||||||
|
return globalMetaAttributeContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MetadataImplementor getMetadataImplementor() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final String DEFAULT_IDENTIFIER_COLUMN_NAME = "id";
|
||||||
|
private static final String DEFAULT_DISCRIMINATOR_COLUMN_NAME = "class";
|
||||||
|
private static final String DEFAULT_CASCADE = "none";
|
||||||
|
private static final String DEFAULT_PROPERTY_ACCESS = "property";
|
||||||
|
|
||||||
|
private class MappingDefaultsImpl implements MappingDefaults {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPackageName() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDefaultSchemaName() {
|
||||||
|
return options.getDefaultSchemaName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDefaultCatalogName() {
|
||||||
|
return options.getDefaultCatalogName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDefaultIdColumnName() {
|
||||||
|
return DEFAULT_IDENTIFIER_COLUMN_NAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDefaultDiscriminatorColumnName() {
|
||||||
|
return DEFAULT_DISCRIMINATOR_COLUMN_NAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDefaultCascade() {
|
||||||
|
return DEFAULT_CASCADE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDefaultAccess() {
|
||||||
|
return DEFAULT_PROPERTY_ACCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDefaultLazy() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, MetaAttribute> getMappingMetas() {
|
||||||
|
return Collections.emptyMap();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,116 @@
|
||||||
|
/*
|
||||||
|
* 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.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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Steve Ebersole
|
||||||
|
*/
|
||||||
|
public class OverriddenMappingDefaults implements MappingDefaults {
|
||||||
|
private MappingDefaults overriddenValues;
|
||||||
|
|
||||||
|
private final String packageName;
|
||||||
|
private final String schemaName;
|
||||||
|
private final String catalogName;
|
||||||
|
private final String idColumnName;
|
||||||
|
private final String discriminatorColumnName;
|
||||||
|
private final String cascade;
|
||||||
|
private final String propertyAccess;
|
||||||
|
private final Boolean associationLaziness;
|
||||||
|
|
||||||
|
public OverriddenMappingDefaults(
|
||||||
|
MappingDefaults overriddenValues,
|
||||||
|
String packageName,
|
||||||
|
String schemaName,
|
||||||
|
String catalogName,
|
||||||
|
String idColumnName,
|
||||||
|
String discriminatorColumnName,
|
||||||
|
String cascade,
|
||||||
|
String propertyAccess,
|
||||||
|
Boolean associationLaziness) {
|
||||||
|
if ( overriddenValues == null ) {
|
||||||
|
throw new IllegalArgumentException( "Overridden values cannot be null" );
|
||||||
|
}
|
||||||
|
this.overriddenValues = overriddenValues;
|
||||||
|
this.packageName = packageName;
|
||||||
|
this.schemaName = schemaName;
|
||||||
|
this.catalogName = catalogName;
|
||||||
|
this.idColumnName = idColumnName;
|
||||||
|
this.discriminatorColumnName = discriminatorColumnName;
|
||||||
|
this.cascade = cascade;
|
||||||
|
this.propertyAccess = propertyAccess;
|
||||||
|
this.associationLaziness = associationLaziness;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPackageName() {
|
||||||
|
return packageName == null ? overriddenValues.getPackageName() : packageName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDefaultSchemaName() {
|
||||||
|
return schemaName == null ? overriddenValues.getDefaultSchemaName() : schemaName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDefaultCatalogName() {
|
||||||
|
return catalogName == null ? overriddenValues.getDefaultCatalogName() : catalogName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDefaultIdColumnName() {
|
||||||
|
return idColumnName == null ? overriddenValues.getDefaultIdColumnName() : idColumnName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDefaultDiscriminatorColumnName() {
|
||||||
|
return discriminatorColumnName == null ? overriddenValues.getDefaultDiscriminatorColumnName() : discriminatorColumnName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDefaultCascade() {
|
||||||
|
return cascade == null ? overriddenValues.getDefaultCascade() : cascade;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDefaultAccess() {
|
||||||
|
return propertyAccess == null ? overriddenValues.getDefaultAccess() : propertyAccess;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDefaultLazy() {
|
||||||
|
return associationLaziness == null ? overriddenValues.isDefaultLazy() : associationLaziness;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, MetaAttribute> getMappingMetas() {
|
||||||
|
return null; // todo : implement method body
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,107 @@
|
||||||
|
/*
|
||||||
|
* 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.source.internal;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.hibernate.metamodel.domain.MetaAttribute;
|
||||||
|
import org.hibernate.metamodel.source.spi.MappingDefaults;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Steve Ebersole
|
||||||
|
*/
|
||||||
|
public class RootMappingDefaults implements MappingDefaults {
|
||||||
|
private final String packageName;
|
||||||
|
private final String schemaName;
|
||||||
|
private final String catalogName;
|
||||||
|
private final String idColumnName;
|
||||||
|
private final String discriminatorColumnName;
|
||||||
|
private final String cascade;
|
||||||
|
private final String propertyAccess;
|
||||||
|
private final boolean associationLaziness;
|
||||||
|
|
||||||
|
public RootMappingDefaults(
|
||||||
|
String packageName,
|
||||||
|
String schemaName,
|
||||||
|
String catalogName,
|
||||||
|
String idColumnName,
|
||||||
|
String discriminatorColumnName,
|
||||||
|
String cascade,
|
||||||
|
String propertyAccess,
|
||||||
|
boolean associationLaziness) {
|
||||||
|
this.packageName = packageName;
|
||||||
|
this.schemaName = schemaName;
|
||||||
|
this.catalogName = catalogName;
|
||||||
|
this.idColumnName = idColumnName;
|
||||||
|
this.discriminatorColumnName = discriminatorColumnName;
|
||||||
|
this.cascade = cascade;
|
||||||
|
this.propertyAccess = propertyAccess;
|
||||||
|
this.associationLaziness = associationLaziness;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPackageName() {
|
||||||
|
return packageName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDefaultSchemaName() {
|
||||||
|
return schemaName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDefaultCatalogName() {
|
||||||
|
return catalogName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDefaultIdColumnName() {
|
||||||
|
return idColumnName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDefaultDiscriminatorColumnName() {
|
||||||
|
return discriminatorColumnName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDefaultCascade() {
|
||||||
|
return cascade;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDefaultAccess() {
|
||||||
|
return propertyAccess;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDefaultLazy() {
|
||||||
|
return associationLaziness;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, MetaAttribute> getMappingMetas() {
|
||||||
|
return null; // todo : implement method body
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
/*
|
||||||
|
* 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.source.spi;
|
||||||
|
|
||||||
|
import org.hibernate.cfg.NamingStrategy;
|
||||||
|
import org.hibernate.service.ServiceRegistry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Steve Ebersole
|
||||||
|
*/
|
||||||
|
public interface BindingContext {
|
||||||
|
public ServiceRegistry getServiceRegistry();
|
||||||
|
|
||||||
|
public NamingStrategy getNamingStrategy();
|
||||||
|
|
||||||
|
public MappingDefaults getMappingDefaults();
|
||||||
|
|
||||||
|
public MetaAttributeContext getMetaAttributeContext();
|
||||||
|
|
||||||
|
public MetadataImplementor getMetadataImplementor();
|
||||||
|
}
|
|
@ -21,7 +21,7 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.metamodel.source.hbm;
|
package org.hibernate.metamodel.source.spi;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -31,9 +31,9 @@ import org.hibernate.service.ServiceRegistry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Gail Badner
|
* @author Gail Badner
|
||||||
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public interface MappingDefaults {
|
public interface MappingDefaults {
|
||||||
Map<String, MetaAttribute> getMappingMetas();
|
|
||||||
|
|
||||||
String getPackageName();
|
String getPackageName();
|
||||||
|
|
||||||
|
@ -51,7 +51,8 @@ public interface MappingDefaults {
|
||||||
|
|
||||||
boolean isDefaultLazy();
|
boolean isDefaultLazy();
|
||||||
|
|
||||||
ServiceRegistry getServiceRegistry();
|
|
||||||
|
|
||||||
NamingStrategy getNamingStrategy();
|
// Not happy about these here ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
Map<String, MetaAttribute> getMappingMetas();
|
||||||
}
|
}
|
|
@ -0,0 +1,88 @@
|
||||||
|
/*
|
||||||
|
* 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.source.spi;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.hibernate.metamodel.domain.MetaAttribute;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Steve Ebersole
|
||||||
|
*/
|
||||||
|
public class MetaAttributeContext {
|
||||||
|
private final MetaAttributeContext parentContext;
|
||||||
|
private final ConcurrentHashMap<String, MetaAttribute> metaAttributeMap = new ConcurrentHashMap<String, MetaAttribute>();
|
||||||
|
|
||||||
|
public MetaAttributeContext() {
|
||||||
|
this( null );
|
||||||
|
}
|
||||||
|
|
||||||
|
public MetaAttributeContext(MetaAttributeContext parentContext) {
|
||||||
|
this.parentContext = parentContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// read contract ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
public Iterable<String> getKeys() {
|
||||||
|
HashSet<String> keys = new HashSet<String>();
|
||||||
|
addKeys( keys );
|
||||||
|
return keys;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addKeys(Set<String> keys) {
|
||||||
|
keys.addAll( metaAttributeMap.keySet() );
|
||||||
|
if ( parentContext != null ) {
|
||||||
|
// recursive call
|
||||||
|
parentContext.addKeys( keys );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Iterable<String> getLocalKeys() {
|
||||||
|
return metaAttributeMap.keySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
public MetaAttribute getMetaAttribute(String key) {
|
||||||
|
MetaAttribute value = getLocalMetaAttribute( key );
|
||||||
|
if ( value == null ) {
|
||||||
|
// recursive call
|
||||||
|
value = parentContext.getMetaAttribute( key );
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MetaAttribute getLocalMetaAttribute(String key) {
|
||||||
|
return metaAttributeMap.get( key );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// write contract ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
public void add(MetaAttribute metaAttribute) {
|
||||||
|
metaAttributeMap.put( metaAttribute.getName(), metaAttribute );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -27,7 +27,6 @@ import org.hibernate.engine.spi.FilterDefinition;
|
||||||
import org.hibernate.metamodel.Metadata;
|
import org.hibernate.metamodel.Metadata;
|
||||||
import org.hibernate.metamodel.binding.EntityBinding;
|
import org.hibernate.metamodel.binding.EntityBinding;
|
||||||
import org.hibernate.metamodel.binding.FetchProfile;
|
import org.hibernate.metamodel.binding.FetchProfile;
|
||||||
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.relational.AuxiliaryDatabaseObject;
|
import org.hibernate.metamodel.relational.AuxiliaryDatabaseObject;
|
||||||
|
@ -38,15 +37,11 @@ import org.hibernate.type.TypeResolver;
|
||||||
/**
|
/**
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public interface MetadataImplementor extends Metadata {
|
public interface MetadataImplementor extends Metadata, BindingContext {
|
||||||
public BasicServiceRegistry getServiceRegistry();
|
public BasicServiceRegistry getServiceRegistry();
|
||||||
|
|
||||||
public Database getDatabase();
|
public Database getDatabase();
|
||||||
|
|
||||||
public Iterable<EntityBinding> getEntityBindings();
|
|
||||||
|
|
||||||
public EntityBinding getEntityBinding(String entityName);
|
|
||||||
|
|
||||||
public TypeResolver getTypeResolver();
|
public TypeResolver getTypeResolver();
|
||||||
|
|
||||||
public void addImport(String entityName, String entityName1);
|
public void addImport(String entityName, String entityName1);
|
||||||
|
@ -59,15 +54,9 @@ public interface MetadataImplementor extends Metadata {
|
||||||
|
|
||||||
public void addTypeDefinition(TypeDef typeDef);
|
public void addTypeDefinition(TypeDef typeDef);
|
||||||
|
|
||||||
public Iterable<TypeDef> getTypeDefinitions();
|
|
||||||
|
|
||||||
public void addFilterDefinition(FilterDefinition filterDefinition);
|
public void addFilterDefinition(FilterDefinition filterDefinition);
|
||||||
|
|
||||||
public Iterable<FilterDefinition> getFilterDefinitions();
|
|
||||||
|
|
||||||
public void registerIdentifierGenerator(String name, String clazz);
|
public void registerIdentifierGenerator(String name, String clazz);
|
||||||
|
|
||||||
public IdGenerator getIdGenerator(String name);
|
|
||||||
|
|
||||||
public void addAuxiliaryDatabaseObject(AuxiliaryDatabaseObject auxiliaryDatabaseObject);
|
public void addAuxiliaryDatabaseObject(AuxiliaryDatabaseObject auxiliaryDatabaseObject);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue