mirror of https://github.com/apache/openjpa.git
OPENJPA-648 Table generator uses incorrect schema name
commit OPENJPA-648_1.2.0.patch provided by Jeremy Bauer git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@673267 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
de790be2ad
commit
25a69ffe0a
|
@ -595,6 +595,8 @@ public class TableJDBCSeq
|
|||
String tableName;
|
||||
if (sName == null)
|
||||
tableName = table.getFullName();
|
||||
else if (table.getSchemaName() != null)
|
||||
tableName = table.getFullName();
|
||||
else
|
||||
tableName = sName + "." + table.getName();
|
||||
return tableName;
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.openjpa.persistence.generationtype;
|
||||
|
||||
import java.io.*;
|
||||
import javax.persistence.*;
|
||||
|
||||
/**
|
||||
* Extension of Animal class illustrating inheritance.
|
||||
*/
|
||||
@Entity(name = "DogTable3")
|
||||
@Table(name = "DOGTABLES", schema = "SCHEMA3")
|
||||
public class DogTable3 implements Serializable
|
||||
|
||||
{
|
||||
@Id
|
||||
@TableGenerator(name = "Dog_Gen3", table = "ID_Gen3", schema="SCHEMA3G",
|
||||
pkColumnName = "GEN_NAME", valueColumnName = "GEN_VAL",
|
||||
pkColumnValue = "ID2", initialValue = 100, allocationSize = 10)
|
||||
@GeneratedValue(strategy = GenerationType.TABLE, generator = "Dog_Gen3")
|
||||
private int id2;
|
||||
|
||||
private String name;
|
||||
|
||||
private float price;
|
||||
|
||||
private boolean domestic;
|
||||
|
||||
public DogTable3() {
|
||||
super();
|
||||
|
||||
}
|
||||
|
||||
public DogTable3(String name) {
|
||||
this.name = name;
|
||||
|
||||
}
|
||||
|
||||
public int getId2() {
|
||||
return id2;
|
||||
}
|
||||
|
||||
public void setId2(int id) {
|
||||
this.id2 = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public float getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public void setPrice(float price) {
|
||||
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public boolean isDomestic() {
|
||||
return domestic;
|
||||
}
|
||||
|
||||
public void setDomestic(boolean domestic) {
|
||||
this.domestic = domestic;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.openjpa.persistence.generationtype;
|
||||
|
||||
import java.io.*;
|
||||
import javax.persistence.*;
|
||||
|
||||
/**
|
||||
* Extension of Animal class illustrating inheritance.
|
||||
*/
|
||||
@Entity(name = "DogTable4")
|
||||
@Table(name = "DOGTABLES4")
|
||||
public class DogTable4 implements Serializable
|
||||
|
||||
{
|
||||
@Id
|
||||
@TableGenerator(name = "Dog_Gen4", table = "ID_Gen4", schema="SCHEMA4G",
|
||||
pkColumnName = "GEN_NAME", valueColumnName = "GEN_VAL",
|
||||
pkColumnValue = "ID2", initialValue = 100, allocationSize = 10)
|
||||
@GeneratedValue(strategy = GenerationType.TABLE, generator = "Dog_Gen4")
|
||||
private int id2;
|
||||
|
||||
private String name;
|
||||
|
||||
private float price;
|
||||
|
||||
private boolean domestic;
|
||||
|
||||
public DogTable4() {
|
||||
super();
|
||||
|
||||
}
|
||||
|
||||
public DogTable4(String name) {
|
||||
this.name = name;
|
||||
|
||||
}
|
||||
|
||||
public int getId2() {
|
||||
return id2;
|
||||
}
|
||||
|
||||
public void setId2(int id) {
|
||||
this.id2 = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public float getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public void setPrice(float price) {
|
||||
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public boolean isDomestic() {
|
||||
return domestic;
|
||||
}
|
||||
|
||||
public void setDomestic(boolean domestic) {
|
||||
this.domestic = domestic;
|
||||
}
|
||||
}
|
|
@ -26,7 +26,8 @@ import org.apache.openjpa.persistence.test.SingleEMFTestCase;
|
|||
|
||||
public class TestMultipleSchemaNames extends SingleEMFTestCase {
|
||||
public void setUp() {
|
||||
setUp(Dog1.class, Dog2.class, DogTable.class, DogTable2.class);
|
||||
setUp(Dog1.class, Dog2.class, DogTable.class, DogTable2.class,
|
||||
DogTable3.class, DogTable4.class);
|
||||
|
||||
EntityManager em = emf.createEntityManager();
|
||||
em.getTransaction().begin();
|
||||
|
@ -60,6 +61,22 @@ public class TestMultipleSchemaNames extends SingleEMFTestCase {
|
|||
em.remove(Obj);
|
||||
}
|
||||
|
||||
Query qry5 = em.createQuery("select d from DogTable3 d");
|
||||
List result5 = qry5.getResultList();
|
||||
|
||||
for (int index = 0; index < result5.size(); index++) {
|
||||
DogTable3 Obj = (DogTable3) result5.get(index);
|
||||
em.remove(Obj);
|
||||
}
|
||||
|
||||
Query qry6 = em.createQuery("select d from DogTable4 d");
|
||||
List result6 = qry6.getResultList();
|
||||
|
||||
for (int index = 0; index < result6.size(); index++) {
|
||||
DogTable4 Obj = (DogTable4) result6.get(index);
|
||||
em.remove(Obj);
|
||||
}
|
||||
|
||||
Query delschema1 = em
|
||||
.createNativeQuery("delete from schema1.openjpa_sequence_table");
|
||||
delschema1.executeUpdate();
|
||||
|
@ -71,8 +88,15 @@ public class TestMultipleSchemaNames extends SingleEMFTestCase {
|
|||
Query delgentable2 = em
|
||||
.createNativeQuery("delete from schema2.id_gen2");
|
||||
delgentable2.executeUpdate();
|
||||
Query delgentable3 = em
|
||||
.createNativeQuery("delete from schema3g.id_gen3");
|
||||
delgentable3.executeUpdate();
|
||||
Query delgentable4 = em
|
||||
.createNativeQuery("delete from schema4g.id_gen4");
|
||||
delgentable4.executeUpdate();
|
||||
|
||||
em.getTransaction().commit();
|
||||
em.close();
|
||||
|
||||
}
|
||||
|
||||
|
@ -177,6 +201,28 @@ public class TestMultipleSchemaNames extends SingleEMFTestCase {
|
|||
dog2a.setName("helloDog4");
|
||||
dog2a.setPrice(25000);
|
||||
em.persist(dog2a);
|
||||
|
||||
// add dog3
|
||||
DogTable3 dog3 = new DogTable3();
|
||||
dog3.setName("helloDog5");
|
||||
dog3.setPrice(15001);
|
||||
em.persist(dog3);
|
||||
|
||||
DogTable3 dog3a = new DogTable3();
|
||||
dog3a.setName("helloDog6");
|
||||
dog3a.setPrice(25001);
|
||||
em.persist(dog3a);
|
||||
|
||||
// add dog4
|
||||
DogTable4 dog4 = new DogTable4();
|
||||
dog4.setName("helloDog7");
|
||||
dog4.setPrice(15002);
|
||||
em.persist(dog4);
|
||||
|
||||
DogTable4 dog4a = new DogTable4();
|
||||
dog4a.setName("helloDog8");
|
||||
dog4a.setPrice(25002);
|
||||
em.persist(dog4a);
|
||||
em.getTransaction().commit();
|
||||
|
||||
DogTable dog1x = em.find(DogTable.class, kem.getObjectId(dog1));
|
||||
|
@ -189,6 +235,7 @@ public class TestMultipleSchemaNames extends SingleEMFTestCase {
|
|||
assertEquals(dog11.getName(), "helloDog2");
|
||||
dog11.setName("Dog2");
|
||||
dog11.setDomestic(true);
|
||||
|
||||
// update dog2
|
||||
DogTable2 dog2x = em.find(DogTable2.class, kem.getObjectId(dog2));
|
||||
assertTrue(dog2x.getId2() == 100 || dog2x.getId2() == 101);
|
||||
|
@ -196,21 +243,45 @@ public class TestMultipleSchemaNames extends SingleEMFTestCase {
|
|||
dog2x.setName("Dog3");
|
||||
dog2x.setDomestic(true);
|
||||
DogTable2 dog21 = em.find(DogTable2.class, kem.getObjectId(dog2a));
|
||||
assertTrue(dog2x.getId2() == 100 || dog2x.getId2() == 101);
|
||||
assertTrue(dog21.getId2() == 100 || dog21.getId2() == 101);
|
||||
assertEquals(dog21.getName(), "helloDog4");
|
||||
dog21.setName("Dog4");
|
||||
dog21.setDomestic(true);
|
||||
|
||||
// update dog3
|
||||
DogTable3 dog3x = em.find(DogTable3.class, kem.getObjectId(dog3));
|
||||
assertTrue(dog3x.getId2() == 100 || dog3x.getId2() == 101);
|
||||
assertEquals(dog3x.getName(), "helloDog5");
|
||||
dog3x.setName("Dog5");
|
||||
dog3x.setDomestic(true);
|
||||
DogTable3 dog31 = em.find(DogTable3.class, kem.getObjectId(dog3a));
|
||||
assertTrue(dog31.getId2() == 100 || dog31.getId2() == 101);
|
||||
assertEquals(dog31.getName(), "helloDog6");
|
||||
dog31.setName("Dog6");
|
||||
dog31.setDomestic(true);
|
||||
|
||||
// update dog4
|
||||
DogTable4 dog4x = em.find(DogTable4.class, kem.getObjectId(dog4));
|
||||
assertTrue(dog4x.getId2() == 100 || dog4x.getId2() == 101);
|
||||
assertEquals(dog4x.getName(), "helloDog7");
|
||||
dog4x.setName("Dog7");
|
||||
dog4x.setDomestic(true);
|
||||
DogTable4 dog41 = em.find(DogTable4.class, kem.getObjectId(dog4a));
|
||||
assertTrue(dog41.getId2() == 100 || dog41.getId2() == 101);
|
||||
assertEquals(dog41.getName(), "helloDog8");
|
||||
dog41.setName("Dog8");
|
||||
dog41.setDomestic(true);
|
||||
|
||||
// get the update dog name
|
||||
|
||||
em.getTransaction().begin();
|
||||
Query qry1 = em.createQuery("select d from DogTable d order by d.name");
|
||||
List result1 = qry1.getResultList();
|
||||
for (int index = 0; index < result1.size(); index++) {
|
||||
DogTable dog4 = (DogTable) result1.get(index);
|
||||
assertTrue(dog4.getId2() == 20 || dog4.getId2() == 21);
|
||||
DogTable dog1xx = (DogTable) result1.get(index);
|
||||
assertTrue(dog1xx.getId2() == 20 || dog1xx.getId2() == 21);
|
||||
int j = index + 1;
|
||||
assertEquals(dog4.getName(), "Dog" + j);
|
||||
assertEquals(dog1xx.getName(), "Dog" + j);
|
||||
|
||||
}
|
||||
|
||||
|
@ -219,10 +290,32 @@ public class TestMultipleSchemaNames extends SingleEMFTestCase {
|
|||
List result2 = qry2.getResultList();
|
||||
|
||||
for (int index = 0; index < result2.size(); index++) {
|
||||
DogTable2 dog5 = (DogTable2) result2.get(index);
|
||||
assertTrue(dog5.getId2() == 100 || dog5.getId2() == 101);
|
||||
DogTable2 dog2xx = (DogTable2) result2.get(index);
|
||||
assertTrue(dog2xx.getId2() == 100 || dog2xx.getId2() == 101);
|
||||
int j = index + 3;
|
||||
assertEquals(dog5.getName(), "Dog" + j);
|
||||
assertEquals(dog2xx.getName(), "Dog" + j);
|
||||
}
|
||||
|
||||
Query qry3 = em
|
||||
.createQuery("select d from DogTable3 d order by d.name");
|
||||
List result3 = qry3.getResultList();
|
||||
|
||||
for (int index = 0; index < result3.size(); index++) {
|
||||
DogTable3 dog3xx = (DogTable3) result3.get(index);
|
||||
assertTrue(dog3xx.getId2() == 100 || dog3xx.getId2() == 101);
|
||||
int j = index + 5;
|
||||
assertEquals(dog3xx.getName(), "Dog" + j);
|
||||
}
|
||||
|
||||
Query qry4 = em
|
||||
.createQuery("select d from DogTable4 d order by d.name");
|
||||
List result4 = qry4.getResultList();
|
||||
|
||||
for (int index = 0; index < result4.size(); index++) {
|
||||
DogTable4 dog4xx = (DogTable4) result4.get(index);
|
||||
assertTrue(dog4xx.getId2() == 100 || dog4xx.getId2() == 101);
|
||||
int j = index + 7;
|
||||
assertEquals(dog4xx.getName(), "Dog" + j);
|
||||
}
|
||||
|
||||
em.getTransaction().commit();
|
||||
|
|
Loading…
Reference in New Issue