You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by Miłosz Tylenda <mt...@o2.pl> on 2009/02/03 11:49:25 UTC

Revision 736066 of TestMultipleSchemaNames

Hi Mike,

I am afraid that this change (removing try/catch) will prevent running the test (at least the first method) on PostgreSQL more than once. PostgreSQL needs explicit schema creation and the try/catch code was the easiest way I could find to handle the case when schemas are already created. Let me know if you think this should be done in another way.

Also, the closing of emf at the bottom of the method should rather stay as before as the emf is not used outside of the method.

This schema creation stuff was added to harness a bug concerning autoincrement columns in PostgreSQL. The diff follows.

Greetings,
Milosz

--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestMultipleSchemaNames.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestMultipleSchemaNames.java Tue Jan 20 11:01:50 2009
@@ -417,19 +417,11 @@
         String[] schemas =
             { "SCHEMA1", "SCHEMA2", "SCHEMA3", "SCHEMA3G", "SCHEMA4G" };
         for (String schema : schemas) {
-            try {
-                em.getTransaction().begin();
-                Query q = em.createNativeQuery("create schema " + schema);
-                q.executeUpdate();
-                em.getTransaction().commit();
-            } catch (PersistenceException e) {
-                System.err.println("Exception caught while creating schema "
-                    + schema + ". Schema already exists? Message: "
-                    + e.getMessage());
-                em.getTransaction().rollback();
-            }
+            em.getTransaction().begin();
+            Query q = em.createNativeQuery("create schema " + schema);
+            q.executeUpdate();
+            em.getTransaction().commit();
         }
-        closeEMF(emf);
     } 

Re: Revision 736066 of TestMultipleSchemaNames

Posted by Michael Dick <mi...@gmail.com>.
Hi Milosz,

Sorry about that (obviously) I didn't run that change on PostGres and I
missed the comments. For now I'm going to just remove the
System.err.println. Alternatively we could catch and re-throw the exception
after cleaning up.

Just running a sanity check build before committing.


On Tue, Feb 3, 2009 at 4:49 AM, Miłosz Tylenda <mt...@o2.pl> wrote:

> Hi Mike,
>
> I am afraid that this change (removing try/catch) will prevent running the
> test (at least the first method) on PostgreSQL more than once. PostgreSQL
> needs explicit schema creation and the try/catch code was the easiest way I
> could find to handle the case when schemas are already created. Let me know
> if you think this should be done in another way.
>
> Also, the closing of emf at the bottom of the method should rather stay as
> before as the emf is not used outside of the method.
>
> This schema creation stuff was added to harness a bug concerning
> autoincrement columns in PostgreSQL. The diff follows.
>
> Greetings,
> Milosz
>
> ---
> openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestMultipleSchemaNames.java
> (original)
> +++
> openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestMultipleSchemaNames.java
> Tue Jan 20 11:01:50 2009
> @@ -417,19 +417,11 @@
>         String[] schemas =
>             { "SCHEMA1", "SCHEMA2", "SCHEMA3", "SCHEMA3G", "SCHEMA4G" };
>         for (String schema : schemas) {
> -            try {
> -                em.getTransaction().begin();
> -                Query q = em.createNativeQuery("create schema " + schema);
> -                q.executeUpdate();
> -                em.getTransaction().commit();
> -            } catch (PersistenceException e) {
> -                System.err.println("Exception caught while creating schema
> "
> -                    + schema + ". Schema already exists? Message: "
> -                    + e.getMessage());
> -                em.getTransaction().rollback();
> -            }
> +            em.getTransaction().begin();
> +            Query q = em.createNativeQuery("create schema " + schema);
> +            q.executeUpdate();
> +            em.getTransaction().commit();
>         }
> -        closeEMF(emf);
>     }
>