From 66347adca60b61d700d2be2e057e33d1f0487666 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Fri, 27 May 2011 13:00:33 -0500 Subject: [PATCH] HHH-6272 - More logging fix ups --- .../DefaultIdentifierGeneratorFactory.java | 50 +++++++++---------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/id/factory/DefaultIdentifierGeneratorFactory.java b/hibernate-core/src/main/java/org/hibernate/id/factory/DefaultIdentifierGeneratorFactory.java index 169893cc88..824d495fe2 100644 --- a/hibernate-core/src/main/java/org/hibernate/id/factory/DefaultIdentifierGeneratorFactory.java +++ b/hibernate-core/src/main/java/org/hibernate/id/factory/DefaultIdentifierGeneratorFactory.java @@ -22,11 +22,13 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.id.factory; + import java.io.Serializable; import java.util.Properties; import java.util.concurrent.ConcurrentHashMap; -import org.hibernate.internal.CoreMessageLogger; +import org.jboss.logging.Logger; + import org.hibernate.MappingException; import org.hibernate.dialect.Dialect; import org.hibernate.id.Assigned; @@ -45,9 +47,9 @@ import org.hibernate.id.UUIDGenerator; import org.hibernate.id.UUIDHexGenerator; import org.hibernate.id.enhanced.SequenceStyleGenerator; import org.hibernate.id.enhanced.TableGenerator; +import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.ReflectHelper; import org.hibernate.type.Type; -import org.jboss.logging.Logger; /** * Basic templated support for {@link IdentifierGeneratorFactory} implementations. @@ -83,43 +85,37 @@ public class DefaultIdentifierGeneratorFactory implements IdentifierGeneratorFac register( "enhanced-table", TableGenerator.class ); } - /** - * {@inheritDoc} - */ + public void register(String strategy, Class generatorClass) { + LOG.debugf( "Registering IdentifierGenerator strategy [%s] -> [%s]" + strategy + "] -> [" + generatorClass.getName() + "]" ); + final Class previous = generatorStrategyToClassNameMap.put( strategy, generatorClass ); + if ( previous != null ) { + LOG.debugf( " - overriding [%s]", previous.getName() ); + } + } + + @Override public void setDialect(Dialect dialect) { - LOG.debugf("Setting dialect [%s]", dialect); + LOG.debugf( "Setting dialect [%s]", dialect ); this.dialect = dialect; } - public void register(String strategy, Class generatorClass) { - Object old = generatorStrategyToClassNameMap.put( strategy, generatorClass ); - String msg = "Registering IdentifierGenerator strategy [" + strategy + "] -> [" + generatorClass + "]"; - if (old != null) msg += ", overriding [" + old + "]"; - LOG.debugf(msg); - } - - /** - * {@inheritDoc} - */ + @Override public IdentifierGenerator createIdentifierGenerator(String strategy, Type type, Properties config) { try { Class clazz = getIdentifierGeneratorClass( strategy ); - IdentifierGenerator idgen = ( IdentifierGenerator ) clazz.newInstance(); - if ( idgen instanceof Configurable ) { - ( ( Configurable ) idgen ).configure( type, config, dialect ); + IdentifierGenerator identifierGenerator = ( IdentifierGenerator ) clazz.newInstance(); + if ( identifierGenerator instanceof Configurable ) { + ( ( Configurable ) identifierGenerator ).configure( type, config, dialect ); } - return idgen; + return identifierGenerator; } catch ( Exception e ) { - String msg = "Could not instantiate id generator [entity-name=" - + config.get( IdentifierGenerator.ENTITY_NAME ) + "]"; - throw new MappingException( msg, e ); + final String entityName = config.getProperty( IdentifierGenerator.ENTITY_NAME ); + throw new MappingException( String.format( "Could not instantiate id generator [entity-name=%s]", entityName ), e ); } } - /** - * {@inheritDoc} - */ + @Override public Class getIdentifierGeneratorClass(String strategy) { if ( "native".equals( strategy ) ) { return dialect.getNativeIdentifierGeneratorClass(); @@ -132,7 +128,7 @@ public class DefaultIdentifierGeneratorFactory implements IdentifierGeneratorFac } } catch ( ClassNotFoundException e ) { - throw new MappingException( "Could not interpret id generator strategy [" + strategy + "]" ); + throw new MappingException( String.format( "Could not interpret id generator strategy [%s]", strategy ) ); } return generatorClass; }