mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-28 14:59:12 +00:00
HHH-7998 - Add TypeContributions contract
This commit is contained in:
parent
191a711a1d
commit
e40bf012fb
@ -76,12 +76,14 @@
|
||||
import org.hibernate.internal.util.collections.ArrayHelper;
|
||||
import org.hibernate.internal.util.io.StreamCopier;
|
||||
import org.hibernate.mapping.Column;
|
||||
import org.hibernate.metamodel.spi.TypeContributions;
|
||||
import org.hibernate.metamodel.spi.relational.AuxiliaryDatabaseObject;
|
||||
import org.hibernate.metamodel.spi.relational.ForeignKey;
|
||||
import org.hibernate.metamodel.spi.relational.Index;
|
||||
import org.hibernate.metamodel.spi.relational.Sequence;
|
||||
import org.hibernate.metamodel.spi.relational.Table;
|
||||
import org.hibernate.persister.entity.Lockable;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.sql.ANSICaseFragment;
|
||||
import org.hibernate.sql.ANSIJoinFragment;
|
||||
import org.hibernate.sql.CaseFragment;
|
||||
@ -283,6 +285,10 @@ public String toString() {
|
||||
|
||||
// database type mapping support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
|
||||
// by default, nothing to do
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the database type associated with the given
|
||||
* {@link java.sql.Types} typecode.
|
||||
|
@ -40,6 +40,7 @@
|
||||
import org.hibernate.cache.spi.access.AccessType;
|
||||
import org.hibernate.cfg.NamingStrategy;
|
||||
import org.hibernate.cfg.ObjectNameNormalizer;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.engine.ResultSetMappingDefinition;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
||||
import org.hibernate.engine.spi.FilterDefinition;
|
||||
@ -61,6 +62,7 @@
|
||||
import org.hibernate.metamodel.spi.MetadataContributor;
|
||||
import org.hibernate.metamodel.spi.MetadataImplementor;
|
||||
import org.hibernate.metamodel.spi.MetadataSourceProcessor;
|
||||
import org.hibernate.metamodel.spi.TypeContributions;
|
||||
import org.hibernate.metamodel.spi.TypeContributor;
|
||||
import org.hibernate.metamodel.spi.binding.AttributeBinding;
|
||||
import org.hibernate.metamodel.spi.binding.BackRefAttributeBinding;
|
||||
@ -91,6 +93,9 @@
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.type.BasicTypeRegistry;
|
||||
import org.hibernate.type.TypeResolver;
|
||||
import org.hibernate.usertype.CompositeUserType;
|
||||
import org.hibernate.usertype.UserType;
|
||||
|
||||
import org.jboss.jandex.IndexView;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
@ -192,15 +197,40 @@ protected boolean isUseQuotedIdentifiersGlobally() {
|
||||
// build BasicTypeRegistry and TypeResolver ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// ultimately this needs to change a little bit to account for HHH-7792
|
||||
final BasicTypeRegistry basicTypeRegistry = new BasicTypeRegistry();
|
||||
// todo : add concept of Dialect contributed types
|
||||
// add TypeContributor contributed types.
|
||||
for ( TypeContributor contributor : classLoaderService.loadJavaServices( TypeContributor.class ) ) {
|
||||
contributor.contribute( this );
|
||||
|
||||
{
|
||||
final TypeContributions typeContributions = new TypeContributions() {
|
||||
@Override
|
||||
public void contributeType(org.hibernate.type.BasicType type) {
|
||||
basicTypeRegistry.register( type );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contributeType(UserType type, String[] keys) {
|
||||
basicTypeRegistry.register( type, keys );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contributeType(CompositeUserType type, String[] keys) {
|
||||
basicTypeRegistry.register( type, keys );
|
||||
}
|
||||
};
|
||||
|
||||
// add Dialect contributed types
|
||||
final Dialect dialect = serviceRegistry.getService( JdbcServices.class ).getDialect();
|
||||
dialect.contributeTypes( typeContributions, serviceRegistry );
|
||||
|
||||
// add TypeContributor contributed types.
|
||||
for ( TypeContributor contributor : classLoaderService.loadJavaServices( TypeContributor.class ) ) {
|
||||
contributor.contribute( typeContributions, serviceRegistry );
|
||||
}
|
||||
}
|
||||
|
||||
// add explicit application registered types
|
||||
for ( org.hibernate.type.BasicType basicType : options.getBasicTypeRegistrations() ) {
|
||||
basicTypeRegistry.register( basicType );
|
||||
}
|
||||
|
||||
typeResolver = new TypeResolver( basicTypeRegistry );
|
||||
|
||||
processFilterDefinitions( metadataSourceProcessors );
|
||||
|
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2012, 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.spi;
|
||||
|
||||
import org.hibernate.type.BasicType;
|
||||
import org.hibernate.usertype.CompositeUserType;
|
||||
import org.hibernate.usertype.UserType;
|
||||
|
||||
/**
|
||||
* Defines the target contributing types, whether via dialects or {@link TypeContributor}
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface TypeContributions {
|
||||
public void contributeType(BasicType type);
|
||||
|
||||
public void contributeType(UserType type, String[] keys);
|
||||
|
||||
public void contributeType(CompositeUserType type, String[] keys);
|
||||
}
|
@ -23,17 +23,19 @@
|
||||
*/
|
||||
package org.hibernate.metamodel.spi;
|
||||
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
|
||||
/**
|
||||
* Contract for contributing types to a Metadata ({@link MetadataImplementor}) instance. Called before
|
||||
* entity/collection processing happens, but after type definition binding happens (to allow overriding).
|
||||
* Contract for contributing types.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface TypeContributor {
|
||||
/**
|
||||
* Contribute types to the given Metadata object.
|
||||
* Contribute types
|
||||
*
|
||||
* @param metadata The metadata to which to contribute types.
|
||||
* @param typeContributions The callback for adding contributed types
|
||||
* @param serviceRegistry The service registry
|
||||
*/
|
||||
public void contribute(MetadataImplementor metadata);
|
||||
public void contribute(TypeContributions typeContributions, ServiceRegistry serviceRegistry);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user