mirror of https://github.com/apache/openjpa.git
OPENJPA-536. Committing on behalf of Amy Yang.
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@644115 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
79b23557d3
commit
999ce2e670
|
@ -39,6 +39,10 @@ public class InheritanceComparator
|
|||
_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.
|
||||
|
|
|
@ -574,6 +574,7 @@ public class MetaDataRepository
|
|||
* 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();
|
||||
|
@ -616,6 +617,27 @@ public class MetaDataRepository
|
|||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load mapping information for the given metadata.
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue