HHH-7787 - Expose BasicTypeRegistry as part of MetadataBuilder or MetadataSources

This commit is contained in:
Steve Ebersole 2012-11-13 12:30:22 -06:00
parent 1f824b0496
commit 2daa74faa0
3 changed files with 140 additions and 2 deletions

View File

@ -23,6 +23,7 @@
*/ */
package org.hibernate.metamodel; package org.hibernate.metamodel;
import java.util.List;
import java.util.Map; import java.util.Map;
import javax.persistence.SharedCacheMode; import javax.persistence.SharedCacheMode;
@ -36,11 +37,15 @@ import org.hibernate.engine.ResultSetMappingDefinition;
import org.hibernate.engine.spi.FilterDefinition; import org.hibernate.engine.spi.FilterDefinition;
import org.hibernate.engine.spi.NamedQueryDefinition; import org.hibernate.engine.spi.NamedQueryDefinition;
import org.hibernate.engine.spi.NamedSQLQueryDefinition; import org.hibernate.engine.spi.NamedSQLQueryDefinition;
import org.hibernate.metamodel.internal.MetadataBuilderImpl;
import org.hibernate.metamodel.spi.binding.EntityBinding; import org.hibernate.metamodel.spi.binding.EntityBinding;
import org.hibernate.metamodel.spi.binding.FetchProfile; import org.hibernate.metamodel.spi.binding.FetchProfile;
import org.hibernate.metamodel.spi.binding.IdGenerator; import org.hibernate.metamodel.spi.binding.IdGenerator;
import org.hibernate.metamodel.spi.binding.PluralAttributeBinding; import org.hibernate.metamodel.spi.binding.PluralAttributeBinding;
import org.hibernate.metamodel.spi.binding.TypeDefinition; import org.hibernate.metamodel.spi.binding.TypeDefinition;
import org.hibernate.type.BasicType;
import org.hibernate.type.BasicTypeRegistry;
import org.jboss.jandex.IndexView; import org.jboss.jandex.IndexView;
import org.xml.sax.EntityResolver; import org.xml.sax.EntityResolver;
@ -65,6 +70,7 @@ public interface Metadata {
public String getDefaultCatalogName(); public String getDefaultCatalogName();
public MultiTenancyStrategy getMultiTenancyStrategy(); public MultiTenancyStrategy getMultiTenancyStrategy();
public IndexView getJandexView(); public IndexView getJandexView();
public List<BasicType> getBasicTypeRegistrations();
} }
/** /**

View File

@ -30,25 +30,124 @@ import org.xml.sax.EntityResolver;
import org.hibernate.cache.spi.access.AccessType; import org.hibernate.cache.spi.access.AccessType;
import org.hibernate.cfg.NamingStrategy; import org.hibernate.cfg.NamingStrategy;
import org.hibernate.type.BasicType;
import org.hibernate.usertype.CompositeUserType;
import org.hibernate.usertype.UserType;
/** /**
* Contract for specifying various overrides to be used in metamodel building.
*
* @author Steve Ebersole * @author Steve Ebersole
* @author Hardy Ferentschik * @author Hardy Ferentschik
*/ */
public interface MetadataBuilder { public interface MetadataBuilder {
/**
* Specify a specific NamingStrategy to use in building the metamodel.
*
* @param namingStrategy The naming strategy to use.
*
* @return {@code this}, for method chaining
*/
public MetadataBuilder with(NamingStrategy namingStrategy); public MetadataBuilder with(NamingStrategy namingStrategy);
/**
* Specify a specific XML EntityResolver to use in building the metamodel.
*
* @param entityResolver The entity resolver to use.
*
* @return {@code this}, for method chaining
*/
public MetadataBuilder with(EntityResolver entityResolver); public MetadataBuilder with(EntityResolver entityResolver);
/**
* Specify the order in which to process metadata sources.
*
* @param metadataSourceProcessingOrder The order.
*
* @return {@code this}, for method chaining
*/
public MetadataBuilder with(MetadataSourceProcessingOrder metadataSourceProcessingOrder); public MetadataBuilder with(MetadataSourceProcessingOrder metadataSourceProcessingOrder);
/**
* Specify the second-level cache mode to be used. This is the cache mode in terms of whether or
* not to cache.
*
* @param cacheMode The cache mode.
*
* @return {@code this}, for method chaining
*
* @see #with(org.hibernate.cache.spi.access.AccessType)
*/
public MetadataBuilder with(SharedCacheMode cacheMode); public MetadataBuilder with(SharedCacheMode cacheMode);
/**
* Specify the second-level access-type to be used by default for entities and collections that define second-level
* caching, but do not specify a granular access-type.
*
* @param accessType The access-type to use as default.
*
* @return {@code this}, for method chaining
*
* @see #with(javax.persistence.SharedCacheMode)
*/
public MetadataBuilder with(AccessType accessType); public MetadataBuilder with(AccessType accessType);
/**
* Allows specifying a specific Jandex index to use for reading annotation information.
*
* @param jandexView The Jandex index to use.
*
* @return {@code this}, for method chaining
*/
public MetadataBuilder with(IndexView jandexView); public MetadataBuilder with(IndexView jandexView);
/**
* Should the new (well "new" since 3.2) identifier generators be used for
* {@link javax.persistence.GenerationType#SEQUENCE},
* {@link javax.persistence.GenerationType#IDENTITY},
* {@link javax.persistence.GenerationType#TABLE} and
* {@link javax.persistence.GenerationType#AUTO} handling?
*
* @param enabled {@code true} says to use the new generator mappings; {@code false} says to use the legacy
* generator mappings.
*
* @return {@code this}, for method chaining
*/
public MetadataBuilder withNewIdentifierGeneratorsEnabled(boolean enabled); public MetadataBuilder withNewIdentifierGeneratorsEnabled(boolean enabled);
/**
* Specify an additional or overridden basic type mapping.
*
* @param type The type addition or override.
*
* @return {@code this}, for method chaining
*/
public MetadataBuilder with(BasicType type);
/**
* Register an additional or overridden custom type mapping.
*
* @param type The custom type
* @param keys The keys under which to register the custom type.
*
* @return {@code this}, for method chaining
*/
public MetadataBuilder with(UserType type, String[] keys);
/**
* Register an additional or overridden composite custom type mapping.
*
* @param type The composite custom type
* @param keys The keys under which to register the composite custom type.
*
* @return {@code this}, for method chaining
*/
public MetadataBuilder with(CompositeUserType type, String[] keys);
/**
* Actually build the metamodel
*
* @return The built metadata.
*/
public Metadata build(); public Metadata build();
} }

