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 pointmain
method), 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
createSql
properties have placeholder tokens referencing the name of the relevant table or view for each. TheEntity
,Index
, andView
data-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 void
parse(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
-InputStream
source from which Room schema will be read.output
-PrintStream
- Throws:
IOException
- If unable to read frominput
or unable to write tooutput
.JsonIOException
- If unable to read JSON from aReader
attached toinput
.JsonSyntaxException
- If content read frominput
does not contain valid JSON.
-
-