Search in sources :

Example 1 with SessionLog

use of org.vcell.util.SessionLog 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)

Example 2 with SessionLog

use of org.vcell.util.SessionLog in project vcell by virtualcell.

the class StdSessionLogTest method setup.

@SuppressWarnings("resource")
private static void setup(String[] args) throws Exception {
    Logging.init();
    PrintStream output = new PrintStream(args[3]);
    SessionLog log = null;
    String type = args[0];
    if (type.equals("reg")) {
        log = new StdoutSessionLog("stdlog", output);
        if (TEST_STD_OUT) {
            PrintStream ps = new PrintStream(new FileOutputStream("console.txt"), true);
            System.setOut(ps);
        }
    } else if (type.equals("con")) {
        StdoutSessionLogConcurrent a = new StdoutSessionLogConcurrent("conlog", output, new LifeSignInfo());
        if (TEST_STD_OUT) {
            PrintStream ad = a.printStreamFacade();
            System.setOut(ad);
            System.out.print("h");
        }
        log = a;
    } else {
        showUsage();
        return;
    }
    final int nThreads = Integer.parseInt(args[1]);
    final int nSeconds = Integer.parseInt(args[2]);
    Thread[] babblers = new Thread[nThreads];
    if (args.length > 4) {
        final long milliWait = Long.parseLong(args[4]);
        for (int t = 0; t < nThreads; t++) {
            babblers[t] = new BabblerWait(log, t, milliWait);
        }
    } else {
        for (int t = 0; t < nThreads; t++) {
            babblers[t] = new Babbler(log, t);
        }
    }
    for (int t = 0; t < nThreads; t++) {
        babblers[t].start();
    }
    System.err.println("Sleeping " + nSeconds);
    Thread.sleep(1000 * nSeconds);
    log.print("exiting main");
    System.err.println("End of sleep");
}
Also used : PrintStream(java.io.PrintStream) SessionLog(org.vcell.util.SessionLog) LifeSignInfo(cbit.vcell.resource.StdoutSessionLogConcurrent.LifeSignInfo) FileOutputStream(java.io.FileOutputStream)

Aggregations

SessionLog (org.vcell.util.SessionLog)2 StdoutSessionLog (cbit.vcell.resource.StdoutSessionLog)1 LifeSignInfo (cbit.vcell.resource.StdoutSessionLogConcurrent.LifeSignInfo)1 FileOutputStream (java.io.FileOutputStream)1 PrintStream (java.io.PrintStream)1 JFrame (javax.swing.JFrame)1 ConnectionFactory (org.vcell.db.ConnectionFactory)1 DatabaseSyntax (org.vcell.db.DatabaseSyntax)1 KeyFactory (org.vcell.db.KeyFactory)1