Author: mikedd
Date: Thu Jan 29 21:02:22 2009
New Revision: 739012

URL: http://svn.apache.org/viewvc?rev=739012&view=rev
Log:
OPENJPA-536 committing patch provided by Joe Grassel

Added:
    
openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/InheritanceOrderedMetaDataList.java
   (with props)
    
openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Artist.java
   (with props)
    
openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Item.java
   (with props)
    
openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Painter.java
   (with props)
    
openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Person.java
   (with props)
    
openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/TestGetMetaData.java
   (with props)
Modified:
    
openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/InheritanceComparator.java
    
openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
    
openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/TestMetaDataInheritanceComparator.java

Modified: 
openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/InheritanceComparator.java
URL: 
http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/InheritanceComparator.java?rev=739012&r1=739011&r2=739012&view=diff
==============================================================================
--- 
openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/InheritanceComparator.java
 (original)
+++ 
openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/InheritanceComparator.java
 Thu Jan 29 21:02:22 2009
@@ -30,7 +30,7 @@
 public class InheritanceComparator
     implements Comparator, Serializable {
 
-    private Class _base = null;
+    private Class _base = Object.class;
 
     /**
      * Set the least-derived type possible; defaults to <code>null</code>.
@@ -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.

Added: 
openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/InheritanceOrderedMetaDataList.java
URL: 
http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/InheritanceOrderedMetaDataList.java?rev=739012&view=auto
==============================================================================
--- 
openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/InheritanceOrderedMetaDataList.java
 (added)
+++ 
openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/InheritanceOrderedMetaDataList.java
 Thu Jan 29 21:02:22 2009
@@ -0,0 +1,74 @@
+/*
+ * 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.util.Iterator;
+import java.util.LinkedList;
+import java.util.ListIterator;
+import java.io.Serializable;
+
+public class InheritanceOrderedMetaDataList
+    implements Serializable {
+
+    private MetaDataInheritanceComparator _comp
+        = new MetaDataInheritanceComparator();
+    private LinkedList buffer = new LinkedList();
+
+    public boolean add(ClassMetaData meta) {
+        if (meta == null || buffer.contains(meta))
+            return false;
+        for (ListIterator itr = buffer.listIterator();
+            itr.hasNext();) {
+            int ord = _comp.compare(meta, (ClassMetaData) itr.next());
+            if (ord > 0)
+                continue;
+            if (ord == 0)
+                return false;
+            itr.previous();
+            itr.add(meta);
+            return true;
+        }
+        buffer.add(meta);
+        return true;
+    }
+
+    public boolean remove(ClassMetaData meta) {
+        return buffer.remove(meta);
+    }
+
+    public ClassMetaData peek() {
+        return (ClassMetaData) buffer.getFirst();
+    }
+    
+    public int size() {
+        return buffer.size();
+    }
+    
+    public Iterator iterator() {
+        return buffer.iterator();
+    }
+    
+    public boolean isEmpty() {
+        return buffer.isEmpty();
+    }
+    
+    public void clear() {
+        buffer.clear();
+    }
+}

Propchange: 
openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/InheritanceOrderedMetaDataList.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
URL: 
http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java?rev=739012&r1=739011&r2=739012&view=diff
==============================================================================
--- 
openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
 (original)
+++ 
openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
 Thu Jan 29 21:02:22 2009
@@ -30,7 +30,6 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.SortedSet;
 import java.util.TreeSet;
 
 import org.apache.commons.lang.StringUtils;
@@ -135,10 +134,10 @@
     private final Collection _registered = new ArrayList();
 
     // set of metadatas we're in the process of resolving
-    private final SortedSet _resolving = new TreeSet
-        (new MetaDataInheritanceComparator());
-    private final SortedSet _mapping = new TreeSet
-        (new MetaDataInheritanceComparator());
+    private final InheritanceOrderedMetaDataList _resolving =
+        new InheritanceOrderedMetaDataList();
+    private final InheritanceOrderedMetaDataList _mapping =
+        new InheritanceOrderedMetaDataList();
     private final List _errs = new LinkedList();
 
     // system listeners
@@ -655,7 +654,8 @@
     /**
      * Process the given metadata and the associated buffer.
      */
-    private List processBuffer(ClassMetaData meta, SortedSet buffer, int mode) 
{
+    private List processBuffer(ClassMetaData meta,
+        InheritanceOrderedMetaDataList buffer, int mode) {
         // if we're already processing a metadata, just buffer this one; when
         // the initial metadata finishes processing, we traverse the buffer
         // and process all the others that were introduced during reentrant
@@ -670,7 +670,7 @@
         ClassMetaData buffered;
         List processed = new ArrayList(5);
         while (!buffer.isEmpty()) {
-            buffered = (ClassMetaData) buffer.first();
+            buffered = buffer.peek();
             try {
                 buffered.resolve(mode);
                 processed.add(buffered);

Added: 
openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Artist.java
URL: 
http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Artist.java?rev=739012&view=auto
==============================================================================
--- 
openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Artist.java
 (added)
+++ 
openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Artist.java
 Thu Jan 29 21:02:22 2009
@@ -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);
+    }
+}

Propchange: 
openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Artist.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Item.java
URL: 
http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Item.java?rev=739012&view=auto
==============================================================================
--- 
openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Item.java
 (added)
+++ 
openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Item.java
 Thu Jan 29 21:02:22 2009
@@ -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;
+    }
+}

Propchange: 
openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Item.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Painter.java
URL: 
http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Painter.java?rev=739012&view=auto
==============================================================================
--- 
openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Painter.java
 (added)
+++ 
openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Painter.java
 Thu Jan 29 21:02:22 2009
@@ -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);
+    }
+}

Propchange: 
openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Painter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Person.java
URL: 
http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Person.java?rev=739012&view=auto
==============================================================================
--- 
openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Person.java
 (added)
+++ 
openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Person.java
 Thu Jan 29 21:02:22 2009
@@ -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;
+    }
+}

Propchange: 
openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Person.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/TestGetMetaData.java
URL: 
http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/TestGetMetaData.java?rev=739012&view=auto
==============================================================================
--- 
openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/TestGetMetaData.java
 (added)
+++ 
openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/TestGetMetaData.java
 Thu Jan 29 21:02:22 2009
@@ -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));
+    }
+}

Propchange: 
openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/TestGetMetaData.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/TestMetaDataInheritanceComparator.java
URL: 
http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/TestMetaDataInheritanceComparator.java?rev=739012&r1=739011&r2=739012&view=diff
==============================================================================
--- 
openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/TestMetaDataInheritanceComparator.java
 (original)
+++ 
openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/TestMetaDataInheritanceComparator.java
 Thu Jan 29 21:02:22 2009
@@ -25,10 +25,6 @@
 
 public class TestMetaDataInheritanceComparator extends PersistenceTestCase {
 
-    public void testInheritanceComparatorWithoutBase() {
-        inheritanceComparatorHelper(false);
-    }
-
     public void testInheritanceComparatorWithBase() {
         inheritanceComparatorHelper(true);
     }
@@ -47,10 +43,6 @@
         assertTrue(comp.compare(AbstractThing.class, C.class) < 0);
     }
 
-    public void testMetaDataInheritanceComparatorWithoutBase() {
-        metaDataInheritanceComparatorHelper(false);
-    }
-
     public void testMetaDataInheritanceComparatorWithBase() {
         metaDataInheritanceComparatorHelper(true);
     }


Reply via email to