HHH-8355 : Extract Binder code related to relational objects into helpers
This commit is contained in:
parent
d7d4407bad
commit
41513dbb2c
|
@ -44,7 +44,6 @@ import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
import org.hibernate.cfg.NamingStrategy;
|
import org.hibernate.cfg.NamingStrategy;
|
||||||
import org.hibernate.cfg.NotYetImplementedException;
|
import org.hibernate.cfg.NotYetImplementedException;
|
||||||
import org.hibernate.cfg.ObjectNameNormalizer;
|
|
||||||
import org.hibernate.engine.FetchStyle;
|
import org.hibernate.engine.FetchStyle;
|
||||||
import org.hibernate.engine.FetchTiming;
|
import org.hibernate.engine.FetchTiming;
|
||||||
import org.hibernate.engine.config.spi.ConfigurationService;
|
import org.hibernate.engine.config.spi.ConfigurationService;
|
||||||
|
@ -63,7 +62,6 @@ import org.hibernate.internal.FilterConfiguration;
|
||||||
import org.hibernate.internal.util.ReflectHelper;
|
import org.hibernate.internal.util.ReflectHelper;
|
||||||
import org.hibernate.internal.util.StringHelper;
|
import org.hibernate.internal.util.StringHelper;
|
||||||
import org.hibernate.internal.util.ValueHolder;
|
import org.hibernate.internal.util.ValueHolder;
|
||||||
import org.hibernate.jaxb.spi.Origin;
|
|
||||||
import org.hibernate.metamodel.internal.EntityHierarchyHelper.LocalBindingContextExecutionContext;
|
import org.hibernate.metamodel.internal.EntityHierarchyHelper.LocalBindingContextExecutionContext;
|
||||||
import org.hibernate.metamodel.internal.EntityHierarchyHelper.LocalBindingContextExecutor;
|
import org.hibernate.metamodel.internal.EntityHierarchyHelper.LocalBindingContextExecutor;
|
||||||
import org.hibernate.metamodel.internal.HibernateTypeHelper.ReflectedCollectionJavaTypes;
|
import org.hibernate.metamodel.internal.HibernateTypeHelper.ReflectedCollectionJavaTypes;
|
||||||
|
@ -143,8 +141,6 @@ import org.hibernate.metamodel.spi.source.JoinedSubclassEntitySource;
|
||||||
import org.hibernate.metamodel.spi.source.LocalBindingContext;
|
import org.hibernate.metamodel.spi.source.LocalBindingContext;
|
||||||
import org.hibernate.metamodel.spi.source.ManyToManyPluralAttributeElementSource;
|
import org.hibernate.metamodel.spi.source.ManyToManyPluralAttributeElementSource;
|
||||||
import org.hibernate.metamodel.spi.source.MappedByAssociationSource;
|
import org.hibernate.metamodel.spi.source.MappedByAssociationSource;
|
||||||
import org.hibernate.metamodel.spi.source.MappingDefaults;
|
|
||||||
import org.hibernate.metamodel.spi.source.MappingException;
|
|
||||||
import org.hibernate.metamodel.spi.source.MetaAttributeContext;
|
import org.hibernate.metamodel.spi.source.MetaAttributeContext;
|
||||||
import org.hibernate.metamodel.spi.source.MetaAttributeSource;
|
import org.hibernate.metamodel.spi.source.MetaAttributeSource;
|
||||||
import org.hibernate.metamodel.spi.source.MultiTenancySource;
|
import org.hibernate.metamodel.spi.source.MultiTenancySource;
|
||||||
|
@ -167,11 +163,9 @@ import org.hibernate.metamodel.spi.source.UniqueConstraintSource;
|
||||||
import org.hibernate.metamodel.spi.source.VersionAttributeSource;
|
import org.hibernate.metamodel.spi.source.VersionAttributeSource;
|
||||||
import org.hibernate.persister.collection.CollectionPersister;
|
import org.hibernate.persister.collection.CollectionPersister;
|
||||||
import org.hibernate.persister.entity.EntityPersister;
|
import org.hibernate.persister.entity.EntityPersister;
|
||||||
import org.hibernate.service.ServiceRegistry;
|
|
||||||
import org.hibernate.tuple.component.ComponentMetamodel;
|
import org.hibernate.tuple.component.ComponentMetamodel;
|
||||||
import org.hibernate.tuple.component.ComponentTuplizer;
|
import org.hibernate.tuple.component.ComponentTuplizer;
|
||||||
import org.hibernate.tuple.entity.EntityTuplizer;
|
import org.hibernate.tuple.entity.EntityTuplizer;
|
||||||
import org.hibernate.type.EntityType;
|
|
||||||
import org.hibernate.type.ForeignKeyDirection;
|
import org.hibernate.type.ForeignKeyDirection;
|
||||||
import org.hibernate.type.Type;
|
import org.hibernate.type.Type;
|
||||||
import org.jboss.logging.Logger;
|
import org.jboss.logging.Logger;
|
||||||
|
@ -187,15 +181,13 @@ import org.jboss.logging.Logger;
|
||||||
* @author Brett Meyer
|
* @author Brett Meyer
|
||||||
* @author Strong Liu
|
* @author Strong Liu
|
||||||
*/
|
*/
|
||||||
public class Binder {
|
public class Binder implements HelperContext {
|
||||||
private static final CoreMessageLogger log = Logger.getMessageLogger(
|
private static final CoreMessageLogger log = Logger.getMessageLogger(
|
||||||
CoreMessageLogger.class,
|
CoreMessageLogger.class,
|
||||||
Binder.class.getName()
|
Binder.class.getName()
|
||||||
);
|
);
|
||||||
|
|
||||||
private final MetadataImplementor metadata;
|
|
||||||
private final IdentifierGeneratorFactory identifierGeneratorFactory;
|
private final IdentifierGeneratorFactory identifierGeneratorFactory;
|
||||||
private final ObjectNameNormalizer nameNormalizer;
|
|
||||||
|
|
||||||
// Entity hierarchies and source index need be available throughout the binding process
|
// Entity hierarchies and source index need be available throughout the binding process
|
||||||
private final Map<String, EntityHierarchy> entityHierarchiesByRootEntityName =
|
private final Map<String, EntityHierarchy> entityHierarchiesByRootEntityName =
|
||||||
|
@ -204,14 +196,17 @@ public class Binder {
|
||||||
|
|
||||||
// todo : apply org.hibernate.metamodel.MetadataSources.getExternalCacheRegionDefinitions()
|
// todo : apply org.hibernate.metamodel.MetadataSources.getExternalCacheRegionDefinitions()
|
||||||
|
|
||||||
private final LocalBindingContext bindingContext;
|
private final MetadataImplementor metadata;
|
||||||
|
|
||||||
|
private final EntityHierarchyHelper.LocalBindingContextManager localBindingContextManager;
|
||||||
|
|
||||||
// helpers
|
|
||||||
private final EntityHierarchyHelper entityHierarchyHelper;
|
private final EntityHierarchyHelper entityHierarchyHelper;
|
||||||
private final HibernateTypeHelper typeHelper; // todo: refactor helper and remove redundant methods in this class
|
private final HibernateTypeHelper typeHelper; // todo: refactor helper and remove redundant methods in this class
|
||||||
|
private final RelationalIdentifierHelper relationalIdentifierHelper;
|
||||||
private final TableHelper tableHelper;
|
private final TableHelper tableHelper;
|
||||||
private final ForeignKeyHelper foreignKeyHelper;
|
private final ForeignKeyHelper foreignKeyHelper;
|
||||||
private final RelationalValueBindingHelper relationalValueBindingHelper;
|
private final RelationalValueBindingHelper relationalValueBindingHelper;
|
||||||
|
private final NaturalIdUniqueKeyHelper naturalIdUniqueKeyHelper;
|
||||||
|
|
||||||
private final StandardAssociationRelationalBindingResolverImpl standardAssociationRelationalBindingResolver;
|
private final StandardAssociationRelationalBindingResolverImpl standardAssociationRelationalBindingResolver;
|
||||||
private final MappedByAssociationRelationalBindingResolverImpl mappedByAssociationRelationalBindingResolver;
|
private final MappedByAssociationRelationalBindingResolverImpl mappedByAssociationRelationalBindingResolver;
|
||||||
|
@ -220,17 +215,18 @@ public class Binder {
|
||||||
final IdentifierGeneratorFactory identifierGeneratorFactory) {
|
final IdentifierGeneratorFactory identifierGeneratorFactory) {
|
||||||
this.metadata = metadata;
|
this.metadata = metadata;
|
||||||
this.identifierGeneratorFactory = identifierGeneratorFactory;
|
this.identifierGeneratorFactory = identifierGeneratorFactory;
|
||||||
this.entityHierarchyHelper = new EntityHierarchyHelper( metadata );
|
this.localBindingContextManager = new LocalBindingContextManagerImpl();
|
||||||
this.bindingContext = new BinderLocalBindingContextImpl( entityHierarchyHelper );
|
this.entityHierarchyHelper = new EntityHierarchyHelper( localBindingContextManager );
|
||||||
this.typeHelper = new HibernateTypeHelper( bindingContext );
|
this.typeHelper = new HibernateTypeHelper( this );
|
||||||
this.tableHelper = new TableHelper( bindingContext );
|
this.relationalIdentifierHelper = new RelationalIdentifierHelper( this );
|
||||||
this.foreignKeyHelper = new ForeignKeyHelper( bindingContext );
|
this.tableHelper = new TableHelper( this );
|
||||||
this.relationalValueBindingHelper = new RelationalValueBindingHelper( bindingContext );
|
this.foreignKeyHelper = new ForeignKeyHelper( this );
|
||||||
this.nameNormalizer = metadata.getObjectNameNormalizer();
|
this.relationalValueBindingHelper = new RelationalValueBindingHelper( this );
|
||||||
|
this.naturalIdUniqueKeyHelper = new NaturalIdUniqueKeyHelper();
|
||||||
this.standardAssociationRelationalBindingResolver =
|
this.standardAssociationRelationalBindingResolver =
|
||||||
new StandardAssociationRelationalBindingResolverImpl( bindingContext );
|
new StandardAssociationRelationalBindingResolverImpl( this );
|
||||||
this.mappedByAssociationRelationalBindingResolver =
|
this.mappedByAssociationRelationalBindingResolver =
|
||||||
new MappedByAssociationRelationalBindingResolverImpl( bindingContext );
|
new MappedByAssociationRelationalBindingResolverImpl( this );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,16 +243,22 @@ public class Binder {
|
||||||
LocalBindingContextExecutor executor = new LocalBindingContextExecutor() {
|
LocalBindingContextExecutor executor = new LocalBindingContextExecutor() {
|
||||||
@Override
|
@Override
|
||||||
public void execute(LocalBindingContextExecutionContext bindingContextContext) {
|
public void execute(LocalBindingContextExecutionContext bindingContextContext) {
|
||||||
sourceIndex.indexEntitySource( bindingContextContext.getRootEntitySource(), bindingContextContext.getEntitySource() );
|
sourceIndex.indexEntitySource(
|
||||||
|
bindingContextContext.getRootEntitySource(),
|
||||||
|
bindingContextContext.getEntitySource()
|
||||||
|
);
|
||||||
createEntityBinding(
|
createEntityBinding(
|
||||||
bindingContextContext.getSuperEntityBinding(),
|
bindingContextContext.getSuperEntityBinding(),
|
||||||
bindingContextContext.getEntitySource()
|
bindingContextContext.getEntitySource(),
|
||||||
|
bindingContextContext.getInheritanceType(),
|
||||||
|
bindingContextContext.getEntityMode()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
private void resolveEntityLaziness(
|
private void resolveEntityLaziness(
|
||||||
final EntityBinding entityBinding,
|
final EntityBinding entityBinding,
|
||||||
final EntitySource entitySource) {
|
final EntitySource entitySource,
|
||||||
if ( entityMode() == EntityMode.POJO ) {
|
final EntityMode entityMode) {
|
||||||
|
if ( entityMode == EntityMode.POJO ) {
|
||||||
final String proxy = entitySource.getProxy();
|
final String proxy = entitySource.getProxy();
|
||||||
if ( proxy == null ) {
|
if ( proxy == null ) {
|
||||||
if ( entitySource.isLazy() ) {
|
if ( entitySource.isLazy() ) {
|
||||||
|
@ -282,17 +284,16 @@ public class Binder {
|
||||||
}
|
}
|
||||||
private EntityBinding createEntityBinding(
|
private EntityBinding createEntityBinding(
|
||||||
final EntityBinding superEntityBinding,
|
final EntityBinding superEntityBinding,
|
||||||
final EntitySource entitySource) {
|
final EntitySource entitySource,
|
||||||
|
final InheritanceType inheritanceType,
|
||||||
|
final EntityMode entityMode) {
|
||||||
// Create binding
|
// Create binding
|
||||||
final EntityBinding entityBinding =
|
final EntityBinding entityBinding =
|
||||||
entitySource instanceof RootEntitySource ? new EntityBinding(
|
entitySource instanceof RootEntitySource ?
|
||||||
inheritanceType(),
|
new EntityBinding( inheritanceType, entityMode ) :
|
||||||
entityMode()
|
new EntityBinding( superEntityBinding );
|
||||||
) : new EntityBinding(
|
|
||||||
superEntityBinding
|
|
||||||
);
|
|
||||||
// Create domain entity
|
// Create domain entity
|
||||||
final String entityClassName = entityMode() == EntityMode.POJO ? entitySource.getClassName() : null;
|
final String entityClassName = entityMode == EntityMode.POJO ? entitySource.getClassName() : null;
|
||||||
LocalBindingContext bindingContext = bindingContext();
|
LocalBindingContext bindingContext = bindingContext();
|
||||||
entityBinding.setEntity(
|
entityBinding.setEntity(
|
||||||
new Entity(
|
new Entity(
|
||||||
|
@ -346,7 +347,7 @@ public class Binder {
|
||||||
if ( entitySource.getSynchronizedTableNames() != null ) {
|
if ( entitySource.getSynchronizedTableNames() != null ) {
|
||||||
entityBinding.addSynchronizedTableNames( entitySource.getSynchronizedTableNames() );
|
entityBinding.addSynchronizedTableNames( entitySource.getSynchronizedTableNames() );
|
||||||
}
|
}
|
||||||
resolveEntityLaziness( entityBinding, entitySource );
|
resolveEntityLaziness( entityBinding, entitySource, entityMode );
|
||||||
if ( entitySource.getFilterSources() != null ) {
|
if ( entitySource.getFilterSources() != null ) {
|
||||||
for ( FilterSource filterSource : entitySource.getFilterSources() ) {
|
for ( FilterSource filterSource : entitySource.getFilterSources() ) {
|
||||||
entityBinding.addFilterConfiguration( createFilterConfiguration( filterSource, entityBinding ) );
|
entityBinding.addFilterConfiguration( createFilterConfiguration( filterSource, entityBinding ) );
|
||||||
|
@ -415,6 +416,41 @@ public class Binder {
|
||||||
// TODO: when does this have to be done.
|
// TODO: when does this have to be done.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LocalBindingContext bindingContext() {
|
||||||
|
return localBindingContextManager.localBindingContext();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HibernateTypeHelper typeHelper() {
|
||||||
|
return typeHelper;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RelationalIdentifierHelper relationalIdentifierHelper() {
|
||||||
|
return relationalIdentifierHelper;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TableHelper tableHelper() {
|
||||||
|
return tableHelper;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ForeignKeyHelper foreignKeyHelper() {
|
||||||
|
return foreignKeyHelper;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RelationalValueBindingHelper relationalValueBindingHelper() {
|
||||||
|
return relationalValueBindingHelper;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NaturalIdUniqueKeyHelper naturalIdUniqueKeyHelper() {
|
||||||
|
return naturalIdUniqueKeyHelper;
|
||||||
|
}
|
||||||
|
|
||||||
private LocalBindingContextExecutor bindIdentifierGeneratorExecutor() {
|
private LocalBindingContextExecutor bindIdentifierGeneratorExecutor() {
|
||||||
return new LocalBindingContextExecutor() {
|
return new LocalBindingContextExecutor() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -427,24 +463,16 @@ public class Binder {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private InheritanceType inheritanceType() {
|
|
||||||
return entityHierarchyHelper.inheritanceType();
|
|
||||||
}
|
|
||||||
|
|
||||||
private EntityMode entityMode() {
|
|
||||||
return entityHierarchyHelper.entityMode();
|
|
||||||
}
|
|
||||||
|
|
||||||
private LocalBindingContext bindingContext() {
|
|
||||||
return bindingContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void applyToAllEntityHierarchies(LocalBindingContextExecutor executor) {
|
private void applyToAllEntityHierarchies(LocalBindingContextExecutor executor) {
|
||||||
applyToAllEntityHierarchies( executor, executor );
|
applyToAllEntityHierarchies( executor, executor );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyToAllEntityHierarchies(LocalBindingContextExecutor rootExecutor, LocalBindingContextExecutor subExecutor) {
|
private void applyToAllEntityHierarchies(LocalBindingContextExecutor rootExecutor, LocalBindingContextExecutor subExecutor) {
|
||||||
entityHierarchyHelper.applyToAllEntityHierarchies( entityHierarchiesByRootEntityName.values(), rootExecutor, subExecutor );
|
entityHierarchyHelper.applyToAllEntityHierarchies(
|
||||||
|
entityHierarchiesByRootEntityName.values(),
|
||||||
|
rootExecutor,
|
||||||
|
subExecutor
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -863,7 +891,11 @@ public class Binder {
|
||||||
for ( Iterator<EntityHierarchy> it = unresolvedEntityHierarchies.iterator(); it.hasNext(); ) {
|
for ( Iterator<EntityHierarchy> it = unresolvedEntityHierarchies.iterator(); it.hasNext(); ) {
|
||||||
final EntityHierarchy entityHierarchy = it.next();
|
final EntityHierarchy entityHierarchy = it.next();
|
||||||
try {
|
try {
|
||||||
entityHierarchyHelper.applyToEntityHierarchy( entityHierarchy, rootEntityCallback, subEntityCallback );
|
entityHierarchyHelper.applyToEntityHierarchy(
|
||||||
|
entityHierarchy,
|
||||||
|
rootEntityCallback,
|
||||||
|
subEntityCallback
|
||||||
|
);
|
||||||
// succeeded, so the entityHierarchy is no longer unresolved.
|
// succeeded, so the entityHierarchy is no longer unresolved.
|
||||||
it.remove();
|
it.remove();
|
||||||
}
|
}
|
||||||
|
@ -1457,7 +1489,10 @@ public class Binder {
|
||||||
properties.put( AvailableSettings.PREFER_POOLED_VALUES_LO, "false" );
|
properties.put( AvailableSettings.PREFER_POOLED_VALUES_LO, "false" );
|
||||||
}
|
}
|
||||||
if ( !properties.contains( PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER ) ) {
|
if ( !properties.contains( PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER ) ) {
|
||||||
properties.put( PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER, nameNormalizer );
|
properties.put(
|
||||||
|
PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER,
|
||||||
|
metadata.getObjectNameNormalizer()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
final EntityIdentifier entityIdentifier = rootEntityBinding.getHierarchyDetails().getEntityIdentifier();
|
final EntityIdentifier entityIdentifier = rootEntityBinding.getHierarchyDetails().getEntityIdentifier();
|
||||||
entityIdentifier.createIdentifierGenerator( identifierGeneratorFactory, properties );
|
entityIdentifier.createIdentifierGenerator( identifierGeneratorFactory, properties );
|
||||||
|
@ -2790,7 +2825,6 @@ public class Binder {
|
||||||
final PluralAttributeSource attributeSource) {
|
final PluralAttributeSource attributeSource) {
|
||||||
final PluralAttributeSource.Nature pluralAttributeSourceNature = attributeSource.getNature();
|
final PluralAttributeSource.Nature pluralAttributeSourceNature = attributeSource.getNature();
|
||||||
final PluralAttributeElementSource.Nature pluralElementSourceNature = attributeSource.getElementSource().getNature();
|
final PluralAttributeElementSource.Nature pluralElementSourceNature = attributeSource.getElementSource().getNature();
|
||||||
final PluralAttributeElementBinding.Nature pluralElementBindingNature = attributeBinding.getPluralAttributeElementBinding().getNature();
|
|
||||||
|
|
||||||
//TODO what is this case? it would be really good to add a comment
|
//TODO what is this case? it would be really good to add a comment
|
||||||
if ( pluralElementSourceNature == PluralAttributeElementSource.Nature.ONE_TO_MANY
|
if ( pluralElementSourceNature == PluralAttributeElementSource.Nature.ONE_TO_MANY
|
||||||
|
@ -3066,82 +3100,8 @@ public class Binder {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static interface DefaultNamingStrategy {
|
public static interface DefaultNamingStrategy {
|
||||||
|
|
||||||
String defaultName(NamingStrategy namingStrategy);
|
String defaultName(NamingStrategy namingStrategy);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class BinderLocalBindingContextImpl implements LocalBindingContext {
|
|
||||||
private final EntityHierarchyHelper entityHierarchyHelper;
|
|
||||||
|
|
||||||
BinderLocalBindingContextImpl(EntityHierarchyHelper entityHierarchyHelper) {
|
|
||||||
this.entityHierarchyHelper = entityHierarchyHelper;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Origin getOrigin() {
|
|
||||||
return bindingContext().getOrigin();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MappingException makeMappingException(String message) {
|
|
||||||
return bindingContext().makeMappingException( message );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MappingException makeMappingException(String message, Exception cause) {
|
|
||||||
return bindingContext().makeMappingException( message, cause );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ServiceRegistry getServiceRegistry() {
|
|
||||||
return bindingContext().getServiceRegistry();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public NamingStrategy getNamingStrategy() {
|
|
||||||
return bindingContext().getNamingStrategy();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MappingDefaults getMappingDefaults() {
|
|
||||||
return bindingContext().getMappingDefaults();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MetadataImplementor getMetadataImplementor() {
|
|
||||||
return bindingContext().getMetadataImplementor();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public <T> Class<T> locateClassByName(String name) {
|
|
||||||
return bindingContext().locateClassByName( name );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public org.hibernate.metamodel.spi.domain.Type makeJavaType(String className) {
|
|
||||||
return bindingContext().makeJavaType( className );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isGloballyQuotedIdentifiers() {
|
|
||||||
return bindingContext().isGloballyQuotedIdentifiers();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ValueHolder<Class<?>> makeClassReference(String className) {
|
|
||||||
return bindingContext().makeClassReference( className );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String qualifyClassName(String name) {
|
|
||||||
return bindingContext().qualifyClassName( name );
|
|
||||||
}
|
|
||||||
|
|
||||||
private LocalBindingContext bindingContext() {
|
|
||||||
return entityHierarchyHelper.bindingContext();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,10 +23,7 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.metamodel.internal;
|
package org.hibernate.metamodel.internal;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
|
||||||
|
|
||||||
import org.hibernate.EntityMode;
|
import org.hibernate.EntityMode;
|
||||||
import org.hibernate.metamodel.spi.MetadataImplementor;
|
|
||||||
import org.hibernate.metamodel.spi.binding.EntityBinding;
|
import org.hibernate.metamodel.spi.binding.EntityBinding;
|
||||||
import org.hibernate.metamodel.spi.binding.InheritanceType;
|
import org.hibernate.metamodel.spi.binding.InheritanceType;
|
||||||
import org.hibernate.metamodel.spi.source.EntityHierarchy;
|
import org.hibernate.metamodel.spi.source.EntityHierarchy;
|
||||||
|
@ -39,19 +36,32 @@ import org.hibernate.metamodel.spi.source.SubclassEntitySource;
|
||||||
* @author Gail Badner
|
* @author Gail Badner
|
||||||
*/
|
*/
|
||||||
public class EntityHierarchyHelper {
|
public class EntityHierarchyHelper {
|
||||||
|
|
||||||
public interface LocalBindingContextExecutor {
|
public interface LocalBindingContextExecutor {
|
||||||
void execute(LocalBindingContextExecutionContext bindingContextContext);
|
void execute(LocalBindingContextExecutionContext bindingContextContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
private MetadataImplementor metadata;
|
public interface LocalBindingContextExecutionContext {
|
||||||
|
RootEntitySource getRootEntitySource();
|
||||||
|
EntitySource getEntitySource();
|
||||||
|
EntityBinding getEntityBinding();
|
||||||
|
EntityBinding getSuperEntityBinding();
|
||||||
|
InheritanceType getInheritanceType();
|
||||||
|
EntityMode getEntityMode();
|
||||||
|
}
|
||||||
|
|
||||||
// the inheritanceTypes and entityModes correspond with bindingContexts
|
public static interface LocalBindingContextManager extends LocalBindingContextExecutionContext {
|
||||||
private final LinkedList<LocalBindingContext> bindingContexts = new LinkedList<LocalBindingContext>();
|
LocalBindingContext localBindingContext();
|
||||||
private final LinkedList<InheritanceType> inheritanceTypes = new LinkedList<InheritanceType>();
|
void cleanupLocalBindingContexts();
|
||||||
private final LinkedList<EntityMode> entityModes = new LinkedList<EntityMode>();
|
void setupLocalBindingContexts(final EntityHierarchy entityHierarchy);
|
||||||
|
void pushSubEntitySource(EntitySource entitySource);
|
||||||
|
void popSubEntitySource();
|
||||||
|
}
|
||||||
|
|
||||||
EntityHierarchyHelper(final MetadataImplementor metadata) {
|
private LocalBindingContextManager localBindingContextManager;
|
||||||
this.metadata = metadata;
|
|
||||||
|
EntityHierarchyHelper(final LocalBindingContextManager localBindingContextManager) {
|
||||||
|
this.localBindingContextManager = localBindingContextManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -79,127 +89,33 @@ public class EntityHierarchyHelper {
|
||||||
final EntityHierarchy entityHierarchy,
|
final EntityHierarchy entityHierarchy,
|
||||||
final LocalBindingContextExecutor rootEntityExecutor,
|
final LocalBindingContextExecutor rootEntityExecutor,
|
||||||
final LocalBindingContextExecutor subEntityExecutor) {
|
final LocalBindingContextExecutor subEntityExecutor) {
|
||||||
bindingContexts.clear();
|
localBindingContextManager.cleanupLocalBindingContexts();
|
||||||
inheritanceTypes.clear();
|
localBindingContextManager.setupLocalBindingContexts( entityHierarchy );
|
||||||
entityModes.clear();
|
|
||||||
final RootEntitySource rootEntitySource = entityHierarchy.getRootEntitySource();
|
|
||||||
setupBindingContext( entityHierarchy, rootEntitySource );
|
|
||||||
try {
|
try {
|
||||||
LocalBindingContextExecutionContext executionContext =
|
rootEntityExecutor.execute( localBindingContextManager );
|
||||||
new LocalBindingContextExecutionContextImpl( rootEntitySource, null );
|
if ( entityHierarchy.getHierarchyInheritanceType() != InheritanceType.NO_INHERITANCE ) {
|
||||||
rootEntityExecutor.execute( executionContext );
|
applyToSubEntities( subEntityExecutor );
|
||||||
if ( inheritanceTypes.peek() != InheritanceType.NO_INHERITANCE ) {
|
|
||||||
applyToSubEntities(
|
|
||||||
executionContext.getEntityBinding(),
|
|
||||||
rootEntitySource,
|
|
||||||
rootEntitySource,
|
|
||||||
subEntityExecutor );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
cleanupBindingContext();
|
localBindingContextManager.cleanupLocalBindingContexts();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cleanupBindingContext() {
|
private void applyToSubEntities(final LocalBindingContextExecutor subEntityExecutor) {
|
||||||
bindingContexts.pop();
|
for ( final SubclassEntitySource subEntitySource : localBindingContextManager.getEntitySource().subclassEntitySources() ) {
|
||||||
inheritanceTypes.pop();
|
applyToSubEntity( subEntitySource, subEntityExecutor );
|
||||||
entityModes.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
public LocalBindingContext bindingContext() {
|
|
||||||
return bindingContexts.peek();
|
|
||||||
}
|
|
||||||
|
|
||||||
public InheritanceType inheritanceType() {
|
|
||||||
return inheritanceTypes.peek();
|
|
||||||
}
|
|
||||||
|
|
||||||
public EntityMode entityMode() {
|
|
||||||
return entityModes.peek();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setupBindingContext(
|
|
||||||
final EntityHierarchy entityHierarchy,
|
|
||||||
final RootEntitySource rootEntitySource) {
|
|
||||||
// Save inheritance type and entity mode that will apply to entire hierarchy
|
|
||||||
inheritanceTypes.push( entityHierarchy.getHierarchyInheritanceType() );
|
|
||||||
entityModes.push( rootEntitySource.getEntityMode() );
|
|
||||||
bindingContexts.push( rootEntitySource.getLocalBindingContext() );
|
|
||||||
}
|
|
||||||
|
|
||||||
private void applyToSubEntities(
|
|
||||||
final EntityBinding entityBinding,
|
|
||||||
final RootEntitySource rootEntitySource,
|
|
||||||
final EntitySource entitySource,
|
|
||||||
final LocalBindingContextExecutor subEntityExecutor) {
|
|
||||||
for ( final SubclassEntitySource subEntitySource : entitySource.subclassEntitySources() ) {
|
|
||||||
applyToSubEntity( entityBinding, rootEntitySource, subEntitySource, subEntityExecutor );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyToSubEntity(
|
private void applyToSubEntity(final EntitySource entitySource, final LocalBindingContextExecutor subEntityExecutor) {
|
||||||
final EntityBinding superEntityBinding,
|
localBindingContextManager.pushSubEntitySource( entitySource );
|
||||||
final RootEntitySource rootEntitySource,
|
|
||||||
final EntitySource entitySource,
|
|
||||||
final LocalBindingContextExecutor subEntityExecutor) {
|
|
||||||
final LocalBindingContext bindingContext = entitySource.getLocalBindingContext();
|
|
||||||
bindingContexts.push( bindingContext );
|
|
||||||
try {
|
try {
|
||||||
LocalBindingContextExecutionContext executionContext =
|
subEntityExecutor.execute( localBindingContextManager );
|
||||||
new LocalBindingContextExecutionContextImpl( rootEntitySource, entitySource, superEntityBinding );
|
applyToSubEntities( subEntityExecutor );
|
||||||
subEntityExecutor.execute( executionContext );
|
|
||||||
applyToSubEntities( executionContext.getEntityBinding(), rootEntitySource, entitySource, subEntityExecutor );
|
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
bindingContexts.pop();
|
localBindingContextManager.popSubEntitySource();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface LocalBindingContextExecutionContext {
|
|
||||||
RootEntitySource getRootEntitySource();
|
|
||||||
EntitySource getEntitySource();
|
|
||||||
EntityBinding getEntityBinding();
|
|
||||||
EntityBinding getSuperEntityBinding();
|
|
||||||
}
|
|
||||||
|
|
||||||
private class LocalBindingContextExecutionContextImpl implements LocalBindingContextExecutionContext {
|
|
||||||
private final RootEntitySource rootEntitySource;
|
|
||||||
private final EntitySource entitySource;
|
|
||||||
private final EntityBinding superEntityBinding;
|
|
||||||
|
|
||||||
private LocalBindingContextExecutionContextImpl(
|
|
||||||
RootEntitySource rootEntitySource,
|
|
||||||
EntityBinding superEntityBinding) {
|
|
||||||
this.rootEntitySource = rootEntitySource;
|
|
||||||
this.entitySource = rootEntitySource;
|
|
||||||
this.superEntityBinding = superEntityBinding;
|
|
||||||
}
|
|
||||||
|
|
||||||
private LocalBindingContextExecutionContextImpl(
|
|
||||||
RootEntitySource rootEntitySource,
|
|
||||||
EntitySource entitySource,
|
|
||||||
EntityBinding superEntityBinding) {
|
|
||||||
this.rootEntitySource = rootEntitySource;
|
|
||||||
this.entitySource = entitySource;
|
|
||||||
this.superEntityBinding = superEntityBinding;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RootEntitySource getRootEntitySource() {
|
|
||||||
return rootEntitySource;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public EntitySource getEntitySource() {
|
|
||||||
return entitySource;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public EntityBinding getEntityBinding() {
|
|
||||||
return metadata.getEntityBinding( entitySource.getEntityName() );
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public EntityBinding getSuperEntityBinding() {
|
|
||||||
return superEntityBinding;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,12 +55,10 @@ public class ForeignKeyHelper {
|
||||||
ForeignKeyHelper.class.getName()
|
ForeignKeyHelper.class.getName()
|
||||||
);
|
);
|
||||||
|
|
||||||
private final LocalBindingContext bindingContext;
|
private final HelperContext helperContext;
|
||||||
private final RelationalIdentifierHelper relationalIdentifierHelper;
|
|
||||||
|
|
||||||
public ForeignKeyHelper(LocalBindingContext bindingContext) {
|
public ForeignKeyHelper(HelperContext helperContext) {
|
||||||
this.bindingContext = bindingContext;
|
this.helperContext = helperContext;
|
||||||
this.relationalIdentifierHelper = new RelationalIdentifierHelper( bindingContext );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Column> determineForeignKeyTargetColumns(
|
public List<Column> determineForeignKeyTargetColumns(
|
||||||
|
@ -82,7 +80,7 @@ public class ForeignKeyHelper {
|
||||||
final ForeignKeyContributingSource.JoinColumnResolutionContext resolutionContext = new JoinColumnResolutionContextImpl( entityBinding );
|
final ForeignKeyContributingSource.JoinColumnResolutionContext resolutionContext = new JoinColumnResolutionContextImpl( entityBinding );
|
||||||
for ( Value relationalValue : fkColumnResolutionDelegate.getJoinColumns( resolutionContext ) ) {
|
for ( Value relationalValue : fkColumnResolutionDelegate.getJoinColumns( resolutionContext ) ) {
|
||||||
if ( !Column.class.isInstance( relationalValue ) ) {
|
if ( !Column.class.isInstance( relationalValue ) ) {
|
||||||
throw bindingContext.makeMappingException(
|
throw bindingContext().makeMappingException(
|
||||||
"Foreign keys can currently only name columns, not formulas"
|
"Foreign keys can currently only name columns, not formulas"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -130,7 +128,7 @@ public class ForeignKeyHelper {
|
||||||
|
|
||||||
if ( referencedAttributeBinding == null ) {
|
if ( referencedAttributeBinding == null ) {
|
||||||
if ( explicitName != null ) {
|
if ( explicitName != null ) {
|
||||||
throw bindingContext.makeMappingException(
|
throw bindingContext().makeMappingException(
|
||||||
String.format(
|
String.format(
|
||||||
"No attribute binding found with name: %s.%s",
|
"No attribute binding found with name: %s.%s",
|
||||||
referencedEntityBinding.getEntityName(),
|
referencedEntityBinding.getEntityName(),
|
||||||
|
@ -146,7 +144,7 @@ public class ForeignKeyHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !referencedAttributeBinding.getAttribute().isSingular() ) {
|
if ( !referencedAttributeBinding.getAttribute().isSingular() ) {
|
||||||
throw bindingContext.makeMappingException(
|
throw bindingContext().makeMappingException(
|
||||||
String.format(
|
String.format(
|
||||||
"Foreign key references a non-singular attribute [%s]",
|
"Foreign key references a non-singular attribute [%s]",
|
||||||
referencedAttributeBinding.getAttribute().getName()
|
referencedAttributeBinding.getAttribute().getName()
|
||||||
|
@ -167,7 +165,7 @@ public class ForeignKeyHelper {
|
||||||
foreignKeyName = ForeignKey.generateName( sourceTable, targetTable, sourceColumns, targetColumns );
|
foreignKeyName = ForeignKey.generateName( sourceTable, targetTable, sourceColumns, targetColumns );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
foreignKeyName = relationalIdentifierHelper.quotedIdentifier( explicitForeignKeyName );
|
foreignKeyName = helperContext.relationalIdentifierHelper().quotedIdentifier( explicitForeignKeyName );
|
||||||
}
|
}
|
||||||
|
|
||||||
ForeignKey foreignKey = locateAndBindForeignKeyByName( foreignKeyName, sourceTable, sourceColumns, targetTable, targetColumns );
|
ForeignKey foreignKey = locateAndBindForeignKeyByName( foreignKeyName, sourceTable, sourceColumns, targetTable, targetColumns );
|
||||||
|
@ -227,7 +225,7 @@ public class ForeignKeyHelper {
|
||||||
final TableSpecification targetTable,
|
final TableSpecification targetTable,
|
||||||
final List<Column> targetColumns) {
|
final List<Column> targetColumns) {
|
||||||
if ( sourceColumns.size() != targetColumns.size() ) {
|
if ( sourceColumns.size() != targetColumns.size() ) {
|
||||||
throw bindingContext.makeMappingException(
|
throw bindingContext().makeMappingException(
|
||||||
String.format(
|
String.format(
|
||||||
"Non-matching number columns in foreign key source columns [%s : %s] and target columns [%s : %s]",
|
"Non-matching number columns in foreign key source columns [%s : %s] and target columns [%s : %s]",
|
||||||
sourceTable.getLogicalName().getText(),
|
sourceTable.getLogicalName().getText(),
|
||||||
|
@ -254,7 +252,7 @@ public class ForeignKeyHelper {
|
||||||
ForeignKey foreignKey = sourceTable.locateForeignKey( foreignKeyName );
|
ForeignKey foreignKey = sourceTable.locateForeignKey( foreignKeyName );
|
||||||
if ( foreignKey != null ) {
|
if ( foreignKey != null ) {
|
||||||
if ( !targetTable.equals( foreignKey.getTargetTable() ) ) {
|
if ( !targetTable.equals( foreignKey.getTargetTable() ) ) {
|
||||||
throw bindingContext.makeMappingException(
|
throw bindingContext().makeMappingException(
|
||||||
String.format(
|
String.format(
|
||||||
"Unexpected target table defined for foreign key \"%s\"; expected \"%s\"; found \"%s\"",
|
"Unexpected target table defined for foreign key \"%s\"; expected \"%s\"; found \"%s\"",
|
||||||
foreignKeyName,
|
foreignKeyName,
|
||||||
|
@ -273,7 +271,7 @@ public class ForeignKeyHelper {
|
||||||
// Make sure they are the same columns.
|
// Make sure they are the same columns.
|
||||||
if ( !foreignKey.getSourceColumns().equals( sourceColumns ) ||
|
if ( !foreignKey.getSourceColumns().equals( sourceColumns ) ||
|
||||||
!foreignKey.getTargetColumns().equals( targetColumns ) ) {
|
!foreignKey.getTargetColumns().equals( targetColumns ) ) {
|
||||||
throw bindingContext.makeMappingException(
|
throw bindingContext().makeMappingException(
|
||||||
String.format(
|
String.format(
|
||||||
"Attempt to bind exisitng foreign key \"%s\" with different columns.",
|
"Attempt to bind exisitng foreign key \"%s\" with different columns.",
|
||||||
foreignKeyName
|
foreignKeyName
|
||||||
|
@ -285,7 +283,11 @@ public class ForeignKeyHelper {
|
||||||
return foreignKey;
|
return foreignKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class JoinColumnResolutionContextImpl implements ForeignKeyContributingSource.JoinColumnResolutionContext {
|
private LocalBindingContext bindingContext() {
|
||||||
|
return helperContext.bindingContext();
|
||||||
|
}
|
||||||
|
|
||||||
|
private class JoinColumnResolutionContextImpl implements ForeignKeyContributingSource.JoinColumnResolutionContext {
|
||||||
private final EntityBinding referencedEntityBinding;
|
private final EntityBinding referencedEntityBinding;
|
||||||
|
|
||||||
|
|
||||||
|
@ -299,7 +301,7 @@ public class ForeignKeyHelper {
|
||||||
String logicalTableName,
|
String logicalTableName,
|
||||||
String logicalSchemaName,
|
String logicalSchemaName,
|
||||||
String logicalCatalogName) {
|
String logicalCatalogName) {
|
||||||
if ( bindingContext.isGloballyQuotedIdentifiers() && !org.hibernate
|
if ( bindingContext().isGloballyQuotedIdentifiers() && !org.hibernate
|
||||||
.internal
|
.internal
|
||||||
.util
|
.util
|
||||||
.StringHelper
|
.StringHelper
|
||||||
|
@ -313,7 +315,7 @@ public class ForeignKeyHelper {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TableSpecification resolveTable(String logicalTableName, String logicalSchemaName, String logicalCatalogName) {
|
public TableSpecification resolveTable(String logicalTableName, String logicalSchemaName, String logicalCatalogName) {
|
||||||
Identifier tableIdentifier = relationalIdentifierHelper.createIdentifier( logicalTableName );
|
Identifier tableIdentifier = helperContext.relationalIdentifierHelper().createIdentifier( logicalTableName );
|
||||||
if ( tableIdentifier == null ) {
|
if ( tableIdentifier == null ) {
|
||||||
tableIdentifier = referencedEntityBinding.getPrimaryTable().getLogicalName();
|
tableIdentifier = referencedEntityBinding.getPrimaryTable().getLogicalName();
|
||||||
}
|
}
|
||||||
|
@ -325,7 +327,7 @@ public class ForeignKeyHelper {
|
||||||
Identifier schemaName = org.hibernate.internal.util.StringHelper.isNotEmpty( logicalCatalogName ) ?
|
Identifier schemaName = org.hibernate.internal.util.StringHelper.isNotEmpty( logicalCatalogName ) ?
|
||||||
Identifier.toIdentifier( logicalSchemaName )
|
Identifier.toIdentifier( logicalSchemaName )
|
||||||
: referencedEntityBinding.getPrimaryTable().getSchema().getName().getSchema();
|
: referencedEntityBinding.getPrimaryTable().getSchema().getName().getSchema();
|
||||||
Schema schema = bindingContext.getMetadataImplementor().getDatabase().getSchema( catalogName, schemaName );
|
Schema schema = bindingContext().getMetadataImplementor().getDatabase().getSchema( catalogName, schemaName );
|
||||||
return schema.locateTable( tableIdentifier );
|
return schema.locateTable( tableIdentifier );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -364,7 +366,7 @@ public class ForeignKeyHelper {
|
||||||
final AttributeBinding referencedAttributeBinding =
|
final AttributeBinding referencedAttributeBinding =
|
||||||
referencedEntityBinding.locateAttributeBindingByPath( attributeName, true );
|
referencedEntityBinding.locateAttributeBindingByPath( attributeName, true );
|
||||||
if ( referencedAttributeBinding == null ) {
|
if ( referencedAttributeBinding == null ) {
|
||||||
throw bindingContext.makeMappingException(
|
throw bindingContext().makeMappingException(
|
||||||
String.format(
|
String.format(
|
||||||
"Could not resolve named referenced property [%s] against entity [%s]",
|
"Could not resolve named referenced property [%s] against entity [%s]",
|
||||||
attributeName,
|
attributeName,
|
||||||
|
@ -373,7 +375,7 @@ public class ForeignKeyHelper {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if ( !referencedAttributeBinding.getAttribute().isSingular() ) {
|
if ( !referencedAttributeBinding.getAttribute().isSingular() ) {
|
||||||
throw bindingContext.makeMappingException(
|
throw bindingContext().makeMappingException(
|
||||||
String.format(
|
String.format(
|
||||||
"Referenced property [%s] against entity [%s] is a plural attribute; it must be a singular attribute.",
|
"Referenced property [%s] against entity [%s] is a plural attribute; it must be a singular attribute.",
|
||||||
attributeName,
|
attributeName,
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2013, 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.internal;
|
||||||
|
|
||||||
|
import org.hibernate.metamodel.spi.source.LocalBindingContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Gail Badner
|
||||||
|
*/
|
||||||
|
public interface HelperContext {
|
||||||
|
HibernateTypeHelper typeHelper();
|
||||||
|
RelationalIdentifierHelper relationalIdentifierHelper();
|
||||||
|
TableHelper tableHelper();
|
||||||
|
ForeignKeyHelper foreignKeyHelper();
|
||||||
|
RelationalValueBindingHelper relationalValueBindingHelper();
|
||||||
|
NaturalIdUniqueKeyHelper naturalIdUniqueKeyHelper();
|
||||||
|
LocalBindingContext bindingContext();
|
||||||
|
}
|
|
@ -263,11 +263,11 @@ class HibernateTypeHelper {
|
||||||
}
|
}
|
||||||
//--------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------
|
||||||
|
|
||||||
private final LocalBindingContext bindingContext;
|
private final HelperContext helperContext;
|
||||||
|
|
||||||
//package scope methods
|
//package scope methods
|
||||||
HibernateTypeHelper(LocalBindingContext bindingContext) {
|
HibernateTypeHelper(HelperContext helperContext) {
|
||||||
this.bindingContext = bindingContext;
|
this.helperContext = helperContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -314,7 +314,7 @@ class HibernateTypeHelper {
|
||||||
? EntityType.class.cast( resolvedHibernateType ).getIdentifierOrUniqueKeyType( metadata() )
|
? EntityType.class.cast( resolvedHibernateType ).getIdentifierOrUniqueKeyType( metadata() )
|
||||||
: resolvedHibernateType;
|
: resolvedHibernateType;
|
||||||
if ( !CompositeType.class.isInstance( resolvedRelationalType ) ) {
|
if ( !CompositeType.class.isInstance( resolvedRelationalType ) ) {
|
||||||
throw bindingContext
|
throw bindingContext()
|
||||||
.makeMappingException( "Column number mismatch" ); // todo refine the exception message
|
.makeMappingException( "Column number mismatch" ); // todo refine the exception message
|
||||||
}
|
}
|
||||||
Type[] subTypes = CompositeType.class.cast( resolvedRelationalType ).getSubtypes();
|
Type[] subTypes = CompositeType.class.cast( resolvedRelationalType ).getSubtypes();
|
||||||
|
@ -591,7 +591,7 @@ class HibernateTypeHelper {
|
||||||
final String defaultJavaTypeName) {
|
final String defaultJavaTypeName) {
|
||||||
if ( explicitTypeName == null ) {
|
if ( explicitTypeName == null ) {
|
||||||
if ( defaultJavaTypeName != null && hibernateTypeDescriptor.getJavaTypeName() != null ) {
|
if ( defaultJavaTypeName != null && hibernateTypeDescriptor.getJavaTypeName() != null ) {
|
||||||
throw bindingContext.makeMappingException(
|
throw bindingContext().makeMappingException(
|
||||||
String.format(
|
String.format(
|
||||||
"Attempt to re-initialize (non-explicit) Java type name; current=%s new=%s",
|
"Attempt to re-initialize (non-explicit) Java type name; current=%s new=%s",
|
||||||
hibernateTypeDescriptor.getJavaTypeName(),
|
hibernateTypeDescriptor.getJavaTypeName(),
|
||||||
|
@ -605,7 +605,7 @@ class HibernateTypeHelper {
|
||||||
// Check if user-specified name is of a User-Defined Type (UDT)
|
// Check if user-specified name is of a User-Defined Type (UDT)
|
||||||
final TypeDefinition typeDef = metadata().getTypeDefinition( explicitTypeName );
|
final TypeDefinition typeDef = metadata().getTypeDefinition( explicitTypeName );
|
||||||
if ( hibernateTypeDescriptor.getExplicitTypeName() != null ) {
|
if ( hibernateTypeDescriptor.getExplicitTypeName() != null ) {
|
||||||
throw bindingContext.makeMappingException(
|
throw bindingContext().makeMappingException(
|
||||||
String.format(
|
String.format(
|
||||||
"Attempt to re-initialize explicity-mapped Java type name; current=%s new=%s",
|
"Attempt to re-initialize explicity-mapped Java type name; current=%s new=%s",
|
||||||
hibernateTypeDescriptor.getExplicitTypeName(),
|
hibernateTypeDescriptor.getExplicitTypeName(),
|
||||||
|
@ -632,7 +632,7 @@ class HibernateTypeHelper {
|
||||||
final SingularAttributeBinding attributeBinding,
|
final SingularAttributeBinding attributeBinding,
|
||||||
final Type resolvedHibernateType) {
|
final Type resolvedHibernateType) {
|
||||||
if ( resolvedHibernateType == null ) {
|
if ( resolvedHibernateType == null ) {
|
||||||
throw bindingContext.makeMappingException( "Resolved hibernate type can't be null" );
|
throw bindingContext().makeMappingException( "Resolved hibernate type can't be null" );
|
||||||
}
|
}
|
||||||
final HibernateTypeDescriptor hibernateTypeDescriptor = attributeBinding.getHibernateTypeDescriptor();
|
final HibernateTypeDescriptor hibernateTypeDescriptor = attributeBinding.getHibernateTypeDescriptor();
|
||||||
if ( hibernateTypeDescriptor.getResolvedTypeMapping() == null ) {
|
if ( hibernateTypeDescriptor.getResolvedTypeMapping() == null ) {
|
||||||
|
@ -701,12 +701,16 @@ class HibernateTypeHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private LocalBindingContext bindingContext() {
|
||||||
|
return helperContext.bindingContext();
|
||||||
|
}
|
||||||
|
|
||||||
private MetadataImplementor metadata() {
|
private MetadataImplementor metadata() {
|
||||||
return bindingContext.getMetadataImplementor();
|
return bindingContext().getMetadataImplementor();
|
||||||
}
|
}
|
||||||
|
|
||||||
private org.hibernate.metamodel.spi.domain.Type makeJavaType(String name) {
|
private org.hibernate.metamodel.spi.domain.Type makeJavaType(String name) {
|
||||||
return bindingContext.makeJavaType( name );
|
return bindingContext().makeJavaType( name );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,176 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2013, 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.internal;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
|
||||||
|
import org.hibernate.EntityMode;
|
||||||
|
import org.hibernate.metamodel.spi.MetadataImplementor;
|
||||||
|
import org.hibernate.metamodel.spi.binding.EntityBinding;
|
||||||
|
import org.hibernate.metamodel.spi.binding.InheritanceType;
|
||||||
|
import org.hibernate.metamodel.spi.source.EntityHierarchy;
|
||||||
|
import org.hibernate.metamodel.spi.source.EntitySource;
|
||||||
|
import org.hibernate.metamodel.spi.source.LocalBindingContext;
|
||||||
|
import org.hibernate.metamodel.spi.source.RootEntitySource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Gail Badner
|
||||||
|
*/
|
||||||
|
public class LocalBindingContextManagerImpl implements EntityHierarchyHelper.LocalBindingContextManager {
|
||||||
|
private final LocalBindingContextsImpl localBindingContexts = new LocalBindingContextsImpl();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void cleanupLocalBindingContexts() {
|
||||||
|
localBindingContexts.cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setupLocalBindingContexts(final EntityHierarchy entityHierarchy) {
|
||||||
|
localBindingContexts.setup( entityHierarchy );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void pushSubEntitySource(EntitySource entitySource) {
|
||||||
|
localBindingContexts.pushEntitySource( entitySource );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void popSubEntitySource() {
|
||||||
|
localBindingContexts.popEntitySource();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EntityMode getEntityMode() {
|
||||||
|
return entityHierarchy().getRootEntitySource().getEntityMode();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InheritanceType getInheritanceType() {
|
||||||
|
return entityHierarchy().getHierarchyInheritanceType();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RootEntitySource getRootEntitySource() {
|
||||||
|
return entityHierarchy().getRootEntitySource();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EntitySource getEntitySource() {
|
||||||
|
if ( localBindingContexts.isEmpty() ) {
|
||||||
|
throw new IllegalStateException( "No LocalBindingContext defined." );
|
||||||
|
}
|
||||||
|
return localBindingContexts.entitySource();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EntityBinding getEntityBinding() {
|
||||||
|
return getMetadataImplementor().getEntityBinding( getEntitySource().getEntityName() );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EntityBinding getSuperEntityBinding() {
|
||||||
|
final EntitySource superEntitySource = getSuperEntitySource();
|
||||||
|
return superEntitySource == null ?
|
||||||
|
null :
|
||||||
|
getMetadataImplementor().getEntityBinding( superEntitySource.getEntityName() );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LocalBindingContext localBindingContext() {
|
||||||
|
return getEntitySource().getLocalBindingContext();
|
||||||
|
}
|
||||||
|
|
||||||
|
private MetadataImplementor getMetadataImplementor() {
|
||||||
|
return localBindingContext().getMetadataImplementor();
|
||||||
|
}
|
||||||
|
|
||||||
|
private EntitySource getSuperEntitySource() {
|
||||||
|
if ( localBindingContexts.isEmpty() ) {
|
||||||
|
throw new IllegalStateException( "No LocalBindingContext defined." );
|
||||||
|
}
|
||||||
|
return localBindingContexts.superEntitySource();
|
||||||
|
}
|
||||||
|
|
||||||
|
private EntityHierarchy entityHierarchy() {
|
||||||
|
if ( localBindingContexts.isEmpty() ) {
|
||||||
|
throw new IllegalStateException( "No LocalBindingContext defined." );
|
||||||
|
}
|
||||||
|
return localBindingContexts.entityHierarchy();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Each EntitySource contains its LocalBindingContext.
|
||||||
|
private class LocalBindingContextsImpl {
|
||||||
|
private EntityHierarchy entityHierarchy;
|
||||||
|
private final LinkedList<EntitySource> entitySources = new LinkedList<EntitySource>( );
|
||||||
|
|
||||||
|
private boolean isEmpty() {
|
||||||
|
return entityHierarchy == null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setup(final EntityHierarchy entityHierarchy) {
|
||||||
|
// Inheritance type and entity mode applies to entire hierarchy
|
||||||
|
if ( entityHierarchy == null || entityHierarchy.getRootEntitySource() == null ) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"entityHierarchy and entityHierarchy.getRootEntitySource() must be non-null."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if ( this.entityHierarchy != null ) {
|
||||||
|
throw new IllegalStateException( "Attempt to initialize entityHierarchy when it is already initialized." );
|
||||||
|
}
|
||||||
|
this.entityHierarchy = entityHierarchy;
|
||||||
|
this.entitySources.push( entityHierarchy.getRootEntitySource() );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void cleanup() {
|
||||||
|
entityHierarchy = null;
|
||||||
|
entitySources.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void pushEntitySource(EntitySource entitySource) {
|
||||||
|
entitySources.push( entitySource );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void popEntitySource() {
|
||||||
|
entitySources.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
private EntityHierarchy entityHierarchy() {
|
||||||
|
return entityHierarchy;
|
||||||
|
}
|
||||||
|
|
||||||
|
private EntitySource entitySource() {
|
||||||
|
return entitySources.peek();
|
||||||
|
}
|
||||||
|
|
||||||
|
private EntitySource superEntitySource() {
|
||||||
|
if ( entitySources.size() == 1 ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
final EntitySource currentEntitySource = entitySources.pop();
|
||||||
|
final EntitySource superEntitySource = entitySources.peek();
|
||||||
|
entitySources.push( currentEntitySource );
|
||||||
|
return superEntitySource;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -33,19 +33,16 @@ import org.hibernate.metamodel.spi.source.LocalBindingContext;
|
||||||
*/
|
*/
|
||||||
public class RelationalIdentifierHelper {
|
public class RelationalIdentifierHelper {
|
||||||
|
|
||||||
private final LocalBindingContext bindingContext;
|
private final HelperContext helperContext;
|
||||||
|
|
||||||
RelationalIdentifierHelper(LocalBindingContext bindingContext) {
|
RelationalIdentifierHelper(HelperContext helperContext) {
|
||||||
this.bindingContext = bindingContext;
|
this.helperContext = helperContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String normalizeDatabaseIdentifier(
|
public String normalizeDatabaseIdentifier(
|
||||||
final String explicitName,
|
final String explicitName,
|
||||||
ObjectNameNormalizer.NamingStrategyHelper helper) {
|
final ObjectNameNormalizer.NamingStrategyHelper helper) {
|
||||||
return bindingContext
|
return getObjectNameNormalizer().normalizeDatabaseIdentifier( explicitName, helper );
|
||||||
.getMetadataImplementor()
|
|
||||||
.getObjectNameNormalizer()
|
|
||||||
.normalizeDatabaseIdentifier( explicitName, helper );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Identifier createIdentifier(final String name){
|
public Identifier createIdentifier(final String name){
|
||||||
|
@ -59,7 +56,10 @@ public class RelationalIdentifierHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String quotedIdentifier(final String name) {
|
public String quotedIdentifier(final String name) {
|
||||||
return bindingContext.getMetadataImplementor().getObjectNameNormalizer().normalizeIdentifierQuoting( name );
|
return getObjectNameNormalizer().normalizeIdentifierQuoting( name );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ObjectNameNormalizer getObjectNameNormalizer() {
|
||||||
|
return helperContext.bindingContext().getMetadataImplementor().getObjectNameNormalizer();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,6 @@ import org.hibernate.metamodel.spi.relational.TableSpecification;
|
||||||
import org.hibernate.metamodel.spi.relational.Value;
|
import org.hibernate.metamodel.spi.relational.Value;
|
||||||
import org.hibernate.metamodel.spi.source.ColumnSource;
|
import org.hibernate.metamodel.spi.source.ColumnSource;
|
||||||
import org.hibernate.metamodel.spi.source.DerivedValueSource;
|
import org.hibernate.metamodel.spi.source.DerivedValueSource;
|
||||||
import org.hibernate.metamodel.spi.source.LocalBindingContext;
|
|
||||||
import org.hibernate.metamodel.spi.source.RelationalValueSource;
|
import org.hibernate.metamodel.spi.source.RelationalValueSource;
|
||||||
import org.hibernate.metamodel.spi.source.RelationalValueSourceContainer;
|
import org.hibernate.metamodel.spi.source.RelationalValueSourceContainer;
|
||||||
import org.hibernate.metamodel.spi.source.SingularAttributeSource;
|
import org.hibernate.metamodel.spi.source.SingularAttributeSource;
|
||||||
|
@ -49,12 +48,11 @@ import org.hibernate.metamodel.spi.source.SingularAttributeSource;
|
||||||
* @author Gail Badner
|
* @author Gail Badner
|
||||||
*/
|
*/
|
||||||
public class RelationalValueBindingHelper {
|
public class RelationalValueBindingHelper {
|
||||||
private final TableHelper tableHelper;
|
|
||||||
private final NaturalIdUniqueKeyHelper uniqueKeyHelper;
|
|
||||||
|
|
||||||
public RelationalValueBindingHelper(LocalBindingContext bindingContext) {
|
private final HelperContext helperContext;
|
||||||
this.tableHelper = new TableHelper( bindingContext );
|
|
||||||
this.uniqueKeyHelper = new NaturalIdUniqueKeyHelper();
|
public RelationalValueBindingHelper(HelperContext helperContext) {
|
||||||
|
this.helperContext = helperContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasDerivedValue(List<RelationalValueBinding> relationalValueBindings) {
|
public boolean hasDerivedValue(List<RelationalValueBinding> relationalValueBindings) {
|
||||||
|
@ -64,8 +62,7 @@ public class RelationalValueBindingHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<RelationalValueBinding> createRelationalValueBindings(
|
public List<RelationalValueBinding> createRelationalValueBindings(
|
||||||
final AttributeBindingContainer attributeBindingContainer,
|
final AttributeBindingContainer attributeBindingContainer,
|
||||||
|
@ -105,14 +102,14 @@ public class RelationalValueBindingHelper {
|
||||||
|
|
||||||
if ( valueSourceContainer.relationalValueSources().isEmpty() ) {
|
if ( valueSourceContainer.relationalValueSources().isEmpty() ) {
|
||||||
for ( Binder.DefaultNamingStrategy defaultNameStrategy : defaultNameStrategies ) {
|
for ( Binder.DefaultNamingStrategy defaultNameStrategy : defaultNameStrategies ) {
|
||||||
final Column column = tableHelper.locateOrCreateColumn(
|
final Column column = helperContext.tableHelper().locateOrCreateColumn(
|
||||||
defaultTable,
|
defaultTable,
|
||||||
null,
|
null,
|
||||||
new DefaultColumnNamingStrategyHelper( defaultNameStrategy )
|
new DefaultColumnNamingStrategyHelper( defaultNameStrategy )
|
||||||
);
|
);
|
||||||
column.setNullable( !reallyForceNonNullable && valueSourceContainer.areValuesNullableByDefault() );
|
column.setNullable( !reallyForceNonNullable && valueSourceContainer.areValuesNullableByDefault() );
|
||||||
if ( isNaturalId ) {
|
if ( isNaturalId ) {
|
||||||
uniqueKeyHelper.addUniqueConstraintForNaturalIdColumn( defaultTable, column );
|
helperContext.naturalIdUniqueKeyHelper().addUniqueConstraintForNaturalIdColumn( defaultTable, column );
|
||||||
}
|
}
|
||||||
valueBindings.add(
|
valueBindings.add(
|
||||||
new RelationalValueBinding(
|
new RelationalValueBinding(
|
||||||
|
@ -141,7 +138,7 @@ public class RelationalValueBindingHelper {
|
||||||
defaultNameStrategies.get( i ) :
|
defaultNameStrategies.get( i ) :
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
Column column = tableHelper.locateOrCreateColumn(
|
Column column = helperContext.tableHelper().locateOrCreateColumn(
|
||||||
table,
|
table,
|
||||||
columnSource,
|
columnSource,
|
||||||
defaultColumnNamingStrategyHelper,
|
defaultColumnNamingStrategyHelper,
|
||||||
|
@ -149,7 +146,7 @@ public class RelationalValueBindingHelper {
|
||||||
valueSourceContainer.areValuesNullableByDefault()
|
valueSourceContainer.areValuesNullableByDefault()
|
||||||
);
|
);
|
||||||
if ( isNaturalId ) {
|
if ( isNaturalId ) {
|
||||||
uniqueKeyHelper.addUniqueConstraintForNaturalIdColumn( table, column );
|
helperContext.naturalIdUniqueKeyHelper().addUniqueConstraintForNaturalIdColumn( table, column );
|
||||||
}
|
}
|
||||||
final boolean isIncludedInInsert =
|
final boolean isIncludedInInsert =
|
||||||
TruthValue.toBoolean(
|
TruthValue.toBoolean(
|
||||||
|
|
|
@ -28,7 +28,6 @@ import org.jboss.logging.Logger;
|
||||||
import org.hibernate.TruthValue;
|
import org.hibernate.TruthValue;
|
||||||
import org.hibernate.cfg.ObjectNameNormalizer;
|
import org.hibernate.cfg.ObjectNameNormalizer;
|
||||||
import org.hibernate.internal.CoreMessageLogger;
|
import org.hibernate.internal.CoreMessageLogger;
|
||||||
import org.hibernate.metamodel.spi.binding.AttributeBindingContainer;
|
|
||||||
import org.hibernate.metamodel.spi.relational.Column;
|
import org.hibernate.metamodel.spi.relational.Column;
|
||||||
import org.hibernate.metamodel.spi.relational.Identifier;
|
import org.hibernate.metamodel.spi.relational.Identifier;
|
||||||
import org.hibernate.metamodel.spi.relational.Schema;
|
import org.hibernate.metamodel.spi.relational.Schema;
|
||||||
|
@ -39,11 +38,9 @@ import org.hibernate.metamodel.spi.source.ColumnSource;
|
||||||
import org.hibernate.metamodel.spi.source.InLineViewSource;
|
import org.hibernate.metamodel.spi.source.InLineViewSource;
|
||||||
import org.hibernate.metamodel.spi.source.LocalBindingContext;
|
import org.hibernate.metamodel.spi.source.LocalBindingContext;
|
||||||
import org.hibernate.metamodel.spi.source.MappingDefaults;
|
import org.hibernate.metamodel.spi.source.MappingDefaults;
|
||||||
import org.hibernate.metamodel.spi.source.SingularAttributeSource;
|
|
||||||
import org.hibernate.metamodel.spi.source.SizeSource;
|
import org.hibernate.metamodel.spi.source.SizeSource;
|
||||||
import org.hibernate.metamodel.spi.source.TableSource;
|
import org.hibernate.metamodel.spi.source.TableSource;
|
||||||
import org.hibernate.metamodel.spi.source.TableSpecificationSource;
|
import org.hibernate.metamodel.spi.source.TableSpecificationSource;
|
||||||
import org.hibernate.metamodel.spi.source.ToOneAttributeSource;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Gail Badner
|
* @author Gail Badner
|
||||||
|
@ -54,12 +51,10 @@ public class TableHelper {
|
||||||
TableHelper.class.getName()
|
TableHelper.class.getName()
|
||||||
);
|
);
|
||||||
|
|
||||||
private final LocalBindingContext bindingContext;
|
private final HelperContext helperContext;
|
||||||
private final RelationalIdentifierHelper relationalIdentifierHelper;
|
|
||||||
|
|
||||||
public TableHelper(LocalBindingContext bindingContext) {
|
public TableHelper(HelperContext helperContext) {
|
||||||
this.bindingContext = bindingContext;
|
this.helperContext = helperContext;
|
||||||
this.relationalIdentifierHelper = new RelationalIdentifierHelper( bindingContext );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public TableSpecification createTable(
|
public TableSpecification createTable(
|
||||||
|
@ -73,7 +68,9 @@ public class TableHelper {
|
||||||
final ObjectNameNormalizer.NamingStrategyHelper namingStrategyHelper,
|
final ObjectNameNormalizer.NamingStrategyHelper namingStrategyHelper,
|
||||||
final Table includedTable) {
|
final Table includedTable) {
|
||||||
if ( tableSpecSource == null && namingStrategyHelper == null ) {
|
if ( tableSpecSource == null && namingStrategyHelper == null ) {
|
||||||
throw bindingContext.makeMappingException( "An explicit name must be specified for the table" );
|
throw bindingContext().makeMappingException(
|
||||||
|
"An explicit name must be specified for the table"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
final boolean isTableSourceNull = tableSpecSource == null;
|
final boolean isTableSourceNull = tableSpecSource == null;
|
||||||
final Schema schema = resolveSchema( tableSpecSource );
|
final Schema schema = resolveSchema( tableSpecSource );
|
||||||
|
@ -83,7 +80,7 @@ public class TableHelper {
|
||||||
String explicitName = isTableSourceNull ? null : TableSource.class.cast( tableSpecSource ).getExplicitTableName();
|
String explicitName = isTableSourceNull ? null : TableSource.class.cast( tableSpecSource ).getExplicitTableName();
|
||||||
String tableName = normalizeDatabaseIdentifier( explicitName, namingStrategyHelper );
|
String tableName = normalizeDatabaseIdentifier( explicitName, namingStrategyHelper );
|
||||||
String logicTableName = TableNamingStrategyHelper.class.cast( namingStrategyHelper ).getLogicalName(
|
String logicTableName = TableNamingStrategyHelper.class.cast( namingStrategyHelper ).getLogicalName(
|
||||||
bindingContext.getNamingStrategy()
|
bindingContext().getNamingStrategy()
|
||||||
);
|
);
|
||||||
tableSpec = createTableSpecification( schema, tableName, logicTableName, includedTable );
|
tableSpec = createTableSpecification( schema, tableName, logicTableName, includedTable );
|
||||||
}
|
}
|
||||||
|
@ -99,7 +96,7 @@ public class TableHelper {
|
||||||
|
|
||||||
public Schema resolveSchema(final TableSpecificationSource tableSpecSource) {
|
public Schema resolveSchema(final TableSpecificationSource tableSpecSource) {
|
||||||
final boolean tableSourceNull = tableSpecSource == null;
|
final boolean tableSourceNull = tableSpecSource == null;
|
||||||
final MappingDefaults mappingDefaults = bindingContext.getMappingDefaults();
|
final MappingDefaults mappingDefaults = bindingContext().getMappingDefaults();
|
||||||
final String explicitCatalogName = tableSourceNull ? null : tableSpecSource.getExplicitCatalogName();
|
final String explicitCatalogName = tableSourceNull ? null : tableSpecSource.getExplicitCatalogName();
|
||||||
final String explicitSchemaName = tableSourceNull ? null : tableSpecSource.getExplicitSchemaName();
|
final String explicitSchemaName = tableSourceNull ? null : tableSpecSource.getExplicitSchemaName();
|
||||||
final Schema.Name schemaName =
|
final Schema.Name schemaName =
|
||||||
|
@ -107,7 +104,7 @@ public class TableHelper {
|
||||||
createIdentifier( explicitCatalogName, mappingDefaults.getCatalogName() ),
|
createIdentifier( explicitCatalogName, mappingDefaults.getCatalogName() ),
|
||||||
createIdentifier( explicitSchemaName, mappingDefaults.getSchemaName() )
|
createIdentifier( explicitSchemaName, mappingDefaults.getSchemaName() )
|
||||||
);
|
);
|
||||||
return bindingContext.getMetadataImplementor().getDatabase().locateSchema( schemaName );
|
return bindingContext().getMetadataImplementor().getDatabase().locateSchema( schemaName );
|
||||||
}
|
}
|
||||||
|
|
||||||
public TableSpecification createTableSpecification(
|
public TableSpecification createTableSpecification(
|
||||||
|
@ -136,7 +133,7 @@ public class TableHelper {
|
||||||
final String columnName,
|
final String columnName,
|
||||||
final ObjectNameNormalizer.NamingStrategyHelper namingStrategyHelper) {
|
final ObjectNameNormalizer.NamingStrategyHelper namingStrategyHelper) {
|
||||||
if ( columnName == null && namingStrategyHelper == null ) {
|
if ( columnName == null && namingStrategyHelper == null ) {
|
||||||
throw bindingContext.makeMappingException(
|
throw bindingContext().makeMappingException(
|
||||||
"Cannot resolve name for column because no name was specified and namingStrategyHelper is null."
|
"Cannot resolve name for column because no name was specified and namingStrategyHelper is null."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -210,14 +207,18 @@ public class TableHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Identifier createIdentifier(String name) {
|
private Identifier createIdentifier(String name) {
|
||||||
return relationalIdentifierHelper.createIdentifier( name );
|
return helperContext.relationalIdentifierHelper().createIdentifier( name );
|
||||||
}
|
}
|
||||||
|
|
||||||
private Identifier createIdentifier(String name, String defaultName) {
|
private Identifier createIdentifier(String name, String defaultName) {
|
||||||
return relationalIdentifierHelper.createIdentifier( name, defaultName );
|
return helperContext.relationalIdentifierHelper().createIdentifier( name, defaultName );
|
||||||
}
|
}
|
||||||
|
|
||||||
private String normalizeDatabaseIdentifier(String explicitName, ObjectNameNormalizer.NamingStrategyHelper namingStrategyHelper) {
|
private String normalizeDatabaseIdentifier(String explicitName, ObjectNameNormalizer.NamingStrategyHelper namingStrategyHelper) {
|
||||||
return relationalIdentifierHelper.normalizeDatabaseIdentifier( explicitName, namingStrategyHelper );
|
return helperContext.relationalIdentifierHelper().normalizeDatabaseIdentifier( explicitName, namingStrategyHelper );
|
||||||
|
}
|
||||||
|
|
||||||
|
private LocalBindingContext bindingContext() {
|
||||||
|
return helperContext.bindingContext();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ import java.util.List;
|
||||||
import org.hibernate.AssertionFailure;
|
import org.hibernate.AssertionFailure;
|
||||||
import org.hibernate.cfg.NotYetImplementedException;
|
import org.hibernate.cfg.NotYetImplementedException;
|
||||||
import org.hibernate.metamodel.internal.ForeignKeyHelper;
|
import org.hibernate.metamodel.internal.ForeignKeyHelper;
|
||||||
|
import org.hibernate.metamodel.internal.HelperContext;
|
||||||
import org.hibernate.metamodel.internal.RelationalValueBindingHelper;
|
import org.hibernate.metamodel.internal.RelationalValueBindingHelper;
|
||||||
import org.hibernate.metamodel.spi.binding.AttributeBinding;
|
import org.hibernate.metamodel.spi.binding.AttributeBinding;
|
||||||
import org.hibernate.metamodel.spi.binding.AttributeBindingContainer;
|
import org.hibernate.metamodel.spi.binding.AttributeBindingContainer;
|
||||||
|
@ -55,14 +56,10 @@ import org.hibernate.type.ForeignKeyDirection;
|
||||||
+ * @author Gail Badner
|
+ * @author Gail Badner
|
||||||
+ */
|
+ */
|
||||||
public class MappedByAssociationRelationalBindingResolverImpl implements AssociationRelationalBindingResolver {
|
public class MappedByAssociationRelationalBindingResolverImpl implements AssociationRelationalBindingResolver {
|
||||||
private final LocalBindingContext bindingContext;
|
private final HelperContext helperContext;
|
||||||
private final ForeignKeyHelper foreignKeyHelper;
|
|
||||||
private final RelationalValueBindingHelper relationalValueBindingHelper;
|
|
||||||
|
|
||||||
public MappedByAssociationRelationalBindingResolverImpl(LocalBindingContext bindingContext) {
|
public MappedByAssociationRelationalBindingResolverImpl(HelperContext helperContext) {
|
||||||
this.bindingContext = bindingContext;
|
this.helperContext = helperContext;
|
||||||
this.foreignKeyHelper = new ForeignKeyHelper( bindingContext );
|
|
||||||
this.relationalValueBindingHelper = new RelationalValueBindingHelper( bindingContext );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -93,15 +90,15 @@ public class MappedByAssociationRelationalBindingResolverImpl implements Associa
|
||||||
if ( attributeSource.getForeignKeyDirection() == ForeignKeyDirection.TO_PARENT ) {
|
if ( attributeSource.getForeignKeyDirection() == ForeignKeyDirection.TO_PARENT ) {
|
||||||
throw new AssertionFailure( "Cannot create a foreign key for one-to-one with foreign key direction going to the parent." );
|
throw new AssertionFailure( "Cannot create a foreign key for one-to-one with foreign key direction going to the parent." );
|
||||||
}
|
}
|
||||||
final List<Column> targetColumns = foreignKeyHelper.determineForeignKeyTargetColumns(
|
final List<Column> targetColumns = foreignKeyHelper().determineForeignKeyTargetColumns(
|
||||||
referencedEntityBinding,
|
referencedEntityBinding,
|
||||||
attributeSource
|
attributeSource
|
||||||
);
|
);
|
||||||
final TableSpecification targetTable = foreignKeyHelper.determineForeignKeyTargetTable(
|
final TableSpecification targetTable = foreignKeyHelper().determineForeignKeyTargetTable(
|
||||||
referencedEntityBinding,
|
referencedEntityBinding,
|
||||||
attributeSource
|
attributeSource
|
||||||
);
|
);
|
||||||
return foreignKeyHelper.locateOrCreateForeignKey(
|
return foreignKeyHelper().locateOrCreateForeignKey(
|
||||||
attributeSource.getExplicitForeignKeyName(),
|
attributeSource.getExplicitForeignKeyName(),
|
||||||
sourceTable,
|
sourceTable,
|
||||||
sourceColumns,
|
sourceColumns,
|
||||||
|
@ -143,7 +140,7 @@ public class MappedByAssociationRelationalBindingResolverImpl implements Associa
|
||||||
getMappedByAssociationSource( attributeSource ),
|
getMappedByAssociationSource( attributeSource ),
|
||||||
referencedEntityBinding
|
referencedEntityBinding
|
||||||
);
|
);
|
||||||
return relationalValueBindingHelper.bindInverseRelationalValueBindings(
|
return relationalValueBindingHelper().bindInverseRelationalValueBindings(
|
||||||
ownerSecondaryTable.getForeignKeyReference().getSourceTable(),
|
ownerSecondaryTable.getForeignKeyReference().getSourceTable(),
|
||||||
ownerSecondaryTable.getForeignKeyReference().getSourceColumns()
|
ownerSecondaryTable.getForeignKeyReference().getSourceColumns()
|
||||||
);
|
);
|
||||||
|
@ -180,14 +177,14 @@ public class MappedByAssociationRelationalBindingResolverImpl implements Associa
|
||||||
// for the secondary table.
|
// for the secondary table.
|
||||||
final SecondaryTable ownerSecondaryTable =
|
final SecondaryTable ownerSecondaryTable =
|
||||||
referencedEntityBinding.getSecondaryTables().get( collectionTable.getLogicalName() );
|
referencedEntityBinding.getSecondaryTables().get( collectionTable.getLogicalName() );
|
||||||
relationalValueBindings = relationalValueBindingHelper.bindInverseRelationalValueBindings(
|
relationalValueBindings = relationalValueBindingHelper().bindInverseRelationalValueBindings(
|
||||||
collectionTable,
|
collectionTable,
|
||||||
ownerSecondaryTable.getForeignKeyReference().getSourceColumns()
|
ownerSecondaryTable.getForeignKeyReference().getSourceColumns()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
final PluralAttributeBinding ownerPluralAttributeBinding = (PluralAttributeBinding) ownerAttributeBinding;
|
final PluralAttributeBinding ownerPluralAttributeBinding = (PluralAttributeBinding) ownerAttributeBinding;
|
||||||
relationalValueBindings = relationalValueBindingHelper.bindInverseRelationalValueBindings(
|
relationalValueBindings = relationalValueBindingHelper().bindInverseRelationalValueBindings(
|
||||||
collectionTable,
|
collectionTable,
|
||||||
ownerPluralAttributeBinding.getPluralAttributeKeyBinding().getValues()
|
ownerPluralAttributeBinding.getPluralAttributeKeyBinding().getValues()
|
||||||
);
|
);
|
||||||
|
@ -307,6 +304,10 @@ public class MappedByAssociationRelationalBindingResolverImpl implements Associa
|
||||||
return referencedAttributeBinding;
|
return referencedAttributeBinding;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private LocalBindingContext bindingContext() {
|
||||||
|
return helperContext.bindingContext();
|
||||||
|
}
|
||||||
|
|
||||||
private MappedByAssociationSource getMappedByAssociationSource(AssociationSource associationSource) {
|
private MappedByAssociationSource getMappedByAssociationSource(AssociationSource associationSource) {
|
||||||
if ( !associationSource.isMappedBy() || !MappedByAssociationSource.class.isInstance( associationSource ) ) {
|
if ( !associationSource.isMappedBy() || !MappedByAssociationSource.class.isInstance( associationSource ) ) {
|
||||||
throw new AssertionFailure( "Expected a MappedByAssociationSource." );
|
throw new AssertionFailure( "Expected a MappedByAssociationSource." );
|
||||||
|
@ -315,7 +316,7 @@ public class MappedByAssociationRelationalBindingResolverImpl implements Associa
|
||||||
}
|
}
|
||||||
|
|
||||||
private AttributeBinding getOwnerAttributeBinding(MappedByAssociationSource associationSource) {
|
private AttributeBinding getOwnerAttributeBinding(MappedByAssociationSource associationSource) {
|
||||||
final EntityBinding referencedEntityBinding = bindingContext.getMetadataImplementor().getEntityBinding(
|
final EntityBinding referencedEntityBinding = bindingContext().getMetadataImplementor().getEntityBinding(
|
||||||
associationSource.getReferencedEntityName()
|
associationSource.getReferencedEntityName()
|
||||||
);
|
);
|
||||||
final AttributeBinding ownerAttributeBinding = referencedEntityBinding.locateAttributeBindingByPath(
|
final AttributeBinding ownerAttributeBinding = referencedEntityBinding.locateAttributeBindingByPath(
|
||||||
|
@ -323,7 +324,7 @@ public class MappedByAssociationRelationalBindingResolverImpl implements Associa
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
if ( ownerAttributeBinding == null ) {
|
if ( ownerAttributeBinding == null ) {
|
||||||
throw bindingContext.makeMappingException(
|
throw bindingContext().makeMappingException(
|
||||||
String.format(
|
String.format(
|
||||||
"Attribute not found: [%s.%s]",
|
"Attribute not found: [%s.%s]",
|
||||||
referencedEntityBinding.getEntityName(),
|
referencedEntityBinding.getEntityName(),
|
||||||
|
@ -347,4 +348,12 @@ public class MappedByAssociationRelationalBindingResolverImpl implements Associa
|
||||||
}
|
}
|
||||||
return referencedEntityBinding.getSecondaryTables().get( table.getLogicalName() );
|
return referencedEntityBinding.getSecondaryTables().get( table.getLogicalName() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ForeignKeyHelper foreignKeyHelper() {
|
||||||
|
return helperContext.foreignKeyHelper();
|
||||||
|
}
|
||||||
|
|
||||||
|
private RelationalValueBindingHelper relationalValueBindingHelper() {
|
||||||
|
return helperContext.relationalValueBindingHelper();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ import org.hibernate.cfg.NamingStrategy;
|
||||||
import org.hibernate.cfg.NotYetImplementedException;
|
import org.hibernate.cfg.NotYetImplementedException;
|
||||||
import org.hibernate.metamodel.internal.Binder;
|
import org.hibernate.metamodel.internal.Binder;
|
||||||
import org.hibernate.metamodel.internal.ForeignKeyHelper;
|
import org.hibernate.metamodel.internal.ForeignKeyHelper;
|
||||||
|
import org.hibernate.metamodel.internal.HelperContext;
|
||||||
import org.hibernate.metamodel.internal.ManyToManyCollectionTableNamingStrategyHelper;
|
import org.hibernate.metamodel.internal.ManyToManyCollectionTableNamingStrategyHelper;
|
||||||
import org.hibernate.metamodel.internal.RelationalValueBindingHelper;
|
import org.hibernate.metamodel.internal.RelationalValueBindingHelper;
|
||||||
import org.hibernate.metamodel.internal.TableHelper;
|
import org.hibernate.metamodel.internal.TableHelper;
|
||||||
|
@ -45,7 +46,6 @@ import org.hibernate.metamodel.spi.relational.TableSpecification;
|
||||||
import org.hibernate.metamodel.spi.relational.Value;
|
import org.hibernate.metamodel.spi.relational.Value;
|
||||||
import org.hibernate.metamodel.spi.source.AssociationSource;
|
import org.hibernate.metamodel.spi.source.AssociationSource;
|
||||||
import org.hibernate.metamodel.spi.source.ForeignKeyContributingSource;
|
import org.hibernate.metamodel.spi.source.ForeignKeyContributingSource;
|
||||||
import org.hibernate.metamodel.spi.source.LocalBindingContext;
|
|
||||||
import org.hibernate.metamodel.spi.source.ManyToManyPluralAttributeElementSource;
|
import org.hibernate.metamodel.spi.source.ManyToManyPluralAttributeElementSource;
|
||||||
import org.hibernate.metamodel.spi.source.PluralAttributeElementSource;
|
import org.hibernate.metamodel.spi.source.PluralAttributeElementSource;
|
||||||
import org.hibernate.metamodel.spi.source.PluralAttributeKeySource;
|
import org.hibernate.metamodel.spi.source.PluralAttributeKeySource;
|
||||||
|
@ -60,14 +60,10 @@ import org.hibernate.type.ForeignKeyDirection;
|
||||||
+ * @author Gail Badner
|
+ * @author Gail Badner
|
||||||
+ */
|
+ */
|
||||||
public class StandardAssociationRelationalBindingResolverImpl implements AssociationRelationalBindingResolver {
|
public class StandardAssociationRelationalBindingResolverImpl implements AssociationRelationalBindingResolver {
|
||||||
private final RelationalValueBindingHelper relationalValueBindingHelper;
|
private final HelperContext helperContext;
|
||||||
private final ForeignKeyHelper foreignKeyHelper;
|
|
||||||
private final TableHelper tableHelper;
|
|
||||||
|
|
||||||
public StandardAssociationRelationalBindingResolverImpl(LocalBindingContext bindingContext) {
|
public StandardAssociationRelationalBindingResolverImpl(HelperContext helperContext) {
|
||||||
this.relationalValueBindingHelper = new RelationalValueBindingHelper( bindingContext );
|
this.helperContext = helperContext;
|
||||||
this.foreignKeyHelper = new ForeignKeyHelper( bindingContext );
|
|
||||||
this.tableHelper = new TableHelper( bindingContext );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -124,15 +120,15 @@ public class StandardAssociationRelationalBindingResolverImpl implements Associa
|
||||||
throw new AssertionFailure( "Cannot create a foreign key for one-to-one with foreign key direction going to the parent." );
|
throw new AssertionFailure( "Cannot create a foreign key for one-to-one with foreign key direction going to the parent." );
|
||||||
}
|
}
|
||||||
|
|
||||||
final TableSpecification targetTable = foreignKeyHelper.determineForeignKeyTargetTable(
|
final TableSpecification targetTable = foreignKeyHelper().determineForeignKeyTargetTable(
|
||||||
referencedEntityBinding,
|
referencedEntityBinding,
|
||||||
attributeSource
|
attributeSource
|
||||||
);
|
);
|
||||||
final List<Column> targetColumns = foreignKeyHelper.determineForeignKeyTargetColumns(
|
final List<Column> targetColumns = foreignKeyHelper().determineForeignKeyTargetColumns(
|
||||||
referencedEntityBinding,
|
referencedEntityBinding,
|
||||||
attributeSource
|
attributeSource
|
||||||
);
|
);
|
||||||
return foreignKeyHelper.locateOrCreateForeignKey(
|
return foreignKeyHelper().locateOrCreateForeignKey(
|
||||||
attributeSource.getExplicitForeignKeyName(),
|
attributeSource.getExplicitForeignKeyName(),
|
||||||
sourceTable,
|
sourceTable,
|
||||||
sourceColumns,
|
sourceColumns,
|
||||||
|
@ -180,7 +176,7 @@ public class StandardAssociationRelationalBindingResolverImpl implements Associa
|
||||||
AttributeBindingContainer attributeBindingContainer,
|
AttributeBindingContainer attributeBindingContainer,
|
||||||
List<RelationalValueBinding> relationalValueBindings,
|
List<RelationalValueBinding> relationalValueBindings,
|
||||||
EntityBinding referencedEntityBinding) {
|
EntityBinding referencedEntityBinding) {
|
||||||
final List<Column> targetColumns = foreignKeyHelper.determineForeignKeyTargetColumns(
|
final List<Column> targetColumns = foreignKeyHelper().determineForeignKeyTargetColumns(
|
||||||
referencedEntityBinding,
|
referencedEntityBinding,
|
||||||
attributeSource
|
attributeSource
|
||||||
);
|
);
|
||||||
|
@ -200,7 +196,7 @@ public class StandardAssociationRelationalBindingResolverImpl implements Associa
|
||||||
final TableSpecification collectionTable,
|
final TableSpecification collectionTable,
|
||||||
final EntityBinding referencedEntityBinding) {
|
final EntityBinding referencedEntityBinding) {
|
||||||
final List<Column> targetColumns =
|
final List<Column> targetColumns =
|
||||||
foreignKeyHelper.determineForeignKeyTargetColumns(
|
foreignKeyHelper().determineForeignKeyTargetColumns(
|
||||||
referencedEntityBinding,
|
referencedEntityBinding,
|
||||||
elementSource
|
elementSource
|
||||||
);
|
);
|
||||||
|
@ -237,7 +233,7 @@ public class StandardAssociationRelationalBindingResolverImpl implements Associa
|
||||||
final List<RelationalValueBinding> relationalValueBindings,
|
final List<RelationalValueBinding> relationalValueBindings,
|
||||||
final EntityBinding referencedEntityBinding) {
|
final EntityBinding referencedEntityBinding) {
|
||||||
final List<Column> targetColumns =
|
final List<Column> targetColumns =
|
||||||
foreignKeyHelper.determineForeignKeyTargetColumns(
|
foreignKeyHelper().determineForeignKeyTargetColumns(
|
||||||
referencedEntityBinding,
|
referencedEntityBinding,
|
||||||
elementSource
|
elementSource
|
||||||
);
|
);
|
||||||
|
@ -258,7 +254,7 @@ public class StandardAssociationRelationalBindingResolverImpl implements Associa
|
||||||
EntityBinding referencedEntityBinding) {
|
EntityBinding referencedEntityBinding) {
|
||||||
|
|
||||||
final TableSpecificationSource collectionTableSource = pluralAttributeSource.getCollectionTableSpecificationSource();
|
final TableSpecificationSource collectionTableSource = pluralAttributeSource.getCollectionTableSpecificationSource();
|
||||||
return tableHelper.createTable(
|
return tableHelper().createTable(
|
||||||
collectionTableSource,
|
collectionTableSource,
|
||||||
new ManyToManyCollectionTableNamingStrategyHelper(
|
new ManyToManyCollectionTableNamingStrategyHelper(
|
||||||
attributePath,
|
attributePath,
|
||||||
|
@ -277,7 +273,7 @@ public class StandardAssociationRelationalBindingResolverImpl implements Associa
|
||||||
final EntityBinding referencedEntityBinding) {
|
final EntityBinding referencedEntityBinding) {
|
||||||
final PluralAttributeKeySource keySource = attributeSource.getKeySource();
|
final PluralAttributeKeySource keySource = attributeSource.getKeySource();
|
||||||
|
|
||||||
final List<Column>targetColumns = foreignKeyHelper.determineForeignKeyTargetColumns(
|
final List<Column>targetColumns = foreignKeyHelper().determineForeignKeyTargetColumns(
|
||||||
referencedEntityBinding,
|
referencedEntityBinding,
|
||||||
keySource
|
keySource
|
||||||
);
|
);
|
||||||
|
@ -334,7 +330,7 @@ public class StandardAssociationRelationalBindingResolverImpl implements Associa
|
||||||
final EntityBinding referencedEntityBinding) {
|
final EntityBinding referencedEntityBinding) {
|
||||||
final PluralAttributeKeySource keySource = attributeSource.getKeySource();
|
final PluralAttributeKeySource keySource = attributeSource.getKeySource();
|
||||||
List<Column> targetColumns =
|
List<Column> targetColumns =
|
||||||
foreignKeyHelper.determineForeignKeyTargetColumns(
|
foreignKeyHelper().determineForeignKeyTargetColumns(
|
||||||
referencedEntityBinding,
|
referencedEntityBinding,
|
||||||
keySource
|
keySource
|
||||||
);
|
);
|
||||||
|
@ -353,7 +349,7 @@ public class StandardAssociationRelationalBindingResolverImpl implements Associa
|
||||||
public SingularAttributeBinding resolvePluralAttributeKeyReferencedBinding(
|
public SingularAttributeBinding resolvePluralAttributeKeyReferencedBinding(
|
||||||
AttributeBindingContainer attributeBindingContainer,
|
AttributeBindingContainer attributeBindingContainer,
|
||||||
PluralAttributeSource attributeSource) {
|
PluralAttributeSource attributeSource) {
|
||||||
return foreignKeyHelper.determineReferencedAttributeBinding(
|
return foreignKeyHelper().determineReferencedAttributeBinding(
|
||||||
attributeSource.getKeySource(),
|
attributeSource.getKeySource(),
|
||||||
attributeBindingContainer.seekEntityBinding()
|
attributeBindingContainer.seekEntityBinding()
|
||||||
);
|
);
|
||||||
|
@ -363,7 +359,7 @@ public class StandardAssociationRelationalBindingResolverImpl implements Associa
|
||||||
private SingularAttributeBinding resolveReferencedAttributeBinding(
|
private SingularAttributeBinding resolveReferencedAttributeBinding(
|
||||||
ToOneAttributeSource attributeSource,
|
ToOneAttributeSource attributeSource,
|
||||||
EntityBinding referencedEntityBinding) {
|
EntityBinding referencedEntityBinding) {
|
||||||
return foreignKeyHelper.determineReferencedAttributeBinding( attributeSource, referencedEntityBinding );
|
return foreignKeyHelper().determineReferencedAttributeBinding( attributeSource, referencedEntityBinding );
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<RelationalValueBinding> resolveRelationalValueBindings(
|
public List<RelationalValueBinding> resolveRelationalValueBindings(
|
||||||
|
@ -372,7 +368,7 @@ public class StandardAssociationRelationalBindingResolverImpl implements Associa
|
||||||
TableSpecification defaultTable,
|
TableSpecification defaultTable,
|
||||||
boolean forceNonNullable,
|
boolean forceNonNullable,
|
||||||
List<Binder.DefaultNamingStrategy> defaultNamingStrategies) {
|
List<Binder.DefaultNamingStrategy> defaultNamingStrategies) {
|
||||||
return relationalValueBindingHelper.createRelationalValueBindings(
|
return relationalValueBindingHelper().createRelationalValueBindings(
|
||||||
entityBinding,
|
entityBinding,
|
||||||
relationalValueSourceContainer,
|
relationalValueSourceContainer,
|
||||||
defaultTable,
|
defaultTable,
|
||||||
|
@ -387,11 +383,11 @@ public class StandardAssociationRelationalBindingResolverImpl implements Associa
|
||||||
final TableSpecification sourceTable,
|
final TableSpecification sourceTable,
|
||||||
final List<RelationalValueBinding> sourceRelationalValueBindings,
|
final List<RelationalValueBinding> sourceRelationalValueBindings,
|
||||||
final List<Column> targetColumns) {
|
final List<Column> targetColumns) {
|
||||||
final TableSpecification targetTable = foreignKeyHelper.determineForeignKeyTargetTable(
|
final TableSpecification targetTable = foreignKeyHelper().determineForeignKeyTargetTable(
|
||||||
referencedEntityBinding,
|
referencedEntityBinding,
|
||||||
foreignKeyContributingSource
|
foreignKeyContributingSource
|
||||||
);
|
);
|
||||||
return foreignKeyHelper.locateOrCreateForeignKey(
|
return foreignKeyHelper().locateOrCreateForeignKey(
|
||||||
foreignKeyContributingSource.getExplicitForeignKeyName(),
|
foreignKeyContributingSource.getExplicitForeignKeyName(),
|
||||||
sourceTable,
|
sourceTable,
|
||||||
extractColumnsFromRelationalValueBindings( sourceRelationalValueBindings ),
|
extractColumnsFromRelationalValueBindings( sourceRelationalValueBindings ),
|
||||||
|
@ -400,6 +396,18 @@ public class StandardAssociationRelationalBindingResolverImpl implements Associa
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private TableHelper tableHelper() {
|
||||||
|
return helperContext.tableHelper();
|
||||||
|
}
|
||||||
|
|
||||||
|
private ForeignKeyHelper foreignKeyHelper() {
|
||||||
|
return helperContext.foreignKeyHelper();
|
||||||
|
}
|
||||||
|
|
||||||
|
private RelationalValueBindingHelper relationalValueBindingHelper() {
|
||||||
|
return helperContext.relationalValueBindingHelper();
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: try to get rid of this...
|
// TODO: try to get rid of this...
|
||||||
private static List<Column> extractColumnsFromRelationalValueBindings(
|
private static List<Column> extractColumnsFromRelationalValueBindings(
|
||||||
final List<RelationalValueBinding> valueBindings) {
|
final List<RelationalValueBinding> valueBindings) {
|
||||||
|
|
Loading…
Reference in New Issue