/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* 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, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY 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
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.id.enhanced;
import java.lang.reflect.Constructor;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.ReflectHelper;
import org.jboss.logging.Logger;
Factory for Optimizer
instances. Author: Steve Ebersole
/**
* Factory for {@link Optimizer} instances.
*
* @author Steve Ebersole
*/
public class OptimizerFactory {
private static final CoreMessageLogger LOG = Logger.getMessageLogger(
CoreMessageLogger.class,
OptimizerFactory.class.getName()
);
Does the given optimizer name represent a pooled strategy?
Params: - optimizerName – The name of the optimizer
Returns: true
indicates the optimizer is a pooled strategy.
/**
* Does the given optimizer name represent a pooled strategy?
*
* @param optimizerName The name of the optimizer
*
* @return {@code true} indicates the optimizer is a pooled strategy.
*/
public static boolean isPooledOptimizer(String optimizerName) {
final StandardOptimizerDescriptor standardDescriptor = StandardOptimizerDescriptor.fromExternalName( optimizerName );
return standardDescriptor != null && standardDescriptor.isPooled();
}
private static final Class[] CTOR_SIG = new Class[] { Class.class, int.class };
Builds an optimizer
Params: - type – The optimizer type, either a short-hand name or the
Optimizer
class name. - returnClass – The generated value java type
- incrementSize – The increment size.
Returns: The built optimizer Deprecated: Use buildOptimizer(String, Class, int, long)
instead
/**
* Builds an optimizer
*
* @param type The optimizer type, either a short-hand name or the {@link Optimizer} class name.
* @param returnClass The generated value java type
* @param incrementSize The increment size.
*
* @return The built optimizer
*
* @deprecated Use {@link #buildOptimizer(String, Class, int, long)} instead
*/
@Deprecated
public static Optimizer buildOptimizer(String type, Class returnClass, int incrementSize) {
final Class<? extends Optimizer> optimizerClass;
final StandardOptimizerDescriptor standardDescriptor = StandardOptimizerDescriptor.fromExternalName( type );
if ( standardDescriptor != null ) {
optimizerClass = standardDescriptor.getOptimizerClass();
}
else {
try {
optimizerClass = ReflectHelper.classForName( type );
}
catch( Throwable ignore ) {
LOG.unableToLocateCustomOptimizerClass( type );
return buildFallbackOptimizer( returnClass, incrementSize );
}
}
try {
final Constructor ctor = optimizerClass.getConstructor( CTOR_SIG );
return (Optimizer) ctor.newInstance( returnClass, incrementSize );
}
catch( Throwable ignore ) {
LOG.unableToInstantiateOptimizer( type );
}
return buildFallbackOptimizer( returnClass, incrementSize );
}
private static Optimizer buildFallbackOptimizer(Class returnClass, int incrementSize) {
return new NoopOptimizer( returnClass, incrementSize );
}
Builds an optimizer
Params: - type – The optimizer type, either a short-hand name or the
Optimizer
class name. - returnClass – The generated value java type
- incrementSize – The increment size.
- explicitInitialValue – The user supplied initial-value (-1 indicates the user did not specify).
Returns: The built optimizer
/**
* Builds an optimizer
*
* @param type The optimizer type, either a short-hand name or the {@link Optimizer} class name.
* @param returnClass The generated value java type
* @param incrementSize The increment size.
* @param explicitInitialValue The user supplied initial-value (-1 indicates the user did not specify).
*
* @return The built optimizer
*/
public static Optimizer buildOptimizer(String type, Class returnClass, int incrementSize, long explicitInitialValue) {
final Optimizer optimizer = buildOptimizer( type, returnClass, incrementSize );
if ( InitialValueAwareOptimizer.class.isInstance( optimizer ) ) {
( (InitialValueAwareOptimizer) optimizer ).injectInitialValue( explicitInitialValue );
}
return optimizer;
}
Deprecated!
Deprecated: Use StandardOptimizerDescriptor.getExternalName()
via StandardOptimizerDescriptor.NONE
/**
* Deprecated!
*
* @deprecated Use {@link StandardOptimizerDescriptor#getExternalName()} via {@link StandardOptimizerDescriptor#NONE}
*/
@Deprecated
@SuppressWarnings( {"UnusedDeclaration"})
public static final String NONE = StandardOptimizerDescriptor.NONE.getExternalName();
Deprecated!
Deprecated: Use StandardOptimizerDescriptor.getExternalName()
via StandardOptimizerDescriptor.HILO
/**
* Deprecated!
*
* @deprecated Use {@link StandardOptimizerDescriptor#getExternalName()} via {@link StandardOptimizerDescriptor#HILO}
*/
@Deprecated
@SuppressWarnings( {"UnusedDeclaration"})
public static final String HILO = StandardOptimizerDescriptor.HILO.getExternalName();
Deprecated!
Deprecated: Use StandardOptimizerDescriptor.getExternalName()
via StandardOptimizerDescriptor.LEGACY_HILO
/**
* Deprecated!
*
* @deprecated Use {@link StandardOptimizerDescriptor#getExternalName()} via {@link StandardOptimizerDescriptor#LEGACY_HILO}
*/
@Deprecated
@SuppressWarnings( {"UnusedDeclaration"})
public static final String LEGACY_HILO = "legacy-hilo";
Deprecated!
Deprecated: Use StandardOptimizerDescriptor.getExternalName()
via StandardOptimizerDescriptor.POOLED
/**
* Deprecated!
*
* @deprecated Use {@link StandardOptimizerDescriptor#getExternalName()} via {@link StandardOptimizerDescriptor#POOLED}
*/
@Deprecated
@SuppressWarnings( {"UnusedDeclaration"})
public static final String POOL = "pooled";
Deprecated!
Deprecated: Use StandardOptimizerDescriptor.getExternalName()
via StandardOptimizerDescriptor.POOLED_LO
/**
* Deprecated!
*
* @deprecated Use {@link StandardOptimizerDescriptor#getExternalName()} via {@link StandardOptimizerDescriptor#POOLED_LO}
*/
@Deprecated
@SuppressWarnings( {"UnusedDeclaration"})
public static final String POOL_LO = "pooled-lo";
private OptimizerFactory() {
}
}