View File

@ -24,6 +24,8 @@
package org.hibernate.metamodel.internal; package org.hibernate.metamodel.internal;
import javax.persistence.SharedCacheMode; import javax.persistence.SharedCacheMode;
import java.util.ArrayList;
import java.util.List;
import org.jboss.jandex.IndexView; import org.jboss.jandex.IndexView;
import org.xml.sax.EntityResolver; import org.xml.sax.EntityResolver;
@ -41,16 +43,23 @@ import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.EJB3DTDEntityResolver; import org.hibernate.cfg.EJB3DTDEntityResolver;
import org.hibernate.cfg.EJB3NamingStrategy; import org.hibernate.cfg.EJB3NamingStrategy;
import org.hibernate.cfg.NamingStrategy; import org.hibernate.cfg.NamingStrategy;
import org.hibernate.engine.config.spi.ConfigurationService;
import org.hibernate.engine.config.spi.StandardConverters;
import org.hibernate.metamodel.Metadata; import org.hibernate.metamodel.Metadata;
import org.hibernate.metamodel.MetadataBuilder; import org.hibernate.metamodel.MetadataBuilder;
import org.hibernate.metamodel.MetadataSourceProcessingOrder; import org.hibernate.metamodel.MetadataSourceProcessingOrder;
import org.hibernate.metamodel.MetadataSources; import org.hibernate.metamodel.MetadataSources;
import org.hibernate.metamodel.spi.MetadataSourcesContributor; import org.hibernate.metamodel.spi.MetadataSourcesContributor;
import org.hibernate.engine.config.spi.ConfigurationService;
import org.hibernate.engine.config.spi.StandardConverters;
import org.hibernate.service.ServiceRegistry; import org.hibernate.service.ServiceRegistry;
import org.hibernate.type.BasicType;
import org.hibernate.type.CompositeCustomType;
import org.hibernate.type.CustomType;
import org.hibernate.usertype.CompositeUserType;
import org.hibernate.usertype.UserType;
/** /**
* The implementation of the {@link MetadataBuilder} contract.
*
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class MetadataBuilderImpl implements MetadataBuilder { public class MetadataBuilderImpl implements MetadataBuilder {
@ -144,6 +153,24 @@ public class MetadataBuilderImpl implements MetadataBuilder {
return this; return this;
} }
@Override
public MetadataBuilder with(BasicType type) {
options.basicTypeRegistrations.add( type );
return this;
}
@Override
public MetadataBuilder with(UserType type, String[] keys) {
options.basicTypeRegistrations.add( new CustomType( type, keys ) );
return this;
}
@Override
public MetadataBuilder with(CompositeUserType type, String[] keys) {
options.basicTypeRegistrations.add( new CompositeCustomType( type, keys ) );
return this;
}
@Override @Override
public Metadata build() { public Metadata build() {
return new MetadataImpl( sources, options ); return new MetadataImpl( sources, options );
@ -165,6 +192,7 @@ public class MetadataBuilderImpl implements MetadataBuilder {
private String defaultCatalogName; private String defaultCatalogName;
private MultiTenancyStrategy multiTenancyStrategy; private MultiTenancyStrategy multiTenancyStrategy;
public IndexView jandexView; public IndexView jandexView;
public List<BasicType> basicTypeRegistrations = new ArrayList<BasicType>();
public OptionsImpl(StandardServiceRegistry serviceRegistry) { public OptionsImpl(StandardServiceRegistry serviceRegistry) {
this.serviceRegistry = serviceRegistry; this.serviceRegistry = serviceRegistry;
@ -268,5 +296,10 @@ public class MetadataBuilderImpl implements MetadataBuilder {
public IndexView getJandexView() { public IndexView getJandexView() {
return jandexView; return jandexView;
} }
@Override
public List<BasicType> getBasicTypeRegistrations() {
return basicTypeRegistrations;
}
} }
} }