openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mik...@apache.org
Subject svn commit: r909127 - in /openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations: ./ entity/
Date Thu, 11 Feb 2010 19:58:15 GMT
Author: mikedd
Date: Thu Feb 11 19:58:14 2010
New Revision: 909127

URL: http://svn.apache.org/viewvc?rev=909127&view=rev
Log:
OPENJPA-1001: 
Testcase for IndexOutOfBounds problem.
Submitted By : Richard Rak

Added:
    openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestIncompleteRelationship.java
  (with props)
    openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/entity/
    openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/entity/IncompleteRelationshipChildEntity.java
  (with props)
    openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/entity/IncompleteRelationshipParentEntity.java
  (with props)
    openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/entity/IncompleteRelationshipSubclass.java
  (with props)

Added: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestIncompleteRelationship.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestIncompleteRelationship.java?rev=909127&view=auto
==============================================================================
--- openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestIncompleteRelationship.java
(added)
+++ openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestIncompleteRelationship.java
Thu Feb 11 19:58:14 2010
@@ -0,0 +1,84 @@
+/*
+ * 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.relations;
+
+import org.apache.openjpa.persistence.relations.entity.IncompleteRelationshipChildEntity;
+import org.apache.openjpa.persistence.relations.entity.IncompleteRelationshipParentEntity;
+import org.apache.openjpa.persistence.relations.entity.IncompleteRelationshipSubclass;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+import javax.persistence.EntityManager;
+
+/**
+ * A test case that tests for incomplete foreign-key relationships and ensures
+ * that proper database mechanics are enforced.
+ */
+public class TestIncompleteRelationship extends SingleEMFTestCase {
+    private static final String CLIENT_ID = "00000-00000-00000-00000-00000-00000";
+
+    private static final String DISCOUNTS[] = {
+        "Five-Finger Discount",
+        "Staff Discount"
+    };
+
+    @Override
+    public void setUp() {
+        super.setUp(CLEAR_TABLES,
+                    IncompleteRelationshipParentEntity.class,
+                    IncompleteRelationshipParentEntity.IncompleteRelationshipParentEntityPk.class,
+                    IncompleteRelationshipChildEntity.class,
+                    IncompleteRelationshipChildEntity.IncompleteRelationshipChildEntityPk.class,
+                    IncompleteRelationshipSubclass.class,
+                    "openjpa.jdbc.QuerySQLCache", "true", "openjpa.Log", "JDBC=TRACE,SQL=TRACE");
+    }
+
+    public void testIncompleteRelationship() {
+        final EntityManager em = emf.createEntityManager();
+        IncompleteRelationshipSubclass parent = null;
+        IncompleteRelationshipChildEntity child = null;
+
+        em.getTransaction().begin();
+        for (String s : DISCOUNTS) {
+            child = new IncompleteRelationshipChildEntity(s, CLIENT_ID);
+            em.persist(child);
+        }
+        em.getTransaction().commit();
+
+        for (int i = 1; i < 2; i++) {
+            em.getTransaction().begin();
+
+            parent = new IncompleteRelationshipSubclass(i, CLIENT_ID);
+
+            em.persist(parent);
+            em.getTransaction().commit();
+
+            parent = (IncompleteRelationshipSubclass)
+                    em.createQuery("SELECT i "+
+                                   "FROM IncompleteRelationshipSubclass i "+
+                                   "WHERE   i.pk.id = :id "+
+                                   "AND     i.pk.clientId = :clientId ")
+              .setParameter("id", i)
+              .setParameter("clientId", CLIENT_ID)
+              .getSingleResult();
+
+            assertEquals(parent.getPk().getId(), i);
+            assertNull(parent.getChild());
+        }
+    }
+}

