Class SchemaPrinter


  • public class SchemaPrinter
    extends Object
    The SchemaPrinter outputs the DDL into three files - schema.sql, grants.sql, stored-procedures.sql.
    These files are generated using Mock java.sql objects. These mock objects follow through the code to
    capture the SQL as it flows to the prospective database:
    • Build a JDBCTarget with PrintConnection
    • The Database Tools builds the schema retrieving a PreparedStatement, CallableStatement or Statement from the PrintConnection
    • The PrintConnection passes a PrintPreparedStatement, PrintCallableStatement, PrintStatement
    • As the prepareStatement, execute or executeQuery are executed, the SQL passed is put into the commands or stored procedures map.
    • the results, after the full schema generation, is printed out to console or files

      • For real work, use Main.

        To run this code, build the jar (fhir-database-utils and fhir-persistence-schema)
        java -cp ./fhir-database-utils.jar:fhir-persistence-schema.jar com.ibm.fhir.schema.app.SchemaPrinter [--to-file]

        Without to-file, the output is the current System.out else it's schema.sql, grants.sql and stored-procedures.sql of
        the current directory.

        For db2 import to
        - schema.sql db2 -tvf schema.sql
        - grants.sql db2 -tvf grants.sql
        - stored-procedures.sql db2 -td@ -vf stored-procedures.sql

    • Method Detail

      • addCommand

        public void addCommand​(String sql)
        process each sql so it can be 'cleaned' before putting into the linked map.
      • process

        public void process()
        processes through using a fake connection.
      • processApplyGrants

        public void processApplyGrants()
      • printGrants

        public void printGrants()
        prints the grants
      • print

        public void print()
        prints the schema out to two locations (sometimes the same printstream
      • main

        public static void main​(String[] args)