HHH-6084 define id strategy provider in HEM (waiting for MetadataImpl replacement in 4.1)

Conflicts:

	hibernate-entitymanager/src/main/java/org/hibernate/ejb/Ejb3Configuration.java
This commit is contained in:
Emmanuel Bernard 2011-04-05 19:53:51 +02:00
parent 7c39b19ab2
commit 9b2dedc681
3 changed files with 58 additions and 0 deletions

View File

@ -252,6 +252,12 @@ public class AvailableSettings {
*/
public static final String NAMING_STRATEGY = "hibernate.ejb.naming_strategy";
/**
* IdentifierGeneratorStrategyProvider class name, the class must have a no-arg constructor
* @deprecated if possible wait of Hibernate 4.1 and theService registry (MutableIdentifierGeneratorStrategy service)
*/
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 ...

View File

@ -74,6 +74,7 @@ import org.hibernate.cfg.Environment;
import org.hibernate.cfg.NamingStrategy;
import org.hibernate.cfg.annotations.reflection.XMLContext;
import org.hibernate.cfg.beanvalidation.BeanValidationIntegrator;
import org.hibernate.ejb.cfg.spi.IdentifierGeneratorStrategyProvider;
import org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider;
import org.hibernate.ejb.event.JpaIntegrator;
import org.hibernate.ejb.instrument.InterceptFieldClassFileTransformer;
@ -90,6 +91,7 @@ import org.hibernate.ejb.util.NamingHelper;
import org.hibernate.engine.spi.FilterDefinition;
import org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory;
import org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory;
import org.hibernate.id.factory.spi.MutableIdentifierGeneratorFactory;
import org.hibernate.integrator.spi.IntegratorService;
import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.internal.util.StringHelper;
@ -1071,6 +1073,21 @@ public class Ejb3Configuration implements Serializable, Referenceable {
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 MutableIdentifierGeneratorFactory identifierGeneratorFactory = cfg.getIdentifierGeneratorFactory();
for ( Map.Entry<String,Class<?>> entry : strategyProvider.getStrategies().entrySet() ) {
identifierGeneratorFactory.register( entry.getKey(), entry.getValue() );
}
}
if ( jaccKeys.size() > 0 ) {
addSecurity( jaccKeys, preparedProperties, workingVars );
}

View File

@ -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 <emmanuel@hibernate.org>
*/
public interface IdentifierGeneratorStrategyProvider {
/**
* set of strategy / generator class pairs to register as accepted strategies
*/
Map<String,Class<?>> getStrategies();
}