From aecd5a444bc0df5adec09618d7b66dbd30d26235 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Tue, 30 Apr 2013 10:36:38 -0400 Subject: [PATCH] HHH-7998 - Add TypeContributions contract Conflicts: hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataImpl.java hibernate-core/src/main/java/org/hibernate/metamodel/spi/TypeContributor.java --- .../java/org/hibernate/dialect/Dialect.java | 6 +++ .../metamodel/spi/TypeContributions.java | 41 +++++++++++++++++++ .../metamodel/spi/TypeContributor.java | 41 +++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/spi/TypeContributions.java create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/spi/TypeContributor.java diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java index c7f71b123f..e0a9d30ac4 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java @@ -77,7 +77,9 @@ import org.hibernate.internal.util.StringHelper; 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.persister.entity.Lockable; +import org.hibernate.service.ServiceRegistry; import org.hibernate.sql.ANSICaseFragment; import org.hibernate.sql.ANSIJoinFragment; import org.hibernate.sql.CaseFragment; @@ -272,6 +274,10 @@ public abstract class Dialect implements ConversionContext { // 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. diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/TypeContributions.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/TypeContributions.java new file mode 100644 index 0000000000..630e63b4d0 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/TypeContributions.java @@ -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); +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/TypeContributor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/TypeContributor.java new file mode 100644 index 0000000000..004caef5e6 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/TypeContributor.java @@ -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.service.ServiceRegistry; + +/** + * Contract for contributing types. + * + * @author Steve Ebersole + */ +public interface TypeContributor { + /** + * Contribute types + * + * @param typeContributions The callback for adding contributed types + * @param serviceRegistry The service registry + */ + public void contribute(TypeContributions typeContributions, ServiceRegistry serviceRegistry); +}