Package com.ibm.fhir.schema.app
Class SchemaPrinter
- java.lang.Object
-
- com.ibm.fhir.schema.app.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, useMain
.
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.sqldb2 -tvf schema.sql
- grants.sqldb2 -tvf grants.sql
- stored-procedures.sqldb2 -td@ -vf stored-procedures.sql
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) class
SchemaPrinter.PrintCallableStatement
(package private) class
SchemaPrinter.PrintConnection
(package private) class
SchemaPrinter.PrintPreparedStatement
(package private) class
SchemaPrinter.PrintResultSet
(package private) class
SchemaPrinter.PrintStatement
-
Field Summary
Fields Modifier and Type Field Description PrintStream
out
PrintStream
outGrants
PrintStream
outStoredProcedure
-
Constructor Summary
Constructors Constructor Description SchemaPrinter(boolean toFile, boolean multitenant)
constructor that switches behavior toFile our output stream.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addCommand(String sql)
process each sql so it can be 'cleaned' before putting into the linked map.static void
main(String[] args)
void
print()
prints the schema out to two locations (sometimes the same printstreamvoid
printGrants()
prints the grantsvoid
process()
processes through using a fake connection.void
processApplyGrants()
-
-
-
Field Detail
-
out
public PrintStream out
-
outStoredProcedure
public PrintStream outStoredProcedure
-
outGrants
public PrintStream outGrants
-
-
Constructor Detail
-
SchemaPrinter
public SchemaPrinter(boolean toFile, boolean multitenant) throws FileNotFoundException
constructor that switches behavior toFile our output stream.- Throws:
FileNotFoundException
-
-
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)
-
-