Author: mikedd Date: Fri Oct 12 17:51:54 2007 New Revision: 584354 URL: http://svn.apache.org/viewvc?rev=584354&view=rev Log: OPENJPA-399 Committing Teresa's patch
Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/LocalConstraint.java openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/Dog1.java openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/Dog2.java openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/DogId.java openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/DogTable.java openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/DogTable2.java openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestMultipleSchemaNames.java Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/LocalConstraint.java URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/LocalConstraint.java?rev=584354&r1=584353&r2=584354&view=diff ============================================================================== --- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/LocalConstraint.java (original) +++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/LocalConstraint.java Fri Oct 12 17:51:54 2007 @@ -93,6 +93,11 @@ * 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)) Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/Dog1.java URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/Dog1.java?rev=584354&r1=584353&r2=584354&view=diff ============================================================================== --- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/Dog1.java (original) +++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/Dog1.java Fri Oct 12 17:51:54 2007 @@ -25,8 +25,7 @@ * Extension of Animal class illustrating inheritance. */ @Entity(name = "Dog1") [EMAIL PROTECTED](name = "DOGTAB", schema = "SCHEMA1") [EMAIL PROTECTED](DogId.class) [EMAIL PROTECTED](name = "DOGAUTO", schema = "SCHEMA1") public class Dog1 implements Serializable { @@ -34,9 +33,6 @@ @GeneratedValue(strategy = GenerationType.AUTO) private int id2; - @Id - private int datastoreid; - private String name; private float price; @@ -86,11 +82,4 @@ this.domestic = domestic; } - public int getDatastoreid() { - return datastoreid; - } - - public void setDatastoreid(int datastoreid) { - this.datastoreid = datastoreid; - } } Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/Dog2.java URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/Dog2.java?rev=584354&r1=584353&r2=584354&view=diff ============================================================================== --- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/Dog2.java (original) +++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/Dog2.java Fri Oct 12 17:51:54 2007 @@ -25,8 +25,7 @@ * Extension of Animal class illustrating inheritance. */ @Entity(name = "Dog2") [EMAIL PROTECTED](name = "DOGTAB", schema = "SCHEMA2") [EMAIL PROTECTED](DogId.class) [EMAIL PROTECTED](name = "DOGAUTO", schema = "SCHEMA2") public class Dog2 implements Serializable { @@ -34,9 +33,6 @@ @GeneratedValue(strategy = GenerationType.AUTO) private int id2; - @Id - private int datastoreid; - private String name; private float price; @@ -86,11 +82,4 @@ this.domestic = domestic; } - public int getDatastoreid() { - return datastoreid; - } - - public void setDatastoreid(int datastoreid) { - this.datastoreid = datastoreid; - } } Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/DogId.java URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/DogId.java?rev=584354&r1=584353&r2=584354&view=diff ============================================================================== --- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/DogId.java (original) +++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/DogId.java Fri Oct 12 17:51:54 2007 @@ -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 Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/DogTable.java URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/DogTable.java?rev=584354&r1=584353&r2=584354&view=diff ============================================================================== --- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/DogTable.java (original) +++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/DogTable.java Fri Oct 12 17:51:54 2007 @@ -26,8 +26,7 @@ * Extension of Animal class illustrating inheritance. */ @Entity(name = "DogTable") [EMAIL PROTECTED](name = "DOGTABLE", schema = "SCHEMA1") [EMAIL PROTECTED](DogId.class) [EMAIL PROTECTED](name = "DOGTABLES", schema = "SCHEMA1") public class DogTable implements Serializable { @@ -38,9 +37,6 @@ @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 DogTable(String name) { - this.id2 = id2; this.name = name; } @@ -91,11 +86,4 @@ this.domestic = domestic; } - public int getDatastoreid() { - return datastoreid; - } - - public void setDatastoreid(int datastoreid) { - this.datastoreid = datastoreid; - } } Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/DogTable2.java URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/DogTable2.java?rev=584354&r1=584353&r2=584354&view=diff ============================================================================== --- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/DogTable2.java (original) +++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/DogTable2.java Fri Oct 12 17:51:54 2007 @@ -25,8 +25,7 @@ * Extension of Animal class illustrating inheritance. */ @Entity(name = "DogTable2") [EMAIL PROTECTED](name = "DOGTABLE", schema = "SCHEMA2") [EMAIL PROTECTED](DogId.class) [EMAIL PROTECTED](name = "DOGTABLES", schema = "SCHEMA2") public class DogTable2 implements Serializable { @@ -37,9 +36,6 @@ @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 DogTable2(String name) { - this.id2 = id2; this.name = name; } @@ -88,13 +83,5 @@ public void setDomestic(boolean domestic) { this.domestic = domestic; - } - - public int getDatastoreid() { - return datastoreid; - } - - public void setDatastoreid(int datastoreid) { - this.datastoreid = datastoreid; } } Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestMultipleSchemaNames.java URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestMultipleSchemaNames.java?rev=584354&r1=584353&r2=584354&view=diff ============================================================================== --- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestMultipleSchemaNames.java (original) +++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestMultipleSchemaNames.java Fri Oct 12 17:51:54 2007 @@ -83,31 +83,29 @@ 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 @@ 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();