2 * Copyright 2005-2010 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;
19 * This class is used for starting the database from ant.
21 public class DatabaseStarter {
24 * Database class which encapsulates management of the database.
26 private Class databaseClass;
29 * Execution as a main program. Commandline
33 * DatabaseStarter <databaseClassName>
37 * where the database class name must be the name of a concrete subclass of
42 public static void main(String[] aArgs) throws Exception {
43 String clazz = aArgs[0];
45 new DatabaseStarter(Class.forName(clazz)).start();
46 } catch (Exception e) {
48 System.out.println("\nUsage: ant dbClass ");
53 * Constructs the database starter.
56 * Classname of the database class to use.
59 public DatabaseStarter(Class aClass) throws Exception {
60 if (!Database.class.isAssignableFrom(aClass)) {
61 throw new IllegalArgumentException("Class '" + aClass.getName() +
62 "' is not a subclass of Database");
64 databaseClass = aClass;
68 * Constructs a database starter with the derby database.
72 public DatabaseStarter() throws Exception {
73 this(DerbyDatabase.class);
77 * Starts the database.
81 public void start() throws Exception {
82 Database lDatabase = (Database) databaseClass.newInstance();
84 System.out.println("Database has been started. ");
87 .println("=======================================================");
88 System.out.println("Connection details:");
89 // System.out.println( " Driver class: "
90 // + lDatabase.getDriverClassName( ) );
91 System.out.println(" JDBC URL: " + lDatabase.getExternalJdbcUrl());
92 System.out.println(" username: '" + lDatabase.getUsername() + "'");
93 System.out.println(" password: '" + lDatabase.getPassword() + "'");
94 System.out.println("Interrupt the program to stop the database.");
96 .println("=======================================================");
98 .println("You must now populate the database with a schema. Use 'ant help' for information.");