public final class XmlImport
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 | Class and Description |
---|---|
private static class |
XmlImport.Relation
Internal structure for storing a
DataSet relation until the full set of tables is
read. |
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
ATTR_NIL
Nil attribute name
|
private int |
attrSetOffset
The location of the currently processed element.
|
private java.util.Map<java.lang.String,java.lang.String> |
crtAttSet
The set of attributes of the current read XML element.
|
private DataSet |
ds
Current dataset, if one is being processed.
|
private static java.lang.String |
ELEM_SCHEMA
XSD schema element name
|
private ExtentTracker |
extentTracker
Helper which tracks current index values for extent fields.
|
private java.util.Map<java.lang.String,java.lang.String> |
fieldTypeMapping
The desired mapping of fields to new type, if one is defined.
|
private boolean |
knownTableSchema
Flags whether the processed table has a known schema or it should be read from file.
|
private java.util.function.BiConsumer<RecordBuffer,Record> |
loader
Helper for setting a
Record into a buffer, avoiding direct access to private method. |
private static java.util.logging.Logger |
log
Logger for objects of this type.
|
private java.util.Map<java.lang.String,rowid> |
peerMapping
The mapping between the before and after-images.
|
private Buffer |
proxy
Buffer proxy.
|
private javax.xml.stream.XMLStreamReader |
reader
The stream where the data is read from.
|
(package private) boolean |
readingBefore
If
true we are reading the before tables. |
private SerializeOptions.Read |
readMode
Read mode to determine how records are stored and how non-unique records are handled
|
private java.util.List<XmlImport.Relation> |
relations
The list of read relations of a dataset being read.
|
private TempTableSchema |
schema
Temp-table schema information.
|
private java.lang.String |
schemaLocation
'External' schema location, if one is provided.
|
private SourceData |
source
Data source which normalizes access of various media to an input stream.
|
private java.util.Map<java.lang.String,AbstractTempTable> |
tables
The set of temp-table builders for a dataset.
|
private java.util.Map<CaseInsensitiveString,java.lang.String> |
tablesByXmlName
The mapping of the legacy table names by their (case-insensitive) XML name.
|
private static java.lang.String |
TEXT_TRUE
String constant for 'true'
|
private AbstractTempTable |
tt
Current temp-table, if one is being processed.
|
private java.lang.String |
ttName
The future name of the read temp-table.
|
private java.util.Map<java.lang.String,P2JIndex> |
uniqueIndexes
All unique indexes in this dataset, mapped by their unique names.
|
private boolean |
useLobs
Use CLOB/BLOB instead of character/raw type? (Value of
override-default-mapping parameter). |
private SerializeOptions.Verify |
verifySchemaMode
Verify schema mode.
|
Constructor and Description |
---|
XmlImport(SourceData source,
java.lang.String readMode,
java.lang.String schemaLocation,
boolean overrideDefaultMapping,
java.util.Map<java.lang.String,java.lang.String> fieldTypeMapping,
java.lang.String verifySchemaMode)
Constructor which configures the importer for an import of a Dataset or a TempTable/Buffer.
|
Modifier and Type | Method and Description |
---|---|
private boolean |
checkNil(TempTableSchema.Column column,
javax.xml.stream.XMLStreamReader reader)
Check whether the current temp-table value read from XML content is null.
|
private java.lang.String |
get4GLType(java.lang.String type,
java.lang.String proType,
java.lang.String nullable,
boolean useLobs,
java.lang.String tableName,
java.lang.String fieldName)
Helper method for detecting the 4GL field type using XML data types.
|
private java.lang.String |
getXmlAttribute(java.lang.String fullName)
Obtain the value of an attribute for the currently processed XML element.
|
boolean |
importDataset(DataSet dataSet,
java.util.function.BiConsumer<RecordBuffer,Record> loader)
Imports a dataset.
|
boolean |
importDatasetSchema(DataSet ds)
Configures a dataset schema or validates it against the XML file.
|
boolean |
importTable(AbstractTempTable tempTable,
java.util.function.BiConsumer<RecordBuffer,Record> loader)
Reads a TEMP-TABLE from the configured source.
|
boolean |
importTempTableSchema(AbstractTempTable tt)
Configures a temp-table schema or validates it against the XML file.
|
private javax.xml.stream.XMLInputFactory |
newXmlInputFactory()
Create a factory which treats XML 1.0 files as XML 1.1.
|
private java.io.Reader |
openReader(java.io.InputStream stream)
Create a
Reader which has the encoding as specified in the XML file targeted by this stream. |
private boolean |
readContent(java.lang.String rowName)
Read XML content from reader and import records into the temp-table.
|
private boolean |
readDatasetData()
Reads data from XML stream and populates the tables of a
DataSet . |
private boolean |
readDatasetSchema(boolean verify)
Reads and processes a
DataSet schema. |
private boolean |
readIndex(java.lang.String indexName,
java.lang.String originalName,
java.lang.String nsPrefix,
boolean primary,
boolean unique,
boolean word)
Reads and process an index from the XML stream.
|
private boolean |
readRecord()
Read XML content from the stream corresponding with a single data record and store it in
the temp-table.
|
private boolean |
readRecord2()
Read XML content from the stream corresponding with a single data record and store it in
the temp-table.
|
private boolean |
readSchema()
Read XSD schema data from the XML content.
|
private boolean |
readTableSchema(AbstractTempTable tempTable,
java.lang.String nsPrefix,
java.lang.String nsUri)
Reads and processes a
TEMP-TABLE schema. |
private boolean |
readTableSchema(java.lang.String tableName,
java.lang.String nsPrefix)
The read table is automatically added to the dataset if one is processed.
|
private boolean |
readTableSchema(java.lang.String xmlNodeName,
java.lang.String nsPrefix,
java.lang.String nsUri)
Reads and processes an
AbstractTempTable schema. |
private java.lang.String |
readText()
Read text content from within an element or a CDATA section.
|
private void |
setField(TempTableSchema.Column column,
java.lang.String name,
java.lang.String value)
Set the value of a single field in the temp-table record currently being read from the XML
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 XML
content.
|
private boolean |
skipRecord(java.lang.String tableName)
Skip the whole subtree because the record belongs to an unknown table.
|
private static final java.util.logging.Logger log
private static final java.lang.String ELEM_SCHEMA
private static final java.lang.String ATTR_NIL
private static final java.lang.String TEXT_TRUE
private final SerializeOptions.Read readMode
private final SerializeOptions.Verify verifySchemaMode
private final boolean useLobs
override-default-mapping
parameter).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 final SourceData source
private DataSet ds
private AbstractTempTable tt
private java.lang.String ttName
private final java.util.Map<java.lang.String,java.lang.String> fieldTypeMapping
private final java.lang.String schemaLocation
private final java.util.Map<java.lang.String,AbstractTempTable> tables
private java.util.Map<CaseInsensitiveString,java.lang.String> tablesByXmlName
private java.util.List<XmlImport.Relation> relations
private final java.util.Map<java.lang.String,P2JIndex> uniqueIndexes
boolean readingBefore
true
we are reading the before tables.private java.util.Map<java.lang.String,rowid> peerMapping
private javax.xml.stream.XMLStreamReader reader
private java.util.Map<java.lang.String,java.lang.String> crtAttSet
getXmlAttribute()
method.private int attrSetOffset
crtAttSet
, which acts as a cache. If the position of the current XML element is
different from attrSetOffset
then crtAttSet
needs to be updated.private boolean knownTableSchema
public XmlImport(SourceData source, java.lang.String readMode, java.lang.String schemaLocation, boolean overrideDefaultMapping, java.util.Map<java.lang.String,java.lang.String> fieldTypeMapping, java.lang.String verifySchemaMode)
source
- XML data source which normalizes access of various media to an input stream.readMode
- 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.schemaLocation
- Path to XML schema (not currently used).overrideDefaultMapping
- Not currently used.fieldTypeMapping
- Not currently used.verifySchemaMode
- Not currently used.public boolean importDatasetSchema(DataSet ds)
ds
- The destination for read schema.true
on success. On failure, false
is returned and the eventual
error is already displayed.public boolean importTempTableSchema(AbstractTempTable tt)
tt
- The destination for read schema.true
on success. On failure, false
is returned and the eventual error is
already displayed.public boolean importDataset(DataSet dataSet, java.util.function.BiConsumer<RecordBuffer,Record> loader)
dataSet
- The destination for read data.loader
- A BiConsumer
which helps loading a Record
into the buffer.true
on success. On failure, false
is returned and the eventual
error is already displayed.public boolean importTable(AbstractTempTable tempTable, java.util.function.BiConsumer<RecordBuffer,Record> loader)
tempTable
- Temp-table in which data will be stored.loader
- A BiConsumer
which helps loading a Record
into the buffer.true
on success.private java.io.Reader openReader(java.io.InputStream stream) throws java.io.IOException
Reader
which has the encoding as specified in the XML file targeted by this stream.
If no encoding is specified, it defaults to UTF-8.
The reader is wrapped in a filter which automatically escapes ISO control characters which are not whitespace.
java.io.IOException
private javax.xml.stream.XMLInputFactory newXmlInputFactory()
private boolean readTableSchema(AbstractTempTable tempTable, java.lang.String nsPrefix, java.lang.String nsUri) throws javax.xml.stream.XMLStreamException
TEMP-TABLE
schema.nsPrefix
- The detected XML namespace prefix.nsUri
- The detected XML namespace URI.true
on success and false
otherwise. When false
is returned
then the error message has already been dispatched to ErrorManager
.javax.xml.stream.XMLStreamException
- If a XML-related error occurs (like an unexpected end of stream).private boolean readDatasetSchema(boolean verify) throws javax.xml.stream.XMLStreamException
DataSet
schema. If the DataSet
is in CLEAR state, the
structure is initialized and its tables and relations are set up. Otherwise the schema is
checked according to verifySchemaMode
.verify
- When true
the schema is only verified. Otherwise the methods attempts to create the
read schema into the dataset.true
on success and false
otherwise. When false
is returned
then the error message has already been dispatched to ErrorManager
.javax.xml.stream.XMLStreamException
- If a XML-related error occurs (like an unexpected end of stream).private boolean readTableSchema(java.lang.String xmlNodeName, java.lang.String nsPrefix, java.lang.String nsUri) throws javax.xml.stream.XMLStreamException
AbstractTempTable
schema. If the TempTable
is in CLEAR state, the
structure is initialized. Otherwise the schema is checked according to verifySchemaMode
.xmlNodeName
- The detected XML node name.nsPrefix
- The detected XML namespace prefix.nsUri
- The detected XML namespace URI.true
on success and false
otherwise. When false
is returned
then the error message has already been dispatched to ErrorManager
.javax.xml.stream.XMLStreamException
- If a XML-related error occurs (like an unexpected end of stream).private boolean readIndex(java.lang.String indexName, java.lang.String originalName, java.lang.String nsPrefix, boolean primary, boolean unique, boolean word) throws javax.xml.stream.XMLStreamException
indexName
- The index name (aka XML name).originalName
- The index's original name only if the xml name was altered because of collisions.nsPrefix
- The detected XML namespace prefix.primary
- true
if this is a primary index.unique
- true
is this is an unique index.word
- true
is this is a word index.true
on success and false
otherwise. When false
is returned
then the error message has already been dispatched to ErrorManager
.javax.xml.stream.XMLStreamException
- If a XML-related error occurs (like an unexpected end of stream).private boolean readDatasetData() throws javax.xml.stream.XMLStreamException, PersistenceException
DataSet
.true
on success and false
otherwise. When false
is returned
then the error message has already been dispatched to ErrorManager
.javax.xml.stream.XMLStreamException
- if a XML-related error occurs (like an unexpected end of stream).PersistenceException
- if a persistence error occurs while saving data to database.private boolean readTableSchema(java.lang.String tableName, java.lang.String nsPrefix) throws javax.xml.stream.XMLStreamException
<xsd:element>
node for this table was already processed
(no look-ahead) in order to decide to call this method.tableName
- The name of the table which is being processed.nsPrefix
- The detected XML namespace prefix.true
if the operation is successful. If the operation fails, false
is returned.javax.xml.stream.XMLStreamException
- in the event of an exception occurred while reading the XML stream.private boolean readContent(java.lang.String rowName) throws javax.xml.stream.XMLStreamException, PersistenceException
rowName
- Element name for temp-table record data in XML content.javax.xml.stream.XMLStreamException
- if there is an error reading XML content from the stream.PersistenceException
- if there is an error storing data in the temp-table.private boolean readSchema() throws javax.xml.stream.XMLStreamException
The current implementation simply skips this section of the content, if present.
javax.xml.stream.XMLStreamException
- if there is an error reading XML content from the stream.private boolean skipRecord(java.lang.String tableName) throws javax.xml.stream.XMLStreamException
tableName
- The table name.true
on success. Otherwise an error is issued before returning false
.javax.xml.stream.XMLStreamException
- if the XML stream cannot be parsed.private boolean readRecord() throws javax.xml.stream.XMLStreamException, PersistenceException
This version ensures that the group and decimal separators are ',' and '.' for the duration of the deserialization.
javax.xml.stream.XMLStreamException
- if there is an error reading XML content from the stream.PersistenceException
- if there is an error storing data in the temp-table.private boolean readRecord2() throws javax.xml.stream.XMLStreamException, PersistenceException
javax.xml.stream.XMLStreamException
- if there is an error reading XML content from the stream.PersistenceException
- if there is an error storing data in the temp-table.private java.lang.String readText() throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
- if there is an error reading XML content from the stream.private boolean checkNil(TempTableSchema.Column column, javax.xml.stream.XMLStreamReader reader)
column
- Schema information for the associated column.reader
- XML stream reader.true
if the XML content is nil; else false
.ErrorConditionException
- if value is nil and column does not allow null values.private void setField(TempTableSchema.Column column, java.lang.String name, java.lang.String value) throws PersistenceException
column
- Schema information for the associated column.name
- Element or attribute name associated with serialized XML data for a temp-table
column.value
- Data value read from XML content. Set to null
to represent unknown value.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 XML data for a temp-table
column.value
- Data value read from XML 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.private java.lang.String getXmlAttribute(java.lang.String fullName)
attrSetOffset
to compare the location of the current element. If they are different,
the cache is updated. Note that the cache is updated only on request, the current of
crtAttSet
may be stalled if the getXmlAttribute()
was not yet called for the
new element.fullName
- The full-name of the attribute.null
if there is no such attribute
in current element.private java.lang.String get4GLType(java.lang.String type, java.lang.String proType, java.lang.String nullable, boolean useLobs, java.lang.String tableName, java.lang.String fieldName)
type
- The pure xsd
type.proType
- Additional information needed to distinct the original 4GL type.nullable
- Whether the original field type was nullable.useLobs
- If true
, clob
and blob
types will be used instead of character
and raw
, respectively.tableName
- Optional. If specified the table name is looked up in the type map instead of the type
specified in XML file.fieldName
- Optional. If specified the field name is looked up in the type map instead of the type
specified in XML file.null
is returned.Util.xsdMap
,
Util.xsdProdataMap