Skip to content

Commit

Permalink
HHH-6084 define id strategy provider in HEM
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuelbernard committed Apr 6, 2011
1 parent 8ca8713 commit cea2cfd
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
Expand Up @@ -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 ...
Expand Down
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<String,Class<?>> entry : strategyProvider.getStrategies().entrySet() ) {
identifierGeneratorFactory.register( entry.getKey(), entry.getValue() );
}
}

if ( jaccKeys.size() > 0 ) {
addSecurity( jaccKeys, preparedProperties, workingVars );
}
Expand Down
@@ -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();
}

0 comments on commit cea2cfd

Please sign in to comment.