mirror of https://github.com/apache/openjpa.git
OPENJPA-258
git-svn-id: https://svn.apache.org/repos/asf/openjpa/branches/1.0.x@617039 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ae0f7eea4f
commit
31b93870cf
|
@ -75,7 +75,13 @@ public class InheritanceComparator
|
|||
return 1;
|
||||
return c1.getName().compareTo(c2.getName());
|
||||
}
|
||||
return i1 - i2;
|
||||
int diff = i1 - i2;
|
||||
if (diff < 0)
|
||||
return -1;
|
||||
else if (diff > 0)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* 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 A extends AbstractThing {
|
||||
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* 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.MappedSuperclass;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Column;
|
||||
|
||||
@MappedSuperclass
|
||||
public class AbstractThing {
|
||||
|
||||
private String id;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(generator = "uuid-hex")
|
||||
@Column(columnDefinition = "char(32)")
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
void setId(final String id) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* 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.Set;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.OneToMany;
|
||||
|
||||
import org.apache.openjpa.meta.C;
|
||||
|
||||
@Entity
|
||||
public class B extends AbstractThing {
|
||||
private Set<C> cs;
|
||||
private Set<A> as;
|
||||
|
||||
@OneToMany
|
||||
public Set<C> getCs() {
|
||||
return cs;
|
||||
}
|
||||
|
||||
public void setCs(Set<C> cs) {
|
||||
this.cs = cs;
|
||||
}
|
||||
|
||||
@OneToMany
|
||||
public Set<A> getAs() {
|
||||
return as;
|
||||
}
|
||||
|
||||
public void setAs(Set<A> as) {
|
||||
this.as = as;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,101 @@
|
|||
/*
|
||||
* 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;
|
||||
import javax.persistence.IdClass;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Id;
|
||||
|
||||
import org.apache.openjpa.meta.C.Identity;
|
||||
|
||||
@Entity
|
||||
@IdClass(Identity.class)
|
||||
public class C {
|
||||
private A a;
|
||||
private B b;
|
||||
private long num;
|
||||
|
||||
@ManyToOne(optional = false)
|
||||
@Column(nullable = false)
|
||||
public A getA() {
|
||||
return a;
|
||||
}
|
||||
|
||||
public void setA(A a) {
|
||||
this.a = a;
|
||||
}
|
||||
|
||||
@Id
|
||||
@ManyToOne(optional = false)
|
||||
@Column(nullable = false)
|
||||
public B getB() {
|
||||
return b;
|
||||
}
|
||||
|
||||
public void setB(B b) {
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
@Id
|
||||
public long getNum() {
|
||||
return num;
|
||||
}
|
||||
|
||||
public void setNum(long num) {
|
||||
this.num = num;
|
||||
}
|
||||
|
||||
public static class Identity {
|
||||
private String b;
|
||||
private long num;
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return b.hashCode() * 17 + (int) num;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj != null && (obj instanceof Identity)
|
||||
&& b.equals(((Identity) obj).b) && num == ((Identity) obj).num;
|
||||
}
|
||||
|
||||
public String getB() {
|
||||
return b;
|
||||
}
|
||||
|
||||
public void setB(B b) {
|
||||
this.b = b.getId();
|
||||
}
|
||||
|
||||
public void setB(String b) {
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
public long getNum() {
|
||||
return num;
|
||||
}
|
||||
|
||||
public void setNum(long num) {
|
||||
this.num = num;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* 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.EntityManagerFactory;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.openjpa.persistence.test.PersistenceTestCase;
|
||||
import org.apache.openjpa.persistence.test.SingleEMFTestCase;
|
||||
import org.apache.openjpa.persistence.JPAFacadeHelper;
|
||||
|
||||
public class TestMetaDataInheritanceComparator extends PersistenceTestCase {
|
||||
|
||||
public void testMetaDataInheritanceComparator() {
|
||||
InheritanceComparator comp = new MetaDataInheritanceComparator();
|
||||
comp.setBase(AbstractThing.class);
|
||||
|
||||
EntityManagerFactory emf = createEMF(A.class, B.class, C.class,
|
||||
AbstractThing.class);
|
||||
|
||||
ClassMetaData a = JPAFacadeHelper.getMetaData(emf, A.class);
|
||||
ClassMetaData b = JPAFacadeHelper.getMetaData(emf, B.class);
|
||||
ClassMetaData c = JPAFacadeHelper.getMetaData(emf, C.class);
|
||||
|
||||
assertEquals(-1, comp.compare(a, b));
|
||||
assertEquals(-1, comp.compare(b, c));
|
||||
assertEquals(-1, comp.compare(a, c));
|
||||
}
|
||||
|
||||
public void testInheritanceComparator() {
|
||||
InheritanceComparator comp = new InheritanceComparator();
|
||||
comp.setBase(AbstractThing.class);
|
||||
|
||||
assertEquals(-1, comp.compare(A.class, B.class));
|
||||
assertEquals(-1, comp.compare(B.class, C.class));
|
||||
assertEquals(-1, comp.compare(A.class, C.class));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue