OPENJPA-1028 OPENJPA-1021 fix eol style for new classes

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@763677 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Dick 2009-04-09 15:07:33 +00:00
parent be8731aafa
commit 3b2585f39b
10 changed files with 1154 additions and 1154 deletions

View File

@ -1,65 +1,65 @@
/*
* 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.embed;
import javax.persistence.Embeddable;
import javax.persistence.OneToOne;
@Embeddable
public class Embed_MappedToOne {
protected String name1;
protected String name2;
protected String name3;
@OneToOne(mappedBy="entityA")
protected EntityB1 bm;
public String getName1() {
return name1;
}
public void setName1(String name1) {
this.name1 = name1;
}
public String getName2() {
return name2;
}
public void setName2(String name2) {
this.name2 = name2;
}
public String getName3() {
return name3;
}
public void setName3(String name3) {
this.name3 = name3;
}
public void setMappedEntityB(EntityB1 bm) {
this.bm = bm;
}
public EntityB1 getMappedEntityB() {
return bm;
}
}
/*
* 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.embed;
import javax.persistence.Embeddable;
import javax.persistence.OneToOne;
@Embeddable
public class Embed_MappedToOne {
protected String name1;
protected String name2;
protected String name3;
@OneToOne(mappedBy="entityA")
protected EntityB1 bm;
public String getName1() {
return name1;
}
public void setName1(String name1) {
this.name1 = name1;
}
public String getName2() {
return name2;
}
public void setName2(String name2) {
this.name2 = name2;
}
public String getName3() {
return name3;
}
public void setName3(String name3) {
this.name3 = name3;
}
public void setMappedEntityB(EntityB1 bm) {
this.bm = bm;
}
public EntityB1 getMappedEntityB() {
return bm;
}
}

View File

@ -1,75 +1,75 @@
/*
* 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.embed;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
@Entity
public class EntityA_Embed_MappedToOne implements Serializable {
@Id
Integer id;
@Column(length=30)
String name;
@Basic(fetch=FetchType.LAZY)
int age;
@Embedded
protected Embed_MappedToOne embed;
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Embed_MappedToOne getEmbed() {
return embed;
}
public void setEmbed(Embed_MappedToOne embed) {
this.embed = embed;
}
}
/*
* 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.embed;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
@Entity
public class EntityA_Embed_MappedToOne implements Serializable {
@Id
Integer id;
@Column(length=30)
String name;
@Basic(fetch=FetchType.LAZY)
int age;
@Embedded
protected Embed_MappedToOne embed;
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Embed_MappedToOne getEmbed() {
return embed;
}
public void setEmbed(Embed_MappedToOne embed) {
this.embed = embed;
}
}

View File

@ -1,60 +1,60 @@
/*
* 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.jdbc.maps.spec_10_1_27_ex6;
import java.util.HashMap;
import java.util.Map;
import javax.persistence.*;
@Entity
@Table(name="S27x6Comp")
public class Company {
@Id
int id;
@OneToMany
@MapKey(name="div")
Map<Division, VicePresident> organization =
new HashMap<Division, VicePresident>();
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public Map getOrganization() {
return organization;
}
public void addToOrganization(VicePresident vp) {
organization.put(vp.getDivision(), vp);
}
public void removeFromOrganization(Division d) {
organization.remove(d);
}
public VicePresident getOrganization(Division d) {
return organization.get(d);
}
}
/*
* 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.jdbc.maps.spec_10_1_27_ex6;
import java.util.HashMap;
import java.util.Map;
import javax.persistence.*;
@Entity
@Table(name="S27x6Comp")
public class Company {
@Id
int id;
@OneToMany
@MapKey(name="div")
Map<Division, VicePresident> organization =
new HashMap<Division, VicePresident>();
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public Map getOrganization() {
return organization;
}
public void addToOrganization(VicePresident vp) {
organization.put(vp.getDivision(), vp);
}
public void removeFromOrganization(Division d) {
organization.remove(d);
}
public VicePresident getOrganization(Division d) {
return organization.get(d);
}
}

View File

@ -1,63 +1,63 @@
/*
* 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.jdbc.maps.spec_10_1_27_ex6;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name="S27x6Div")
public class Division {
@Id
int id;
String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public boolean equals(Object o) {
Division d = (Division) o;
if (d.name.equals(name) &&
d.getId() == id)
return true;
return false;
}
public int hashCode() {
int ret = 0;
ret = ret * 31 + name.hashCode();
ret = ret *31 + id;
return ret;
}
}
/*
* 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.jdbc.maps.spec_10_1_27_ex6;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name="S27x6Div")
public class Division {
@Id
int id;
String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public boolean equals(Object o) {
Division d = (Division) o;
if (d.name.equals(name) &&
d.getId() == id)
return true;
return false;
}
public int hashCode() {
int ret = 0;
ret = ret * 31 + name.hashCode();
ret = ret *31 + id;
return ret;
}
}

View File

@ -1,293 +1,293 @@
/*
* 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.jdbc.maps.spec_10_1_27_ex6;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Query;
import junit.framework.Assert;
import org.apache.openjpa.kernel.QueryImpl;
import org.apache.openjpa.persistence.test.AllowFailure;
import org.apache.openjpa.persistence.test.SQLListenerTestCase;
public class TestSpec10_1_27_Ex6 extends SQLListenerTestCase {
public int numCompany = 2;
public int numDivisionsPerCo = 2;
public int compId = 1;
public int divId = 1;
public int vpId = 1;
public int newDivId = 100;
public int newVpId = 100;
public List rsAllCompany = null;
public void setUp() {
super.setUp(CLEAR_TABLES,
Company.class,
Division.class,
VicePresident.class);
createObj(emf);
rsAllCompany = getAll(Company.class);
}
public void testQueryObj() throws Exception {
queryObj(emf);
}
@AllowFailure
public void testQueryInMemoryQualifiedId() throws Exception {
queryQualifiedId(true);
}
@AllowFailure
public void testQueryQualifiedId() throws Exception {
queryQualifiedId(false);
}
public void setCandidate(Query q, Class clz)
throws Exception {
org.apache.openjpa.persistence.QueryImpl q1 =
(org.apache.openjpa.persistence.QueryImpl) q;
org.apache.openjpa.kernel.Query q2 = q1.getDelegate();
org.apache.openjpa.kernel.QueryImpl qi = (QueryImpl) q2;
if (clz == Company.class)
qi.setCandidateCollection(rsAllCompany);
}
public void queryQualifiedId(boolean inMemory) throws Exception {
EntityManager em = emf.createEntityManager();
String query = "select KEY(e) from Company c, " +
" in (c.organization) e order by c.id";
Query q = em.createQuery(query);
if (inMemory)
setCandidate(q, Company.class);
List rs = q.getResultList();
Division d = (Division) rs.get(0);
em.clear();
query = "select ENTRY(e) from Company c, " +
" in (c.organization) e order by c.id";
q = em.createQuery(query);
if (inMemory)
setCandidate(q, Company.class);
rs = q.getResultList();
Map.Entry me = (Map.Entry) rs.get(0);
assertTrue(d.equals(me.getKey()));
em.clear();
query = "select KEY(e) from Company c " +
" left join c.organization e order by c.id";
q = em.createQuery(query);
if (inMemory)
setCandidate(q, Company.class);
rs = q.getResultList();
d = (Division) rs.get(0);
em.clear();
query = "select ENTRY(e) from Company c " +
" left join c.organization e order by c.id";
q = em.createQuery(query);
if (inMemory)
setCandidate(q, Company.class);
rs = q.getResultList();
me = (Map.Entry) rs.get(0);
assertTrue(d.equals(me.getKey()));
em.close();
}
public void createObj(EntityManagerFactory emf) {
EntityManager em = emf.createEntityManager();
EntityTransaction tran = em.getTransaction();
for (int i = 0; i < numCompany; i++)
createCompany(em, compId++);
tran.begin();
em.flush();
tran.commit();
em.close();
}
public void createCompany(EntityManager em, int id) {
Company c = new Company();
c.setId(id);
for (int i = 0; i < numDivisionsPerCo; i++) {
Division d = createDivision(em, divId++);
VicePresident vp = createVicePresident(em, vpId++, d);
c.addToOrganization(vp);
em.persist(d);
em.persist(vp);
}
em.persist(c);
}
public Division createDivision(EntityManager em, int id) {
Division d = new Division();
d.setId(id);
d.setName("d" + id);
return d;
}
public VicePresident createVicePresident(EntityManager em, int id,
Division div) {
VicePresident vp = new VicePresident();
vp.setId(id);
vp.setDivision(div);
vp.setName("vp" + id);
return vp;
}
public void findObj(EntityManagerFactory emf) {
EntityManager em = emf.createEntityManager();
Company c = em.find(Company.class, 1);
assertCompany(c);
Division d = em.find(Division.class, 1);
assertDivision(d);
VicePresident vp = em.find(VicePresident.class, 1);
assertVicePresident(vp);
updateObj(em, c);
em.close();
em = emf.createEntityManager();
c = em.find(Company.class, 1);
assertCompany(c);
deleteObj(em, c);
em.close();
}
public void updateObj(EntityManager em, Company c) {
EntityTransaction tran = em.getTransaction();
// remove an element
tran.begin();
Map orgs = c.getOrganization();
Set keys = orgs.keySet();
for (Object key : keys) {
Division d = (Division)key;
VicePresident vp = c.getOrganization(d);
vp.setCompany(null);
em.persist(vp);
orgs.remove(d);
break;
}
em.persist(c);
em.flush();
tran.commit();
// add an element
tran.begin();
Division d = createDivision(em, newDivId++);
VicePresident vp = createVicePresident(em, newVpId++, d);
c.addToOrganization(vp);
vp.setCompany(c);
em.persist(d);
em.persist(vp);
em.persist(c);
em.flush();
tran.commit();
// modify an element
tran.begin();
vp = c.getOrganization(d);
vp.setName("newAgain");
em.persist(vp);
em.persist(c);
em.flush();
tran.commit();
}
public void deleteObj(EntityManager em, Company c) {
EntityTransaction tran = em.getTransaction();
tran.begin();
em.remove(c);
tran.commit();
}
public void assertCompany(Company c) {
int id = c.getId();
Map organization = c.getOrganization();
Assert.assertEquals(2,organization.size());
}
public void assertDivision(Division d) {
int id = d.getId();
String name = d.getName();
}
public void assertVicePresident(VicePresident vp) {
int id = vp.getId();
String name = vp.getName();
}
public void queryObj(EntityManagerFactory emf) {
queryCompany(emf);
queryDivision(emf);
queryVicePresident(emf);
}
public void queryCompany(EntityManagerFactory emf) {
EntityManager em = emf.createEntityManager();
EntityTransaction tran = em.getTransaction();
tran.begin();
Query q = em.createQuery("select c from Company c");
List<Company> cs = q.getResultList();
for (Company c : cs){
assertCompany(c);
}
tran.commit();
em.close();
}
public void queryDivision(EntityManagerFactory emf) {
EntityManager em = emf.createEntityManager();
EntityTransaction tran = em.getTransaction();
tran.begin();
Query q = em.createQuery("select d from Division d");
List<Division> ds = q.getResultList();
for (Division d : ds){
assertDivision(d);
}
tran.commit();
em.close();
}
public void queryVicePresident(EntityManagerFactory emf) {
EntityManager em = emf.createEntityManager();
EntityTransaction tran = em.getTransaction();
tran.begin();
Query q = em.createQuery("select vp from VicePresident vp");
List<VicePresident> vps = q.getResultList();
for (VicePresident vp : vps){
assertVicePresident(vp);
}
tran.commit();
em.close();
}
}
/*
* 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.jdbc.maps.spec_10_1_27_ex6;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Query;
import junit.framework.Assert;
import org.apache.openjpa.kernel.QueryImpl;
import org.apache.openjpa.persistence.test.AllowFailure;
import org.apache.openjpa.persistence.test.SQLListenerTestCase;
public class TestSpec10_1_27_Ex6 extends SQLListenerTestCase {
public int numCompany = 2;
public int numDivisionsPerCo = 2;
public int compId = 1;
public int divId = 1;
public int vpId = 1;
public int newDivId = 100;
public int newVpId = 100;
public List rsAllCompany = null;
public void setUp() {
super.setUp(CLEAR_TABLES,
Company.class,
Division.class,
VicePresident.class);
createObj(emf);
rsAllCompany = getAll(Company.class);
}
public void testQueryObj() throws Exception {
queryObj(emf);
}
@AllowFailure
public void testQueryInMemoryQualifiedId() throws Exception {
queryQualifiedId(true);
}
@AllowFailure
public void testQueryQualifiedId() throws Exception {
queryQualifiedId(false);
}
public void setCandidate(Query q, Class clz)
throws Exception {
org.apache.openjpa.persistence.QueryImpl q1 =
(org.apache.openjpa.persistence.QueryImpl) q;
org.apache.openjpa.kernel.Query q2 = q1.getDelegate();
org.apache.openjpa.kernel.QueryImpl qi = (QueryImpl) q2;
if (clz == Company.class)
qi.setCandidateCollection(rsAllCompany);
}
public void queryQualifiedId(boolean inMemory) throws Exception {
EntityManager em = emf.createEntityManager();
String query = "select KEY(e) from Company c, " +
" in (c.organization) e order by c.id";
Query q = em.createQuery(query);
if (inMemory)
setCandidate(q, Company.class);
List rs = q.getResultList();
Division d = (Division) rs.get(0);
em.clear();
query = "select ENTRY(e) from Company c, " +
" in (c.organization) e order by c.id";
q = em.createQuery(query);
if (inMemory)
setCandidate(q, Company.class);
rs = q.getResultList();
Map.Entry me = (Map.Entry) rs.get(0);
assertTrue(d.equals(me.getKey()));
em.clear();
query = "select KEY(e) from Company c " +
" left join c.organization e order by c.id";
q = em.createQuery(query);
if (inMemory)
setCandidate(q, Company.class);
rs = q.getResultList();
d = (Division) rs.get(0);
em.clear();
query = "select ENTRY(e) from Company c " +
" left join c.organization e order by c.id";
q = em.createQuery(query);
if (inMemory)
setCandidate(q, Company.class);
rs = q.getResultList();
me = (Map.Entry) rs.get(0);
assertTrue(d.equals(me.getKey()));
em.close();
}
public void createObj(EntityManagerFactory emf) {
EntityManager em = emf.createEntityManager();
EntityTransaction tran = em.getTransaction();
for (int i = 0; i < numCompany; i++)
createCompany(em, compId++);
tran.begin();
em.flush();
tran.commit();
em.close();
}
public void createCompany(EntityManager em, int id) {
Company c = new Company();
c.setId(id);
for (int i = 0; i < numDivisionsPerCo; i++) {
Division d = createDivision(em, divId++);
VicePresident vp = createVicePresident(em, vpId++, d);
c.addToOrganization(vp);
em.persist(d);
em.persist(vp);
}
em.persist(c);
}
public Division createDivision(EntityManager em, int id) {
Division d = new Division();
d.setId(id);
d.setName("d" + id);
return d;
}
public VicePresident createVicePresident(EntityManager em, int id,
Division div) {
VicePresident vp = new VicePresident();
vp.setId(id);
vp.setDivision(div);
vp.setName("vp" + id);
return vp;
}
public void findObj(EntityManagerFactory emf) {
EntityManager em = emf.createEntityManager();
Company c = em.find(Company.class, 1);
assertCompany(c);
Division d = em.find(Division.class, 1);
assertDivision(d);
VicePresident vp = em.find(VicePresident.class, 1);
assertVicePresident(vp);
updateObj(em, c);
em.close();
em = emf.createEntityManager();
c = em.find(Company.class, 1);
assertCompany(c);
deleteObj(em, c);
em.close();
}
public void updateObj(EntityManager em, Company c) {
EntityTransaction tran = em.getTransaction();
// remove an element
tran.begin();
Map orgs = c.getOrganization();
Set keys = orgs.keySet();
for (Object key : keys) {
Division d = (Division)key;
VicePresident vp = c.getOrganization(d);
vp.setCompany(null);
em.persist(vp);
orgs.remove(d);
break;
}
em.persist(c);
em.flush();
tran.commit();
// add an element
tran.begin();
Division d = createDivision(em, newDivId++);
VicePresident vp = createVicePresident(em, newVpId++, d);
c.addToOrganization(vp);
vp.setCompany(c);
em.persist(d);
em.persist(vp);
em.persist(c);
em.flush();
tran.commit();
// modify an element
tran.begin();
vp = c.getOrganization(d);
vp.setName("newAgain");
em.persist(vp);
em.persist(c);
em.flush();
tran.commit();
}
public void deleteObj(EntityManager em, Company c) {
EntityTransaction tran = em.getTransaction();
tran.begin();
em.remove(c);
tran.commit();
}
public void assertCompany(Company c) {
int id = c.getId();
Map organization = c.getOrganization();
Assert.assertEquals(2,organization.size());
}
public void assertDivision(Division d) {
int id = d.getId();
String name = d.getName();
}
public void assertVicePresident(VicePresident vp) {
int id = vp.getId();
String name = vp.getName();
}
public void queryObj(EntityManagerFactory emf) {
queryCompany(emf);
queryDivision(emf);
queryVicePresident(emf);
}
public void queryCompany(EntityManagerFactory emf) {
EntityManager em = emf.createEntityManager();
EntityTransaction tran = em.getTransaction();
tran.begin();
Query q = em.createQuery("select c from Company c");
List<Company> cs = q.getResultList();
for (Company c : cs){
assertCompany(c);
}
tran.commit();
em.close();
}
public void queryDivision(EntityManagerFactory emf) {
EntityManager em = emf.createEntityManager();
EntityTransaction tran = em.getTransaction();
tran.begin();
Query q = em.createQuery("select d from Division d");
List<Division> ds = q.getResultList();
for (Division d : ds){
assertDivision(d);
}
tran.commit();
em.close();
}
public void queryVicePresident(EntityManagerFactory emf) {
EntityManager em = emf.createEntityManager();
EntityTransaction tran = em.getTransaction();
tran.begin();
Query q = em.createQuery("select vp from VicePresident vp");
List<VicePresident> vps = q.getResultList();
for (VicePresident vp : vps){
assertVicePresident(vp);
}
tran.commit();
em.close();
}
}

View File

@ -1,68 +1,68 @@
/*
* 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.jdbc.maps.spec_10_1_27_ex6;
import javax.persistence.*;
@Entity
@Table(name="S27x6VP")
public class VicePresident {
@Id
int id;
String name;
@ManyToOne
Company co;
@OneToOne
Division div;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Company getCompany() {
return co;
}
public void setCompany(Company co) {
this.co = co;
}
public Division getDivision() {
return div;
}
public void setDivision(Division div) {
this.div = div;
}
}
/*
* 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.jdbc.maps.spec_10_1_27_ex6;
import javax.persistence.*;
@Entity
@Table(name="S27x6VP")
public class VicePresident {
@Id
int id;
String name;
@ManyToOne
Company co;
@OneToOne
Division div;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Company getCompany() {
return co;
}
public void setCompany(Company co) {
this.co = co;
}
public Division getDivision() {
return div;
}
public void setDivision(Division div) {
this.div = div;
}
}

View File

@ -1,61 +1,61 @@
/*
* 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.jdbc.maps.spec_10_1_27_ex7;
import java.util.HashMap;
import java.util.Map;
import javax.persistence.*;
@Entity
@Table(name="S27x7Comp")
public class Company {
@Id
int id;
@OneToMany(mappedBy="co")
@MapKey(name="div")
Map<Division, VicePresident> orgs =
new HashMap<Division, VicePresident>();
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public Map getOrganization() {
return orgs;
}
public void addToOrganization(VicePresident vp) {
orgs.put(vp.getDivision(), vp);
}
public void removeFromOrganization(Division d) {
orgs.remove(d);
}
public VicePresident getOrganization(Division d) {
return orgs.get(d);
}
}
/*
* 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.jdbc.maps.spec_10_1_27_ex7;
import java.util.HashMap;
import java.util.Map;
import javax.persistence.*;
@Entity
@Table(name="S27x7Comp")
public class Company {
@Id
int id;
@OneToMany(mappedBy="co")
@MapKey(name="div")
Map<Division, VicePresident> orgs =
new HashMap<Division, VicePresident>();
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public Map getOrganization() {
return orgs;
}
public void addToOrganization(VicePresident vp) {
orgs.put(vp.getDivision(), vp);
}
public void removeFromOrganization(Division d) {
orgs.remove(d);
}
public VicePresident getOrganization(Division d) {
return orgs.get(d);
}
}

View File

@ -1,63 +1,63 @@
/*
* 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.jdbc.maps.spec_10_1_27_ex7;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name="S27x7Div")
public class Division {
@Id
int id;
String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public boolean equals(Object o) {
Division d = (Division) o;
if (d.name.equals(name) &&
d.getId() == id)
return true;
return false;
}
public int hashCode() {
int ret = 0;
ret = ret * 31 + name.hashCode();
ret = ret *31 + id;
return ret;
}
}
/*
* 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.jdbc.maps.spec_10_1_27_ex7;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name="S27x7Div")
public class Division {
@Id
int id;
String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public boolean equals(Object o) {
Division d = (Division) o;
if (d.name.equals(name) &&
d.getId() == id)
return true;
return false;
}
public int hashCode() {
int ret = 0;
ret = ret * 31 + name.hashCode();
ret = ret *31 + id;
return ret;
}
}

View File

@ -1,338 +1,338 @@
/*
* 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.jdbc.maps.spec_10_1_27_ex7;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Query;
import junit.framework.Assert;
import org.apache.openjpa.kernel.QueryImpl;
import org.apache.openjpa.persistence.test.AllowFailure;
import org.apache.openjpa.persistence.test.SQLListenerTestCase;
public class TestSpec10_1_27_Ex7 extends SQLListenerTestCase {
public int numCompany = 2;
public int numDivisionsPerCo = 2;
public List<String> namedQueries = new ArrayList<String>();
public int compId = 1;
public int divId = 1;
public int vpId = 1;
public int newDivId = 100;
public int newVpId = 100;
public List rsAllCompany = null;
public void setUp() {
super.setUp(CLEAR_TABLES,
Company.class,
Division.class,
VicePresident.class);
createObj(emf);
rsAllCompany = getAll(Company.class);
}
public void testQueryObj() throws Exception {
queryObj(emf);
}
@AllowFailure
public void testQueryInMemoryQualifiedId() throws Exception {
queryQualifiedId(true);
}
@AllowFailure
public void testQueryQualifiedId() throws Exception {
queryQualifiedId(false);
}
public void setCandidate(Query q, Class clz)
throws Exception {
org.apache.openjpa.persistence.QueryImpl q1 =
(org.apache.openjpa.persistence.QueryImpl) q;
org.apache.openjpa.kernel.Query q2 = q1.getDelegate();
org.apache.openjpa.kernel.QueryImpl qi = (QueryImpl) q2;
if (clz == Company.class)
qi.setCandidateCollection(rsAllCompany);
}
public void queryQualifiedId(boolean inMemory) throws Exception {
EntityManager em = emf.createEntityManager();
String query = "select KEY(e) from Company c, " +
" in (c.orgs) e order by c.id";
Query q = em.createQuery(query);
if (inMemory)
setCandidate(q, Company.class);
List rs = q.getResultList();
Division d = (Division) rs.get(0);
em.clear();
query = "select ENTRY(e) from Company c, " +
" in (c.orgs) e order by c.id";
q = em.createQuery(query);
if (inMemory)
setCandidate(q, Company.class);
rs = q.getResultList();
Map.Entry me = (Map.Entry) rs.get(0);
assertTrue(d.equals(me.getKey()));
em.clear();
query = "select KEY(e) from Company c " +
" left join c.orgs e order by c.id";
q = em.createQuery(query);
if (inMemory)
setCandidate(q, Company.class);
rs = q.getResultList();
d = (Division) rs.get(0);
em.clear();
query = "select ENTRY(e) from Company c " +
" left join c.orgs e order by c.id";
q = em.createQuery(query);
if (inMemory)
setCandidate(q, Company.class);
rs = q.getResultList();
me = (Map.Entry) rs.get(0);
assertTrue(d.equals(me.getKey()));
em.close();
}
public void createObj(EntityManagerFactory emf) {
EntityManager em = emf.createEntityManager();
EntityTransaction tran = em.getTransaction();
for (int i = 0; i < numCompany; i++)
createCompany(em, compId++);
tran.begin();
em.flush();
tran.commit();
em.close();
}
public void createCompany(EntityManager em, int id) {
Company c = new Company();
c.setId(id);
for (int i = 0; i < numDivisionsPerCo; i++) {
Division d = createDivision(em, divId++);
VicePresident vp = createVicePresident(em, vpId++, d);
c.addToOrganization(vp);
vp.setCompany(c);
em.persist(d);
em.persist(vp);
}
em.persist(c);
}
public Division createDivision(EntityManager em, int id) {
Division d = new Division();
d.setId(id);
d.setName("d" + id);
return d;
}
public VicePresident createVicePresident(EntityManager em, int id,
Division d) {
VicePresident vp = new VicePresident();
vp.setId(id);
vp.setDivision(d);
vp.setName("vp" + id);
return vp;
}
public void findObj(EntityManagerFactory emf) {
EntityManager em = emf.createEntityManager();
Company c = em.find(Company.class, 1);
assertCompany(c);
Division d = em.find(Division.class, 1);
assertDivision(d);
VicePresident vp = em.find(VicePresident.class, 1);
assertVicePresident(vp);
updateObj1(em, c);
/*
updateObj(em, c);
em.close();
em = emf.createEntityManager();
c = em.find(Company.class, 1);
assertCompany(c);
deleteObj(em, c);
em.close();
*/
}
public void updateObj1(EntityManager em, Company c) {
EntityTransaction tran = em.getTransaction();
// remove an element
tran.begin();
Map orgs = c.getOrganization();
VicePresident vp = null;
Set keys = orgs.keySet();
for (Object key : keys) {
Division d = (Division)key;
vp = c.getOrganization(d);
vp.setCompany(null);
em.persist(vp);
c.removeFromOrganization(d);
break;
}
em.persist(c);
em.flush();
tran.commit();
tran.begin();
em.remove(c);
em.flush();
tran.commit();
tran.begin();
Company c1 = new Company();
c1.setId(1);
Division d = createDivision(em, divId++);
c1.addToOrganization(vp);
vp.setCompany(c1);
em.persist(d);
em.persist(c1);
em.flush();
tran.commit();
}
public void updateObj(EntityManager em, Company c) {
EntityTransaction tran = em.getTransaction();
// remove an element
tran.begin();
Map orgs = c.getOrganization();
Set keys = orgs.keySet();
for (Object key : keys) {
Division d = (Division)key;
VicePresident vp = c.getOrganization(d);
vp.setCompany(null);
em.persist(vp);
c.removeFromOrganization(d);
break;
}
em.persist(c);
em.flush();
tran.commit();
// add an element
tran.begin();
Division d = createDivision(em, newDivId++);
VicePresident vp = createVicePresident(em, newVpId++, d);
c.addToOrganization(vp);
vp.setCompany(c);
em.persist(d);
em.persist(vp);
em.persist(c);
em.flush();
tran.commit();
// modify an element
tran.begin();
vp = c.getOrganization(d);
vp.setName("newAgain");
em.persist(vp);
em.persist(c);
em.flush();
tran.commit();
}
public void deleteObj(EntityManager em, Company c) {
EntityTransaction tran = em.getTransaction();
tran.begin();
em.remove(c);
tran.commit();
}
public void assertCompany(Company c) {
int id = c.getId();
Map organization = c.getOrganization();
Assert.assertEquals(2,organization.size());
}
public void assertDivision(Division d) {
int id = d.getId();
String name = d.getName();
}
public void assertVicePresident(VicePresident vp) {
int id = vp.getId();
String name = vp.getName();
}
public void queryObj(EntityManagerFactory emf) {
queryCompany(emf);
queryDivision(emf);
queryVicePresident(emf);
}
public void queryCompany(EntityManagerFactory emf) {
EntityManager em = emf.createEntityManager();
EntityTransaction tran = em.getTransaction();
tran.begin();
Query q = em.createQuery("select c from Company c");
List<Company> cs = q.getResultList();
for (Company c : cs){
assertCompany(c);
}
tran.commit();
em.close();
}
public void queryDivision(EntityManagerFactory emf) {
EntityManager em = emf.createEntityManager();
EntityTransaction tran = em.getTransaction();
tran.begin();
Query q = em.createQuery("select d from Division d");
List<Division> ds = q.getResultList();
for (Division d : ds){
assertDivision(d);
}
tran.commit();
em.close();
}
public void queryVicePresident(EntityManagerFactory emf) {
EntityManager em = emf.createEntityManager();
EntityTransaction tran = em.getTransaction();
tran.begin();
Query q = em.createQuery("select vp from VicePresident vp");
List<VicePresident> vps = q.getResultList();
for (VicePresident vp : vps){
assertVicePresident(vp);
}
tran.commit();
em.close();
}
}
/*
* 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.jdbc.maps.spec_10_1_27_ex7;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Query;
import junit.framework.Assert;
import org.apache.openjpa.kernel.QueryImpl;
import org.apache.openjpa.persistence.test.AllowFailure;
import org.apache.openjpa.persistence.test.SQLListenerTestCase;
public class TestSpec10_1_27_Ex7 extends SQLListenerTestCase {
public int numCompany = 2;
public int numDivisionsPerCo = 2;
public List<String> namedQueries = new ArrayList<String>();
public int compId = 1;
public int divId = 1;
public int vpId = 1;
public int newDivId = 100;
public int newVpId = 100;
public List rsAllCompany = null;
public void setUp() {
super.setUp(CLEAR_TABLES,
Company.class,
Division.class,
VicePresident.class);
createObj(emf);
rsAllCompany = getAll(Company.class);
}
public void testQueryObj() throws Exception {
queryObj(emf);
}
@AllowFailure
public void testQueryInMemoryQualifiedId() throws Exception {
queryQualifiedId(true);
}
@AllowFailure
public void testQueryQualifiedId() throws Exception {
queryQualifiedId(false);
}
public void setCandidate(Query q, Class clz)
throws Exception {
org.apache.openjpa.persistence.QueryImpl q1 =
(org.apache.openjpa.persistence.QueryImpl) q;
org.apache.openjpa.kernel.Query q2 = q1.getDelegate();
org.apache.openjpa.kernel.QueryImpl qi = (QueryImpl) q2;
if (clz == Company.class)
qi.setCandidateCollection(rsAllCompany);
}
public void queryQualifiedId(boolean inMemory) throws Exception {
EntityManager em = emf.createEntityManager();
String query = "select KEY(e) from Company c, " +
" in (c.orgs) e order by c.id";
Query q = em.createQuery(query);
if (inMemory)
setCandidate(q, Company.class);
List rs = q.getResultList();
Division d = (Division) rs.get(0);
em.clear();
query = "select ENTRY(e) from Company c, " +
" in (c.orgs) e order by c.id";
q = em.createQuery(query);
if (inMemory)
setCandidate(q, Company.class);
rs = q.getResultList();
Map.Entry me = (Map.Entry) rs.get(0);
assertTrue(d.equals(me.getKey()));
em.clear();
query = "select KEY(e) from Company c " +
" left join c.orgs e order by c.id";
q = em.createQuery(query);
if (inMemory)
setCandidate(q, Company.class);
rs = q.getResultList();
d = (Division) rs.get(0);
em.clear();
query = "select ENTRY(e) from Company c " +
" left join c.orgs e order by c.id";
q = em.createQuery(query);
if (inMemory)
setCandidate(q, Company.class);
rs = q.getResultList();
me = (Map.Entry) rs.get(0);
assertTrue(d.equals(me.getKey()));
em.close();
}
public void createObj(EntityManagerFactory emf) {
EntityManager em = emf.createEntityManager();
EntityTransaction tran = em.getTransaction();
for (int i = 0; i < numCompany; i++)
createCompany(em, compId++);
tran.begin();
em.flush();
tran.commit();
em.close();
}
public void createCompany(EntityManager em, int id) {
Company c = new Company();
c.setId(id);
for (int i = 0; i < numDivisionsPerCo; i++) {
Division d = createDivision(em, divId++);
VicePresident vp = createVicePresident(em, vpId++, d);
c.addToOrganization(vp);
vp.setCompany(c);
em.persist(d);
em.persist(vp);
}
em.persist(c);
}
public Division createDivision(EntityManager em, int id) {
Division d = new Division();
d.setId(id);
d.setName("d" + id);
return d;
}
public VicePresident createVicePresident(EntityManager em, int id,
Division d) {
VicePresident vp = new VicePresident();
vp.setId(id);
vp.setDivision(d);
vp.setName("vp" + id);
return vp;
}
public void findObj(EntityManagerFactory emf) {
EntityManager em = emf.createEntityManager();
Company c = em.find(Company.class, 1);
assertCompany(c);
Division d = em.find(Division.class, 1);
assertDivision(d);
VicePresident vp = em.find(VicePresident.class, 1);
assertVicePresident(vp);
updateObj1(em, c);
/*
updateObj(em, c);
em.close();
em = emf.createEntityManager();
c = em.find(Company.class, 1);
assertCompany(c);
deleteObj(em, c);
em.close();
*/
}
public void updateObj1(EntityManager em, Company c) {
EntityTransaction tran = em.getTransaction();
// remove an element
tran.begin();
Map orgs = c.getOrganization();
VicePresident vp = null;
Set keys = orgs.keySet();
for (Object key : keys) {
Division d = (Division)key;
vp = c.getOrganization(d);
vp.setCompany(null);
em.persist(vp);
c.removeFromOrganization(d);
break;
}
em.persist(c);
em.flush();
tran.commit();
tran.begin();
em.remove(c);
em.flush();
tran.commit();
tran.begin();
Company c1 = new Company();
c1.setId(1);
Division d = createDivision(em, divId++);
c1.addToOrganization(vp);
vp.setCompany(c1);
em.persist(d);
em.persist(c1);
em.flush();
tran.commit();
}
public void updateObj(EntityManager em, Company c) {
EntityTransaction tran = em.getTransaction();
// remove an element
tran.begin();
Map orgs = c.getOrganization();
Set keys = orgs.keySet();
for (Object key : keys) {
Division d = (Division)key;
VicePresident vp = c.getOrganization(d);
vp.setCompany(null);
em.persist(vp);
c.removeFromOrganization(d);
break;
}
em.persist(c);
em.flush();
tran.commit();
// add an element
tran.begin();
Division d = createDivision(em, newDivId++);
VicePresident vp = createVicePresident(em, newVpId++, d);
c.addToOrganization(vp);
vp.setCompany(c);
em.persist(d);
em.persist(vp);
em.persist(c);
em.flush();
tran.commit();
// modify an element
tran.begin();
vp = c.getOrganization(d);
vp.setName("newAgain");
em.persist(vp);
em.persist(c);
em.flush();
tran.commit();
}
public void deleteObj(EntityManager em, Company c) {
EntityTransaction tran = em.getTransaction();
tran.begin();
em.remove(c);
tran.commit();
}
public void assertCompany(Company c) {
int id = c.getId();
Map organization = c.getOrganization();
Assert.assertEquals(2,organization.size());
}
public void assertDivision(Division d) {
int id = d.getId();
String name = d.getName();
}
public void assertVicePresident(VicePresident vp) {
int id = vp.getId();
String name = vp.getName();
}
public void queryObj(EntityManagerFactory emf) {
queryCompany(emf);
queryDivision(emf);
queryVicePresident(emf);
}
public void queryCompany(EntityManagerFactory emf) {
EntityManager em = emf.createEntityManager();
EntityTransaction tran = em.getTransaction();
tran.begin();
Query q = em.createQuery("select c from Company c");
List<Company> cs = q.getResultList();
for (Company c : cs){
assertCompany(c);
}
tran.commit();
em.close();
}
public void queryDivision(EntityManagerFactory emf) {
EntityManager em = emf.createEntityManager();
EntityTransaction tran = em.getTransaction();
tran.begin();
Query q = em.createQuery("select d from Division d");
List<Division> ds = q.getResultList();
for (Division d : ds){
assertDivision(d);
}
tran.commit();
em.close();
}
public void queryVicePresident(EntityManagerFactory emf) {
EntityManager em = emf.createEntityManager();
EntityTransaction tran = em.getTransaction();
tran.begin();
Query q = em.createQuery("select vp from VicePresident vp");
List<VicePresident> vps = q.getResultList();
for (VicePresident vp : vps){
assertVicePresident(vp);
}
tran.commit();
em.close();
}
}

View File

@ -1,68 +1,68 @@
/*
* 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.jdbc.maps.spec_10_1_27_ex7;
import javax.persistence.*;
@Entity
@Table(name="S27x7VP")
public class VicePresident {
@Id
int id;
String name;
@ManyToOne
Company co;
@OneToOne
Division div;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Company getCompany() {
return co;
}
public void setCompany(Company co) {
this.co = co;
}
public Division getDivision() {
return div;
}
public void setDivision(Division div) {
this.div = div;
}
}
/*
* 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.jdbc.maps.spec_10_1_27_ex7;
import javax.persistence.*;
@Entity
@Table(name="S27x7VP")
public class VicePresident {
@Id
int id;
String name;
@ManyToOne
Company co;
@OneToOne
Division div;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Company getCompany() {
return co;
}
public void setCompany(Company co) {
this.co = co;
}
public Division getDivision() {
return div;
}
public void setDivision(Division div) {
this.div = div;
}
}