Author: struberg
Date: Thu Oct 24 21:31:58 2013
New Revision: 1535560
URL: http://svn.apache.org/r1535560
Log:
OPENJPA-2444 fix default orm.xml location for ReverseMappingTool
I also fixed the badly formatted and partly broken TestUseSchemaElement.
Modified:
openjpa/branches/2.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestUseSchemaElement.java
openjpa/branches/2.3.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataFactory.java
Modified:
openjpa/branches/2.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestUseSchemaElement.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/2.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestUseSchemaElement.java?rev=1535560&r1=1535559&r2=1535560&view=diff
==============================================================================
---
openjpa/branches/2.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestUseSchemaElement.java
(original)
+++
openjpa/branches/2.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestUseSchemaElement.java
Thu Oct 24 21:31:58 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,106 +34,106 @@ 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();
-
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();
+
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("./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/branches/2.3.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataFactory.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/2.3.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataFactory.java?rev=1535560&r1=1535559&r2=1535560&view=diff
==============================================================================
---
openjpa/branches/2.3.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataFactory.java
(original)
+++
openjpa/branches/2.3.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataFactory.java
Thu Oct 24 21:31:58 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) {