openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Dick <michael.d.d...@gmail.com>
Subject Re: svn commit: r817815 - /openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbeddable.java
Date Tue, 22 Sep 2009 20:33:46 GMT
Why do we need to regenerate the tables for this testcase? I'd guess that
two entities with different mappings use the same table name, but if that's
the case couldn't we just change the name for one of the entities?

-mike

On Tue, Sep 22, 2009 at 3:15 PM, <jrbauer@apache.org> wrote:

> Author: jrbauer
> Date: Tue Sep 22 20:15:07 2009
> New Revision: 817815
>
> URL: http://svn.apache.org/viewvc?rev=817815&view=rev
> Log:
> Updated test code to use mapping tool to regenerate subset of DB artifacts
> if running on Oracle.  This will create the triggers required to support
> generated identity columns.
>
> Modified:
>
>  openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbeddable.java
>
> Modified:
> openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbeddable.java
> URL:
> http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbeddable.java?rev=817815&r1=817814&r2=817815&view=diff
>
> ==============================================================================
> ---
> openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbeddable.java
> (original)
> +++
> openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbeddable.java
> Tue Sep 22 20:15:07 2009
> @@ -18,6 +18,8 @@
>  */
>  package org.apache.openjpa.persistence.embed;
>
> +import java.io.IOException;
> +import java.sql.SQLException;
>  import java.sql.Timestamp;
>  import java.util.Calendar;
>  import java.util.Collection;
> @@ -33,14 +35,14 @@
>  import javax.persistence.EntityTransaction;
>  import javax.persistence.Query;
>
> -
>  import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
> +import org.apache.openjpa.jdbc.meta.MappingTool;
> +import org.apache.openjpa.jdbc.meta.MappingTool.Flags;
>  import org.apache.openjpa.jdbc.sql.DBDictionary;
>  import org.apache.openjpa.jdbc.sql.OracleDictionary;
> -import org.apache.openjpa.lib.log.Log;
>  import org.apache.openjpa.persistence.ArgumentException;
> +import org.apache.openjpa.persistence.OpenJPAEntityManagerSPI;
>  import org.apache.openjpa.persistence.test.SQLListenerTestCase;
> -import org.apache.openjpa.persistence.test.SingleEMFTestCase;
>
>  public class TestEmbeddable extends SQLListenerTestCase {
>     private static final Calendar cal = new GregorianCalendar();
> @@ -197,7 +199,8 @@
>         updateEntityA_Embed_MappedToOneCascadeDelete();
>     }
>
> -    public void testEmbeddableContainingRelationWithGeneratedKey() {
> +    public void testEmbeddableContainingRelationWithGeneratedKey()
> +        throws IOException, SQLException {
>         createEmbeddableContainingRelationWithGeneratedKey();
>     }
>
> @@ -2567,8 +2570,20 @@
>         em.close();
>     }
>
> -    public void createEmbeddableContainingRelationWithGeneratedKey() {
> +    /**
> +     * To run this method on Oracle requires the user to have the
> authority
> +     * to create triggers.  ex.  GRANT CREATE TRIGGER TO "SCOTT"
> +     */
> +    public void createEmbeddableContainingRelationWithGeneratedKey()
> +        throws IOException, SQLException {
>         EntityManager em = emf.createEntityManager();
> +
> +        OpenJPAEntityManagerSPI ojem = (OpenJPAEntityManagerSPI)em;
> +        JDBCConfiguration conf = (JDBCConfiguration)
> ojem.getConfiguration();
> +        DBDictionary dict = conf.getDBDictionaryInstance();
> +        if (dict instanceof OracleDictionary) {
> +            recreateOracleArtifacts((OracleDictionary)dict, conf);
> +        }
>         EntityTransaction tran = em.getTransaction();
>
>         Book b = new Book(1590596455);
> @@ -2593,6 +2608,27 @@
>     }
>
>     /*
> +     * This method uses the mapping tool to regenerate Oracle db artifacts
> +     * with the useTriggersForAutoAssign db option enabled.
> +     */
> +    private void recreateOracleArtifacts(OracleDictionary dict,
> +        JDBCConfiguration conf) throws IOException, SQLException {
> +        dict.useTriggersForAutoAssign = true;
> +        Flags flags = new MappingTool.Flags();
> +        flags.dropTables = true;
> +        flags.schemaAction = "drop,add";
> +        flags.sequences = true;
> +        flags.ignoreErrors = true;
> +        flags.dropSequences = true;
> +        MappingTool.run(
> +            conf,
> +            new String[] { "org.apache.openjpa.persistence.embed.Book" },
> +            flags,
> +            conf.getClassResolverInstance().
> +            getClassLoader(MappingTool.class, null));
> +    }
> +
> +    /*
>      * EntityA_Embed_Complex routines
>      */
>     public void testEntityA_Embed_Complex() {
>
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message