Author: stliu
Date: 2010-06-22 12:18:14 -0400 (Tue, 22 Jun 2010)
New Revision: 19780
Modified:
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/impl/SessionFactoryObjectFactory.java
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/tuple/EntityModeToTuplizerMapping.java
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/tuple/component/ComponentTuplizerFactory.java
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/tuple/entity/EntityTuplizerFactory.java
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/util/FastHashMap.java
Log:
JBPAPP-4512 HHH-3050 Convert usage of Hibernate's FastHashMap to ConcurrentHashMap
Modified:
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/impl/SessionFactoryObjectFactory.java
===================================================================
---
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/impl/SessionFactoryObjectFactory.java 2010-06-22
16:00:31 UTC (rev 19779)
+++
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/impl/SessionFactoryObjectFactory.java 2010-06-22
16:18:14 UTC (rev 19780)
@@ -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 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.
+ * distributed under license by Red Hat 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
@@ -27,6 +27,7 @@
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;
@@ -41,7 +42,6 @@
import javax.naming.spi.ObjectFactory;
import org.hibernate.SessionFactory;
-import org.hibernate.util.FastHashMap;
import org.hibernate.util.NamingHelper;
import org.slf4j.Logger;
@@ -62,8 +62,8 @@
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) {
Modified:
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/tuple/EntityModeToTuplizerMapping.java
===================================================================
---
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/tuple/EntityModeToTuplizerMapping.java 2010-06-22
16:00:31 UTC (rev 19779)
+++
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/tuple/EntityModeToTuplizerMapping.java 2010-06-22
16:18:14 UTC (rev 19780)
@@ -30,7 +30,7 @@
import org.hibernate.EntityMode;
import org.hibernate.HibernateException;
-import org.hibernate.util.FastHashMap;
+import java.util.concurrent.ConcurrentHashMap;
/**
* Centralizes handling of {@link EntityMode} to {@link Tuplizer} mappings.
@@ -40,10 +40,10 @@
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>();
}
public EntityModeToTuplizerMapping(Map tuplizers) {
@@ -70,12 +70,9 @@
* @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 +86,7 @@
* @return The tuplizer, or null if not found.
*/
public Tuplizer getTuplizerOrNull(EntityMode entityMode) {
- return ( Tuplizer ) tuplizers.get( entityMode );
+ return tuplizers.get( entityMode );
}
/**
Modified:
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/tuple/component/ComponentTuplizerFactory.java
===================================================================
---
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/tuple/component/ComponentTuplizerFactory.java 2010-06-22
16:00:31 UTC (rev 19779)
+++
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/tuple/component/ComponentTuplizerFactory.java 2010-06-22
16:18:14 UTC (rev 19780)
@@ -25,10 +25,10 @@
package org.hibernate.tuple.component;
import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
import java.lang.reflect.Constructor;
import java.io.Serializable;
-import org.hibernate.util.FastHashMap;
import org.hibernate.util.ReflectHelper;
import org.hibernate.EntityMode;
import org.hibernate.HibernateException;
@@ -43,15 +43,14 @@
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.
*
* @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
ComponentTuplizer> tuplizerClass) {
assert isComponentTuplizerImplementor( tuplizerClass )
: "Specified tuplizer class [" + tuplizerClass.getName() + "] does not
implement " + ComponentTuplizer.class.getName();
assert hasProperConstructor( tuplizerClass )
@@ -73,7 +72,7 @@
*/
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 +90,11 @@
*
* @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 +113,7 @@
* {@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 + "]" );
}
@@ -130,28 +129,28 @@
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 );
Modified:
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/tuple/entity/EntityTuplizerFactory.java
===================================================================
---
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/tuple/entity/EntityTuplizerFactory.java 2010-06-22
16:00:31 UTC (rev 19779)
+++
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/tuple/entity/EntityTuplizerFactory.java 2010-06-22
16:18:14 UTC (rev 19780)
@@ -25,11 +25,10 @@
package org.hibernate.tuple.entity;
import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
import java.lang.reflect.Constructor;
import java.io.Serializable;
-
-import org.hibernate.util.FastHashMap;
import org.hibernate.util.ReflectHelper;
import org.hibernate.EntityMode;
import org.hibernate.HibernateException;
@@ -44,7 +43,7 @@
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 +51,7 @@
* @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 )
@@ -78,7 +77,7 @@
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 +97,13 @@
* @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 +126,7 @@
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 +138,33 @@
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 );
+ 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 );
Modified:
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/util/FastHashMap.java
===================================================================
---
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/util/FastHashMap.java 2010-06-22
16:00:31 UTC (rev 19779)
+++
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/util/FastHashMap.java 2010-06-22
16:18:14 UTC (rev 19780)
@@ -51,7 +51,7 @@
* maximum performance.</p>
*
*/
-
+@Deprecated
public final class FastHashMap implements Map, Serializable {
// ----------------------------------------------------------- Constructors