Package com.nickbenn.room.service
Class Parser
- java.lang.Object
-
- com.nickbenn.room.service.Parser
-
public class Parser extends Object
Provides a simple parsing service that extracts DDL from a Room-generated JSON schema file. This class is not a Java application (i.e. it does not provide an entry pointmainmethod), but is suitable for consumption by many different types of applications or plugins.The JSON schema produced by Room is structured as shown below. Property values, properties that are not read by this implementation, and repeated properties in arrays are indicated by "
..." placeholders.{ "database": { "version": ..., "entities": [ { "tableName": "...", "createSql": "...", indices: [ { "name": "...", "createSql": "...", ... }, ... ], ... }, ... ], "views": [ { "viewName": "...", "createSql": "..." }, ... ], }, ... }In general, the SQL fragments in the values of the
createSqlproperties have placeholder tokens referencing the name of the relevant table or view for each. TheEntity,Index, andViewdata-transfer object (DTO) classes replace these placeholders in their implementations of theStreamable.stream()methods.
-
-
Constructor Summary
Constructors Constructor Description Parser()Initializes this instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidparse(InputStream input, OutputStream output)Parses Room schema DDL from JSON content obtained frominput, and writes the extracted DDL (with placeholders replaced by the appropriate table and view names) tooutput.
-
-
-
Method Detail
-
parse
public void parse(InputStream input, OutputStream output) throws IOException, JsonIOException, JsonSyntaxException
Parses Room schema DDL from JSON content obtained frominput, and writes the extracted DDL (with placeholders replaced by the appropriate table and view names) tooutput.- Parameters:
input-InputStreamsource from which Room schema will be read.output-PrintStream- Throws:
IOException- If unable to read frominputor unable to write tooutput.JsonIOException- If unable to read JSON from aReaderattached toinput.JsonSyntaxException- If content read frominputdoes not contain valid JSON.
-
-