1 21 22 package org.dbunit; 23 24 import org.dbunit.operation.DatabaseOperation; 25 26 import java.io.BufferedReader ; 27 import java.io.File ; 28 import java.io.FileReader ; 29 import java.sql.Connection ; 30 import java.sql.DriverManager ; 31 import java.sql.Statement ; 32 33 38 public class HypersonicEnvironment extends DatabaseEnvironment 39 { 40 public HypersonicEnvironment(DatabaseProfile profile) throws Exception 41 { 42 super(profile); 43 44 File ddlFile = new File ("src/sql/hypersonic.sql"); 46 Connection connection = getConnection().getConnection(); 47 48 executeDdlFile(ddlFile, connection); 49 50 } 51 52 public static void executeDdlFile(File ddlFile, Connection connection) throws Exception 53 { 54 BufferedReader sqlReader = new BufferedReader (new FileReader (ddlFile)); 55 StringBuffer sqlBuffer = new StringBuffer (); 56 while (sqlReader.ready()) 57 { 58 String line = sqlReader.readLine(); 59 if (!line.startsWith("-")) 60 { 61 sqlBuffer.append(line); 62 } 63 } 64 65 String sql = sqlBuffer.toString(); 66 Statement statement = connection.createStatement(); 67 try 68 { 69 statement.execute(sql); 70 } 71 finally 72 { 73 statement.close(); 74 } 75 } 76 77 public static Connection createJdbcConnection(String databaseName) throws Exception 78 { 79 Class.forName("org.hsqldb.jdbcDriver"); 80 Connection connection = DriverManager.getConnection( 81 "jdbc:hsqldb:" + databaseName, "sa", ""); 82 return connection; 83 } 84 85 public void closeConnection() throws Exception 86 { 87 DatabaseOperation.DELETE_ALL.execute(getConnection(), getInitDataSet()); 88 } 89 } 90 91 92 93 94 95 96 | Popular Tags |