You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by dw...@apache.org on 2009/09/14 19:09:44 UTC

svn commit: r814737 - in /openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compatible: ./ EmbeddableSuper.java EmbeddableSuperSub.java TestEmbeddableSuperclass.java

Author: dwoods
Date: Mon Sep 14 17:09:44 2009
New Revision: 814737

URL: http://svn.apache.org/viewvc?rev=814737&view=rev
Log:
OPENJPA-1214 Testcase to demonstrate RelationFieldStrategy behaviour differences between OpenJPA 1.x and 2.0.  Testcase contributed by Tim McConnell.

Added:
    openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compatible/
    openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compatible/EmbeddableSuper.java   (with props)
    openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compatible/EmbeddableSuperSub.java   (with props)
    openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compatible/TestEmbeddableSuperclass.java   (with props)

Added: openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compatible/EmbeddableSuper.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compatible/EmbeddableSuper.java?rev=814737&view=auto
==============================================================================
--- openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compatible/EmbeddableSuper.java (added)
+++ openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compatible/EmbeddableSuper.java Mon Sep 14 17:09:44 2009
@@ -0,0 +1,77 @@
+/*
+ * 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.compatible;
+
+
+import javax.persistence.*;
+
+@MappedSuperclass
+public class EmbeddableSuper {
+
+    @Id
+    @GeneratedValue
+    @Column(name = "ID")
+    private long pk;
+
+    @Version
+    @Column(name = "SUPVERS")
+    private int version;
+
+    @Transient
+    private int trans;
+
+    @Lob
+    @Column(name = "CLOBVAL")
+    protected String clob;
+
+    public EmbeddableSuper() {
+    }
+
+    public long getPK() {
+        return this.pk;
+    }
+
+    public void setPK(long pk) {
+        this.pk = pk;
+    }
+
+    public int getTrans() {
+        return this.trans;
+    }
+
+    public void setTrans(int trans) {
+        this.trans = trans;
+    }
+
+    public String getClob() {
+        return this.clob;
+    }
+
+    public void setClob(String clob) {
+        this.clob = clob;
+    }
+
+    public int getVersion() {
+        return this.version;
+    }
+
+    public void setVersion(int version) {
+        this.version = version;
+    }
+}

Propchange: openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compatible/EmbeddableSuper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compatible/EmbeddableSuperSub.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compatible/EmbeddableSuperSub.java?rev=814737&view=auto
==============================================================================
--- openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compatible/EmbeddableSuperSub.java (added)
+++ openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compatible/EmbeddableSuperSub.java Mon Sep 14 17:09:44 2009
@@ -0,0 +1,58 @@
+/*
+ * 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.compatible;
+
+
+import javax.persistence.*;
+
+@Entity
+@DiscriminatorColumn(name = "DISC")
+@AttributeOverrides({
+    @AttributeOverride(name = "clob", column = @Column(name = "CC")),
+    @AttributeOverride(name = "version", column = @Column(name = "VERSVAL"))
+})
+public class EmbeddableSuperSub
+    extends EmbeddableSuper {
+
+    @ManyToOne
+    private EmbeddableSuperSub sub;
+
+    @ManyToOne
+    // #####
+    private EmbeddableSuper sup;
+
+    public EmbeddableSuperSub() {
+    }
+
+    public EmbeddableSuperSub getSub() {
+        return this.sub;
+    }
+
+    public void setSub(EmbeddableSuperSub sub) {
+        this.sub = sub;
+    }
+
+    public EmbeddableSuper getSup() {
+        return this.sup;
+    }
+
+    public void setSup(EmbeddableSuper sup) {
+        this.sup = sup;
+    }
+}

Propchange: openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compatible/EmbeddableSuperSub.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compatible/TestEmbeddableSuperclass.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compatible/TestEmbeddableSuperclass.java?rev=814737&view=auto
==============================================================================
--- openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compatible/TestEmbeddableSuperclass.java (added)
+++ openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compatible/TestEmbeddableSuperclass.java Mon Sep 14 17:09:44 2009
@@ -0,0 +1,72 @@
+/*
+ * 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.compatible;
+
+import java.sql.Types;
+
+import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
+import org.apache.openjpa.jdbc.meta.ClassMapping;
+import org.apache.openjpa.jdbc.meta.FieldMapping;
+import org.apache.openjpa.jdbc.meta.strats.ClobValueHandler;
+import org.apache.openjpa.jdbc.meta.strats.FullClassStrategy;
+import org.apache.openjpa.jdbc.meta.strats.MaxEmbeddedClobFieldStrategy;
+import org.apache.openjpa.jdbc.meta.strats.NoneClassStrategy;
+import org.apache.openjpa.jdbc.meta.strats.RelationFieldStrategy;
+import org.apache.openjpa.jdbc.meta.strats.StringFieldStrategy;
+import org.apache.openjpa.jdbc.sql.DBDictionary;
+import org.apache.openjpa.meta.ValueStrategies;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+/**
+ * <p>Test embeddable superclasses</p>
+ *
+ *
+ * <b>Compatible testcases</b> are used to test various backwards compatibility scenarios between JPA 2.0 and JPA 1.2
+ * 
+ * <p>The following scenarios are tested:
+ * <ol>
+ * <li>RelationFieldStrategy
+ * </ol>
+ * <p> 
+ * <b>Note(s):</b>
+ * <ul>
+ * <li>The proper openjpa.Compatibility value(s) must be provided in order for the testcase(s) to succeed
+ * </ul>
+ */
+public class TestEmbeddableSuperclass
+    extends SingleEMFTestCase {
+
+    public void setUp() {
+        setUp(EmbeddableSuper.class, EmbeddableSuperSub.class, CLEAR_TABLES);
+    }
+
+    public void testRelationMappings() {
+        JDBCConfiguration conf = (JDBCConfiguration) emf.getConfiguration();
+        ClassMapping cls = conf.getMappingRepositoryInstance().
+            getMapping(EmbeddableSuperSub.class, null, true);
+        FieldMapping fm = cls.getFieldMapping("sub");
+        assertTrue(fm.getStrategy() instanceof RelationFieldStrategy);
+
+        fm = cls.getFieldMapping("sup");
+        // OPENJPA-1214 - Starting with OpenJPA 2, the below will return
+        // an EmbedFieldStrategy instead.
+        assertTrue(fm.getStrategy() instanceof RelationFieldStrategy);
+    } 
+}

Propchange: openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compatible/TestEmbeddableSuperclass.java
------------------------------------------------------------------------------
    svn:eol-style = native