2 * Copyright 2005 the original author or authors.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.wamblee.support.persistence;
20 * This class is used for starting the database from ant.
22 public class DatabaseStarter {
25 * Database class which encapsulates management of the database.
27 private Class _databaseClass;
30 * Execution as a main program. Commandline
34 * DatabaseStarter <databaseClassName>
38 * where the database class name must be the name of a concrete subclass of
43 public static void main( String[] args ) throws Exception {
44 String clazz = args[0];
46 new DatabaseStarter( Class.forName( clazz ) ).start( );
47 } catch ( Exception e ) {
50 .println( "\nUsage: ant dbClass ");
55 * Constructs the database starter.
58 * Classname of the database class to use.
61 public DatabaseStarter( Class aClass ) throws Exception {
62 if ( !Database.class.isAssignableFrom( aClass ) ) {
63 throw new IllegalArgumentException( "Class '"
65 + "' is not a subclass of Database" );
67 _databaseClass = aClass;
71 * Constructs a database starter with the derby database.
75 public DatabaseStarter( ) throws Exception {
76 this( DerbyDatabase.class );
80 * Starts the database.
84 public void start( ) throws Exception {
85 Database lDatabase = (Database) _databaseClass.newInstance( );
87 System.out.println( "Database has been started. " );
88 System.out.println( );
89 System.out.println("=======================================================");
90 System.out.println( "Connection details:" );
91 // System.out.println( " Driver class: "
92 // + lDatabase.getDriverClassName( ) );
93 System.out.println( " JDBC URL: "
94 + lDatabase.getExternalJdbcUrl( ) );
95 System.out.println( " username: '" + lDatabase.getUsername( )
97 System.out.println( " password: '" + lDatabase.getPassword( )
99 System.out.println( "Interrupt the program to stop the database." );
100 System.out.println("=======================================================");
101 System.out.println("You must now populate the database with a schema. Use 'ant help' for information.");
103 Thread.sleep( 1000 );