1 20 21 package org.apache.derbyTesting.functionTests.tests.jdbc4; 22 23 import org.apache.derbyTesting.functionTests.util.TestDataSourceFactory; 24 import org.apache.derbyTesting.junit.BaseJDBCTestCase; 25 26 import junit.framework.*; 27 28 import java.sql.*; 29 30 import javax.sql.XAConnection ; 31 import javax.sql.XADataSource ; 32 import javax.transaction.xa.XAResource ; 33 34 import org.apache.derby.iapi.jdbc.BrokeredStatement40; 35 import org.apache.derby.iapi.jdbc.BrokeredPreparedStatement40; 36 import org.apache.derby.iapi.jdbc.BrokeredCallableStatement40; 37 38 39 42 public class XA40Test extends BaseJDBCTestCase { 43 44 45 private XADataSource xads = null; 46 47 48 private XAConnection xac = null; 49 50 51 private XAResource xar = null; 52 53 54 private Connection con = null; 55 56 61 public XA40Test(String name) { 62 super(name); 63 } 64 65 71 public void setUp() 72 throws SQLException { 73 xads = TestDataSourceFactory.getXADataSource(); 74 xac = xads.getXAConnection(); 75 xar = xac.getXAResource(); 76 con = xac.getConnection(); 77 assertFalse("Connection must be open initially", con.isClosed()); 78 con.setAutoCommit(false); 79 } 80 81 86 public void tearDown() 87 throws SQLException { 88 if (con != null && !con.isClosed()) { 91 con.rollback(); 94 con.close(); 95 } 96 if (xac != null) { 97 xac.close(); 98 } 99 } 100 101 102 109 public void testStatementPoolable() throws SQLException { 110 Statement s = con.createStatement(); 111 if (usingEmbedded()) { 112 assertTrue("s must be an instance of BrokeredStatement40, " + 113 "but is " + s.getClass(), 114 (s instanceof BrokeredStatement40)); 115 } 116 assertFalse("Statement must not be poolable by default", 117 s.isPoolable()); 118 s.setPoolable(true); 119 assertTrue("Statement must be poolable", s.isPoolable()); 120 121 s.setPoolable(false); 122 assertFalse("Statement cannot be poolable", s.isPoolable()); 123 } 124 125 132 public void testPreparedStatementPoolable() throws SQLException { 133 PreparedStatement ps = 134 con.prepareStatement("CREATE TABLE foo(i int)"); 135 if (usingEmbedded()) { 136 assertTrue("ps must be an instance of " + 137 "BrokeredPreparedStatement40, " + 138 "but is " + ps.getClass(), 139 (ps instanceof BrokeredPreparedStatement40)); 140 } 141 assertTrue("PreparedStatement must be poolable by default", 142 ps.isPoolable()); 143 ps.setPoolable(false); 144 assertFalse("PreparedStatement cannot be poolable", ps.isPoolable()); 145 146 ps.setPoolable(true); 147 assertTrue("PreparedStatement must be poolable", ps.isPoolable()); 148 } 149 150 157 public void testCallableStatementPoolable() throws SQLException { 158 CallableStatement cs = 159 con.prepareCall("CALL SYSCS_UTIL.SYSCS_BACKUP_DATABASE(?)"); 160 if (usingEmbedded()) { 161 assertTrue("cs must be an instance of " + 162 "BrokeredCallableStatement40, " + 163 "but is " + cs.getClass(), 164 (cs instanceof BrokeredCallableStatement40)); 165 } 166 assertTrue("CallableStatement must be poolable by default", 167 cs.isPoolable()); 168 cs.setPoolable(false); 169 assertFalse("CallableStatement cannot be poolable", cs.isPoolable()); 170 171 cs.setPoolable(true); 172 assertTrue("CallableStatement must be poolable", cs.isPoolable()); 173 } 174 175 176 179 public static Test suite() { 180 TestSuite suite = new TestSuite("XA40Test suite"); 181 suite.addTest(new TestSuite(XA40Test.class)); 183 184 return suite; 185 } 186 187 } | Popular Tags |