public object GetColumnSchema(XmlNode node, bool fIgnoreNamespace) { Debug.Assert(node != null, "Argument validation"); TableSchemaInfo tableSchemaInfo = null; XmlNode nodeRegion = (node.NodeType == XmlNodeType.Attribute) ? ((XmlAttribute)node).OwnerElement : node.ParentNode; do { if (nodeRegion == null || nodeRegion.NodeType != XmlNodeType.Element) { return(null); } tableSchemaInfo = (TableSchemaInfo)(fIgnoreNamespace ? tableSchemaMap[nodeRegion.LocalName] : tableSchemaMap[nodeRegion]); nodeRegion = nodeRegion.ParentNode; } while(tableSchemaInfo == null); if (fIgnoreNamespace) { return(tableSchemaInfo.ColumnsSchemaMap[node.LocalName]); } else { return(tableSchemaInfo.ColumnsSchemaMap[node]); } }
private TableSchemaInfo AddTableSchema(XmlNameTable nameTable, DataTable table) { string encodedTableName = table.EncodedTableName; string localName = nameTable.Get(encodedTableName); if (localName == null) { localName = nameTable.Add(encodedTableName); } table.encodedTableName = localName; string namespaceURI = nameTable.Get(table.Namespace); if (namespaceURI == null) { namespaceURI = nameTable.Add(table.Namespace); } else if (table.tableNamespace != null) { table.tableNamespace = namespaceURI; } TableSchemaInfo info = new TableSchemaInfo(table); this.tableSchemaMap[new XmlNodeIdentety(localName, namespaceURI)] = info; return(info); }
private void BuildIdentityMap(XmlNameTable nameTable, DataSet dataSet) { _tableSchemaMap = new XmlNodeIdHashtable(dataSet.Tables.Count); // This hash table contains // tables schemas as TableSchemaInfo objects // These objects holds reference to the table. // Hash tables with columns schema maps // and child tables schema maps string dsNamespace = nameTable.Get(dataSet.Namespace) ?? // Attempt to look up DataSet namespace in the name table nameTable.Add(dataSet.Namespace); // Found? Nope. Add it dataSet._namespaceURI = dsNamespace; // Set a DataSet namespace URI foreach (DataTable t in dataSet.Tables) { // For each table TableSchemaInfo tableSchemaInfo = AddTableSchema(nameTable, t); // Add table schema info to hash table if (tableSchemaInfo != null) { foreach (DataColumn c in t.Columns) { // Add column schema map // don't include auto-generated PK, FK and any hidden columns to be part of mapping if (IsMappedColumn(c)) { // If mapped column AddColumnSchema(nameTable, c, tableSchemaInfo.ColumnsSchemaMap); } // Add it to the map } // Add child nested tables to the schema foreach (DataRelation r in t.ChildRelations) { // Do we have a child tables ? if (r.Nested) { // Is it nested? // don't include non nested tables // Handle namespaces and names as usuall string _tableLocalName = XmlConvert.EncodeLocalName(r.ChildTable.TableName); string?tableLocalName = nameTable.Get(_tableLocalName) ?? nameTable.Add(_tableLocalName); string?tableNamespace = nameTable.Get(r.ChildTable.Namespace) ?? nameTable.Add(r.ChildTable.Namespace); XmlNodeIdentety idTable = new XmlNodeIdentety(tableLocalName, tableNamespace); tableSchemaInfo.ColumnsSchemaMap[idTable] = r.ChildTable; } } } } }
// This one is used while reading data with preloaded schema private void BuildIdentityMap(XmlNameTable nameTable, DataTable dataTable) { ArrayList tableList = GetSelfAndDescendants(dataTable); // Get list of tables we're loading // This includes our table and // related tables tree this.tableSchemaMap = new XmlNodeIdHashtable(tableList.Count); // Create hash table to hold all // tables to load. foreach (DataTable t in tableList) // For each table { TableSchemaInfo tableSchemaInfo = AddTableSchema(nameTable, t); // Create schema info if (tableSchemaInfo != null) { foreach (DataColumn c in t.Columns) // Add column information // don't include auto-generated PK, FK and any hidden columns to be part of mapping { if (IsMappedColumn(c)) { AddColumnSchema(nameTable, c, tableSchemaInfo.ColumnsSchemaMap); } } foreach (DataRelation r in t.ChildRelations) // Add nested tables information { if (r.Nested) // Is it nested? // don't include non nested tables // Handle namespaces and names as usuall { string _tableLocalName = XmlConvert.EncodeLocalName(r.ChildTable.TableName); string tableLocalName = nameTable.Get(_tableLocalName); if (tableLocalName == null) { tableLocalName = nameTable.Add(_tableLocalName); } string tableNamespace = nameTable.Get(r.ChildTable.Namespace); if (tableNamespace == null) { tableNamespace = nameTable.Add(r.ChildTable.Namespace); } XmlNodeIdentety idTable = new XmlNodeIdentety(tableLocalName, tableNamespace); tableSchemaInfo.ColumnsSchemaMap[idTable] = r.ChildTable; } } } } }
private static void MapColumnInformation(TableSchema table, TableSchemaInfo tSchema) { foreach (var c in table.Columns) { var cSchema = new ColumnSchemaInfo(); cSchema.ColumnName = c.Name; cSchema.DataType = c.DataType.ToString(); tSchema.Columns.Add(cSchema); } }
public void AddTable(TableSchemaInfo schema) { if (!HasTable(schema.TableName)) { var columns = new List <Column>(); schema.Columns.ForEach(c => columns.Add(new Column(c.ColumnName, Type.GetType(c.DataType)))); var table = new Table(schema.TableName, columns, _id, _process); Tables.Add(table); } }
private static void MapTableInformation(DbSchema schema, DbSchemaInfo info) { foreach (var table in schema.Tables) { var tSchema = new TableSchemaInfo(); tSchema.TableName = table.TableName; MapColumnInformation(table, tSchema); info.Tables.Add(tSchema); } }
public DataTable GetTableForNode(XmlReader node, bool fIgnoreNamespace) { TableSchemaInfo tableSchemaInfo = (TableSchemaInfo)(fIgnoreNamespace ? _tableSchemaMap[node.LocalName] : _tableSchemaMap[node]); if (tableSchemaInfo != null) { _lastTableSchemaInfo = tableSchemaInfo; return(_lastTableSchemaInfo.TableSchema); } return(null); }
public DataTable GetTableForNode(XmlReader node, bool fIgnoreNamespace) { TableSchemaInfo info = fIgnoreNamespace ? ((TableSchemaInfo)this.tableSchemaMap[node.LocalName]) : ((TableSchemaInfo)this.tableSchemaMap[node]); if (info != null) { this.lastTableSchemaInfo = info; return(this.lastTableSchemaInfo.TableSchema); } return(null); }
public object GetColumnSchema(DataTable table, XmlReader dataReader, bool fIgnoreNamespace) { if ((this.lastTableSchemaInfo == null) || (this.lastTableSchemaInfo.TableSchema != table)) { this.lastTableSchemaInfo = fIgnoreNamespace ? ((TableSchemaInfo)this.tableSchemaMap[table.EncodedTableName]) : ((TableSchemaInfo)this.tableSchemaMap[table]); } if (fIgnoreNamespace) { return(this.lastTableSchemaInfo.ColumnsSchemaMap[dataReader.LocalName]); } return(this.lastTableSchemaInfo.ColumnsSchemaMap[dataReader]); }
private TableSchemaInfo AddTableSchema(DataTable table, XmlNameTable nameTable) { string localName = nameTable.Get(table.EncodedTableName); string namespaceURI = nameTable.Get(table.Namespace); if (localName == null) { return null; } TableSchemaInfo info = new TableSchemaInfo(table); this.tableSchemaMap[new XmlNodeIdentety(localName, namespaceURI)] = info; return info; }
public object GetSchemaForNode(XmlNode node, bool fIgnoreNamespace) { TableSchemaInfo info = null; if (node.NodeType == XmlNodeType.Element) { info = fIgnoreNamespace ? ((TableSchemaInfo)this.tableSchemaMap[node.LocalName]) : ((TableSchemaInfo)this.tableSchemaMap[node]); } if (info != null) { return(info.TableSchema); } return(this.GetColumnSchema(node, fIgnoreNamespace)); }
private TableSchemaInfo AddTableSchema(DataTable table, XmlNameTable nameTable) { string localName = nameTable.Get(table.EncodedTableName); string namespaceURI = nameTable.Get(table.Namespace); if (localName == null) { return(null); } TableSchemaInfo info = new TableSchemaInfo(table); this.tableSchemaMap[new XmlNodeIdentety(localName, namespaceURI)] = info; return(info); }
public object GetColumnSchema(DataTable table, XmlReader dataReader, bool fIgnoreNamespace) { TableSchemaInfo tableSchemaInfo = null; tableSchemaInfo = (TableSchemaInfo)(fIgnoreNamespace ? tableSchemaMap[table.EncodedTableName] : tableSchemaMap[table]); if (fIgnoreNamespace) { return(tableSchemaInfo.ColumnsSchemaMap[dataReader.LocalName]); } else { return(tableSchemaInfo.ColumnsSchemaMap[dataReader]); } }
public DataTable GetTableForNode(XmlReader node, bool fIgnoreNamespace) { TableSchemaInfo tableSchemaInfo = null; tableSchemaInfo = (TableSchemaInfo)(fIgnoreNamespace ? tableSchemaMap[node.LocalName] : tableSchemaMap[node]); if (tableSchemaInfo != null) { return(tableSchemaInfo.TableSchema); } else { return(null); } }
// Used to infer schema public object GetSchemaForNode(XmlNode node, bool fIgnoreNamespace) { TableSchemaInfo tableSchemaInfo = null; if (node.NodeType == XmlNodeType.Element) { // If element tableSchemaInfo = (TableSchemaInfo)(fIgnoreNamespace ? _tableSchemaMap[node.LocalName] : _tableSchemaMap[node]); } // Look up table schema info for it if (tableSchemaInfo != null) { // Got info ? return(tableSchemaInfo.TableSchema); // Yes, Return table } return(GetColumnSchema(node, fIgnoreNamespace)); // Attempt to locate column }
private void BuildIdentityMap(DataTable dataTable, XmlNameTable nameTable) { this.tableSchemaMap = new XmlNodeIdHashtable(1); TableSchemaInfo info = this.AddTableSchema(dataTable, nameTable); if (info != null) { foreach (DataColumn column in dataTable.Columns) { if (IsMappedColumn(column)) { this.AddColumnSchema(column, nameTable, info.ColumnsSchemaMap); } } } }
private TableSchemaInfo AddTableSchema(XmlNameTable nameTable, DataTable table) { // Enzol:This is the opposite of the previous function: // we populate the nametable so that the hash comparison can happen as // object comparison instead of strings. // Sdub: GetIdentity is called from two places: BuildIdentityMap() and LoadRows() // First case deals with decoded names; Second one with encoded names. // We decided encoded names in first case (instead of decoding them in second) // because it save us time in LoadRows(). We have, as usual, more data them schemas string _tableLocalName = table.EncodedTableName; // Table name string?tableLocalName = nameTable.Get(_tableLocalName); // Look it up in nametable if (tableLocalName == null) { // If not found tableLocalName = nameTable.Add(_tableLocalName); // Add it } table._encodedTableName = tableLocalName; // And set it back string?tableNamespace = nameTable.Get(table.Namespace); // Look ip table namespace if (tableNamespace == null) { // If not found tableNamespace = nameTable.Add(table.Namespace); // Add it } else { if (table._tableNamespace != null) // Update table namespace { table._tableNamespace = tableNamespace; } } TableSchemaInfo tableSchemaInfo = new TableSchemaInfo(table); // Create new table schema info _tableSchemaMap[new XmlNodeIdentety(tableLocalName, tableNamespace)] = tableSchemaInfo; // And add it to the hashtable return(tableSchemaInfo); // Return it as we have to populate // Column schema map and Child table // schema map in it }
// Used for inference private void BuildIdentityMap(DataTable dataTable, XmlNameTable nameTable) { _tableSchemaMap = new XmlNodeIdHashtable(1); TableSchemaInfo tableSchemaInfo = AddTableSchema(dataTable, nameTable); if (tableSchemaInfo != null) { foreach (DataColumn c in dataTable.Columns) { // don't include auto-generated PK, FK and any hidden columns to be part of mapping if (IsMappedColumn(c)) { AddColumnSchema(c, nameTable, tableSchemaInfo.ColumnsSchemaMap); } } } }
public object GetSchemaForNode(XmlNode node, bool fIgnoreNamespace) { TableSchemaInfo tableSchemaInfo = null; if (node.NodeType == XmlNodeType.Element) { tableSchemaInfo = (TableSchemaInfo)(fIgnoreNamespace ? tableSchemaMap[node.LocalName] : tableSchemaMap[node]); } if (tableSchemaInfo != null) { return(tableSchemaInfo.TableSchema); } else { return(GetColumnSchema(node, fIgnoreNamespace)); } }
private void BuildIdentityMap(XmlNameTable nameTable, DataSet dataSet) { this.tableSchemaMap = new XmlNodeIdHashtable(dataSet.Tables.Count); string str3 = nameTable.Get(dataSet.Namespace); if (str3 == null) { str3 = nameTable.Add(dataSet.Namespace); } dataSet.namespaceURI = str3; foreach (DataTable table in dataSet.Tables) { TableSchemaInfo info = this.AddTableSchema(nameTable, table); if (info != null) { foreach (DataColumn column in table.Columns) { if (IsMappedColumn(column)) { this.AddColumnSchema(nameTable, column, info.ColumnsSchemaMap); } } foreach (DataRelation relation in table.ChildRelations) { if (relation.Nested) { string array = XmlConvert.EncodeLocalName(relation.ChildTable.TableName); string localName = nameTable.Get(array); if (localName == null) { localName = nameTable.Add(array); } string namespaceURI = nameTable.Get(relation.ChildTable.Namespace); if (namespaceURI == null) { namespaceURI = nameTable.Add(relation.ChildTable.Namespace); } XmlNodeIdentety identety = new XmlNodeIdentety(localName, namespaceURI); info.ColumnsSchemaMap[identety] = relation.ChildTable; } } } } }
public object GetColumnSchema(XmlNode node, bool fIgnoreNamespace) { TableSchemaInfo info = null; XmlNode parentNode = (node.NodeType == XmlNodeType.Attribute) ? ((XmlAttribute)node).OwnerElement : node.ParentNode; do { if ((parentNode == null) || (parentNode.NodeType != XmlNodeType.Element)) { return(null); } info = fIgnoreNamespace ? ((TableSchemaInfo)this.tableSchemaMap[parentNode.LocalName]) : ((TableSchemaInfo)this.tableSchemaMap[parentNode]); parentNode = parentNode.ParentNode; }while (info == null); if (fIgnoreNamespace) { return(info.ColumnsSchemaMap[node.LocalName]); } return(info.ColumnsSchemaMap[node]); }
private TableSchemaInfo AddTableSchema(XmlNameTable nameTable, DataTable table) { // Enzol:This is the opposite of the previous function: // we populate the nametable so that the hash comparison can happen as // object comparison instead of strings. // Sdub: GetIdentity is called from two places: BuildIdentityMap() and LoadRows() // First case deals with decoded names; Second one with encoded names. // We decided encoded names in first case (instead of decoding them in second) // because it save us time in LoadRows(). We have, as usual, more data them schemas string _tableLocalName = table.EncodedTableName; string tableLocalName = nameTable.Get(_tableLocalName); if (tableLocalName == null) { tableLocalName = nameTable.Add(_tableLocalName); } table.encodedTableName = tableLocalName; string tableNamespace = nameTable.Get(table.Namespace); if (tableNamespace == null) { tableNamespace = nameTable.Add(table.Namespace); } else { if (table.tableNamespace != null) { table.tableNamespace = tableNamespace; } } TableSchemaInfo tableSchemaInfo = new TableSchemaInfo(table); tableSchemaMap[new XmlNodeIdentety(tableLocalName, tableNamespace)] = tableSchemaInfo; return(tableSchemaInfo); }
// Used to infere schema private TableSchemaInfo?AddTableSchema(DataTable table, XmlNameTable nameTable) { // SDUB: Because in our case reader already read the document all names that we can meet in the // document already has an entry in NameTable. // If in future we will build identity map before reading XML we can replace Get() to Add() // Sdub: GetIdentity is called from two places: BuildIdentityMap() and LoadRows() // First case deals with decoded names; Second one with encoded names. // We decided encoded names in first case (instead of decoding them in second) // because it save us time in LoadRows(). We have, as usual, more data them schemas string?tableLocalName = nameTable.Get(table.EncodedTableName); string?tableNamespace = nameTable.Get(table.Namespace); if (tableLocalName == null) { // because name of this table isn't present in XML we don't need mapping for it. // Less mapping faster we work. return(null); } TableSchemaInfo tableSchemaInfo = new TableSchemaInfo(table); _tableSchemaMap[new XmlNodeIdentety(tableLocalName, tableNamespace)] = tableSchemaInfo; return(tableSchemaInfo); }
private void BuildIdentityMap(XmlNameTable nameTable, DataSet dataSet) { this.tableSchemaMap = new XmlNodeIdHashtable(dataSet.Tables.Count); string dsNamespace = nameTable.Get(dataSet.Namespace); if (dsNamespace == null) { dsNamespace = nameTable.Add(dataSet.Namespace); } dataSet.namespaceURI = dsNamespace; foreach (DataTable t in dataSet.Tables) { TableSchemaInfo tableSchemaInfo = AddTableSchema(nameTable, t); if (tableSchemaInfo != null) { foreach (DataColumn c in t.Columns) { // don't include auto-generated PK, FK and any hidden columns to be part of mapping if (IsMappedColumn(c)) { AddColumnSchema(nameTable, c, tableSchemaInfo.ColumnsSchemaMap); } } foreach (DataRelation r in t.ChildRelations) { if (r.Nested) { // don't include non nested tables AddChildTableSchema(nameTable, r, tableSchemaInfo.ChildTablesSchemaMap); } } } } }
public object GetColumnSchema(DataTable table, XmlReader dataReader, bool fIgnoreNamespace) { if ((this.lastTableSchemaInfo == null) || (this.lastTableSchemaInfo.TableSchema != table)) { this.lastTableSchemaInfo = fIgnoreNamespace ? ((TableSchemaInfo) this.tableSchemaMap[table.EncodedTableName]) : ((TableSchemaInfo) this.tableSchemaMap[table]); } if (fIgnoreNamespace) { return this.lastTableSchemaInfo.ColumnsSchemaMap[dataReader.LocalName]; } return this.lastTableSchemaInfo.ColumnsSchemaMap[dataReader]; }
private TableSchemaInfo AddTableSchema(XmlNameTable nameTable, DataTable table) { string encodedTableName = table.EncodedTableName; string localName = nameTable.Get(encodedTableName); if (localName == null) { localName = nameTable.Add(encodedTableName); } table.encodedTableName = localName; string namespaceURI = nameTable.Get(table.Namespace); if (namespaceURI == null) { namespaceURI = nameTable.Add(table.Namespace); } else if (table.tableNamespace != null) { table.tableNamespace = namespaceURI; } TableSchemaInfo info = new TableSchemaInfo(table); this.tableSchemaMap[new XmlNodeIdentety(localName, namespaceURI)] = info; return info; }
// Used to infere schema private TableSchemaInfo AddTableSchema(DataTable table, XmlNameTable nameTable) { // SDUB: Because in our case reader already read the document all names that we can meet in the // document already has an entry in NameTable. // If in future we will build identity map before reading XML we can replace Get() to Add() // Sdub: GetIdentity is called from two places: BuildIdentityMap() and LoadRows() // First case deals with decoded names; Second one with encoded names. // We decided encoded names in first case (instead of decoding them in second) // because it save us time in LoadRows(). We have, as usual, more data them schemas string tableLocalName = nameTable.Get(table.EncodedTableName); string tableNamespace = nameTable.Get(table.Namespace); if (tableLocalName == null) { // because name of this table isn't present in XML we don't need mapping for it. // Less mapping faster we work. return null; } TableSchemaInfo tableSchemaInfo = new TableSchemaInfo(table); _tableSchemaMap[new XmlNodeIdentety(tableLocalName, tableNamespace)] = tableSchemaInfo; return tableSchemaInfo; }
private TableSchemaInfo AddTableSchema(XmlNameTable nameTable, DataTable table) { // Enzol:This is the opposite of the previous function: // we populate the nametable so that the hash comparison can happen as // object comparison instead of strings. // Sdub: GetIdentity is called from two places: BuildIdentityMap() and LoadRows() // First case deals with decoded names; Second one with encoded names. // We decided encoded names in first case (instead of decoding them in second) // because it save us time in LoadRows(). We have, as usual, more data them schemas string _tableLocalName = table.EncodedTableName; // Table name string tableLocalName = nameTable.Get(_tableLocalName); // Look it up in nametable if (tableLocalName == null) { // If not found tableLocalName = nameTable.Add(_tableLocalName); // Add it } table._encodedTableName = tableLocalName; // And set it back string tableNamespace = nameTable.Get(table.Namespace); // Look ip table namespace if (tableNamespace == null) { // If not found tableNamespace = nameTable.Add(table.Namespace); // Add it } else { if (table._tableNamespace != null) // Update table namespace table._tableNamespace = tableNamespace; } TableSchemaInfo tableSchemaInfo = new TableSchemaInfo(table); // Create new table schema info _tableSchemaMap[new XmlNodeIdentety(tableLocalName, tableNamespace)] = tableSchemaInfo; // And add it to the hashtable return tableSchemaInfo; // Return it as we have to populate // Column schema map and Child table // schema map in it }
public object GetColumnSchema(DataTable table, XmlReader dataReader, bool fIgnoreNamespace) { if ((_lastTableSchemaInfo == null) || (_lastTableSchemaInfo.TableSchema != table)) { _lastTableSchemaInfo = (TableSchemaInfo)(fIgnoreNamespace ? _tableSchemaMap[table.EncodedTableName] : _tableSchemaMap[table]); } if (fIgnoreNamespace) return _lastTableSchemaInfo.ColumnsSchemaMap[dataReader.LocalName]; return _lastTableSchemaInfo.ColumnsSchemaMap[dataReader]; }
public DataTable GetTableForNode(XmlReader node, bool fIgnoreNamespace) { TableSchemaInfo tableSchemaInfo = (TableSchemaInfo)(fIgnoreNamespace ? _tableSchemaMap[node.LocalName] : _tableSchemaMap[node]); if (tableSchemaInfo != null) { _lastTableSchemaInfo = tableSchemaInfo; return _lastTableSchemaInfo.TableSchema; } return null; }
public DataTable GetTableForNode(XmlReader node, bool fIgnoreNamespace) { TableSchemaInfo info = fIgnoreNamespace ? ((TableSchemaInfo) this.tableSchemaMap[node.LocalName]) : ((TableSchemaInfo) this.tableSchemaMap[node]); if (info != null) { this.lastTableSchemaInfo = info; return this.lastTableSchemaInfo.TableSchema; } return null; }