Skip to content

Commit cea2cfd

Browse files
HHH-6084 define id strategy provider in HEM
1 parent 8ca8713 commit cea2cfd

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

hibernate-entitymanager/src/main/java/org/hibernate/ejb/AvailableSettings.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,11 @@ public class AvailableSettings {
256256
*/
257257
public static final String SESSION_FACTORY_OBSERVER = "hibernate.ejb.session_factory_observer";
258258

259+
/**
260+
* IdentifierGeneratorStrategyRegisterer class name, the class must have a no-arg constructor
261+
*/
262+
public static final String IDENTIFIER_GENERATOR_STRATEGY_PROVIDER = "hibernate.ejb.identifier_generator_strategy_provider";
263+
259264
/**
260265
* Event configuration should follow the following pattern
261266
* hibernate.ejb.event.[eventType] f.q.c.n.EventListener1, f.q.c.n.EventListener12 ...

hibernate-entitymanager/src/main/java/org/hibernate/ejb/Ejb3Configuration.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
import org.hibernate.cfg.Settings;
7878
import org.hibernate.cfg.SettingsFactory;
7979
import org.hibernate.cfg.annotations.reflection.XMLContext;
80+
import org.hibernate.ejb.cfg.spi.IdentifierGeneratorStrategyProvider;
8081
import org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider;
8182
import org.hibernate.ejb.instrument.InterceptFieldClassFileTransformer;
8283
import org.hibernate.ejb.packaging.JarVisitorFactory;
@@ -91,6 +92,7 @@
9192
import org.hibernate.ejb.util.NamingHelper;
9293
import org.hibernate.engine.FilterDefinition;
9394
import org.hibernate.event.EventListeners;
95+
import org.hibernate.id.factory.DefaultIdentifierGeneratorFactory;
9496
import org.hibernate.mapping.AuxiliaryDatabaseObject;
9597
import org.hibernate.mapping.PersistentClass;
9698
import org.hibernate.persister.PersisterClassProvider;
@@ -1074,6 +1076,21 @@ else if ( propertyKey.startsWith( AvailableSettings.JACC_PREFIX )
10741076
cfg.setSessionFactoryObserver( observer );
10751077
}
10761078

1079+
final IdentifierGeneratorStrategyProvider strategyProvider = instantiateCustomClassFromConfiguration(
1080+
preparedProperties,
1081+
null,
1082+
null,
1083+
AvailableSettings.IDENTIFIER_GENERATOR_STRATEGY_PROVIDER,
1084+
"Identifier generator strategy provider",
1085+
IdentifierGeneratorStrategyProvider.class
1086+
);
1087+
if ( strategyProvider != null ) {
1088+
final DefaultIdentifierGeneratorFactory identifierGeneratorFactory = cfg.getIdentifierGeneratorFactory();
1089+
for ( Map.Entry<String,Class<?>> entry : strategyProvider.getStrategies().entrySet() ) {
1090+
identifierGeneratorFactory.register( entry.getKey(), entry.getValue() );
1091+
}
1092+
}
1093+
10771094
if ( jaccKeys.size() > 0 ) {
10781095
addSecurity( jaccKeys, preparedProperties, workingVars );
10791096
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* JBoss, Home of Professional Open Source
5+
* Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors
6+
* as indicated by the @authors tag. All rights reserved.
7+
* See the copyright.txt in the distribution for a
8+
* full listing of individual contributors.
9+
*
10+
* This copyrighted material is made available to anyone wishing to use,
11+
* modify, copy, or redistribute it subject to the terms and conditions
12+
* of the GNU Lesser General Public License, v. 2.1.
13+
* This program is distributed in the hope that it will be useful, but WITHOUT A
14+
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
15+
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16+
* You should have received a copy of the GNU Lesser General Public License,
17+
* v.2.1 along with this distribution; if not, write to the Free Software
18+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19+
* MA 02110-1301, USA.
20+
*/
21+
package org.hibernate.ejb.cfg.spi;
22+
23+
import java.util.Map;
24+
25+
/**
26+
* Provide a set of IdentifierGenerator strategies allowing to override the Hibernate Core default ones
27+
*
28+
* @author Emmanuel Bernard <emmanuel@hibernate.org>
29+
*/
30+
public interface IdentifierGeneratorStrategyProvider {
31+
/**
32+
* set of strategy / generator class pairs to register as accepted strategies
33+
*/
34+
Map<String,Class<?>> getStrategies();
35+
}

0 commit comments

Comments
 (0)