diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/ejb/AvailableSettings.java b/hibernate-entitymanager/src/main/java/org/hibernate/ejb/AvailableSettings.java index 8a31c49185..161659fd31 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/ejb/AvailableSettings.java +++ b/hibernate-entitymanager/src/main/java/org/hibernate/ejb/AvailableSettings.java @@ -256,6 +256,11 @@ public class AvailableSettings { */ public static final String SESSION_FACTORY_OBSERVER = "hibernate.ejb.session_factory_observer"; + /** + * IdentifierGeneratorStrategyRegisterer class name, the class must have a no-arg constructor + */ + public static final String IDENTIFIER_GENERATOR_STRATEGY_PROVIDER = "hibernate.ejb.identifier_generator_strategy_provider"; + /** * Event configuration should follow the following pattern * hibernate.ejb.event.[eventType] f.q.c.n.EventListener1, f.q.c.n.EventListener12 ... diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/ejb/Ejb3Configuration.java b/hibernate-entitymanager/src/main/java/org/hibernate/ejb/Ejb3Configuration.java index e4cafcbd4d..8fda6801a0 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/ejb/Ejb3Configuration.java +++ b/hibernate-entitymanager/src/main/java/org/hibernate/ejb/Ejb3Configuration.java @@ -77,6 +77,7 @@ import org.hibernate.cfg.Settings; import org.hibernate.cfg.SettingsFactory; import org.hibernate.cfg.annotations.reflection.XMLContext; +import org.hibernate.ejb.cfg.spi.IdentifierGeneratorStrategyProvider; import org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider; import org.hibernate.ejb.instrument.InterceptFieldClassFileTransformer; import org.hibernate.ejb.packaging.JarVisitorFactory; @@ -91,6 +92,7 @@ import org.hibernate.ejb.util.NamingHelper; import org.hibernate.engine.FilterDefinition; import org.hibernate.event.EventListeners; +import org.hibernate.id.factory.DefaultIdentifierGeneratorFactory; import org.hibernate.mapping.AuxiliaryDatabaseObject; import org.hibernate.mapping.PersistentClass; import org.hibernate.persister.PersisterClassProvider; @@ -1074,6 +1076,21 @@ else if ( propertyKey.startsWith( AvailableSettings.JACC_PREFIX ) cfg.setSessionFactoryObserver( observer ); } + final IdentifierGeneratorStrategyProvider strategyProvider = instantiateCustomClassFromConfiguration( + preparedProperties, + null, + null, + AvailableSettings.IDENTIFIER_GENERATOR_STRATEGY_PROVIDER, + "Identifier generator strategy provider", + IdentifierGeneratorStrategyProvider.class + ); + if ( strategyProvider != null ) { + final DefaultIdentifierGeneratorFactory identifierGeneratorFactory = cfg.getIdentifierGeneratorFactory(); + for ( Map.Entry> entry : strategyProvider.getStrategies().entrySet() ) { + identifierGeneratorFactory.register( entry.getKey(), entry.getValue() ); + } + } + if ( jaccKeys.size() > 0 ) { addSecurity( jaccKeys, preparedProperties, workingVars ); } diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/ejb/cfg/spi/IdentifierGeneratorStrategyProvider.java b/hibernate-entitymanager/src/main/java/org/hibernate/ejb/cfg/spi/IdentifierGeneratorStrategyProvider.java new file mode 100644 index 0000000000..61d07bc821 --- /dev/null +++ b/hibernate-entitymanager/src/main/java/org/hibernate/ejb/cfg/spi/IdentifierGeneratorStrategyProvider.java @@ -0,0 +1,35 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * JBoss, Home of Professional Open Source + * Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors + * as indicated by the @authors tag. All rights reserved. + * See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * 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, v. 2.1. + * This program is distributed in the hope that it will be useful, but WITHOUT A + * 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, + * v.2.1 along with this distribution; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ +package org.hibernate.ejb.cfg.spi; + +import java.util.Map; + +/** + * Provide a set of IdentifierGenerator strategies allowing to override the Hibernate Core default ones + * + * @author Emmanuel Bernard + */ +public interface IdentifierGeneratorStrategyProvider { + /** + * set of strategy / generator class pairs to register as accepted strategies + */ + Map> getStrategies(); +}