Propchange: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestIncompleteRelationship.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/entity/IncompleteRelationshipChildEntity.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/entity/IncompleteRelationshipChildEntity.java?rev=909127&view=auto
==============================================================================
--- openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/entity/IncompleteRelationshipChildEntity.java
(added)
+++ openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/entity/IncompleteRelationshipChildEntity.java
Thu Feb 11 19:58:14 2010
@@ -0,0 +1,155 @@
+/*
+ * 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.relations.entity;
+
+import java.io.Serializable;
+import javax.persistence.Column;
+import javax.persistence.Embeddable;
+import javax.persistence.EmbeddedId;
+import javax.persistence.Entity;
+
+/**
+ * This is the child entity for the IncompleteRelationship test case.
+ */
+@Entity
+public class IncompleteRelationshipChildEntity implements Serializable {
+    private static final long serialVersionUID = 1L;
+    
+    @Embeddable
+    public static class IncompleteRelationshipChildEntityPk implements Serializable {
+        private static final long serialVersionUID = 1L;
+        
+        @Column(name = "DISCOUNT", nullable = false, length = 120)
+        protected String discount;
+        @Column(name = "CLIENT_ID", nullable = false, length = 35)
+        protected String clientId;
+
+        public IncompleteRelationshipChildEntityPk() {
+        }
+
+        public IncompleteRelationshipChildEntityPk(String discount, String clientId) {
+            this.discount = discount;
+            this.clientId = clientId;
+        }
+
+        public String getClientId() {
+            return clientId;
+        }
+
+        public void setClientId(String clientId) {
+            this.clientId = clientId;
+        }
+
+        public String getDiscount() {
+            return discount;
+        }
+
+        public void setDiscount(String discount) {
+            this.discount = discount;
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            if (obj == null) {
+                return false;
+            }
+            if (getClass() != obj.getClass()) {
+                return false;
+            }
+            final IncompleteRelationshipChildEntityPk other = (IncompleteRelationshipChildEntityPk)
obj;
+            if ((this.discount == null) ? (other.discount != null) : !this.discount.equals(other.discount))
{
+                return false;
+            }
+            if ((this.clientId == null) ? (other.clientId != null) : !this.clientId.equals(other.clientId))
{
+                return false;
+            }
+            return true;
+        }
+
+        @Override
+        public int hashCode() {
+            int hash = 5;
+            hash = 53 * hash + (this.discount != null ? this.discount.hashCode() : 0);
+            hash = 53 * hash + (this.clientId != null ? this.clientId.hashCode() : 0);
+            return hash;
+        }
+
+        @Override
+        public String toString() {
+            return "IncompleteRelationshipChildEntityPk[discount="+discount+","+
+                    "clientId="+clientId+"]";
+        }
+    }
+
+    @EmbeddedId
+    protected IncompleteRelationshipChildEntityPk pk;
+
+    public IncompleteRelationshipChildEntity() {
+    }
+
+    public IncompleteRelationshipChildEntity(IncompleteRelationshipChildEntityPk pk) {
+        this.pk = pk;
+    }
+
+    public IncompleteRelationshipChildEntity(String discount, String clientId) {
+        this(new IncompleteRelationshipChildEntityPk(discount, clientId));
+    }
+
+    public IncompleteRelationshipChildEntityPk getPk() {
+        return pk;
+    }
+
+    public void setPk(IncompleteRelationshipChildEntityPk pk) {
+        this.pk = pk;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (obj == null) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        final IncompleteRelationshipChildEntity other = (IncompleteRelationshipChildEntity)
obj;
+        if (this.pk != other.pk && (this.pk == null || !this.pk.equals(other.pk)))
{
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    public int hashCode() {
+        if (this.pk != null) {
+            return pk.hashCode();
+        } else {
+            return 0;
+        }
+    }
+
+    @Override
+    public String toString() {
+        if (this.pk != null) {
+            return pk.toString();
+        } else {
+            return "IncompleteRelationshipChildEntity[pk=null]";
+        }
+    }
+}

Propchange: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/entity/IncompleteRelationshipChildEntity.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/entity/IncompleteRelationshipParentEntity.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/entity/IncompleteRelationshipParentEntity.java?rev=909127&view=auto
==============================================================================
--- openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/entity/IncompleteRelationshipParentEntity.java
(added)
+++ openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/entity/IncompleteRelationshipParentEntity.java
Thu Feb 11 19:58:14 2010
@@ -0,0 +1,177 @@
+/*
+ * 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.relations.entity;
+
+import java.io.Serializable;
+
+import javax.persistence.Column;
+import javax.persistence.Embeddable;
+import javax.persistence.EmbeddedId;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.JoinColumn;
+import javax.persistence.JoinColumns;
+import javax.persistence.ManyToOne;
+
+/**
+ * This is the parent entity for the IncompleteRelationship test case.
+ */
+@Entity
+@Inheritance(strategy = InheritanceType.JOINED)
+public class IncompleteRelationshipParentEntity implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    @Embeddable
+    public static class IncompleteRelationshipParentEntityPk implements Serializable {
+        private static final long serialVersionUID = 1L;
+
+        @Column(name = "ID", nullable = false, precision = 9)
+        protected int id;
+        @Column(name = "CLIENT_ID", nullable = false, length = 35)
+        protected String clientId;
+
+        public IncompleteRelationshipParentEntityPk() {
+        }
+
+        public IncompleteRelationshipParentEntityPk(int id, String clientId) {
+            this.id = id;
+            this.clientId = clientId;
+        }
+
+        public String getClientId() {
+            return clientId;
+        }
+
+        public void setClientId(String clientId) {
+            this.clientId = clientId;
+        }
+
+        public void setId(int id) {
+            this.id = id;
+        }
+
+        public int getId() {
+            return id;
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            if (obj == null) {
+                return false;
+            }
+            if (getClass() != obj.getClass()) {
+                return false;
+            }
+            final IncompleteRelationshipParentEntityPk other = (IncompleteRelationshipParentEntityPk)
obj;
+            if (this.id != other.id) {
+                return false;
+            }
+            if ((this.clientId == null) ? (other.clientId != null) : !this.clientId.equals(other.clientId))
{
+                return false;
+            }
+            return true;
+        }
+
+        @Override
+        public int hashCode() {
+            int hash = 7;
+            hash = 89 * hash + (this.id);
+            hash = 89 * hash + (this.clientId != null ? this.clientId.hashCode() : 0);
+            return hash;
+        }
+
+        @Override
+        public String toString() {
+            return "IncompleteRelationshipParentEntityPk[id="+id+","+
+                    "clientId="+clientId+"]";
+        }
+    }
+
+    @EmbeddedId
+    protected IncompleteRelationshipParentEntityPk pk;
+    @JoinColumns({
+        @JoinColumn(name = "DEFAULT_DISCOUNT", referencedColumnName = "DISCOUNT"),
+        @JoinColumn(name = "CLIENT_ID", referencedColumnName = "CLIENT_ID")
+    })
+    @ManyToOne(fetch = FetchType.LAZY)
+    protected IncompleteRelationshipChildEntity child;
+
+    public IncompleteRelationshipParentEntity() {
+    }
+
+    public IncompleteRelationshipParentEntity(IncompleteRelationshipParentEntityPk pk) {
+        this.pk = pk;
+    }
+
+    public IncompleteRelationshipParentEntity(int id, String clientId) {
+        this(new IncompleteRelationshipParentEntityPk(id, clientId));
+    }
+
+    public IncompleteRelationshipChildEntity getChild() {
+        return child;
+    }
+
+    public void setChild(IncompleteRelationshipChildEntity child) {
+        this.child = child;
+    }
+
+    public IncompleteRelationshipParentEntityPk getPk() {
+        return pk;
+    }
+
+    public void setPk(IncompleteRelationshipParentEntityPk pk) {
+        this.pk = pk;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (obj == null) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        final IncompleteRelationshipParentEntity other = (IncompleteRelationshipParentEntity)
obj;
+        if (this.pk != other.pk && (this.pk == null || !this.pk.equals(other.pk)))
{
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    public int hashCode() {
+        if (this.pk != null) {
+            return pk.hashCode();
+        } else {
+            return 0;
+        }
+    }
+
+    @Override
+    public String toString() {
+        if (this.pk != null) {
+            return pk.toString();
+        } else {
+            return "IncompleteRelationshipParentEntity[pk=null]";
+        }
+    }
+}

Propchange: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/entity/IncompleteRelationshipParentEntity.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/entity/IncompleteRelationshipSubclass.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/entity/IncompleteRelationshipSubclass.java?rev=909127&view=auto
==============================================================================
--- openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/entity/IncompleteRelationshipSubclass.java
(added)
+++ openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/entity/IncompleteRelationshipSubclass.java
Thu Feb 11 19:58:14 2010
@@ -0,0 +1,42 @@
+/*
+ * 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.relations.entity;
+
+import javax.persistence.Entity;
+
+/**
+ * This class simply extends IncompleteRelationshipParentEntity.
+ */
+@Entity
+public class IncompleteRelationshipSubclass
+        extends IncompleteRelationshipParentEntity {
+    private static final long serialVersionUID = 1L;
+
+    public IncompleteRelationshipSubclass(int id, String clientId) {
+        super(id, clientId);
+    }
+
+    public IncompleteRelationshipSubclass(IncompleteRelationshipParentEntityPk pk) {
+        super(pk);
+    }
+
+    public IncompleteRelationshipSubclass() {
+    }
+}

Propchange: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/entity/IncompleteRelationshipSubclass.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message