Author: struberg Date: Fri Oct 25 07:13:13 2013 New Revision: 1535648 URL: http://svn.apache.org/r1535648 Log: OPENJPA-2444 fix default orm.xml location for ReverseMappingTool
I also fixed the badly formatted and partly broken TestUseSchemaElement. Modified: openjpa/trunk/ (props changed) openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestUseSchemaElement.java openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataFactory.java Propchange: openjpa/trunk/ ------------------------------------------------------------------------------ Merged /openjpa/branches/2.3.x:r1535560 Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestUseSchemaElement.java URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestUseSchemaElement.java?rev=1535648&r1=1535647&r2=1535648&view=diff ============================================================================== --- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestUseSchemaElement.java (original) +++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestUseSchemaElement.java Fri Oct 25 07:13:13 2013 @@ -20,15 +20,11 @@ package org.apache.openjpa.persistence.j import java.io.File; import java.io.FileNotFoundException; -import java.io.IOException; -import java.sql.SQLException; import java.util.Scanner; import javax.persistence.EntityManager; import javax.persistence.Query; -import junit.textui.TestRunner; - import org.apache.openjpa.jdbc.conf.JDBCConfiguration; import org.apache.openjpa.jdbc.meta.ReverseMappingTool; import org.apache.openjpa.lib.util.Files; @@ -38,112 +34,112 @@ import org.apache.openjpa.persistence.te /** * Tests the added useSchemaElement functionality of the * ReverseMappingTool and CodeGenerator classes. - * + * * @author Austin Dorenkamp (ajdorenk) */ public class TestUseSchemaElement extends /*TestCase*/ SingleEMFTestCase { - - public void setUp() throws Exception { - super.setUp(); - File f = new File("./orm.xml"); - - // Make sure to clean up orm.xml from a prior run - if (f.exists()) { - assertTrue(f.delete()); - } - setSupportedDatabases(org.apache.openjpa.jdbc.sql.DerbyDictionary.class); - } - - @Override - public String getPersistenceUnitName(){ - return "rev-mapping-pu"; - } - - public void testGettersAndSetters() { - - JDBCConfiguration conf = (JDBCConfiguration) ((OpenJPAEntityManagerFactory) emf).getConfiguration(); - - EntityManager em = emf.createEntityManager(); - - em.getTransaction().begin(); - - Query q = em.createNativeQuery("CREATE TABLE USCHEMA.USCHANTBL (ID INTEGER PRIMARY KEY)"); - try { - q.executeUpdate(); - em.getTransaction().commit(); - } catch (Throwable t) { - em.getTransaction().rollback(); - System.out.println(t.toString()); - } - - try { - ReverseMappingTool.Flags flags = new ReverseMappingTool.Flags(); - flags.metaDataLevel = "package"; - flags.generateAnnotations = true; - flags.accessType = "property"; - flags.nullableAsObject = true; - flags.useSchemaName = false; - flags.useSchemaElement = false; - flags.packageName = ""; - flags.directory = Files.getFile("./target", null); - ReverseMappingTool.run(conf, new String[0], flags, null); - } catch (IOException e) { - e.printStackTrace(); - } catch (SQLException e) { - e.printStackTrace(); - } catch (Throwable t) { - t.printStackTrace(); - } - - /* Now that the tool has been run, we will test it by reading the generated files */ - - // This tests the removal of the schema annotation in the Uschantbl.java file - File uschantbl = new File("./target/Uschantbl.java"); - Scanner inFile = new Scanner(""); - String currentLine; - try { - inFile = new Scanner(uschantbl); - } catch (FileNotFoundException e) { - fail("Uschantbl.java not generated in ./target by ReverseMappingTool"); - } - while(inFile.hasNextLine()) - { - currentLine = inFile.nextLine(); - if((currentLine.length()) > 0 && (currentLine.charAt(0) != '@')) - { - continue; - } - - if(currentLine.contains("Table(schema=")) - { - fail("Uschantbl.java still contains schema name"); - } - } - inFile.close(); - // Delete file to clean up workspace - assertTrue(uschantbl.delete()); - - // This tests the removal of the schema name from the orm.xml file - File orm = new File("./orm.xml"); - try { - inFile = new Scanner(orm); - } catch (FileNotFoundException e) { - fail("Orm.xml not generated in root directory by ReverseMappingTool"); - } - while(inFile.hasNextLine()) - { - if(inFile.nextLine().contains("<table schema=")) - { - fail("Orm.xml still contains schema name"); - } - } - inFile.close(); - // Delete file to clean up workspace. Also, test will break with - // org.apache.openjpa.util.UserException if orm.xml exists prior to running -// assertTrue(orm.delete()); - } - - public static void main(String[] args) { - TestRunner.run(TestUseSchemaElement.class); - } + + public void setUp() throws Exception { + super.setUp(); + File f = new File("./orm.xml"); + + // Make sure to clean up orm.xml from a prior run + if (f.exists()) { + assertTrue(f.delete()); + } + setSupportedDatabases(org.apache.openjpa.jdbc.sql.DerbyDictionary.class); + } + + @Override + public String getPersistenceUnitName(){ + return "rev-mapping-pu"; + } + + public void testGettersAndSetters() throws Exception { + + JDBCConfiguration conf = (JDBCConfiguration) ((OpenJPAEntityManagerFactory) emf).getConfiguration(); + + EntityManager em = emf.createEntityManager(); + + em.getTransaction().begin(); + + Query q = em.createNativeQuery("CREATE TABLE USCHEMA.USCHANTBL (ID INTEGER PRIMARY KEY)"); + try { + q.executeUpdate(); + em.getTransaction().commit(); + } catch (Throwable t) { + em.getTransaction().rollback(); + System.out.println(t.toString()); + } + + ReverseMappingTool.Flags flags = new ReverseMappingTool.Flags(); + flags.metaDataLevel = "package"; + flags.generateAnnotations = true; + flags.accessType = "property"; + flags.nullableAsObject = true; + flags.useSchemaName = false; + flags.useSchemaElement = false; + flags.packageName = ""; + flags.directory = Files.getFile("./target", null); + ReverseMappingTool.run(conf, new String[0], flags, null); + + /* Now that the tool has been run, we will test it by reading the generated files */ + + // This tests the removal of the schema annotation in the Uschantbl.java file + File uschantbl = new File("./target/Uschantbl.java"); + Scanner inFile = null; + String currentLine; + try { + inFile = new Scanner(uschantbl); + + while(inFile.hasNextLine()) + { + currentLine = inFile.nextLine(); + if((currentLine.length()) > 0 && (currentLine.charAt(0) != '@')) + { + continue; + } + + if(currentLine.contains("Table(schema=")) + { + fail("Uschantbl.java still contains schema name"); + } + } + + // Delete file to clean up workspace + assertTrue(uschantbl.delete()); + + } catch (FileNotFoundException e) { + fail("Uschantbl.java not generated in ./target by ReverseMappingTool"); + } + finally { + if (inFile != null) { + inFile.close(); + } + } + + // This tests the removal of the schema name from the orm.xml file + File orm = new File("target/orm.xml"); + try { + inFile = new Scanner(orm); + while(inFile.hasNextLine()) + { + if(inFile.nextLine().contains("<table schema=")) + { + fail("Orm.xml still contains schema name"); + } + } + } catch (FileNotFoundException e) { + fail("Orm.xml not generated in root directory by ReverseMappingTool"); + } + finally { + if (inFile != null) { + inFile.close(); + } + } + // Delete file to clean up workspace. Also, test will break with + // org.apache.openjpa.util.UserException if orm.xml exists prior to running + //assertTrue(orm.delete()); + } + } Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataFactory.java URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataFactory.java?rev=1535648&r1=1535647&r2=1535648&view=diff ============================================================================== --- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataFactory.java (original) +++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataFactory.java Fri Oct 25 07:13:13 2013 @@ -521,7 +521,7 @@ public class PersistenceMetaDataFactory J2DoPrivHelper.existsAction(file))).booleanValue()) return file; } - return new File("orm.xml"); + return new File(dir, "orm.xml"); } public void setConfiguration(Configuration conf) {