OPENJPA-240 XMLMapping Query testcase - fix identation

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@557444 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
David J. Wisneski 2007-07-19 01:32:03 +00:00
parent b761732fdf
commit 462cf31ed5
1 changed files with 75 additions and 72 deletions

View File

@ -50,7 +50,8 @@ public class TestXMLCustomerOrder
public void setUp() { public void setUp() {
setUp(org.apache.openjpa.persistence.xmlmapping.entities.Customer.class setUp(org.apache.openjpa.persistence.xmlmapping.entities.Customer.class
, org.apache.openjpa.persistence.xmlmapping.entities.Customer.CustomerKey.class , org.apache.openjpa.persistence.xmlmapping.entities.Customer
.CustomerKey.class
, org.apache.openjpa.persistence.xmlmapping.entities.Order.class , org.apache.openjpa.persistence.xmlmapping.entities.Order.class
, org.apache.openjpa.persistence.xmlmapping.entities.EAddress.class , org.apache.openjpa.persistence.xmlmapping.entities.EAddress.class
, "openjpa.MetaDataRepository" , "openjpa.MetaDataRepository"
@ -89,32 +90,34 @@ public class TestXMLCustomerOrder
// For platform specific expected sqls are under resources. // For platform specific expected sqls are under resources.
// The generated sql of the test is captured and written to file: // The generated sql of the test is captured and written to file:
// ./TestXMLCustomerOrder.log // ./TestXMLCustomerOrder.log
// This output file contents should match with the platform specfic sqls. // This output file contents should match with the platform specfic
// sqls.
System.out.println("Expected pushdown SQL log file is in: " + sqllog); System.out.println("Expected pushdown SQL log file is in: " + sqllog);
sql.clear(); sql.clear();
try { try {
em.getTransaction().begin();
deleteAllData(em );
em.getTransaction().commit();
em.getTransaction().begin(); em.getTransaction().begin();
loadData(em); deleteAllData(em );
em.getTransaction().commit(); em.getTransaction().commit();
em.close(); em.getTransaction().begin();
loadData(em);
// By closing and recreating the EntityManager, em.getTransaction().commit();
// this guarantees that data will be retrieved from
// the database rather than just reused from the em.close();
// persistence context created by the load methods above.
// By closing and recreating the EntityManager,
em = emf.createEntityManager(); // this guarantees that data will be retrieved from
// the database rather than just reused from the
System.err.println("Main started."); // persistence context created by the load methods above.
em = emf.createEntityManager();
System.err.println("Main started.");
int test=1; int test=1;
List<Address> addrs = em.createQuery("select o.shipAddress from Order o") List<Address> addrs = em.createQuery(
"select o.shipAddress from Order o")
.getResultList(); .getResultList();
for (Address addr : addrs) { for (Address addr : addrs) {
System.out.println("addr= " + addr.toString()); System.out.println("addr= " + addr.toString());
@ -133,26 +136,26 @@ public class TestXMLCustomerOrder
List orders = em.createQuery(qstring).getResultList(); List orders = em.createQuery(qstring).getResultList();
printOrders(orders, test++); printOrders(orders, test++);
} }
// query passing parameters // query passing parameters
qstring = "select o from Order o where o.shipAddress.city = ?1"; qstring = "select o from Order o where o.shipAddress.city = ?1";
Query q5 = em.createQuery(qstring); Query q5 = em.createQuery(qstring);
q5.setParameter(1, "San Jose"); q5.setParameter(1, "San Jose");
List orders =q5.getResultList(); List orders =q5.getResultList();
printOrders(orders, test++); printOrders(orders, test++);
qstring = "select o from Order o where ?1 = o.shipAddress.city"; qstring = "select o from Order o where ?1 = o.shipAddress.city";
Query q6 = em.createQuery(qstring); Query q6 = em.createQuery(qstring);
q6.setParameter(1, "San Jose"); q6.setParameter(1, "San Jose");
orders = q6.getResultList(); orders = q6.getResultList();
printOrders(orders, test++); printOrders(orders, test++);
em.close(); em.close();
// test updates // test updates
em = emf.createEntityManager(); em = emf.createEntityManager();
testUpdateShipaddress(em, test++); testUpdateShipaddress(em, test++);
em.close(); em.close();
em = emf.createEntityManager(); em = emf.createEntityManager();
@ -189,7 +192,7 @@ public class TestXMLCustomerOrder
e.printStackTrace(); e.printStackTrace();
} }
} }
private void dumpSql() { private void dumpSql() {
String out = "./TestXMLCustomerOrder.log"; String out = "./TestXMLCustomerOrder.log";
try { try {
@ -212,56 +215,56 @@ public class TestXMLCustomerOrder
} }
private void loadData(EntityManager em) { private void loadData(EntityManager em) {
ObjectFactory addressFactory = new ObjectFactory(); ObjectFactory addressFactory = new ObjectFactory();
Customer c2 = new Customer(); Customer c2 = new Customer();
c2.setCid( new Customer.CustomerKey("USA", 2) ); c2.setCid( new Customer.CustomerKey("USA", 2) );
c2.setName("A&J Auto"); c2.setName("A&J Auto");
c2.setRating( CreditRating.GOOD ); c2.setRating( CreditRating.GOOD );
c2.setAddress(new EAddress("2480 Campbell Ave", "Campbell", "CA" c2.setAddress(new EAddress("2480 Campbell Ave", "Campbell", "CA"
, "95123")); , "95123"));
em.persist(c2); em.persist(c2);
Customer c1 = new Customer(); Customer c1 = new Customer();
c1.setCid( new Customer.CustomerKey("USA", 1) ); c1.setCid( new Customer.CustomerKey("USA", 1) );
c1.setName("Harry's Auto"); c1.setName("Harry's Auto");
c1.setRating( CreditRating.GOOD ); c1.setRating( CreditRating.GOOD );
c1.setAddress( new EAddress("12500 Monterey", "San Jose", "CA" c1.setAddress( new EAddress("12500 Monterey", "San Jose", "CA"
, "95141")); , "95141"));
em.persist(c1); em.persist(c1);
Order o1 = new Order(10, 850, false, c1); Order o1 = new Order(10, 850, false, c1);
USAAddress addr1 = addressFactory.createUSAAddress(); USAAddress addr1 = addressFactory.createUSAAddress();
addr1.setCity("San Jose"); addr1.setCity("San Jose");
addr1.setState("CA"); addr1.setState("CA");
addr1.setZIP(new Integer("95141")); addr1.setZIP(new Integer("95141"));
addr1.getStreet().add("12500 Monterey"); addr1.getStreet().add("12500 Monterey");
addr1.setName( c1.getName()); addr1.setName( c1.getName());
o1.setShipAddress(addr1); o1.setShipAddress(addr1);
em.persist(o1); em.persist(o1);
Order o2 = new Order(20, 1000, false, c1); Order o2 = new Order(20, 1000, false, c1);
CANAddress addr2 = addressFactory.createCANAddress(); CANAddress addr2 = addressFactory.createCANAddress();
addr2.setName(c2.getName()); addr2.setName(c2.getName());
addr2.getStreet().add("123 Warden Road"); addr2.getStreet().add("123 Warden Road");
addr2.setCity("Markham"); addr2.setCity("Markham");
addr2.setPostalCode("L6G 1C7"); addr2.setPostalCode("L6G 1C7");
addr2.setProvince("ON"); addr2.setProvince("ON");
o2.setShipAddress(addr2); o2.setShipAddress(addr2);
em.persist(o2); em.persist(o2);
} }
private void testUpdateShipaddress(EntityManager em, int test) private void testUpdateShipaddress(EntityManager em, int test)
throws Exception { throws Exception {
em.getTransaction().begin(); em.getTransaction().begin();
String query = "select o from Order o where o.shipAddress.city " + String query = "select o from Order o where o.shipAddress.city " +
"= 'San Jose'"; "= 'San Jose'";
List orders = em.createQuery(query).getResultList(); List orders = em.createQuery(query).getResultList();
System.out.println("Before Update: "); System.out.println("Before Update: ");
printOrders(orders, test); printOrders(orders, test);
em.getTransaction().commit(); em.getTransaction().commit();
// update in separate transaction // update in separate transaction
Order o = (Order) orders.get(0); Order o = (Order) orders.get(0);
EntityTransaction et = em.getTransaction(); EntityTransaction et = em.getTransaction();
@ -270,21 +273,21 @@ public class TestXMLCustomerOrder
addr.setCity("Cupertino"); addr.setCity("Cupertino");
if (addr instanceof USAAddress) if (addr instanceof USAAddress)
((USAAddress) addr).setZIP(95014); ((USAAddress) addr).setZIP(95014);
// update shipAddress // update shipAddress
o.setShipAddress(addr); o.setShipAddress(addr);
et.commit(); et.commit();
} }
private void deleteAllData(EntityManager em) {
em.createQuery("delete from Order o").executeUpdate();
em.createQuery("delete from Customer c").executeUpdate();
}
private void printOrder(Order o){ private void deleteAllData(EntityManager em) {
em.createQuery("delete from Order o").executeUpdate();
em.createQuery("delete from Customer c").executeUpdate();
}
private void printOrder(Order o){
System.out.println(" Customer ID:"+o.getCustomer().getCid()); System.out.println(" Customer ID:"+o.getCustomer().getCid());
System.out.println(" Order Number:"+o.getOid()); System.out.println(" Order Number:"+o.getOid());
System.out.println("Ship to: "+o.getShipAddress().toString()); System.out.println("Ship to: "+o.getShipAddress().toString());
System.out.println(); System.out.println();
} }
} }