JDOHelper patch
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Web Servers reviews > Apache Server configuration support > Apache JDO Project > JDOHelper patch




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    JDOHelper patch  
erik@jpox.org


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-16-05 10:45 PM

Hi,

There are two issues in JDOHelper.getPersistenceManagerFactory

1 - the JDOHelper.getPMF raises will raise an exception if there is no
getPMF(Properties) or getPMF(Map) in the implementation. The exception for t
he
properties method is not raised, but in its place the exception for the map
method.

2 - a try catch block is hidding JDOExceptions.

Here is the patch:

Index: C:/trunck/api20/test/java/javax/jdo/JDOHelperTest.java
 ========================================
===========================
--- C:/trunck/api20/test/java/javax/jdo/JDOHelperTest.java	(revision 219338)
+++ C:/trunck/api20/test/java/javax/jdo/JDOHelperTest.java	(working copy)
@@ -18,14 +18,14 @@

import java.io.File;
import java.io.InputStream;
-
+import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import javax.jdo.pc.PCPoint;
+import javax.jdo.spi.I18NHelper;
import javax.jdo.util.AbstractTest;
import javax.jdo.util.BatchTestRunner;
-
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
@@ -38,6 +38,9 @@
* TBD: getPMF for valid PMF class
*/
public class JDOHelperTest extends AbstractTest {
+    /** The Internationalization message helper.
+     */
+    private final static I18NHelper msg = I18NHelper.getInstance
("javax.jdo.Bundle"); //NOI18N

/** */
public static void main(String args[]) {
@@ -130,6 +133,7 @@
// TBD test JDOHelper.isDeleted(pc) for persistent instance
}

+
/** Test null String resource with no class loader.
*/
public void testGetPMFNullResource() {
@@ -401,7 +405,21 @@
catch (JDOFatalInternalException ex) {
if (verbose)
println("Caught expected exception " + ex);
+            assertEquals(msg.msg("EXC_GetPMFNoSuchMethod"),ex.getMessage())
;
}
+        Map map = new HashMap();
+        map.put("javax.jdo.PersistenceManagerFactoryClass",
+                "javax.jdo.JDOHelperTest$BadPMFNoGetPMFMethod");
+        try {
+            pmf = JDOHelper.getPersistenceManagerFactory(map);
+            fail("Bad PersistenceManagerFactoryClass should result in
JDOFatalUserException ");
+        }
+        catch (JDOFatalInternalException ex) {
+            if (verbose)
+                println("Caught expected exception " + ex);
+            assertEquals(msg.msg("EXC_GetPMFNoSuchMethod"),ex.getMessage())
;
+        }
+
}

/** Test bad PMF class non-static getPMF method.
Index: C:/trunck/api20/src/java/javax/jdo/JDOHelper.java
 ========================================
===========================
--- C:/trunck/api20/src/java/javax/jdo/JDOHelper.java	(revision 219338)
+++ C:/trunck/api20/src/java/javax/jdo/JDOHelper.java	(working copy)
@@ -24,26 +24,21 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
-import java.io.InputStream;
import java.io.IOException;
-
-import java.lang.reflect.Method;
+import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
-
+import java.lang.reflect.Method;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
import java.util.Map;
import java.util.Properties;

-import java.security.AccessController;
-import java.security.PrivilegedAction;
-
import javax.jdo.spi.I18NHelper;
import javax.jdo.spi.PersistenceCapable;
-import javax.jdo.spi.StateManager; // for javadoc
-
+import javax.jdo.spi.StateManager;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
-
import javax.rmi.PortableRemoteObject;


@@ -338,7 +333,7 @@
} else if (propsMethod != null) {
pmfMethod = propsMethod;
} else {
-                    throw mapGetMethodException;
+                    throw propsGetMethodException;
}
}
return (PersistenceManagerFactory) pmfMethod.invoke (null, new
Object[] {props});
@@ -357,6 +352,8 @@
throw new JDOFatalInternalException
(msg.msg("EXC_GetPMFNullPointerException", pmfClassName), e); //NOI18N
} catch (ClassCastException e) {
throw new JDOFatalInternalException
(msg.msg("EXC_GetPMFClassCastException", pmfClassName), e); //NOI18N
+        } catch (JDOException jdoex) {
+            throw jdoex;
} catch (Exception e) {
throw new JDOFatalInternalException
(msg.msg("EXC_GetPMFUnexpectedException"), e); //NOI18N
}







[ Post a follow-up to this message ]



    Re: JDOHelper patch  
Craig Russell


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-16-05 10:45 PM






[ Post a follow-up to this message ]



    Re: JDOHelper patch  
erik@jpox.org


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-17-05 12:45 PM

Quoting Craig Russell <Craig.Russell@Sun.COM>:

> This exception is not thrown by Method.invoke. It will be caught by
> the catch (InvocationTargetException). Reflective invocation wraps
> all exceptions in InvocationTargetException which we then unwrap and
> rethrow JDOExceptions.
>
> I've added a new test case in JDOHelperTest to test that a
> JDOException thrown from getPersistenceManagerFactory will be thrown
> to the user.
>

When the mapGetMethodException is thrown, it is inside the try catch block
catching java.lang.Exception. The JDOException catch there fixes it.







[ Post a follow-up to this message ]



    Re: JDOHelper patch  
Craig Russell


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-17-05 10:45 PM






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 08:49 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register