HHH-3050 - Convert usage of Hibernate's FastHashMap to ConcurrentHashMap (Java 1.5)
git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@19584 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
96664aeb2f
commit
ddac598513
|
@ -1,10 +1,10 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||
* 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 Middleware LLC.
|
||||
* 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
|
||||
|
@ -20,12 +20,12 @@
|
|||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
package org.hibernate.id.factory;
|
||||
|
||||
import java.util.Properties;
|
||||
import java.io.Serializable;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -46,7 +46,6 @@ import org.hibernate.id.Configurable;
|
|||
import org.hibernate.id.enhanced.SequenceStyleGenerator;
|
||||
import org.hibernate.id.enhanced.TableGenerator;
|
||||
import org.hibernate.type.Type;
|
||||
import org.hibernate.util.FastHashMap;
|
||||
import org.hibernate.util.ReflectHelper;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.MappingException;
|
||||
|
@ -60,7 +59,7 @@ public class DefaultIdentifierGeneratorFactory implements IdentifierGeneratorFac
|
|||
private static final Logger log = LoggerFactory.getLogger( DefaultIdentifierGeneratorFactory.class );
|
||||
|
||||
private transient Dialect dialect;
|
||||
private FastHashMap generatorStrategyToClassNameMap = new FastHashMap();
|
||||
private ConcurrentHashMap<String, Class> generatorStrategyToClassNameMap = new ConcurrentHashMap<String, Class>();
|
||||
|
||||
/**
|
||||
* Constructs a new DefaultIdentifierGeneratorFactory.
|
||||
|
@ -126,7 +125,7 @@ public class DefaultIdentifierGeneratorFactory implements IdentifierGeneratorFac
|
|||
return dialect.getNativeIdentifierGeneratorClass();
|
||||
}
|
||||
|
||||
Class generatorClass = ( Class ) generatorStrategyToClassNameMap.get( strategy );
|
||||
Class generatorClass = generatorStrategyToClassNameMap.get( strategy );
|
||||
try {
|
||||
if ( generatorClass == null ) {
|
||||
generatorClass = ReflectHelper.classForName( strategy );
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||
* 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 Middleware LLC.
|
||||
* 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
|
||||
|
@ -20,14 +20,13 @@
|
|||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
package org.hibernate.impl;
|
||||
|
||||
import java.util.Hashtable;
|
||||
import java.util.Iterator;
|
||||
import java.util.Properties;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import javax.naming.Context;
|
||||
import javax.naming.InvalidNameException;
|
||||
import javax.naming.Name;
|
||||
|
@ -40,18 +39,18 @@ import javax.naming.event.NamingExceptionEvent;
|
|||
import javax.naming.event.NamingListener;
|
||||
import javax.naming.spi.ObjectFactory;
|
||||
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.util.FastHashMap;
|
||||
import org.hibernate.util.NamingHelper;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.util.NamingHelper;
|
||||
|
||||
/**
|
||||
* Resolves <tt>SessionFactory</tt> JNDI lookups and deserialization
|
||||
* Resolves {@link SessionFactory} instances during <tt>JNDI<tt> look-ups as well as during deserialization
|
||||
*/
|
||||
public class SessionFactoryObjectFactory implements ObjectFactory {
|
||||
|
||||
@SuppressWarnings({ "UnusedDeclaration" })
|
||||
private static final SessionFactoryObjectFactory INSTANCE; //to stop the class from being unloaded
|
||||
|
||||
private static final Logger log;
|
||||
|
@ -62,8 +61,8 @@ public class SessionFactoryObjectFactory implements ObjectFactory {
|
|||
log.debug("initializing class SessionFactoryObjectFactory");
|
||||
}
|
||||
|
||||
private static final FastHashMap INSTANCES = new FastHashMap();
|
||||
private static final FastHashMap NAMED_INSTANCES = new FastHashMap();
|
||||
private static final ConcurrentHashMap<String, SessionFactory> INSTANCES = new ConcurrentHashMap<String, SessionFactory>();
|
||||
private static final ConcurrentHashMap<String, SessionFactory> NAMED_INSTANCES = new ConcurrentHashMap<String, SessionFactory>();
|
||||
|
||||
private static final NamingListener LISTENER = new NamespaceChangeListener() {
|
||||
public void objectAdded(NamingEvent evt) {
|
||||
|
@ -84,6 +83,7 @@ public class SessionFactoryObjectFactory implements ObjectFactory {
|
|||
NAMED_INSTANCES.put( evt.getNewBinding().getName(), NAMED_INSTANCES.remove(name) );
|
||||
}
|
||||
public void namingExceptionThrown(NamingExceptionEvent evt) {
|
||||
//noinspection ThrowableResultOfMethodCallIgnored
|
||||
log.warn( "Naming exception occurred accessing factory: " + evt.getException() );
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||
* 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 Middleware LLC.
|
||||
* 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
|
||||
|
@ -20,17 +20,16 @@
|
|||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
package org.hibernate.tuple;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.hibernate.EntityMode;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.util.FastHashMap;
|
||||
|
||||
/**
|
||||
* Centralizes handling of {@link EntityMode} to {@link Tuplizer} mappings.
|
||||
|
@ -38,14 +37,13 @@ import org.hibernate.util.FastHashMap;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
public abstract class EntityModeToTuplizerMapping implements Serializable {
|
||||
|
||||
// map of EntityMode -> Tuplizer
|
||||
private final Map tuplizers;
|
||||
private final Map<EntityMode,Tuplizer> tuplizers;
|
||||
|
||||
public EntityModeToTuplizerMapping() {
|
||||
tuplizers = new FastHashMap();
|
||||
tuplizers = new ConcurrentHashMap<EntityMode,Tuplizer>();
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "UnusedDeclaration" })
|
||||
public EntityModeToTuplizerMapping(Map tuplizers) {
|
||||
this.tuplizers = tuplizers;
|
||||
}
|
||||
|
@ -70,12 +68,9 @@ public abstract class EntityModeToTuplizerMapping implements Serializable {
|
|||
* @return The guessed entity mode.
|
||||
*/
|
||||
public EntityMode guessEntityMode(Object object) {
|
||||
Iterator itr = tuplizers.entrySet().iterator();
|
||||
while( itr.hasNext() ) {
|
||||
Map.Entry entry = ( Map.Entry ) itr.next();
|
||||
Tuplizer tuplizer = ( Tuplizer ) entry.getValue();
|
||||
if ( tuplizer.isInstance( object ) ) {
|
||||
return ( EntityMode ) entry.getKey();
|
||||
for ( Map.Entry<EntityMode, Tuplizer> entityModeTuplizerEntry : tuplizers.entrySet() ) {
|
||||
if ( entityModeTuplizerEntry.getValue().isInstance( object ) ) {
|
||||
return entityModeTuplizerEntry.getKey();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@ -89,7 +84,7 @@ public abstract class EntityModeToTuplizerMapping implements Serializable {
|
|||
* @return The tuplizer, or null if not found.
|
||||
*/
|
||||
public Tuplizer getTuplizerOrNull(EntityMode entityMode) {
|
||||
return ( Tuplizer ) tuplizers.get( entityMode );
|
||||
return tuplizers.get( entityMode );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||
* 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 Middleware LLC.
|
||||
* 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
|
||||
|
@ -20,15 +20,14 @@
|
|||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
package org.hibernate.tuple.component;
|
||||
|
||||
import java.util.Map;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.io.Serializable;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.hibernate.util.FastHashMap;
|
||||
import org.hibernate.util.ReflectHelper;
|
||||
import org.hibernate.EntityMode;
|
||||
import org.hibernate.HibernateException;
|
||||
|
@ -40,10 +39,9 @@ import org.hibernate.mapping.Component;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
public class ComponentTuplizerFactory implements Serializable {
|
||||
|
||||
private static final Class[] COMPONENT_TUP_CTOR_SIG = new Class[] { Component.class };
|
||||
|
||||
private Map defaultImplClassByMode = buildBaseMapping();
|
||||
private Map<EntityMode,Class<? extends ComponentTuplizer>> defaultImplClassByMode = buildBaseMapping();
|
||||
|
||||
/**
|
||||
* Method allowing registration of the tuplizer class to use as default for a particular entity-mode.
|
||||
|
@ -51,7 +49,8 @@ public class ComponentTuplizerFactory implements Serializable {
|
|||
* @param entityMode The entity-mode for which to register the tuplizer class
|
||||
* @param tuplizerClass The class to use as the default tuplizer for the given entity-mode.
|
||||
*/
|
||||
public void registerDefaultTuplizerClass(EntityMode entityMode, Class tuplizerClass) {
|
||||
@SuppressWarnings({ "UnusedDeclaration" })
|
||||
public void registerDefaultTuplizerClass(EntityMode entityMode, Class<? extends ComponentTuplizer> tuplizerClass) {
|
||||
assert isComponentTuplizerImplementor( tuplizerClass )
|
||||
: "Specified tuplizer class [" + tuplizerClass.getName() + "] does not implement " + ComponentTuplizer.class.getName();
|
||||
assert hasProperConstructor( tuplizerClass )
|
||||
|
@ -71,9 +70,10 @@ public class ComponentTuplizerFactory implements Serializable {
|
|||
* @throws HibernateException If class name cannot be resolved to a class reference, or if the
|
||||
* {@link Constructor#newInstance} call fails.
|
||||
*/
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public ComponentTuplizer constructTuplizer(String tuplizerClassName, Component metadata) {
|
||||
try {
|
||||
Class tuplizerClass = ReflectHelper.classForName( tuplizerClassName );
|
||||
Class<? extends ComponentTuplizer> tuplizerClass = ReflectHelper.classForName( tuplizerClassName );
|
||||
return constructTuplizer( tuplizerClass, metadata );
|
||||
}
|
||||
catch ( ClassNotFoundException e ) {
|
||||
|
@ -91,11 +91,11 @@ public class ComponentTuplizerFactory implements Serializable {
|
|||
*
|
||||
* @throws HibernateException if the {@link java.lang.reflect.Constructor#newInstance} call fails.
|
||||
*/
|
||||
public ComponentTuplizer constructTuplizer(Class tuplizerClass, Component metadata) {
|
||||
Constructor ctor = getProperConstructor( tuplizerClass );
|
||||
assert ctor != null : "Unable to locate proper constructor for tuplizer [" + tuplizerClass.getName() + "]";
|
||||
public ComponentTuplizer constructTuplizer(Class<? extends ComponentTuplizer> tuplizerClass, Component metadata) {
|
||||
Constructor<? extends ComponentTuplizer> constructor = getProperConstructor( tuplizerClass );
|
||||
assert constructor != null : "Unable to locate proper constructor for tuplizer [" + tuplizerClass.getName() + "]";
|
||||
try {
|
||||
return ( ComponentTuplizer ) ctor.newInstance( new Object[] { metadata } );
|
||||
return constructor.newInstance( metadata );
|
||||
}
|
||||
catch ( Throwable t ) {
|
||||
throw new HibernateException( "Unable to instantiate default tuplizer [" + tuplizerClass.getName() + "]", t );
|
||||
|
@ -114,7 +114,7 @@ public class ComponentTuplizerFactory implements Serializable {
|
|||
* {@link #constructTuplizer} too.
|
||||
*/
|
||||
public ComponentTuplizer constructDefaultTuplizer(EntityMode entityMode, Component metadata) {
|
||||
Class tuplizerClass = ( Class ) defaultImplClassByMode.get( entityMode );
|
||||
Class<? extends ComponentTuplizer> tuplizerClass = defaultImplClassByMode.get( entityMode );
|
||||
if ( tuplizerClass == null ) {
|
||||
throw new HibernateException( "could not determine default tuplizer class to use [" + entityMode + "]" );
|
||||
}
|
||||
|
@ -126,32 +126,33 @@ public class ComponentTuplizerFactory implements Serializable {
|
|||
return ReflectHelper.implementsInterface( tuplizerClass, ComponentTuplizer.class );
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
private boolean hasProperConstructor(Class tuplizerClass) {
|
||||
return getProperConstructor( tuplizerClass ) != null;
|
||||
}
|
||||
|
||||
private Constructor getProperConstructor(Class clazz) {
|
||||
Constructor ctor = null;
|
||||
private Constructor<? extends ComponentTuplizer> getProperConstructor(Class<? extends ComponentTuplizer> clazz) {
|
||||
Constructor<? extends ComponentTuplizer> constructor = null;
|
||||
try {
|
||||
ctor = clazz.getDeclaredConstructor( COMPONENT_TUP_CTOR_SIG );
|
||||
if ( ! ReflectHelper.isPublic( ctor ) ) {
|
||||
constructor = clazz.getDeclaredConstructor( COMPONENT_TUP_CTOR_SIG );
|
||||
if ( ! ReflectHelper.isPublic( constructor ) ) {
|
||||
try {
|
||||
// found a ctor, but it was not publicly accessible so try to request accessibility
|
||||
ctor.setAccessible( true );
|
||||
// found a constructor, but it was not publicly accessible so try to request accessibility
|
||||
constructor.setAccessible( true );
|
||||
}
|
||||
catch ( SecurityException e ) {
|
||||
ctor = null;
|
||||
constructor = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( NoSuchMethodException ignore ) {
|
||||
}
|
||||
|
||||
return ctor;
|
||||
return constructor;
|
||||
}
|
||||
|
||||
private static Map buildBaseMapping() {
|
||||
Map map = new FastHashMap();
|
||||
private static Map<EntityMode,Class<? extends ComponentTuplizer>> buildBaseMapping() {
|
||||
Map<EntityMode,Class<? extends ComponentTuplizer>> map = new ConcurrentHashMap<EntityMode,Class<? extends ComponentTuplizer>>();
|
||||
map.put( EntityMode.POJO, PojoComponentTuplizer.class );
|
||||
map.put( EntityMode.DOM4J, Dom4jComponentTuplizer.class );
|
||||
map.put( EntityMode.MAP, DynamicMapComponentTuplizer.class );
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||
* 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 Middleware LLC.
|
||||
* 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
|
||||
|
@ -20,20 +20,18 @@
|
|||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
package org.hibernate.tuple.entity;
|
||||
|
||||
import java.util.Map;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
|
||||
import org.hibernate.util.FastHashMap;
|
||||
import org.hibernate.util.ReflectHelper;
|
||||
import org.hibernate.EntityMode;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.mapping.PersistentClass;
|
||||
import org.hibernate.util.ReflectHelper;
|
||||
|
||||
/**
|
||||
* A registry allowing users to define the default {@link EntityTuplizer} class to use per {@link EntityMode}.
|
||||
|
@ -41,10 +39,9 @@ import org.hibernate.mapping.PersistentClass;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
public class EntityTuplizerFactory implements Serializable {
|
||||
|
||||
public static final Class[] ENTITY_TUP_CTOR_SIG = new Class[] { EntityMetamodel.class, PersistentClass.class };
|
||||
|
||||
private Map defaultImplClassByMode = buildBaseMapping();
|
||||
private Map<EntityMode,Class<? extends EntityTuplizer>> defaultImplClassByMode = buildBaseMapping();
|
||||
|
||||
/**
|
||||
* Method allowing registration of the tuplizer class to use as default for a particular entity-mode.
|
||||
|
@ -52,7 +49,7 @@ public class EntityTuplizerFactory implements Serializable {
|
|||
* @param entityMode The entity-mode for which to register the tuplizer class
|
||||
* @param tuplizerClass The class to use as the default tuplizer for the given entity-mode.
|
||||
*/
|
||||
public void registerDefaultTuplizerClass(EntityMode entityMode, Class tuplizerClass) {
|
||||
public void registerDefaultTuplizerClass(EntityMode entityMode, Class<? extends EntityTuplizer> tuplizerClass) {
|
||||
assert isEntityTuplizerImplementor( tuplizerClass )
|
||||
: "Specified tuplizer class [" + tuplizerClass.getName() + "] does not implement " + EntityTuplizer.class.getName();
|
||||
assert hasProperConstructor( tuplizerClass )
|
||||
|
@ -73,12 +70,13 @@ public class EntityTuplizerFactory implements Serializable {
|
|||
* @throws HibernateException If class name cannot be resolved to a class reference, or if the
|
||||
* {@link Constructor#newInstance} call fails.
|
||||
*/
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public EntityTuplizer constructTuplizer(
|
||||
String tuplizerClassName,
|
||||
EntityMetamodel metamodel,
|
||||
PersistentClass persistentClass) {
|
||||
try {
|
||||
Class tuplizerClass = ReflectHelper.classForName( tuplizerClassName );
|
||||
Class<? extends EntityTuplizer> tuplizerClass = ReflectHelper.classForName( tuplizerClassName );
|
||||
return constructTuplizer( tuplizerClass, metamodel, persistentClass );
|
||||
}
|
||||
catch ( ClassNotFoundException e ) {
|
||||
|
@ -98,13 +96,13 @@ public class EntityTuplizerFactory implements Serializable {
|
|||
* @throws HibernateException if the {@link Constructor#newInstance} call fails.
|
||||
*/
|
||||
public EntityTuplizer constructTuplizer(
|
||||
Class tuplizerClass,
|
||||
Class<? extends EntityTuplizer> tuplizerClass,
|
||||
EntityMetamodel metamodel,
|
||||
PersistentClass persistentClass) {
|
||||
Constructor ctor = getProperConstructor( tuplizerClass );
|
||||
assert ctor != null : "Unable to locate proper constructor for tuplizer [" + tuplizerClass.getName() + "]";
|
||||
Constructor<? extends EntityTuplizer> constructor = getProperConstructor( tuplizerClass );
|
||||
assert constructor != null : "Unable to locate proper constructor for tuplizer [" + tuplizerClass.getName() + "]";
|
||||
try {
|
||||
return ( EntityTuplizer ) ctor.newInstance( new Object[] { metamodel, persistentClass } );
|
||||
return constructor.newInstance( metamodel, persistentClass );
|
||||
}
|
||||
catch ( Throwable t ) {
|
||||
throw new HibernateException( "Unable to instantiate default tuplizer [" + tuplizerClass.getName() + "]", t );
|
||||
|
@ -127,7 +125,7 @@ public class EntityTuplizerFactory implements Serializable {
|
|||
EntityMode entityMode,
|
||||
EntityMetamodel metamodel,
|
||||
PersistentClass persistentClass) {
|
||||
Class tuplizerClass = ( Class ) defaultImplClassByMode.get( entityMode );
|
||||
Class<? extends EntityTuplizer> tuplizerClass = defaultImplClassByMode.get( entityMode );
|
||||
if ( tuplizerClass == null ) {
|
||||
throw new HibernateException( "could not determine default tuplizer class to use [" + entityMode + "]" );
|
||||
}
|
||||
|
@ -139,33 +137,33 @@ public class EntityTuplizerFactory implements Serializable {
|
|||
return ReflectHelper.implementsInterface( tuplizerClass, EntityTuplizer.class );
|
||||
}
|
||||
|
||||
private boolean hasProperConstructor(Class tuplizerClass) {
|
||||
private boolean hasProperConstructor(Class<? extends EntityTuplizer> tuplizerClass) {
|
||||
return getProperConstructor( tuplizerClass ) != null
|
||||
&& ! ReflectHelper.isAbstractClass( tuplizerClass );
|
||||
}
|
||||
|
||||
private Constructor getProperConstructor(Class clazz) {
|
||||
Constructor ctor = null;
|
||||
private Constructor<? extends EntityTuplizer> getProperConstructor(Class<? extends EntityTuplizer> clazz) {
|
||||
Constructor<? extends EntityTuplizer> constructor = null;
|
||||
try {
|
||||
ctor = clazz.getDeclaredConstructor( ENTITY_TUP_CTOR_SIG );
|
||||
if ( ! ReflectHelper.isPublic( ctor ) ) {
|
||||
constructor = clazz.getDeclaredConstructor( ENTITY_TUP_CTOR_SIG );
|
||||
if ( ! ReflectHelper.isPublic( constructor ) ) {
|
||||
try {
|
||||
// found a ctor, but it was not publicly accessible so try to request accessibility
|
||||
ctor.setAccessible( true );
|
||||
// found a constructor, but it was not publicly accessible so try to request accessibility
|
||||
constructor.setAccessible( true );
|
||||
}
|
||||
catch ( SecurityException e ) {
|
||||
ctor = null;
|
||||
constructor = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( NoSuchMethodException ignore ) {
|
||||
}
|
||||
|
||||
return ctor;
|
||||
return constructor;
|
||||
}
|
||||
|
||||
private static Map buildBaseMapping() {
|
||||
Map map = new FastHashMap();
|
||||
private static Map<EntityMode,Class<? extends EntityTuplizer>> buildBaseMapping() {
|
||||
Map<EntityMode,Class<? extends EntityTuplizer>> map = new ConcurrentHashMap<EntityMode,Class<? extends EntityTuplizer>>();
|
||||
map.put( EntityMode.POJO, PojoEntityTuplizer.class );
|
||||
map.put( EntityMode.DOM4J, Dom4jEntityTuplizer.class );
|
||||
map.put( EntityMode.MAP, DynamicMapEntityTuplizer.class );
|
||||
|
|
|
@ -1,335 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2008, Red Hat Middleware LLC 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 Middleware LLC.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
|
||||
// This class was taken from Apache commons-collections -
|
||||
// I made it final + removed the "slow" mode...
|
||||
|
||||
package org.hibernate.util;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* <p>A customized implementation of <code>java.util.HashMap</code> designed
|
||||
* to operate in a multithreaded environment where the large majority of
|
||||
* method calls are read-only, instead of structural changes.
|
||||
* Read calls are non-synchronized and write calls perform the
|
||||
* following steps:</p>
|
||||
* <ul>
|
||||
* <li>Clone the existing collection
|
||||
* <li>Perform the modification on the clone
|
||||
* <li>Replace the existing collection with the (modified) clone
|
||||
* </ul>
|
||||
* <p><strong>NOTE</strong>: If you are creating and accessing a
|
||||
* <code>HashMap</code> only within a single thread, you should use
|
||||
* <code>java.util.HashMap</code> directly (with no synchronization), for
|
||||
* maximum performance.</p>
|
||||
*
|
||||
*/
|
||||
|
||||
public final class FastHashMap implements Map, Serializable {
|
||||
|
||||
// ----------------------------------------------------------- Constructors
|
||||
|
||||
/**
|
||||
* Construct a an empty map.
|
||||
*/
|
||||
public FastHashMap() {
|
||||
|
||||
super();
|
||||
this.map = new HashMap();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an empty map with the specified capacity.
|
||||
*
|
||||
* @param capacity The initial capacity of the empty map
|
||||
*/
|
||||
public FastHashMap(int capacity) {
|
||||
|
||||
super();
|
||||
this.map = new HashMap(capacity);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an empty map with the specified capacity and load factor.
|
||||
*
|
||||
* @param capacity The initial capacity of the empty map
|
||||
* @param factor The load factor of the new map
|
||||
*/
|
||||
public FastHashMap(int capacity, float factor) {
|
||||
|
||||
super();
|
||||
this.map = new HashMap(capacity, factor);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new map with the same mappings as the specified map.
|
||||
*
|
||||
* @param map The map whose mappings are to be copied
|
||||
*/
|
||||
public FastHashMap(Map map) {
|
||||
|
||||
super();
|
||||
this.map = new HashMap(map);
|
||||
|
||||
}
|
||||
|
||||
// ----------------------------------------------------- Instance Variables
|
||||
|
||||
/**
|
||||
* The underlying map we are managing.
|
||||
*/
|
||||
private HashMap map = null;
|
||||
|
||||
// --------------------------------------------------------- Public Methods
|
||||
|
||||
/**
|
||||
* Remove all mappings from this map.
|
||||
*/
|
||||
public void clear() {
|
||||
|
||||
synchronized (this) {
|
||||
HashMap temp = (HashMap) map.clone();
|
||||
temp.clear();
|
||||
map = temp;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a shallow copy of this <code>FastHashMap</code> instance.
|
||||
* The keys and values themselves are not copied.
|
||||
*/
|
||||
public Object clone() {
|
||||
|
||||
return new FastHashMap(map);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return <code>true</code> if this map contains a mapping for the
|
||||
* specified key.
|
||||
*
|
||||
* @param key Key to be searched for
|
||||
*/
|
||||
public boolean containsKey(Object key) {
|
||||
|
||||
return map.containsKey(key);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return <code>true</code> if this map contains one or more keys mapping
|
||||
* to the specified value.
|
||||
*
|
||||
* @param value Value to be searched for
|
||||
*/
|
||||
public boolean containsValue(Object value) {
|
||||
|
||||
return map.containsValue(value);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a collection view of the mappings contained in this map. Each
|
||||
* element in the returned collection is a <code>Map.Entry</code>.
|
||||
*/
|
||||
public Set entrySet() {
|
||||
|
||||
return map.entrySet();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare the specified object with this list for equality. This
|
||||
* implementation uses exactly the code that is used to define the
|
||||
* list equals function in the documentation for the
|
||||
* <code>Map.equals</code> method.
|
||||
*
|
||||
* @param o Object to be compared to this list
|
||||
*/
|
||||
public boolean equals(Object o) {
|
||||
|
||||
// Simple tests that require no synchronization
|
||||
if (o == this)
|
||||
return true;
|
||||
else if ( !(o instanceof Map) )
|
||||
return false;
|
||||
Map mo = (Map) o;
|
||||
|
||||
// Compare the two maps for equality
|
||||
|
||||
if ( mo.size() != map.size() )
|
||||
return false;
|
||||
java.util.Iterator i = map.entrySet().iterator();
|
||||
while ( i.hasNext() ) {
|
||||
Map.Entry e = (Map.Entry) i.next();
|
||||
Object key = e.getKey();
|
||||
Object value = e.getValue();
|
||||
if (value == null) {
|
||||
if ( !( mo.get(key) == null && mo.containsKey(key) ) )
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
if ( !value.equals( mo.get(key) ) )
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value to which this map maps the specified key. Returns
|
||||
* <code>null</code> if the map contains no mapping for this key, or if
|
||||
* there is a mapping with a value of <code>null</code>. Use the
|
||||
* <code>containsKey()</code> method to disambiguate these cases.
|
||||
*
|
||||
* @param key Key whose value is to be returned
|
||||
*/
|
||||
public Object get(Object key) {
|
||||
|
||||
return map.get(key);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the hash code value for this map. This implementation uses
|
||||
* exactly the code that is used to define the list hash function in the
|
||||
* documentation for the <code>Map.hashCode</code> method.
|
||||
*/
|
||||
public int hashCode() {
|
||||
|
||||
int h = 0;
|
||||
java.util.Iterator i = map.entrySet().iterator();
|
||||
while ( i.hasNext() )
|
||||
h += i.next().hashCode();
|
||||
return h;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return <code>true</code> if this map contains no mappings.
|
||||
*/
|
||||
public boolean isEmpty() {
|
||||
|
||||
return map.isEmpty();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a set view of the keys contained in this map.
|
||||
*/
|
||||
public Set keySet() {
|
||||
|
||||
return map.keySet();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Associate the specified value with the specified key in this map.
|
||||
* If the map previously contained a mapping for this key, the old
|
||||
* value is replaced and returned.
|
||||
*
|
||||
* @param key The key with which the value is to be associated
|
||||
* @param value The value to be associated with this key
|
||||
*/
|
||||
public Object put(Object key, Object value) {
|
||||
|
||||
synchronized (this) {
|
||||
HashMap temp = (HashMap) map.clone();
|
||||
Object result = temp.put(key, value);
|
||||
map = temp;
|
||||
return (result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy all of the mappings from the specified map to this one, replacing
|
||||
* any mappings with the same keys.
|
||||
*
|
||||
* @param in Map whose mappings are to be copied
|
||||
*/
|
||||
public void putAll(Map in) {
|
||||
|
||||
synchronized (this) {
|
||||
HashMap temp = (HashMap) map.clone();
|
||||
temp.putAll(in);
|
||||
map = temp;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove any mapping for this key, and return any previously
|
||||
* mapped value.
|
||||
*
|
||||
* @param key Key whose mapping is to be removed
|
||||
*/
|
||||
public Object remove(Object key) {
|
||||
|
||||
synchronized (this) {
|
||||
HashMap temp = (HashMap) map.clone();
|
||||
Object result = temp.remove(key);
|
||||
map = temp;
|
||||
return (result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of key-value mappings in this map.
|
||||
*/
|
||||
public int size() {
|
||||
|
||||
return map.size();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a collection view of the values contained in this map.
|
||||
*/
|
||||
public Collection values() {
|
||||
|
||||
return map.values();
|
||||
|
||||
}
|
||||
|
||||
public String toString() { return map.toString(); }
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue