public final class JsonImport
extends java.lang.Object
Runtime support is partial at this time; not all modes and features are supported. PRODATASET is not supported at this time.
Modifier and Type | Field and Description |
---|---|
private DataSet |
ds
Current dataset, if one is being processed.
|
private ExtentTracker |
extentTracker
Helper which tracks current index values for extent fields
|
private java.util.function.BiConsumer<RecordBuffer,Record> |
loader
Helper for setting a
Record into a buffer, avoiding direct access to private method. |
private com.fasterxml.jackson.core.JsonParser |
parser
JSON parser
|
private java.util.Map<java.lang.String,rowid> |
peerMapping
Associates the
prod:id to their record's rowid . |
private P2JIndex |
primaryIndex
The primary index which drives the duplicate resolution, in case the read mode is REPLACE.
|
private Buffer |
proxy
Buffer proxy
|
private boolean |
readingBefore
true when reading a before-table image. |
private SerializeOptions.Read |
readMode
Read mode to determine how records are stored and how non-unique records are handled
|
private TempTableSchema |
schema
Temp-table schema information
|
private SourceData |
source
Data source which normalizes access of various media to an input stream.
|
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 |
---|---|
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 boolean |
createTableStructure(TempTableBuilder builder,
SourceData source)
Validates the
source and create the table structure for builder temp-table. |
private TempTableSchema.Column |
getColumn(java.lang.String name)
Get schema information for the column associated with the given name.
|
private static P2JField |
inferFieldType(java.lang.String name,
java.lang.Object value)
TBA
|
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 |
readDatasetFromJsonObject(JsonObject source)
Iterates the
JsonObject source and populates the tables matching the properties. |
private boolean |
readRecord()
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(TemporaryBuffer buffer,
java.util.function.BiConsumer<RecordBuffer,Record> loader)
Read JSON data from the input source and store it in the 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. |
private void |
setField(TempTableSchema.Column column,
java.lang.String name,
java.lang.String value,
boolean extent)
Set the value of a single field in the temp-table record currently being read from the JSON content.
|
private void |
setField(TempTableSchema.Column column,
java.lang.String name,
java.lang.String value,
int index)
Set the value of a single field in the temp-table record currently being read from the JSON content.
|
private final SerializeOptions.Read readMode
private Buffer proxy
private java.util.function.BiConsumer<RecordBuffer,Record> loader
Record
into a buffer, avoiding direct access to private method.private TempTableSchema schema
private ExtentTracker extentTracker
private P2JIndex primaryIndex
private com.fasterxml.jackson.core.JsonParser parser
private final SourceData source
private DataSet ds
private boolean readingBefore
true
when reading a before-table image.private java.util.Map<java.lang.String,rowid> peerMapping
prod:id
to their record's rowid
.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 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 and false
otherwise.private static P2JField inferFieldType(java.lang.String name, java.lang.Object value)
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() 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 readRecord() throws java.io.IOException, PersistenceException
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 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 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.private TempTableSchema.Column getColumn(java.lang.String name)
name
- Element or attribute name associated with serialized JSON data for a temp-table column.ErrorConditionException
- if name
is not associated with a column.private void setField(TempTableSchema.Column column, java.lang.String name, java.lang.String value, boolean extent) throws PersistenceException
column
- Schema information for the associated column.name
- Element or attribute name associated with serialized JSON data for a temp-table column.value
- Data value read from JSON content. Set to null
to represent unknown value.extent
- true
to indicate an extent field; false
if scalar.PersistenceException
- if there is an error storing data in the temp-table.private void setField(TempTableSchema.Column column, java.lang.String name, java.lang.String value, int index) throws PersistenceException
column
- Schema information for the associated column.name
- Element or attribute name associated with serialized JSON data for a temp-table column.value
- Data value read from JSON content. Set to null
to represent unknown value.index
- The offset value in case of an extent field. -1 to be ignored.PersistenceException
- if there is an error storing data in the temp-table.