mirror of https://github.com/apache/openjpa.git
OPENJPA-399 Committing Teresa's patch
git-svn-id: https://svn.apache.org/repos/asf/openjpa/branches/1.0.x@584350 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3b2b878d0a
commit
9e807991b0
|
@ -93,6 +93,11 @@ public abstract class LocalConstraint
|
|||
* Add a column to the constraint.
|
||||
*/
|
||||
public void addColumn(Column col) {
|
||||
if (col == null)
|
||||
throw new InvalidStateException(_loc.get("table-mismatch",
|
||||
col == null ? null : col.getTable(),
|
||||
col == null ? null : getTable()));
|
||||
|
||||
if (_colList == null)
|
||||
_colList = new ArrayList(3);
|
||||
else if (_colList.contains(col))
|
||||
|
|
|
@ -25,8 +25,7 @@ import java.io.*;
|
|||
* Extension of Animal class illustrating inheritance.
|
||||
*/
|
||||
@Entity(name = "Dog1")
|
||||
@Table(name = "DOGTAB", schema = "SCHEMA1")
|
||||
@IdClass(DogId.class)
|
||||
@Table(name = "DOGAUTO", schema = "SCHEMA1")
|
||||
public class Dog1 implements Serializable
|
||||
|
||||
{
|
||||
|
@ -34,9 +33,6 @@ public class Dog1 implements Serializable
|
|||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private int id2;
|
||||
|
||||
@Id
|
||||
private int datastoreid;
|
||||
|
||||
private String name;
|
||||
|
||||
private float price;
|
||||
|
@ -86,11 +82,4 @@ public class Dog1 implements Serializable
|
|||
this.domestic = domestic;
|
||||
}
|
||||
|
||||
public int getDatastoreid() {
|
||||
return datastoreid;
|
||||
}
|
||||
|
||||
public void setDatastoreid(int datastoreid) {
|
||||
this.datastoreid = datastoreid;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,8 +25,7 @@ import java.io.*;
|
|||
* Extension of Animal class illustrating inheritance.
|
||||
*/
|
||||
@Entity(name = "Dog2")
|
||||
@Table(name = "DOGTAB", schema = "SCHEMA2")
|
||||
@IdClass(DogId.class)
|
||||
@Table(name = "DOGAUTO", schema = "SCHEMA2")
|
||||
public class Dog2 implements Serializable
|
||||
|
||||
{
|
||||
|
@ -34,9 +33,6 @@ public class Dog2 implements Serializable
|
|||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private int id2;
|
||||
|
||||
@Id
|
||||
private int datastoreid;
|
||||
|
||||
private String name;
|
||||
|
||||
private float price;
|
||||
|
@ -86,11 +82,4 @@ public class Dog2 implements Serializable
|
|||
this.domestic = domestic;
|
||||
}
|
||||
|
||||
public int getDatastoreid() {
|
||||
return datastoreid;
|
||||
}
|
||||
|
||||
public void setDatastoreid(int datastoreid) {
|
||||
this.datastoreid = datastoreid;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,103 +0,0 @@
|
|||
/*
|
||||
* 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.*;
|
||||
|
||||
/**
|
||||
* Application identity class for: tutorial.ejb.Animal
|
||||
*
|
||||
* Auto-generated by: org.apache.openjpa.enhance.ApplicationIdTool
|
||||
*/
|
||||
public class DogId implements Serializable {
|
||||
static {
|
||||
// register persistent class in JVM
|
||||
try {
|
||||
Class.forName("tutorial.ejb.Dog");
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
public int id2;
|
||||
|
||||
public int datastoreid;
|
||||
|
||||
public DogId() {
|
||||
}
|
||||
|
||||
public DogId(String str) {
|
||||
fromString(str);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return String.valueOf(id2) + "::" + datastoreid;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int rs = 17;
|
||||
rs = rs * 37 + (int) (id2 ^ (id2 >>> 32));
|
||||
rs = rs
|
||||
* 37
|
||||
+ ((datastoreid == 0) ? 0 : new Integer(datastoreid).hashCode());
|
||||
return rs;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null || obj.getClass() != getClass())
|
||||
return false;
|
||||
|
||||
DogId other = (DogId) obj;
|
||||
return (id2 == other.id2)
|
||||
&& ((datastoreid == 0 && other.datastoreid == 0) || (datastoreid != 0 && datastoreid == other.datastoreid));
|
||||
}
|
||||
|
||||
private void fromString(String str) {
|
||||
Tokenizer toke = new Tokenizer(str);
|
||||
str = toke.nextToken();
|
||||
id2 = Integer.parseInt(str);
|
||||
str = toke.nextToken();
|
||||
datastoreid = Integer.parseInt(str);
|
||||
}
|
||||
|
||||
protected static class Tokenizer {
|
||||
private final String str;
|
||||
|
||||
private int last;
|
||||
|
||||
public Tokenizer(String str) {
|
||||
this.str = str;
|
||||
}
|
||||
|
||||
public String nextToken() {
|
||||
int next = str.indexOf("::", last);
|
||||
String part;
|
||||
if (next == -1) {
|
||||
part = str.substring(last);
|
||||
last = str.length();
|
||||
} else {
|
||||
part = str.substring(last, next);
|
||||
last = next + 2;
|
||||
}
|
||||
return part;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -26,8 +26,7 @@ import java.io.*;
|
|||
* Extension of Animal class illustrating inheritance.
|
||||
*/
|
||||
@Entity(name = "DogTable")
|
||||
@Table(name = "DOGTABLE", schema = "SCHEMA1")
|
||||
@IdClass(DogId.class)
|
||||
@Table(name = "DOGTABLES", schema = "SCHEMA1")
|
||||
public class DogTable implements Serializable
|
||||
|
||||
{
|
||||
|
@ -38,9 +37,6 @@ public class DogTable implements Serializable
|
|||
@GeneratedValue(strategy = GenerationType.TABLE, generator = "Dog_Gen1")
|
||||
private int id2;
|
||||
|
||||
@Id
|
||||
private int datastoreid;
|
||||
|
||||
private String name;
|
||||
|
||||
private float price;
|
||||
|
@ -53,7 +49,6 @@ public class DogTable implements Serializable
|
|||
}
|
||||
|
||||
public DogTable(String name) {
|
||||
this.id2 = id2;
|
||||
this.name = name;
|
||||
|
||||
}
|
||||
|
@ -91,11 +86,4 @@ public class DogTable implements Serializable
|
|||
this.domestic = domestic;
|
||||
}
|
||||
|
||||
public int getDatastoreid() {
|
||||
return datastoreid;
|
||||
}
|
||||
|
||||
public void setDatastoreid(int datastoreid) {
|
||||
this.datastoreid = datastoreid;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,8 +25,7 @@ import javax.persistence.*;
|
|||
* Extension of Animal class illustrating inheritance.
|
||||
*/
|
||||
@Entity(name = "DogTable2")
|
||||
@Table(name = "DOGTABLE", schema = "SCHEMA2")
|
||||
@IdClass(DogId.class)
|
||||
@Table(name = "DOGTABLES", schema = "SCHEMA2")
|
||||
public class DogTable2 implements Serializable
|
||||
|
||||
{
|
||||
|
@ -37,9 +36,6 @@ public class DogTable2 implements Serializable
|
|||
@GeneratedValue(strategy = GenerationType.TABLE, generator = "Dog_Gen2")
|
||||
private int id2;
|
||||
|
||||
@Id
|
||||
private int datastoreid;
|
||||
|
||||
private String name;
|
||||
|
||||
private float price;
|
||||
|
@ -52,7 +48,6 @@ public class DogTable2 implements Serializable
|
|||
}
|
||||
|
||||
public DogTable2(String name) {
|
||||
this.id2 = id2;
|
||||
this.name = name;
|
||||
|
||||
}
|
||||
|
@ -89,12 +84,4 @@ public class DogTable2 implements Serializable
|
|||
public void setDomestic(boolean domestic) {
|
||||
this.domestic = domestic;
|
||||
}
|
||||
|
||||
public int getDatastoreid() {
|
||||
return datastoreid;
|
||||
}
|
||||
|
||||
public void setDatastoreid(int datastoreid) {
|
||||
this.datastoreid = datastoreid;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,31 +83,29 @@ public class TestMultipleSchemaNames extends SingleEMFTestCase {
|
|||
|
||||
Dog1 dog1 = new Dog1();
|
||||
dog1.setName("helloDog1");
|
||||
dog1.setDatastoreid(12);
|
||||
dog1.setPrice(12000);
|
||||
|
||||
em.persist(dog1);
|
||||
Dog1 dog1a = new Dog1();
|
||||
dog1a.setName("helloDog2");
|
||||
dog1a.setDatastoreid(15);
|
||||
dog1a.setPrice(22000);
|
||||
em.persist(dog1a);
|
||||
// add dog2
|
||||
Dog2 dog2 = new Dog2();
|
||||
dog2.setName("helloDog3");
|
||||
dog2.setDatastoreid(12);
|
||||
dog2.setPrice(15000);
|
||||
em.persist(dog2);
|
||||
|
||||
Dog2 dog2a = new Dog2();
|
||||
dog2a.setName("helloDog4");
|
||||
dog2a.setDatastoreid(19);
|
||||
dog2a.setPrice(25000);
|
||||
em.persist(dog2a);
|
||||
em.getTransaction().commit();
|
||||
// System.out.println("persist dogs are done");
|
||||
|
||||
Dog1 dog1x = em.find(Dog1.class, kem.getObjectId(dog1));
|
||||
// Derby can't guarantee the order of the generated value, therefore,
|
||||
// we can't assert the id based on the order. For db2, we see the id
|
||||
// value in the right order
|
||||
assertTrue(dog1x.getId2() == 1 || dog1x.getId2() == 2);
|
||||
assertEquals(dog1x.getName(), "helloDog1");
|
||||
dog1x.setName("Dog1");
|
||||
|
@ -162,25 +160,21 @@ public class TestMultipleSchemaNames extends SingleEMFTestCase {
|
|||
|
||||
DogTable dog1 = new DogTable();
|
||||
dog1.setName("helloDog1");
|
||||
dog1.setDatastoreid(12);
|
||||
dog1.setPrice(12000);
|
||||
|
||||
em.persist(dog1);
|
||||
DogTable dog1a = new DogTable();
|
||||
dog1a.setName("helloDog2");
|
||||
dog1a.setDatastoreid(15);
|
||||
dog1a.setPrice(22000);
|
||||
em.persist(dog1a);
|
||||
// add dog2
|
||||
DogTable2 dog2 = new DogTable2();
|
||||
dog2.setName("helloDog3");
|
||||
dog2.setDatastoreid(12);
|
||||
dog2.setPrice(15000);
|
||||
em.persist(dog2);
|
||||
|
||||
DogTable2 dog2a = new DogTable2();
|
||||
dog2a.setName("helloDog4");
|
||||
dog2a.setDatastoreid(19);
|
||||
dog2a.setPrice(25000);
|
||||
em.persist(dog2a);
|
||||
em.getTransaction().commit();
|
||||
|
|
Loading…
Reference in New Issue