Search in sources :

Example 1 with DatabaseSyntax

use of org.vcell.db.DatabaseSyntax in project vcell by virtualcell.

the class CompareDatabaseSchema method main.

/**
 * Starts the application.
 * @param args an array of command-line arguments
 */
public static void main(java.lang.String[] args) {
    // 
    try {
        final String oracle = "oracle";
        final String postgres = "postgres";
        final String usage = "Usage: (" + oracle + "|" + postgres + ") connectURL schemaUser schemaUserPassword";
        if (args.length != 4 || (!args[0].equalsIgnoreCase(oracle) && !args[0].equalsIgnoreCase(postgres))) {
            System.out.println(usage);
            System.exit(0);
        }
        String connectURL = args[1];
        String dbSchemaUser = args[2];
        String dbPassword = args[3];
        // 
        int ok = javax.swing.JOptionPane.showConfirmDialog(new JFrame(), "Will compare VCell Software 'Tables' with Database Schema: " + "connectURL=" + connectURL + "\nUser=" + dbSchemaUser + "\npassword=" + dbPassword, "Confirm", javax.swing.JOptionPane.OK_CANCEL_OPTION, javax.swing.JOptionPane.WARNING_MESSAGE);
        if (ok != javax.swing.JOptionPane.OK_OPTION) {
            throw new RuntimeException("Aborted by user");
        }
        SessionLog log = new StdoutSessionLog("CompareDatabaseSchema");
        ConnectionFactory conFactory = null;
        KeyFactory keyFactory = null;
        new cbit.vcell.resource.PropertyLoader();
        // 
        // get appropriate database factory objects
        // 
        DatabaseSyntax dbSyntax = null;
        if (args[0].equalsIgnoreCase(oracle)) {
            dbSyntax = DatabaseSyntax.ORACLE;
            String driverName = "oracle.jdbc.driver.OracleDriver";
            conFactory = DatabaseService.getInstance().createConnectionFactory(driverName, connectURL, dbSchemaUser, dbPassword);
            keyFactory = conFactory.getKeyFactory();
        } else if (args[0].equalsIgnoreCase(postgres)) {
            dbSyntax = DatabaseSyntax.POSTGRES;
            String driverName = "org.postgresql.Driver";
            conFactory = DatabaseService.getInstance().createConnectionFactory(driverName, connectURL, dbSchemaUser, dbPassword);
            keyFactory = conFactory.getKeyFactory();
        } else {
            System.out.println(usage);
            System.exit(1);
        }
        // 
        // compare with VCell Software 'tables'
        // 
        Table[] tables = SQLCreateAllTables.getVCellTables();
        compareSchemas(log, conFactory, keyFactory, tables, dbSyntax);
    } catch (Throwable e) {
        e.printStackTrace(System.out);
    }
    System.exit(0);
}
Also used : DatabaseSyntax(org.vcell.db.DatabaseSyntax) StdoutSessionLog(cbit.vcell.resource.StdoutSessionLog) StdoutSessionLog(cbit.vcell.resource.StdoutSessionLog) SessionLog(org.vcell.util.SessionLog) ConnectionFactory(org.vcell.db.ConnectionFactory) JFrame(javax.swing.JFrame) KeyFactory(org.vcell.db.KeyFactory)

Aggregations

StdoutSessionLog (cbit.vcell.resource.StdoutSessionLog)1 JFrame (javax.swing.JFrame)1 ConnectionFactory (org.vcell.db.ConnectionFactory)1 DatabaseSyntax (org.vcell.db.DatabaseSyntax)1 KeyFactory (org.vcell.db.KeyFactory)1 SessionLog (org.vcell.util.SessionLog)1