openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p..@apache.org
Subject svn commit: r644115 - in /openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/meta/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/
Date Thu, 03 Apr 2008 00:01:54 GMT
Author: pcl
Date: Wed Apr  2 17:01:47 2008
New Revision: 644115

URL: http://svn.apache.org/viewvc?rev=644115&view=rev
Log:
OPENJPA-536. Committing on behalf of Amy Yang.

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Artist.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Item.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Painter.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Person.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/TestGetMetaData.java
Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/InheritanceComparator.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/InheritanceComparator.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/InheritanceComparator.java?rev=644115&r1=644114&r2=644115&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/InheritanceComparator.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/InheritanceComparator.java
Wed Apr  2 17:01:47 2008
@@ -39,6 +39,10 @@
         _base = base;
     }
 
+    public Class getBase() {
+        return _base;
+    }
+
     /**
      * Subclasses can override this method to extract the class to compare
      * on from the elements of the collection.

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java?rev=644115&r1=644114&r2=644115&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
Wed Apr  2 17:01:47 2008
@@ -574,6 +574,7 @@
      * if we're still in the process of resolving other metadatas.
      */
     private List resolveMeta(ClassMetaData meta) {
+    	setBaseIfNecessary(meta);
         if (meta.getPCSuperclass() == null) {
             // set superclass
             Class sup = meta.getDescribedType().getSuperclass();
@@ -615,6 +616,27 @@
         // others, this will return the set of interrelated metas that
         // resolved
         return processBuffer(meta, _resolving, MODE_META);
+    }
+    
+    private void setBaseIfNecessary(ClassMetaData meta) {
+        if (_resolving == null)
+            return;
+
+        InheritanceComparator comp =
+            (InheritanceComparator) _resolving.comparator();
+        if (meta.getPCSuperclass() == null) {
+            Class sup = meta.getDescribedType().getSuperclass();
+            Class pBase = null;
+            while (sup != null && sup != Object.class) {
+                pBase = sup;
+                sup = sup.getSuperclass();
+            }
+            if (pBase != null && !pBase.equals(comp.getBase())) {
+                // setBase() can be called because getMetaData() is
+                // syncronized
+                comp.setBase(pBase);
+            }
+        }
     }
 
     /**

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Artist.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Artist.java?rev=644115&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Artist.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Artist.java
Wed Apr  2 17:01:47 2008
@@ -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.meta;
+
+import javax.persistence.Entity;
+
+@Entity
+public class Artist
+    extends Person {
+
+    /**
+     * Default constructor required for enhancement.
+     */
+    public Artist() {
+        super();
+    }
+
+    /**
+     * The public constructor constructs with a name.
+     *
+     * @param name the name of the artist.
+     */
+    public Artist(String name) {
+        super(name);
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Item.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Item.java?rev=644115&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Item.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Item.java
Wed Apr  2 17:01:47 2008
@@ -0,0 +1,110 @@
+/*
+ * 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.meta;
+
+import java.io.Serializable;
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+
+@Entity
+public class Item implements Serializable {
+
+    @Id
+    @GeneratedValue
+    private int id;
+
+    private String title;
+
+    @ManyToOne(cascade = CascadeType.PERSIST)
+    private Artist artist;
+
+    /**
+     * A no-arg constructor is required for enhancement.
+     */
+    protected Item() {
+        super();
+    }
+
+    /**
+     * The public constructor constructs with a title.
+     *
+     * @param title the title of the item.
+     */
+    public Item(String title) {
+        super();
+        this.title = title;
+    }
+
+    /**
+     * Gets the unique identifier of this receiver. There is no corresponding
+     * <code>setId()</code> method as the identifier value is generated by the
+     * Persistence Provider Runtime.
+     *
+     * @return unique identifier of this instance.
+     */
+    public int getId() {
+        return id;
+    }
+
+    /**
+     * Gets the title of this item.
+     *
+     * @return return the tile of the item.
+     */
+    public String getTitle() {
+        return title;
+    }
+
+    /**
+     * Sets the title of this receiver.
+     *
+     * @param title must not be null or empty.
+     */
+    public void setTitle(String title) {
+        if (title == null || title.trim().length() == 0)
+            throw new IllegalArgumentException(
+                "null or empty title not allowed");
+        this.title = title;
+    }
+
+    /**
+     * Gets the artist who created this item. This is an example of
+     * unidirectional single-valued relationship.
+     *
+     * @return the artist who created this item.
+     */
+    public Artist getArtist() {
+        return artist;
+    }
+
+    /**
+     * Sets the artist who created this Item.
+     *
+     * @param artist must not be null.
+     */
+    public void setArtist(Artist artist) {
+        if (artist == null)
+            throw new IllegalArgumentException("null Artist for " + this);
+
+        this.artist = artist;
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Painter.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Painter.java?rev=644115&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Painter.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Painter.java
Wed Apr  2 17:01:47 2008
@@ -0,0 +1,33 @@
+/*
+ * 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.meta;
+
+import javax.persistence.Entity;
+
+@Entity
+public class Painter extends Artist {
+
+    public Painter() {
+        super();
+    }
+
+    public Painter(String name) {
+        super(name);
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Person.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Person.java?rev=644115&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Person.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Person.java
Wed Apr  2 17:01:47 2008
@@ -0,0 +1,78 @@
+/*
+ * 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.meta;
+
+import java.io.Serializable;
+import java.util.Collection;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+
+@Entity
+public class Person implements Serializable {
+
+    @Id
+    private String name;
+
+    @OneToMany
+    private Collection<Painter> paitersForPortrait;
+
+    /**
+     * default constructor required by enhancement.
+     */
+    protected Person() {
+
+    }
+
+    /**
+     * The public constructor constructs with a name.
+     *
+     * @param name the name of the person.
+     */
+
+    public Person(String name) {
+        this.name = name;
+    }
+
+    /**
+     * Gets the name of this person. This is the unique identifier.
+     *
+     * @return return the name of this person.
+     */
+    public String getName() {
+
+        return name;
+    }
+
+    public void setName(String name) {
+        if (name == null || name.trim().length() == 0)
+            throw new IllegalArgumentException(
+                "null or empty name not allowed");
+        this.name = name;
+    }
+
+    public Collection<Painter> getPainters() {
+
+        return paitersForPortrait;
+    }
+
+    public void setPainters(Collection<Painter> p) {
+        this.paitersForPortrait = p;
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/TestGetMetaData.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/TestGetMetaData.java?rev=644115&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/TestGetMetaData.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/TestGetMetaData.java
Wed Apr  2 17:01:47 2008
@@ -0,0 +1,35 @@
+/*
+ * 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.meta;
+
+import org.apache.openjpa.persistence.JPAFacadeHelper;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+public class TestGetMetaData extends SingleEMFTestCase {
+
+    public void setUp() {
+        setUp(Item.class, Person.class, Artist.class, Painter.class,
+            CLEAR_TABLES);
+    }
+
+    public void testGetMetaData() {
+        assertNotNull(JPAFacadeHelper.getMetaData(emf, Item.class));
+        assertNotNull(JPAFacadeHelper.getMetaData(emf, Person.class));
+    }
+}



Mime
View raw message