示例#1
0
def export_db_schema(JDBC_URL, bin_dir, class_path, MAX_JAVA_HEAP, DB_USER,
                     DB_PASSWORD, DB_NAME, DB_SCHEMA, subsystem_dir,
                     INCL_TABLES, SKIP_TABLES, OVERWRITE_TABLES, DDL_GEN):
    url, driver_jar, driver_class = get_db_details(JDBC_URL, bin_dir)
    if driver_jar and driver_class:
        # Start Java virtual machine if not started already:
        class_paths = class_path + ':' + driver_jar
        init_jvm(class_paths, MAX_JAVA_HEAP)

        try:
            jdbc = Jdbc(url, DB_USER, DB_PASSWORD, DB_NAME, DB_SCHEMA,
                        driver_jar, driver_class, True, True)
            if jdbc:
                # Get database metadata:
                db_tables, table_columns = get_db_meta(jdbc)
                export_schema(class_path, MAX_JAVA_HEAP, subsystem_dir, jdbc,
                              db_tables)
                export_tables, overwrite_tables = table_check(
                    INCL_TABLES, SKIP_TABLES, OVERWRITE_TABLES, db_tables,
                    subsystem_dir)

            if export_tables:
                # Copy schema data:
                copy_db_schema(subsystem_dir, jdbc, class_path, MAX_JAVA_HEAP,
                               export_tables, bin_dir, table_columns,
                               overwrite_tables, DDL_GEN)
            else:
                print_and_exit('No table data to export. Exiting.')

        except Exception as e:
            print_and_exit(e)

    else:
        print_and_exit('Not a supported jdbc url. Exiting')
示例#2
0
def export_schema(class_paths, max_java_heap, subsystem_dir, jdbc,
                  schema_names):
    base_dir = os.path.join(subsystem_dir, 'header')
    schema_file = os.path.join(subsystem_dir, 'header', 'metadata.xml')

    if os.path.isfile(schema_file):
        return

    init_jvm(class_paths, max_java_heap)
    WbManager = jp.JPackage('workbench').WbManager
    WbManager.prepareForEmbedded()
    batch = jp.JPackage('workbench.sql').BatchRunner()
    batch.setAbortOnError(True)

    batch.setBaseDir(base_dir)
    batch.runScript("WbConnect -url='" + jdbc.url + "' -username='******' -password="******";")
    # TODO: Fjernet foreløpig SYNONYM, fra types under
    # --> Hvorfor ble ikke SYNONYM håndtert -> sjekk i senere kode. Var dette evt tilfelle hvor synonym ikke er annet navn på table
    # men annen type dataobjekt?
    gen_report_str = "WbSchemaReport -file=metadata.xml -schemas=" + schema_names + " -types=TABLE,VIEW -includeProcedures=true \
                            -includeTriggers=true -writeFullSource=true;"

    batch.runScript(gen_report_str)
    remove_illegal_characters(schema_file)
示例#3
0
def test_db_connect(conn,
                    bin_dir,
                    class_path,
                    java_path,
                    MAX_JAVA_HEAP,
                    INCL_TABLES,
                    SKIP_TABLES,
                    OVERWRITE_TABLES,
                    new_schema=False):

    url, driver_jar, driver_class = get_db_details(conn.jdbc_url, bin_dir)
    if driver_jar and driver_class:
        # Start Java virtual machine if not started already:
        class_paths = class_path + get_java_path_sep() + driver_jar

        init_jvm(class_paths, MAX_JAVA_HEAP)

        try:
            jdbc = Jdbc(url, conn.db_user, conn.db_password, conn.db_name,
                        conn.schema_name, driver_jar, driver_class, True, True)
            # TODO: Legg inn sjekk på at jdbc url er riktig, ikke bare på om db_name og skjema returnerer tabeller
            if jdbc:
                if new_schema:
                    run_ddl(
                        jdbc, 'CREATE SCHEMA IF NOT EXISTS "' +
                        conn.schema_name.upper() + '"')
                    # TODO: Ok med 'upper' for alle støttede databasetyper?
                else:
                    # Get database metadata:
                    db_tables, table_columns = get_db_meta(jdbc)
                    if not db_tables:
                        return "Database '" + conn.db_name + "', schema '" + conn.schema_name + "' returns no tables."

                    export_tables, overwrite_tables = table_check(
                        INCL_TABLES, SKIP_TABLES, OVERWRITE_TABLES, db_tables)
                return 'ok'

            if not export_tables and not new_schema:
                return 'No table data to export. Exiting.'

        except Exception as e:
            return e

    else:
        return 'Not a supported jdbc url. Exiting'
