1 19 package com.mysql.jdbc.util; 20 21 import java.sql.Connection ; 22 import java.sql.SQLException ; 23 import java.util.Properties ; 24 25 import com.mysql.jdbc.Driver; 26 27 86 public abstract class BaseBugReport { 87 88 private Connection conn; 89 private Driver driver; 90 91 95 protected BaseBugReport() { 96 try { 97 this.driver = new Driver(); 98 } catch (SQLException ex) { 99 throw new RuntimeException (ex.toString()); 100 } 101 } 102 103 111 public abstract void setUp() throws Exception ; 112 113 120 public abstract void tearDown() throws Exception ; 121 122 130 public abstract void runTest() throws Exception ; 131 132 140 public final void run() throws Exception { 141 try { 142 setUp(); 143 runTest(); 144 145 } finally { 146 tearDown(); 147 } 148 } 149 150 158 protected final void assertTrue(String message, boolean condition) throws Exception { 159 if (!condition) { 160 throw new Exception ("Assertion failed: " + message); 161 } 162 } 163 164 171 protected final void assertTrue(boolean condition) throws Exception { 172 assertTrue("(no message given)", condition); 173 } 174 175 182 public String getUrl() { 183 return "jdbc:mysql:///test"; 184 } 185 186 197 public final synchronized Connection getConnection() throws SQLException { 198 if (this.conn == null || this.conn.isClosed()) { 199 this.conn = getNewConnection(); 200 } 201 202 return this.conn; 203 } 204 205 214 public final synchronized Connection getNewConnection() throws SQLException { 215 return getConnection(getUrl()); 216 } 217 218 225 public final synchronized Connection getConnection(String url) throws SQLException { 226 return getConnection(url, null); 227 } 228 229 237 public final synchronized Connection getConnection(String url, Properties props) throws SQLException { 238 239 242 return this.driver.connect(url, props); 243 } 244 } | Popular Tags |