1 25 26 package org.objectweb.jonas.jtests.clients.entity; 27 28 import java.util.Enumeration ; 29 30 import org.objectweb.jonas.jtests.beans.ebasic.Simple; 31 import org.objectweb.jonas.jtests.beans.ebasic.SimpleHome; 32 import org.objectweb.jonas.jtests.util.JTestCase; 33 34 37 public abstract class A_Isolation extends JTestCase { 38 39 public A_Isolation(String name) { 40 super(name); 41 } 42 43 protected void setUp() { 44 super.setUp(); 45 useBeans("ebasic", true); 46 } 47 48 51 abstract public SimpleHome getHome(); 52 53 58 public void testIsolation1() throws Exception { 59 int val1 = 11; 60 int val2 = 12; 61 Simple s1 = getHome().findByPrimaryKey("pk4"); 62 s1.setInfo(val1); 63 utx.begin(); 64 try { 65 assertEquals(val1, s1.getInfo()); 66 s1.setInfo(val2); 67 } finally { 68 utx.commit(); 69 } 70 assertEquals(val2, s1.getInfo()); 71 } 72 73 76 public void testFinderInTx() throws Exception { 77 int found2 = 0; 78 int found3 = 0; 79 int newval = 14; 80 utx.begin(); 81 try { 82 Simple s1 = getHome().create("n1", 1001, newval); 83 Simple s2 = getHome().create("n2", 1002, 2); 84 s2.setNumTest(newval); 85 Enumeration list = getHome().findInfoForNum(newval); 86 while (list.hasMoreElements()) { 87 list.nextElement(); 88 found2++; 89 } 90 assertEquals("first try", 2, found2); 91 } finally { 92 utx.rollback(); 94 } 95 } 96 97 100 public void testFinderOutTx() throws Exception { 101 int found2 = 0; 102 int found3 = 0; 103 int newval = 14; 104 Simple s1 = null; 105 Simple s2 = null; 106 try { 107 s1 = getHome().create("n3", 1001, newval); 108 s2 = getHome().create("n4", 1002, 2); 109 s2.setNumTest(newval); 110 Enumeration list = getHome().findInfoForNum(newval); 111 while (list.hasMoreElements()) { 112 list.nextElement(); 113 found2++; 114 } 115 assertEquals("first try", 2, found2); 116 } finally { 117 if (s1 != null) { 119 s1.remove(); 120 } 121 if (s2 != null) { 122 s2.remove(); 123 } 124 } 125 } 126 127 130 public void testFinderInTx2() throws Exception { 131 int found2 = 0; 132 int found3 = 0; 133 int newval = 14; 134 utx.begin(); 135 try { 136 Simple s1 = getHome().create("n5", 1001, newval); 137 Simple s2 = getHome().create("n6", 1002, 2); 138 Simple s3 = getHome().create("n7", 1003, 3); 139 s2.setNumTest(newval); 140 Enumeration list = getHome().findInfoForNum(newval); 141 while (list.hasMoreElements()) { 142 list.nextElement(); 143 found2++; 144 } 145 s3.setNumTest(newval); 146 list = getHome().findInfoForNum(newval); 147 while (list.hasMoreElements()) { 148 list.nextElement(); 149 found3++; 150 } 151 assertEquals("second try", 3, found3); 152 assertEquals("first try", 2, found2); 153 } finally { 154 utx.rollback(); 156 } 157 } 158 } 159 | Popular Tags |