Class SchemaPrinter


  • public class SchemaPrinter
    extends java.lang.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

    • Field Detail

      • out

        public java.io.PrintStream out
      • outStoredProcedure

        public java.io.PrintStream outStoredProcedure
      • outGrants

        public java.io.PrintStream outGrants
    • Constructor Detail

      • SchemaPrinter

        public SchemaPrinter​(boolean toFile,
                             boolean multitenant)
                      throws java.io.FileNotFoundException
        constructor that switches behavior toFile our output stream.
        Throws:
        java.io.FileNotFoundException
    • Method Detail

      • addCommand

        public void addCommand​(java.lang.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​(java.lang.String[] args)