edu.wustl.common.util.dbManager.GenerateSchema.java Source code

Java tutorial

Introduction

Here is the source code for edu.wustl.common.util.dbManager.GenerateSchema.java

Source

/*L
 * Copyright Georgetown University, Washington University.
 *
 * Distributed under the OSI-approved BSD 3-Clause License.
 * See http://ncip.github.com/cab2b/LICENSE.txt for details.
 */

package edu.wustl.common.util.dbManager;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

import org.hibernate.HibernateException;
import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;

/*
 * Created on Feb 20, 2004
 *
 * To change the template for this generated file go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */

/**
 * @author kapil_kaveeshwar
 *
 * To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
public class GenerateSchema {
    public static void main(String[] args) throws HibernateException, IOException, Exception {
        boolean isToPrintOnConsole = false;
        boolean isToExecuteOnDB = false;
        if (args.length != 0) {
            String arg = args[0];
            if (arg.equalsIgnoreCase("true")) {
                isToPrintOnConsole = true;
                isToExecuteOnDB = true;
            }
            if (arg.equalsIgnoreCase("false")) {
                isToPrintOnConsole = false;
                isToExecuteOnDB = false;
            }
        }

        File file = new File("db.properties");
        BufferedInputStream stram = new BufferedInputStream(new FileInputStream(file));
        Properties p = new Properties();
        p.load(stram);
        stram.close();

        Configuration cfg = new Configuration();
        cfg.setProperties(p);
        cfg.addDirectory(new File("./src"));
        new SchemaExport(cfg).setOutputFile("query.sql").setDelimiter(";").create(isToPrintOnConsole,
                isToExecuteOnDB);
        //      if(isToExecuteOnDB)
        //         new GenerateUser();
    }
}