示例#4
0
def export_schema(class_path, max_java_heap, subsystem_dir, jdbc, db_tables):
    base_dir = subsystem_dir + '/documentation/'

    if os.path.isfile(base_dir + 'metadata.xml'):
        return

    init_jvm(class_path, max_java_heap)  # Start Java virtual machine
    WbManager = jp.JPackage('workbench').WbManager
    WbManager.prepareForEmbedded()
    batch = jp.JPackage('workbench.sql').BatchRunner()
    batch.setAbortOnError(True)

    batch.setBaseDir(base_dir)
    batch.runScript("WbConnect -url='" + jdbc.url + "' -password="******";")
    gen_report_str = "WbSchemaReport -file=metadata.xml -schemas=" + jdbc.db_schema + " -types=SYNONYM,TABLE,VIEW -includeProcedures=true \
                            -includeTriggers=true -writeFullSource=true;"

    batch.runScript(gen_report_str)
    add_row_count_to_schema_file(subsystem_dir, db_tables)
示例#5
0
def export_db_schema(JDBC_URL, bin_dir, class_path, java_path, MAX_JAVA_HEAP,
                     DB_USER, DB_PASSWORD, DB_NAME, DB_SCHEMA, subsystem_dir,
                     INCL_TABLES, SKIP_TABLES, OVERWRITE_TABLES, DDL_GEN,
                     schema_names):
    url, driver_jar, driver_class = get_db_details(JDBC_URL, bin_dir)
    if driver_jar and driver_class:
        # Start Java virtual machine if not started already:
        class_paths = class_path + get_java_path_sep() + driver_jar
        init_jvm(class_paths, MAX_JAVA_HEAP)
        try:
            jdbc = Jdbc(url, DB_USER, DB_PASSWORD, DB_NAME, DB_SCHEMA,
                        driver_jar, driver_class, True, True)
            if jdbc:
                # Get database metadata:
                db_tables, table_columns = get_db_meta(
                    jdbc)  # WAIT: Fiks så ikke henter to ganger (også i test)
                export_schema(class_paths, MAX_JAVA_HEAP, subsystem_dir, jdbc,
                              schema_names)
                add_row_count_to_schema_file(subsystem_dir, db_tables,
                                             DB_SCHEMA)
                export_tables, overwrite_tables = table_check(
                    INCL_TABLES, SKIP_TABLES, OVERWRITE_TABLES, db_tables)

            if export_tables:
                # Copy schema data:
                copy_db_schema(subsystem_dir, jdbc, class_path, MAX_JAVA_HEAP,
                               export_tables, bin_dir, table_columns,
                               overwrite_tables, DDL_GEN)
                return 'ok'
            else:
                print('No table data to export. Exiting.')
                return

        except Exception as e:
            print(e)
            return

    else:
        print('Not a supported jdbc url. Exiting')
        return
