You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jdo-commits@db.apache.org by cl...@apache.org on 2005/08/11 18:14:01 UTC
svn commit: r231477 -
/incubator/jdo/trunk/api20/src/java/javax/jdo/spi/JDOImplHelper.java
Author: clr
Date: Thu Aug 11 09:13:57 2005
New Revision: 231477
URL: http://svn.apache.org/viewcvs?rev=231477&view=rev
Log:
Made construct(String, String) static; fixed synchronization bug in addStringConstructor
Modified:
incubator/jdo/trunk/api20/src/java/javax/jdo/spi/JDOImplHelper.java
Modified: incubator/jdo/trunk/api20/src/java/javax/jdo/spi/JDOImplHelper.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api20/src/java/javax/jdo/spi/JDOImplHelper.java?rev=231477&r1=231476&r2=231477&view=diff
==============================================================================
--- incubator/jdo/trunk/api20/src/java/javax/jdo/spi/JDOImplHelper.java (original)
+++ incubator/jdo/trunk/api20/src/java/javax/jdo/spi/JDOImplHelper.java Thu Aug 11 09:13:57 2005
@@ -552,7 +552,9 @@
* @return the previous StringConstructor registered for this class
*/
public Object registerStringConstructor(Class cls, StringConstructor sc) {
- return stringConstructorMap.put(cls, sc);
+ synchronized(stringConstructorMap) {
+ return stringConstructorMap.put(cls, sc);
+ }
}
/** Register the default special StringConstructor instances.
@@ -648,31 +650,32 @@
* @param keyString the String parameter for the constructor
* @return the result of construction
*/
- public Object construct(String className, String keyString) {
- synchronized(stringConstructorMap) {
- try {
- Class keyClass = Class.forName(className);
- StringConstructor stringConstructor =
+ public static Object construct(String className, String keyString) {
+ StringConstructor stringConstructor;
+ try {
+ Class keyClass = Class.forName(className);
+ synchronized(stringConstructorMap) {
+ stringConstructor =
(StringConstructor) stringConstructorMap.get(keyClass);
- if (stringConstructor == null) {
- Constructor keyConstructor =
- keyClass.getConstructor(new Class[]{String.class});
- return keyConstructor.newInstance(new Object[]{keyString});
- } else {
- return stringConstructor.construct(keyString);
- }
- } catch (JDOException ex) {
- throw ex;
- } catch (Exception ex) {
- /* ClassNotFoundException,
- NoSuchMethodException,
- InstantiationException,
- IllegalAccessException,
- InvocationTargetException */
- throw new JDOUserException(
- msg.msg("EXC_ObjectIdentityStringConstruction", //NOI18N
- new Object[] {ex.toString(), className, keyString}), ex);
}
+ if (stringConstructor != null) {
+ return stringConstructor.construct(keyString);
+ } else {
+ Constructor keyConstructor =
+ keyClass.getConstructor(new Class[]{String.class});
+ return keyConstructor.newInstance(new Object[]{keyString});
+ }
+ } catch (JDOException ex) {
+ throw ex;
+ } catch (Exception ex) {
+ /* ClassNotFoundException,
+ NoSuchMethodException,
+ InstantiationException,
+ IllegalAccessException,
+ InvocationTargetException */
+ throw new JDOUserException(
+ msg.msg("EXC_ObjectIdentityStringConstruction", //NOI18N
+ new Object[] {ex.toString(), className, keyString}), ex);
}
}