From 9e807991b062850bbc958913cc09bdae47852698 Mon Sep 17 00:00:00 2001 From: Michael Dick Date: Sat, 13 Oct 2007 00:35:12 +0000 Subject: [PATCH] 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 --- .../openjpa/jdbc/schema/LocalConstraint.java | 5 + .../persistence/generationtype/Dog1.java | 13 +-- .../persistence/generationtype/Dog2.java | 13 +-- .../persistence/generationtype/DogId.java | 103 ------------------ .../persistence/generationtype/DogTable.java | 14 +-- .../persistence/generationtype/DogTable2.java | 15 +-- .../TestMultipleSchemaNames.java | 12 +- 7 files changed, 12 insertions(+), 163 deletions(-) delete mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/DogId.java diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/LocalConstraint.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/LocalConstraint.java index c68a674b7..57f0a74a2 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/LocalConstraint.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/LocalConstraint.java @@ -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)) diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/Dog1.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/Dog1.java index b6ee13c95..a101690ab 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/Dog1.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/Dog1.java @@ -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; - } } diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/Dog2.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/Dog2.java index 9e7c5656a..5a62ed6ee 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/Dog2.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/Dog2.java @@ -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; - } } diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/DogId.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/DogId.java deleted file mode 100644 index f7d68629d..000000000 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/DogId.java +++ /dev/null @@ -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; - } - } -} \ No newline at end of file diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/DogTable.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/DogTable.java index 537ccec76..695da4845 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/DogTable.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/DogTable.java @@ -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; - } } diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/DogTable2.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/DogTable2.java index 4ddf69e5b..de0640428 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/DogTable2.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/DogTable2.java @@ -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; - } } diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestMultipleSchemaNames.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestMultipleSchemaNames.java index c3a44c4ed..94310df54 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestMultipleSchemaNames.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestMultipleSchemaNames.java @@ -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();