001    /*
002    @license.text@
003     */
004    package biz.hammurapi.sql.cloudscape;
005    
006    import java.io.File;
007    import java.io.IOException;
008    import java.sql.SQLException;
009    
010    import biz.hammurapi.sql.Transaction;
011    
012    
013    
014    /**
015     * Hypersonic standalone data source.
016     * @author Pavel Vlasov 
017     * @version $Revision: 1.2 $
018     */
019    public class CloudscapeStandaloneDataSource extends CloudscapeDataSource {
020    
021            /**
022             * Constructor. Creates a database if one doesn't exist.
023             * @param dbName - Database name. E.g. C:\myproject\myDB.
024             * @param initConnectionTransaction 
025             * @throws ClassNotFoundException
026             * @throws IOException
027             * @throws SQLException
028             */
029            public CloudscapeStandaloneDataSource(
030                            String dbName, 
031                            String user, 
032                            String password, 
033                            boolean createDb, 
034                            Transaction initConnectionTransaction) throws ClassNotFoundException, IOException, SQLException {
035                    super("org.apache.derby.jdbc.EmbeddedDriver", "jdbc:derby:"+dbName+(createDb ? ";create=true" : ""), user, password, initConnectionTransaction);
036                    File dbFile=new File(dbName);
037                    if (!dbFile.exists()) {
038                            initDB();
039                    }
040            }       
041            
042            /**
043             * Override this method to automatically initialize database if it does not exist
044             * @throws SQLException
045             */
046            protected void initDB() throws SQLException {
047                    
048            }       
049    }