From d2c748d1094f295243c7a3b9efe2b937d8bc9b0b Mon Sep 17 00:00:00 2001 From: Patrick Linskey Date: Tue, 6 Mar 2007 23:57:29 +0000 Subject: [PATCH] OPENJPA-121: Table name defaults to the class name instead of the entity name. The key change is in PersistenceMappingDefaults; other changes include a new test case and removal of spurious @Table annotations from previous workaround. git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@515375 13f79535-47bb-0310-9956-ffa450edef68 --- .../jdbc/PersistenceMappingDefaults.java | 6 ++- .../kernel/TestQueryCompilationCache.java | 4 +- .../models/company/basic/Address.java | 1 - .../models/company/basic/Company.java | 1 - .../models/company/basic/LineItem.java | 1 - .../models/company/basic/Person.java | 1 - .../models/company/basic/Product.java | 1 - .../models/company/basic/ProductOrder.java | 1 - .../models/company/fetchlazy/Address.java | 1 - .../models/company/fetchlazy/Company.java | 1 - .../models/company/fetchlazy/LineItem.java | 1 - .../models/company/fetchlazy/Person.java | 1 - .../models/company/fetchlazy/Product.java | 1 - .../company/fetchlazy/ProductOrder.java | 1 - .../models/company/idclass/Address.java | 1 - .../models/company/idclass/Company.java | 1 - .../models/company/idclass/LineItem.java | 1 - .../models/company/idclass/Person.java | 1 - .../models/company/idclass/Product.java | 1 - .../models/company/idclass/ProductOrder.java | 1 - .../models/company/joined/Address.java | 1 - .../models/company/joined/Company.java | 1 - .../models/company/joined/Customer.java | 1 - .../models/company/joined/Employee.java | 1 - .../company/joined/FullTimeEmployee.java | 1 - .../models/company/joined/LineItem.java | 1 - .../company/joined/PartTimeEmployee.java | 1 - .../models/company/joined/Person.java | 1 - .../models/company/joined/Product.java | 1 - .../models/company/joined/ProductOrder.java | 1 - .../query/TestAbstractSchemaName.java | 1 + .../{query => simple}/NamedEntity.java | 2 +- .../TestTableNamesDefaultToEntityNames.java | 20 ++++++++++ .../persistence/test/PersistenceTestCase.java | 39 +++++++++++++++++++ 34 files changed, 68 insertions(+), 32 deletions(-) rename openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/{query => simple}/NamedEntity.java (92%) create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestTableNamesDefaultToEntityNames.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/PersistenceTestCase.java diff --git a/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/PersistenceMappingDefaults.java b/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/PersistenceMappingDefaults.java index ded3d6f74..913f46d1a 100644 --- a/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/PersistenceMappingDefaults.java +++ b/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/PersistenceMappingDefaults.java @@ -114,7 +114,11 @@ public class PersistenceMappingDefaults @Override public String getTableName(ClassMapping cls, Schema schema) { - return Strings.getClassName(cls.getDescribedType()).replace('$', '_'); + if (cls.getTypeAlias() != null) + return cls.getTypeAlias(); + else + return Strings.getClassName( + cls.getDescribedType()).replace('$', '_'); } @Override diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/kernel/TestQueryCompilationCache.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/kernel/TestQueryCompilationCache.java index c949dd07e..4cf6bb63f 100755 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/kernel/TestQueryCompilationCache.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/kernel/TestQueryCompilationCache.java @@ -26,7 +26,7 @@ import org.apache.openjpa.persistence.OpenJPAEntityManager; import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory; import org.apache.openjpa.persistence.OpenJPAPersistence; import org.apache.openjpa.persistence.OpenJPAQuery; -import org.apache.openjpa.persistence.query.NamedEntity; +import org.apache.openjpa.persistence.simple.NamedEntity; import junit.framework.TestCase; @@ -53,7 +53,7 @@ public class TestQueryCompilationCache // dig into the entry and check its internal state Compilation comp = (Compilation) cache.values().iterator().next(); - assertEquals(NamedEntity.class, + assertEquals(NamedEntity.class, ((ParsedJPQL) comp.storeData).getCandidateType()); emf.close(); diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/basic/Address.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/basic/Address.java index 6aaa77017..95f89a802 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/basic/Address.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/basic/Address.java @@ -19,7 +19,6 @@ import javax.persistence.*; import org.apache.openjpa.persistence.models.company.*; @Entity(name="BAS_Address") -@Table(name="BAS_Address") // OPENJPA-121 public class Address implements IAddress { private static long idCounter = System.currentTimeMillis(); diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/basic/Company.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/basic/Company.java index 06d8e8cab..2f91f706f 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/basic/Company.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/basic/Company.java @@ -20,7 +20,6 @@ import javax.persistence.*; import org.apache.openjpa.persistence.models.company.*; @Entity(name="BAS_Company") -@Table(name="BAS_Company") // OPENJPA-121 public class Company implements ICompany { private static long idCounter = System.currentTimeMillis(); diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/basic/LineItem.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/basic/LineItem.java index b17506b4c..041f31bda 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/basic/LineItem.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/basic/LineItem.java @@ -19,7 +19,6 @@ import javax.persistence.*; import org.apache.openjpa.persistence.models.company.*; @Entity(name="BAS_LineItem") -@Table(name="BAS_LineItem") // OPENJPA-121 public class LineItem implements ILineItem { private static long idCounter = System.currentTimeMillis(); diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/basic/Person.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/basic/Person.java index ca2867550..a9911b32e 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/basic/Person.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/basic/Person.java @@ -19,7 +19,6 @@ import javax.persistence.*; import org.apache.openjpa.persistence.models.company.*; @Entity(name="BAS_Person") -@Table(name="BAS_Person") // OPENJPA-121 @Inheritance(strategy=InheritanceType.SINGLE_TABLE) public abstract class Person implements IPerson { private static long idCounter = System.currentTimeMillis(); diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/basic/Product.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/basic/Product.java index 174182ae5..a939203a0 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/basic/Product.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/basic/Product.java @@ -20,7 +20,6 @@ import javax.persistence.*; import org.apache.openjpa.persistence.models.company.*; @Entity(name="BAS_Product") -@Table(name="BAS_Product") // OPENJPA-121 public class Product implements IProduct { private static long idCounter = System.currentTimeMillis(); diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/basic/ProductOrder.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/basic/ProductOrder.java index 0baaf9469..68f314cd5 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/basic/ProductOrder.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/basic/ProductOrder.java @@ -20,7 +20,6 @@ import javax.persistence.*; import org.apache.openjpa.persistence.models.company.*; @Entity(name="BAS_ProductOrder") -@Table(name="BAS_ProductOrder") // OPENJPA-121 public class ProductOrder implements IProductOrder { private static long idCounter = System.currentTimeMillis(); diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/fetchlazy/Address.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/fetchlazy/Address.java index 8ea2b35c9..966d23018 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/fetchlazy/Address.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/fetchlazy/Address.java @@ -19,7 +19,6 @@ import javax.persistence.*; import org.apache.openjpa.persistence.models.company.*; @Entity(name="LAZ_Address") -@Table(name="LAZ_Address") // OPENJPA-121 public class Address implements IAddress { private static long idCounter = System.currentTimeMillis(); diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/fetchlazy/Company.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/fetchlazy/Company.java index 4798410ef..48e026eff 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/fetchlazy/Company.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/fetchlazy/Company.java @@ -20,7 +20,6 @@ import javax.persistence.*; import org.apache.openjpa.persistence.models.company.*; @Entity(name="LAZ_Company") -@Table(name="LAZ_Company") // OPENJPA-121 public class Company implements ICompany { private static long idCounter = System.currentTimeMillis(); diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/fetchlazy/LineItem.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/fetchlazy/LineItem.java index 1f02f665f..b4f154fb6 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/fetchlazy/LineItem.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/fetchlazy/LineItem.java @@ -19,7 +19,6 @@ import javax.persistence.*; import org.apache.openjpa.persistence.models.company.*; @Entity(name="LAZ_LineItem") -@Table(name="LAZ_LineItem") // OPENJPA-121 public class LineItem implements ILineItem { private static long idCounter = System.currentTimeMillis(); diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/fetchlazy/Person.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/fetchlazy/Person.java index 117582e22..94a9e42c1 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/fetchlazy/Person.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/fetchlazy/Person.java @@ -19,7 +19,6 @@ import javax.persistence.*; import org.apache.openjpa.persistence.models.company.*; @Entity(name="LAZ_Person") -@Table(name="LAZ_Person") // OPENJPA-121 @Inheritance(strategy=InheritanceType.SINGLE_TABLE) public abstract class Person implements IPerson { private static long idCounter = System.currentTimeMillis(); diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/fetchlazy/Product.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/fetchlazy/Product.java index 3f70de285..875fb90dd 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/fetchlazy/Product.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/fetchlazy/Product.java @@ -20,7 +20,6 @@ import javax.persistence.*; import org.apache.openjpa.persistence.models.company.*; @Entity(name="LAZ_Product") -@Table(name="LAZ_Product") // OPENJPA-121 public class Product implements IProduct { private static long idCounter = System.currentTimeMillis(); diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/fetchlazy/ProductOrder.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/fetchlazy/ProductOrder.java index 68d8c1b4f..6612d5f31 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/fetchlazy/ProductOrder.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/fetchlazy/ProductOrder.java @@ -20,7 +20,6 @@ import javax.persistence.*; import org.apache.openjpa.persistence.models.company.*; @Entity(name="LAZ_ProductOrder") -@Table(name="LAZ_ProductOrder") // OPENJPA-121 public class ProductOrder implements IProductOrder { private static long idCounter = System.currentTimeMillis(); diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/idclass/Address.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/idclass/Address.java index 4061da701..53097fb07 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/idclass/Address.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/idclass/Address.java @@ -19,7 +19,6 @@ import javax.persistence.*; import org.apache.openjpa.persistence.models.company.*; @Entity(name="IDC_Address") -@Table(name="IDC_Address") // OPENJPA-121 public class Address implements IAddress { private static int ids = 1; diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/idclass/Company.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/idclass/Company.java index c6583f800..2097a71a5 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/idclass/Company.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/idclass/Company.java @@ -20,7 +20,6 @@ import javax.persistence.*; import org.apache.openjpa.persistence.models.company.*; @Entity(name="IDC_Company") -@Table(name="IDC_Company") // OPENJPA-121 public class Company implements ICompany { private static int ids = 1; diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/idclass/LineItem.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/idclass/LineItem.java index 5a9009123..32314dc70 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/idclass/LineItem.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/idclass/LineItem.java @@ -19,7 +19,6 @@ import javax.persistence.*; import org.apache.openjpa.persistence.models.company.*; @Entity(name="IDC_LineItem") -@Table(name="IDC_LineItem") // OPENJPA-121 public class LineItem implements ILineItem { private static int ids = 1; diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/idclass/Person.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/idclass/Person.java index f2d2aacb6..280adaa2b 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/idclass/Person.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/idclass/Person.java @@ -19,7 +19,6 @@ import javax.persistence.*; import org.apache.openjpa.persistence.models.company.*; @Entity(name="IDC_Person") -@Table(name="IDC_Person") // OPENJPA-121 @Inheritance(strategy=InheritanceType.SINGLE_TABLE) public abstract class Person implements IPerson { private static int ids = 1; diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/idclass/Product.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/idclass/Product.java index 938d36a6f..c94e64096 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/idclass/Product.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/idclass/Product.java @@ -20,7 +20,6 @@ import javax.persistence.*; import org.apache.openjpa.persistence.models.company.*; @Entity(name="IDC_Product") -@Table(name="IDC_Product") // OPENJPA-121 public class Product implements IProduct { private static int ids = 1; diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/idclass/ProductOrder.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/idclass/ProductOrder.java index 95dfea961..c59e86e6c 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/idclass/ProductOrder.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/idclass/ProductOrder.java @@ -20,7 +20,6 @@ import javax.persistence.*; import org.apache.openjpa.persistence.models.company.*; @Entity(name="IDC_ProductOrder") -@Table(name="IDC_ProductOrder") // OPENJPA-121 public class ProductOrder implements IProductOrder { private static int ids = 1; diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/joined/Address.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/joined/Address.java index 48fb1f59e..60170e006 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/joined/Address.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/joined/Address.java @@ -19,7 +19,6 @@ import javax.persistence.*; import org.apache.openjpa.persistence.models.company.*; @Entity(name="JI_Address") -@Table(name="JI_Address") // OPENJPA-121 public class Address implements IAddress { private static long idCounter = System.currentTimeMillis(); diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/joined/Company.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/joined/Company.java index 3cd984f69..2cbaf8d6f 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/joined/Company.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/joined/Company.java @@ -20,7 +20,6 @@ import javax.persistence.*; import org.apache.openjpa.persistence.models.company.*; @Entity(name="JI_Company") -@Table(name="JI_Company") // OPENJPA-121 public class Company implements ICompany { private static long idCounter = System.currentTimeMillis(); diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/joined/Customer.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/joined/Customer.java index 44d9bf224..2e86a379f 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/joined/Customer.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/joined/Customer.java @@ -20,7 +20,6 @@ import javax.persistence.*; import org.apache.openjpa.persistence.models.company.*; @Entity(name="JI_Customer") -@Table(name="JI_Customer") // OPENJPA-121 @Inheritance(strategy=InheritanceType.JOINED) public class Customer extends Person implements ICustomer { @OneToMany(mappedBy="customer") diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/joined/Employee.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/joined/Employee.java index c03a23a29..f22a2fea4 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/joined/Employee.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/joined/Employee.java @@ -20,7 +20,6 @@ import javax.persistence.*; import org.apache.openjpa.persistence.models.company.*; @Entity(name="JI_Employee") -@Table(name="JI_Employee") // OPENJPA-121 @Inheritance(strategy=InheritanceType.JOINED) public abstract class Employee extends Person implements IEmployee { @OneToOne diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/joined/FullTimeEmployee.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/joined/FullTimeEmployee.java index 2ce322566..c0907631f 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/joined/FullTimeEmployee.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/joined/FullTimeEmployee.java @@ -19,7 +19,6 @@ import javax.persistence.*; import org.apache.openjpa.persistence.models.company.*; @Entity(name="JI_FullTimeEmployee") -@Table(name="JI_FullTimeEmployee") // OPENJPA-121 @Inheritance(strategy=InheritanceType.JOINED) public class FullTimeEmployee extends Employee implements IFullTimeEmployee { diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/joined/LineItem.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/joined/LineItem.java index ccb6b81ac..0f598175b 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/joined/LineItem.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/joined/LineItem.java @@ -19,7 +19,6 @@ import javax.persistence.*; import org.apache.openjpa.persistence.models.company.*; @Entity(name="JI_LineItem") -@Table(name="JI_LineItem") // OPENJPA-121 public class LineItem implements ILineItem { private static long idCounter = System.currentTimeMillis(); diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/joined/PartTimeEmployee.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/joined/PartTimeEmployee.java index df3101541..1c47dcb7c 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/joined/PartTimeEmployee.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/joined/PartTimeEmployee.java @@ -19,7 +19,6 @@ import javax.persistence.*; import org.apache.openjpa.persistence.models.company.*; @Entity(name="JI_PartTimeEmployee") -@Table(name="JI_PartTimeEmployee") // OPENJPA-121 @Inheritance(strategy=InheritanceType.JOINED) public class PartTimeEmployee extends Employee implements IPartTimeEmployee { diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/joined/Person.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/joined/Person.java index 43ae57b21..e74eb1db4 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/joined/Person.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/joined/Person.java @@ -19,7 +19,6 @@ import javax.persistence.*; import org.apache.openjpa.persistence.models.company.*; @Entity(name="JI_Person") -@Table(name="JI_Person") // OPENJPA-121 @Inheritance(strategy=InheritanceType.JOINED) public abstract class Person implements IPerson { private static long idCounter = System.currentTimeMillis(); diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/joined/Product.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/joined/Product.java index a61aaeb58..f28dc1de7 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/joined/Product.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/joined/Product.java @@ -20,7 +20,6 @@ import javax.persistence.*; import org.apache.openjpa.persistence.models.company.*; @Entity(name="JI_Product") -@Table(name="JI_Product") // OPENJPA-121 public class Product implements IProduct { private static long idCounter = System.currentTimeMillis(); diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/joined/ProductOrder.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/joined/ProductOrder.java index c5809ea06..05bb5146a 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/joined/ProductOrder.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/models/company/joined/ProductOrder.java @@ -20,7 +20,6 @@ import javax.persistence.*; import org.apache.openjpa.persistence.models.company.*; @Entity(name="JI_ProductOrder") -@Table(name="JI_ProductOrder") // OPENJPA-121 public class ProductOrder implements IProductOrder { private static long idCounter = System.currentTimeMillis(); diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestAbstractSchemaName.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestAbstractSchemaName.java index 948ac26f3..3a3485078 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestAbstractSchemaName.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestAbstractSchemaName.java @@ -24,6 +24,7 @@ import javax.persistence.Query; import junit.framework.TestCase; import junit.textui.TestRunner; +import org.apache.openjpa.persistence.simple.NamedEntity; /** * Test that we can query by an entity's abstract schema name. diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/NamedEntity.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/NamedEntity.java similarity index 92% rename from openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/NamedEntity.java rename to openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/NamedEntity.java index 6df13916c..8ac3a1c82 100755 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/NamedEntity.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/NamedEntity.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.openjpa.persistence.query; +package org.apache.openjpa.persistence.simple; import javax.persistence.Entity; import javax.persistence.GeneratedValue; diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestTableNamesDefaultToEntityNames.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestTableNamesDefaultToEntityNames.java new file mode 100644 index 000000000..3c6458b4d --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestTableNamesDefaultToEntityNames.java @@ -0,0 +1,20 @@ +package org.apache.openjpa.persistence.simple; + +import org.apache.openjpa.persistence.OpenJPAPersistence; +import org.apache.openjpa.persistence.test.PersistenceTestCase; +import org.apache.openjpa.jdbc.meta.ClassMapping; + +public class TestTableNamesDefaultToEntityNames + extends PersistenceTestCase { + + @Override + protected Class[] getEntityTypes() { + return new Class[] { NamedEntity.class }; + } + + public void testEntityNames() { + ClassMapping cm = (ClassMapping) OpenJPAPersistence.getMetaData( + getEntityManagerFactory(), NamedEntity.class); + assertEquals("named", cm.getTable().getName()); + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/PersistenceTestCase.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/PersistenceTestCase.java new file mode 100644 index 000000000..45fec7c1b --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/PersistenceTestCase.java @@ -0,0 +1,39 @@ +package org.apache.openjpa.persistence.test; + +import java.util.Map; +import java.util.HashMap; +import javax.persistence.Persistence; + +import junit.framework.TestCase; +import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory; + +public abstract class PersistenceTestCase + extends TestCase { + + protected OpenJPAEntityManagerFactory emf; + + protected Class[] getEntityTypes() { + return new Class[0]; + } + + public void setUp() { + Map props = new HashMap(System.getProperties()); + Class[] types = getEntityTypes(); + if (types != null && types.length > 0) { + StringBuffer buf = new StringBuffer(); + for (int i = 0; i < types.length; i++) { + buf.append(types[i].getName()); + if (i != types.length - 1) + buf.append(","); + } + props.put("openjpa.MetaDataFactory", + "jpa(Types=" + buf.toString() + ")"); + } + emf = (OpenJPAEntityManagerFactory) + Persistence.createEntityManagerFactory("test", props); + } + + public OpenJPAEntityManagerFactory getEntityManagerFactory() { + return emf; + } +}