001 /* 002 @license.text@ 003 */ 004 package biz.hammurapi.sql.hypersonic; 005 006 import java.io.File; 007 import java.io.IOException; 008 import java.sql.SQLException; 009 010 import biz.hammurapi.sql.SQLProcessor; 011 import biz.hammurapi.sql.Transaction; 012 013 014 015 /** 016 * Hypersonic standalone data source. 017 * @author Pavel Vlasov 018 * @version $Revision: 1.5 $ 019 */ 020 public class HypersonicStandaloneDataSource extends HypersonicDataSource { 021 022 /** 023 * Constructor. Uses "sa" as user name and blank password. Creates a database if one doesn't exist. 024 * @param dbName - Database name. E.g. C:\myproject\myDB. 025 * @throws ClassNotFoundException 026 * @throws IOException 027 * @throws SQLException 028 */ 029 public HypersonicStandaloneDataSource(String dbName, Transaction databaseInitTransaction) throws ClassNotFoundException, SQLException { 030 this(dbName, "sa", "", databaseInitTransaction, null); 031 } 032 033 /** 034 * Constructor. Creates a database if one doesn't exist. 035 * @param dbName - Database name. E.g. C:\myproject\myDB. 036 * @param initTransaction - Transaction to initialize database if it doesn't exist 037 * @throws ClassNotFoundException 038 * @throws IOException 039 * @throws SQLException 040 */ 041 public HypersonicStandaloneDataSource(String dbName, String user, String password, Transaction databaseInitTransaction, Transaction connectionInitTransaction) throws ClassNotFoundException, SQLException { 042 super("jdbc:hsqldb:"+dbName, user, password, connectionInitTransaction); 043 File dbFile=new File(dbName+".properties"); 044 if (databaseInitTransaction!=null && !dbFile.exists()) { 045 new SQLProcessor(this, null).executeTransaction(databaseInitTransaction); 046 } 047 } 048 }