01: package net.sourceforge.jaxor.example.tests;
02:
03: import net.sourceforge.jaxor.MetaRow;
04: import net.sourceforge.jaxor.api.JaxorContext;
05: import net.sourceforge.jaxor.example.domain.*;
06:
07: /**
08: * Author: mrettig
09: * Created: Aug 20, 2003
10: *
11: * Last Checkin: $Author: mrettig $
12: * Date: $Date: 2004/02/13 03:27:57 $
13: * Revision: $Revision: 1.11 $
14: */
15: public class NoSessionTest extends TableTestCase {
16:
17: protected MetaRow getRow() {
18: return new AddressMetaRow();
19: }
20:
21: public void testSingleSession() {
22: JaxorContext session = createSession();
23: AddressFinderBase finder = createAddress(session);
24: assertEquals(1, finder.findAll().size());
25: }
26:
27: private AddressFinderBase createAddress(JaxorContext session) {
28: AddressFinderBase finder = new AddressFinderBase(session);
29: assertEquals(0, finder.findAll().size());
30: AddressEntity address = finder.newInstance(new Long(1));
31: ObjectFactory.setDefaultFields(address);
32: session.flush();
33: return finder;
34: }
35:
36: private JaxorContext createSession() {
37: return getNewContext();
38: }
39:
40: public void testMultipleSession() {
41: JaxorContext session1 = createSession();
42: JaxorContext session2 = createSession();
43: createAddress(session1);
44: session1.commit();
45: AddressFinderBase addressFinder = new AddressFinderBase(
46: session1);
47: addressFinder.findAll().deleteAll();
48: // The entity has been deleted but not flushed from first session so we should still see it
49: assertEquals(1, new AddressFinderBase(session2).findAll()
50: .size());
51: }
52:
53: public void testQueryWithCustomSql() {
54: JaxorContext session = createSession();
55: AddressFinderBase finder = new AddressFinderBase(session);
56: AddressEntity address = finder.newInstance(new Long(23452));
57: address.setCity("Chicago");
58: address.setStreet("623 W State");
59: address.setState("IL");
60: address.setZipCode("60607");
61:
62: session.flush();
63:
64: assertEquals(
65: 1,
66: finder
67: .query(
68: "select * from address where city='Chicago' AND state='IL'")
69: .size());
70: assertNotNull(finder.selectByPrimaryKey(new Long(23452)));
71:
72: assertEquals(1, finder.findAll().size());
73: }
74:
75: public void testFindingAndDeleting() {
76: JaxorContext session = createSession();
77: AddressFinderBase finder = new AddressFinderBase(session);
78: AddressList list = finder.selectByStateList("IL");
79: for (AddressIterator iter = list.iterator(); iter.hasNext();) {
80: AddressEntity addressInIL = iter.next();
81: }
82: }
83:
84: }
|