public final class JsonImport extends Importer implements TableReader
Runtime support is partial at this time; not all modes and features are supported. PRODATASET is not supported at this time.
Importer.FieldMaker, Importer.ImportContext| Modifier and Type | Field and Description |
|---|---|
private static CentralLogger |
LOG
Logger.
|
private com.fasterxml.jackson.core.JsonParser |
parser
JSON parser
|
private P2JIndex |
primaryIndex
The primary index which drives the duplicate resolution, in case the read mode is REPLACE.
|
b4tables, bufMan, childFieldsByChild, ctx, ds, inferredRelations, loader, peerMapping, readingBefore, readMode, savedCtx, source, tables| Constructor and Description |
|---|
JsonImport(SourceData source,
java.lang.String mode)
Constructor which immediately performs the import of a DATASET or a TEMP-TABLE.
|
| Modifier and Type | Method and Description |
|---|---|
private void |
addField(TempTableBuilder ttb,
java.lang.String name,
java.lang.Object val)
Add field to the temp-table.
|
static boolean |
createDatasetStructure(DataSet ds,
SourceData source)
Validates the
source and create the dataset structure by building all temp-tables according to
source JsonObject. |
static java.lang.Boolean |
createTableStructure(TempTableBuilder builder,
SourceData source)
Validates the
source and create the table structure for builder temp-table. |
private static P2JField |
inferFieldType(java.lang.String name,
java.lang.Object value)
TBA
|
private boolean |
parseRecord(boolean addLinkToParent)
Parse JSON record to retrieve fields' data, prepare table and populate the first record
|
boolean |
readDataset(DataSet ds)
Read JSON data from the input source and store it in each temp-table of the dataset.
|
private boolean |
readDataSetContent()
Reads the content of a dataset, by populating its whole set of tables.
|
private boolean |
readDataSetContent(java.lang.String name)
Reads the content of an empty dynamic dataset, by inferring its structure and
populating its whole set of tables.
|
private boolean |
readDatasetFromJsonObject(JsonObject source)
Iterates the
JsonObject source and populates the tables matching the properties. |
private boolean |
readNested(java.lang.String name)
Read nested table.
|
private boolean |
readRecord(boolean addLinkToParent)
Read JSON content from the stream corresponding with a single data record and store it in
the temp-table.
|
private boolean |
readRowFromJsonObject(TempTableSchema schema,
JsonObject jsonObject)
Creates a new record in target temp-table, iterates the
JsonObject source and populates the new
records with data extracted from the source JsonObject. |
boolean |
readTable(java.lang.String tableName,
TempTableBuilder table,
java.util.function.BiConsumer<RecordBuffer,Record> loader)
Read JSON data from the input source and store it in the just created empty TEMP-TABLE
which is a part of a DATA-SET.
|
boolean |
readTable(TemporaryBuffer buffer,
java.util.function.BiConsumer<RecordBuffer,Record> loader)
Read JSON data from the input source and store it in the temp-table.
|
boolean |
readTable(TempTableBuilder table,
java.util.function.BiConsumer<RecordBuffer,Record> loader)
Read JSON data from the input source and store it in the just created empty TEMP-TABLE.
|
private boolean |
readTableContent()
Read JSON content from reader and import records into the temp-table.
|
private boolean |
readTableFromJsonArray(TempTableSchema schema,
JsonArray jsonArray)
Iterates the
JsonArray source and for each element creates a new row in the target temp-table. |
protected ParmType |
typeOf(java.lang.Object val)
Get an inferred type of the value.
|
fillFromParent, getColumn, peekContext, persist, popContext, populateRecord, processHiddenFk, processId, processRowState, pushContext, setField, setField, setField, setParentValues, setupDatasetprivate static final CentralLogger LOG
private P2JIndex primaryIndex
private com.fasterxml.jackson.core.JsonParser parser
public JsonImport(SourceData source, java.lang.String mode)
source - Data source which normalizes access of various media to an input stream.mode - Read mode to determine how records are stored and how non-unique records are
handled. Not currently honored, except temp-table records are deleted if mode
is EMPTY.public static boolean createDatasetStructure(DataSet ds, SourceData source)
source and create the dataset structure by building all temp-tables according to
source JsonObject.ds - The Dataset to be populated with fields and finally prepared.source - The data source.true if operation is successful and false otherwise.public static java.lang.Boolean createTableStructure(TempTableBuilder builder, SourceData source)
source and create the table structure for builder temp-table.builder - The TempTableBuilder to be populated with fields and finally prepared.source - The data source.true if operation is successful, false on failure, or null
if source is not JSONOBJECT or JSONARRAY.private static P2JField inferFieldType(java.lang.String name, java.lang.Object value)
public boolean readTable(TempTableBuilder table, java.util.function.BiConsumer<RecordBuffer,Record> loader) throws PersistenceException
table - TEMP-TABLE to be loaded.loader - A BiConsumer which helps loading a Record into the buffer.true on success.PersistenceException - if there is any error reading or storing JSON data.public boolean readTable(java.lang.String tableName,
TempTableBuilder table,
java.util.function.BiConsumer<RecordBuffer,Record> loader)
throws PersistenceException
readTable in interface TableReadertableName - table nametable - TEMP-TABLE to be loaded.loader - A BiConsumer which helps loading a Record into the buffer.true on success.PersistenceException - if there is any error reading or storing JSON data.public boolean readTable(TemporaryBuffer buffer, java.util.function.BiConsumer<RecordBuffer,Record> loader) throws PersistenceException
buffer - A buffer of a table in which data is stored.loader - A BiConsumer which helps loading a Record into the buffer.true on success.PersistenceException - if there is any error reading or storing JSON data.public boolean readDataset(DataSet ds) throws PersistenceException
ds - The DataSet in which data is stored.true on success.PersistenceException - if there is any error reading or storing JSON data.private boolean readDataSetContent(java.lang.String name)
throws java.io.IOException,
PersistenceException
name - dataset name.true on success.java.io.IOException - If an IO error occurred while getting the data.PersistenceException - If an error occurred while persisting the read data.private boolean readDataSetContent()
throws java.io.IOException,
PersistenceException
true on success.java.io.IOException - If an IO error occurred while getting the data.PersistenceException - If an error occurred while persisting the read data.private boolean readTableContent()
throws java.io.IOException,
PersistenceException
This version ensures that the group and decimal separators are ',' and '.' for the duration of the deserialization.
java.io.IOException - if there is an error reading JSON content from the stream.PersistenceException - if there is an error storing data in the temp-table.private boolean parseRecord(boolean addLinkToParent)
throws java.io.IOException,
PersistenceException
addLinkToParent - flag indicating that a link to the parent must be addedtrue on success.java.io.IOException - on I/O errorPersistenceException - on error.protected ParmType typeOf(java.lang.Object val) throws PersistenceException
typeOf in class Importerval - The value to be analyzed.PersistenceException - when the type cannot be inferred from the provided value.private boolean readRecord(boolean addLinkToParent)
throws java.io.IOException,
PersistenceException
addLinkToParent - flag indicating that a link to the parent must be added.java.io.IOException - if there is an error reading JSON content from the stream.PersistenceException - if there is an error storing data in the temp-table.private boolean readNested(java.lang.String name)
throws PersistenceException,
java.io.IOException
name - The name of the table to be read.true on success and false on fail.PersistenceException - on database error.java.io.IOException - on file I/O error.private boolean readDatasetFromJsonObject(JsonObject source) throws PersistenceException
JsonObject source and populates the tables matching the properties.source - The source which contains the JsonObject source.true on success and false otherwise.PersistenceException - on unexpected events related to persistence.private boolean readTableFromJsonArray(TempTableSchema schema, JsonArray jsonArray) throws PersistenceException
JsonArray source and for each element creates a new row in the target temp-table.schema - The schema of the temp-table.jsonArray - The source which contains the JsonArray source.true on success and false otherwise.PersistenceException - on unexpected events related to persistence.private void addField(TempTableBuilder ttb, java.lang.String name, java.lang.Object val) throws PersistenceException
ttb - The destination temp-table builder.name - The name of the field to be added.val - The value of field. It is used for inferring the type of the new field.PersistenceException - If the type of the field cannot be inferred from the provided value.private boolean readRowFromJsonObject(TempTableSchema schema, JsonObject jsonObject) throws PersistenceException
JsonObject source and populates the new
records with data extracted from the source JsonObject.schema - The schema of the temp-table.jsonObject - The source which contains the JsonObject source.true on success and false otherwise.PersistenceException - on unexpected events related to persistence.