示例#6
0
def export_schema(class_paths, max_java_heap, java_path, subsystem_dir, jdbc,
                  db_tables):
    base_dir = os.path.join(subsystem_dir, 'header')
    Path(base_dir).mkdir(parents=True, exist_ok=True)

    if os.path.isfile(os.path.join(base_dir, 'metadata.xml')):
        return

    init_jvm(class_paths, max_java_heap)
    WbManager = jp.JPackage('workbench').WbManager
    WbManager.prepareForEmbedded()
    batch = jp.JPackage('workbench.sql').BatchRunner()
    batch.setAbortOnError(True)

    batch.setBaseDir(base_dir)
    batch.runScript("WbConnect -url='" + jdbc.url + "' -password="******";")
    gen_report_str = "WbSchemaReport -file=metadata.xml -schemas=" + jdbc.db_schema + " -types=SYNONYM,TABLE,VIEW -includeProcedures=true \
                            -includeTriggers=true -writeFullSource=true;"

    batch.runScript(gen_report_str)
    add_row_count_to_schema_file(subsystem_dir, db_tables)
示例#7
0
def test_db_connect(JDBC_URL, bin_dir, class_path, java_path, MAX_JAVA_HEAP,
                    DB_USER, DB_PASSWORD, DB_NAME, DB_SCHEMA, INCL_TABLES,
                    SKIP_TABLES, OVERWRITE_TABLES):

    url, driver_jar, driver_class = get_db_details(JDBC_URL, bin_dir)

    if driver_jar and driver_class:
        # Start Java virtual machine if not started already:
        class_paths = class_path + get_java_path_sep() + driver_jar
        if driver_jar != 'org.h2.Driver':
            class_paths = class_paths + get_java_path_sep() + os.path.join(
                bin_dir, 'vendor', 'jars', 'h2.jar')

        init_jvm(class_paths, MAX_JAVA_HEAP)

        try:
            jdbc = Jdbc(url, DB_USER, DB_PASSWORD, DB_NAME, DB_SCHEMA,
                        driver_jar, driver_class, True, True)
            # TODO: Legg inn sjekk på at jdbc url er riktig, ikke bare på om db_name og skjema returnerer tabeller
            if jdbc:
                # Get database metadata:
                db_tables, table_columns = get_db_meta(
                    jdbc)  # WAIT: Endre så ikke henter columns og her

                if not db_tables:
                    return "Database '" + DB_NAME + "', schema '" + DB_SCHEMA + "' returns no tables."

                export_tables, overwrite_tables = table_check(
                    INCL_TABLES, SKIP_TABLES, OVERWRITE_TABLES, db_tables)
                return 'ok'

            if not export_tables:
                return 'No table data to export. Exiting.'

        except Exception as e:
            return e

    else:
        return 'Not a supported jdbc url. Exiting'
示例#8
0
def export_db_schema(source, target, bin_dir, class_path, java_path,
                     MAX_JAVA_HEAP, subsystem_dir, INCL_TABLES, SKIP_TABLES,
                     OVERWRITE_TABLES, DDL_GEN):
    url, driver_jar, driver_class = get_db_details(source.jdbc_url, bin_dir)
    if driver_jar and driver_class:
        # Start Java virtual machine if not started already:
        class_paths = class_path + get_java_path_sep() + driver_jar
        init_jvm(class_paths, MAX_JAVA_HEAP)
        try:
            jdbc = Jdbc(url, source.db_user, source.db_password,
                        source.db_name, source.schema_name, driver_jar,
                        driver_class, True, True)
            if jdbc:
                # Get database metadata:
                db_tables, table_columns = get_db_meta(jdbc)
                export_schema(class_paths, MAX_JAVA_HEAP, java_path,
                              subsystem_dir, jdbc, db_tables)
                export_tables, overwrite_tables = table_check(
                    INCL_TABLES, SKIP_TABLES, OVERWRITE_TABLES, db_tables)

            if export_tables:
                # Copy schema data:
                copy_db_schema(subsystem_dir, jdbc, class_path, java_path,
                               MAX_JAVA_HEAP, export_tables, bin_dir,
                               table_columns, overwrite_tables, DDL_GEN,
                               target)
                return 'ok'
            else:
                print('No table data to export. Exiting.')
                return

        except Exception as e:
            print(e)
            return

    else:
        print('Not a supported jdbc url. Exiting')
        return