Package org.apache.metamodel.xml
Class XmlDomDataContext
- java.lang.Object
-
- org.apache.metamodel.AbstractDataContext
-
- org.apache.metamodel.QueryPostprocessDataContext
-
- org.apache.metamodel.xml.XmlDomDataContext
-
- All Implemented Interfaces:
org.apache.metamodel.convert.HasReadTypeConverters,org.apache.metamodel.DataContext
public class XmlDomDataContext extends org.apache.metamodel.QueryPostprocessDataContextA DataContext strategy that reads XML content and maps it to a table-based model similar to the rest of MetaModel. Tables are created by examining the data in the XML file, NOT by reading XML Schemas (xsd/dtd's). This enables compliancy with ALL xml formats but also raises a risk that two XML files with the same format wont nescesarily yield the same table model if some optional attributes or tags are omitted in one of the files. The parsing method applied in this datacontext is DOM based, which means that at upon parsing (only a single point in time), the whole file will be read and it's tree structure kept in memory. Therefore this DataContext is NOT appropriate for large XML files (10's, 100's or 1000's of megabytes).- See Also:
XmlSaxDataContext
-
-
Field Summary
Fields Modifier and Type Field Description static StringNATIVE_TYPE_ATTRIBUTEstatic StringNATIVE_TYPE_FOREIGN_KEYstatic StringNATIVE_TYPE_PRIMARY_KEYstatic StringNATIVE_TYPE_TEXT
-
Constructor Summary
Constructors Constructor Description XmlDomDataContext(File file)Creates an XML DataContext strategy based on a file.XmlDomDataContext(File file, boolean autoFlattenTables)XmlDomDataContext(String schemaName, Document document, boolean autoFlattenTables)Creates an XML DataContext strategy based on an already parsed Document.XmlDomDataContext(URL url, boolean autoFlattenTables)XmlDomDataContext(org.apache.metamodel.util.Resource resource, boolean autoFlattenTables)Creates an XML DataContext strategy based on a file.XmlDomDataContext(InputSource inputSource, String schemaName, boolean autoFlattenTables)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description XmlDomDataContextautoFlattenTables()Automatically flattens tables that only contain a single data carrying column.XmlDomDataContextflattenTables(org.apache.metamodel.schema.Relationship relationship)static Attr[]getAttributes(Element element)static Element[]getChildElements(Element element)protected org.apache.metamodel.schema.SchemagetMainSchema()protected StringgetMainSchemaName()static StringgetTextContent(Element element)static booleanhasSiblings(Element element)booleanisAutoFlattenTables()static booleanisRootElement(Element element)XmlDomDataContextloadSchema()Loads the schema if it hasn't been loaded beforeorg.apache.metamodel.data.DataSetmaterializeMainSchemaTable(org.apache.metamodel.schema.Table table, List<org.apache.metamodel.schema.Column> columnList, int maxRows)XmlDomDataContextreloadSchema()Forces a fresh load of the schema, even though it has already been loadedvoidsetAutoFlattenTables(boolean autoFlattenTables)-
Methods inherited from class org.apache.metamodel.QueryPostprocessDataContext
addConverter, executeCountQuery, executePrimaryKeyLookupQuery, executeQuery, getDefaultSchemaName, getSchemaByNameInternal, getSchemaNamesInternal, isMainSchemaTable, isScalarFunctionMaterialized, materializeFromItem, materializeMainSchemaTable, materializeMainSchemaTable, materializeMainSchemaTableSelect, materializeTable
-
Methods inherited from class org.apache.metamodel.AbstractDataContext
compileQuery, executeQuery, executeQuery, getColumnByQualifiedLabel, getDefaultSchema, getSchemaByName, getSchemaNames, getSchemas, getTableByQualifiedLabel, isQualifiedPathDelim, onSchemaCacheRefreshed, parseQuery, query, refreshSchemas
-
-
-
-
Field Detail
-
NATIVE_TYPE_PRIMARY_KEY
public static final String NATIVE_TYPE_PRIMARY_KEY
- See Also:
- Constant Field Values
-
NATIVE_TYPE_FOREIGN_KEY
public static final String NATIVE_TYPE_FOREIGN_KEY
- See Also:
- Constant Field Values
-
NATIVE_TYPE_ATTRIBUTE
public static final String NATIVE_TYPE_ATTRIBUTE
- See Also:
- Constant Field Values
-
NATIVE_TYPE_TEXT
public static final String NATIVE_TYPE_TEXT
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
XmlDomDataContext
public XmlDomDataContext(String schemaName, Document document, boolean autoFlattenTables)
Creates an XML DataContext strategy based on an already parsed Document.- Parameters:
schemaName-document-autoFlattenTables-
-
XmlDomDataContext
public XmlDomDataContext(org.apache.metamodel.util.Resource resource, boolean autoFlattenTables) throws IllegalArgumentExceptionCreates an XML DataContext strategy based on a file.- Parameters:
resource- the resource to parseautoFlattenTables- a parameter indicating whether or not tags with only text content or a single attribute should be flattened with it's parent table- Throws:
IllegalArgumentException- if the file does not exist
-
XmlDomDataContext
public XmlDomDataContext(File file, boolean autoFlattenTables)
-
XmlDomDataContext
public XmlDomDataContext(InputSource inputSource, String schemaName, boolean autoFlattenTables)
-
XmlDomDataContext
public XmlDomDataContext(URL url, boolean autoFlattenTables) throws IllegalArgumentException
- Throws:
IllegalArgumentException
-
XmlDomDataContext
public XmlDomDataContext(File file)
Creates an XML DataContext strategy based on a file.- Parameters:
file- the file to parse
-
-
Method Detail
-
isAutoFlattenTables
public boolean isAutoFlattenTables()
-
setAutoFlattenTables
public void setAutoFlattenTables(boolean autoFlattenTables)
-
materializeMainSchemaTable
public org.apache.metamodel.data.DataSet materializeMainSchemaTable(org.apache.metamodel.schema.Table table, List<org.apache.metamodel.schema.Column> columnList, int maxRows)- Specified by:
materializeMainSchemaTablein classorg.apache.metamodel.QueryPostprocessDataContext
-
getMainSchemaName
protected String getMainSchemaName() throws org.apache.metamodel.MetaModelException
- Specified by:
getMainSchemaNamein classorg.apache.metamodel.QueryPostprocessDataContext- Throws:
org.apache.metamodel.MetaModelException
-
getMainSchema
protected org.apache.metamodel.schema.Schema getMainSchema() throws org.apache.metamodel.MetaModelException- Specified by:
getMainSchemain classorg.apache.metamodel.QueryPostprocessDataContext- Throws:
org.apache.metamodel.MetaModelException
-
reloadSchema
public XmlDomDataContext reloadSchema()
Forces a fresh load of the schema, even though it has already been loaded
-
loadSchema
public XmlDomDataContext loadSchema()
Loads the schema if it hasn't been loaded before
-
hasSiblings
public static boolean hasSiblings(Element element)
-
isRootElement
public static boolean isRootElement(Element element)
-
flattenTables
public XmlDomDataContext flattenTables(org.apache.metamodel.schema.Relationship relationship)
-
autoFlattenTables
public XmlDomDataContext autoFlattenTables()
Automatically flattens tables that only contain a single data carrying column. Data carrying column are all columns that are not artificial columns (created to enable referential integrity between tag-to-table mapped tables).
-
-