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
This commit is contained in:
Patrick Linskey 2007-03-06 23:57:29 +00:00
parent 1af233a0b3
commit d2c748d109
34 changed files with 68 additions and 32 deletions

View File

@ -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

View File

@ -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;

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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();

View File

@ -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();

View File

@ -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")

View File

@ -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

View File

@ -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 {

View File

@ -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();

View File

@ -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 {

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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.

View File

@ -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;

View File

@ -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());
}
}

View File

@ -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;
}
}